新增系统配置服务处理器的分页查询抽象

This commit is contained in:
gaoqr
2024-11-14 14:40:13 +08:00
parent d69a283ed5
commit f719f9916d
6 changed files with 96 additions and 24 deletions
@@ -2,14 +2,17 @@ package com.cf.imes.module.system.controller.admin.systemconfig.vo;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.module.system.validation.common.CommonStatus;
import com.cf.imes.module.system.validation.config.SystemConfigTypeEnumValid;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* 系统配置分页查询VO
*
* @author Gqr
* @since 2024/11/7 16:29
*/
@@ -25,4 +28,9 @@ public class ConfigPageReqVO extends PageParam {
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
@CommonStatus
private Integer status;
@Schema(description = "配置类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "配置类型不能为空")
@SystemConfigTypeEnumValid
private Integer type;
}
@@ -19,7 +19,6 @@ import com.cf.imes.module.system.dal.redis.RedisKeyConstants;
import com.cf.imes.module.system.enums.config.SystemConfigTypeEnum;
import com.cf.imes.module.system.service.config.factory.SystemConfigServiceFactory;
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.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@@ -27,9 +26,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_NOT_EXISTS;
@@ -51,17 +47,9 @@ public class SystemConfigServiceImpl implements SystemConfigService {
@Override
public PageResult<SystemConfigDO> getSystemConfigPage(ConfigPageReqVO reqVO) {
PageResult<SystemConfigDO> configDOPageResult = systemConfigMapper.selectPage(reqVO);
// todo 后续所有configTypeEnum中的类型需要上到列表补全时通过遍历enum来补充
SystemConfigTypeEnum customplateNoEnum = SystemConfigTypeEnum.CUSTOM_PLATE_NO;
CopyOnWriteArrayList<SystemConfigDO> configDOS = Lists.newCopyOnWriteArrayList(configDOPageResult.getList());
Optional<SystemConfigDO> configDOOptional = configDOS.stream().filter(c -> ObjectUtil.equal(customplateNoEnum.getType(), c.getType())).findAny();
if (configDOOptional.isEmpty()) {
configDOS.add(new SystemConfigDO().builder().id(null).name(customplateNoEnum.getName()).type(customplateNoEnum.getType()).build());
configDOPageResult.setList(configDOS);
configDOPageResult.setTotal(configDOPageResult.getTotal() + 1);
}
return configDOPageResult;
// 根据配置类型选择对应的service
AbstractSystemConfigServiceHandler configService = configServiceFactory.getConfigServiceHandler(reqVO.getType());
return configService.selectPage(reqVO);
}
@Override
@@ -1,16 +1,13 @@
package com.cf.imes.module.system.service.config.factory;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.module.system.enums.config.SystemConfigTypeEnum;
import com.cf.imes.module.system.service.config.factory.service.AbstractSystemConfigServiceHandler;
import com.cf.imes.module.system.service.config.factory.service.impl.CustomPlateNoGenerateServiceHandler;
import com.cf.imes.module.system.service.config.factory.service.impl.CustomPlateNoServiceHandler;
import com.cf.imes.module.system.service.config.factory.service.impl.DefaultSystemConfigServiceHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_TYPE_NOT_SUPPORT;
/**
* 系统配置服务分配工厂类
*
@@ -35,13 +32,13 @@ public class SystemConfigServiceFactory {
public AbstractSystemConfigServiceHandler getConfigServiceHandler(int type) {
switch (SystemConfigTypeEnum.fromType(type)) {
case CUSTOM_PLATE_NO:
return applicationContext.getBean(CustomPlateNoGenerateServiceHandler.class);
return applicationContext.getBean(CustomPlateNoServiceHandler.class);
case INTELLIGENT_BRANCH:
// todo 智能分线
case ADVANCED_SCREEN:
// todo 高级筛选
default:
throw ServiceExceptionUtil.exception(SYSTEM_CONFIG_TYPE_NOT_SUPPORT);
return applicationContext.getBean(DefaultSystemConfigServiceHandler.class);
}
}
}
@@ -1,5 +1,7 @@
package com.cf.imes.module.system.service.config.factory.service;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigPageReqVO;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigSaveReqVO;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigUpdateStatusReqVO;
import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDO;
@@ -12,6 +14,14 @@ import com.cf.imes.module.system.dal.dataobject.systemconfig.SystemConfigDO;
*/
public abstract class AbstractSystemConfigServiceHandler {
/**
* 分页查询系统配置
*
* @param pageReqVO
* @return
*/
public abstract PageResult<SystemConfigDO> selectPage(ConfigPageReqVO pageReqVO);
/**
* 校验配置的合法性
* 校验异常抛出ServiceException
@@ -9,7 +9,9 @@ import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.ErrorCode;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigPageReqVO;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigSaveReqVO;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigUpdateStatusReqVO;
import com.cf.imes.module.system.dal.dataobject.customplateno.CustomPlateNoSeqDO;
@@ -39,9 +41,9 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_C
* @author Gqr
* @since 2024/11/8 16:48
*/
@Service("customPlateNoGenerateServiceHandler")
@Service("customPlateNoServiceHandler")
@Slf4j
public class CustomPlateNoGenerateServiceHandler extends AbstractSystemConfigServiceHandler {
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, "规则编码不能为空");
@@ -62,6 +64,11 @@ public class CustomPlateNoGenerateServiceHandler extends AbstractSystemConfigSer
@Resource
private StringRedisTemplate stringRedisTemplate;
@Override
public PageResult<SystemConfigDO> selectPage(ConfigPageReqVO pageReqVO) {
return null;
}
@Override
public void checkValid(String setting) {
// 字典中的时间格式
@@ -0,0 +1,62 @@
package com.cf.imes.module.system.service.config.factory.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigPageReqVO;
import com.cf.imes.module.system.controller.admin.systemconfig.vo.ConfigSaveReqVO;
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.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 javax.annotation.Resource;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
* @author Gqr
* @since 2024/11/14 14:30
*/
public class DefaultSystemConfigServiceHandler extends AbstractSystemConfigServiceHandler {
@Resource
private SystemConfigMapper systemConfigMapper;
@Override
public PageResult<SystemConfigDO> selectPage(ConfigPageReqVO reqVO) {
PageResult<SystemConfigDO> configDOPageResult = systemConfigMapper.selectPage(reqVO);
// todo 后续所有configTypeEnum中的类型需要上到列表补全时通过遍历enum来补充
SystemConfigTypeEnum customplateNoEnum = SystemConfigTypeEnum.CUSTOM_PLATE_NO;
CopyOnWriteArrayList<SystemConfigDO> configDOS = Lists.newCopyOnWriteArrayList(configDOPageResult.getList());
Optional<SystemConfigDO> configDOOptional = configDOS.stream().filter(c -> ObjectUtil.equal(customplateNoEnum.getType(), c.getType())).findAny();
if (configDOOptional.isEmpty()) {
configDOS.add(new SystemConfigDO().builder().id(null).name(customplateNoEnum.getName()).type(customplateNoEnum.getType()).build());
configDOPageResult.setList(configDOS);
configDOPageResult.setTotal(configDOPageResult.getTotal() + 1);
}
return configDOPageResult;
}
@Override
public void checkValid(String setting) {
// todo checkValid
}
@Override
public void beforeSaveConfig(ConfigSaveReqVO reqVO) {
// todo beforeSaveConfig
}
@Override
public void afterSaveConfig(SystemConfigDO systemConfigDO, ConfigSaveReqVO reqVO) {
// todo afterSaveConfig
}
@Override
public void afterUpdateStatus(SystemConfigDO systemConfigDO, ConfigUpdateStatusReqVO reqVO) {
// todo afterUpdateStatus
}
}