From 481d8165f26fc7e37f0e87f6444ac0340bb563a3 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期二, 03 十一月 2026 18:53:22 +0800
Subject: [PATCH] fix: 移植长辉已验证的四类接口 500/体验问题(不含物料颜色字段)
---
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseOrderServiceImpl.java | 339 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 270 insertions(+), 69 deletions(-)
diff --git a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseOrderServiceImpl.java b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseOrderServiceImpl.java
index cd140a7..40f9f63 100644
--- a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseOrderServiceImpl.java
+++ b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseOrderServiceImpl.java
@@ -2,35 +2,47 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
-import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
-import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum;
-import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
-import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
+import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderImportExcelVO;
+import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderImportReqVO;
+import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderImportRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.order.ErpPurchaseOrderSaveReqVO;
+import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpAccountDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderItemDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseRequestDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseRequestItemDO;
+import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO;
+import cn.iocoder.yudao.module.erp.dal.mysql.finance.ErpAccountMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseOrderItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseOrderMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseRequestItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseRequestMapper;
+import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpSupplierMapper;
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
import cn.iocoder.yudao.module.erp.enums.ErpPurchaseOrderInStatusEnum;
+import cn.iocoder.yudao.module.erp.enums.ErpPurchaseOrderStatusEnum;
import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService;
+import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
+import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi;
+import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO;
import cn.iocoder.yudao.module.mes.api.arrivalnotice.MesArrivalNoticeApi;
+import cn.iocoder.yudao.module.system.api.approval.ApprovalConfigApi;
import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
-import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -41,12 +53,13 @@
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
/**
* ERP 閲囪喘璁㈠崟 Service 瀹炵幇绫�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@Service
@Validated
@@ -54,9 +67,19 @@
public class ErpPurchaseOrderServiceImpl implements ErpPurchaseOrderService {
/**
- * BPM 閲囪喘璁㈠崟瀹℃壒鍒嗙被缂栫爜
+ * 閲囪喘璁㈠崟瀹℃壒涓氬姟绫诲瀷缂栫爜锛堝搴� system_approval_config.biz_type锛�
+ *
+ * 娉ㄦ剰锛氭敼閫犱负杞婚噺绾х姸鎬佹満瀹℃壒鍓嶏紝姝ゅ鍘熶负 "purchase_request_approve"锛�
+ * 涓庨噰璐敵璇凤紙ErpPurchaseRequestServiceImpl锛夌殑 BPM 鍒嗙被缂栫爜瀹屽叏鐩稿悓锛�
+ * 瀵艰嚧閲囪喘璁㈠崟鏌ヨ瀹℃壒娴佺▼鏃朵細鍛戒腑閲囪喘鐢宠鐨勬祦绋嬪畾涔夛紝涓よ�呬簰鐩镐覆鐢ㄣ��
+ * 鐜版洿姝d负閲囪喘璁㈠崟涓撳睘缂栫爜銆�
*/
- private static final String PURCHASE_ORDER_APPROVE_CATEGORY_CODE = "purchase_request_approve";
+ private static final String PURCHASE_ORDER_APPROVE_BIZ_TYPE = "erp_purchase_order_approve";
+
+ /**
+ * 閲囪喘璁㈠崟瀹℃壒鐨� BPM 娴佺▼瀹氫箟 Key
+ */
+ private static final String PURCHASE_ORDER_PROCESS_KEY = "purchase_approve";
@Resource
private ErpPurchaseOrderMapper purchaseOrderMapper;
@@ -70,13 +93,21 @@
private ErpSupplierService supplierService;
@Resource
private ErpAccountService accountService;
+ @Resource
+ private ErpSupplierMapper supplierMapper;
+ @Resource
+ private ErpAccountMapper accountMapper;
+ @Resource
+ private MdmItemApi mdmItemApi;
+ @Resource
+ private MdmUnitMeasureApi mdmUnitMeasureApi;
@Resource
- private BpmProcessInstanceApi processInstanceApi;
+ private ApprovalConfigApi approvalConfigApi;
@Resource
- private BpmCategoryService bpmCategoryService;
+ private BpmProcessInstanceApi bpmProcessInstanceApi;
@Resource
- private BpmProcessDefinitionService bpmProcessDefinitionService;
+ private AdminUserApi adminUserApi;
@Resource
@Lazy
@@ -107,9 +138,9 @@
throw exception(PURCHASE_ORDER_NO_EXISTS);
}
- // 2.1 鎻掑叆璁㈠崟锛堥噰璐鍗曞垱寤哄悗涓烘湭瀹℃牳鐘舵�侊紝闇�瑕佹彁浜ゅ鎵癸級
+ // 2.1 鎻掑叆璁㈠崟锛堥噰璐鍗曞垱寤哄悗涓恒�愭湭鎻愪氦銆戠姸鎬侊紝闇�鎻愪氦杩涘叆瀹℃壒娴佺▼锛�
ErpPurchaseOrderDO purchaseOrder = BeanUtils.toBean(createReqVO, ErpPurchaseOrderDO.class, in -> in
- .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())
+ .setNo(no).setStatus(ErpPurchaseOrderStatusEnum.DRAFT.getStatus())
.setInCount(BigDecimal.ZERO).setInStatus(ErpPurchaseOrderInStatusEnum.NOT_IN.getStatus()));
calculateTotalPrice(purchaseOrder, purchaseOrderItems);
purchaseOrderMapper.insert(purchaseOrder);
@@ -127,9 +158,13 @@
public void updatePurchaseOrder(ErpPurchaseOrderSaveReqVO updateReqVO) {
// 1.1 鏍¢獙瀛樺湪
ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(updateReqVO.getId());
- // 閲囪喘璁㈠崟涓嶅厑璁镐慨鏀癸紙宸插鏍哥姸鎬侊級
- if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseOrder.getStatus())) {
+ // 宸插鏍哥姸鎬佷笉鍏佽淇敼
+ if (ErpPurchaseOrderStatusEnum.APPROVE.getStatus().equals(purchaseOrder.getStatus())) {
throw exception(PURCHASE_ORDER_UPDATE_FAIL_APPROVE, purchaseOrder.getNo());
+ }
+ // 瀹℃壒涓笉鍏佽淇敼锛氶渶鍏堢敱瀹℃壒浜恒�屽鏍镐笉閫氳繃銆嶉��鍥烇紝鎵嶈兘閲嶆柊淇敼骞舵彁浜�
+ if (ErpPurchaseOrderStatusEnum.PROCESS.getStatus().equals(purchaseOrder.getStatus())) {
+ throw exception(PURCHASE_ORDER_UPDATE_FAIL_PROCESS, purchaseOrder.getNo());
}
// 1.2 鏍¢獙渚涘簲鍟�
supplierService.validateSupplier(updateReqVO.getSupplierId());
@@ -169,6 +204,10 @@
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
// 1.1 鏍¢獙瀛樺湪
ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id);
+ // 1.1.1 瀹℃牳閫氳繃灞炰簬瀹℃壒鍔ㄤ綔锛屽繀椤荤敱閰嶇疆鍐呯殑瀹℃壒浜烘墽琛岋紙鏈嶅姟绔己鍒讹紝閬垮厤缁曡繃瀹℃牳鎸夐挳鑷姪閫氳繃锛�
+ if (approve) {
+ approvalConfigApi.validateApprover(PURCHASE_ORDER_APPROVE_BIZ_TYPE, getLoginUserId());
+ }
// 1.2 鏍¢獙鐘舵��
if (purchaseOrder.getStatus().equals(status)) {
throw exception(approve ? PURCHASE_ORDER_APPROVE_FAIL : PURCHASE_ORDER_PROCESS_FAIL);
@@ -194,61 +233,80 @@
@Override
@Transactional(rollbackFor = Exception.class)
- public void submitPurchaseOrder(Long id, String processDefinitionKey, Long userId) {
- // 1. 鏍¢獙瀛樺湪 + 鏈鏍哥姸鎬�
+ public void submitPurchaseOrder(Long id) {
+ // 1.1 鏍¢獙瀛樺湪
ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id);
- if (!ErpAuditStatus.PROCESS.getStatus().equals(purchaseOrder.getStatus())) {
- throw exception(PURCHASE_ORDER_SUBMIT_FAIL_STATUS);
+ // 1.2 鍙湁銆愭湭鎻愪氦銆戞垨銆愬鏍镐笉閫氳繃銆戞墠鍏佽鎻愪氦
+ if (!ErpPurchaseOrderStatusEnum.DRAFT.getStatus().equals(purchaseOrder.getStatus())
+ && !ErpPurchaseOrderStatusEnum.REJECT.getStatus().equals(purchaseOrder.getStatus())) {
+ throw exception(PURCHASE_ORDER_SUBMIT_FAIL_NOT_ALLOWED);
+ }
+ // 1.3 蹇呴』閰嶇疆璁㈠崟椤�
+ List<ErpPurchaseOrderItemDO> items = purchaseOrderItemMapper.selectListByOrderId(id);
+ if (CollUtil.isEmpty(items)) {
+ throw exception(PURCHASE_ORDER_SUBMIT_FAIL_ITEM_EMPTY);
}
- // 2. 鍒涘缓 BPM 娴佺▼瀹炰緥
- String processInstanceId = processInstanceApi.createProcessInstance(userId,
- new BpmProcessInstanceCreateReqDTO()
- .setProcessDefinitionKey(processDefinitionKey)
- .setBusinessKey(String.valueOf(id)));
+ // 2. 鏍¢獙瀹℃壒宸插紑鍚笖閰嶇疆浜嗘湁鏁堝鎵逛汉锛堟湭寮�鍚鎵规椂涓嶅厑璁告彁浜わ級
+ approvalConfigApi.validateApprovalEnabledAndGetApprovers(PURCHASE_ORDER_APPROVE_BIZ_TYPE);
- // 3. 鏇存柊閲囪喘璁㈠崟鐘舵�佷负瀹℃壒涓�
- purchaseOrderMapper.updateById(new ErpPurchaseOrderDO()
- .setId(id)
- .setStatus(ErpAuditStatus.APPROVING.getStatus())
- .setProcessInstanceId(processInstanceId));
+ // 3. 缃负瀹℃壒涓紝骞舵竻绌轰笂涓�杞鏍镐俊鎭紝閬垮厤椹冲洖鍘熷洜娈嬬暀
+ if (purchaseOrderMapper.submitAndResetAuditInfo(id, ErpPurchaseOrderStatusEnum.PROCESS.getStatus()) != 1) {
+ throw exception(PURCHASE_ORDER_SUBMIT_FAIL_NOT_ALLOWED);
+ }
+
+ // 4. 鍒涘缓 BPM 娴佺▼瀹炰緥锛屼娇瀹℃壒鍑虹幇鍦ㄣ�屽崗鍚屽姙鍏� - 鎴戠殑娴佺▼銆�
+ bpmProcessInstanceApi.createProcessInstance(getLoginUserId(),
+ new BpmProcessInstanceCreateReqDTO()
+ .setProcessDefinitionKey(PURCHASE_ORDER_PROCESS_KEY)
+ .setBusinessKey(String.valueOf(id)));
}
@Override
- public List<Map<String, Object>> getPurchaseOrderApproveProcessDefinitionList() {
- // 1. 鏍¢獙鍒嗙被鍜屾祦绋嬪畾涔夋槸鍚﹀瓨鍦�
- validatePurchaseOrderApproveCategoryAndProcessDefinition();
+ public Set<Long> getPurchaseOrderApproverUserIds() {
+ return approvalConfigApi.getApproverUserIds(PURCHASE_ORDER_APPROVE_BIZ_TYPE);
+ }
- // 2. 鑾峰彇鍒嗙被涓嬬殑娴佺▼瀹氫箟淇℃伅
- List<BpmProcessDefinitionInfoDO> definitionInfoList = bpmProcessDefinitionService
- .getProcessDefinitionInfoListByCategory(PURCHASE_ORDER_APPROVE_CATEGORY_CODE);
- if (CollUtil.isEmpty(definitionInfoList)) {
- return Collections.emptyList();
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void auditPurchaseOrder(Long id, Boolean pass, String reviewRemark) {
+ // 1.1 鏍¢獙瀛樺湪 + 瀹℃壒涓姸鎬�
+ ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id);
+ if (!ErpPurchaseOrderStatusEnum.PROCESS.getStatus().equals(purchaseOrder.getStatus())) {
+ throw exception(PURCHASE_ORDER_AUDIT_FAIL_NOT_PROCESS);
}
+ // 1.2 鏍¢獙褰撳墠鐧诲綍浜烘槸閰嶇疆鐨勫鎵逛汉锛堟垨绛撅細浠讳竴浜哄鏍稿嵆鍙級
+ Long userId = getLoginUserId();
+ approvalConfigApi.validateApprover(PURCHASE_ORDER_APPROVE_BIZ_TYPE, userId);
- // 3. 閬嶅巻鑾峰彇娴佺▼瀹氫箟璇︽儏锛岃繃婊ゆ縺娲荤姸鎬侊紝淇濈暀鏈�鏂扮増鏈�
- Map<String, ProcessDefinition> latestVersionMap = new HashMap<>();
- for (BpmProcessDefinitionInfoDO info : definitionInfoList) {
- ProcessDefinition pd = bpmProcessDefinitionService.getProcessDefinition(info.getProcessDefinitionId());
- if (pd == null || pd.isSuspended()) {
- continue;
+ // 2. 瀹℃牳涓嶉�氳繃锛氬繀椤诲~鍐欓┏鍥炲師鍥狅紝鍗曟嵁閫�鍥炲悗鍙紪杈戝苟閲嶆柊鎻愪氦
+ if (!Boolean.TRUE.equals(pass)) {
+ if (StrUtil.isBlank(reviewRemark)) {
+ throw exception(PURCHASE_ORDER_AUDIT_REJECT_REASON_REQUIRED);
}
- ProcessDefinition existing = latestVersionMap.get(pd.getKey());
- if (existing == null || pd.getVersion() > existing.getVersion()) {
- latestVersionMap.put(pd.getKey(), pd);
+ if (purchaseOrderMapper.auditPurchaseOrder(id, ErpPurchaseOrderStatusEnum.REJECT.getStatus(),
+ userId, getUserNickname(userId), reviewRemark) != 1) {
+ throw exception(PURCHASE_ORDER_AUDIT_FAIL_NOT_PROCESS);
}
+ return;
}
- // 4. 杩斿洖娴佺▼瀹氫箟鍒楄〃
- List<Map<String, Object>> result = new ArrayList<>();
- for (ProcessDefinition pd : latestVersionMap.values()) {
- Map<String, Object> item = new HashMap<>();
- item.put("id", pd.getId());
- item.put("key", pd.getKey());
- item.put("name", pd.getName());
- result.add(item);
+ // 3. 瀹℃牳閫氳繃
+ if (purchaseOrderMapper.auditPurchaseOrder(id, ErpPurchaseOrderStatusEnum.APPROVE.getStatus(),
+ userId, getUserNickname(userId), reviewRemark) != 1) {
+ throw exception(PURCHASE_ORDER_AUDIT_FAIL_NOT_PROCESS);
}
- return result;
+ }
+
+ /**
+ * 鑾峰彇鐢ㄦ埛鏄电О锛岀敤浜庡啑浣欏瓨鍌ㄥ鏍镐汉濮撳悕
+ */
+ private String getUserNickname(Long userId) {
+ if (userId == null) {
+ return null;
+ }
+ AdminUserRespDTO user = adminUserApi.getUser(userId);
+ return user == null ? null : user.getNickname();
}
@Override
@@ -256,7 +314,7 @@
public void updatePurchaseOrderAuditStatus(Long id, Integer bpmResult) {
// 1. 鏍¢獙瀛樺湪
ErpPurchaseOrderDO purchaseOrder = validatePurchaseOrderExists(id);
- if (!ErpAuditStatus.APPROVING.getStatus().equals(purchaseOrder.getStatus())) {
+ if (!ErpPurchaseOrderStatusEnum.PROCESS.getStatus().equals(purchaseOrder.getStatus())) {
log.warn("[updatePurchaseOrderAuditStatus] 閲囪喘璁㈠崟({}) 涓嶅浜庡鎵逛腑鐘舵��", id);
return;
}
@@ -269,15 +327,17 @@
}
}
- /**
- * 鏍¢獙閲囪喘璁㈠崟瀹℃壒鍒嗙被鍜屾祦绋嬪畾涔夋槸鍚﹀瓨鍦�
- */
- private void validatePurchaseOrderApproveCategoryAndProcessDefinition() {
- // 1. 鏍¢獙鍒嗙被鏄惁瀛樺湪
- List<BpmCategoryDO> categories = bpmCategoryService.getCategoryListByCode(
- Collections.singletonList(PURCHASE_ORDER_APPROVE_CATEGORY_CODE));
- if (CollUtil.isEmpty(categories)) {
- throw exception(PURCHASE_ORDER_BPM_CATEGORY_NOT_EXISTS);
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void updatePurchaseOrderAuditStatus(Long id, Integer bpmStatus, String reason) {
+ // 1. BPM 瀹℃壒缁撴灉鏄犲皠涓洪噰璐鍗曠姸鎬侊細閫氳繃=20 / 涓嶉�氳繃=30 / 鍙栨秷=40
+ Integer newStatus = convertBpmResultToAuditStatus(bpmStatus);
+ if (newStatus == null) {
+ return;
+ }
+ // 2. 浠呭綋浠嶅浜庛�屽鎵逛腑銆嶆椂鍥炲啓锛岄伩鍏嶉噸澶嶈鐩�
+ if (purchaseOrderMapper.updateAuditStatusByBpm(id, newStatus, reason) != 1) {
+ log.warn("[updatePurchaseOrderAuditStatus] 閲囪喘璁㈠崟({}) 涓嶅浜庡鎵逛腑鐘舵�侊紝蹇界暐 BPM 缁撴灉({})", id, bpmStatus);
}
}
@@ -286,11 +346,11 @@
*/
private Integer convertBpmResultToAuditStatus(Integer bpmResult) {
if (BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmResult)) {
- return ErpAuditStatus.APPROVE.getStatus();
+ return ErpPurchaseOrderStatusEnum.APPROVE.getStatus();
} else if (BpmTaskStatusEnum.REJECT.getStatus().equals(bpmResult)) {
- return ErpAuditStatus.PROCESS.getStatus();
+ return ErpPurchaseOrderStatusEnum.REJECT.getStatus();
} else if (BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmResult)) {
- return ErpAuditStatus.CANCEL.getStatus();
+ return ErpPurchaseOrderStatusEnum.CANCEL.getStatus();
}
return null;
}
@@ -376,8 +436,12 @@
return;
}
purchaseOrders.forEach(purchaseOrder -> {
- if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseOrder.getStatus())) {
+ if (ErpPurchaseOrderStatusEnum.APPROVE.getStatus().equals(purchaseOrder.getStatus())) {
throw exception(PURCHASE_ORDER_DELETE_FAIL_APPROVE, purchaseOrder.getNo());
+ }
+ // 瀹℃壒涓姝㈠垹闄わ紝闇�鍏堢敱瀹℃壒浜恒�屽鏍镐笉閫氳繃銆嶉��鍥�
+ if (ErpPurchaseOrderStatusEnum.PROCESS.getStatus().equals(purchaseOrder.getStatus())) {
+ throw exception(PURCHASE_ORDER_UPDATE_FAIL_PROCESS, purchaseOrder.getNo());
}
});
@@ -448,6 +512,14 @@
return Collections.emptyList();
}
return purchaseOrderMapper.selectByIds(ids);
+ }
+
+ @Override
+ public List<ErpPurchaseOrderDO> getPurchaseOrderListBySource(Integer sourceType, Long sourceId) {
+ if (sourceType == null || sourceId == null) {
+ return Collections.emptyList();
+ }
+ return purchaseOrderMapper.selectListBySource(sourceType, sourceId);
}
@Override
@@ -574,4 +646,133 @@
return arrivalNoticeId;
}
+ @Override
+ public ErpPurchaseOrderImportRespVO importPurchaseOrderList(List<ErpPurchaseOrderImportExcelVO> rows,
+ ErpPurchaseOrderImportReqVO req) {
+ if (CollUtil.isEmpty(rows)) throw exception(PURCHASE_ORDER_IMPORT_LIST_IS_EMPTY);
+ if (Boolean.TRUE.equals(req.getUpdateSupport())) throw exception(PURCHASE_ORDER_IMPORT_INVALID, "浠呮敮鎸佹柊澧烇紝涓嶆敮鎸佽鐩�");
+ ErpPurchaseOrderImportRespVO result = ErpPurchaseOrderImportRespVO.builder()
+ .createPurchaseOrderNos(new ArrayList<>()).failurePurchaseOrderNos(new LinkedHashMap<>()).build();
+ List<List<ErpPurchaseOrderImportExcelVO>> groups = new ArrayList<>();
+ List<String> labels = new ArrayList<>();
+ Map<String, Integer> indexes = new LinkedHashMap<>();
+ for (int i = 0; i < rows.size(); i++) {
+ ErpPurchaseOrderImportExcelVO row = rows.get(i);
+ if (row == null || cn.hutool.core.bean.BeanUtil.beanToMap(row).values().stream()
+ .noneMatch(value -> value != null && (!(value instanceof String) || StrUtil.isNotBlank((String) value)))) continue;
+ if (StrUtil.isBlank(row.getNo())) {
+ groups.add(new ArrayList<>(Collections.singletonList(row)));
+ labels.add("绗�" + (i + 2) + "琛�");
+ continue;
+ }
+ String key = row.getNo().trim();
+ Integer index = indexes.get(key);
+ if (index == null) {
+ index = groups.size(); indexes.put(key, index);
+ groups.add(new ArrayList<>()); labels.add(key);
+ }
+ groups.get(index).add(row);
+ }
+ if (groups.isEmpty()) throw exception(PURCHASE_ORDER_IMPORT_LIST_IS_EMPTY);
+ for (int i = 0; i < groups.size(); i++) {
+ try {
+ Long id = cn.hutool.extra.spring.SpringUtil.getBean(ErpPurchaseOrderServiceImpl.class)
+ .createImportedPurchaseOrder(groups.get(i));
+ result.getCreatePurchaseOrderNos().add(purchaseOrderMapper.selectById(id).getNo());
+ } catch (ServiceException ex) {
+ result.getFailurePurchaseOrderNos().put(labels.get(i), ex.getMessage());
+ } catch (RuntimeException ex) {
+ log.error("[importPurchaseOrderList] 閲囪喘璁㈠崟瀵煎叆澶辫触锛屽垎缁�={}", labels.get(i), ex);
+ result.getFailurePurchaseOrderNos().put(labels.get(i), "瀵煎叆澶辫触锛岃妫�鏌ュ熀纭�璧勬枡鍜岃鍗曟槑缁�");
+ }
+ }
+ return result;
+ }
+
+ @Transactional(rollbackFor = Exception.class)
+ public Long createImportedPurchaseOrder(List<ErpPurchaseOrderImportExcelVO> group) {
+ return createPurchaseOrder(buildPurchaseOrderImportSaveReqVO(group));
+ }
+
+
+ /**
+ * 灏嗗悓涓�寮犻噰璐鍗曠殑澶氳鏄庣粏杞崲鎴愬垱寤� Request VO
+ */
+ private ErpPurchaseOrderSaveReqVO buildPurchaseOrderImportSaveReqVO(List<ErpPurchaseOrderImportExcelVO> group) {
+ ErpPurchaseOrderImportExcelVO first = group.get(0);
+ // 1. 鏍¢獙骞惰В鏋愪緵搴斿晢
+ if (StrUtil.isBlank(first.getSupplierName())) {
+ throw exception(PURCHASE_ORDER_IMPORT_SUPPLIER_NOT_EXISTS, "");
+ }
+ ErpSupplierDO supplier = supplierMapper.selectByName(first.getSupplierName());
+ if (supplier == null) {
+ throw exception(PURCHASE_ORDER_IMPORT_SUPPLIER_NOT_EXISTS, first.getSupplierName());
+ }
+ if (first.getOrderTime() == null) {
+ throw exception(PURCHASE_ORDER_IMPORT_ORDER_TIME_REQUIRED);
+ }
+ if (first.getDiscountPercent() != null && (first.getDiscountPercent().signum() < 0 || first.getDiscountPercent().compareTo(new BigDecimal("100")) > 0)
+ || first.getDepositPrice() != null && first.getDepositPrice().signum() < 0) {
+ throw exception(PURCHASE_ORDER_IMPORT_INVALID, "浼樻儬鐜囬』鍦� 0 鑷� 100 涔嬮棿锛屽畾閲戜笉鑳戒负璐熸暟");
+ }
+ for (ErpPurchaseOrderImportExcelVO row : group) {
+ if (StrUtil.isNotBlank(row.getSupplierName()) && !StrUtil.equals(first.getSupplierName(), row.getSupplierName())
+ || row.getOrderTime() != null && !row.getOrderTime().equals(first.getOrderTime())
+ || StrUtil.isNotBlank(row.getAccountName()) && !StrUtil.equals(first.getAccountName(), row.getAccountName())
+ || row.getDiscountPercent() != null && (first.getDiscountPercent() == null || row.getDiscountPercent().compareTo(first.getDiscountPercent()) != 0)
+ || row.getDepositPrice() != null && (first.getDepositPrice() == null || row.getDepositPrice().compareTo(first.getDepositPrice()) != 0)
+ || StrUtil.isNotBlank(row.getRemark()) && !StrUtil.equals(first.getRemark(), row.getRemark())) {
+ throw exception(PURCHASE_ORDER_IMPORT_INVALID, "鍚屼竴閲囪喘璁㈠崟鐨勪富琛ㄤ俊鎭笉涓�鑷�");
+ }
+ if (StrUtil.isBlank(row.getProductCode()) || StrUtil.isBlank(row.getProductUnitCode()) || row.getCount() == null || row.getCount().signum() <= 0
+ || row.getProductPrice() == null || row.getProductPrice().signum() < 0
+ || row.getTaxPercent() != null && (row.getTaxPercent().signum() < 0 || row.getTaxPercent().compareTo(new BigDecimal("100")) > 0)) {
+ throw exception(PURCHASE_ORDER_IMPORT_INVALID, "姣忚椤诲~鍐欑墿鏂欍�佸崟浣嶃�佹鏁版暟閲忋�侀潪璐熷崟浠凤紱绋庣巼椤诲湪 0 鑷� 100 涔嬮棿");
+ }
+ }
+ // 2. 瑙f瀽缁撶畻璐︽埛锛堝彲閫夛級
+ Long accountId = null;
+ if (StrUtil.isNotBlank(first.getAccountName())) {
+ ErpAccountDO account = accountMapper.selectByName(first.getAccountName());
+ if (account == null) {
+ throw exception(PURCHASE_ORDER_IMPORT_ACCOUNT_NOT_EXISTS, first.getAccountName());
+ }
+ accountId = account.getId();
+ }
+ // 3. 缁勮鏄庣粏
+ List<ErpPurchaseOrderSaveReqVO.Item> items = new ArrayList<>();
+ for (ErpPurchaseOrderImportExcelVO row : group) {
+ MdmItemRespDTO product = mdmItemApi.getItemByCode(row.getProductCode().trim()).getCheckedData();
+ if (product == null) {
+ throw exception(PURCHASE_ORDER_IMPORT_PRODUCT_NOT_EXISTS, row.getProductCode());
+ }
+ MdmUnitMeasureRespDTO unit = mdmUnitMeasureApi.getUnitMeasureByCode(row.getProductUnitCode().trim()).getCheckedData();
+ if (unit == null) {
+ throw exception(PURCHASE_ORDER_IMPORT_UNIT_NOT_EXISTS, row.getProductUnitCode());
+ }
+ if (product.getStatus() != null && product.getStatus() != 0 || unit.getStatus() != null && unit.getStatus() != 0) {
+ throw exception(PURCHASE_ORDER_IMPORT_INVALID, "鐗╂枡鎴栬閲忓崟浣嶅凡鍋滅敤");
+ }
+ ErpPurchaseOrderSaveReqVO.Item item = new ErpPurchaseOrderSaveReqVO.Item()
+ .setProductId(product.getId())
+ .setProductUnitId(unit.getId())
+ .setProductPrice(row.getProductPrice())
+ .setCount(row.getCount())
+ .setTaxPercent(row.getTaxPercent())
+ .setQcCheckFlag(row.getQcCheckFlag())
+ .setRemark(row.getItemRemark());
+ items.add(item);
+ }
+ // 4. 缁勮涓昏〃
+ ErpPurchaseOrderSaveReqVO createReqVO = new ErpPurchaseOrderSaveReqVO()
+ .setSupplierId(supplier.getId())
+ .setAccountId(accountId)
+ .setOrderTime(first.getOrderTime())
+ .setDiscountPercent(ObjectUtil.defaultIfNull(first.getDiscountPercent(), BigDecimal.ZERO))
+ .setDepositPrice(ObjectUtil.defaultIfNull(first.getDepositPrice(), BigDecimal.ZERO))
+ .setRemark(first.getRemark())
+ .setItems(items);
+ return createReqVO;
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.3