| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.base.BaseSelect; |
| | | import com.ycl.platform.domain.entity.CheckTemplate; |
| | | import com.ycl.platform.domain.entity.CheckTemplateRule; |
| | | import com.ycl.platform.domain.query.CheckTemplateQuery; |
| | | import com.ycl.platform.mapper.CheckTemplateMapper; |
| | | import com.ycl.platform.mapper.CheckTemplateRuleMapper; |
| | | import com.ycl.platform.service.ICheckTemplateRuleService; |
| | | import com.ycl.platform.service.ICheckTemplateService; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.entity.SysDept; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import io.jsonwebtoken.lang.Collections; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import constant.CheckConstants; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import utils.DateUtils; |
| | | import utils.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | * @date 2024-04-01 |
| | | */ |
| | | @Service |
| | | public class CheckTemplateServiceImpl implements ICheckTemplateService { |
| | | public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper,CheckTemplate> implements ICheckTemplateService { |
| | | @Autowired |
| | | private CheckTemplateMapper checkTemplateMapper; |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | private ICheckTemplateRuleService templateRuleServicee; |
| | | @Autowired |
| | | private CheckTemplateRuleMapper checkTemplateRuleMapper; |
| | | /** |
| | | * 查询考核模板 |
| | | * |
| | |
| | | * @return 考核模板 |
| | | */ |
| | | @Override |
| | | public CheckTemplateQuery selectCheckTemplateById(Long id) { |
| | | public CheckTemplateQuery selectCheckTemplateById(Integer id) { |
| | | CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(id); |
| | | CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery(); |
| | | BeanUtils.copyProperties(checkTemplate,checkTemplateQuery); |
| | | String deptId = checkTemplate.getDeptId(); |
| | | String deptIdStr = deptId.substring(1, deptId.length() - 1); |
| | | List<Integer> deptIds = Arrays.stream(deptIdStr.split(",")) |
| | | .mapToInt(Integer::parseInt) |
| | | .boxed().collect(Collectors.toList()); |
| | | checkTemplateQuery.setDeptId(deptIds); |
| | | BeanUtils.copyProperties(checkTemplate, checkTemplateQuery); |
| | | List<Integer> deptIds = JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class); |
| | | checkTemplateQuery.setDeptId(deptIds) |
| | | .setAlarmScore(checkTemplate.getAlarmScore()+""); |
| | | //查询规则权重 |
| | | List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplate.getId()); |
| | | 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()); |
| | | list.add(map); |
| | | } |
| | | checkTemplateQuery.setRuleFormList(list); |
| | | //TODO:查询template_rule表中的权重信息。 |
| | | |
| | | |
| | | return checkTemplateQuery; |
| | | } |
| | | |
| | |
| | | * @return 考核模板 |
| | | */ |
| | | @Override |
| | | public List<CheckTemplate> selectCheckTemplateList(CheckTemplateQuery checkTemplateDTO) { |
| | | public List<CheckTemplateQuery> selectCheckTemplateList(CheckTemplateQuery checkTemplateDTO) { |
| | | List<CheckTemplate> checkTemplates = checkTemplateMapper.selectCheckTemplateList(checkTemplateDTO); |
| | | //部门区域下拉列表 |
| | | Result all = deptService.pullList(); |
| | | List<BaseSelect> data = (List<BaseSelect>) all.get("data"); |
| | | //翻译部门id |
| | | List<CheckTemplateQuery> checkTemplateList = new ArrayList<>(); |
| | | //转换部门id为集合,转换alarmScore为string |
| | | for (CheckTemplate template : checkTemplates) { |
| | | if(template.getDeptId() == null)continue; |
| | | String[] deptIds = template.getDeptId().replace("[", "").replace("]", "").split(","); |
| | | List<String> deptName = new ArrayList<>(); |
| | | for (String deptId : deptIds) { |
| | | List<String> deptStr = data.stream() |
| | | .filter(baseSelect -> baseSelect.getId().equals(Integer.parseInt(deptId))) |
| | | .map(BaseSelect::getValue) |
| | | .collect(Collectors.toList()); |
| | | deptName.addAll(deptStr); |
| | | } |
| | | template.setDeptId(StringUtils.join(deptName,",")); |
| | | List<Integer> deptIds = JSONArray.parseArray(template.getDeptId(), Integer.class); |
| | | CheckTemplateQuery checkTemplateQuery = new CheckTemplateQuery(); |
| | | BeanUtils.copyProperties(template, checkTemplateQuery); |
| | | checkTemplateQuery.setDeptId(deptIds); |
| | | checkTemplateList.add(checkTemplateQuery); |
| | | } |
| | | |
| | | return checkTemplates; |
| | | return checkTemplateList; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertCheckTemplate(CheckTemplateQuery checkTemplateDTO) { |
| | | checkTemplateDTO.setCreateTime(DateUtils.getNowDate()); |
| | | //TODO:新增定时任务,状态同模板,然后赋值jobId给template |
| | | |
| | | |
| | | String username = SecurityUtils.getUsername(); |
| | | /** 插入t_template */ |
| | | CheckTemplate checkTemplate = new CheckTemplate(); |
| | | BeanUtils.copyProperties(checkTemplateDTO,checkTemplate); |
| | | checkTemplate.setDeptId(checkTemplateDTO.getDeptId().toString().replaceAll(" ","")); |
| | | return checkTemplateMapper.insertCheckTemplate(checkTemplate); |
| | | BeanUtils.copyProperties(checkTemplateDTO, checkTemplate); |
| | | //从小到大排序 |
| | | List<Integer> deptId = checkTemplateDTO.getDeptId(); |
| | | Collections.sort(deptId); |
| | | Date nowDate = DateUtils.getNowDate(); |
| | | checkTemplate.setDeptId(JSONArray.toJSONString(deptId)) |
| | | .setUpdateUserName(username) |
| | | .setCreateUserName(username) |
| | | //不填报警分数---->零分---->不报警 |
| | | .setAlarmScore(new BigDecimal(checkTemplateDTO.getAlarmScore() == null? "":checkTemplateDTO.getAlarmScore())); |
| | | int i = checkTemplateMapper.insertCheckTemplate(checkTemplate); |
| | | /** t_template_rule新增权重 */ |
| | | insertTemlpateRule(checkTemplateDTO, checkTemplate); |
| | | |
| | | return i; |
| | | } |
| | | /** |
| | | * 复制考核模板 |
| | | * |
| | | * @param checkTemplate 考核模板 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int copyCheckTemplate(CheckTemplateQuery checkTemplateDTO) { |
| | | //TODO:新增定时任务,状态同模板,然后赋值jobId给template |
| | | |
| | | //插入模板表 |
| | | CheckTemplate checkTemplate = checkTemplateMapper.selectCheckTemplateById(checkTemplateDTO.getId()); |
| | | String username = SecurityUtils.getUsername(); |
| | | checkTemplate.setUpdateUserName(username) |
| | | .setCreateUserName(username) |
| | | .setStatus(CheckConstants.Status_Stop) |
| | | .setId(null); |
| | | int i = checkTemplateMapper.insertCheckTemplate(checkTemplate); |
| | | //插入template_rule表 |
| | | List<CheckTemplateRule> templateRuleList = checkTemplateRuleMapper.selectListByTemplateId(checkTemplateDTO.getId()); |
| | | templateRuleList.forEach(checkTemplateRule -> checkTemplateRule.setCheckTemplateId(checkTemplate.getId()).setId(null)); |
| | | templateRuleServicee.saveBatch(templateRuleList); |
| | | |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateCheckTemplate(CheckTemplate checkTemplate) { |
| | | checkTemplate.setUpdateTime(DateUtils.getNowDate()); |
| | | return checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateCheckTemplate(CheckTemplateQuery checkTemplateDTO) { |
| | | 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)); |
| | | int i = checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | /** t_template_rule修改权重 */ |
| | | //先删除原数据 |
| | | checkTemplateRuleMapper.deleteByTemplateId(checkTemplate.getId()); |
| | | //插入新规则数据 |
| | | insertTemlpateRule(checkTemplateDTO, checkTemplate); |
| | | |
| | | //TODO:判断状态是否修改,调整job表里的状态 |
| | | |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteCheckTemplateByIds(Long[] ids) { |
| | | public int deleteCheckTemplateByIds(Integer[] ids) { |
| | | return checkTemplateMapper.deleteCheckTemplateByIds(ids); |
| | | } |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteCheckTemplateById(Long id) { |
| | | return checkTemplateMapper.deleteCheckTemplateById(id); |
| | | public int deleteCheckTemplateById(Integer id) { |
| | | //TODO:删除定时任务 |
| | | |
| | | |
| | | return checkTemplateMapper.updateCheckTemplate(new CheckTemplate().setId(id) |
| | | .setDeleted(CheckConstants.Delete)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | return Result.ok().data(checkTemplates); |
| | | } |
| | | |
| | | |
| | | |
| | | private void insertTemlpateRule(CheckTemplateQuery checkTemplateDTO, CheckTemplate checkTemplate) { |
| | | List<Map<String, Object>> ruleFormList = checkTemplateDTO.getRuleFormList(); |
| | | if (!CollectionUtils.isEmpty(ruleFormList)) { |
| | | List<CheckTemplateRule> templateRuleList = new ArrayList<>(); |
| | | for (Map<String, Object> map : ruleFormList) { |
| | | templateRuleList.add(new CheckTemplateRule() |
| | | .setCheckRuleId((Integer) map.get("ruleId")) |
| | | .setCheckTemplateId(checkTemplate.getId()) |
| | | .setWeight(new BigDecimal(map.get("weight").toString()))); |
| | | } |
| | | //批量插入数据库 |
| | | templateRuleServicee.saveBatch(templateRuleList); |
| | | } |
| | | } |
| | | } |