| | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.exception.job.TaskException; |
| | | import com.ycl.platform.base.BaseSelect; |
| | | import com.ycl.platform.domain.entity.CheckTemplate; |
| | | import com.ycl.platform.domain.entity.CheckTemplateRule; |
| | |
| | | import com.ycl.platform.mapper.CheckTemplateRuleMapper; |
| | | import com.ycl.platform.service.ICheckTemplateRuleService; |
| | | import com.ycl.platform.service.ICheckTemplateService; |
| | | import com.ycl.system.AjaxResult; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.domain.SysJob; |
| | | import com.ycl.system.entity.SysDept; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import com.ycl.system.service.ISysJobService; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import constant.CheckConstants; |
| | | import org.quartz.SchedulerException; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | |
| | | * @date 2024-04-01 |
| | | */ |
| | | @Service |
| | | public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper,CheckTemplate> implements ICheckTemplateService { |
| | | public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper, CheckTemplate> implements ICheckTemplateService { |
| | | @Autowired |
| | | private CheckTemplateMapper checkTemplateMapper; |
| | | @Autowired |
| | | private ICheckTemplateRuleService templateRuleServicee; |
| | | @Autowired |
| | | private CheckTemplateRuleMapper checkTemplateRuleMapper; |
| | | @Autowired |
| | | private ISysJobService jobService; |
| | | |
| | | /** |
| | | * 查询考核模板 |
| | | * |
| | |
| | | BeanUtils.copyProperties(checkTemplate, checkTemplateQuery); |
| | | List<Integer> deptIds = JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class); |
| | | checkTemplateQuery.setDeptId(deptIds) |
| | | .setAdjustCoefficient(checkTemplate.getAdjustCoefficient()+"") |
| | | .setAlarmScore(checkTemplate.getAlarmScore()+""); |
| | | .setAdjustCoefficient(checkTemplate.getAdjustCoefficient() + "") |
| | | .setAlarmScore(checkTemplate.getAlarmScore() + ""); |
| | | //查询规则权重 |
| | | List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplate.getId()); |
| | | List<Map<String,Object>> list = new ArrayList<>(); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (CheckTemplateRule checkTemplateRule : templateRuleList) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("ruleId",checkTemplateRule.getCheckRuleId()); |
| | | map.put("weight",checkTemplateRule.getWeight()); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("ruleId", checkTemplateRule.getCheckRuleId()); |
| | | map.put("weight", checkTemplateRule.getWeight()); |
| | | list.add(map); |
| | | } |
| | | checkTemplateQuery.setRuleFormList(list); |
| | | //TODO:查询template_rule表中的权重信息。 |
| | | |
| | | |
| | | return checkTemplateQuery; |
| | | } |
| | |
| | | CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery(); |
| | | BeanUtils.copyProperties(template, checkTemplateQuery); |
| | | checkTemplateQuery.setDeptId(deptIds) |
| | | .setAdjustCoefficient(template.getAdjustCoefficient()+""); |
| | | .setAdjustCoefficient(template.getAdjustCoefficient() + ""); |
| | | checkTemplateList.add(checkTemplateQuery); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) { |
| | | //TODO:新增定时任务,状态同模板,然后赋值jobId给template |
| | | |
| | | |
| | | public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException { |
| | | String username = SecurityUtils.getUsername(); |
| | | /** 插入t_template */ |
| | | CheckTemplate checkTemplate = new CheckTemplate(); |
| | |
| | | checkTemplate.setDeptId(JSONArray.toJSONString(deptId)) |
| | | .setUpdateUserName(username) |
| | | .setCreateUserName(username) |
| | | .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient()+"")) |
| | | .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient() + "")) |
| | | //不填报警分数---->零分---->不报警 |
| | | .setAlarmScore(new BigDecimal(checkTemplateDTO.getAlarmScore() == null? "":checkTemplateDTO.getAlarmScore())); |
| | | .setAlarmScore(new BigDecimal(checkTemplateDTO.getAlarmScore() == null ? "" : checkTemplateDTO.getAlarmScore())); |
| | | int i = checkTemplateMapper.insertCheckTemplate(checkTemplate); |
| | | |
| | | //新增定时任务,状态同模板,然后赋值jobId给template |
| | | SysJob sysJob = addJob(checkTemplateDTO.setId(checkTemplate.getId())); |
| | | checkTemplate.setJobId(Integer.parseInt(sysJob.getJobId() + "")); |
| | | checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | |
| | | /** t_template_rule新增权重 */ |
| | | insertTemlpateRule(checkTemplateDTO, checkTemplate); |
| | | |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * 复制考核模板 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int copyCheckTemplate(CheckTemplateQuery checkTemplateDTO) { |
| | | //TODO:新增定时任务,状态同模板,然后赋值jobId给template |
| | | |
| | | public int copyCheckTemplate(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException { |
| | | //插入模板表 |
| | | CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(checkTemplateDTO.getId()); |
| | | String username = SecurityUtils.getUsername(); |
| | |
| | | List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplateDTO.getId()); |
| | | templateRuleList.forEach(checkTemplateRule -> checkTemplateRule.setCheckTemplateId(checkTemplate.getId()).setId(null)); |
| | | templateRuleServicee.saveBatch(templateRuleList); |
| | | |
| | | //新增定时任务,状态同模板,然后赋值jobId给template |
| | | SysJob sysJob = addJob(checkTemplateDTO.setId(checkTemplate.getId())); |
| | | checkTemplate.setJobId(Integer.parseInt(sysJob.getJobId() + "")); |
| | | checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | return i; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateCheckTemplate(CheckTemplateQuery checkTemplateDTO) { |
| | | public AjaxResult updateCheckTemplate(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException { |
| | | CheckTemplate checkTemplate = new CheckTemplate(); |
| | | BeanUtils.copyProperties(checkTemplateDTO, checkTemplate); |
| | | checkTemplate.setUpdateUserName(SecurityUtils.getUsername()); |
| | | List<Integer> deptId = checkTemplateDTO.getDeptId(); |
| | | Collections.sort(deptId); |
| | | checkTemplate.setDeptId(JSONArray.toJSONString(deptId)) |
| | | .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient()+"")); |
| | | int i = checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | .setAdjustCoefficient(new BigDecimal(checkTemplateDTO.getAdjustCoefficient() + "")); |
| | | checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | |
| | | /** t_template_rule修改权重 */ |
| | | //先删除原数据 |
| | | checkTemplateRuleMapper.deleteByTemplateId(checkTemplate.getId()); |
| | | //插入新规则数据 |
| | | insertTemlpateRule(checkTemplateDTO, checkTemplate); |
| | | |
| | | //TODO:判断状态是否修改,调整job表里的状态 |
| | | |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * 批量删除考核模板 |
| | | * |
| | | * @param ids 需要删除的考核模板主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteCheckTemplateByIds(Integer[] ids) { |
| | | return checkTemplateMapper.deleteCheckTemplateByIds(ids); |
| | | if (!CollectionUtils.isEmpty(checkTemplateDTO.getRuleFormList())) { |
| | | //先删除原数据 |
| | | checkTemplateRuleMapper.deleteByTemplateId(checkTemplate.getId()); |
| | | //插入新规则数据 |
| | | insertTemlpateRule(checkTemplateDTO, checkTemplate); |
| | | } |
| | | //调整job表里的状态 |
| | | SysJob job = jobService.selectJobById(Long.valueOf(checkTemplateDTO.getJobId())); |
| | | job.setStatus(checkTemplateDTO.getStatus()); |
| | | jobService.updateJob(job); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteCheckTemplateById(Integer id) { |
| | | //TODO:删除定时任务 |
| | | |
| | | |
| | | return checkTemplateMapper.updateCheckTemplate(new CheckTemplate().setId(id) |
| | | .setDeleted(CheckConstants.Delete)); |
| | | public int deleteCheckTemplateById(Integer id) throws SchedulerException { |
| | | CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(id); |
| | | //删除定时任务 |
| | | SysJob job = new SysJob(); |
| | | if (checkTemplate.getJobId() != null) { |
| | | job.setJobId(Long.valueOf(checkTemplate.getJobId())); |
| | | job.setJobGroup("CHECK"); |
| | | jobService.deleteJob(job); |
| | | } |
| | | return checkTemplateMapper.deleteCheckTemplateById(id); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | return Result.ok().data(checkTemplates); |
| | | } |
| | | |
| | | |
| | | |
| | | private void insertTemlpateRule(CheckTemplateQuery checkTemplateDTO, CheckTemplate checkTemplate) { |
| | |
| | | templateRuleServicee.saveBatch(templateRuleList); |
| | | } |
| | | } |
| | | |
| | | private SysJob addJob(CheckTemplateQuery checkTemplateDTO) throws SchedulerException, TaskException { |
| | | SysJob job = new SysJob(); |
| | | job.setCreateBy(SecurityUtils.getLoginUser().getUsername()); |
| | | //调用方法名 |
| | | job.setInvokeTarget("checkScoreTask.executeTemplate(" + checkTemplateDTO.getId() + ")"); |
| | | job.setConcurrent("1"); |
| | | job.setStatus(checkTemplateDTO.getStatus()); |
| | | job.setJobGroup("CHECK"); |
| | | job.setCronExpression("0 0 6 * * ?"); |
| | | job.setJobName(checkTemplateDTO.getTemplateName()); |
| | | int i = jobService.insertJob(job); |
| | | return job; |
| | | } |
| | | |
| | | // /** |
| | | // * 批量删除考核模板 |
| | | // * |
| | | // * @param ids 需要删除的考核模板主键 |
| | | // * @return 结果 |
| | | // */ |
| | | // @Override |
| | | // public int deleteCheckTemplateByIds(Integer[] ids) { |
| | | // return checkTemplateMapper.deleteCheckTemplateByIds(ids); |
| | | // } |
| | | } |