| | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.merge.LoopMergeStrategy; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.domain.query.ContractQuery; |
| | | import com.ycl.platform.domain.vo.ContractVO; |
| | | 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.system.Result; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.StringUtils; |
| | | import enumeration.ContractStatus; |
| | | 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.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 |
| | |
| | | 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())) { |
| | |
| | | } |
| | | // 保存父规则获取父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(); |
| | | public Result selectAll(ContractQuery query) { |
| | | IPage<ContractVO> page = PageUtil.getPage(query, ContractVO.class); |
| | | baseMapper.getPage(page, query); |
| | | page.getRecords().stream().forEach(contract -> { |
| | | Date now = new Date(); |
| | | if (now.before(contract.getStartTime())) { |
| | | contract.setStatus(ContractStatus.NOT_START); |
| | | } else if (now.after(contract.getEndTime())) { |
| | | contract.setStatus(ContractStatus.FINISHED); |
| | | } else { |
| | | contract.setStatus(ContractStatus.ACTIVE); |
| | | } |
| | | }); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | @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(); |
| | | } |
| | | } |