自定义板编号生成功能实现

This commit is contained in:
gaoqr
2024-11-27 17:31:42 +08:00
parent 1ea586b316
commit 137c1a0485
28 changed files with 1646 additions and 158 deletions
@@ -59,4 +59,11 @@ public class ErrorCodeConstants {
public static final ErrorCode SOURCE_NOT_EXITS_ERROR = new ErrorCode(1_002_029_013, "源数据查询失败");
public static final ErrorCode ORDER_DELETED_ERR = new ErrorCode(1_002_029_006, "生产单删除失败");
public static final ErrorCode ORDER_RESTORE_ERR = new ErrorCode(1_002_029_006, "生产单还原失败");
// ========== 自定义板编号生成 ==========
public static final ErrorCode CUSTOM_PLATENO_GENERATE_ORDERNO_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_001, "自定义版编号生产单序号规则中存在不支持的复位类型:{}");
public static final ErrorCode CUSTOM_PLATENO_GENERATE_BODY_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_002, "自定义版编号柜体序号规则中存在不支持的复位类型:{}");
public static final ErrorCode CUSTOM_PLATENO_GENERATE_PROCESSGROUP_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_003, "自定义版编号加工组序号规则中存在不支持的复位类型:{}");
public static final ErrorCode CUSTOM_PLATENO_GENERATE_PLATE_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_004, "自定义版编号板件序号规则中存在不支持的复位类型:{}");
public static final ErrorCode CUSTOM_PLATENO_GENERATE_ORG_CUSTOM_PLATENO_SEQ_MODIFY_ERROR = new ErrorCode(1_002_030_005, "保存组织下自定义板编号序号配置失败,请联系客服处理");
}
@@ -189,15 +189,15 @@ public class PlateDO extends BaseDO {
/**
* 房间名
*/
@TableField(exist = false)
private String roomName;
/**
* 柜体名
*/
@TableField(exist = false)
private String bodyName;
/**
* 加工组名
*/
private String processGroupName;
@TableField(exist = false)
private StringBuilder customPlateNo;
}
@@ -1,5 +1,6 @@
package com.cf.imes.module.executor.service.customplateno;
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import java.util.List;
@@ -14,7 +15,8 @@ public interface CustomPlateNoGenerateService {
/**
* 生成自定义板编号
*
* @param orderDO 生产单号
* @param plateDOList 板件列表
*/
void generateCustomPlateNo(List<PlateDO> plateDOList);
void generateCustomPlateNo(OrderDO orderDO, List<PlateDO> plateDOList);
}
@@ -1,10 +1,32 @@
package com.cf.imes.module.executor.service.customplateno;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.enums.ErrorCodeConstants;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqVO;
import com.cf.imes.module.executor.service.customplatenorule.CustomPlateNoGenerateRuleService;
import com.cf.imes.module.executor.service.order.OrderService;
import com.cf.imes.module.system.api.customplateno.CustomPlateNoSeqApi;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.api.systemconfig.SystemConfigApi;
import com.cf.imes.module.system.api.systemconfig.dto.SystemConfigRespDTO;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
/**
* @author Gqr
@@ -14,8 +36,125 @@ import java.util.List;
@Slf4j
public class CustomPlateNoGenerateServiceImpl implements CustomPlateNoGenerateService {
@Resource
@Lazy
private OrderService orderService;
@Resource
private SystemConfigApi systemConfigApi;
@Resource
private CustomPlateNoSeqApi customPlateNoSeqApi;
@Resource
private List<CustomPlateNoGenerateRuleService> ruleServices;
private static final DateTimeFormatter YEAR_FORMATTER = DateTimeFormatter.ofPattern("yyyy");
private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMM");
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
@Override
public void generateCustomPlateNo(List<PlateDO> plateDOList) {
// todo generateCustomPlateNo
public void generateCustomPlateNo(OrderDO orderDO, List<PlateDO> plateDOList) {
Long orderId = orderDO.getId();
// 1、获取生产配置
CustomPlateNoGenerateConfigVO generateConfig = getGenerateConfig(orderId);
// 如果没有查到配置规则就不做后续生成操作了
List<CustomPlateNoRuleVO> orgCustomPlateNoRuleVOList = generateConfig.getOrgCustomPlateNoRuleVOList();
if (CollUtil.isEmpty(orgCustomPlateNoRuleVOList)) {
return;
}
// 开始生成时记录时间,用于后续年月日复位、上次年月日记录等
LocalDateTime now = LocalDateTime.now();
orgCustomPlateNoRuleVOList.forEach(rule -> rule.setNow(now));
// 2、遍历小板列表,生成板编号
for (PlateDO plateDO : plateDOList) {
loopGenerateNo(orderId, plateDO, orgCustomPlateNoRuleVOList, generateConfig);
}
// 3、保存生产单序号json
orderDO.setCustomPlatenoSeq(JSON.toJSONString(generateConfig.getOrderCustomPlateNoSeqVO()));
CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
orgCustomPlateNoSeqRespDTO.setLastOrderNo(orderId);
orgCustomPlateNoSeqRespDTO.setLastYear(Integer.parseInt(YEAR_FORMATTER.format(now)));
orgCustomPlateNoSeqRespDTO.setLastMonth(Integer.parseInt(MONTH_FORMATTER.format(now)));
orgCustomPlateNoSeqRespDTO.setLastDay(Integer.parseInt(DAY_FORMATTER.format(now)));
// 保存组织下全局序号配置
CommonResult<Boolean> orgCustomPlateNoSeqModifyResult = customPlateNoSeqApi.modifyOrgCustomPlateNoSeq(orgCustomPlateNoSeqRespDTO);
if (orgCustomPlateNoSeqModifyResult.isError() || !orgCustomPlateNoSeqModifyResult.getData().booleanValue()) {
throw new ServiceException(ErrorCodeConstants.CUSTOM_PLATENO_GENERATE_ORG_CUSTOM_PLATENO_SEQ_MODIFY_ERROR);
}
}
/**
* 循环规则和板件列表生成编号
*
* @param orderId
* @param plateDO
* @param orgCustomPlateNoRuleVOList
* @param generateConfig
*/
private void loopGenerateNo(Long orderId, PlateDO plateDO, List<CustomPlateNoRuleVO> orgCustomPlateNoRuleVOList, CustomPlateNoGenerateConfigVO generateConfig) {
// 遍历规则列表
for (CustomPlateNoRuleVO plateNoRule : orgCustomPlateNoRuleVOList) {
if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.CUSTOM.getRuleCode(), plateNoRule.getRuleCode())) {
plateDO.getCustomPlateNo().append(plateNoRule.getValue());
}
if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.DATE.getRuleCode(), plateNoRule.getRuleCode())) {
plateDO.getCustomPlateNo().append(plateNoRule.getNow().format(DateTimeFormatter.ofPattern(plateNoRule.getValue())));
}
// 遍历规则生成服务列表,获取对应的规则服务
for (CustomPlateNoGenerateRuleService ruleService : ruleServices) {
if (ruleService.match(plateNoRule.getRuleCode())) {
generateConfig = ruleService.generateNo(orderId, plateNoRule, generateConfig, plateDO);
break;
}
}
}
plateDO.setPlateNo(plateDO.getCustomPlateNo().toString());
}
private CustomPlateNoGenerateConfigVO getGenerateConfig(Long orderId) {
// 生成自定义版编号所需配置
CustomPlateNoGenerateConfigVO customPlateNoGenerateConfigVO = new CustomPlateNoGenerateConfigVO();
// 机构下自定义板编号配置
SystemConfigRespDTO orgCustomPlateNoConfig = null;
// 生产单下序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO();
// 自定义板编号配置规则明细列表
List<CustomPlateNoRuleVO> customPlateNoRuleVOS = List.of();
// 查询机构的自定义版编号配置
CommonResult<SystemConfigRespDTO> orgCustomPlateNoConfigResult = systemConfigApi.getOrgCustomPlateNoConfig();
if (orgCustomPlateNoConfigResult.isSuccess()) {
orgCustomPlateNoConfig = orgCustomPlateNoConfigResult.getData();
customPlateNoRuleVOS = Optional.ofNullable(orgCustomPlateNoConfig)
.map(config -> JSON.parseArray(config.getSetting(), CustomPlateNoRuleVO.class))
.orElse(List.of());
}
OrderDO order = orderService.getOrder(orderId);
if (ObjectUtil.isNotNull(order) && ObjectUtil.isNotNull(orgCustomPlateNoConfig)) {
// 老单
// 生产单上的自定义板编号配置id和当前最新的对比,不同用生产单号上的
Long orderCustomPlatenoConfigId = order.getCustomPlatenoConfigId();
if (ObjectUtil.isNotNull(orderCustomPlatenoConfigId) && ObjectUtil.notEqual(orgCustomPlateNoConfig.getId(), orderCustomPlatenoConfigId)) {
CommonResult<SystemConfigRespDTO> previousCustomPlateNoConfig = systemConfigApi.getById(orderCustomPlatenoConfigId);
if (previousCustomPlateNoConfig.isSuccess()) {
customPlateNoRuleVOS = JSON.parseArray(previousCustomPlateNoConfig.getData().getSetting(), CustomPlateNoRuleVO.class);
}
}
// 上一次的生产单内 自定义版编号序号
orderCustomPlateNoSeqVO = JSON.parseObject(order.getCustomPlatenoSeq(), OrderCustomPlateNoSeqVO.class);
}
customPlateNoGenerateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO);
customPlateNoGenerateConfigVO.setOrgCustomPlateNoRuleVOList(customPlateNoRuleVOS);
CommonResult<CustomPlateNoSeqDTO> orgCustomPlateNoSeq = customPlateNoSeqApi.getOrgCustomPlateNoSeq();
if (orgCustomPlateNoSeq.isSuccess()) {
customPlateNoGenerateConfigVO.setOrgCustomPlateNoSeqRespDTO(orgCustomPlateNoSeq.getData());
}
return customPlateNoGenerateConfigVO;
}
}
@@ -1,6 +1,6 @@
package com.cf.imes.module.executor.service.customplateno.vo;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqRespDTO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import lombok.Data;
import java.io.Serializable;
@@ -27,5 +27,5 @@ public class CustomPlateNoGenerateConfigVO implements Serializable {
/**
* 机构下的自定义板编号序号
*/
private CustomPlateNoSeqRespDTO orgCustomPlateNoSeqRespDTO;
private CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO;
}
@@ -3,6 +3,7 @@ package com.cf.imes.module.executor.service.customplateno.vo;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 系统配置-自定义板编号setting项 vo
@@ -48,4 +49,9 @@ public class CustomPlateNoRuleVO implements Serializable {
* 复位/清零模式
*/
private Integer resetMode;
/**
* 开始生成板编号的时间
*/
private LocalDateTime now;
}
@@ -0,0 +1,26 @@
package com.cf.imes.module.executor.service.customplateno.vo;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
@Data
@Builder
public class OrderCustomPlateNoSeqBodyVO implements Serializable {
private static final long serialVersionUID = 2686882895438975156L;
/**
* 柜体名
*/
private String bodyName;
/**
* 柜体下板件序号
*/
private Integer plateNoSeq;
/**
* 柜体序号
*/
private Integer bodyNoSeq;
}
@@ -0,0 +1,26 @@
package com.cf.imes.module.executor.service.customplateno.vo;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
@Data
@Builder
public class OrderCustomPlateNoSeqProcessGroupVO implements Serializable {
private static final long serialVersionUID = -6834098282222544638L;
/**
* 加工组名
*/
private String processGroupName;
/**
* 加工组下板件序号
*/
private Integer plateNoSeq;
/**
* 加工组序号
*/
private Integer processGroupNoSeq;
}
@@ -0,0 +1,37 @@
package com.cf.imes.module.executor.service.customplateno.vo;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@Builder
public class OrderCustomPlateNoSeqRoomVO implements Serializable {
private static final long serialVersionUID = -127388898531267048L;
/**
* 房间名
*/
private String roomName;
/**
* 房间序号
*/
private Integer roomNoSeq;
/**
* 房间下板件序号
*/
private Integer plateNoSeq;
/**
* 房间下柜体序号
*/
private Integer bodyNoSeq;
/**
* 房间下柜体列表
*/
private List<OrderCustomPlateNoSeqBodyVO> bodys;
}
@@ -1,6 +1,8 @@
package com.cf.imes.module.executor.service.customplateno.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
@@ -12,92 +14,39 @@ import java.util.List;
* @since 2024/11/15 10:41
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderCustomPlateNoSeqVO implements Serializable {
private static final long serialVersionUID = 5841977329049878792L;
/**
* 生产单序号
*/
private Integer orderNoSeq;
/**
* 生产单下房间序号
*/
private int roomSeq;
private Integer roomNoSeq;
/**
* 生产单下柜体序号
*/
private int bodySeq;
/**
* 生产单下加工组序号
*/
private int processGroupSeq;
private Integer bodyNoSeq;
/**
* 生产单下板件序号
*/
private int plateNoSeq;
private Integer plateNoSeq;
/**
* 生产单下房间列表
*/
private List<Room> rooms;
private List<OrderCustomPlateNoSeqRoomVO> rooms;
/**
* 生产单下柜体列表
*/
private List<OrderCustomPlateNoSeqBodyVO> bodys;
}
@Data
class Room implements Serializable {
private static final long serialVersionUID = -127388898531267048L;
/**
* 房间名
*/
private String roomNo;
/**
* 房间下板件序号
*/
private int plateNoSeq;
/**
* 房间下柜体序号
*/
private int bodySeq;
/**
* 房间下柜体列表
*/
private List<Body> bodys;
/**
* 房间下加工组序号
*/
private int processGroupSeq;
/**
* 房间下加工组列表
*/
private List<ProcessGroup> processGroups;
}
@Data
class Body implements Serializable {
private static final long serialVersionUID = 2686882895438975156L;
/**
* 柜体名
*/
private String bodyNo;
/**
* 柜体下板件序号
*/
private int plateNoSeq;
}
@Data
class ProcessGroup implements Serializable {
private static final long serialVersionUID = -6834098282222544638L;
/**
* 加工组名
*/
private String processGroupNo;
/**
* 加工组下板件序号
*/
private int plateNoSeq;
}
@@ -0,0 +1,223 @@
package com.cf.imes.module.executor.service.customplatenorule;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqBodyVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqRoomVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqVO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import com.cf.imes.module.system.enums.customplateno.ResetModeEnum;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.CUSTOM_PLATENO_GENERATE_BODY_RULE_NOT_SUPPORT_RESETMODE;
/**
* 柜体序号生成规则服务实现类
*
* @author Gqr
* @since 2024/11/19 16:35
*/
@Service("bodyNoGenerateRuleService")
public class BodyNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
@Override
public boolean match(String ruleCode) {
return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.BODYNO.getRuleCode(), ruleCode);
}
@Override
public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
// 初始化配置
initConfig(generateConfig);
// 按复位模式走不同的生成方式
ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(plateNoRule.getResetMode());
if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) {
generateConfig = generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDO);
} else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) {
generateConfig = generateNoByRoomResetMode(plateNoRule, generateConfig, plateDO);
} else {
throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_BODY_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode());
}
return generateConfig;
}
/**
* 初始化生成所需配置
*
* @param generateConfigVO
*/
private static void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) {
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO();
if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) {
orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO();
generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO);
}
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
if (CollUtil.isEmpty(rooms)) {
rooms = new ArrayList<>();
orderCustomPlateNoSeqVO.setRooms(rooms);
}
List<OrderCustomPlateNoSeqBodyVO> boyds = orderCustomPlateNoSeqVO.getBodys();
if (CollUtil.isEmpty(boyds)) {
boyds = new ArrayList<>();
orderCustomPlateNoSeqVO.setBodys(boyds);
}
}
/**
* 按生产单复位模式下的板编号生成
*
* @param orderId 生产单号
* @param plateNoRule 当前规则配置
* @param generateConfig 生成规则配置
* @param plateDO 板件列表
* @return
*/
private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
Integer incrementStep = plateNoRule.getIncrementStep();
Integer initValue = plateNoRule.getInitValue() - incrementStep;
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
// 机构下的自定义板编号序号
CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
// 生产单下柜体序号
Integer orderBodyNoSeq = Optional.ofNullable(orderCustomPlateNoSeqVO.getBodyNoSeq()).orElse(initValue);
// 生产单序号下的房间序号列表
List<OrderCustomPlateNoSeqBodyVO> bodys = orderCustomPlateNoSeqVO.getBodys();
// 上次导入的生产单号
Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo();
if (ObjectUtil.isNotNull(lastOrderNo) && ObjectUtil.notEqual(orderId, lastOrderNo)) {
// 跨单复位到初始值
orderBodyNoSeq = initValue;
}
String bodyName = plateDO.getBodyName();
// 根据柜体名获取生产单下序号json中第一层柜体列表的柜体序号
OrderCustomPlateNoSeqBodyVO bodySeqVo = getBodySeqVOByBodyName(bodyName, bodys);
// 获取当前柜体序号值
Integer bodyNoSeq = Optional.ofNullable(bodySeqVo).map(OrderCustomPlateNoSeqBodyVO::getBodyNoSeq).orElse(null);
if (bodySeqVo == null) {
// 生产单序号下柜体为空,新建柜体,取生产单下柜体序号
bodySeqVo = OrderCustomPlateNoSeqBodyVO.builder()
.bodyName(bodyName)
.build();
bodys.add(bodySeqVo);
// 累加步长
bodyNoSeq = orderBodyNoSeq + incrementStep;
// 累加后的值同步到当前生产单序号中,生产单下柜体序号累加到多少了
orderCustomPlateNoSeqVO.setBodyNoSeq(bodyNoSeq);
} else if (bodyNoSeq == null) {
// 柜体下序号为空,取生产单下房间序号
// 累加步长
bodyNoSeq = orderBodyNoSeq + incrementStep;
// 累加后的值同步到当前生产单序号中,生产单下柜体序号累加到多少了
orderCustomPlateNoSeqVO.setBodyNoSeq(bodyNoSeq);
}
// 补零
String noPartAfterFillZero = fillZero(bodyNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFillZero);
// 累加后同步到json:柜体下累加到多少了
bodySeqVo.setBodyNoSeq(bodyNoSeq);
return generateConfig;
}
/**
* 按房间号复位模式下的板编号生成
*
* @param plateNoRule
* @param generateConfig
* @param plateDO
* @return
*/
private CustomPlateNoGenerateConfigVO generateNoByRoomResetMode(CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
Integer incrementStep = plateNoRule.getIncrementStep();
Integer initValue = plateNoRule.getInitValue() - incrementStep;
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
String roomName = plateDO.getRoomName();
// 根据房间名获取生产单下序号json中的房间下的柜体序号
OrderCustomPlateNoSeqRoomVO roomSeqVo = getRoomSeqVOByRoomName(roomName, rooms);
Integer roomBodyNoRoomSeq = Optional.ofNullable(roomSeqVo)
.map(OrderCustomPlateNoSeqRoomVO::getBodyNoSeq)
.orElse(initValue);
if (roomSeqVo == null) {
// 房间为空,新建对象,设置初始值
roomSeqVo = OrderCustomPlateNoSeqRoomVO.builder()
.roomName(roomName)
.bodyNoSeq(roomBodyNoRoomSeq)
.bodys(new ArrayList<>())
.build();
rooms.add(roomSeqVo);
}
// 如果是新的柜体vo,要把累加的值记录到生产单rooms下的柜体
String bodyName = plateDO.getBodyName();
// 根据柜体名获取生产单下序号中rooms下柜体列表的柜体序号
List<OrderCustomPlateNoSeqBodyVO> roomBodys = roomSeqVo.getBodys();
OrderCustomPlateNoSeqBodyVO roomBodySeqVo = getBodySeqVOByBodyName(bodyName, roomBodys);
// 获取当前房间下柜体的序号值
Integer roomBodyNoSeq = Optional.ofNullable(roomBodySeqVo).map(OrderCustomPlateNoSeqBodyVO::getBodyNoSeq).orElse(null);
if (roomBodySeqVo == null) {
// 房间下柜体为空,新建对象,设置房间下全局柜体序号值
roomBodySeqVo = OrderCustomPlateNoSeqBodyVO.builder()
.bodyName(bodyName)
.build();
roomBodys.add(roomBodySeqVo);
// 累加步长
roomBodyNoSeq = roomBodyNoRoomSeq + incrementStep;
// 累加后的值同步到当前生产单序号中,生产单下房间中柜体累加到多少了
roomSeqVo.setBodyNoSeq(roomBodyNoSeq);
} else if (roomBodyNoSeq == null) {
// 房间下柜体序号为空,设置房间下全局柜体序号值
// 累加步长
roomBodyNoSeq = roomBodyNoRoomSeq + incrementStep;
// 累加后的值同步到当前生产单序号中,生产单下房间中柜体累加到多少了
roomSeqVo.setBodyNoSeq(roomBodyNoSeq);
}
// 补零
String noPartAfterFillZero = fillZero(roomBodyNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFillZero);
// 累加后同步到json中,room下柜体累加到多少了
roomBodySeqVo.setBodyNoSeq(roomBodyNoSeq);
return generateConfig;
}
/**
* 根据房间名从生产单序号json中获取房间序号
*
* @param roomName
* @param roomVOList
* @return
*/
private OrderCustomPlateNoSeqRoomVO getRoomSeqVOByRoomName(String roomName, List<OrderCustomPlateNoSeqRoomVO> roomVOList) {
return roomVOList.stream().filter(roomVO -> ObjectUtil.equal(roomName, roomVO.getRoomName())).findAny().orElse(null);
}
/**
* 根据柜体名从生产单序号json中获取柜体序号
*
* @param bodyName
* @param bodyVOList
* @return
*/
private OrderCustomPlateNoSeqBodyVO getBodySeqVOByBodyName(String bodyName, List<OrderCustomPlateNoSeqBodyVO> bodyVOList) {
if (CollUtil.isEmpty(bodyVOList)) {
return null;
}
return bodyVOList.stream().filter(bodyVO -> ObjectUtil.equal(bodyName, bodyVO.getBodyName())).findAny().orElse(null);
}
}
@@ -0,0 +1,33 @@
//package com.cf.imes.module.executor.service.customplatenorule;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
//import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
//import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
//import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
///**
// * 自定义规则生成实现类
// *
// * @author Gqr
// * @since 2024/11/18 16:37
// */
////@Service("customGenerateRuleService")
//public class CustomGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
// @Override
// public boolean match(String ruleCode) {
// return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.CUSTOM.getRuleCode(), ruleCode);
// }
//
// @Override
// public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, List<PlateDO> plateDOList) {
// for (PlateDO plateDO : plateDOList) {
// plateDO.getCustomPlateNo().append(plateNoRule.getValue());
// }
// return generateConfig;
// }
//
//}
@@ -0,0 +1,47 @@
package com.cf.imes.module.executor.service.customplatenorule;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
/**
* 自定义板编号生成规则服务
*
* @author Gqr
* @since 2024/11/18 16:30
*/
public interface CustomPlateNoGenerateRuleService {
/**
* 是否匹配的规则编码
*
* @param ruleCode
* @return
*/
boolean match(String ruleCode);
/**
* 生成编号
*
* @param orderId 生产单号
* @param plateDO 板材列表
* @param generateConfig 生成所需要的配置
* @return 生成后改变的配置
*/
CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO);
/**
* 左补零
*
* @param curr 当前值
* @param plateNoRule 生成规则
* @return
*/
default String fillZero(int curr, CustomPlateNoRuleVO plateNoRule) {
boolean leftFillZero = plateNoRule.isLeftFillZero();
Integer length = plateNoRule.getLength();
if (leftFillZero) {
return String.format("%0" + length + "d", curr);
}
return String.valueOf(curr);
}
}
@@ -0,0 +1,33 @@
//package com.cf.imes.module.executor.service.customplatenorule;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
//import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
//import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
//import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
//import org.springframework.stereotype.Service;
//
//import java.time.format.DateTimeFormatter;
//import java.util.List;
//
///**
// * 日期规则生成服务实现类
// *
// * @author Gqr
// * @since 2024/11/18 16:46
// */
//@Service("dateGenerateRuleService")
//public class DateGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
// @Override
// public boolean match(String ruleCode) {
// return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.DATE.getRuleCode(), ruleCode);
// }
//
// @Override
// public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, List<PlateDO> plateDOList) {
// for (PlateDO plateDO : plateDOList) {
// plateDO.getCustomPlateNo().append(plateNoRule.getNow().format(DateTimeFormatter.ofPattern(plateNoRule.getValue())));
// }
// return generateConfig;
// }
//}
@@ -0,0 +1,185 @@
package com.cf.imes.module.executor.service.customplatenorule;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqVO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import com.cf.imes.module.system.enums.customplateno.ResetModeEnum;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.CUSTOM_PLATENO_GENERATE_ORDERNO_RULE_NOT_SUPPORT_RESETMODE;
/**
* 生产单序号生成规则服务实现类
*
* @author Gqr
* @since 2024/11/18 17:18
*/
@Service("orderNoGenerateRuleService")
public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
private static final DateTimeFormatter YEAR_FORMATTER = DateTimeFormatter.ofPattern("yyyy");
private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMM");
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
@Override
public boolean match(String ruleCode) {
return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ORDERNO.getRuleCode(), ruleCode);
}
/**
* 初始化生成所需配置
*
* @param generateConfigVO
*/
private static void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) {
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO();
if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) {
orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO();
generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO);
}
}
@Override
public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
// 初始化配置
initConfig(generateConfig);
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
Integer orderNoSeq = orderCustomPlateNoSeqVO.getOrderNoSeq();
// 当前导入已有序号的,生产单内生产单序号不会再变直接用
if (ObjectUtil.isNotNull(orderNoSeq)) {
// 补零
String noPartAfterFill = this.fillZero(orderNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFill);
return generateConfig;
}
// 机构下的自定义板编号序号
CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
// 获取当前序号值
int currOrderNoSeq = Optional.ofNullable(orgCustomPlateNoSeqRespDTO.getOrderNoSeq()).orElse(plateNoRule.getInitValue() - plateNoRule.getIncrementStep());
// 上次导入的生产单号
Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo();
if (ObjectUtil.isNull(lastOrderNo) || ObjectUtil.notEqual(orderId, lastOrderNo)) {
// 跨单
// 根据复位模式计算序号
currOrderNoSeq = generateNoByResetMode(currOrderNoSeq, ResetModeEnum.getByMode(plateNoRule.getResetMode()), plateNoRule, orgCustomPlateNoSeqRespDTO);
}
// 补零
String noPartAfterFill = this.fillZero(currOrderNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFill);
// 累加后的值同步到当前生产单序号和机构序号中
orderCustomPlateNoSeqVO.setOrderNoSeq(currOrderNoSeq);
orgCustomPlateNoSeqRespDTO.setOrderNoSeq(currOrderNoSeq);
return generateConfig;
}
/**
* 基于复位模式的板编号生成
*
* @param orderNoSeq
* @param resetModeEnum
* @param plateNoRule
* @param orgCustomPlateNoSeqRespDTO
* @return 循环累加后的序号
*/
private int generateNoByResetMode(int orderNoSeq, ResetModeEnum resetModeEnum, CustomPlateNoRuleVO plateNoRule, CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO) {
// 机构全局序号下的上一次年月日记录
int year = orgCustomPlateNoSeqRespDTO.getLastYear();
int month = orgCustomPlateNoSeqRespDTO.getLastMonth();
int day = orgCustomPlateNoSeqRespDTO.getLastDay();
// 根据不同复位模式生成序号
if (ObjectUtil.equal(ResetModeEnum.DIGIT, resetModeEnum)) {
orderNoSeq = resetByLength(orderNoSeq, plateNoRule);
} else if (ObjectUtil.equal(ResetModeEnum.YEAR, resetModeEnum)) {
orderNoSeq = resetByYear(orderNoSeq, year, plateNoRule);
} else if (ObjectUtil.equal(ResetModeEnum.MONTH, resetModeEnum)) {
orderNoSeq = resetByMonth(orderNoSeq, month, plateNoRule);
} else if (ObjectUtil.equal(ResetModeEnum.DAY, resetModeEnum)) {
orderNoSeq = resetByDay(orderNoSeq, day, plateNoRule);
} else {
throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_ORDERNO_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode());
}
return orderNoSeq;
}
/**
* 按位数复位
*
* @param curr 当前值
* @param plateNoRule 规则配置
*/
private int resetByLength(int curr, CustomPlateNoRuleVO plateNoRule) {
// 位数下的最大值 10的length次方-1
int maxNum = (int) (Math.pow(10, plateNoRule.getLength()) - 1);
// 加上步长后的下一个序号
int nextValue = curr + plateNoRule.getIncrementStep();
// 超过最大值复位到初始值,没超过就继续下一个
if (nextValue > maxNum) {
return plateNoRule.getInitValue();
} else {
return nextValue;
}
}
/**
* 按年复位
*
* @param curr
* @param year
* @param plateNoRule
* @return
*/
private int resetByYear(int curr, int year, CustomPlateNoRuleVO plateNoRule) {
LocalDateTime now = plateNoRule.getNow();
Integer initValue = plateNoRule.getInitValue();
if (ObjectUtil.notEqual(String.valueOf(year), now.format(YEAR_FORMATTER))) {
return initValue;
}
return curr + plateNoRule.getIncrementStep();
}
/**
* 按月复位
*
* @param curr
* @param month
* @param plateNoRule
* @return
*/
private int resetByMonth(int curr, int month, CustomPlateNoRuleVO plateNoRule) {
LocalDateTime now = plateNoRule.getNow();
Integer initValue = plateNoRule.getInitValue();
if (ObjectUtil.notEqual(String.valueOf(month), now.format(MONTH_FORMATTER))) {
return initValue;
}
return curr + plateNoRule.getIncrementStep();
}
/**
* 按天复位
*
* @param curr
* @param day
* @param plateNoRule
* @return
*/
private int resetByDay(int curr, int day, CustomPlateNoRuleVO plateNoRule) {
LocalDateTime now = plateNoRule.getNow();
Integer initValue = plateNoRule.getInitValue();
if (ObjectUtil.notEqual(String.valueOf(day), now.format(DAY_FORMATTER))) {
return initValue;
}
return curr + plateNoRule.getIncrementStep();
}
}
@@ -0,0 +1,311 @@
package com.cf.imes.module.executor.service.customplatenorule;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqBodyVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqRoomVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqVO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import com.cf.imes.module.system.enums.customplateno.ResetModeEnum;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.CUSTOM_PLATENO_GENERATE_PLATE_RULE_NOT_SUPPORT_RESETMODE;
/**
* @author Gqr
* @since 2024/11/20 15:28
*/
@Service("plateNoGenerateRuleService")
public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
private static final DateTimeFormatter YEAR_FORMATTER = DateTimeFormatter.ofPattern("yyyy");
private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMM");
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
@Override
public boolean match(String ruleCode) {
return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.PLATENO.getRuleCode(), ruleCode);
}
@Override
public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
// 初始化配置
initConfig(generateConfig);
// 按复位模式走不同的生成方式
ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(plateNoRule.getResetMode());
if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) {
return generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDO);
} else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) {
return generateNoByRoomResetMode(plateNoRule, generateConfig, plateDO);
} else if (ObjectUtil.equal(ResetModeEnum.BODY, resetModeEnum)) {
return generateNoByBodyResetMode(plateNoRule, generateConfig, plateDO);
} else if (ObjectUtil.equal(ResetModeEnum.YEAR, resetModeEnum) || ObjectUtil.equal(ResetModeEnum.MONTH, resetModeEnum) || ObjectUtil.equal(ResetModeEnum.DAY, resetModeEnum)) {
return generateNoByDateResetMode(resetModeEnum, plateNoRule, generateConfig, plateDO);
} else {
throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_PLATE_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode());
}
}
/**
* 按年/月/日复位模式下的板编号生成
*/
private CustomPlateNoGenerateConfigVO generateNoByDateResetMode(ResetModeEnum resetModeEnum, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
// 机构下的自定义板编号序号
CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
// 上一次自定义编号生成的年月日
int year = orgCustomPlateNoSeqRespDTO.getLastYear();
int month = orgCustomPlateNoSeqRespDTO.getLastMonth();
int day = orgCustomPlateNoSeqRespDTO.getLastDay();
// 从全局配置获取当前序号,取不到用初始值
Integer orderNoSeq = orgCustomPlateNoSeqRespDTO.getPlateNoSeq();
if (ObjectUtil.isNull(orderNoSeq)) {
orderNoSeq = plateNoRule.getInitValue() - plateNoRule.getIncrementStep();
}
if (ObjectUtil.equal(ResetModeEnum.YEAR, resetModeEnum)) {
orderNoSeq = resetByYear(orderNoSeq, year, plateNoRule);
} else if (ObjectUtil.equal(ResetModeEnum.MONTH, resetModeEnum)) {
orderNoSeq = resetByMonth(orderNoSeq, month, plateNoRule);
} else if (ObjectUtil.equal(ResetModeEnum.DAY, resetModeEnum)) {
orderNoSeq = resetByDay(orderNoSeq, day, plateNoRule);
}
// 跨板件累加步长,补零
orderNoSeq += plateNoRule.getIncrementStep();
String noPartAfterFillZero = fillZero(orderNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFillZero);
orgCustomPlateNoSeqRespDTO.setPlateNoSeq(orderNoSeq);
return generateConfig;
}
/**
* 按生产单复位模式下的板编号生成
*
* @param orderId
* @param plateNoRule
* @param generateConfig
* @param plateDO
*/
private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
Integer incrementStep = plateNoRule.getIncrementStep();
Integer initValue = plateNoRule.getInitValue() - incrementStep;
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
// 机构下的自定义板编号序号
CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
// 获取当前生产单下板件序号
Integer orderPlateNoSeq = Optional.ofNullable(orderCustomPlateNoSeqVO.getPlateNoSeq()).orElse(initValue);
// 上次导入的生产单号
Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo();
if (ObjectUtil.isNotNull(lastOrderNo) && ObjectUtil.notEqual(orderId, lastOrderNo)) {
// 跨单复位到初始值
orderPlateNoSeq = initValue;
}
// 跨板件累加步长,补零
orderPlateNoSeq += incrementStep;
plateDO.getCustomPlateNo().append(fillZero(orderPlateNoSeq, plateNoRule));
// 累加后的值同步到当前生产单序号中
orderCustomPlateNoSeqVO.setPlateNoSeq(orderPlateNoSeq);
return generateConfig;
}
/**
* 按房间复位模式下的板编号生成
*
* @param plateNoRule
* @param generateConfig
* @param plateDO
* @return
*/
private CustomPlateNoGenerateConfigVO generateNoByRoomResetMode(CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
Integer incrementStep = plateNoRule.getIncrementStep();
Integer initValue = plateNoRule.getInitValue() - incrementStep;
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
String roomName = plateDO.getRoomName();
// 根据房间名获取生产单下序号json中的房间下的加工组序号
OrderCustomPlateNoSeqRoomVO roomSeqVo = getSeqRoomByRoomName(roomName, rooms);
// 为空初始化,加入列表
if (roomSeqVo == null) {
roomSeqVo = OrderCustomPlateNoSeqRoomVO.builder()
.roomName(roomName)
.bodys(new ArrayList<>())
.build();
rooms.add(roomSeqVo);
}
// 获取当前房间下板件序号
// 累加步长
Integer roomPlateNoSeq = Optional.ofNullable(roomSeqVo.getPlateNoSeq())
.orElse(initValue) + incrementStep;
// 累加后的值同步到当前生产单序号中
roomSeqVo.setPlateNoSeq(roomPlateNoSeq);
// 补零
plateDO.getCustomPlateNo().append(fillZero(roomPlateNoSeq, plateNoRule));
return generateConfig;
}
/**
* 根据房间名从生产单序号json中获取房间序号列表
*
* @param roomName
* @param roomVOList
* @return
*/
private OrderCustomPlateNoSeqRoomVO getSeqRoomByRoomName(String roomName, List<OrderCustomPlateNoSeqRoomVO> roomVOList) {
return roomVOList.stream().filter(roomVO -> ObjectUtil.equal(roomName, roomVO.getRoomName())).findAny().orElse(null);
}
/**
* 按柜体复位模式下的板编号生成
*
* @param plateNoRule
* @param generateConfig
* @param plateDO
* @return
*/
private CustomPlateNoGenerateConfigVO generateNoByBodyResetMode(CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
Integer incrementStep = plateNoRule.getIncrementStep();
Integer initValue = plateNoRule.getInitValue() - incrementStep;
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
String roomName = plateDO.getRoomName();
// 根据房间名获取生产单下序号json中的房间下的加工组序号
OrderCustomPlateNoSeqRoomVO roomSeqVo = getSeqRoomByRoomName(roomName, rooms);
if (ObjectUtil.isNull(roomSeqVo)) {
// 房间为空,new房间
roomSeqVo = OrderCustomPlateNoSeqRoomVO.
builder()
.roomName(roomName)
.bodys(new ArrayList<>())
.build();
rooms.add(roomSeqVo);
}
String bodyName = plateDO.getBodyName();
// 根据柜体名获取生产单下序号json中的房间下的加工组序号
OrderCustomPlateNoSeqBodyVO bodySeqVO = getBodySeqByBodyName(bodyName, roomSeqVo);
if (bodySeqVO == null) {
// 柜体为空,new柜体
bodySeqVO = OrderCustomPlateNoSeqBodyVO.builder()
.bodyName(bodyName)
.build();
roomSeqVo.getBodys().add(bodySeqVO);
}
// 累加步长
// 获取柜体下的板件序号
Integer bodyPlateNoSeq = Optional.ofNullable(bodySeqVO.getPlateNoSeq()).orElse(initValue) + incrementStep;
// 累加后的值同步到当前生产单序号中
bodySeqVO.setPlateNoSeq(bodyPlateNoSeq);
// 补零
String noPartAfterFillZero = fillZero(bodyPlateNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFillZero);
return generateConfig;
}
/**
* 根据房间名从生产单序号json中获取房间序号列表
*
* @param bodyName
* @param roomVO
* @return
*/
private OrderCustomPlateNoSeqBodyVO getBodySeqByBodyName(String bodyName, OrderCustomPlateNoSeqRoomVO roomVO) {
List<OrderCustomPlateNoSeqBodyVO> bodys = roomVO.getBodys();
if (ObjectUtil.isNotNull(bodys)) {
for (OrderCustomPlateNoSeqBodyVO bodyVO : bodys) {
if (ObjectUtil.equal(bodyVO.getBodyName(), bodyName)) {
return bodyVO;
}
}
} else {
bodys = new ArrayList<>();
roomVO.setBodys(bodys);
}
return null;
}
/**
* 初始化生成所需配置
*
* @param generateConfigVO
*/
private void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) {
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO();
if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) {
orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO();
generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO);
}
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
if (CollUtil.isEmpty(rooms)) {
rooms = new ArrayList<>();
orderCustomPlateNoSeqVO.setRooms(rooms);
}
}
/**
* 按年复位
*
* @param curr
* @param year
* @param plateNoRule
* @return
*/
private int resetByYear(int curr, int year, CustomPlateNoRuleVO plateNoRule) {
LocalDateTime now = plateNoRule.getNow();
Integer initValue = plateNoRule.getInitValue();
if (ObjectUtil.notEqual(String.valueOf(year), now.format(YEAR_FORMATTER))) {
return initValue;
}
return curr + plateNoRule.getIncrementStep();
}
/**
* 按月复位
*
* @param curr
* @param month
* @param plateNoRule
* @return
*/
private int resetByMonth(int curr, int month, CustomPlateNoRuleVO plateNoRule) {
LocalDateTime now = plateNoRule.getNow();
Integer initValue = plateNoRule.getInitValue();
if (ObjectUtil.notEqual(String.valueOf(month), now.format(MONTH_FORMATTER))) {
return initValue;
}
return curr + plateNoRule.getIncrementStep();
}
/**
* 按天复位
*
* @param curr
* @param day
* @param plateNoRule
* @return
*/
private int resetByDay(int curr, int day, CustomPlateNoRuleVO plateNoRule) {
LocalDateTime now = plateNoRule.getNow();
Integer initValue = plateNoRule.getInitValue();
if (ObjectUtil.notEqual(String.valueOf(day), now.format(DAY_FORMATTER))) {
return initValue;
}
return curr + plateNoRule.getIncrementStep();
}
}
@@ -0,0 +1,240 @@
//package com.cf.imes.module.executor.service.customplatenorule;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.util.ObjectUtil;
//import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
//import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
//import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
//import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
//import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqProcessGroupVO;
//import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqRoomVO;
//import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqVO;
//import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqRespDTO;
//import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
//import com.cf.imes.module.system.enums.customplateno.ResetModeEnum;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.Optional;
//import java.util.concurrent.atomic.AtomicReference;
//import java.util.stream.Collectors;
//
//import static com.cf.imes.module.executor.enums.ErrorCodeConstants.CUSTOM_PLATENO_GENERATE_PROCESSGROUP_RULE_NOT_SUPPORT_RESETMODE;
//
///**
// * 加工组序号生成规则服务实现类
// *
// * @author Gqr
// * @since 2024/11/20 13:42
// */
//@Service("processGroupNoGenerateRuleService")
//public class ProcessGroupNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
// @Override
// public boolean match(String ruleCode) {
// return false;
// }
//
// @Override
// public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, List<PlateDO> plateDOList) {
// // 初始化配置
// initConfig(generateConfig);
// // 按复位模式走不同的生成方式
// ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(plateNoRule.getResetMode());
// if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) {
// generateConfig = generateNoByOrderResetMode(orderId, plateNoRule, generateConfig, plateDOList);
// } else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) {
// generateConfig = generateNoByRoomResetMode(plateNoRule, generateConfig, plateDOList);
// } else {
// throw ServiceExceptionUtil.exception(CUSTOM_PLATENO_GENERATE_PROCESSGROUP_RULE_NOT_SUPPORT_RESETMODE, plateNoRule.getResetMode());
// }
// return generateConfig;
// }
//
// /**
// * 初始化生成所需配置
// *
// * @param generateConfigVO
// */
// private static void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) {
// OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO();
// if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) {
// orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO();
// generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO);
// }
// List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
// if (CollUtil.isEmpty(rooms)) {
// rooms = new ArrayList<>();
// orderCustomPlateNoSeqVO.setRooms(rooms);
// }
// List<OrderCustomPlateNoSeqProcessGroupVO> processGroups = orderCustomPlateNoSeqVO.getProcessGroups();
// if (CollUtil.isEmpty(processGroups)) {
// processGroups = new ArrayList<>();
// orderCustomPlateNoSeqVO.setProcessGroups(processGroups);
// }
// }
//
//
// /**
// * 按生产单复位模式下的板编号生成
// *
// * @param orderId 生产单号
// * @param plateNoRule 当前规则配置
// * @param generateConfig 生成规则配置
// * @param plateDOList 板件列表
// * @return
// */
// private CustomPlateNoGenerateConfigVO generateNoByOrderResetMode(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, List<PlateDO> plateDOList) {
// Integer initValue = plateNoRule.getInitValue() - plateNoRule.getIncrementStep();
// // 生产单下的序号
// OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
// // 机构下的自定义板编号序号
// CustomPlateNoSeqRespDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
// // 生产单下加工组序号
// Integer orderProcessGroupNoSeq = null;
// List<OrderCustomPlateNoSeqProcessGroupVO> processGroups = orderCustomPlateNoSeqVO.getProcessGroups();
// if (ObjectUtil.equal(orderId, orgCustomPlateNoSeqRespDTO.getLastOrderNo())) {
// // 当次导入和上次导入是同一个生产单
// // 取之前的生产单下加工组序号,没有就用初始值
// orderProcessGroupNoSeq = Optional.ofNullable(orderCustomPlateNoSeqVO.getProcessGroupNoSeq()).orElse(initValue);
// }
// // 基于加工组名分组
// Map<String, List<PlateDO>> processGroupMap = plateDOList.stream().collect(Collectors.groupingBy(PlateDO::getProcessGroupName, Collectors.toList()));
// for (Map.Entry<String, List<PlateDO>> processGroupEntry : processGroupMap.entrySet()) {
// // 如果是新的加工组vo,要把累加的值记录到生产单
// boolean needRecordToOrder = false;
// String processGroupName = processGroupEntry.getKey();
// // 根据加工组名获取生产单下序号json中第一层加工组列表的加工组序号
// OrderCustomPlateNoSeqProcessGroupVO processSeqVO = getProcessGroupSeqVOByProcessGroupName(processGroupName, processGroups);
// // 获取当前加工组序号值
// Integer processGroupNoSeq = Optional.ofNullable(processSeqVO).map(OrderCustomPlateNoSeqProcessGroupVO::getProcessGroupNoSeq).orElse(initValue);
// if (processSeqVO == null) {
// // 房间为空,新建对象,设置初始值
// processSeqVO = OrderCustomPlateNoSeqProcessGroupVO.builder()
// .processGroupName(processGroupName)
// .build();
// processGroups.add(processSeqVO);
// needRecordToOrder = true;
// }
//
// List<PlateDO> processGroupPlateList = processGroupEntry.getValue();
// processGroupNoSeq += plateNoRule.getIncrementStep();
// // 跨柜体累加步长,补零
// String noPartAfterFillZero = fillZero(processGroupNoSeq, plateNoRule);
// processGroupPlateList.forEach(processGroupPlate -> processGroupPlate.getCustomPlateNo().append(noPartAfterFillZero));
// // 累加后同步到json:加工组下累加到多少了
// processSeqVO.setProcessGroupNoSeq(processGroupNoSeq);
// if (needRecordToOrder) {
// // 新的房间下加工组vo,累加值同步到房间中
// orderProcessGroupNoSeq = processGroupNoSeq;
// }
// }
// // 累加后的值同步到当前生产单序号中,生产单下加工组序号累加到多少了
// orderCustomPlateNoSeqVO.setProcessGroupNoSeq(orderProcessGroupNoSeq);
// return generateConfig;
// }
//
// /**
// * 按房间号复位模式下的板编号生成
// *
// * @param plateNoRule
// * @param generateConfig
// * @param plateDOList
// * @return
// */
// private CustomPlateNoGenerateConfigVO generateNoByRoomResetMode(CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, List<PlateDO> plateDOList) {
// Integer initValue = plateNoRule.getInitValue() - plateNoRule.getIncrementStep();
// // 生产单下的序号
// OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
// List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
// // 基于房间名分组
// Map<String, List<PlateDO>> roomGroupMap = plateDOList.stream().collect(Collectors.groupingBy(PlateDO::getRoomName, Collectors.toList()));
//
// for (Map.Entry<String, List<PlateDO>> roomEntry : roomGroupMap.entrySet()) {
// List<PlateDO> roomPlateList = roomEntry.getValue();
// String roomName = roomEntry.getKey();
// // 根据房间名获取生产单下序号json中的房间下的柜体序号
// OrderCustomPlateNoSeqRoomVO roomSeqVo = getRoomSeqVOByRoomName(roomName, rooms);
// Integer roomProcessGroupNoRoomSeq = Optional.ofNullable(roomSeqVo)
// .map(OrderCustomPlateNoSeqRoomVO::getProcessGroupNoSeq)
// .orElse(initValue);
//
// if (roomSeqVo == null) {
// // 房间为空,新建对象,设置初始值
// roomSeqVo = OrderCustomPlateNoSeqRoomVO.builder()
// .roomName(roomName)
// .processGroupNoSeq(roomProcessGroupNoRoomSeq)
// .processGroups(new ArrayList<>())
// .build();
// rooms.add(roomSeqVo);
// }
//
// // 基于加工组分组
// Map<String, List<PlateDO>> roomProcessGroupMap = roomPlateList.stream()
// .collect(Collectors.groupingBy(PlateDO::getProcessGroupName, Collectors.toList()));
// for (Map.Entry<String, List<PlateDO>> roomPrcesssGroupEntry : roomProcessGroupMap.entrySet()) {
// // 如果是新的柜体vo,要把累加的值记录到生产单rooms下的柜体
// boolean needRecordToOrder = false;
// String processGroupName = roomPrcesssGroupEntry.getKey();
// // 根据加工组名获取生产单下序号中rooms下加工组列表的加工组序号
// List<OrderCustomPlateNoSeqProcessGroupVO> roomProcessGroups = roomSeqVo.getProcessGroups();
// OrderCustomPlateNoSeqProcessGroupVO roomProcessGroupSeqVo = getProcessGroupSeqVOByProcessGroupName(processGroupName, roomProcessGroups);
// // 获取当前房间下加工组的序号值
// Integer roomProcessGroupNoSeq = Optional.ofNullable(roomProcessGroupSeqVo).map(OrderCustomPlateNoSeqProcessGroupVO::getProcessGroupNoSeq).orElse(null);
// if (roomProcessGroupSeqVo == null) {
// // 房间下柜体为空,新建对象,设置初始值
// roomProcessGroupSeqVo = OrderCustomPlateNoSeqProcessGroupVO.builder()
// .processGroupName(processGroupName)
// .build();
// roomProcessGroups.add(roomProcessGroupSeqVo);
// roomProcessGroupNoSeq= roomProcessGroupNoRoomSeq;
// needRecordToOrder = true;
// } else if(roomProcessGroupNoSeq == null){
// roomProcessGroupNoSeq= roomProcessGroupNoRoomSeq;
// needRecordToOrder = true;
// }
//
// // 跨加工组累加步长
// roomProcessGroupNoSeq += plateNoRule.getIncrementStep();
// // 补零
// String noPartAfterFillZero = fillZero(roomProcessGroupNoSeq, plateNoRule);
// roomPrcesssGroupEntry.getValue().forEach(roomPrcesssGroupPlate -> roomPrcesssGroupPlate.getCustomPlateNo().append(noPartAfterFillZero));
// // 累加后同步到json中,room下柜体累加到多少了
// roomProcessGroupSeqVo.setProcessGroupNoSeq(roomProcessGroupNoSeq);
// if (needRecordToOrder) {
// // 新的房间下柜体vo,累加值同步到房间中
// roomProcessGroupNoRoomSeq = roomProcessGroupNoSeq;
// }
// }
// // 累加后的值同步到当前生产单序号中,生产单下房间中加工组累加到多少了
// roomSeqVo.setProcessGroupNoSeq(roomProcessGroupNoRoomSeq);
// }
// return generateConfig;
// }
//
// /**
// * 根据房间名从生产单序号json中获取房间序号列表
// *
// * @param roomName
// * @param roomVOList
// * @return
// */
// private OrderCustomPlateNoSeqRoomVO getRoomSeqVOByRoomName(String roomName, List<OrderCustomPlateNoSeqRoomVO> roomVOList) {
// return roomVOList.stream().filter(roomVO -> ObjectUtil.equal(roomName, roomVO.getRoomName())).findAny().orElse(null);
// }
//
// /**
// * 根据柜体名从生产单序号json中获取柜体序号列表
// *
// * @param processGroupName
// * @param processGroupVOList
// * @return
// */
// private OrderCustomPlateNoSeqProcessGroupVO getProcessGroupSeqVOByProcessGroupName(String processGroupName, List<OrderCustomPlateNoSeqProcessGroupVO> processGroupVOList) {
// if (CollUtil.isEmpty(processGroupVOList)) {
// return null;
// }
// return processGroupVOList.stream().filter(processGroupVO -> ObjectUtil.equal(processGroupName, processGroupVO.getProcessGroupName())).findAny().orElse(null);
// }
//}
@@ -0,0 +1,107 @@
package com.cf.imes.module.executor.service.customplatenorule;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.executor.service.customplateno.vo.CustomPlateNoRuleVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqRoomVO;
import com.cf.imes.module.executor.service.customplateno.vo.OrderCustomPlateNoSeqVO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* 房间序号生成规则服务实现类
*
* @author Gqr
* @since 2024/11/19 13:41
*/
@Service("roomNoGenerateRuleService")
public class RoomNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleService {
@Override
public boolean match(String ruleCode) {
return ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ROOMNO.getRuleCode(), ruleCode);
}
@Override
public CustomPlateNoGenerateConfigVO generateNo(Long orderId, CustomPlateNoRuleVO plateNoRule, CustomPlateNoGenerateConfigVO generateConfig, PlateDO plateDO) {
Integer incrementStep = plateNoRule.getIncrementStep();
Integer initValue = plateNoRule.getInitValue() - incrementStep;
// 初始化配置
initConfig(generateConfig);
// 生产单下的序号
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfig.getOrderCustomPlateNoSeqVO();
// 机构下的自定义板编号序号
CustomPlateNoSeqDTO orgCustomPlateNoSeqRespDTO = generateConfig.getOrgCustomPlateNoSeqRespDTO();
// 生产单下房间序号
Integer orderRoomNoSeq = Optional.ofNullable(orderCustomPlateNoSeqVO.getRoomNoSeq()).orElse(initValue);
// 生产单序号下的的房间序号列表
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
// 上次导入的生产单号
Long lastOrderNo = orgCustomPlateNoSeqRespDTO.getLastOrderNo();
if (ObjectUtil.isNotNull(lastOrderNo) && ObjectUtil.notEqual(orderId, lastOrderNo)) {
// 跨单复位到初始值
orderRoomNoSeq = initValue;
}
String roomName = plateDO.getRoomName();
// 根据房间名获取生产单下序号json中的房间下的柜体序号
OrderCustomPlateNoSeqRoomVO roomSeqVo = getRoomSeqVOByRoomName(roomName, rooms);
// 获取当前房间序号值
Integer roomNoSeq = Optional.ofNullable(roomSeqVo).map(OrderCustomPlateNoSeqRoomVO::getRoomNoSeq).orElse(null);
if (roomSeqVo == null) {
// 房间为空,新建房间,取生产单下房间序号
roomSeqVo = OrderCustomPlateNoSeqRoomVO.builder()
.roomName(roomName)
.bodys(new ArrayList<>())
.build();
rooms.add(roomSeqVo);
// 累加步长
roomNoSeq = orderRoomNoSeq + incrementStep;
// 累加后的值同步到当前生产单序号中,生产单下房间序号累加到多少了
orderCustomPlateNoSeqVO.setRoomNoSeq(roomNoSeq);
} else if (roomNoSeq == null) {
// 房间下序号为空,取生产单下房间序号
// 累加步长
roomNoSeq = orderRoomNoSeq + incrementStep;
// 累加后的值同步到当前生产单序号中,生产单下房间序号累加到多少了
orderCustomPlateNoSeqVO.setRoomNoSeq(roomNoSeq);
}
// 补零
String noPartAfterFillZero = fillZero(roomNoSeq, plateNoRule);
plateDO.getCustomPlateNo().append(noPartAfterFillZero);
// 累加后同步到json:房间下累加到多少了
roomSeqVo.setRoomNoSeq(roomNoSeq);
return generateConfig;
}
/**
* 初始化生成所需配置
*
* @param generateConfigVO
*/
private static void initConfig(CustomPlateNoGenerateConfigVO generateConfigVO) {
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = generateConfigVO.getOrderCustomPlateNoSeqVO();
if (ObjectUtil.isNull(orderCustomPlateNoSeqVO)) {
orderCustomPlateNoSeqVO = new OrderCustomPlateNoSeqVO();
generateConfigVO.setOrderCustomPlateNoSeqVO(orderCustomPlateNoSeqVO);
}
}
/**
* 根据房间名从生产单序号json中获取房间序号列表
*
* @param roomName
* @param roomVOList
* @return
*/
private OrderCustomPlateNoSeqRoomVO getRoomSeqVOByRoomName(String roomName, List<OrderCustomPlateNoSeqRoomVO> roomVOList) {
return roomVOList.stream().filter(roomVO -> ObjectUtil.equal(roomName, roomVO.getRoomName())).findAny().orElse(null);
}
}
@@ -1,12 +1,14 @@
package com.cf.imes.module.system.api.customplateno;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqRespDTO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
@@ -22,5 +24,9 @@ public interface CustomPlateNoSeqApi {
@GetMapping(PREFIX + "/organ")
@Operation(summary = "获取组织下自定义版编号序号")
CommonResult<CustomPlateNoSeqRespDTO> getOrgCustomPlateNoSeq();
CommonResult<CustomPlateNoSeqDTO> getOrgCustomPlateNoSeq();
@PostMapping(PREFIX + "/organ")
@Operation(summary = "更新组织下自定义版编号序号")
CommonResult<Boolean> modifyOrgCustomPlateNoSeq(@RequestBody CustomPlateNoSeqDTO customPlateNoSeqDTO);
}
@@ -15,7 +15,7 @@ import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CustomPlateNoSeqRespDTO implements Serializable {
public class CustomPlateNoSeqDTO implements Serializable {
private static final long serialVersionUID = -3415615478757941611L;
private Long id;
@@ -48,15 +48,15 @@ public class CustomPlateNoSeqRespDTO implements Serializable {
/**
* 上次年
*/
private int lastYear;
private Integer lastYear;
/**
* 上次月
*/
private int lastMonth;
private Integer lastMonth;
/**
* 上次天
*/
private int lastDay;
private Integer lastDay;
}
@@ -349,5 +349,5 @@ public class ErrorCodeConstants {
//=========== 系统配置 1-002-040-000 ============
public static final ErrorCode SYSTEM_CONFIG_NOT_EXISTS = new ErrorCode(1_002_040_001, "系统配置不存在");
public static final ErrorCode SYSTEM_CONFIG_TYPE_NOT_SUPPORT = new ErrorCode(1_002_040_002, "不支持的系统配置类型");
public static final ErrorCode SYSTEM_CONFIG_CUSTOM_BOARD_NO_RULE_SAVE_CHECK_ERROR = new ErrorCode(1_002_040_003, "系统配置:自定义板编号保存解析失败,请检查配置规则或联系客服");
public static final ErrorCode SYSTEM_CONFIG_CUSTOM_PLATE_NO_RULE_SAVE_CHECK_ERROR = new ErrorCode(1_002_040_003, "系统配置:自定义板编号保存解析失败,请检查配置规则或联系客服");
}
@@ -1,6 +1,7 @@
package com.cf.imes.module.system.enums.config;
package com.cf.imes.module.system.enums.customplateno;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 自定义板编号规则编码枚举
@@ -9,7 +10,7 @@ import lombok.AllArgsConstructor;
* @since 2024/11/11 15:20
*/
@AllArgsConstructor
public enum CustBoardRuleCodeEnum {
public enum CustomPlateNoRuleCodeEnum {
/**
* 自定义
*/
@@ -38,22 +39,19 @@ public enum CustBoardRuleCodeEnum {
/**
* 柜体序号
*/
BODYNO("bodyNo"),
/**
* 加工组序号
*/
PROCESSGROUP("processGroupNo");
BODYNO("bodyNo");
@Getter
private String ruleCode;
/**
* 是否匹配
*
* @param ruleCode
* @return
*/
public static CustBoardRuleCodeEnum match(String ruleCode) {
for (CustBoardRuleCodeEnum codeEnum : CustBoardRuleCodeEnum.values()) {
public static CustomPlateNoRuleCodeEnum match(String ruleCode) {
for (CustomPlateNoRuleCodeEnum codeEnum : CustomPlateNoRuleCodeEnum.values()) {
if (codeEnum.ruleCode.equals(ruleCode)) {
return codeEnum;
}
@@ -0,0 +1,70 @@
package com.cf.imes.module.system.enums.customplateno;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author Gqr
* @since 2024/11/19 9:40
*/
@AllArgsConstructor
public enum ResetModeEnum {
/**
* 不清零,累加
*/
ACCUMULATION(0),
/**
* 按位数
*/
DIGIT(1),
/**
* 按年
*/
YEAR(2),
/**
* 按月
*/
MONTH(3),
/**
* 按天
*/
DAY(4),
/**
* 按生产单
*/
ORDER(5),
/**
* 按房间
*/
ROOM(6),
/**
* 按柜体
*/
BODY(7);
@Getter
private int mode;
/**
* 根据mode获取对应枚举
*
* @param mode
* @return
*/
public static ResetModeEnum getByMode(int mode) {
for (ResetModeEnum modeEnum : ResetModeEnum.values()) {
if (ObjectUtil.equal(modeEnum.getMode(), mode)) {
return modeEnum;
}
}
return null;
}
}
@@ -2,7 +2,8 @@ package com.cf.imes.module.system.api.customplateno;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqRespDTO;
import com.cf.imes.module.system.api.customplateno.dto.CustomPlateNoSeqDTO;
import com.cf.imes.module.system.dal.dataobject.customplateno.CustomPlateNoSeqDO;
import com.cf.imes.module.system.service.customplateno.CustomPlateNoSeqService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
@@ -23,7 +24,12 @@ public class CustomPlateNoSeqApiImpl implements CustomPlateNoSeqApi {
private CustomPlateNoSeqService customPlateNoSeqService;
@Override
public CommonResult<CustomPlateNoSeqRespDTO> getOrgCustomPlateNoSeq() {
return CommonResult.success(BeanUtils.toBean(customPlateNoSeqService.getOrgCustomPlateNoSeq(), CustomPlateNoSeqRespDTO.class));
public CommonResult<CustomPlateNoSeqDTO> getOrgCustomPlateNoSeq() {
return CommonResult.success(BeanUtils.toBean(customPlateNoSeqService.getOrgCustomPlateNoSeq(), CustomPlateNoSeqDTO.class));
}
@Override
public CommonResult<Boolean> modifyOrgCustomPlateNoSeq(CustomPlateNoSeqDTO customPlateNoSeqDTO) {
return CommonResult.success(customPlateNoSeqService.modifyOrgCustomPlateNoSeq(BeanUtils.toBean(customPlateNoSeqDTO, CustomPlateNoSeqDO.class)));
}
}
@@ -17,11 +17,11 @@ import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigSaveReqV
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigUpdateStatusReqVO;
import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDO;
import com.cf.imes.module.system.dal.dataobject.dict.DictDataDO;
import com.cf.imes.module.system.dal.mysql.customplateno.CustomPlateNoSeqMapper;
import com.cf.imes.module.system.dal.mysql.systemconfig.SystemConfigMapper;
import com.cf.imes.module.system.dal.redis.RedisKeyConstants;
import com.cf.imes.module.system.enums.config.CustBoardRuleCodeEnum;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import com.cf.imes.module.system.enums.config.SystemConfigTypeEnum;
import com.cf.imes.module.system.enums.customplateno.ResetModeEnum;
import com.cf.imes.module.system.service.config.factory.service.AbstractSystemConfigServiceHandler;
import com.cf.imes.module.system.service.dict.DictDataService;
import lombok.extern.slf4j.Slf4j;
@@ -35,7 +35,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_CUSTOM_BOARD_NO_RULE_SAVE_CHECK_ERROR;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_CUSTOM_PLATE_NO_RULE_SAVE_CHECK_ERROR;
/**
* 自定义板编号服务处理器
@@ -48,21 +48,19 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_C
public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHandler {
// 自定义板编号校验错误全部统一编号:1_002_040_003
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_RULECODE_EMPTY_ERROR = new ErrorCode(1_002_040_003, "规则编码不能为空");
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_RULECODE_NOT_MATCH_ERROR = new ErrorCode(1_002_040_003, "规则编码【{}】不合法,请检查配置规则");
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_DATE_TYPE_FORMAT_ERROR = new ErrorCode(1_002_040_003, "时间格式【{}】不合法,请检查配置规则");
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_RESETMODE_ERROR = new ErrorCode(1_002_040_003, "复位/清零模式【{}】不合法,请检查配置规则");
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_INT_TYPE_NO_EMPTY = new ErrorCode(1_002_040_003, "参数【{}】不能为空,请检查配置规则");
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_INT_TYPE_ERROR = new ErrorCode(1_002_040_003, "数值类型参数{}:【{}】转换异常,请检查配置规则");
public static final ErrorCode CUSTOM_BOARD_NO_RULE_CHECK_BOL_TYPE_ERROR = new ErrorCode(1_002_040_003, "布尔类型参数{}:【{}】转换异常,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_RULECODE_EMPTY_ERROR = new ErrorCode(1_002_040_003, "规则编码不能为空");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_RULECODE_NOT_MATCH_ERROR = new ErrorCode(1_002_040_003, "规则编码【{}】不合法,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_DATE_TYPE_FORMAT_ERROR = new ErrorCode(1_002_040_003, "时间格式【{}】不合法,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_CUSTOM_VALUE_EMPTY_ERROR = new ErrorCode(1_002_040_003, "自定义字符值不能为空,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_RESETMODE_ERROR = new ErrorCode(1_002_040_003, "规则【{}】复位/清零模式【{}】不合法,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY = new ErrorCode(1_002_040_003, "参数【{}】不能为空,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_ERROR = new ErrorCode(1_002_040_003, "数值类型参数{}:【{}】转换异常,请检查配置规则");
public static final ErrorCode CUSTOM_PLATE_NO_RULE_CHECK_BOL_TYPE_ERROR = new ErrorCode(1_002_040_003, "布尔类型参数{}:【{}】转换异常,请检查配置规则");
@Resource
private DictDataService dictDataService;
@Resource
private CustomPlateNoSeqMapper customPlateNoSeqMapper;
@Resource
private SystemConfigMapper systemConfigMapper;
@@ -78,30 +76,30 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
public void checkValid(String setting) {
// 字典中的时间格式
List<DictDataDO> dateTypeFormatDictList = dictDataService.getDictDataList(CommonStatusEnum.ENABLE.getStatus(), "system_setting_date_type");
// 字典中的复位模式
List<DictDataDO> resetModeDictList = dictDataService.getDictDataList(CommonStatusEnum.ENABLE.getStatus(), "system_setting_rest_type");
try {
JSONArray jsonArray = JSON.parseArray(setting);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String ruleCode = jsonObject.getString("ruleCode");
// 1.校验code
CustBoardRuleCodeEnum custBoardRuleCodeEnum = checkRoleCode(ruleCode);
CustomPlateNoRuleCodeEnum custBoardRuleCodeEnum = checkRoleCode(ruleCode);
// 2.时间格式校验
// 2.自定义格式校验
checkCustom(custBoardRuleCodeEnum, jsonObject);
// 3.时间格式校验
checkDateFormat(custBoardRuleCodeEnum, jsonObject.getString("value"), dateTypeFormatDictList);
// 3.序号类型校验数字和布尔类型
// 4.序号类型校验数字和布尔类型
checkNoType(custBoardRuleCodeEnum, jsonObject);
// 4.复位类型校验
checkResetMode(custBoardRuleCodeEnum, jsonObject.getInteger("resetMode"), resetModeDictList);
// 5.复位类型校验
checkResetMode(custBoardRuleCodeEnum, jsonObject.getInteger("resetMode"), ruleCode);
}
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
ErrorCode systemConfigCustomPlateNoRuleSaveCheckError = SYSTEM_CONFIG_CUSTOM_BOARD_NO_RULE_SAVE_CHECK_ERROR;
ErrorCode systemConfigCustomPlateNoRuleSaveCheckError = SYSTEM_CONFIG_CUSTOM_PLATE_NO_RULE_SAVE_CHECK_ERROR;
log.error(systemConfigCustomPlateNoRuleSaveCheckError.getMsg(), e);
throw new ServiceException(systemConfigCustomPlateNoRuleSaveCheckError);
}
@@ -112,13 +110,13 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
*
* @param ruleCode 规则编码
*/
private CustBoardRuleCodeEnum checkRoleCode(String ruleCode) {
private CustomPlateNoRuleCodeEnum checkRoleCode(String ruleCode) {
if (StringUtils.isEmpty(ruleCode)) {
throw new ServiceException(CUSTOM_BOARD_NO_RULE_CHECK_RULECODE_EMPTY_ERROR);
throw new ServiceException(CUSTOM_PLATE_NO_RULE_CHECK_RULECODE_EMPTY_ERROR);
}
CustBoardRuleCodeEnum custBoardRuleCodeEnum = CustBoardRuleCodeEnum.match(ruleCode);
CustomPlateNoRuleCodeEnum custBoardRuleCodeEnum = CustomPlateNoRuleCodeEnum.match(ruleCode);
if (ObjectUtil.isNull(custBoardRuleCodeEnum)) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_RULECODE_NOT_MATCH_ERROR, ruleCode);
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_RULECODE_NOT_MATCH_ERROR, ruleCode);
}
return custBoardRuleCodeEnum;
}
@@ -129,11 +127,25 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
* @param custBoardRuleCodeEnum 规则编码枚举
* @param format 格式
*/
private void checkDateFormat(CustBoardRuleCodeEnum custBoardRuleCodeEnum, String format, List<DictDataDO> dateTypeFormatDictList) {
if (ObjectUtil.equal(CustBoardRuleCodeEnum.DATE, custBoardRuleCodeEnum) && StringUtils.isNotEmpty(format)) {
private void checkDateFormat(CustomPlateNoRuleCodeEnum custBoardRuleCodeEnum, String format, List<DictDataDO> dateTypeFormatDictList) {
if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.DATE, custBoardRuleCodeEnum) && StringUtils.isNotEmpty(format)) {
Optional<DictDataDO> dateFormatDictDataOptional = dateTypeFormatDictList.stream().filter(d -> format.equals(d.getValue())).findAny();
if (dateFormatDictDataOptional.isEmpty()) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_DATE_TYPE_FORMAT_ERROR, format);
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_DATE_TYPE_FORMAT_ERROR, format);
}
}
}
/**
* 校验自定义格式
*
* @param custBoardRuleCodeEnum
* @param jsonObject
*/
private void checkCustom(CustomPlateNoRuleCodeEnum custBoardRuleCodeEnum, JSONObject jsonObject) {
if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.CUSTOM, custBoardRuleCodeEnum)) {
if (ObjectUtil.isEmpty(jsonObject.get("value"))) {
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_CUSTOM_VALUE_EMPTY_ERROR, jsonObject.get("ruleCode"));
}
}
}
@@ -144,13 +156,13 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
* @param custBoardRuleCodeEnum
* @param object
*/
private void checkNoType(CustBoardRuleCodeEnum custBoardRuleCodeEnum, JSONObject object) {
private void checkNoType(CustomPlateNoRuleCodeEnum custBoardRuleCodeEnum, JSONObject object) {
// 序号类型才校验
if (ObjectUtil.equal(CustBoardRuleCodeEnum.ORDERNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.PLATENO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.ROOMNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.BODYNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.PROCESSGROUP, custBoardRuleCodeEnum)) {
if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ORDERNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustomPlateNoRuleCodeEnum.PLATENO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ROOMNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustomPlateNoRuleCodeEnum.BODYNO, custBoardRuleCodeEnum)
) {
Map<String, String> intTypeFieldMap = new HashMap<>() {{
put("initValue", "起始值");
put("length", "位数");
@@ -173,10 +185,10 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
*/
private void checkInt(Object intObj, String fieldName) {
if (ObjectUtil.isNull(intObj)) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, fieldName);
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, fieldName);
}
if (!NumberUtil.isInteger(intObj.toString())) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_INT_TYPE_ERROR, fieldName, intObj);
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_ERROR, fieldName, intObj);
}
}
@@ -188,10 +200,10 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
*/
private void checkBol(Object bolObj, String fieldName) {
if (ObjectUtil.isNull(bolObj)) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, fieldName);
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_INT_TYPE_NO_EMPTY, fieldName);
}
if (!(bolObj instanceof Boolean)) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_BOL_TYPE_ERROR, fieldName, bolObj);
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_BOL_TYPE_ERROR, fieldName, bolObj);
}
}
@@ -200,16 +212,22 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
*
* @param resetMode
*/
private void checkResetMode(CustBoardRuleCodeEnum custBoardRuleCodeEnum, Integer resetMode, List<DictDataDO> resetModeDictList) {
if (ObjectUtil.equal(CustBoardRuleCodeEnum.ORDERNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.PLATENO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.ROOMNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.BODYNO, custBoardRuleCodeEnum)
|| ObjectUtil.equal(CustBoardRuleCodeEnum.PROCESSGROUP, custBoardRuleCodeEnum)) {
Optional<DictDataDO> resetModeDictDataOptional = resetModeDictList.stream().filter(d -> resetMode.toString().equals(d.getValue())).findAny();
if (resetModeDictDataOptional.isEmpty()) {
throw ServiceExceptionUtil.exception(CUSTOM_BOARD_NO_RULE_CHECK_RESETMODE_ERROR, resetMode);
}
private void checkResetMode(CustomPlateNoRuleCodeEnum custBoardRuleCodeEnum, Integer resetMode, String ruleCode) {
boolean checkSuccess = true;
if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ORDERNO, custBoardRuleCodeEnum)) {
checkSuccess = ObjectUtil.equal(resetMode, ResetModeEnum.DIGIT.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.YEAR.getMode())
|| ObjectUtil.equal(resetMode, ResetModeEnum.MONTH.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.DAY.getMode());
} else if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.PLATENO, custBoardRuleCodeEnum)) {
checkSuccess = ObjectUtil.equal(resetMode, ResetModeEnum.ORDER.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.YEAR.getMode())
|| ObjectUtil.equal(resetMode, ResetModeEnum.MONTH.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.ROOM.getMode())
|| ObjectUtil.equal(resetMode, ResetModeEnum.BODY.getMode());
} else if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.ROOMNO, custBoardRuleCodeEnum)) {
checkSuccess = ObjectUtil.equal(resetMode, ResetModeEnum.ORDER.getMode());
} else if (ObjectUtil.equal(CustomPlateNoRuleCodeEnum.BODYNO, custBoardRuleCodeEnum)) {
checkSuccess = ObjectUtil.equal(resetMode, ResetModeEnum.ORDER.getMode()) || ObjectUtil.equal(resetMode, ResetModeEnum.ROOM.getMode());
}
if (!checkSuccess) {
throw ServiceExceptionUtil.exception(CUSTOM_PLATE_NO_RULE_CHECK_RESETMODE_ERROR, ruleCode, resetMode);
}
}
@@ -246,6 +264,11 @@ public class CustomPlateNoServiceHandler extends AbstractSystemConfigServiceHand
.eq(SystemConfigDO::getType, SystemConfigTypeEnum.CUSTOM_PLATE_NO.getType())
.le(SystemConfigDO::getVersion, minReserveVersion));
}
// 移除机构下的板编号配置缓存
// 禁用配置移除缓存
String redisKey = String.format("%s:%d:%s", RedisKeyConstants.SYSTEM_CONFIG, OrganContextHolder.getOrganId(), RedisKeyConstants.CUSTOM_PLATE_NO);
Boolean delete = stringRedisTemplate.delete(redisKey);
log.info("[CustomPlateNoGenerateService][afterUpdateStatus]key{}缓存删除结果:{}", redisKey, delete);
}
@Override
@@ -1,6 +1,7 @@
package com.cf.imes.module.system.service.config.factory.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigDeleteReqVO;
@@ -11,7 +12,6 @@ import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDO;
import com.cf.imes.module.system.dal.mysql.systemconfig.SystemConfigMapper;
import com.cf.imes.module.system.enums.config.SystemConfigTypeEnum;
import com.cf.imes.module.system.service.config.factory.service.AbstractSystemConfigServiceHandler;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -19,7 +19,6 @@ import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
@@ -35,15 +34,16 @@ public class DefaultSystemConfigServiceHandler extends AbstractSystemConfigServi
@Override
public List<SystemConfigDO> selectList(ConfigPageReqVO reqVO) {
List<SystemConfigDO> systemConfigDOS = systemConfigMapper.selectList(new LambdaQueryWrapperX<SystemConfigDO>()
.likeIfPresent(SystemConfigDO::getName, reqVO.getName())
.eqIfPresent(SystemConfigDO::getStatus, reqVO.getStatus())
.eqIfPresent(SystemConfigDO::getOrganId, OrganContextHolder.getOrganId())
.orderByAsc(SystemConfigDO::getId));
// todo 后续所有configTypeEnum中的类型需要上到列表补全时通过遍历enum来补充
SystemConfigTypeEnum customplateNoEnum = SystemConfigTypeEnum.CUSTOM_PLATE_NO;
CopyOnWriteArrayList<SystemConfigDO> configDOS = Lists.newCopyOnWriteArrayList(systemConfigDOS);
Optional<SystemConfigDO> configDOOptional = configDOS.stream().filter(c -> ObjectUtil.equal(customplateNoEnum.getType(), c.getType())).findAny();
List<SystemConfigDO> systemConfigDOS = systemConfigMapper.selectList(new LambdaQueryWrapperX<SystemConfigDO>()
.likeIfPresent(SystemConfigDO::getName, reqVO.getName())
.eq(SystemConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
.eq(SystemConfigDO::getType, customplateNoEnum.getType())
.eqIfPresent(SystemConfigDO::getOrganId, OrganContextHolder.getOrganId())
.select(SystemConfigDO::getId, SystemConfigDO::getName, SystemConfigDO::getStatus, SystemConfigDO::getType)
.orderByAsc(SystemConfigDO::getId));
Optional<SystemConfigDO> configDOOptional = systemConfigDOS.stream().filter(c -> ObjectUtil.equal(customplateNoEnum.getType(), c.getType())).findAny();
if (configDOOptional.isEmpty()) {
SystemConfigDO initCustomPlateNoConfig = new SystemConfigDO().builder().id(null).name(customplateNoEnum.getName()).type(customplateNoEnum.getType()).build();
return List.of(initCustomPlateNoConfig);
@@ -15,4 +15,11 @@ public interface CustomPlateNoSeqService {
* @return
*/
CustomPlateNoSeqDO getOrgCustomPlateNoSeq();
/**
* 修改机构的自定义版编号序号
*
* @param seqDO
*/
Boolean modifyOrgCustomPlateNoSeq(CustomPlateNoSeqDO seqDO);
}
@@ -24,4 +24,11 @@ public class CustomPlateNoSeqServiceImpl implements CustomPlateNoSeqService {
return customPlateNoSeqMapper.selectOne(new LambdaQueryWrapperX<CustomPlateNoSeqDO>()
.eq(CustomPlateNoSeqDO::getOrganId, OrganContextHolder.getOrganId()));
}
}
@Override
public Boolean modifyOrgCustomPlateNoSeq(CustomPlateNoSeqDO seqDO) {
return customPlateNoSeqMapper.insertOrUpdate(seqDO);
}
}