|
@@ -7,6 +7,7 @@ import com.fjhx.common.entity.InOutBo;
|
|
|
import com.fjhx.common.enums.FlowStatusEnum1;
|
|
|
import com.fjhx.common.enums.InOutType;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
+import com.fjhx.common.utils.Utils;
|
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
@@ -14,35 +15,26 @@ import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
|
|
|
import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
|
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
|
|
|
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseArrival;
|
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
|
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
|
|
|
-import com.fjhx.sale.service.contract.ContractProductService;
|
|
|
-import com.fjhx.sale.service.purchase.EhsdPurchaseArrivalService;
|
|
|
import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
|
|
|
import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
|
|
|
import com.fjhx.sale.service.purchase.EhsdPurchaseService;
|
|
|
-import com.fjhx.sale.service.sample.SampleProductService;
|
|
|
-import com.ruoyi.common.annotation.LogicIgnore;
|
|
|
import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
- * EHSD采购变更流程
|
|
|
+ * 采购变更流程
|
|
|
*/
|
|
|
@Component
|
|
|
-//@DS(SourceConstant.SALE)
|
|
|
public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
@Autowired
|
|
|
private EhsdPurchaseService ehsdPurchaseService;
|
|
@@ -53,12 +45,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
@Autowired
|
|
|
private EhsdPurchaseProjectService ehsdPurchaseProjectService;
|
|
|
@Autowired
|
|
|
- private EhsdPurchaseArrivalService ehsdPurchaseArrivalService;
|
|
|
- @Autowired
|
|
|
- private ContractProductService contractProductService;
|
|
|
- @Autowired
|
|
|
- private SampleProductService sampleProductService;
|
|
|
- @Autowired
|
|
|
private ProductInfoService productInfoService;
|
|
|
|
|
|
@Override
|
|
@@ -72,53 +58,35 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
@Override
|
|
|
public Long start(Long flowId, JSONObject submitData) {
|
|
|
EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
- Assert.notEmpty(purchase.getId(), "采购合同id不能为空");
|
|
|
|
|
|
- //判断合同是否在变更中,防止用户缓存导致重复变更
|
|
|
- EhsdPurchase byId = ehsdPurchaseService.getById(purchase.getId());
|
|
|
- Assert.notEmpty(byId, "查询不到采购信息");
|
|
|
- if (byId.getStatus().equals(FlowStatusEnum1.UPDATE_LOADING.getKey())) {
|
|
|
- throw new ServiceException("合同正在变更中,禁止重复变更!");
|
|
|
- }
|
|
|
-
|
|
|
- //赋值原合同id
|
|
|
- purchase.setOldPurchaseId(purchase.getId());
|
|
|
+ //清理Id防止前端误传
|
|
|
+ purchase.setId(null);
|
|
|
|
|
|
//赋值流程id
|
|
|
purchase.setFlowId(flowId);
|
|
|
|
|
|
- //变更 用原来合同号加后缀
|
|
|
- EhsdPurchase oldPurchase = ehsdPurchaseService.getById(purchase.getOldPurchaseId());
|
|
|
- Assert.notEmpty(oldPurchase, "查询不到原合同信息");
|
|
|
- //原合同修改为变更中
|
|
|
- oldPurchase.setStatus(FlowStatusEnum1.UPDATE_LOADING.getKey());
|
|
|
- ehsdPurchaseService.updateById(oldPurchase);
|
|
|
+ Long oldPurchaseId = purchase.getOldPurchaseId();
|
|
|
+ Assert.notEmpty(oldPurchaseId, "原采购订单id不能为空");
|
|
|
|
|
|
- String code = oldPurchase.getCode();
|
|
|
- Matcher matcher = Pattern.compile(".*\\((.*?)\\)$").matcher(code);
|
|
|
- int index = 2;
|
|
|
- if (matcher.find()) {
|
|
|
- index = (Integer.parseInt(matcher.group(1)) + 1);
|
|
|
- code = code.substring(0, code.lastIndexOf("("));
|
|
|
+ //判断合同是否在变更中,防止用户缓存导致重复变更
|
|
|
+ EhsdPurchase oldPurchase = ehsdPurchaseService.getById(oldPurchaseId);
|
|
|
+ Assert.notEmpty(oldPurchase, "查询不到原采购订单信息");
|
|
|
+ if (oldPurchase.getStatus().equals(FlowStatusEnum1.UPDATE_LOADING.getKey())) {
|
|
|
+ throw new ServiceException("原采购订单正在变更中,禁止重复变更!");
|
|
|
}
|
|
|
- purchase.setCode(code + "(" + index + ")");
|
|
|
+
|
|
|
+ //原采购订单修改为变更中
|
|
|
+ ehsdPurchaseService.update(q -> q.eq(EhsdPurchase::getId, oldPurchaseId).set(EhsdPurchase::getStatus, FlowStatusEnum1.UPDATE_LOADING.getKey()));
|
|
|
+
|
|
|
+ //赋值新单号
|
|
|
+ purchase.setCode(Utils.getNewCode(oldPurchase.getCode()));
|
|
|
|
|
|
//获取明细信息
|
|
|
List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
|
List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
|
- List<EhsdPurchaseArrival> purchaseArrivalList = purchase.getPurchaseArrivalList();
|
|
|
-
|
|
|
- //清空采购合同的id
|
|
|
- purchase.setId(null);
|
|
|
- //清空采购明细的id 以及 配件id 方便后面重新发起
|
|
|
- for (EhsdPurchaseProduct ehsdPurchaseProduct : purchaseProductList) {
|
|
|
- ehsdPurchaseProduct.setId(null);
|
|
|
- ehsdPurchaseProduct.getPurchaseProductMountingsList().forEach(item -> item.setId(null));
|
|
|
- }
|
|
|
- //清空其他费用的id方便后面重新发起
|
|
|
+ //清空物料,收费项目id 防止前端误传
|
|
|
+ purchaseProductList.forEach(item -> item.setId(null));
|
|
|
purchaseProjectList.forEach(item -> item.setId(null));
|
|
|
- //清空到货要求的id方便后面重新发起
|
|
|
- purchaseArrivalList.forEach(item -> item.setId(null));
|
|
|
|
|
|
//调用采购发起公共代码块
|
|
|
purchase = ehsdPurchaseFlow.connStart(purchase);
|
|
@@ -127,67 +95,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 重新发起
|
|
|
- */
|
|
|
- @Override
|
|
|
- @LogicIgnore
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
|
|
|
- //删除采购合同
|
|
|
- EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
- if (ObjectUtils.isEmpty(purchase)) {
|
|
|
- throw new ServiceException("采购数据不能为空");
|
|
|
- }
|
|
|
- purchase.setFlowId(flowId);
|
|
|
- ehsdPurchaseFlow.connStart(purchase);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 驳回
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
- ehsdPurchaseService.update(q -> q
|
|
|
- .eq(EhsdPurchase::getId, businessId)
|
|
|
- .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.getKey())
|
|
|
- .set(EhsdPurchase::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
-
|
|
|
- //恢复原合同
|
|
|
- EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
|
|
|
- ehsdPurchaseService.update(q -> q
|
|
|
- .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
|
|
|
- .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 作废
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
- super.cancellation(flowId, businessId, flowStatus);
|
|
|
- ehsdPurchaseService.update(q -> q
|
|
|
- .eq(EhsdPurchase::getId, businessId)
|
|
|
- .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
|
|
|
- .set(EhsdPurchase::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
-
|
|
|
- //恢复原合同
|
|
|
- EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
|
|
|
- ehsdPurchaseService.update(q -> q
|
|
|
- .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
|
|
|
- .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 结束流程
|
|
|
*/
|
|
|
@Override
|
|
@@ -201,25 +108,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
oldEhsdPurchase.setStatus(FlowStatusEnum1.UPDATE.getKey());
|
|
|
ehsdPurchaseService.updateById(oldEhsdPurchase);
|
|
|
|
|
|
-// //回滚旧合同的已采购数量
|
|
|
-// List<EhsdPurchaseProduct> oldPurchaseProductList = ehsdPurchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, purchase.getOldPurchaseId()));
|
|
|
-// for (EhsdPurchaseProduct ehsdPurchaseProduct : oldPurchaseProductList) {
|
|
|
-// if (ObjectUtils.isNotEmpty(ehsdPurchaseProduct.getDataResourceId()) && ehsdPurchaseProduct.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
|
|
|
-// ContractProduct contractProduct = contractProductService.getById(ehsdPurchaseProduct.getDataResourceId());
|
|
|
-// //回滚变更前待采购数量
|
|
|
-// contractProduct.setExpendQuantity(contractProduct.getExpendQuantity().add(ehsdPurchaseProduct.getQuantity()));
|
|
|
-// contractProductService.updateById(contractProduct);
|
|
|
-// }
|
|
|
-// if (ObjectUtils.isNotEmpty(ehsdPurchaseProduct.getDataResourceId()) && ehsdPurchaseProduct.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()) {//如果采购的是样品单
|
|
|
-// SampleProduct sampleProduct = sampleProductService.getById(ehsdPurchaseProduct.getDataResourceId());
|
|
|
-// //回滚变更前待采购数量
|
|
|
-// sampleProduct.setExpendQuantity(sampleProduct.getExpendQuantity().add(ehsdPurchaseProduct.getQuantity()));
|
|
|
-// sampleProductService.updateById(sampleProduct);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- //---------------------------------------
|
|
|
-
|
|
|
//修改可用库存
|
|
|
//回滚旧合同数据
|
|
|
List<InOutBo> oldInOutBoList = new ArrayList<>();
|
|
@@ -251,9 +139,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
productInfoService.editAvailableQuantity(inOutBoList, InOutType.IN, businessId, ProductAvailableRecordType.PURCHASE_UPDATE, purchase.getCompanyId());
|
|
|
|
|
|
|
|
|
- //-----------------------------
|
|
|
-
|
|
|
-
|
|
|
//调用采购发起流程的结束方法
|
|
|
ehsdPurchaseFlow.end(flowId, businessId, submitData);
|
|
|
|
|
@@ -264,7 +149,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
ehsdPurchaseService.updatePurchaseId(businessId, tempId, SecurityUtils.getUserId(), null);
|
|
|
ehsdPurchaseProductService.update(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId).set(EhsdPurchaseProduct::getPurchaseId, tempId));
|
|
|
ehsdPurchaseProjectService.update(q -> q.eq(EhsdPurchaseProject::getPurchaseId, businessId).set(EhsdPurchaseProject::getPurchaseId, tempId));
|
|
|
-// ehsdPurchaseArrivalService.update(q -> q.eq(EhsdPurchaseArrival::getPurchaseId, businessId).set(EhsdPurchaseArrival::getPurchaseId, tempId));
|
|
|
|
|
|
|
|
|
//将旧合同的id改为新合同id
|
|
@@ -281,12 +165,6 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
.set(BasePo::getUpdateTime, new Date())
|
|
|
.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
);
|
|
|
-// ehsdPurchaseArrivalService.update(q -> q
|
|
|
-// .eq(EhsdPurchaseArrival::getPurchaseId, oldPurchaseId)
|
|
|
-// .set(EhsdPurchaseArrival::getPurchaseId, businessId)
|
|
|
-// .set(BasePo::getUpdateTime, new Date())
|
|
|
-// .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
-// );
|
|
|
//将新合同id改为旧合同id
|
|
|
ehsdPurchaseService.updatePurchaseId(tempId, oldPurchaseId, SecurityUtils.getUserId(), businessId);
|
|
|
ehsdPurchaseProductService.update(q -> q
|
|
@@ -301,12 +179,64 @@ public class EhsdPurchaseUpdateFlow extends FlowDelegate {
|
|
|
.set(BasePo::getUpdateTime, new Date())
|
|
|
.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
);
|
|
|
-// ehsdPurchaseArrivalService.update(q -> q
|
|
|
-// .eq(EhsdPurchaseArrival::getPurchaseId, tempId)
|
|
|
-// .set(EhsdPurchaseArrival::getPurchaseId, oldPurchaseId)
|
|
|
-// .set(BasePo::getUpdateTime, new Date())
|
|
|
-// .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
-// );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新发起
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
|
|
|
+ EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
+ if (ObjectUtils.isEmpty(purchase)) {
|
|
|
+ throw new ServiceException("采购数据不能为空");
|
|
|
+ }
|
|
|
+ purchase.setFlowId(flowId);
|
|
|
+ ehsdPurchaseFlow.connStart(purchase);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 驳回
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ ehsdPurchaseService.update(q -> q
|
|
|
+ .eq(EhsdPurchase::getId, businessId)
|
|
|
+ .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.getKey())
|
|
|
+ .set(EhsdPurchase::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ //恢复原合同
|
|
|
+ EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
|
|
|
+ ehsdPurchaseService.update(q -> q
|
|
|
+ .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
|
|
|
+ .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 作废
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ super.cancellation(flowId, businessId, flowStatus);
|
|
|
+ ehsdPurchaseService.update(q -> q
|
|
|
+ .eq(EhsdPurchase::getId, businessId)
|
|
|
+ .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
|
|
|
+ .set(EhsdPurchase::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ //恢复原合同
|
|
|
+ EhsdPurchase ehsdPurchase = ehsdPurchaseService.getById(businessId);
|
|
|
+ ehsdPurchaseService.update(q -> q
|
|
|
+ .eq(BasePo::getId, ehsdPurchase.getOldPurchaseId())
|
|
|
+ .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
}
|