|
@@ -1,6 +1,5 @@
|
|
package com.fjhx.service.impl;
|
|
package com.fjhx.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fjhx.base.BaseEntity;
|
|
import com.fjhx.base.BaseEntity;
|
|
@@ -8,16 +7,20 @@ import com.fjhx.constants.ErrorMsgConstant;
|
|
import com.fjhx.constants.LibrarySupplyLockConstant;
|
|
import com.fjhx.constants.LibrarySupplyLockConstant;
|
|
import com.fjhx.constants.StatusConstant;
|
|
import com.fjhx.constants.StatusConstant;
|
|
import com.fjhx.entity.ApplyPurchase;
|
|
import com.fjhx.entity.ApplyPurchase;
|
|
|
|
+import com.fjhx.entity.OrderFlow;
|
|
import com.fjhx.enums.ApplyPurchaseStatusEnum;
|
|
import com.fjhx.enums.ApplyPurchaseStatusEnum;
|
|
import com.fjhx.mapper.ApplyPurchaseMapper;
|
|
import com.fjhx.mapper.ApplyPurchaseMapper;
|
|
import com.fjhx.service.ApplyPurchaseService;
|
|
import com.fjhx.service.ApplyPurchaseService;
|
|
|
|
+import com.fjhx.service.OrderFlowService;
|
|
import com.fjhx.utils.Assert;
|
|
import com.fjhx.utils.Assert;
|
|
import org.springblade.core.redis.lock.RedisLockClient;
|
|
import org.springblade.core.redis.lock.RedisLockClient;
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -35,39 +38,63 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
@Resource
|
|
@Resource
|
|
private RedisLockClient redisLockClient;
|
|
private RedisLockClient redisLockClient;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private OrderFlowService orderFlowService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void add(ApplyPurchase applyPurchase) {
|
|
public void add(ApplyPurchase applyPurchase) {
|
|
Assert.notEmpty(applyPurchase.getGoodsId(), "物品id不能为空");
|
|
Assert.notEmpty(applyPurchase.getGoodsId(), "物品id不能为空");
|
|
Assert.notEmpty(applyPurchase.getQuantity(), "申购数量不能为空");
|
|
Assert.notEmpty(applyPurchase.getQuantity(), "申购数量不能为空");
|
|
Assert.notEmpty(applyPurchase.getPlanArrivalTime(), "到货时间不能为空");
|
|
Assert.notEmpty(applyPurchase.getPlanArrivalTime(), "到货时间不能为空");
|
|
|
|
|
|
|
|
+ // 到货数量
|
|
|
|
+ applyPurchase.setArrivalQuantity(BigDecimal.ZERO);
|
|
|
|
+
|
|
|
|
+ // 到货金额
|
|
|
|
+ applyPurchase.setArrivalPrice(BigDecimal.ZERO);
|
|
|
|
+
|
|
|
|
+ // 状态
|
|
applyPurchase.setStatus(ApplyPurchaseStatusEnum.WAIT_START.getValue());
|
|
applyPurchase.setStatus(ApplyPurchaseStatusEnum.WAIT_START.getValue());
|
|
|
|
|
|
save(applyPurchase);
|
|
save(applyPurchase);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void initiateSubscription(List<ApplyPurchase> applyPurchaseList, Long flowLinkNo) {
|
|
|
|
-
|
|
|
|
|
|
+ public void initiateSubscription(List<ApplyPurchase> applyPurchaseList, Long flowLinkNo, String code) {
|
|
String tenantId = AuthUtil.getTenantId();
|
|
String tenantId = AuthUtil.getTenantId();
|
|
|
|
|
|
Boolean flag = redisLockClient.lockFair(LibrarySupplyLockConstant.APPLY_PURCHASE_CODE_LOCK + tenantId,
|
|
Boolean flag = redisLockClient.lockFair(LibrarySupplyLockConstant.APPLY_PURCHASE_CODE_LOCK + tenantId,
|
|
() -> {
|
|
() -> {
|
|
- String applyPurchaseCode = createApplyPurchaseCode();
|
|
|
|
- applyPurchaseList.forEach(applyPurchase -> {
|
|
|
|
- // 赋值申购单号
|
|
|
|
- applyPurchase.setCode(applyPurchaseCode);
|
|
|
|
- // 状态改为审批中
|
|
|
|
- applyPurchase.setStatus(ApplyPurchaseStatusEnum.IN_APPROVAL.getValue());
|
|
|
|
- // 赋值流程id
|
|
|
|
- applyPurchase.setFlowLinkNo(flowLinkNo);
|
|
|
|
- });
|
|
|
|
- updateBatchById(applyPurchaseList);
|
|
|
|
|
|
+
|
|
|
|
+ int count = count(Wrappers.<ApplyPurchase>lambdaQuery()
|
|
|
|
+ .eq(ApplyPurchase::getCode, code)
|
|
|
|
+ .eq(BaseEntity::getTenantId, tenantId));
|
|
|
|
+ Assert.eqZero(count, "申购单号已存在");
|
|
|
|
+
|
|
|
|
+ updateApplyPurchaseInApproval(applyPurchaseList, flowLinkNo, code);
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
});
|
|
});
|
|
|
|
|
|
Assert.eqTrue(flag, ErrorMsgConstant.SYSTEM_BUSY_ERROR);
|
|
Assert.eqTrue(flag, ErrorMsgConstant.SYSTEM_BUSY_ERROR);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void initiateSubscriptionAuto(List<ApplyPurchase> applyPurchaseList, Long flowLinkNo, String codePrefix) {
|
|
|
|
|
|
|
|
+ String tenantId = AuthUtil.getTenantId();
|
|
|
|
+
|
|
|
|
+ Boolean flag = redisLockClient.lockFair(LibrarySupplyLockConstant.APPLY_PURCHASE_CODE_LOCK + tenantId,
|
|
|
|
+ () -> {
|
|
|
|
+
|
|
|
|
+ String code = createApplyPurchaseCode(codePrefix);
|
|
|
|
+
|
|
|
|
+ updateApplyPurchaseInApproval(applyPurchaseList, flowLinkNo, code);
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Assert.eqTrue(flag, ErrorMsgConstant.SYSTEM_BUSY_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -81,7 +108,9 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void bindingOrder(List<ApplyPurchase> applyPurchaseList, Long orderId, String orderCode, Long supplierId, Integer accountPeriod) {
|
|
|
|
|
|
+ public void flowOrder(List<ApplyPurchase> applyPurchaseList, Long orderId, String orderCode, Long supplierId, Integer accountPeriod) {
|
|
|
|
+
|
|
|
|
+ List<OrderFlow> orderFlowList = new ArrayList<>();
|
|
|
|
|
|
for (ApplyPurchase applyPurchase : applyPurchaseList) {
|
|
for (ApplyPurchase applyPurchase : applyPurchaseList) {
|
|
|
|
|
|
@@ -96,24 +125,56 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
applyPurchase.setOrderCode(orderCode);
|
|
applyPurchase.setOrderCode(orderCode);
|
|
applyPurchase.setSupplierId(supplierId);
|
|
applyPurchase.setSupplierId(supplierId);
|
|
applyPurchase.setAccountPeriod(accountPeriod);
|
|
applyPurchase.setAccountPeriod(accountPeriod);
|
|
- applyPurchase.setStatus(ApplyPurchaseStatusEnum.PURCHASED.getValue());
|
|
|
|
|
|
+ applyPurchase.setStatus(ApplyPurchaseStatusEnum.PURCHASE_FLOW.getValue());
|
|
|
|
|
|
// 申购金额
|
|
// 申购金额
|
|
applyPurchase.setApplyPrice(unitPrice.multiply(applyPurchase.getQuantity()));
|
|
applyPurchase.setApplyPrice(unitPrice.multiply(applyPurchase.getQuantity()));
|
|
|
|
|
|
- // 到货数量
|
|
|
|
- applyPurchase.setArrivalQuantity(BigDecimal.ZERO);
|
|
|
|
-
|
|
|
|
- // 到货金额
|
|
|
|
- applyPurchase.setArrivalPrice(BigDecimal.ZERO);
|
|
|
|
-
|
|
|
|
|
|
+ OrderFlow orderFlow = new OrderFlow();
|
|
|
|
+ orderFlow.setOrderId(orderId);
|
|
|
|
+ orderFlow.setApplyPurchaseId(id);
|
|
|
|
+ orderFlow.setUnitPrice(applyPurchase.getUnitPrice());
|
|
|
|
+ orderFlow.setRemark(applyPurchase.getRemark());
|
|
|
|
+ orderFlowList.add(orderFlow);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 保留订单采购记录
|
|
|
|
+ orderFlowService.saveBatch(orderFlowList);
|
|
|
|
+
|
|
updateBatchById(applyPurchaseList);
|
|
updateBatchById(applyPurchaseList);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ public void flowOrderPass(Long orderId) {
|
|
|
|
+ update(Wrappers.<ApplyPurchase>lambdaUpdate()
|
|
|
|
+ .eq(ApplyPurchase::getOrderId, orderId)
|
|
|
|
+ .set(ApplyPurchase::getStatus, ApplyPurchaseStatusEnum.PURCHASED.getValue())
|
|
|
|
+ .set(BaseEntity::getCreateTime, new Date())
|
|
|
|
+ .set(BaseEntity::getUpdateUser, AuthUtil.getUserId())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void flowOrderNotPass(Long orderId) {
|
|
|
|
+ update(Wrappers.<ApplyPurchase>lambdaUpdate()
|
|
|
|
+ .eq(ApplyPurchase::getOrderId, orderId)
|
|
|
|
+ .set(ApplyPurchase::getStatus, ApplyPurchaseStatusEnum.PASS.getValue())
|
|
|
|
+ .set(ApplyPurchase::getOrderId, null)
|
|
|
|
+ .set(ApplyPurchase::getOrderCode, null)
|
|
|
|
+ .set(ApplyPurchase::getSupplierId, null)
|
|
|
|
+ .set(ApplyPurchase::getAccountPeriod, null)
|
|
|
|
+ .set(ApplyPurchase::getApplyPrice, null)
|
|
|
|
+ .set(ApplyPurchase::getUnitPrice, null)
|
|
|
|
+ .set(ApplyPurchase::getRemark, null)
|
|
|
|
+ .set(BaseEntity::getCreateTime, new Date())
|
|
|
|
+ .set(BaseEntity::getUpdateUser, AuthUtil.getUserId())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
public void arrival(Long applyPurchaseId, BigDecimal arrivalQuantity, Boolean autoComplete) {
|
|
public void arrival(Long applyPurchaseId, BigDecimal arrivalQuantity, Boolean autoComplete) {
|
|
|
|
|
|
ApplyPurchase applyPurchase = getById(applyPurchaseId);
|
|
ApplyPurchase applyPurchase = getById(applyPurchaseId);
|
|
@@ -163,20 +224,16 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
.eq(ApplyPurchase::getId, applyPurchaseId)
|
|
.eq(ApplyPurchase::getId, applyPurchaseId)
|
|
.set(BaseEntity::getCreateTime, new Date())
|
|
.set(BaseEntity::getCreateTime, new Date())
|
|
.set(BaseEntity::getUpdateUser, AuthUtil.getUserId())
|
|
.set(BaseEntity::getUpdateUser, AuthUtil.getUserId())
|
|
- .set(ApplyPurchase::getStatus, ApplyPurchaseStatusEnum.DISCARD.getValue()));
|
|
|
|
|
|
+ .set(ApplyPurchase::getStatus, ApplyPurchaseStatusEnum.DISCARD.getValue())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 生成申购单号
|
|
|
|
|
|
+ * 自动生成申购单编号
|
|
*/
|
|
*/
|
|
- private String createApplyPurchaseCode() {
|
|
|
|
|
|
+ public String createApplyPurchaseCode(String codePrefix) {
|
|
StringBuilder builder = new StringBuilder();
|
|
StringBuilder builder = new StringBuilder();
|
|
- builder.append("PA");
|
|
|
|
- builder.append(DateUtil.format(new Date(), "yyyyMM"));
|
|
|
|
- builder.append("-");
|
|
|
|
-
|
|
|
|
- String codePrefix = builder.toString();
|
|
|
|
|
|
+ builder.append(codePrefix);
|
|
|
|
|
|
ApplyPurchase applyPurchase = getOne(Wrappers.<ApplyPurchase>lambdaQuery()
|
|
ApplyPurchase applyPurchase = getOne(Wrappers.<ApplyPurchase>lambdaQuery()
|
|
.select(ApplyPurchase::getCode)
|
|
.select(ApplyPurchase::getCode)
|
|
@@ -192,17 +249,26 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
|
|
|
int codeNum = Integer.parseInt(applyPurchase.getCode().replace(codePrefix, ""));
|
|
int codeNum = Integer.parseInt(applyPurchase.getCode().replace(codePrefix, ""));
|
|
|
|
|
|
- if (codeNum < 9) {
|
|
|
|
- builder.append("00");
|
|
|
|
- } else if (codeNum < 99) {
|
|
|
|
- builder.append("0");
|
|
|
|
- }
|
|
|
|
|
|
+ return builder.append(codeNum < 9 ? "00" : codeNum < 99 ? "0" : "").append(codeNum + 1).toString();
|
|
|
|
+ }
|
|
|
|
|
|
- return builder.append(codeNum + 1).toString();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 赋值申购单状态为审批中
|
|
|
|
+ */
|
|
|
|
+ private void updateApplyPurchaseInApproval(List<ApplyPurchase> applyPurchaseList, Long flowLinkNo, String code) {
|
|
|
|
+ applyPurchaseList.forEach(applyPurchase -> {
|
|
|
|
+ // 赋值申购单号
|
|
|
|
+ applyPurchase.setCode(code);
|
|
|
|
+ // 状态改为审批中
|
|
|
|
+ applyPurchase.setStatus(ApplyPurchaseStatusEnum.IN_APPROVAL.getValue());
|
|
|
|
+ // 赋值流程id
|
|
|
|
+ applyPurchase.setFlowLinkNo(flowLinkNo);
|
|
|
|
+ });
|
|
|
|
+ updateBatchById(applyPurchaseList);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 修改合同审批状态
|
|
|
|
|
|
+ * 修改申购单状态
|
|
*/
|
|
*/
|
|
private void updateFlowStatus(Long flowLinkNo, ApplyPurchaseStatusEnum applyPurchaseStatusEnum) {
|
|
private void updateFlowStatus(Long flowLinkNo, ApplyPurchaseStatusEnum applyPurchaseStatusEnum) {
|
|
update(Wrappers.<ApplyPurchase>lambdaUpdate()
|
|
update(Wrappers.<ApplyPurchase>lambdaUpdate()
|