diff --git a/config/application-local.yml b/config/application-local.yml index 2c4480a..d66f3ea 100644 --- a/config/application-local.yml +++ b/config/application-local.yml @@ -24,6 +24,8 @@ spring : add-mappings: false jackson : + date-format: yyyy-MM-dd HH:mm:ss.SSS + timezone: GMT+8 default-property-inclusion: non_null datasource: diff --git a/src/main/java/com/cmhi/cf/controller/SystemDictController.java b/src/main/java/com/cmhi/cf/controller/SystemDictController.java index 65d2df7..aff12c1 100644 --- a/src/main/java/com/cmhi/cf/controller/SystemDictController.java +++ b/src/main/java/com/cmhi/cf/controller/SystemDictController.java @@ -5,11 +5,15 @@ import com.cmhi.cf.misc.HelperUtils; import com.cmhi.cf.restapi.annotation.DecryptionProtocol; import com.cmhi.cf.restapi.annotation.EncryptionProtocol; import com.cmhi.cf.restapi.annotation.OperationLogAnnotation; +import com.cmhi.cf.restapi.pojo.base.BasePageResultResp; +import com.cmhi.cf.restapi.pojo.base.BasePagedReq; import com.cmhi.cf.restapi.pojo.base.BaseRespStatus; import com.cmhi.cf.restapi.pojo.dto.DictContentReq; import com.cmhi.cf.restapi.pojo.dto.NewUserDictReq; import com.cmhi.cf.restapi.pojo.dto.ProtocolReq; import com.cmhi.cf.restapi.pojo.po.DictContent; +import com.cmhi.cf.restapi.pojo.po.PageResults; +import com.cmhi.cf.restapi.pojo.po.UserDictionary; import com.cmhi.cf.restapi.pojo.vo.DictContentResp; import com.cmhi.cf.restapi.pojo.vo.DictTypeResp; import com.cmhi.cf.restapi.pojo.vo.NewUserDictResp; @@ -50,7 +54,7 @@ public class SystemDictController { .build()); } - @PostMapping("/enum/allDictContent") + @PostMapping("/enum/dictContent") @ResponseBody @EncryptionProtocol @OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取系统枚举字典详细内容") @@ -61,7 +65,7 @@ public class SystemDictController { if (validate.isEmpty()) { DictContentReq req = mr.getMsgContent(); - List ret = dictionaryService.getEnumDictionaryContent(req.getDictTpe()); + List ret = dictionaryService.getUserDictionaryContent(req.getDictTpe()); return ProtocolResp.result(DictContentResp.builder() .sysDict(ret) @@ -73,7 +77,7 @@ public class SystemDictController { } } - @PutMapping("/add") + @PutMapping("/user/add") @ResponseBody @EncryptionProtocol @DecryptionProtocol @@ -92,4 +96,67 @@ public class SystemDictController { validate.toArray(new String[0])); } } + + @PostMapping("/user/upgrade") + @ResponseBody + @EncryptionProtocol + @DecryptionProtocol + @OperationLogAnnotation(OperationModule = "字典模块", OperationType = "修改", OperationDesc = "修改用户字典内容") + public ProtocolResp upgradeDictionary(@RequestBody ProtocolReq mr) { + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class); + // 如果校验通过,validate为空;否则,validate包含未校验通过项 + if (validate.isEmpty()) { + NewUserDictReq req = mr.getMsgContent(); + dictionaryService.addNewDbDictionary(req.getDictType(), req.getDictName(), req.getRemark()); + return ProtocolResp.result(NewUserDictResp.builder() + .dictType(req.getDictType()) + .build()); + } else { + return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION, ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(), + validate.toArray(new String[0])); + } + } + + @PostMapping("/user/allDict") + @ResponseBody + @EncryptionProtocol + @DecryptionProtocol + @OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取所有用户字典") + public ProtocolResp getUserDictionary(@RequestBody ProtocolReq mr) { + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.BasePagedReqValid.class); + // 如果校验通过,validate为空;否则,validate包含未校验通过项 + if (validate.isEmpty()) { + BasePagedReq req = mr.getMsgContent(); + PageResults ret = dictionaryService.getUserDictionary(req.getPageNumber(), + req.getPageSize(), + req.getTotalSize()); + return ProtocolResp.result(BasePageResultResp.builder() + .items(ret) + .build()); + } else { + return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION, ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(), + validate.toArray(new String[0])); + } + } + + @PostMapping("/user/dictContent") + @ResponseBody + @EncryptionProtocol + @DecryptionProtocol + @OperationLogAnnotation(OperationModule = "字典模块", OperationType = "读取", OperationDesc = "获取所有用户字典") + public ProtocolResp getUserDictionaryContent(@RequestBody ProtocolReq mr) { + List validate = HelperUtils.validate(mr, ValidGroups.ProtocolCommonValid.class, ValidGroups.DictReqValid.class); + // 如果校验通过,validate为空;否则,validate包含未校验通过项 + if (validate.isEmpty()) { + DictContentReq req = mr.getMsgContent(); + List ret = dictionaryService.getUserDictionaryContent(req.getDictTpe()); + + return ProtocolResp.result(DictContentResp.builder() + .sysDict(ret) + .build()); + } else { + return ProtocolResp.result(ErrorCode.ERR_PARAMEXCEPTION, ErrorCode.ERR_PARAMEXCEPTION.getHttpCode(), + validate.toArray(new String[0])); + } + } } diff --git a/src/main/java/com/cmhi/cf/database/common/entity/DictData.java b/src/main/java/com/cmhi/cf/database/common/entity/DictData.java index 4a2730c..ac40ca7 100644 --- a/src/main/java/com/cmhi/cf/database/common/entity/DictData.java +++ b/src/main/java/com/cmhi/cf/database/common/entity/DictData.java @@ -5,7 +5,9 @@ import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.sql.Timestamp; @@ -18,6 +20,8 @@ import java.sql.Timestamp; @Data @Schema(name = "字典数据表") @Table(value = "sys_dict_data") +@AllArgsConstructor +@NoArgsConstructor public class DictData { /** diff --git a/src/main/java/com/cmhi/cf/restapi/pojo/po/DictContent.java b/src/main/java/com/cmhi/cf/restapi/pojo/po/DictContent.java index 607fb12..4910c69 100644 --- a/src/main/java/com/cmhi/cf/restapi/pojo/po/DictContent.java +++ b/src/main/java/com/cmhi/cf/restapi/pojo/po/DictContent.java @@ -4,22 +4,20 @@ import com.cmhi.cf.restapi.pojo.base.BaseRespStatus; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.houkunlin.system.dict.starter.bean.DictTypeVo; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; @EqualsAndHashCode(callSuper = true) @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor @JsonPropertyOrder({"dictName", "dictContent", "status", "message"}) @JsonInclude(JsonInclude.Include.NON_NULL) public class DictContent extends BaseRespStatus { private String dictName; private DictTypeVo dictContent; - - @Builder - public DictContent(String dictName, DictTypeVo dictContent, Integer status, String[] message) { - super(status, message); - this.dictContent = dictContent; - this.dictName = dictName; - } } diff --git a/src/main/java/com/cmhi/cf/restapi/pojo/po/UserDictionary.java b/src/main/java/com/cmhi/cf/restapi/pojo/po/UserDictionary.java new file mode 100644 index 0000000..385f723 --- /dev/null +++ b/src/main/java/com/cmhi/cf/restapi/pojo/po/UserDictionary.java @@ -0,0 +1,35 @@ +package com.cmhi.cf.restapi.pojo.po; + +import com.cmhi.cf.database.common.entity.DictData; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.sql.Timestamp; +import java.util.List; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonPropertyOrder({"dictName", "dictAlias", "remark", "dictStatus"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class UserDictionary { + @JsonProperty("dictAlias") + private String dictName; + @JsonProperty("dictName") + private String dictType; + @JsonProperty("dictStatus") + private String status; + private String createBy; + private Timestamp createTime; + private String updateBy; + private Timestamp updateTime; + @JsonProperty("dictRemark") + private String remark; + List dictDataList; +} diff --git a/src/main/java/com/cmhi/cf/service/DictionaryService.java b/src/main/java/com/cmhi/cf/service/DictionaryService.java index 2a93d5c..e8b4fd3 100644 --- a/src/main/java/com/cmhi/cf/service/DictionaryService.java +++ b/src/main/java/com/cmhi/cf/service/DictionaryService.java @@ -1,6 +1,8 @@ package com.cmhi.cf.service; import com.cmhi.cf.restapi.pojo.po.DictContent; +import com.cmhi.cf.restapi.pojo.po.PageResults; +import com.cmhi.cf.restapi.pojo.po.UserDictionary; import java.util.List; import java.util.Set; @@ -11,4 +13,8 @@ public interface DictionaryService { List getEnumDictionaryContent(List dictType); void addNewDbDictionary(String type, String name, String remark); + + PageResults getUserDictionary(Long pageNumber, Long pageSize, Long totalSize); + + List getUserDictionaryContent(List dictName); } diff --git a/src/main/java/com/cmhi/cf/service/impl/DictionaryServiceImpl.java b/src/main/java/com/cmhi/cf/service/impl/DictionaryServiceImpl.java index d93b216..4b3c789 100644 --- a/src/main/java/com/cmhi/cf/service/impl/DictionaryServiceImpl.java +++ b/src/main/java/com/cmhi/cf/service/impl/DictionaryServiceImpl.java @@ -6,11 +6,19 @@ import com.cmhi.cf.database.common.mapper.DictTypeMapper; import com.cmhi.cf.exception.CommonErrorCodeException; import com.cmhi.cf.restapi.misc.ApiContextUtils; import com.cmhi.cf.restapi.pojo.po.DictContent; +import com.cmhi.cf.restapi.pojo.po.PageResults; +import com.cmhi.cf.restapi.pojo.po.UserDictionary; import com.cmhi.cf.service.DictionaryService; +import com.houkunlin.system.dict.starter.DictUtil; import com.houkunlin.system.dict.starter.SystemDictStarter; +import com.houkunlin.system.dict.starter.bean.DictTypeVo; +import com.houkunlin.system.dict.starter.notice.RefreshDictTypeEvent; import com.houkunlin.system.dict.starter.provider.SystemDictProvider; import com.houkunlin.system.dict.starter.store.DictStore; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; import jakarta.annotation.Resource; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,11 +27,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import static com.cmhi.cf.database.common.entity.table.DictTypeTableDef.DICT_TYPE; + @Service public class DictionaryServiceImpl implements DictionaryService { @Resource private DictTypeMapper dictTypeMapper; + @Resource + private ApplicationEventPublisher publisher; + @Override public Set getAllEnumDictionary() { return SystemDictStarter.getBean(DictStore.class).systemDictTypeKeys(); @@ -39,8 +52,6 @@ public class DictionaryServiceImpl implements DictionaryService { sysDictList.add(DictContent.builder() .dictName(k.getType()) .dictContent(k) - .status(ErrorCode.ERR_OK.getCode()) - .message(new String[] {ErrorCode.ERR_OK.getDescription()}) .build()); } allSysDict.add(k.getType()); @@ -51,8 +62,6 @@ public class DictionaryServiceImpl implements DictionaryService { dictType.forEach(k -> sysDictList.add(DictContent.builder() .dictName(k) .dictContent(null) - .status(ErrorCode.ERR_NOSUCHITEM.getCode()) - .message(new String[] {ErrorCode.ERR_NOSUCHITEM.getDescription()}) .build())); return sysDictList; @@ -72,8 +81,65 @@ public class DictionaryServiceImpl implements DictionaryService { if (dictTypeMapper.insert(dt) != 1) { throw new CommonErrorCodeException(ErrorCode.ERR_DATABASE); } + + // 更新字典 + DictTypeVo.DictTypeBuilder builder = DictTypeVo.newBuilder(type, name, remark); + publisher.publishEvent(new RefreshDictTypeEvent(builder.build())); } catch (DataAccessException e) { throw new CommonErrorCodeException(ErrorCode.ERR_ITEMEXISTS, type + ": " + ErrorCode.ERR_ITEMEXISTS.getDescription()); } } + + @Override + public PageResults getUserDictionary(Long pageNumber, Long pageSize, Long totalSize) { + if (totalSize == 0) { + totalSize = -1L; + } + + QueryWrapper wrapper = QueryWrapper.create() + .from(DICT_TYPE) + .select(); + + Page dict = dictTypeMapper.paginateAs(pageNumber, pageSize, totalSize, wrapper, UserDictionary.class); + + return PageResults.builder() + .items(dict.getRecords()) + .pageNumber(dict.getPageNumber()) + .pageSize(dict.getPageSize()) + .totalPage(dict.getTotalPage()) + .totalRow(dict.getTotalRow()) + .build(); + } + + @Override + public List getUserDictionaryContent(List dictName) { + List resp = new ArrayList<>(); + + QueryWrapper wrapper = QueryWrapper.create() + .from(DICT_TYPE) + .select() + .where(DICT_TYPE.DICT_TYPE_.in(dictName)); + + List ret = dictTypeMapper.selectListWithRelationsByQuery(wrapper); + + ret.forEach(k -> { + resp.add(DictContent.builder() + .dictName(k.getDictType()) + .dictContent(DictUtil.getDictType(k.getDictType())) + .build()); + }); + + dictName.stream() + .filter(k -> ret.stream().noneMatch(v -> v.getDictType().equals(k))) + .forEach(m -> { + DictContent dt = DictContent.builder() + .dictName(m) + .build(); + dt.setStatus(ErrorCode.ERR_NOSUCHITEM.getCode()); + dt.setMessage(new String[] {ErrorCode.ERR_NOSUCHITEM.getDescription()}); + resp.add(dt); + }); + + return resp; + } } diff --git a/src/main/java/com/cmhi/cf/service/impl/OperationLogServiceImpl.java b/src/main/java/com/cmhi/cf/service/impl/OperationLogServiceImpl.java index 3082f7e..818f575 100644 --- a/src/main/java/com/cmhi/cf/service/impl/OperationLogServiceImpl.java +++ b/src/main/java/com/cmhi/cf/service/impl/OperationLogServiceImpl.java @@ -25,8 +25,13 @@ public class OperationLogServiceImpl implements OperationLogService { Page optLog = operationLogDataBaseService.getSystemOperationSummary(pageNumber, pageSize, totalSize, userName); - return PageResults.builder().items(optLog.getRecords()).pageNumber(optLog.getPageNumber()).pageSize( - optLog.getPageSize()).totalPage(optLog.getTotalPage()).totalRow(optLog.getTotalRow()).build(); + return PageResults.builder() + .items(optLog.getRecords()) + .pageNumber(optLog.getPageNumber()) + .pageSize(optLog.getPageSize()) + .totalPage(optLog.getTotalPage()) + .totalRow(optLog.getTotalRow()) + .build(); } @Override diff --git a/src/main/resources/rbac/data.sql b/src/main/resources/rbac/data.sql index d137a93..cfb6ed6 100644 --- a/src/main/resources/rbac/data.sql +++ b/src/main/resources/rbac/data.sql @@ -39,9 +39,11 @@ INSERT IGNORE INTO rbac_resource_data VALUES (302, '221c8d8e-c47a-4200-88a8-34d3 INSERT IGNORE INTO rbac_resource_data VALUES (303, '8adf6875-2be4-459e-9c1d-3bb87114cb08', '/api/user/remove', '删除用户', 'DELETE', 0); INSERT IGNORE INTO rbac_resource_data VALUES (304, '4c6c859b-2625-45eb-83b8-1426ff96dbe6', '/api/user/userList', '分页获取当前所有用户', 'POST', 0); INSERT IGNORE INTO rbac_resource_data VALUES (400, '8ac928d8-5a6a-47c7-8697-0fb9ebd7249d', '/api/dict/enum/allDict', '获取所以枚举字典列表', 'GET', 0); -INSERT IGNORE INTO rbac_resource_data VALUES (401, '9ecf1662-f891-4829-8d3e-81c42bf22e2a', '/api/dict/enum/allDictContent', '获取枚举字典详细内容', 'POST', 0); -INSERT IGNORE INTO rbac_resource_data VALUES (402, 'C083F441-9624-AF2C-B353-0768F9C0A932', '/api/dict/add', '新增用户字典', 'PUT', 0); - +INSERT IGNORE INTO rbac_resource_data VALUES (401, '9ecf1662-f891-4829-8d3e-81c42bf22e2a', '/api/dict/enum/dictContent', '获取枚举字典详细内容', 'POST', 0); +INSERT IGNORE INTO rbac_resource_data VALUES (402, 'C083F441-9624-AF2C-B353-0768F9C0A932', '/api/dict/user/add', '新增用户字典', 'PUT', 0); +INSERT IGNORE INTO rbac_resource_data VALUES (403, '953cea37-cc7a-4e7e-bd86-cb3c14daa8c4', '/api/dict/user/upgrade', '修改用户字典', 'POST', 0); +INSERT IGNORE INTO rbac_resource_data VALUES (404, '54b43614-45c6-4672-a1d8-fa8f326d5e53', '/api/dict/user/allDict', '分页获取所有用户字典', 'POST', 0); +INSERT IGNORE INTO rbac_resource_data VALUES (405, 'e441dbb4-b844-461c-a5f8-07ee3fa658cc', '/api/dict/user/dictContent', '获取用户字典详细信息', 'POST', 0); -- ---------------------------- -- Records of role_resource -- (role_id, resource_id, authorize) @@ -63,7 +65,9 @@ INSERT IGNORE INTO rbac_role_resource VALUES (1, 304, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 400, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 401, 1); INSERT IGNORE INTO rbac_role_resource VALUES (1, 402, 1); - +INSERT IGNORE INTO rbac_role_resource VALUES (1, 403, 1); +INSERT IGNORE INTO rbac_role_resource VALUES (1, 404, 1); +INSERT IGNORE INTO rbac_role_resource VALUES (1, 405, 1); # INSERT IGNORE INTO role_resource (role_id, resource_id, authorize) VALUES (2, 1, 1); # INSERT IGNORE INTO role_resource (role_id, resource_id, authorize) VALUES (2, 2, 1); # INSERT IGNORE INTO role_resource (role_id, resource_id, authorize) VALUES (2, 3, 1); diff --git a/src/main/resources/rbac/schema.sql b/src/main/resources/rbac/schema.sql index 95d2974..a6c33a1 100644 --- a/src/main/resources/rbac/schema.sql +++ b/src/main/resources/rbac/schema.sql @@ -208,7 +208,7 @@ CREATE TABLE IF NOT EXISTS `sys_dict_type` `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime(6) NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新者', - `update_time` datetime NULL DEFAULT NULL COMMENT '更新时间', + `update_time` datetime(6) NULL DEFAULT NULL COMMENT '更新时间', `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', `delete_time` datetime NULL DEFAULT NULL COMMENT '逻辑删除标记', PRIMARY KEY (`id`) USING BTREE,