|
|
@@ -6,6 +6,7 @@ import easydo.technology.exception.BizException;
|
|
|
import easydo.technology.model.*;
|
|
|
import easydo.technology.model.vo.DispatchVO;
|
|
|
import easydo.technology.model.vo.ProductOrderDispatchVO;
|
|
|
+import easydo.technology.service.FlowNoService;
|
|
|
import easydo.technology.service.ProductOrderDispatchService;
|
|
|
import easydo.technology.system.model.SysUser;
|
|
|
import easydo.technology.utils.SecurityUtils;
|
|
|
@@ -28,6 +29,8 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
private JdbcClient jdbcClient;
|
|
|
@Resource
|
|
|
private DataSource dataSource;
|
|
|
+ @Resource
|
|
|
+ private FlowNoService flowNoService;
|
|
|
|
|
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
@@ -51,6 +54,8 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
|
|
|
// 复制主要字段
|
|
|
vo.setId(model.getId());
|
|
|
+ vo.setCode(model.getCode());
|
|
|
+ vo.setName(model.getName());
|
|
|
vo.setOrderId(model.getOrderId());
|
|
|
vo.setBomId(model.getBomId());
|
|
|
vo.setStageId(model.getStageId());
|
|
|
@@ -65,66 +70,54 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
vo.setIsReport(model.getIsReport());
|
|
|
vo.setIsReview(model.getIsReview());
|
|
|
vo.setIsRound(model.getIsRound());
|
|
|
- vo.setBeginTime(model.getBeginTime());
|
|
|
- vo.setEndTime(model.getEndTime());
|
|
|
+ vo.setIsInspection(model.getIsInspection());
|
|
|
+ vo.setBeginDate(model.getBeginDate());
|
|
|
+ vo.setEndDate(model.getEndDate());
|
|
|
vo.setCreateTime(model.getCreateTime());
|
|
|
vo.setTenantId(model.getTenantId());
|
|
|
|
|
|
- // 查询并设置工单信息
|
|
|
+ // 查询并设置工单信息(返回整表对象)
|
|
|
if (model.getOrderId() != null) {
|
|
|
ProductOrder orderParam = new ProductOrder();
|
|
|
orderParam.setId(model.getOrderId());
|
|
|
ProductOrder order = jdbcClient.getJdbcModelById(orderParam, connection);
|
|
|
if (order != null) {
|
|
|
- ProductOrderDispatchVO.SimpleProductOrder simpleOrder = new ProductOrderDispatchVO.SimpleProductOrder();
|
|
|
- simpleOrder.setId(order.getId());
|
|
|
- simpleOrder.setCode(order.getCode());
|
|
|
- simpleOrder.setName(order.getName());
|
|
|
- vo.setProductOrder(simpleOrder);
|
|
|
+ vo.setProductOrder(order);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 查询并设置工序信息
|
|
|
+ // 查询并设置工序信息(返回整表对象)
|
|
|
if (model.getStageId() != null) {
|
|
|
ProcessStage stageParam = new ProcessStage();
|
|
|
stageParam.setId(model.getStageId());
|
|
|
ProcessStage stage = jdbcClient.getJdbcModelById(stageParam, connection);
|
|
|
if (stage != null) {
|
|
|
- ProductOrderDispatchVO.SimpleStage simpleStage = new ProductOrderDispatchVO.SimpleStage();
|
|
|
- simpleStage.setId(stage.getId());
|
|
|
- simpleStage.setName(stage.getName());
|
|
|
- simpleStage.setCode(stage.getCode());
|
|
|
- vo.setStage(simpleStage);
|
|
|
+ vo.setStage(stage);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询并设置 BOM 信息
|
|
|
if (model.getBomId() != null) {
|
|
|
- ProductOrderBom bomParam = new ProductOrderBom();
|
|
|
- bomParam.setId(model.getBomId());
|
|
|
- ProductOrderBom bom = jdbcClient.getJdbcModelById(bomParam, connection);
|
|
|
-
|
|
|
- if (bom != null) {
|
|
|
- ProductOrderDispatchVO.SimpleProductOrderBom simpleBom = new ProductOrderDispatchVO.SimpleProductOrderBom();
|
|
|
- simpleBom.setId(bom.getId());
|
|
|
- simpleBom.setBomId(bom.getBomId());
|
|
|
- simpleBom.setNumber(bom.getNumber());
|
|
|
-
|
|
|
- // 查询产品 BOM 信息
|
|
|
+ // 注意:派工表中的 bomId 对应 product_order_bom.bom_id(产品BOM主键),不是 product_order_bom.id
|
|
|
+ ProductOrderBom bomQueryParam = new ProductOrderBom();
|
|
|
+ bomQueryParam.setOrderId(model.getOrderId());
|
|
|
+ bomQueryParam.setBomId(model.getBomId());
|
|
|
+ List<ProductOrderBom> bomList = jdbcClient.getJdbcList(bomQueryParam, connection);
|
|
|
+
|
|
|
+ if (bomList != null && !bomList.isEmpty()) {
|
|
|
+ ProductOrderBom bom = bomList.get(0);
|
|
|
+
|
|
|
+ vo.setProductOrderBom(bom);
|
|
|
+
|
|
|
+ // 查询产品 BOM 信息(返回整表对象)
|
|
|
if (bom.getBomId() != null) {
|
|
|
ProductBom productBomParam = new ProductBom();
|
|
|
productBomParam.setId(bom.getBomId());
|
|
|
ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
|
|
|
if (productBom != null) {
|
|
|
- ProductOrderDispatchVO.SimpleProductBom simpleProductBom = new ProductOrderDispatchVO.SimpleProductBom();
|
|
|
- simpleProductBom.setId(productBom.getId());
|
|
|
- simpleProductBom.setBomCode(productBom.getBomCode());
|
|
|
- simpleProductBom.setMaterialName(productBom.getMaterialName());
|
|
|
- simpleBom.setProductBom(simpleProductBom);
|
|
|
+ vo.setProductBom(productBom);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- vo.setProductOrderBom(simpleBom);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -193,36 +186,18 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
|
|
|
// 2. 获取租户ID
|
|
|
String tenantId = order.getTenantId();
|
|
|
-
|
|
|
- // 3. 校验 bomId 必填
|
|
|
- if (vo.getBomId() == null || vo.getBomId().isEmpty()) {
|
|
|
- throw new BizException("bomId 不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- // 4. 查询 BOM 并获取 routeId
|
|
|
- ProductOrderBom bomParam = new ProductOrderBom();
|
|
|
- bomParam.setId(vo.getBomId());
|
|
|
- ProductOrderBom bom = jdbcClient.getJdbcModelById(bomParam, connection);
|
|
|
- if (bom == null) {
|
|
|
- throw new BizException("BOM不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 从 BOM 获取 routeId
|
|
|
- String routeId = bom.getRouteId();
|
|
|
- if (routeId == null || routeId.isEmpty()) {
|
|
|
- throw new BizException("BOM 未关联工艺路线");
|
|
|
- }
|
|
|
|
|
|
- // 5. 按明细处理:新增 / 修改 / 删除
|
|
|
+ // 3. 按明细处理:新增 / 修改 / 删除
|
|
|
if (vo.getItems() != null && !vo.getItems().isEmpty()) {
|
|
|
for (DispatchVO.DispatchItem item : vo.getItems()) {
|
|
|
boolean hasId = item.getId() != null && !item.getId().trim().isEmpty();
|
|
|
boolean deleteOnly = hasId
|
|
|
+ && (item.getBomId() == null || item.getBomId().trim().isEmpty())
|
|
|
&& (item.getStageId() == null || item.getStageId().trim().isEmpty())
|
|
|
&& (item.getUserIds() == null || item.getUserIds().isEmpty())
|
|
|
&& item.getOrderNum() == null
|
|
|
- && (item.getBeginTime() == null || item.getBeginTime().trim().isEmpty())
|
|
|
- && (item.getEndTime() == null || item.getEndTime().trim().isEmpty());
|
|
|
+ && (item.getBeginDate() == null || item.getBeginDate().trim().isEmpty())
|
|
|
+ && (item.getEndDate() == null || item.getEndDate().trim().isEmpty());
|
|
|
|
|
|
// 删除:仅传派工id
|
|
|
if (deleteOnly) {
|
|
|
@@ -249,6 +224,9 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
}
|
|
|
|
|
|
// 新增/修改都需要完整基础字段
|
|
|
+ if (item.getBomId() == null || item.getBomId().trim().isEmpty()) {
|
|
|
+ throw new BizException("bomId 不能为空");
|
|
|
+ }
|
|
|
if (item.getStageId() == null || item.getStageId().trim().isEmpty()) {
|
|
|
throw new BizException("工序不能为空");
|
|
|
}
|
|
|
@@ -256,6 +234,22 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
throw new BizException("派工人员不能为空");
|
|
|
}
|
|
|
|
|
|
+ // 校验 BOM 是否存在于工单中,并获取 routeId
|
|
|
+ ProductOrderBom bomQueryParam = new ProductOrderBom();
|
|
|
+ bomQueryParam.setOrderId(vo.getOrderId());
|
|
|
+ bomQueryParam.setBomId(item.getBomId());
|
|
|
+ List<ProductOrderBom> bomList = jdbcClient.getJdbcList(bomQueryParam, connection);
|
|
|
+
|
|
|
+ if (bomList == null || bomList.isEmpty()) {
|
|
|
+ throw new BizException("工单中不存在该BOM: " + item.getBomId());
|
|
|
+ }
|
|
|
+
|
|
|
+ ProductOrderBom bom = bomList.get(0);
|
|
|
+ String routeId = bom.getRouteId();
|
|
|
+ if (routeId == null || routeId.isEmpty()) {
|
|
|
+ throw new BizException("BOM 未关联工艺路线: " + item.getBomId());
|
|
|
+ }
|
|
|
+
|
|
|
// 校验工序是否存在
|
|
|
ProcessStage stageParam = new ProcessStage();
|
|
|
stageParam.setId(item.getStageId());
|
|
|
@@ -277,11 +271,12 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
}
|
|
|
|
|
|
existDispatch.setRouteId(routeId);
|
|
|
- existDispatch.setBomId(vo.getBomId());
|
|
|
+ existDispatch.setBomId(item.getBomId());
|
|
|
existDispatch.setStageId(item.getStageId());
|
|
|
existDispatch.setOrderNum(item.getOrderNum());
|
|
|
- existDispatch.setBeginTime(item.getBeginTime());
|
|
|
- existDispatch.setEndTime(item.getEndTime());
|
|
|
+ existDispatch.setIsInspection(item.getIsInspection() != null ? item.getIsInspection() : false);
|
|
|
+ existDispatch.setBeginDate(item.getBeginDate());
|
|
|
+ existDispatch.setEndDate(item.getEndDate());
|
|
|
jdbcClient.jdbcUpdateById(existDispatch, connection);
|
|
|
|
|
|
// 子表先删后插,确保人员同步
|
|
|
@@ -294,11 +289,12 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
userItem.setDispatchId(existDispatch.getId());
|
|
|
userItem.setOrderId(vo.getOrderId());
|
|
|
userItem.setUserId(userIdItem);
|
|
|
- userItem.setBomId(vo.getBomId());
|
|
|
+ userItem.setRouteId(routeId);
|
|
|
+ userItem.setBomId(item.getBomId());
|
|
|
userItem.setStageId(item.getStageId());
|
|
|
userItem.setOrderNum(item.getOrderNum());
|
|
|
- userItem.setBeginTime(item.getBeginTime());
|
|
|
- userItem.setEndTime(item.getEndTime());
|
|
|
+ userItem.setBeginDate(item.getBeginDate());
|
|
|
+ userItem.setEndDate(item.getEndDate());
|
|
|
userItem.setStatus(existDispatch.getStatus());
|
|
|
userItem.setIsReport(false);
|
|
|
userItem.setIsReview(false);
|
|
|
@@ -312,12 +308,16 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
// 新增:不传派工id
|
|
|
ProductOrderDispatch dispatch = new ProductOrderDispatch();
|
|
|
dispatch.setOrderId(vo.getOrderId());
|
|
|
+ dispatch.setTenantId(tenantId);
|
|
|
+ String dispatchCode = flowNoService.generateProductOrderDispatchCode(dispatch, connection);
|
|
|
+ dispatch.setCode(dispatchCode);
|
|
|
dispatch.setRouteId(routeId);
|
|
|
- dispatch.setBomId(vo.getBomId());
|
|
|
+ dispatch.setBomId(item.getBomId());
|
|
|
dispatch.setStageId(item.getStageId());
|
|
|
dispatch.setOrderNum(item.getOrderNum());
|
|
|
- dispatch.setBeginTime(item.getBeginTime());
|
|
|
- dispatch.setEndTime(item.getEndTime());
|
|
|
+ dispatch.setIsInspection(item.getIsInspection() != null ? item.getIsInspection() : false);
|
|
|
+ dispatch.setBeginDate(item.getBeginDate());
|
|
|
+ dispatch.setEndDate(item.getEndDate());
|
|
|
dispatch.setStatus(MESEnum.PRODUCT_ORDER_DISPATCH_OF_STATUS_PENDING.getValue());
|
|
|
dispatch.setIsReport(false);
|
|
|
dispatch.setIsReview(false);
|
|
|
@@ -333,11 +333,12 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
userItem.setDispatchId(dispatch.getId());
|
|
|
userItem.setOrderId(vo.getOrderId());
|
|
|
userItem.setUserId(userIdItem);
|
|
|
- userItem.setBomId(vo.getBomId());
|
|
|
+ userItem.setRouteId(routeId);
|
|
|
+ userItem.setBomId(item.getBomId());
|
|
|
userItem.setStageId(item.getStageId());
|
|
|
userItem.setOrderNum(item.getOrderNum());
|
|
|
- userItem.setBeginTime(item.getBeginTime());
|
|
|
- userItem.setEndTime(item.getEndTime());
|
|
|
+ userItem.setBeginDate(item.getBeginDate());
|
|
|
+ userItem.setEndDate(item.getEndDate());
|
|
|
userItem.setStatus(MESEnum.PRODUCT_ORDER_DISPATCH_OF_STATUS_PENDING.getValue());
|
|
|
userItem.setIsReport(false);
|
|
|
userItem.setIsReview(false);
|
|
|
@@ -351,7 +352,7 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 6. 更新工单状态为进行中(如果当前是待进行状态)
|
|
|
+ // 4. 更新工单状态为进行中(如果当前是待进行状态)
|
|
|
if (MESEnum.PRODUCT_ORDER_OF_STATUS_PENDING.getValue().equals(order.getStatus())) {
|
|
|
order.setStatus(MESEnum.PRODUCT_ORDER_OF_STATUS_PROCESSING.getValue());
|
|
|
jdbcClient.jdbcUpdateById(order, connection);
|
|
|
@@ -368,7 +369,7 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> getDispatchSummary(String orderId) throws Exception {
|
|
|
+ public List<Map<String, Object>> getDispatchSummary(String orderId) throws Exception {
|
|
|
Connection connection = dataSource.getConnection();
|
|
|
try {
|
|
|
// 1. 查询该工单的所有派工记录(从主表 product_order_dispatch)
|
|
|
@@ -385,6 +386,7 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
|
|
|
// 基本字段
|
|
|
dispatchInfo.put("id", dispatch.getId());
|
|
|
+ dispatchInfo.put("code", dispatch.getCode());
|
|
|
dispatchInfo.put("orderId", dispatch.getOrderId());
|
|
|
dispatchInfo.put("bomId", dispatch.getBomId());
|
|
|
dispatchInfo.put("stageId", dispatch.getStageId());
|
|
|
@@ -399,8 +401,9 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
dispatchInfo.put("isReport", dispatch.getIsReport());
|
|
|
dispatchInfo.put("isReview", dispatch.getIsReview());
|
|
|
dispatchInfo.put("isRound", dispatch.getIsRound());
|
|
|
- dispatchInfo.put("beginTime", dispatch.getBeginTime());
|
|
|
- dispatchInfo.put("endTime", dispatch.getEndTime());
|
|
|
+ dispatchInfo.put("isInspection", dispatch.getIsInspection());
|
|
|
+ dispatchInfo.put("beginDate", dispatch.getBeginDate());
|
|
|
+ dispatchInfo.put("endDate", dispatch.getEndDate());
|
|
|
dispatchInfo.put("createTime", dispatch.getCreateTime());
|
|
|
|
|
|
// 3. 查询关联的用户信息(从子表 dispatch_user_item)
|
|
|
@@ -427,10 +430,7 @@ public class ProductOrderDispatchServiceImpl implements ProductOrderDispatchServ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("dispatches", dispatches);
|
|
|
-
|
|
|
- return result;
|
|
|
+ return dispatches;
|
|
|
} catch (Exception e) {
|
|
|
throw new BizException(e.getMessage());
|
|
|
} finally {
|