|
@@ -6,8 +6,9 @@ import cn.com.ty.lift.business.contract.dao.entity.ContractsHistory;
|
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.ContractRequest;
|
|
|
import cn.com.ty.lift.business.contract.dao.entity.model.ContractsHistoryRequest;
|
|
|
import cn.com.ty.lift.business.contract.dao.mapper.ContractsMapper;
|
|
|
-import cn.com.ty.lift.business.framework.BusinessBasicException;
|
|
|
import cn.com.ty.lift.business.framework.util.MessageUtils;
|
|
|
+import cn.com.ty.lift.business.project.dao.entity.Project;
|
|
|
+import cn.com.ty.lift.business.project.service.ProjectService;
|
|
|
import cn.com.ty.lift.common.utils.DateUtils;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
@@ -15,8 +16,10 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -26,6 +29,7 @@ import javax.annotation.Resource;
|
|
|
* @description 合同管理业务层
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
|
|
|
@Resource
|
|
@@ -37,6 +41,9 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
@Resource
|
|
|
private PaymentService paymentService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ProjectService projectService;
|
|
|
+
|
|
|
/**
|
|
|
* @param request 合同列表查询条件
|
|
|
* @return RestResponse 合同分页列表结果
|
|
@@ -64,6 +71,23 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
return contractHistoryService.list(request);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param contracts 合同信息
|
|
|
+ * @param extend 项目名称、项目地址、台量
|
|
|
+ * @return 是否成功
|
|
|
+ * @description 保存项目信息
|
|
|
+ * @date 2020/1/14 4:30 下午
|
|
|
+ */
|
|
|
+ public boolean saveProject(Contracts contracts, ContractsExtend extend) {
|
|
|
+ Project project = new Project();
|
|
|
+ project.setProjectName(extend.getProjectName());
|
|
|
+ project.setAddress(extend.getProjectAddress());
|
|
|
+ project.setNum(contracts.getLiftNum());
|
|
|
+ project.setStartDate(contracts.getStarDate());
|
|
|
+ project.setEndDate(contracts.getEndDate());
|
|
|
+ return projectService.saveProject(project);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param extend 新增合同数据项
|
|
|
* @return 1.成功, 0.失败, 消息描述
|
|
@@ -79,27 +103,61 @@ public class ContractService extends ServiceImpl<ContractsMapper, Contracts> {
|
|
|
contracts.setNextId(contractId);
|
|
|
}
|
|
|
contracts.setNextId(contracts.getCode());
|
|
|
+ //插入合同信息
|
|
|
int result = contractsMapper.insert(contracts);
|
|
|
- if (result > 0) {
|
|
|
- //批量插入收款信息
|
|
|
- boolean ret = paymentService.insertBatch(extend.getPaymentList(), contracts.getNextId());
|
|
|
- if (ret) {
|
|
|
- return RestResponse.success(null, MessageUtils.get("msg.add.success"));
|
|
|
- } else {
|
|
|
- throw new BusinessBasicException("批量插入收款信息失败");
|
|
|
- }
|
|
|
+ if (result < 0) {
|
|
|
+ //强制手动事务回滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
|
+ }
|
|
|
+ //插入项目信息
|
|
|
+ boolean info = saveProject(contracts, extend);
|
|
|
+ if (!info) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
|
}
|
|
|
- return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
|
+ //批量插入收款信息
|
|
|
+ boolean ret = paymentService.insertBatch(extend.getPaymentList(), contracts.getNextId());
|
|
|
+ if (!ret) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.add.batch.fail"));
|
|
|
+ }
|
|
|
+ return RestResponse.success(null, MessageUtils.get("msg.add.success"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param contracts 修改合同数据项
|
|
|
+ * @param extend 修改合同、项目、付款信息数据项
|
|
|
* @return 1.成功, 0.失败, 消息描述
|
|
|
* @description 合同变更
|
|
|
* @date 2019/12/7 3:31 PM
|
|
|
*/
|
|
|
- public int modify(Contracts contracts) {
|
|
|
- return contractsMapper.updateById(contracts);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public RestResponse modify(ContractsExtend extend) {
|
|
|
+ Contracts contracts = extend.getContracts();
|
|
|
+ //修改合同信息
|
|
|
+ boolean contractResult = updateById(contracts);
|
|
|
+ if (!contractResult) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
+ }
|
|
|
+ //修改项目信息
|
|
|
+ Project project = new Project();
|
|
|
+ project.setId(contracts.getProjectId());
|
|
|
+ project.setProjectName(extend.getProjectName());
|
|
|
+ project.setAddress(extend.getProjectAddress());
|
|
|
+ project.setNum(contracts.getLiftNum());
|
|
|
+ boolean projectResult = projectService.modify(project);
|
|
|
+ if (!projectResult) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
+ }
|
|
|
+ //修改付款信息
|
|
|
+ boolean paymentResult = paymentService.modifyBatchById(extend.getPaymentList());
|
|
|
+ if (!paymentResult) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
|
|
|
+ }
|
|
|
+ return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
|
|
|
}
|
|
|
|
|
|
/**
|