| | |
| | | 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.handler.CommentWriteHandler; |
| | | import com.ycl.handler.CustomSheetWriteHandler; |
| | | 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.utils.DateUtils; |
| | | import com.ycl.utils.StringUtils; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * @date 2024-03-12 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class TContractServiceImpl extends ServiceImpl<TContractMapper, TContract> implements ITContractService { |
| | | |
| | | private final ICalculateRuleService calculateRuleService; |
| | | private final YwUnitServiceImpl ywUnitService; |
| | | |
| | | @Override |
| | | public void importTemplate(HttpServletResponse response) { |
| | | try { |
| | |
| | | calculateRule4.setCalcFraction(0.1); |
| | | list.add(calculateRule4); |
| | | CalculateRule calculateRule7 = new CalculateRule(); |
| | | calculateRule7.setRuleName("…………"); |
| | | calculateRule7.setRuleDesc("…………"); |
| | | calculateRule7.setRuleCondition("…………"); |
| | | list.add(calculateRule7); |
| | | CalculateRule calculateRule6 = new CalculateRule(); |
| | | calculateRule6.setRuleName("…………"); |
| | | calculateRule6.setRuleDesc("…………"); |
| | | calculateRule6.setRuleCondition("…………"); |
| | | list.add(calculateRule6); |
| | |
| | | list.add(calculateRule5); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void 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(); |
| | | for (CalculateRule calculateRule : list) { |
| | | // 父规则 |
| | | 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.setContractId(tContract.getId().intValue()); |
| | | calculateRule.setCreateTime(DateUtils.getNowDate()); |
| | | calculateRule.setDeleted(0); |
| | | calculateRule.setParentId(temp.getId()); |
| | | calculateRulesToSave.add(calculateRule); |
| | | } |
| | | // 批量保存规则 |
| | | calculateRuleService.saveBatch(calculateRulesToSave); |
| | | } |
| | | |
| | | @Override |
| | | public List<TContract> selectAll() { |
| | | return list(new LambdaQueryWrapper<TContract>() |
| | | .orderByDesc(TContract::getCreateTime)) |
| | | .stream().peek( |
| | | tContract -> tContract.setUnitName(ywUnitService.getById(tContract.getUnitId()).getUnitName()) |
| | | ).toList(); |
| | | } |
| | | } |