|
@@ -1,6 +1,8 @@
|
|
|
package com.fjhx.purchase.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.fjhx.activiti.ProcessTaskReferBuilder;
|
|
|
import com.fjhx.activiti.ProcessTaskResult;
|
|
|
import com.fjhx.activiti.SubmitFlowCondition;
|
|
@@ -16,27 +18,18 @@ import com.fjhx.message.constant.MessageNoticeConstant;
|
|
|
import com.fjhx.message.enums.MessageNoticeEnum;
|
|
|
import com.fjhx.message.service.IMessageNoticeService;
|
|
|
import com.fjhx.purchase.constant.PurchaseContractConstant;
|
|
|
-import com.fjhx.purchase.entity.PurchaseContract;
|
|
|
-import com.fjhx.purchase.entity.PurchaseContractChange;
|
|
|
-import com.fjhx.purchase.entity.PurchaseContractProduct;
|
|
|
-import com.fjhx.purchase.entity.PurchaseContractProductChange;
|
|
|
-import com.fjhx.purchase.entity.PurchaseContractProject;
|
|
|
-import com.fjhx.purchase.entity.PurchaseContractProjectChange;
|
|
|
+import com.fjhx.purchase.entity.*;
|
|
|
import com.fjhx.purchase.enums.PurchaseCycleEnum;
|
|
|
import com.fjhx.purchase.enums.PurchaseStatusEnum;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractChangeFlowService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractChangeService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractPdfService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractProductChangeService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractProductService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractProjectChangeService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractProjectService;
|
|
|
-import com.fjhx.purchase.service.IPurchaseContractService;
|
|
|
+import com.fjhx.purchase.service.*;
|
|
|
import com.fjhx.shipmentdetailed.entity.ShipmentDetailed;
|
|
|
import com.fjhx.shipmentdetailed.entity.ShipmentDetailedChange;
|
|
|
import com.fjhx.shipmentdetailed.service.IShipmentDetailedChangeService;
|
|
|
import com.fjhx.shipmentdetailed.service.IShipmentDetailedService;
|
|
|
import com.fjhx.utils.CodeRuleUtil;
|
|
|
+import com.fjhx.utils.ExampleAbstract;
|
|
|
+import com.fjhx.utils.ExampleResult;
|
|
|
+import com.fjhx.utils.FlowConstructor;
|
|
|
import com.fjhx.wms.due.entity.Due;
|
|
|
import com.fjhx.wms.due.enums.DuePaymentItemsEnum;
|
|
|
import com.fjhx.wms.warehouse.IWmsDueApi;
|
|
@@ -63,13 +56,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -485,10 +472,319 @@ public class PurchaseContractChangeFlowServiceImpl implements IPurchaseContractC
|
|
|
|
|
|
// 删除
|
|
|
// iPurchaseContractService.removeById(condition.getId());
|
|
|
- //修改状态999
|
|
|
+ // 修改状态999
|
|
|
iPurchaseContractService.updateStatusById(Arrays.asList(condition.getId()), PurchaseStatusEnum.INVALID.getKey());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化流程
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FlowConstructor flowConstructor() {
|
|
|
+ return FlowConstructor.init(
|
|
|
+ new ExampleAbstract() {
|
|
|
+ @Override
|
|
|
+ public String getCode() {
|
|
|
+ return MessageNoticeEnum.MESSAGE_NOTICE_TYPE_20.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结束
|
|
|
+ * @param flowLinkNo 流程关联编码
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ @Override
|
|
|
+ public void end(String flowLinkNo) {
|
|
|
+
|
|
|
+ String id = getCacheData(String.class);
|
|
|
+
|
|
|
+ // 查询采购合同信息
|
|
|
+ QueryWrapper<PurchaseContract> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda().eq(PurchaseContract::getId, id).or().eq(PurchaseContract::getProcessInstanceId, id);
|
|
|
+ PurchaseContract purchaseContract = iPurchaseContractService.getOne(wrapper);
|
|
|
+ if (Func.isEmpty(purchaseContract)) {
|
|
|
+ throw new ServiceException("采购合同不存在");
|
|
|
+ } else if (purchaseContract.getPurchaseStatus() == PurchaseStatusEnum.INVALID.getKey()) {
|
|
|
+ throw new ServiceException("采购合同已作废");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 采购状态:采购中
|
|
|
+ PurchaseContract update = new PurchaseContract();
|
|
|
+ update.setId(purchaseContract.getId());
|
|
|
+ update.setPurchaseStatus(PurchaseStatusEnum.IN_PROCUREMENT.getKey());
|
|
|
+ iPurchaseContractService.updateById(update);
|
|
|
+
|
|
|
+ // 修改合同表状态,合同状态:采购中
|
|
|
+ // 合同ID
|
|
|
+ String contractId = purchaseContract.getContractId();
|
|
|
+ String[] contractIds = StringUtils.split(contractId, ",");
|
|
|
+ if (ArrayUtils.isNotEmpty(contractIds)) {
|
|
|
+ iContractService.updateStatusById(Arrays.stream(contractIds).collect(Collectors.toList()), ContractStatusEnum.PURCHASE.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加账单数据
|
|
|
+ if (ObjectUtil.isNotEmpty(purchaseContract.getPaymentCycleType())) {
|
|
|
+ Due due = new Due();
|
|
|
+ due.setId(IdUtils.fastSimpleUUID());
|
|
|
+ due.setPurchaseContractId(purchaseContract.getId());
|
|
|
+ if (purchaseContract.getPaymentCycleType() == PurchaseCycleEnum.FULL_PREPAYMENT.getKey()) {
|
|
|
+ // 添加一条全款预付得账单数据
|
|
|
+ String promptDate = DateUtil.dateAddASub(purchaseContract.getCreateTime(), purchaseContract.getPaymentCyclePrescribe());
|
|
|
+ due.setPromptDate(promptDate);
|
|
|
+ due.setDueMoney(purchaseContract.getPurchasePrice());
|
|
|
+ due.setPaymentItemsType(DuePaymentItemsEnum.FULL_PREPAYMENT.getKey());
|
|
|
+ } else if (purchaseContract.getPaymentCycleType() == PurchaseCycleEnum.BALANCE_PAYMENT.getKey()) {
|
|
|
+ // 添加一条账期尾款数据
|
|
|
+ due.setPaymentItemsType(DuePaymentItemsEnum.BALANCE_PAYMENT.getKey());
|
|
|
+ due.setDueMoney(purchaseContract.getPurchasePrice().subtract(purchaseContract.getPaymentFull()));
|
|
|
+ } else if (purchaseContract.getPaymentCycleType() == PurchaseCycleEnum.TOP_PERIOD.getKey()) {
|
|
|
+ // 添加一条小账期款数据
|
|
|
+ String promptDate = DateUtil.dateAddASub(purchaseContract.getCreateTime(), purchaseContract.getPaymentDays());
|
|
|
+ due.setPromptDate(promptDate);
|
|
|
+ due.setPaymentItemsType(DuePaymentItemsEnum.TOP_PERIOD.getKey());
|
|
|
+ due.setDueMoney(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ iWmsDueApi.saveDue(due);
|
|
|
+ if (purchaseContract.getPaymentFull().compareTo(BigDecimal.ZERO) == 1 &&
|
|
|
+ purchaseContract.getPaymentCycleType() != PurchaseCycleEnum.FULL_PREPAYMENT.getKey()) {
|
|
|
+ String promptDate = DateUtil.dateAddASub(purchaseContract.getCreateTime(), purchaseContract.getPaymentCyclePrescribe());
|
|
|
+ // 添加一条预付款得账单数据
|
|
|
+ due.setId(IdUtils.fastSimpleUUID());
|
|
|
+ due.setPromptDate(promptDate);
|
|
|
+ due.setPaymentItemsType(DuePaymentItemsEnum.ADVANCE.getKey());
|
|
|
+ due.setDueMoney(purchaseContract.getPaymentFull());
|
|
|
+ iWmsDueApi.saveDue(due);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 添加日志
|
|
|
+ iContractTrackLogService.addLog(purchaseContract.getContractId(), ContractTrackTypeEnum.PURCHASE.getKey(), ContractTrackLogConstant.Status.END, new Date());
|
|
|
+ iContractTrackLogService.addLog(purchaseContract.getContractId(), ContractTrackTypeEnum.PRODUCTION.getKey(), ContractTrackLogConstant.Status.SEND, new Date());
|
|
|
+
|
|
|
+ // 生成采购合同PDF
|
|
|
+ purchaseContractPdfService.generate(purchaseContract.getId());
|
|
|
+ // 发送消息通知
|
|
|
+ sendMessageNotice(purchaseContract);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除流程
|
|
|
+ *
|
|
|
+ * @param flowLinkNo 流程关联编码
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ @Override
|
|
|
+ public boolean deleteLogic(String flowLinkNo) {
|
|
|
+ String id = getCacheData(String.class);
|
|
|
+
|
|
|
+ iWmsDueApi.deleteDue(id);
|
|
|
+
|
|
|
+ // 删除
|
|
|
+ // iPurchaseContractService.removeById(condition.getId());
|
|
|
+ // 修改状态999
|
|
|
+ iPurchaseContractService.updateStatusById(Collections.singletonList(id), PurchaseStatusEnum.INVALID.getKey());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void startV2(PurchaseContract contract) {
|
|
|
+ // 获取分布式锁key
|
|
|
+ String lockKey = CodeRuleUtil.getLockKey(AuthUtil.getTenantId(), CodeRuleTypeEnum.CODE_RULE_TYPE_4.getKey());
|
|
|
+ RLock lock = redisLockClient.lockFair(lockKey, 0, -1L);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 加锁,阻塞
|
|
|
+ lock.lock();
|
|
|
+
|
|
|
+ // 获取当前的租户id
|
|
|
+ String tenantId = AuthUtil.getTenantId();
|
|
|
+ if (StringUtils.isBlank(tenantId)) {
|
|
|
+ throw new ServiceException("获取不到当前租户");
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (StringUtils.isBlank(contract.getId())) {
|
|
|
+ // // 此处设为null,是防止复制采购合同时把复制对象的值携带过来
|
|
|
+ // contract.setProcessInstanceId(null);
|
|
|
+ // contract.setProcessInstanceName(null);
|
|
|
+ // contract.setProcessInstanceUserId(null);
|
|
|
+ // contract.setProcessInstanceUserName(null);
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ // try {
|
|
|
+ // 查询采购合同旧数据
|
|
|
+ PurchaseContract oldContract = iPurchaseContractService.getById(contract.getId());
|
|
|
+ if (Func.isEmpty(oldContract)) {
|
|
|
+ throw new ServiceException("采购信息不存在!!!");
|
|
|
+ }
|
|
|
+ PurchaseContractChange contractChange = new PurchaseContractChange();
|
|
|
+ BeanUtils.copyProperties(oldContract, contractChange);
|
|
|
+ contractChange.setId(IdUtils.fastSimpleUUID());
|
|
|
+ contractChange.setOldId(oldContract.getId());
|
|
|
+ // 保存采购变更历史记录
|
|
|
+ iPurchaseContractChangeService.save(contractChange);
|
|
|
+
|
|
|
+ // 新、旧采购产品ID关联map
|
|
|
+ Map<String, String> newAndOldIdMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 查询采购产品旧数据
|
|
|
+ List<PurchaseContractProduct> products = iPurchaseContractProductService.lambdaQuery().eq(PurchaseContractProduct::getPurchaseContractId, contract.getId()).list();
|
|
|
+ if (CollectionUtils.isNotEmpty(products)) {
|
|
|
+ List<PurchaseContractProductChange> productChanges = new ArrayList<>();
|
|
|
+ for (PurchaseContractProduct product : products) {
|
|
|
+ PurchaseContractProductChange productChange = new PurchaseContractProductChange();
|
|
|
+ BeanUtils.copyProperties(product, productChange);
|
|
|
+ productChange.setId(IdUtils.fastSimpleUUID());
|
|
|
+ productChange.setOldId(product.getId());
|
|
|
+ productChange.setPurchaseContractId(contractChange.getId());
|
|
|
+ // 记录新旧采购产品ID
|
|
|
+ newAndOldIdMap.put(productChange.getOldId(), productChange.getId());
|
|
|
+ // 配件辅材父类ID替换成新父类ID
|
|
|
+ if (StringUtils.isNotBlank(product.getParentId()) && !StringUtils.equals(product.getParentId(), "0")) {
|
|
|
+ productChange.setParentId(newAndOldIdMap.get(product.getParentId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ productChanges.add(productChange);
|
|
|
+ }
|
|
|
+ // 保存采购产品变更历史记录
|
|
|
+ iPurchaseContractProductChangeService.saveBatch(productChanges);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询采购收费项目旧数据
|
|
|
+ List<PurchaseContractProject> projects = iPurchaseContractProjectService.lambdaQuery().eq(PurchaseContractProject::getPurchaseContractId, contract.getId()).list();
|
|
|
+ if (CollectionUtils.isNotEmpty(projects)) {
|
|
|
+ List<PurchaseContractProjectChange> projectChanges = new ArrayList<>();
|
|
|
+ for (PurchaseContractProject project : projects) {
|
|
|
+ PurchaseContractProjectChange projectChange = new PurchaseContractProjectChange();
|
|
|
+ BeanUtils.copyProperties(project, projectChange);
|
|
|
+ projectChange.setId(IdUtils.fastSimpleUUID());
|
|
|
+ projectChange.setOldId(project.getId());
|
|
|
+ projectChange.setPurchaseContractId(contractChange.getId());
|
|
|
+ projectChanges.add(projectChange);
|
|
|
+ }
|
|
|
+ // 保存采购收费项目变更历史记录
|
|
|
+ iPurchaseContractProjectChangeService.saveBatch(projectChanges);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询采购出货明细旧数据
|
|
|
+ List<ShipmentDetailed> detaileds = iShipmentDetailedService.lambdaQuery().eq(ShipmentDetailed::getBusinessId, contract.getId()).list();
|
|
|
+ if (CollectionUtils.isNotEmpty(detaileds)) {
|
|
|
+ List<ShipmentDetailedChange> detailedChanges = new ArrayList<>();
|
|
|
+ for (ShipmentDetailed detailed : detaileds) {
|
|
|
+ ShipmentDetailedChange detailedChange = new ShipmentDetailedChange();
|
|
|
+ BeanUtils.copyProperties(detailed, detailedChange);
|
|
|
+ detailedChange.setId(IdUtils.fastSimpleUUID());
|
|
|
+ detailedChange.setOldId(detailed.getId());
|
|
|
+ detailedChange.setBusinessId(contractChange.getId());
|
|
|
+ // 赋值新采购合同产品ID
|
|
|
+ detailedChange.setProductId(newAndOldIdMap.get(detailed.getProductId()));
|
|
|
+ detailedChanges.add(detailedChange);
|
|
|
+ }
|
|
|
+ // 保存采购出货明细变更历史记录
|
|
|
+ iShipmentDetailedChangeService.saveBatch(detailedChanges);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 状态:审批中
|
|
|
+ contract.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
+ // 版本号+1
|
|
|
+ contract.setVersion(contract.getVersion() + 1);
|
|
|
+ // 存在变更数据(表示该条合同被发起变更)
|
|
|
+ contract.setIsChange(PurchaseContractConstant.IsChange.EXIST_CHANGE);
|
|
|
+ // 数据来源:变更新增
|
|
|
+ contract.setSource(PurchaseContractConstant.Source.PURCHASE_CHANGE);
|
|
|
+
|
|
|
+ // 设置流程字段
|
|
|
+ // contract.setProcessInstanceId(processTaskResult.getProcessInstanceId());
|
|
|
+ // contract.setProcessInstanceName(processTaskResult.getName());
|
|
|
+ // contract.setProcessInstanceUserId(processTaskResult.getAssignee());
|
|
|
+ // contract.setProcessInstanceUserName(processTaskResult.getAssigneeName());
|
|
|
+
|
|
|
+ // 更新数据
|
|
|
+ iPurchaseContractService.saveOrUpdate(contract);
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // //手动处理事务回滚
|
|
|
+ // // activitiApi.deleteFlow(contract.getProcessInstanceId());
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // throw e;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 添加日志
|
|
|
+ Date startTime = Optional.ofNullable(contract.getStartTime()).orElse(new Date());
|
|
|
+ iContractTrackLogService.addLog(contract.getContractId(), ContractTrackTypeEnum.PURCHASE.getKey(), ContractTrackLogConstant.Status.SEND, startTime);
|
|
|
+
|
|
|
+ // 启动流程
|
|
|
+ // ProcessTaskResult processTaskResult = startUpFlow(contract);
|
|
|
+
|
|
|
+ String title = AuthUtil.getUserName() + " 在" + LocalDate.now() + "日发起了 采购变更审批流程(单号" + contract.getCode() + ")";
|
|
|
+ flowConstructor().create(contract.getId(), title, contract.getFlowRemark(), contract.getId());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ // 解锁
|
|
|
+ lock.unlock();
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void examineV2(SubmitFlowCondition condition) {
|
|
|
+
|
|
|
+ if (StringUtils.isAnyBlank(condition.getId(), condition.getProcessInstanceId())) {
|
|
|
+ throw new ServiceException("参数缺失");
|
|
|
+ }
|
|
|
+ // 查询采购合同信息
|
|
|
+ QueryWrapper<PurchaseContract> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda().eq(PurchaseContract::getId, condition.getId()).or().eq(PurchaseContract::getProcessInstanceId, condition.getId());
|
|
|
+ PurchaseContract purchaseContract = iPurchaseContractService.getOne(wrapper);
|
|
|
+ if (Func.isEmpty(purchaseContract)) {
|
|
|
+ throw new ServiceException("采购合同不存在");
|
|
|
+ } else if (purchaseContract.getPurchaseStatus() == PurchaseStatusEnum.INVALID.getKey()) {
|
|
|
+ throw new ServiceException("采购合同已作废");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //审批操作
|
|
|
+ ExampleResult exampleResult = flowConstructor().jump(condition.getId(), condition.getButtonId(), condition.getFlowRemark());
|
|
|
+ // exampleResult.after(() -> {
|
|
|
+ // //获取下一节点处理人信息
|
|
|
+ // JSONObject nextNodeHandleUserInfo = new JSONObject();
|
|
|
+ // getNextNodeHandleUserInfo(exampleResult, nextNodeHandleUserInfo);
|
|
|
+ //
|
|
|
+ // //设置流程字段
|
|
|
+ // UpdateWrapper<Contract> wrapper = new UpdateWrapper<>();
|
|
|
+ // wrapper.lambda().set(Contract::getProcessInstanceId, nextNodeHandleUserInfo.getString("processInstanceId"));
|
|
|
+ // wrapper.lambda().set(Contract::getProcessInstanceUserId, nextNodeHandleUserInfo.getString("processInstanceUserId"));
|
|
|
+ // wrapper.lambda().set(Contract::getProcessInstanceUserName, nextNodeHandleUserInfo.getString("processInstanceUserName"));
|
|
|
+ // wrapper.lambda().eq(Contract::getId, entity.getId());
|
|
|
+ //
|
|
|
+ // //修改外销合同表
|
|
|
+ // contractService.update(wrapper);
|
|
|
+ // });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteV2(Contract entity) {
|
|
|
+ //旧审批数据做伪删除,并同时处理业务数据
|
|
|
+ flowConstructor().deleteLogic(entity.getProcessInstanceId(), entity.getId());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送消息通知
|
|
|
*
|