package com.qmth.ops.biz.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.qmth.ops.biz.dao.ModuleDao; import com.qmth.ops.biz.domain.Module; import com.qmth.ops.biz.query.ModuleQuery; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @Service public class ModuleService { @Resource private ModuleDao moduleDao; @Transactional public Module insert(Module module) { module.setCreateTime(System.currentTimeMillis()); module.setUpdateTime(module.getCreateTime()); moduleDao.insert(module); return module; } @Transactional public Module update(Module module) { moduleDao.update(module, new LambdaUpdateWrapper().set(module.getCode() != null, Module::getCode, module.getCode()) .set(module.getName() != null, Module::getName, module.getName()) .set(module.getEnable() != null, Module::getEnable, module.getEnable()) .set(Module::getUpdateTime, System.currentTimeMillis()).eq(Module::getId, module.getId())); return moduleDao.selectById(module.getId()); } public List list(ModuleQuery query) { return moduleDao.selectList(query.build()); } public Module findById(Long id) { return moduleDao.selectById(id); } public Module findByAppAndCode(Long appId, String code) { return moduleDao .selectOne(new LambdaQueryWrapper().eq(Module::getAppId, appId).eq(Module::getCode, code)); } }