Merge remote-tracking branch 'origin/master'

master
wanghao 1 month ago
commit 685799de4a

@ -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<T> extends BaseMapper<T> {
// 自定义动态插入方法,接收表名和对象作为参数
@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);
}

@ -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<String, Object> 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<String, Object> params) {
String tableName = (String) params.get("tableName");

@ -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<Void> issuePlanByPlanIds(@PathVariable("workshopId") Long workshopId, @NotEmpty(message = "主键不能为空") @PathVariable("planIds") Long[] planIds) {
return toAjax(prodPlanInfoService.issuePlanByPlanIds(workshopId, List.of(planIds)));
}
}

@ -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<Long> planIds;
}

@ -44,7 +44,8 @@ public interface ProdPlanInfoMapper extends BaseMapperPlus<ProdPlanInfo, ProdPla
* @param queryWrapper
* @return
*/
Page<ProdPlanInfoVo> selectProdPlanInfoList(@Param("tableName") String tableName,@Param("page") Page<ProdPlanInfoVo> page,
@Param(Constants.WRAPPER) Wrapper<ProdPlanInfo> queryWrapper);
List<ProdPlanInfoVo> selectProdPlanInfoList(@Param("tableName") String tableName, @Param(Constants.WRAPPER) Wrapper<ProdPlanInfo> queryWrapper);
}

@ -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<Long> planIds);
}

@ -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<ProdPlanInfo> dynamicBaseSqlMapper;
/**
*
@ -60,13 +59,7 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
@Override
public TableDataInfo<ProdPlanInfoVo> queryPageList(ProdPlanInfoBo bo, PageQuery pageQuery) {
MPJLambdaWrapper<ProdPlanInfo> 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<ProdPlanInfoVo> result = baseMapper.selectProdPlanInfoList(pageQuery.build(), tableName, lqw);
return TableDataInfo.build(result);
}
@ -81,7 +74,8 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
@Override
public List<ProdPlanInfoVo> queryList(ProdPlanInfoBo bo) {
MPJLambdaWrapper<ProdPlanInfo> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
String tableName = getPlanInfoTableName(bo.getWorkshopId());
return baseMapper.selectProdPlanInfoList(tableName, lqw);
}
private MPJLambdaWrapper<ProdPlanInfo> 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<Long> planIds) {
ProdPlanInfoBo bo = new ProdPlanInfoBo();
bo.setWorkshopId(workshopId);
bo.setPlanIds(planIds);
List<ProdPlanInfoVo> 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;
}
}

Loading…
Cancel
Save