| | |
| | | import me.zhengjie.modules.project.service.dto.ProjectDto; |
| | | import me.zhengjie.modules.project.service.impl.ProjectServiceImpl; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.contract.service.ContractService; |
| | | import me.zhengjie.modules.contract.service.mapstruct.ContractMapper; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | |
| | | } |
| | | // 计算下一编号 |
| | | String nextNumber = maxNumber + 1 >= 100 ? "" + (maxNumber + 1) : maxNumber + 1 >= 10 ? "0" + (maxNumber + 1) : "00" + (maxNumber + 1); |
| | | // 合同编号 |
| | | resources.setContractNumber(year + "-" + month + date + "-" + nextNumber); |
| | | // 更新金额相关数据 |
| | | Contract contract = updateAmountData(resources); |
| | | return contractMapper.toDto(contractRepository.save(contract)); |
| | | |
| | | // 保存后再更新合同编号(获取健全信息,防止顺序编号冲突) |
| | | contract = updateContractNumber(contractRepository.save(contract)); |
| | | |
| | | return contractMapper.toDto(contract); |
| | | } |
| | | |
| | | @Override |
| | |
| | | Contract contractOne = updatePaymentStatus(contract); |
| | | // 更新金额相关数据 |
| | | Contract contractTwo = updateAmountData(contractOne); |
| | | contractRepository.save(contractTwo); |
| | | |
| | | updateContractNumber(contractRepository.save(contractTwo)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | /** |
| | | * 更新合同编号(因更新序号需求加锁执行)(本更新为先存其他后改) |
| | | * @param resources |
| | | * @return |
| | | */ |
| | | public synchronized Contract updateContractNumber(Contract resources) { |
| | | StringBuilder contractNumber = new StringBuilder(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | |
| | | if (StringUtils.isNotBlank(resources.getContractNumber())) { |
| | | // 修改编号 |
| | | calendar.setTime(resources.getSignDate()); |
| | | contractNumber.append(resources.getContractNumber().substring(0, 9)); |
| | | |
| | | // 业绩年度 |
| | | String oldSignYear = resources.getContractNumber().substring(9, 11); |
| | | String newSignYear = String.valueOf(calendar.get(Calendar.YEAR)).substring(2); |
| | | // 是否有真实合同 |
| | | String oldTrueContract = resources.getContractNumber().substring(14, 15); |
| | | String newTrueContract = resources.getContractStatus().equals("contract_not_sign") ? "N" : "Y"; |
| | | |
| | | if (oldSignYear.equals(newSignYear)) { |
| | | contractNumber.append(resources.getContractNumber().substring(9, 14)); |
| | | } else { |
| | | String companyCode = resources.getContractNumber().substring(0, 4); |
| | | // 业绩年度(以签订日期为准) |
| | | contractNumber.append(newSignYear); |
| | | // 本公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | Long companySort = contractRepository.countContractSort(String.valueOf(calendar.get(Calendar.YEAR)), companyCode, resources.getContractId()); |
| | | contractNumber.append(String.format("%03d", (companySort == null ? 0L : companySort) + 1)); |
| | | } |
| | | if (oldTrueContract.equals(newTrueContract)) { |
| | | contractNumber.append(resources.getContractNumber().substring(14, 15)); |
| | | } else { |
| | | // 是否有真实合同 |
| | | contractNumber.append(newTrueContract); |
| | | } |
| | | if (oldSignYear.equals(newSignYear)) { |
| | | contractNumber.append(resources.getContractNumber().substring(15)); |
| | | } else { |
| | | // 全部公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | Long allCompanySort = contractRepository.countAllContractSort(String.valueOf(calendar.get(Calendar.YEAR)), resources.getContractId()); |
| | | contractNumber.append(String.format("%04d", (allCompanySort == null ? 0L : allCompanySort) + 1)); |
| | | } |
| | | |
| | | if (resources.getContractNumber().equals(contractNumber.toString())) { |
| | | return resources; |
| | | } else { |
| | | resources.setContractNumber(contractNumber.toString()); |
| | | } |
| | | } else { |
| | | // 新建编号 |
| | | String companyCode; |
| | | String sign; |
| | | |
| | | // 合同前缀 |
| | | String firstName = contractFirstName(resources); |
| | | String SecondName = contractSecondName(resources); |
| | | if (ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstName) != null) { |
| | | companyCode = ElAdminConstant.Enum.CompanySuffix.findByCompanyName(firstName).getCode(); |
| | | sign = "J"; |
| | | contractNumber.append(companyCode); |
| | | } else if (ElAdminConstant.Enum.CompanySuffix.findByCompanyName(SecondName) != null) { |
| | | companyCode = ElAdminConstant.Enum.CompanySuffix.findByCompanyName(SecondName).getCode(); |
| | | sign = "Y"; |
| | | contractNumber.append(companyCode); |
| | | } else { |
| | | return resources; |
| | | } |
| | | // 签订年度(以创建日期为准) |
| | | calendar.setTime(resources.getCreateTime()); |
| | | contractNumber.append(String.valueOf(calendar.get(Calendar.YEAR)).substring(2)); |
| | | // 签订月份(以创建日期为准) |
| | | contractNumber.append(calendar.get(Calendar.MONTH) + 1 >= 10 ? "" + (calendar.get(Calendar.MONTH) + 1) : "0" + (calendar.get(Calendar.MONTH) + 1)); |
| | | // 甲乙标识 |
| | | contractNumber.append(sign); |
| | | // 业绩年度(以签订日期为准) |
| | | calendar.setTime(resources.getSignDate()); |
| | | contractNumber.append(String.valueOf(calendar.get(Calendar.YEAR)).substring(2)); |
| | | // 本公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | Long companySort = contractRepository.countContractSort(String.valueOf(calendar.get(Calendar.YEAR)), companyCode, resources.getContractId()); |
| | | contractNumber.append(String.format("%03d", (companySort == null ? 0L : companySort) + 1)); |
| | | // 是否有真实合同 |
| | | if (resources.getContractStatus().equals("contract_not_sign")) { |
| | | contractNumber.append("N"); |
| | | } else { |
| | | contractNumber.append("Y"); |
| | | } |
| | | // 全部公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | Long allCompanySort = contractRepository.countAllContractSort(String.valueOf(calendar.get(Calendar.YEAR)), resources.getContractId()); |
| | | contractNumber.append(String.format("%04d", (allCompanySort == null ? 0L : allCompanySort) + 1)); |
| | | |
| | | System.out.println("新合同编号:" + contractNumber.toString()); |
| | | resources.setContractNumber(contractNumber.toString()); |
| | | } |
| | | |
| | | return contractRepository.save(resources); |
| | | } |
| | | |
| | | /** |
| | | * 查询合同款总金额 |
| | | * @param criteria |
| | | * @return |