|
@@ -56,6 +56,7 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
* @date 2019/12/7 11:53 AM
|
|
|
*/
|
|
|
public IPage<ContractResponse> list(ContractRequest request) {
|
|
|
+ request.addDesc("end_date");
|
|
|
return contractsMapper.findByCondition(request.getPage(), request);
|
|
|
}
|
|
|
|
|
@@ -113,20 +114,76 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
return RestResponse.success(null, MessageUtils.get("msg.add.success"));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param request 续签合同数据项
|
|
|
+ * @return 1.成功, 0.失败, 消息描述
|
|
|
+ * @description 续签合同
|
|
|
+ * @date 2020/5/3 10:48 上午
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public RestResponse renew(ContractRequest request) {
|
|
|
+ Contracts contracts = request.getContracts();
|
|
|
+ //查询原有合同是否存在
|
|
|
+ Long contractId = request.getContractId();
|
|
|
+ Contracts oldContract = getOne(contractId);
|
|
|
+ if (Objects.isNull(oldContract))
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.contract.not.exist"));
|
|
|
+ if (ObjectUtil.isEmpty(contracts.getCode())) {
|
|
|
+ //按当前日期时间戳自动生成合同编号
|
|
|
+ String contractCode = DateUtils.generateCode();
|
|
|
+ contracts.setCode("HT" + contractCode);
|
|
|
+ }
|
|
|
+ contracts.setProjectId(request.getProjectId());
|
|
|
+ List<Payment> paymentList = request.getPaymentList();
|
|
|
+ if (CollUtil.isNotEmpty(paymentList)) {
|
|
|
+ //应收金额总计
|
|
|
+ BigDecimal planMoneyTotal = paymentList.stream().map(Payment::getPlanMoney).reduce(ZERO, BigDecimal::add);
|
|
|
+ contracts.setPlanMoneyTotal(planMoneyTotal);
|
|
|
+ //实收金额总计
|
|
|
+ BigDecimal workMoneyTotal = paymentList.stream().map(Payment::getWorkMoney).reduce(ZERO, BigDecimal::add);
|
|
|
+ contracts.setWorkMoneyTotal(workMoneyTotal);
|
|
|
+ //开票金额总计
|
|
|
+ BigDecimal invoiceTotal = paymentList.stream().map(Payment::getAmountInvoice).reduce(ZERO, BigDecimal::add);
|
|
|
+ contracts.setInvoiceMoneyTotal(invoiceTotal);
|
|
|
+ }
|
|
|
+ //插入新合同信息
|
|
|
+ boolean result = save(contracts);
|
|
|
+ if (!result)
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
|
+
|
|
|
+ //修改原有合同
|
|
|
+ oldContract.setNextId(contracts.getId());
|
|
|
+ boolean ret = updateById(oldContract);
|
|
|
+ if (!ret) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
|
+ }
|
|
|
+ //查询原有付款列表
|
|
|
+ List<Payment> oldPaymentList = paymentService.paymentList(contractId);
|
|
|
+ paymentList.forEach(entry -> {
|
|
|
+ entry.setContractsId(contracts.getId());
|
|
|
+ entry.setCode("PA" + DateUtils.generateCode());
|
|
|
+ entry.setType(contracts.getType());
|
|
|
+ });
|
|
|
+ //修改或删除付款列表
|
|
|
+ return paymentService.modifyPayment(oldPaymentList, paymentList);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param request 合同复核
|
|
|
* @return 1.成功, 0.失败, 消息描述
|
|
|
* @description 合同复核
|
|
|
* @date 2020/2/11 12:55 下午
|
|
|
*/
|
|
|
- public boolean check(ContractRequest request) {
|
|
|
- Optional<Contracts> optional = getOne(request.getId());
|
|
|
- if (optional.isPresent()) {
|
|
|
- Contracts contracts = optional.get();
|
|
|
- contracts.setIsCheck(1);
|
|
|
- return updateById(contracts);
|
|
|
- }
|
|
|
- return false;
|
|
|
+ public RestResponse check(ContractRequest request) {
|
|
|
+ Contracts contracts = getOne(request.getId());
|
|
|
+ if (Objects.isNull(contracts))
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.contract.not.exist"));
|
|
|
+ contracts.setIsCheck(1);
|
|
|
+ boolean result = updateById(contracts);
|
|
|
+ if (!result)
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
+ return RestResponse.success(MessageUtils.get("msg.modify.success"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -135,11 +192,11 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
* @description 查询合同
|
|
|
* @date 2019/12/20 11:04 AM
|
|
|
*/
|
|
|
- public Optional<Contracts> getOne(Long id) {
|
|
|
+ public Contracts getOne(Long id) {
|
|
|
QueryWrapper<Contracts> queryWrapper = new QueryWrapper<>();
|
|
|
LambdaQueryWrapper<Contracts> lambdaQueryWrapper = queryWrapper.lambda();
|
|
|
lambdaQueryWrapper.eq(Contracts::getId, id);
|
|
|
- return Optional.ofNullable(getOne(lambdaQueryWrapper));
|
|
|
+ return getOne(lambdaQueryWrapper);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -151,8 +208,9 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public RestResponse modify(ContractRequest request) {
|
|
|
Contracts contracts = request.getContracts();
|
|
|
- Optional<Contracts> oldContract = getOne(contracts.getId());
|
|
|
- if (!oldContract.isPresent())
|
|
|
+ Long contractId = contracts.getId();
|
|
|
+ Contracts oldContract = getOne(contractId);
|
|
|
+ if (Objects.isNull(oldContract))
|
|
|
return RestResponse.fail(MessageUtils.get("msg.contract.not.exist"));
|
|
|
//修改合同信息
|
|
|
contracts.setIsCheck(0);
|
|
@@ -171,9 +229,8 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
if (!contractResult)
|
|
|
return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
|
|
|
- Contracts entry = oldContract.get();
|
|
|
//生成合同操作记录
|
|
|
- ContractsHistory history = contractHistoryService.createOperaHistory(entry, contracts);
|
|
|
+ ContractsHistory history = contractHistoryService.createOperaHistory(oldContract, contracts);
|
|
|
if (Objects.nonNull(history)) {
|
|
|
//保存合同操作记录
|
|
|
boolean historyResult = contractHistoryService.save(history);
|
|
@@ -182,23 +239,16 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (CollUtil.isNotEmpty(paymentList)) {
|
|
|
- //修改付款信息
|
|
|
- boolean paymentResult = paymentService.modifyBatchById(paymentList);
|
|
|
- if (!paymentResult) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
- }
|
|
|
- } else {
|
|
|
- //批量插入收款信息
|
|
|
- boolean ret = paymentService.insertBatch(paymentList, contracts);
|
|
|
- if (!ret) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return RestResponse.fail(MessageUtils.get("msg.add.batch.fail"));
|
|
|
- }
|
|
|
- }
|
|
|
- return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
|
|
|
+ //查询原有付款列表
|
|
|
+ List<Payment> oldPaymentList = paymentService.paymentList(contractId);
|
|
|
+ //设置合同付款的合同id
|
|
|
+ paymentList.forEach(entry -> {
|
|
|
+ entry.setContractsId(contracts.getId());
|
|
|
+ entry.setCode("PA" + DateUtils.generateCode());
|
|
|
+ entry.setType(contracts.getType());
|
|
|
+ });
|
|
|
+ //修改或删除付款列表
|
|
|
+ return paymentService.modifyPayment(oldPaymentList, paymentList);
|
|
|
}
|
|
|
|
|
|
/**
|