|
|
@@ -1,8 +1,10 @@
|
|
|
package easydo.technology.service.impl;
|
|
|
|
|
|
import easydo.technology.components.JdbcClient;
|
|
|
+import easydo.technology.enums.MESEnum;
|
|
|
import easydo.technology.exception.BizException;
|
|
|
import easydo.technology.model.*;
|
|
|
+import easydo.technology.service.FlowNoService;
|
|
|
import easydo.technology.service.ProductPlanService;
|
|
|
import easydo.technology.system.model.SysUser;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -20,6 +22,8 @@ public class ProductPlanServiceImpl implements ProductPlanService {
|
|
|
private JdbcClient jdbcClient;
|
|
|
@Resource
|
|
|
private DataSource dataSource;
|
|
|
+ @Resource
|
|
|
+ private FlowNoService flowNoService;
|
|
|
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@@ -90,7 +94,16 @@ public class ProductPlanServiceImpl implements ProductPlanService {
|
|
|
if (planBom.getBomId() != null) {
|
|
|
ProductBom productBomParam = new ProductBom();
|
|
|
productBomParam.setId(planBom.getBomId());
|
|
|
- planBom.setProductBom(jdbcClient.getJdbcModelById(productBomParam, connection));
|
|
|
+ ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
|
|
|
+
|
|
|
+ // 4.3.1) 查询 ProductBom 的物料信息(ProductMaterial)
|
|
|
+ if (productBom != null && productBom.getMaterialCode() != null) {
|
|
|
+ ProductMaterial materialParam = new ProductMaterial();
|
|
|
+ materialParam.setCode(productBom.getMaterialCode());
|
|
|
+ productBom.setMaterial(jdbcClient.getJdbcModel(materialParam, connection));
|
|
|
+ }
|
|
|
+
|
|
|
+ planBom.setProductBom(productBom);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -134,5 +147,187 @@ public class ProductPlanServiceImpl implements ProductPlanService {
|
|
|
connection.close();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ProductPlan save(ProductPlan model) throws Exception {
|
|
|
+ Connection connection = dataSource.getConnection();
|
|
|
+ connection.setAutoCommit(false);
|
|
|
+ try {
|
|
|
+ // 1) 生成编码(支持手填校验 + 自动生成)
|
|
|
+ String code = flowNoService.generateProductPlanCode(model, connection);
|
|
|
+ model.setCode(code);
|
|
|
+
|
|
|
+ // 2) 设置初始状态为 pending
|
|
|
+ model.setStatus(MESEnum.PRODUCT_PLAN_OF_STATUS_PENDING.getValue());
|
|
|
+
|
|
|
+ // 3) 插入主表(会自动保存附件 fileList)
|
|
|
+ jdbcClient.jdbcInsert(model, connection);
|
|
|
+
|
|
|
+ // 4) 插入 BOM 列表
|
|
|
+ List<ProductPlanBom> bomList = model.getBomList();
|
|
|
+ if (bomList != null) {
|
|
|
+ for (ProductPlanBom bom : bomList) {
|
|
|
+ bom.setPlanId(model.getId());
|
|
|
+
|
|
|
+ // 根据 bomId 查询 product_bom 表获取工艺路线ID
|
|
|
+ if (bom.getBomId() != null) {
|
|
|
+ ProductBom productBomParam = new ProductBom();
|
|
|
+ productBomParam.setId(bom.getBomId());
|
|
|
+ ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
|
|
|
+ if (productBom != null && productBom.getRouteId() != null) {
|
|
|
+ bom.setRouteId(productBom.getRouteId());
|
|
|
+
|
|
|
+ // 根据工艺路线ID查询工艺路线表获取质检方案ID
|
|
|
+ ProcessRoute processRouteParam = new ProcessRoute();
|
|
|
+ processRouteParam.setId(productBom.getRouteId());
|
|
|
+ ProcessRoute processRoute = jdbcClient.getJdbcModelById(processRouteParam, connection);
|
|
|
+ if (processRoute != null && processRoute.getInspectProgramId() != null) {
|
|
|
+ bom.setInspectProgramId(processRoute.getInspectProgramId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ jdbcClient.jdbcInsert(bom, connection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5) 插入设备列表
|
|
|
+ List<ProductPlanDevice> deviceList = model.getDeviceList();
|
|
|
+ if (deviceList != null) {
|
|
|
+ for (ProductPlanDevice device : deviceList) {
|
|
|
+ device.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcInsert(device, connection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6) 插入人员列表
|
|
|
+ List<ProductPlanUser> userList = model.getUserList();
|
|
|
+ if (userList != null) {
|
|
|
+ for (ProductPlanUser user : userList) {
|
|
|
+ user.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcInsert(user, connection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ connection.commit();
|
|
|
+ return model;
|
|
|
+ } catch (Exception e) {
|
|
|
+ connection.rollback();
|
|
|
+ throw new BizException(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductPlan update(ProductPlan model) throws Exception {
|
|
|
+ Connection connection = dataSource.getConnection();
|
|
|
+ connection.setAutoCommit(false);
|
|
|
+ try {
|
|
|
+ // 1) 更新主表(会自动保存附件 fileList)
|
|
|
+ jdbcClient.jdbcUpdateById(model, connection);
|
|
|
+
|
|
|
+ // 2) 删除旧 BOM 列表
|
|
|
+ ProductPlanBom bomRemoveParam = new ProductPlanBom();
|
|
|
+ bomRemoveParam.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcRemove(bomRemoveParam, connection);
|
|
|
+
|
|
|
+ // 3) 插入新 BOM 列表
|
|
|
+ List<ProductPlanBom> bomList = model.getBomList();
|
|
|
+ if (bomList != null) {
|
|
|
+ for (ProductPlanBom bom : bomList) {
|
|
|
+ bom.setPlanId(model.getId());
|
|
|
+
|
|
|
+ // 根据 bomId 查询 product_bom 表获取工艺路线ID
|
|
|
+ if (bom.getBomId() != null) {
|
|
|
+ ProductBom productBomParam = new ProductBom();
|
|
|
+ productBomParam.setId(bom.getBomId());
|
|
|
+ ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
|
|
|
+ if (productBom != null && productBom.getRouteId() != null) {
|
|
|
+ bom.setRouteId(productBom.getRouteId());
|
|
|
+
|
|
|
+ // 根据工艺路线ID查询工艺路线表获取质检方案ID
|
|
|
+ ProcessRoute processRouteParam = new ProcessRoute();
|
|
|
+ processRouteParam.setId(productBom.getRouteId());
|
|
|
+ ProcessRoute processRoute = jdbcClient.getJdbcModelById(processRouteParam, connection);
|
|
|
+ if (processRoute != null && processRoute.getInspectProgramId() != null) {
|
|
|
+ bom.setInspectProgramId(processRoute.getInspectProgramId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ jdbcClient.jdbcInsert(bom, connection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4) 删除旧设备列表
|
|
|
+ ProductPlanDevice deviceRemoveParam = new ProductPlanDevice();
|
|
|
+ deviceRemoveParam.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcRemove(deviceRemoveParam, connection);
|
|
|
+
|
|
|
+ // 5) 插入新设备列表
|
|
|
+ List<ProductPlanDevice> deviceList = model.getDeviceList();
|
|
|
+ if (deviceList != null) {
|
|
|
+ for (ProductPlanDevice device : deviceList) {
|
|
|
+ device.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcInsert(device, connection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6) 删除旧人员列表
|
|
|
+ ProductPlanUser userRemoveParam = new ProductPlanUser();
|
|
|
+ userRemoveParam.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcRemove(userRemoveParam, connection);
|
|
|
+
|
|
|
+ // 7) 插入新人员列表
|
|
|
+ List<ProductPlanUser> userList = model.getUserList();
|
|
|
+ if (userList != null) {
|
|
|
+ for (ProductPlanUser user : userList) {
|
|
|
+ user.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcInsert(user, connection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ connection.commit();
|
|
|
+ return model;
|
|
|
+ } catch (Exception e) {
|
|
|
+ connection.rollback();
|
|
|
+ throw new BizException(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductPlan remove(ProductPlan model) throws Exception {
|
|
|
+ Connection connection = dataSource.getConnection();
|
|
|
+ connection.setAutoCommit(false);
|
|
|
+ try {
|
|
|
+ // 1) 删除主表(JdbcClient 会自动删除附件)
|
|
|
+ jdbcClient.jdbcRemoveById(model, connection);
|
|
|
+
|
|
|
+ // 2) 删除 BOM 列表
|
|
|
+ ProductPlanBom bomRemoveParam = new ProductPlanBom();
|
|
|
+ bomRemoveParam.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcRemove(bomRemoveParam, connection);
|
|
|
+
|
|
|
+ // 3) 删除设备列表
|
|
|
+ ProductPlanDevice deviceRemoveParam = new ProductPlanDevice();
|
|
|
+ deviceRemoveParam.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcRemove(deviceRemoveParam, connection);
|
|
|
+
|
|
|
+ // 4) 删除人员列表
|
|
|
+ ProductPlanUser userRemoveParam = new ProductPlanUser();
|
|
|
+ userRemoveParam.setPlanId(model.getId());
|
|
|
+ jdbcClient.jdbcRemove(userRemoveParam, connection);
|
|
|
+
|
|
|
+ connection.commit();
|
|
|
+ return model;
|
|
|
+ } catch (Exception e) {
|
|
|
+ connection.rollback();
|
|
|
+ throw new BizException(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|