From c2f5d2878d15de664b1814b63e3eeaedffb602de Mon Sep 17 00:00:00 2001 From: yinq Date: Wed, 19 Feb 2025 15:02:26 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=B8=8B=E5=8F=91=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E3=80=81=E5=88=86=E8=A1=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/mapper/DynamicBaseSqlMapper.java | 4 + .../provider/DynamicBaseSqlProvider.java | 87 ++++++++++++++++++- .../controller/ProdPlanInfoController.java | 11 +++ .../dromara/mes/domain/bo/ProdPlanInfoBo.java | 4 + .../mes/mapper/ProdPlanInfoMapper.java | 5 +- .../mes/service/IProdPlanInfoService.java | 10 ++- .../service/impl/ProdPlanInfoServiceImpl.java | 63 +++++++++++--- 7 files changed, 165 insertions(+), 19 deletions(-) diff --git a/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/mapper/DynamicBaseSqlMapper.java b/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/mapper/DynamicBaseSqlMapper.java index c29f38b1..8efef094 100644 --- a/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/mapper/DynamicBaseSqlMapper.java +++ b/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/mapper/DynamicBaseSqlMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.InsertProvider; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.UpdateProvider; import org.dromara.common.provider.DynamicBaseSqlProvider; @Mapper @@ -10,4 +11,7 @@ public interface DynamicBaseSqlMapper extends BaseMapper { // 自定义动态插入方法,接收表名和对象作为参数 @InsertProvider(type = DynamicBaseSqlProvider.class, method = "dynamicInsert") int dynamicInsert(@Param("tableName") String tableName, @Param("tableNamePrefix") String tableNamePrefix,@Param("entity") T entity); + + @UpdateProvider(type = DynamicBaseSqlProvider.class, method = "dynamicUpdate") + int dynamicUpdate(@Param("tableName") String tableName, @Param("tableNamePrefix") String tableNamePrefix, @Param("entity") T entity); } diff --git a/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/provider/DynamicBaseSqlProvider.java b/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/provider/DynamicBaseSqlProvider.java index 32c73459..97ffc215 100644 --- a/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/provider/DynamicBaseSqlProvider.java +++ b/ruoyi-common/hwmom-common-mom/src/main/java/org/dromara/common/provider/DynamicBaseSqlProvider.java @@ -2,6 +2,7 @@ package org.dromara.common.provider; import org.apache.ibatis.jdbc.SQL; +import java.lang.reflect.Field; import java.util.Map; @@ -13,19 +14,99 @@ public class DynamicBaseSqlProvider { SQL sql = new SQL(); sql.INSERT_INTO(tableName); - switch(tableNamePrefix){ + switch (tableNamePrefix) { case "prod_plan_info": sql.INTO_COLUMNS("plan_code", "material_id", "material_bom_id", "plan_amount", "dispatch_amount", - "process_id", "plan_begin_time", "plan_end_time", "release_type", "release_id", + "process_id", "plan_begin_time", "plan_end_time", "release_type", "release_id", "shift_id", "import_flag", "class_team_id", "model_code", "create_dept", "create_by", "create_time"); sql.INTO_VALUES("#{entity.planCode}", "#{entity.materialId}", "#{entity.materialBomId}", "#{entity.planAmount}", "#{entity.dispatchAmount}", - "#{entity.processId}", "#{entity.planBeginTime}", "#{entity.planEndTime}", "#{entity.releaseType}", "#{entity.releaseId}", + "#{entity.processId}", "#{entity.planBeginTime}", "#{entity.planEndTime}", "#{entity.releaseType}", "#{entity.releaseId}", "#{entity.shiftId}", "#{entity.importFlag}", "#{entity.classTeamId}", "#{entity.modelCode}", "#{entity.createDept}", "#{entity.createBy}", "#{entity.createTime}"); break; } return sql.toString(); } + public String dynamicUpdate(Map params) throws Exception { + String tableName = (String) params.get("tableName"); + Object entity = params.get("entity"); + String tableNamePrefix = (String) params.get("tableNamePrefix"); + SQL sql = new SQL(); + sql.UPDATE(tableName); + switch (tableNamePrefix) { + case "prod_plan_info": + if (hasFieldValue(entity, "dispatchCode")) { + sql.SET("dispatch_code = #{entity.dispatchCode}"); + } + if (hasFieldValue(entity, "materialId")) { + sql.SET("material_id = #{entity.materialId}"); + } + if (hasFieldValue(entity, "materialBomId")) { + sql.SET("material_bom_id = #{entity.materialBomId}"); + } + if (hasFieldValue(entity, "processId")) { + sql.SET("process_id = #{entity.processId}"); + } + if (hasFieldValue(entity, "planAmount")) { + sql.SET("plan_amount = #{entity.planAmount}"); + } + if (hasFieldValue(entity, "dispatchAmount")) { + sql.SET("dispatch_amount = #{entity.dispatchAmount}"); + } + if (hasFieldValue(entity, "planBeginTime")) { + sql.SET("plan_begin_time = #{entity.planBeginTime}"); + } + if (hasFieldValue(entity, "planEndTime")) { + sql.SET("plan_end_time = #{entity.planEndTime}"); + } + if (hasFieldValue(entity, "planStatus")) { + sql.SET("plan_status = #{entity.planStatus}"); + } + if (hasFieldValue(entity, "importFlag")) { + sql.SET("import_flag = #{entity.importFlag}"); + } + if (hasFieldValue(entity, "shiftId")) { + sql.SET("shift_id = #{entity.shiftId}"); + } + if (hasFieldValue(entity, "classTeamId")) { + sql.SET("class_team_id = #{entity.classTeamId}"); + } + if (hasFieldValue(entity, "modelCode")) { + sql.SET("model_code = #{entity.modelCode}"); + } + sql.SET("update_by = #{entity.updateBy}"); + sql.SET("update_time = #{entity.updateTime}"); + break; + } + if (hasFieldValue(entity, "planId")) { + sql.WHERE("plan_id = #{entity.planId}"); + } + return sql.toString(); + } + + + public boolean hasFieldValue(Object entity, String fieldName) { + try { + // 获取字段 + Field field = entity.getClass().getDeclaredField(fieldName); + field.setAccessible(true); // 设置字段可访问 + // 获取字段值 + Object value = field.get(entity); + // 判断字段值是否为 null 或默认值(对于基本类型是默认值) + if (value == null) { + return false; // 字段没有值 + } + // 如果是基本数据类型(如 int, long),并且值是其默认值,则认为没有值 + if (value instanceof Number) { + return !value.equals(0); // 如果是数字类型,0 是默认值 + } + // 对于其他类型,判断值是否为 null + return true; + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + return false; + } + } public String selectByDynamicTableName(Map params) { String tableName = (String) params.get("tableName"); diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java index 9f2440f3..601b893c 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java @@ -162,4 +162,15 @@ public class ProdPlanInfoController extends BaseController { return toAjax(prodPlanInfoService.orderAddMesProductPlanList(productPlanEditVo)); } + /** + * 下发选中计划 + * @param workshopId + * @param planIds + * @return + */ + @GetMapping("/issuePlanInfo/{workshopId}/{planIds}") + public R issuePlanByPlanIds(@PathVariable("workshopId") Long workshopId, @NotEmpty(message = "主键不能为空") @PathVariable("planIds") Long[] planIds) { + return toAjax(prodPlanInfoService.issuePlanByPlanIds(workshopId, List.of(planIds))); + } + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdPlanInfoBo.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdPlanInfoBo.java index f8b8631a..cba37a72 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdPlanInfoBo.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/domain/bo/ProdPlanInfoBo.java @@ -9,6 +9,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; /** @@ -184,5 +186,7 @@ public class ProdPlanInfoBo extends BaseEntity { private Long workshopId; + private List planIds; + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdPlanInfoMapper.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdPlanInfoMapper.java index 2ff30ce0..a038a6b3 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdPlanInfoMapper.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/mapper/ProdPlanInfoMapper.java @@ -44,7 +44,8 @@ public interface ProdPlanInfoMapper extends BaseMapperPlus selectProdPlanInfoList(@Param("tableName") String tableName,@Param("page") Page page, - @Param(Constants.WRAPPER) Wrapper queryWrapper); + List selectProdPlanInfoList(@Param("tableName") String tableName, @Param(Constants.WRAPPER) Wrapper queryWrapper); + + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java index d0543335..5eaf117a 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java @@ -1,6 +1,5 @@ package org.dromara.mes.service; -import org.dromara.mes.domain.ProdPlanInfo; import org.dromara.mes.domain.vo.MesProductPlanEditVo; import org.dromara.mes.domain.vo.ProdPlanInfoVo; import org.dromara.mes.domain.bo.ProdPlanInfoBo; @@ -101,4 +100,13 @@ public interface IProdPlanInfoService { * @return */ public int orderAddMesProductPlanList(MesProductPlanEditVo mesProductPlanEditVo); + + /** + * 下发选中计划 + * @param workshopId + * @param planIds + * @return + */ + Boolean issuePlanByPlanIds(Long workshopId, List planIds); + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java index 484764ad..3419dc46 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java @@ -2,7 +2,6 @@ package org.dromara.mes.service.impl; import org.dromara.common.constant.DatabaseConstants; import org.dromara.common.core.exception.ServiceException; -import org.dromara.common.core.utils.DateUtils; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.uuid.Seq; @@ -37,7 +36,7 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { private final ProdPlanInfoMapper baseMapper; - private final DynamicBaseSqlMapper dynamicBaseSqlMapper; + private final DynamicBaseSqlMapper dynamicBaseSqlMapper; /** * 查询生产工单信息 @@ -60,13 +59,7 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { @Override public TableDataInfo queryPageList(ProdPlanInfoBo bo, PageQuery pageQuery) { MPJLambdaWrapper lqw = buildQueryWrapper(bo); - Long workshopId = bo.getWorkshopId(); - String tableName = null; - if (StringUtils.isNull(workshopId)){ - tableName = DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX; - } else { - tableName = DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX + "_" + workshopId; - } + String tableName = getPlanInfoTableName(bo.getWorkshopId()); Page result = baseMapper.selectProdPlanInfoList(pageQuery.build(), tableName, lqw); return TableDataInfo.build(result); } @@ -81,7 +74,8 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { @Override public List queryList(ProdPlanInfoBo bo) { MPJLambdaWrapper lqw = buildQueryWrapper(bo); - return baseMapper.selectVoList(lqw); + String tableName = getPlanInfoTableName(bo.getWorkshopId()); + return baseMapper.selectProdPlanInfoList(tableName, lqw); } private MPJLambdaWrapper buildQueryWrapper(ProdPlanInfoBo bo) { @@ -119,6 +113,7 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { .eq(bo.getShiftId() != null, ProdPlanInfo::getShiftId, bo.getShiftId()) .eq(bo.getClassTeamId() != null, ProdPlanInfo::getClassTeamId, bo.getClassTeamId()) .eq(StringUtils.isNotBlank(bo.getModelCode()), ProdPlanInfo::getModelCode, bo.getModelCode()) + .in(StringUtils.isNotNull(bo.getPlanIds()), ProdPlanInfo::getPlanId, bo.getPlanIds()) .orderByDesc(ProdPlanInfo::getCreateTime); return lqw; } @@ -136,8 +131,8 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { } ProdPlanInfo add = MapstructUtils.convert(bo, ProdPlanInfo.class); validEntityBeforeSave(add); - String tableName = DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX + "_" + bo.getWorkshopId(); - boolean flag = dynamicBaseSqlMapper.dynamicInsert(tableName, DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX, add) >0; + String tableName = getPlanInfoTableName(bo.getWorkshopId()); + boolean flag = dynamicBaseSqlMapper.dynamicInsert(tableName, DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX, add) > 0; // boolean flag = baseMapper.insert(add) > 0; // if (flag) { // bo.setPlanId(add.getPlanId()); @@ -155,7 +150,8 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { public Boolean updateByBo(ProdPlanInfoBo bo) { ProdPlanInfo update = MapstructUtils.convert(bo, ProdPlanInfo.class); validEntityBeforeSave(update); - return baseMapper.updateById(update) > 0; + String tableName = getPlanInfoTableName(bo.getWorkshopId()); + return dynamicBaseSqlMapper.dynamicUpdate(tableName, DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX, update) > 0; } /** @@ -201,6 +197,20 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { return baseMapper.selectProdPlanInfoJoinProcessList(bo); } + /** + * 获取生产计划数据库表名 + * @param workshopId 车间ID + * @return 生产计划数据库表名 + */ + public String getPlanInfoTableName(Long workshopId){ + String tableName = null; + if (StringUtils.isNull(workshopId)){ + tableName = DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX; + } else { + tableName = DatabaseConstants.TABLE_NAME_PROD_PLAN_INFO_PREFIX + "_" + workshopId; + } + return tableName; + } /** * 生产工单新增生产派工List @@ -243,5 +253,32 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { return successCount; } + /** + * 下发选中计划 + * + * @param workshopId + * @param planIds + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean issuePlanByPlanIds(Long workshopId, List planIds) { + ProdPlanInfoBo bo = new ProdPlanInfoBo(); + bo.setWorkshopId(workshopId); + bo.setPlanIds(planIds); + List prodPlanInfoVoList = queryList(bo); + //校验计划状态是否可下达计划 + for (ProdPlanInfoVo planInfoVo : prodPlanInfoVoList) { + ProdPlanInfoBo prodPlanInfoBo = new ProdPlanInfoBo(); + if (!planInfoVo.getPlanStatus().equals("0")){ + throw new ServiceException(planInfoVo.getPlanCode() + "计划状态不是未派工!"); + } + prodPlanInfoBo.setWorkshopId(workshopId); + prodPlanInfoBo.setPlanId(planInfoVo.getPlanId()); + prodPlanInfoBo.setPlanStatus("1"); + this.updateByBo(prodPlanInfoBo); + } + return true; + } }