| | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.merge.LoopMergeStrategy; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.handler.CommentWriteHandler; |
| | | import com.ycl.handler.CustomSheetWriteHandler; |
| | | import com.ycl.platform.domain.entity.CalculateMoneyRule; |
| | | import com.ycl.platform.domain.entity.CalculateRule; |
| | | import com.ycl.platform.domain.entity.TContract; |
| | | import com.ycl.platform.mapper.TContractMapper; |
| | | import com.ycl.platform.service.ICalculateRuleService; |
| | | import com.ycl.platform.service.ITContractService; |
| | | import com.ycl.system.AjaxResult; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.StringUtils; |
| | | import enumeration.general.RuleDeductCategoryEnum; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.net.URLEncoder; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 【请填写功能名称】Service业务层处理 |
| | |
| | | public class TContractServiceImpl extends ServiceImpl<TContractMapper, TContract> implements ITContractService { |
| | | |
| | | private final ICalculateRuleService calculateRuleService; |
| | | private final CalculateMoneyRuleServiceImpl calculateMoneyRuleService; |
| | | private final YwUnitServiceImpl ywUnitService; |
| | | |
| | | @Override |
| | |
| | | calculateRule1.setRuleName("视频平均在线率"); |
| | | calculateRule1.setRuleDesc("(1)视频在线率=视频在线数量÷前端服务配置数(应扣除不可抗力或与中标人服务无关造成的掉线除外。)"); |
| | | calculateRule1.setRuleCondition("≥98%"); |
| | | calculateRule1.setDeductCategory("扣指定分数"); |
| | | calculateRule1.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); |
| | | calculateRule1.setCalcFraction(0.00); |
| | | list.add(calculateRule1); |
| | | CalculateRule calculateRule2 = new CalculateRule(); |
| | | calculateRule2.setRuleDesc("(2)视频平均在线率:当月每日视频在线率的平均值。"); |
| | | calculateRule2.setRuleCondition("95%≤视频平均在线率<98%"); |
| | | calculateRule2.setDeductCategory("扣指定分数"); |
| | | calculateRule2.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); |
| | | calculateRule2.setCalcFraction(5.00); |
| | | list.add(calculateRule2); |
| | | CalculateRule calculateRule3 = new CalculateRule(); |
| | | calculateRule3.setRuleDesc("(3)视频在线率保留整数并且向下取整。"); |
| | | calculateRule3.setRuleCondition("90%≤视频平均在线率<95%"); |
| | | calculateRule3.setDeductCategory("扣指定分数"); |
| | | calculateRule3.setDeductCategory(RuleDeductCategoryEnum.DEDUCT_POINTS); |
| | | calculateRule3.setCalcFraction(10.00); |
| | | list.add(calculateRule3); |
| | | CalculateRule calculateRule4 = new CalculateRule(); |
| | |
| | | calculateRule4.setRuleName("前端感知源治理工作"); |
| | | calculateRule4.setRuleDesc("时钟同步(超过±3秒为不合格)"); |
| | | calculateRule4.setRuleCondition("视频监控摄像机时钟不同步,24小时内未修复的"); |
| | | calculateRule4.setDeductCategory("分数乘以数量"); |
| | | calculateRule4.setDeductCategory(RuleDeductCategoryEnum.MULTIPLY_POINTS_BY_QUANTITY); |
| | | calculateRule4.setCalcFraction(0.1); |
| | | list.add(calculateRule4); |
| | | CalculateRule calculateRule7 = new CalculateRule(); |
| | |
| | | calculateRule5.setRuleName("后台系统的保障"); |
| | | calculateRule5.setRuleDesc("在个别设备故障但不影响该功能模块整体应用情况下,须在72小时以内排除故障。"); |
| | | calculateRule5.setRuleCondition("单次故障时长若超出144小时以后,每超出12小时(不足12小时按12小时计)"); |
| | | calculateRule5.setDeductCategory("除以数量后乘以分数"); |
| | | calculateRule5.setDeductCategory(RuleDeductCategoryEnum.MULTIPLY_POINTS_AFTER_DIVIDING_QUANTITY); |
| | | calculateRule5.setCalcFraction(2.00); |
| | | calculateRule5.setCalcUnit(12); |
| | | list.add(calculateRule5); |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void importData(MultipartFile file, TContract tContract) { |
| | | public AjaxResult importData(MultipartFile file, TContract tContract) { |
| | | // 保存合同 |
| | | tContract.setCreateTime(DateUtils.getNowDate()); |
| | | tContract.setDeleted("0"); |
| | | save(tContract); |
| | | List<CalculateRule> list = calculateRuleService.readExcel(file); |
| | | |
| | | // 遍历父子关系 |
| | | List<CalculateRule> calculateRulesToSave = new ArrayList<>(); |
| | | CalculateRule temp = new CalculateRule(); |
| | | CalculateRule fu1 = new CalculateRule(); |
| | | CalculateRule fu2 = new CalculateRule(); |
| | | boolean fuNew = true; |
| | | for (CalculateRule calculateRule : list) { |
| | | // 父规则 |
| | | // 判断数据完整性 |
| | | if (ObjectUtils.isEmpty(calculateRule.getDeductCategory())) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.warn("请选择" + calculateRule.getRuleName() + calculateRule.getRuleCondition() + "扣分方式"); |
| | | } |
| | | if (RuleDeductCategoryEnum.MULTIPLY_POINTS_AFTER_DIVIDING_QUANTITY.equals(calculateRule.getDeductCategory()) && ObjectUtils.isEmpty(calculateRule.getCalcUnit())) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.warn("请填写" + calculateRule.getRuleName() + calculateRule.getRuleCondition() + "除以数量"); |
| | | } |
| | | if(ObjectUtils.isEmpty(calculateRule.getCalcFraction())) { |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.warn("请填写" + calculateRule.getRuleName() + calculateRule.getRuleCondition() + "扣分数值"); |
| | | } |
| | | // 保存父规则获取父id |
| | | if (StringUtils.isNotBlank(calculateRule.getRuleName())) { |
| | | CalculateRule fu = new CalculateRule(); |
| | | fu.setContractId(tContract.getId().intValue()); |
| | | fu.setRuleName(calculateRule.getRuleName()); |
| | | fu.setCreateTime(DateUtils.getNowDate()); |
| | | fu.setDeleted(0); |
| | | calculateRuleService.save(fu); |
| | | temp = fu; |
| | | CalculateRule one = new CalculateRule(); |
| | | one.setParentId(0L); |
| | | one.setContractId(tContract.getId().intValue()); |
| | | one.setRuleName(calculateRule.getRuleName()); |
| | | one.setCreateTime(DateUtils.getNowDate()); |
| | | one.setDeleted(0); |
| | | calculateRuleService.save(one); |
| | | fu1 = one; |
| | | fuNew = true; |
| | | } |
| | | // 保存第二层父规则获取第二层父id |
| | | if (StringUtils.isNotBlank(calculateRule.getRuleDesc())) { |
| | | CalculateRule two = new CalculateRule(); |
| | | two.setContractId(tContract.getId().intValue()); |
| | | two.setParentId(fu1.getId()); |
| | | two.setRuleDesc(calculateRule.getRuleDesc()); |
| | | two.setCreateTime(DateUtils.getNowDate()); |
| | | two.setDeleted(0); |
| | | calculateRuleService.save(two); |
| | | fu2 = two; |
| | | fuNew = false; |
| | | } |
| | | calculateRule.setContractId(tContract.getId().intValue()); |
| | | calculateRule.setCreateTime(DateUtils.getNowDate()); |
| | | calculateRule.setDeleted(0); |
| | | calculateRule.setParentId(temp.getId()); |
| | | calculateRule.setParentId(fuNew ? fu1.getId() : fu2.getId()); |
| | | calculateRulesToSave.add(calculateRule); |
| | | } |
| | | // 批量保存规则 |
| | | calculateRuleService.saveBatch(calculateRulesToSave); |
| | | //批量保存考核结果应用规则 |
| | | calculateMoneyRuleService.saveBatch(JSON.parseArray(tContract.getRuleList(), CalculateMoneyRule.class).stream().peek( |
| | | calculateMoneyRule -> calculateMoneyRule.setContractId(tContract.getId().intValue()) |
| | | ).collect(Collectors.toList())); |
| | | return AjaxResult.success("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public List<TContract> selectAll() { |
| | | return list(new LambdaQueryWrapper<TContract>() |
| | | .orderByDesc(TContract::getCreateTime)) |
| | | .stream().peek( |
| | | tContract -> tContract.setUnitName(ywUnitService.getById(tContract.getUnitId()).getUnitName()) |
| | | ).toList(); |
| | | return baseMapper.selectAll(); |
| | | } |
| | | |
| | | @Override |
| | | public List<CalculateMoneyRule> selectMoneyRules(Integer contractId) { |
| | | return calculateMoneyRuleService.selectMoneyRules(contractId); |
| | | } |
| | | |
| | | @Override |
| | | public List<TContract> selectUsingContract() { |
| | | return new LambdaQueryChainWrapper<>(baseMapper) |
| | | .le(TContract::getStartTime, DateUtils.getDate()) |
| | | .ge(TContract::getEndTime, DateUtils.getDate()) |
| | | .list(); |
| | | } |
| | | } |