package com.iailab.module.model.mcs.pre.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iailab.framework.common.page.PageData; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.module.model.mcs.pre.dao.DmModuleDao; import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; import com.iailab.module.model.mcs.pre.service.DmModuleService; import com.iailab.module.model.mcs.pre.vo.DmModulePageReqVO; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; /** * @author PanZhibao * @date 2021年04月23日 8:36 */ @Service("dmModuleService") public class DmModuleServiceImpl extends BaseServiceImpl implements DmModuleService { @Override public PageResult queryPage(DmModulePageReqVO reqVO) { return baseDao.selectPage(reqVO); } @Override public List list(Map params) { QueryWrapper wrapper = getWrapper(params); wrapper.orderByDesc("CREATE_TIME"); return baseDao.selectList(wrapper); } @Override public DmModuleEntity get(String id) { return baseDao.selectById(id); } private QueryWrapper getWrapper(Map params) { String modulename = (String) params.get("modulename"); String moduletype = (String) params.get("moduletype"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.like(StringUtils.isNotBlank(modulename), "modulename", modulename) .eq(StringUtils.isNotBlank(moduletype), "moduletype", moduletype); return wrapper; } @Override @Transactional(rollbackFor = Exception.class) public void saveModule(DmModuleEntity module) { module.setId(UUID.randomUUID().toString()); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); module.setPredicttime(calendar.getTime()); module.setCollecttime(calendar.getTime()); module.setUpdateTime(new Date()); baseDao.insert(module); } @Override @Transactional(rollbackFor = Exception.class) public void update(DmModuleEntity module) { module.setUpdateTime(new Date()); baseDao.updateById(module); } @Override @Transactional(rollbackFor = Exception.class) public void deleteBatch(String[] moduleIds) { baseDao.deleteBatchIds(Arrays.asList(moduleIds)); } @Override public List getModuleByModuleType(String moduletype) { Map params = new HashMap<>(1); params.put("moduletype", moduletype); QueryWrapper wrapper = getWrapper(params); return baseDao.selectList(wrapper); } @Override public int check(DmModuleEntity module) { String id = module.getId(); String modulename = module.getModulename(); QueryWrapper moduleWrapper = new QueryWrapper<>(); moduleWrapper.ne(StringUtils.isNotBlank(id), "id", id); moduleWrapper.and(wrapper -> wrapper.eq("modulename", modulename)); List list = baseDao.selectList(moduleWrapper); return list.size(); } }