mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
新增标签自定义类型增删改和旧数据关联
This commit is contained in:
+3
@@ -225,6 +225,9 @@ public class ErrorCodeConstants {
|
||||
public static final ErrorCode DEFAULT_NOT_DELETED = new ErrorCode(1_002_300_004, "default.not.deleted");
|
||||
public static final ErrorCode LABEL_IS_USE_ERROR = new ErrorCode(1_002_300_006, "label.is.use.error");
|
||||
public static final ErrorCode LABEL_SYSTEM_TYPE_NOT_OPERABLE = new ErrorCode(1_002_300_007, "label.type.not.operable");
|
||||
public static final ErrorCode LABEL_TYPE_NOT_EXISTS = new ErrorCode(1_002_300_008, "label.type.not.exists");
|
||||
public static final ErrorCode LABEL_TYPE_DUPLICATE = new ErrorCode(1_002_300_009, "label.type.duplicate");
|
||||
public static final ErrorCode LABEL_TYPE_IS_USE_ERROR = new ErrorCode(1_002_300_010, "label.type.is.use.error");
|
||||
|
||||
|
||||
// ========== 系统数据源 1_002_301_000 ==========
|
||||
|
||||
+2
-2
@@ -10,6 +10,7 @@ import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelSaveReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelGroupRespVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.lable.LabelDO;
|
||||
import com.cf.imes.module.system.service.lable.LabelService;
|
||||
import com.cf.imes.module.system.validation.label.LabelTemplateTypeValid;
|
||||
@@ -25,7 +26,6 @@ import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
@@ -97,7 +97,7 @@ public class LabelController {
|
||||
@Operation(summary = "获得分组标签列表")
|
||||
@PreAuthorize("@ss.hasAnyPermissions('system:label-template:query','sysTagDesignManager:query')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<Map<String, List<LabelRespVO>>> getGroupList(@RequestParam(value = "organId", required = false) Long organId) {
|
||||
public CommonResult<List<LabelGroupRespVO>> getGroupList(@RequestParam(value = "organId", required = false) Long organId) {
|
||||
return success(labelService.getGroupList(organId));
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.cf.imes.module.system.controller.admin.label.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "标签分组 Response VO")
|
||||
@Data
|
||||
public class LabelGroupRespVO {
|
||||
|
||||
@Schema(description = "标签类型主键")
|
||||
private Long typeId;
|
||||
|
||||
@Schema(description = "标签类型名称")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "标签列表")
|
||||
private List<LabelRespVO> list;
|
||||
}
|
||||
+3
@@ -21,6 +21,9 @@ public class LabelRespVO {
|
||||
@ExcelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签类型主键")
|
||||
private Long labelTypeId;
|
||||
|
||||
@Schema(description = "标签类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("标签类型")
|
||||
private String type;
|
||||
|
||||
+3
-2
@@ -3,7 +3,6 @@ package com.cf.imes.module.system.controller.admin.label.vo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
@@ -15,8 +14,10 @@ public class LabelSaveReqVO {
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "939")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签类型主键;兼容旧调用时可仅传 type")
|
||||
private Long labelTypeId;
|
||||
|
||||
@Schema(description = "标签类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "materialLabel")
|
||||
@NotBlank(message = "label.save.type.notBlank")
|
||||
@Size(max = 32, message = "label.save.type.size")
|
||||
private String type;
|
||||
|
||||
|
||||
+3
@@ -19,6 +19,9 @@ public class LabelTemplateRespVO {
|
||||
@ExcelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签类型主键")
|
||||
private Long labelTypeId;
|
||||
|
||||
@Schema(description = "标签类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("标签类型")
|
||||
private String type;
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.cf.imes.module.system.controller.admin.labeltype;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.module.system.controller.admin.labeltype.vo.LabelTypeRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.labeltype.vo.LabelTypeSaveReqVO;
|
||||
import com.cf.imes.module.system.service.labeltype.LabelTypeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "标签类型管理")
|
||||
@RestController
|
||||
@RequestMapping("/system/label-type")
|
||||
@Validated
|
||||
public class LabelTypeController {
|
||||
|
||||
@Resource
|
||||
private LabelTypeService labelTypeService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得标签类型列表")
|
||||
@PreAuthorize("@ss.hasPermission('sysTagDesignManager:query')")
|
||||
public CommonResult<List<LabelTypeRespVO>> getList(@RequestParam(value = "organId", required = false) Long organId) {
|
||||
return success(labelTypeService.getLabelTypeList(organId));
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建自定义标签类型")
|
||||
@PreAuthorize("@ss.hasPermission('sysTagDesignManager:create')")
|
||||
public CommonResult<Long> create(@Valid @RequestBody LabelTypeSaveReqVO reqVO) {
|
||||
return success(labelTypeService.createLabelType(reqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改自定义标签类型")
|
||||
@PreAuthorize("@ss.hasPermission('sysTagDesignManager:update')")
|
||||
public CommonResult<Boolean> update(@Valid @RequestBody LabelTypeSaveReqVO reqVO) {
|
||||
labelTypeService.updateLabelType(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除自定义标签类型")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('sysTagDesignManager:delete')")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") @NotNull Long id) {
|
||||
labelTypeService.deleteLabelType(id);
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.cf.imes.module.system.controller.admin.labeltype.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 标签类型 Response VO")
|
||||
@Data
|
||||
public class LabelTypeRespVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签类型名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String type;
|
||||
|
||||
@Schema(description = "来源:SYSTEM/CUSTOM")
|
||||
private String source;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.cf.imes.module.system.controller.admin.labeltype.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 标签类型新增/修改 Request VO")
|
||||
@Data
|
||||
public class LabelTypeSaveReqVO {
|
||||
|
||||
@Schema(description = "主键", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签类型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单自定义标签")
|
||||
@NotBlank(message = "label.type.name.notBlank")
|
||||
@Size(max = 32, message = "label.type.name.size")
|
||||
private String type;
|
||||
}
|
||||
+2
@@ -27,6 +27,8 @@ public class LabelTemplateDO extends BaseDO {
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/** 标签类型主键;type 保留用于兼容历史调用方 */
|
||||
private Long labelTypeId;
|
||||
/**
|
||||
* 标签类型
|
||||
*/
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.cf.imes.module.system.dal.dataobject.labeltype;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cf.imes.framework.organ.core.db.OrganBaseDO;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 标签类型 DO。系统类型来自 labelType 字典,自定义类型归属于组织。
|
||||
*/
|
||||
@TableName("system_label_type")
|
||||
@KeySequence("system_label_type_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LabelTypeDO extends OrganBaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/** 前端展示及兼容字段使用的类型名称 */
|
||||
private String type;
|
||||
|
||||
/** SYSTEM / CUSTOM */
|
||||
private String source;
|
||||
|
||||
/** 系统类型对应的字典数据 ID */
|
||||
private Long dictDataId;
|
||||
|
||||
/** 系统类型跟随字典启用禁用;自定义类型固定启用 */
|
||||
private Integer status;
|
||||
}
|
||||
+2
@@ -27,6 +27,8 @@ public class LabelDO extends OrganBaseDO {
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/** 标签类型主键;type 保留用于兼容历史调用方 */
|
||||
private Long labelTypeId;
|
||||
/**
|
||||
* 标签类型
|
||||
*/
|
||||
|
||||
+11
@@ -3,6 +3,7 @@ package com.cf.imes.module.system.dal.mysql.label;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelPageReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.lable.LabelDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -15,6 +16,16 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface LabelMapper extends BaseMapperX<LabelDO> {
|
||||
|
||||
default long selectCountByLabelTypeId(Long labelTypeId) {
|
||||
return selectCount(LabelDO::getLabelTypeId, labelTypeId);
|
||||
}
|
||||
|
||||
default int updateTypeByLabelTypeId(Long labelTypeId, String type) {
|
||||
return update(null, new LambdaUpdateWrapper<LabelDO>()
|
||||
.eq(LabelDO::getLabelTypeId, labelTypeId)
|
||||
.set(LabelDO::getType, type));
|
||||
}
|
||||
|
||||
default PageResult<LabelDO> selectPage(LabelPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<LabelDO>()
|
||||
.eqIfPresent(LabelDO::getType, reqVO.getType())
|
||||
|
||||
+7
@@ -5,6 +5,7 @@ import java.util.*;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltemplate.LabelTemplateDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.cf.imes.module.system.controller.admin.labeltemplate.vo.*;
|
||||
@@ -17,6 +18,12 @@ import com.cf.imes.module.system.controller.admin.labeltemplate.vo.*;
|
||||
@Mapper
|
||||
public interface LabelTemplateMapper extends BaseMapperX<LabelTemplateDO> {
|
||||
|
||||
default int updateTypeByLabelTypeId(Long labelTypeId, String type) {
|
||||
return update(null, new LambdaUpdateWrapper<LabelTemplateDO>()
|
||||
.eq(LabelTemplateDO::getLabelTypeId, labelTypeId)
|
||||
.set(LabelTemplateDO::getType, type));
|
||||
}
|
||||
|
||||
default PageResult<LabelTemplateDO> selectPage(LabelTemplatePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<LabelTemplateDO>()
|
||||
.eqIfPresent(LabelTemplateDO::getType, reqVO.getType())
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.cf.imes.module.system.dal.mysql.labeltype;
|
||||
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltype.LabelTypeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface LabelTypeMapper extends BaseMapperX<LabelTypeDO> {
|
||||
|
||||
default LabelTypeDO selectByTypeAndOrgan(String type, Long organId) {
|
||||
return selectOne(new LambdaQueryWrapperX<LabelTypeDO>()
|
||||
.eq(LabelTypeDO::getType, type)
|
||||
.eq(LabelTypeDO::getSource, "CUSTOM")
|
||||
.eq(LabelTypeDO::getOrganId, organId));
|
||||
}
|
||||
|
||||
default LabelTypeDO selectSystemByType(String type) {
|
||||
return selectOne(new LambdaQueryWrapperX<LabelTypeDO>()
|
||||
.eq(LabelTypeDO::getType, type)
|
||||
.eq(LabelTypeDO::getSource, "SYSTEM"));
|
||||
}
|
||||
|
||||
default LabelTypeDO selectByDictDataId(Long dictDataId) {
|
||||
return selectOne(new LambdaQueryWrapperX<LabelTypeDO>()
|
||||
.eq(LabelTypeDO::getDictDataId, dictDataId));
|
||||
}
|
||||
|
||||
default List<LabelTypeDO> selectAvailable(Long organId) {
|
||||
return selectList(new LambdaQueryWrapperX<LabelTypeDO>()
|
||||
.and(wrapper -> wrapper
|
||||
.and(system -> system.eq(LabelTypeDO::getSource, "SYSTEM")
|
||||
.eq(LabelTypeDO::getStatus, 0))
|
||||
.or(custom -> custom.eq(LabelTypeDO::getSource, "CUSTOM")
|
||||
.eq(LabelTypeDO::getOrganId, organId)))
|
||||
.orderByAsc(LabelTypeDO::getId));
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.cf.imes.module.system.event.dict;
|
||||
|
||||
public enum DictDataChangeOperationEnum {
|
||||
CREATE, UPDATE, DELETE
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.cf.imes.module.system.event.dict;
|
||||
|
||||
import com.cf.imes.module.system.dal.dataobject.dict.DictDataDO;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class DictDataChangedEvent extends ApplicationEvent {
|
||||
|
||||
private final DictDataChangeOperationEnum operation;
|
||||
private final DictDataDO before;
|
||||
private final DictDataDO after;
|
||||
|
||||
public DictDataChangedEvent(Object source, DictDataChangeOperationEnum operation,
|
||||
DictDataDO before, DictDataDO after) {
|
||||
super(source);
|
||||
this.operation = operation;
|
||||
this.before = before;
|
||||
this.after = after;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.cf.imes.module.system.event.dict;
|
||||
|
||||
import com.cf.imes.module.system.dal.dataobject.dict.DictDataDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltype.LabelTypeDO;
|
||||
import com.cf.imes.module.system.dal.mysql.dict.DictDataMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltype.LabelTypeMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.label.LabelMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltemplate.LabelTemplateMapper;
|
||||
import com.cf.imes.module.system.enums.DictTypeConstants;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** labelType 字典到标签类型模型的通用事件处理器。 */
|
||||
@Component
|
||||
public class LabelTypeDictSyncHandler {
|
||||
|
||||
private static final String SOURCE_SYSTEM = "SYSTEM";
|
||||
|
||||
@Resource
|
||||
private DictDataMapper dictDataMapper;
|
||||
@Resource
|
||||
private LabelTypeMapper labelTypeMapper;
|
||||
@Resource
|
||||
private LabelMapper labelMapper;
|
||||
@Resource
|
||||
private LabelTemplateMapper labelTemplateMapper;
|
||||
|
||||
@PostConstruct
|
||||
public void syncExisting() {
|
||||
List<DictDataDO> dictDataList = dictDataMapper.selectListByStatusAndDictType(null, DictTypeConstants.LABEL_TYPE);
|
||||
dictDataList.forEach(this::syncUpsert);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onDictDataChanged(DictDataChangedEvent event) {
|
||||
DictDataDO data = event.getAfter() != null ? event.getAfter() : event.getBefore();
|
||||
if (data == null || !DictTypeConstants.LABEL_TYPE.equals(data.getDictType())) {
|
||||
if (event.getBefore() == null || !DictTypeConstants.LABEL_TYPE.equals(event.getBefore().getDictType())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.getOperation() == DictDataChangeOperationEnum.UPDATE
|
||||
&& event.getAfter() != null
|
||||
&& !DictTypeConstants.LABEL_TYPE.equals(event.getAfter().getDictType())) {
|
||||
deleteType(event.getBefore());
|
||||
return;
|
||||
}
|
||||
if (event.getOperation() == DictDataChangeOperationEnum.DELETE) {
|
||||
deleteType(data);
|
||||
return;
|
||||
}
|
||||
LabelTypeDO typeDO = syncUpsert(data);
|
||||
if (typeDO != null) {
|
||||
labelMapper.updateTypeByLabelTypeId(typeDO.getId(), typeDO.getType());
|
||||
labelTemplateMapper.updateTypeByLabelTypeId(typeDO.getId(), typeDO.getType());
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteType(DictDataDO dictData) {
|
||||
if (dictData == null) {
|
||||
return;
|
||||
}
|
||||
LabelTypeDO typeDO = labelTypeMapper.selectByDictDataId(dictData.getId());
|
||||
if (typeDO != null) {
|
||||
labelTypeMapper.deleteById(typeDO.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private LabelTypeDO syncUpsert(DictDataDO dictData) {
|
||||
LabelTypeDO typeDO = labelTypeMapper.selectByDictDataId(dictData.getId());
|
||||
if (typeDO == null) {
|
||||
typeDO = LabelTypeDO.builder().type(dictData.getValue()).source(SOURCE_SYSTEM)
|
||||
.dictDataId(dictData.getId()).status(dictData.getStatus()).build();
|
||||
labelTypeMapper.insert(typeDO);
|
||||
return typeDO;
|
||||
}
|
||||
LabelTypeDO update = new LabelTypeDO();
|
||||
update.setId(typeDO.getId());
|
||||
update.setType(dictData.getValue());
|
||||
update.setStatus(dictData.getStatus());
|
||||
labelTypeMapper.updateById(update);
|
||||
typeDO.setType(dictData.getValue());
|
||||
typeDO.setStatus(dictData.getStatus());
|
||||
return typeDO;
|
||||
}
|
||||
}
|
||||
+15
@@ -24,6 +24,8 @@ import com.cf.imes.module.system.dal.mysql.dict.DictDataI18nMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.dict.DictDataI18nVersionMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.dict.DictDataMapper;
|
||||
import com.cf.imes.module.system.enums.ErrorCodeConstants;
|
||||
import com.cf.imes.module.system.event.dict.DictDataChangeOperationEnum;
|
||||
import com.cf.imes.module.system.event.dict.DictDataChangedEvent;
|
||||
import com.cf.imes.module.system.enums.common.LanguageEnum;
|
||||
import com.cf.imes.module.system.framework.trans.config.TransApi;
|
||||
import com.cf.imes.module.system.util.locale.DictDataI18nCacheUtils;
|
||||
@@ -31,6 +33,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -84,6 +87,9 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Resource
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Override
|
||||
public List<DictDataDO> getDictDataList(Integer status, String dictType) {
|
||||
List<DictDataDO> list = dictDataMapper.selectListByStatusAndDictType(status, dictType);
|
||||
@@ -111,11 +117,14 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
// 插入字典类型
|
||||
DictDataDO dictData = BeanUtils.toBean(createReqVO, DictDataDO.class);
|
||||
dictDataMapper.insert(dictData);
|
||||
applicationEventPublisher.publishEvent(new DictDataChangedEvent(this,
|
||||
DictDataChangeOperationEnum.CREATE, null, dictData));
|
||||
return dictData.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDictData(DictDataSaveReqVO updateReqVO) {
|
||||
DictDataDO before = dictDataMapper.selectById(updateReqVO.getId());
|
||||
// 校验自己存在
|
||||
validateDictDataExists(updateReqVO.getId());
|
||||
// 校验字典类型有效
|
||||
@@ -126,6 +135,9 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
// 更新字典类型
|
||||
DictDataDO updateObj = BeanUtils.toBean(updateReqVO, DictDataDO.class);
|
||||
dictDataMapper.updateById(updateObj);
|
||||
DictDataDO after = dictDataMapper.selectById(updateReqVO.getId());
|
||||
applicationEventPublisher.publishEvent(new DictDataChangedEvent(this,
|
||||
DictDataChangeOperationEnum.UPDATE, before, after));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,7 +146,10 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
validateDictDataExists(id);
|
||||
|
||||
// 删除字典数据
|
||||
DictDataDO before = dictDataMapper.selectById(id);
|
||||
dictDataMapper.deleteById(id);
|
||||
applicationEventPublisher.publishEvent(new DictDataChangedEvent(this,
|
||||
DictDataChangeOperationEnum.DELETE, before, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+22
-2
@@ -14,6 +14,8 @@ import com.cf.imes.module.system.controller.admin.labeltemplate.vo.*;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltemplate.LabelTemplateDO;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltemplate.LabelTemplateMapper;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltype.LabelTypeDO;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltype.LabelTypeMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
@@ -30,10 +32,16 @@ public class LabelTemplateServiceImpl implements LabelTemplateService {
|
||||
@Resource
|
||||
private LabelTemplateMapper labelTemplateMapper;
|
||||
|
||||
@Resource
|
||||
private LabelTypeMapper labelTypeMapper;
|
||||
|
||||
@Override
|
||||
public Long createLabelTemplate(LabelTemplateSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
LabelTemplateDO labelTemplate = BeanUtils.toBean(createReqVO, LabelTemplateDO.class);
|
||||
LabelTypeDO labelType = requireSystemType(createReqVO.getType());
|
||||
labelTemplate.setLabelTypeId(labelType.getId());
|
||||
labelTemplate.setType(labelType.getType());
|
||||
labelTemplate.setTemplate(JsonUtils.zipString(labelTemplate.getTemplate()));
|
||||
labelTemplateMapper.insert(labelTemplate);
|
||||
// 返回
|
||||
@@ -46,6 +54,9 @@ public class LabelTemplateServiceImpl implements LabelTemplateService {
|
||||
validateLabelTemplateExists(updateReqVO.getId());
|
||||
// 更新
|
||||
LabelTemplateDO updateObj = BeanUtils.toBean(updateReqVO, LabelTemplateDO.class);
|
||||
LabelTypeDO labelType = requireSystemType(updateReqVO.getType());
|
||||
updateObj.setLabelTypeId(labelType.getId());
|
||||
updateObj.setType(labelType.getType());
|
||||
if(!updateReqVO.getTemplate().isEmpty()){
|
||||
updateObj.setTemplate(JsonUtils.zipString(updateObj.getTemplate()));
|
||||
|
||||
@@ -84,9 +95,10 @@ public class LabelTemplateServiceImpl implements LabelTemplateService {
|
||||
|
||||
@Override
|
||||
public LabelTemplateRespVO getDefaultLabelTemplate(String type) {
|
||||
LabelTypeDO labelType = requireSystemType(type);
|
||||
List<LabelTemplateDO> labelTemplateDOS = labelTemplateMapper.selectList(new LambdaQueryWrapperX<LabelTemplateDO>()
|
||||
.eq(LabelTemplateDO::getIsDefault, Boolean.TRUE)
|
||||
.eq(LabelTemplateDO::getType, type)
|
||||
.eq(LabelTemplateDO::getLabelTypeId, labelType.getId())
|
||||
);
|
||||
if(CollUtil.isNotEmpty(labelTemplateDOS)) {
|
||||
if (labelTemplateDOS.size() > 1) {
|
||||
@@ -109,7 +121,7 @@ public class LabelTemplateServiceImpl implements LabelTemplateService {
|
||||
}
|
||||
List<LabelTemplateDO> labelTemplateDOS = labelTemplateMapper.selectList(new LambdaQueryWrapperX<LabelTemplateDO>()
|
||||
.eq(LabelTemplateDO::getIsDefault, Boolean.TRUE)
|
||||
.eq(LabelTemplateDO::getType, labelTemplateDO.getType())
|
||||
.eq(LabelTemplateDO::getLabelTypeId, labelTemplateDO.getLabelTypeId())
|
||||
);
|
||||
// if(CollectionUtil.isEmpty(labelTemplateDOS) || labelTemplateDOS.size()>1) {
|
||||
// throw new ServiceException(DEFAULT_TEMPLATE_COUNT);
|
||||
@@ -127,4 +139,12 @@ public class LabelTemplateServiceImpl implements LabelTemplateService {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private LabelTypeDO requireSystemType(String type) {
|
||||
LabelTypeDO labelType = labelTypeMapper.selectSystemByType(type == null ? null : type.trim());
|
||||
if (labelType == null || !Integer.valueOf(0).equals(labelType.getStatus())) {
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
return labelType;
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.cf.imes.module.system.service.labeltype;
|
||||
|
||||
import com.cf.imes.module.system.controller.admin.labeltype.vo.LabelTypeRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.labeltype.vo.LabelTypeSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltype.LabelTypeDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
public interface LabelTypeService {
|
||||
|
||||
Long createLabelType(@Valid LabelTypeSaveReqVO reqVO);
|
||||
|
||||
void updateLabelType(@Valid LabelTypeSaveReqVO reqVO);
|
||||
|
||||
void deleteLabelType(Long id);
|
||||
|
||||
List<LabelTypeRespVO> getLabelTypeList(Long organId);
|
||||
|
||||
LabelTypeDO getAvailableLabelType(Long id, Long organId);
|
||||
|
||||
LabelTypeDO getAvailableLabelType(String type, Long organId);
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package com.cf.imes.module.system.service.labeltype;
|
||||
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.module.system.controller.admin.labeltype.vo.LabelTypeRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.labeltype.vo.LabelTypeSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltype.LabelTypeDO;
|
||||
import com.cf.imes.module.system.dal.mysql.label.LabelMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltype.LabelTypeMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.dict.DictDataMapper;
|
||||
import com.cf.imes.module.system.enums.DictTypeConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
@Service
|
||||
@Validated
|
||||
public class LabelTypeServiceImpl implements LabelTypeService {
|
||||
|
||||
private static final String SOURCE_SYSTEM = "SYSTEM";
|
||||
private static final String SOURCE_CUSTOM = "CUSTOM";
|
||||
|
||||
@Resource
|
||||
private LabelTypeMapper labelTypeMapper;
|
||||
@Resource
|
||||
private DictDataMapper dictDataMapper;
|
||||
@Resource
|
||||
private LabelMapper labelMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createLabelType(LabelTypeSaveReqVO reqVO) {
|
||||
Long organId = getUserOrganId();
|
||||
String type = normalize(reqVO.getType());
|
||||
validateNotSystemType(type);
|
||||
if (labelTypeMapper.selectByTypeAndOrgan(type, organId) != null) {
|
||||
throw new ServiceException(LABEL_TYPE_DUPLICATE);
|
||||
}
|
||||
LabelTypeDO typeDO = LabelTypeDO.builder().type(type).source(SOURCE_CUSTOM)
|
||||
.status(CommonStatusEnum.ENABLE.getStatus()).build();
|
||||
typeDO.setOrganId(organId);
|
||||
labelTypeMapper.insert(typeDO);
|
||||
return typeDO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateLabelType(LabelTypeSaveReqVO reqVO) {
|
||||
LabelTypeDO typeDO = getOwnedCustomType(reqVO.getId());
|
||||
String type = normalize(reqVO.getType());
|
||||
validateNotSystemType(type);
|
||||
LabelTypeDO duplicate = labelTypeMapper.selectByTypeAndOrgan(type, typeDO.getOrganId());
|
||||
if (duplicate != null && !duplicate.getId().equals(typeDO.getId())) {
|
||||
throw new ServiceException(LABEL_TYPE_DUPLICATE);
|
||||
}
|
||||
LabelTypeDO update = new LabelTypeDO();
|
||||
update.setId(typeDO.getId());
|
||||
update.setType(type);
|
||||
labelTypeMapper.updateById(update);
|
||||
labelMapper.updateTypeByLabelTypeId(typeDO.getId(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteLabelType(Long id) {
|
||||
LabelTypeDO typeDO = getOwnedCustomType(id);
|
||||
if (labelMapper.selectCountByLabelTypeId(id) > 0) {
|
||||
throw new ServiceException(LABEL_TYPE_IS_USE_ERROR);
|
||||
}
|
||||
labelTypeMapper.deleteById(typeDO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LabelTypeRespVO> getLabelTypeList(Long organId) {
|
||||
Long currentOrganId = organId == null ? getUserOrganId() : organId;
|
||||
return BeanUtils.toBean(labelTypeMapper.selectAvailable(currentOrganId), LabelTypeRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelTypeDO getAvailableLabelType(Long id, Long organId) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
LabelTypeDO typeDO = labelTypeMapper.selectById(id);
|
||||
if (typeDO == null || !isAvailable(typeDO, organId)) {
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
return typeDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelTypeDO getAvailableLabelType(String type, Long organId) {
|
||||
String normalized = normalize(type);
|
||||
LabelTypeDO system = labelTypeMapper.selectSystemByType(normalized);
|
||||
if (system != null && isAvailable(system, organId)) {
|
||||
return system;
|
||||
}
|
||||
LabelTypeDO custom = labelTypeMapper.selectByTypeAndOrgan(normalized, organId);
|
||||
if (custom != null && isAvailable(custom, organId)) {
|
||||
return custom;
|
||||
}
|
||||
// 兼容迁移完成前的旧数据:系统字典仍是唯一可信来源。
|
||||
if (dictDataMapper.selectByDictTypeAndValue(DictTypeConstants.LABEL_TYPE, normalized) != null) {
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
private LabelTypeDO getOwnedCustomType(Long id) {
|
||||
LabelTypeDO typeDO = labelTypeMapper.selectById(id);
|
||||
if (typeDO == null || !SOURCE_CUSTOM.equals(typeDO.getSource())
|
||||
|| !getUserOrganId().equals(typeDO.getOrganId())) {
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
return typeDO;
|
||||
}
|
||||
|
||||
private void validateNotSystemType(String type) {
|
||||
if (dictDataMapper.selectAllValuesByDictType(DictTypeConstants.LABEL_TYPE).contains(type)) {
|
||||
throw new ServiceException(LABEL_SYSTEM_TYPE_NOT_OPERABLE);
|
||||
}
|
||||
// 查询包含逻辑删除记录,保证系统历史名称不能被自定义类型复用。
|
||||
if (dictDataMapper.selectAllValuesByDictType(DictTypeConstants.LABEL_TYPE).contains(type)) {
|
||||
throw new ServiceException(LABEL_SYSTEM_TYPE_NOT_OPERABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAvailable(LabelTypeDO typeDO, Long organId) {
|
||||
if (SOURCE_SYSTEM.equals(typeDO.getSource())) {
|
||||
return CommonStatusEnum.ENABLE.getStatus().equals(typeDO.getStatus());
|
||||
}
|
||||
return organId != null && organId.equals(typeDO.getOrganId());
|
||||
}
|
||||
|
||||
private String normalize(String type) {
|
||||
return type == null ? null : type.trim();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -4,11 +4,11 @@ import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelSaveReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelGroupRespVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.lable.LabelDO;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 标签模板 Service 接口
|
||||
@@ -56,7 +56,7 @@ public interface LabelService {
|
||||
PageResult<LabelDO> getLabelPage(LabelPageReqVO pageReqVO);
|
||||
|
||||
|
||||
Map<String, List<LabelRespVO>> getGroupList(Long organId);
|
||||
List<LabelGroupRespVO> getGroupList(Long organId);
|
||||
|
||||
List<LabelDO> list(String type);
|
||||
|
||||
|
||||
+64
-33
@@ -2,7 +2,6 @@ package com.cf.imes.module.system.service.lable;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.enums.DeletedCodeEnum;
|
||||
import com.cf.imes.framework.common.enums.UserSettingTypeEnum;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
@@ -13,17 +12,17 @@ import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.dict.DictDataDO;
|
||||
import com.cf.imes.module.system.controller.admin.label.vo.LabelGroupRespVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltemplate.LabelTemplateDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.lable.LabelDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.labeltype.LabelTypeDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.setting.PackageConfigDO;
|
||||
import com.cf.imes.module.system.dal.mysql.label.LabelMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.dict.DictDataMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltemplate.LabelTemplateMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.labeltype.LabelTypeMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.machine.MachineMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.setting.PackageConfigMapper;
|
||||
import com.cf.imes.module.system.enums.DictTypeConstants;
|
||||
import com.cf.imes.module.system.enums.label.LabelTemplateType;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -33,11 +32,9 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import static com.cf.imes.framework.common.util.json.JsonUtils.parseTree;
|
||||
import static com.cf.imes.framework.common.util.json.JsonUtils.unzipString;
|
||||
@@ -57,9 +54,6 @@ public class LabelServiceImpl implements LabelService {
|
||||
@Resource
|
||||
private LabelMapper labelMapper;
|
||||
|
||||
@Resource
|
||||
private DictDataMapper dictDataMapper;
|
||||
|
||||
@Resource
|
||||
private LabelTemplateMapper labelTemplateMapper;
|
||||
|
||||
@@ -69,15 +63,21 @@ public class LabelServiceImpl implements LabelService {
|
||||
@Resource
|
||||
private PackageConfigMapper packageConfigMapper;
|
||||
|
||||
@Resource
|
||||
private LabelTypeMapper labelTypeMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createLabel(LabelSaveReqVO createReqVO) {
|
||||
String type = normalizeType(createReqVO.getType());
|
||||
validateCustomType(type);
|
||||
Long organId = createReqVO.getOrganId() == null ? getUserOrganId() : createReqVO.getOrganId();
|
||||
LabelTypeDO labelType = resolveLabelType(createReqVO.getLabelTypeId(), createReqVO.getType(), organId);
|
||||
validateCustomType(labelType);
|
||||
|
||||
// 插入
|
||||
LabelDO label = BeanUtils.toBean(createReqVO, LabelDO.class);
|
||||
label.setType(type);
|
||||
label.setLabelTypeId(labelType.getId());
|
||||
label.setType(labelType.getType());
|
||||
label.setOrganId(organId);
|
||||
label.setTemplate(JsonUtils.zipString(label.getTemplate()));
|
||||
labelMapper.insert(label);
|
||||
// 返回
|
||||
@@ -90,14 +90,16 @@ public class LabelServiceImpl implements LabelService {
|
||||
|
||||
// 校验存在
|
||||
LabelDO labelDO = validateLabelExists(updateReqVO.getId());
|
||||
validateCustomType(labelDO.getType());
|
||||
LabelTypeDO oldType = resolveLabelType(labelDO.getLabelTypeId(), labelDO.getType(), labelDO.getOrganId());
|
||||
validateCustomType(oldType);
|
||||
|
||||
String type = normalizeType(updateReqVO.getType());
|
||||
validateCustomType(type);
|
||||
LabelTypeDO newType = resolveLabelType(updateReqVO.getLabelTypeId(), updateReqVO.getType(), labelDO.getOrganId());
|
||||
validateCustomType(newType);
|
||||
|
||||
// 更新
|
||||
LabelDO updateObj = BeanUtils.toBean(updateReqVO, LabelDO.class);
|
||||
updateObj.setType(type);
|
||||
updateObj.setLabelTypeId(newType.getId());
|
||||
updateObj.setType(newType.getType());
|
||||
if(!updateReqVO.getTemplate().isEmpty()){
|
||||
updateObj.setTemplate(JsonUtils.zipString(updateObj.getTemplate()));
|
||||
}
|
||||
@@ -111,7 +113,7 @@ public class LabelServiceImpl implements LabelService {
|
||||
public void deleteLabel(Long id) {
|
||||
// 校验存在
|
||||
LabelDO labelDO = validateLabelExists(id);
|
||||
validateCustomType(labelDO.getType());
|
||||
validateCustomType(resolveLabelType(labelDO.getLabelTypeId(), labelDO.getType(), labelDO.getOrganId()));
|
||||
|
||||
List<MachineDO> machineDOS = machineMapper.selectList(new LambdaQueryWrapperX<MachineDO>()
|
||||
.select(MachineDO::getId)
|
||||
@@ -178,20 +180,28 @@ public class LabelServiceImpl implements LabelService {
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, List<LabelRespVO>> getGroupList(Long organId) {
|
||||
Set<String> dictTypes = new HashSet<>(dictDataMapper.selectAllValuesByDictType(DictTypeConstants.LABEL_TYPE));
|
||||
Set<String> enabledDictTypes = dictDataMapper
|
||||
.selectListByStatusAndDictType(CommonStatusEnum.ENABLE.getStatus(), DictTypeConstants.LABEL_TYPE)
|
||||
.stream().map(DictDataDO::getValue).collect(Collectors.toSet());
|
||||
public List<LabelGroupRespVO> getGroupList(Long organId) {
|
||||
Long currentOrganId = organId == null ? getUserOrganId() : organId;
|
||||
List<LabelTypeDO> typeList = labelTypeMapper.selectAvailable(currentOrganId);
|
||||
Map<Long, LabelGroupRespVO> groups = new LinkedHashMap<>();
|
||||
typeList.forEach(type -> {
|
||||
LabelGroupRespVO group = new LabelGroupRespVO();
|
||||
group.setTypeId(type.getId());
|
||||
group.setType(type.getType());
|
||||
group.setList(new ArrayList<>());
|
||||
groups.put(type.getId(), group);
|
||||
});
|
||||
|
||||
List<LabelDO> LabelDOS = labelMapper.selectList(new LambdaQueryWrapperX<LabelDO>()
|
||||
.eqIfPresent(LabelDO::getOrganId, organId)
|
||||
)
|
||||
.stream()
|
||||
.filter(label -> !dictTypes.contains(label.getType()) || enabledDictTypes.contains(label.getType()))
|
||||
.map(m -> m.setTemplate(unzipString(m.getTemplate()))).toList();
|
||||
List<LabelRespVO> LabelRespVOS = BeanUtils.toBean(LabelDOS, LabelRespVO.class);
|
||||
return LabelRespVOS.stream().collect(Collectors.groupingBy(LabelRespVO::getType));
|
||||
List<LabelDO> labels = labelMapper.selectList(new LambdaQueryWrapperX<LabelDO>()
|
||||
.eq(LabelDO::getOrganId, currentOrganId))
|
||||
.stream().map(m -> m.setTemplate(unzipString(m.getTemplate()))).toList();
|
||||
for (LabelDO label : labels) {
|
||||
LabelGroupRespVO group = groups.get(label.getLabelTypeId());
|
||||
if (group != null) {
|
||||
group.getList().add(BeanUtils.toBean(label, LabelRespVO.class));
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(groups.values());
|
||||
}
|
||||
|
||||
private String normalizeType(String type) {
|
||||
@@ -199,12 +209,32 @@ public class LabelServiceImpl implements LabelService {
|
||||
}
|
||||
|
||||
/** 标签接口只能操作自定义类型,系统默认类型由字段管理维护。 */
|
||||
private void validateCustomType(String type) {
|
||||
if (type != null && dictDataMapper.selectByDictTypeAndValue(DictTypeConstants.LABEL_TYPE, type) != null) {
|
||||
private void validateCustomType(LabelTypeDO type) {
|
||||
if (type == null || "SYSTEM".equals(type.getSource())) {
|
||||
throw new ServiceException(LABEL_SYSTEM_TYPE_NOT_OPERABLE);
|
||||
}
|
||||
}
|
||||
|
||||
private LabelTypeDO resolveLabelType(Long labelTypeId, String type, Long organId) {
|
||||
if (labelTypeId != null) {
|
||||
LabelTypeDO labelType = labelTypeMapper.selectById(labelTypeId);
|
||||
if (labelType != null && ("SYSTEM".equals(labelType.getSource())
|
||||
|| organId != null && organId.equals(labelType.getOrganId()))) {
|
||||
return labelType;
|
||||
}
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
String normalizedType = normalizeType(type);
|
||||
LabelTypeDO labelType = labelTypeMapper.selectSystemByType(normalizedType);
|
||||
if (labelType == null) {
|
||||
labelType = labelTypeMapper.selectByTypeAndOrgan(normalizedType, organId);
|
||||
}
|
||||
if (labelType == null) {
|
||||
throw new ServiceException(LABEL_TYPE_NOT_EXISTS);
|
||||
}
|
||||
return labelType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LabelDO> list(String type) {
|
||||
|
||||
@@ -233,6 +263,7 @@ public class LabelServiceImpl implements LabelService {
|
||||
// 复制标签内容a
|
||||
if (ObjectUtil.isNotNull(labelTemplateDO)) {
|
||||
LabelDO labelDO = LabelDO.builder()
|
||||
.labelTypeId(labelTypeMapper.selectSystemByType(labelType).getId())
|
||||
.type(labelType)
|
||||
.name(labelTemplateDO.getName())
|
||||
.remark(labelTemplateDO.getRemark())
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
label.system.type.not.operable=系统默认标签类型只能在字段管理中操作
|
||||
label.type.not.operable=当前标签类型不可操作
|
||||
label.type.not.exists=标签类型不存在或不可用
|
||||
label.type.duplicate=标签类型已存在
|
||||
label.type.is.use.error=标签类型已被标签使用,无法删除
|
||||
label.type.name.notBlank=标签类型不能为空
|
||||
label.type.name.size=标签类型长度不能超过32个字符
|
||||
label.save.type.notBlank=标签类型不能为空
|
||||
label.save.type.size=标签类型长度不能超过32个字符
|
||||
label.save.name.notEmpty=标签名称不能为空
|
||||
|
||||
+5
File diff suppressed because one or more lines are too long
+5
File diff suppressed because one or more lines are too long
+5
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user