| | |
| | | import com.alibaba.excel.read.listener.PageReadListener; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult importRule(MultipartFile file, TContract tContract) throws IOException { |
| | | |
| | | // 获取合同Excel规则 |
| | | List<CalculateRule> list = new ArrayList<>(); |
| | | if(file!=null) { |
| | | EasyExcel.read(file.getInputStream(), CalculateRule.class, new PageReadListener<CalculateRule>(list::addAll)).sheet().doRead(); |
| | | |
| | | // 遍历父子关系 |
| | | List<CalculateRule> calculateRulesToSave = new ArrayList<>(); |
| | | 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() + "扣分数值"); |
| | | } |
| | | // 保存规则 |
| | | if (StringUtils.isNotBlank(calculateRule.getRuleName())) { |
| | | calculateRule.setContractId(tContract.getId().intValue()); |
| | | calculateRule.setCreateTime(DateUtils.getNowDate()); |
| | | calculateRule.setUpdateTime(DateUtils.getNowDate()); |
| | | calculateRulesToSave.add(calculateRule); |
| | | } |
| | | } |
| | | if (!CollectionUtils.isEmpty(calculateRulesToSave)) { |
| | | //删除原规则 |
| | | calculateRuleService.remove(new QueryWrapper<CalculateRule>().eq("contract_id", tContract.getId())); |
| | | // 批量保存规则 |
| | | calculateRuleService.saveBatch(calculateRulesToSave); |
| | | } |
| | | } |
| | | List<CalculateMoneyRule> moneyRule = JSON.parseArray(tContract.getRuleList(), CalculateMoneyRule.class).stream().peek( |
| | | calculateMoneyRule -> calculateMoneyRule.setContractId(tContract.getId().intValue()) |
| | | ).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(moneyRule)) { |
| | | //删除原规则 |
| | | calculateMoneyRuleService.remove(new QueryWrapper<CalculateMoneyRule>().eq("contract_id",tContract.getId())); |
| | | //批量保存考核结果应用规则 |
| | | calculateMoneyRuleService.saveBatch(moneyRule); |
| | | } |
| | | return AjaxResult.success("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result selectAll(ContractQuery query) { |
| | | IPage<ContractVO> page = PageUtil.getPage(query, ContractVO.class); |
| | | query.setUnitId(SecurityUtils.getUnitId()); |