diff --git a/db/7pigxx_updata.sql b/db/7pigxx_updata.sql new file mode 100644 index 000000000..6e687edb2 --- /dev/null +++ b/db/7pigxx_updata.sql @@ -0,0 +1,70 @@ +/* +公共参数 SysPublicParam +在我们写需求过程中,经常会遇到在一个集合中,许多都是公共的参数, +我们每次创建集合对象时,都得重新添加一遍,太麻烦了。怎么解决呢? +其实我们可以把这些公共参数封装到表里,这样初始化缓存当中, +就不用再次进行添加了,优先到缓存中获取对象里已经有这些参数了。 +*/ +use pigxx; + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- 公共参数设计表 +-- ---------------------------- +DROP TABLE IF EXISTS `sys_public_param`; +CREATE TABLE `sys_public_param` ( + `public_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号', + `public_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '公共参数名称', + `public_key` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '键,英文大写+下划线', + `public_value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '值', + `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '状态:1有效;2无效;', + `delete_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '1' COMMENT '删除状态:0-正常;1-已删除', + `validate_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '公共参数编码', + `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间', + `update_time` timestamp(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间', + `public_type` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '配置类型:0-默认;1-检索;2-原文;3-报表;4-安全;5-文档;6-消息;9-其他', + PRIMARY KEY (`public_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '公共参数配置表' ROW_FORMAT = Compact; + +SET FOREIGN_KEY_CHECKS = 1; + +-- ---------------------------- +-- 公共参数数据 +-- ---------------------------- +INSERT INTO `pigxx`.`sys_public_param`(`public_id`, `public_name`, `public_key`, `public_value`, `status`, `delete_flag`, `validate_code`, `create_time`, `update_time`, `public_type`) +VALUES (1, '系统首页参数配置', 'INDEX_MSG_CONFIG', '运维电话: 18888888888', '0', '0', NULL, '2019-04-28 18:24:38', '2019-04-28 18:31:10', '9'); +INSERT INTO `pigxx`.`sys_public_param`(`public_id`, `public_name`, `public_key`, `public_value`, `status`, `delete_flag`, `validate_code`, `create_time`, `update_time`, `public_type`) +VALUES (2, '版本信息说明', 'VERSION_INSTRUCTIONS', 'PIGX平台3.1版本', '0', '0', NULL, '2019-04-28 18:24:38', '2019-04-28 18:31:10', '9'); +INSERT INTO `pigxx`.`sys_public_param`(`public_id`, `public_name`, `public_key`, `public_value`, `status`, `delete_flag`, `validate_code`, `create_time`, `update_time`, `public_type`) +VALUES (3, '办公安全支持文件类型', 'OFFICE_SAFETY_FILETYPE', 'PDF,CEB,CEBX,DOC,DOCX,XLS,XLSX,PPT,PPTX,WPS', '0', '0', NULL, '2019-04-28 18:24:38', '2019-04-28 18:31:10', '4'); + + +-- ---------------------------- +-- 公共参数菜单 +-- ---------------------------- +INSERT INTO `pigxx`.`sys_menu`(`menu_id`, `name`, `permission`, `path`, `parent_id`, `icon`, `component`, `sort`, `keep_alive`, `type`, `create_time`, `update_time`, `del_flag`) VALUES (1700, '参数配置', '', 'param', 1000, 'icon-navicon-zdgl', 'views/admin/param/index', 8, '0', '0', '2019-03-29 13:17:19', '2019-03-29 13:38:19', '0'); +INSERT INTO `pigxx`.`sys_menu`(`menu_id`, `name`, `permission`, `path`, `parent_id`, `icon`, `component`, `sort`, `keep_alive`, `type`, `create_time`, `update_time`, `del_flag`) VALUES (1701, '参数配置新增', 'admin_syspublicparam_add', NULL, 1700, '1', NULL, 0, '0', '1', '2019-03-29 21:35:18', '2019-03-29 13:38:59', '0'); +INSERT INTO `pigxx`.`sys_menu`(`menu_id`, `name`, `permission`, `path`, `parent_id`, `icon`, `component`, `sort`, `keep_alive`, `type`, `create_time`, `update_time`, `del_flag`) VALUES (1702, '参数配置修改', 'admin_syspublicparam_edit', NULL, 1700, '1', NULL, 1, '0', '1', '2019-03-29 21:35:18', '2019-03-29 13:38:59', '0'); +INSERT INTO `pigxx`.`sys_menu`(`menu_id`, `name`, `permission`, `path`, `parent_id`, `icon`, `component`, `sort`, `keep_alive`, `type`, `create_time`, `update_time`, `del_flag`) VALUES (1703, '参数配置删除', 'admin_syspublicparam_del', NULL, 1700, '1', NULL, 2, '0', '1', '2019-03-29 21:35:18', '2019-03-29 13:38:59', '0'); + +-- ---------------------------- +-- 公共参数字典类型 +-- ---------------------------- +INSERT INTO `pigxx`.`sys_dict`(`id`, `type`, `description`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (11, 'param_type', '参数配置', '2019-04-29 18:20:47', '2019-04-29 18:20:47', '检索、原文、报表、安全、文档、消息、其他', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (36, 11, '0', '默认', 'param_type', '默认', 0, '2019-04-29 18:23:30', '2019-04-29 18:23:30', '默认', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (35, 11, '9', '其他', 'param_type', '其他', 0, '2019-04-29 18:23:16', '2019-04-29 18:23:16', '其他', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (34, 11, '6', '消息', 'param_type', '消息', 0, '2019-04-29 18:23:05', '2019-04-29 18:23:05', '消息', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (33, 11, '5', '文档', 'param_type', '文档', 0, '2019-04-29 18:22:56', '2019-04-29 18:22:56', '文档', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (32, 11, '4', '安全', 'param_type', '安全', 0, '2019-04-29 18:22:46', '2019-04-29 18:22:46', '安全', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (31, 11, '3', '报表', 'param_type', '报表', 0, '2019-04-29 18:22:36', '2019-04-29 18:22:36', '报表', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (30, 11, '2', '原文', 'param_type', '原文', 0, '2019-04-29 18:22:27', '2019-04-29 18:22:27', '原文', '0', 1); +INSERT INTO `pigxx`.`sys_dict_item`(`id`, `dict_id`, `value`, `label`, `type`, `description`, `sort`, `create_time`, `update_time`, `remarks`, `del_flag`, `tenant_id`) VALUES (29, 11, '1', '检索', 'param_type', '检索', 0, '2019-04-29 18:22:17', '2019-04-29 18:22:17', '检索', '0', 1); + + + + + + + diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java index b08e7da6d..cd65ef5d6 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java @@ -77,6 +77,11 @@ public interface CommonConstants { */ String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY_"; + /** + * 公共参数 + */ + String PIG_PUBLIC_PARAM_KEY = "PIG_PUBLIC_PARAM_KEY"; + /** * 成功标记 */ diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysPublicParam.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysPublicParam.java new file mode 100644 index 000000000..53739b718 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysPublicParam.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 公共参数配置 + * + * @author Lucky + * @date 2019-04-29 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel(description = "公共参数") +public class SysPublicParam extends Model { + private static final long serialVersionUID = 1L; + + /** + * 编号 + */ + @TableId + private Long publicId; + + /** + * 公共参数名称 + */ + @ApiModelProperty(value = "公共参数名称", required = true, example = "公共参数名称") + private String publicName; + + /** + * 公共参数地址值,英文大写+下划线 + */ + @ApiModelProperty(value = "键[英文大写+下划线]", required = true, example = "PIGX_PUBLIC_KEY") + private String publicKey; + + /** + * 值 + */ + @ApiModelProperty(value = "值", required = true, example = "999") + private String publicValue; + + /** + * 状态(1有效;2无效;) + */ + @ApiModelProperty(value = "标识[1有效;2无效]", example = "1") + private String status; + + /** + * 删除状态(0:正常 1:已删除) + */ + @ApiModelProperty(value = "状态[0-正常,1-删除]", example = "0") + private String deleteFlag; + + /** + * 公共参数编码 + */ + @ApiModelProperty(value = "编码", example = "^(PIG|PIGX)$") + private String validateCode; + + /** + * 创建时间 + */ + @ApiModelProperty(value = "创建时间", example = "2019-03-21 12:28:48") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime createTime; + + /** + * 修改时间 + */ + @ApiModelProperty(value = "修改时间", example = "2019-03-21 12:28:48") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime updateTime; + + /** + * 配置类型:0-默认;1-检索;2-原文;3-报表;4-安全;5-文档;6-消息;9-其他 + */ + @ApiModelProperty(value = "类型[1-检索;2-原文...]", example = "1") + private String publicType; + +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ParamVo.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ParamVo.java new file mode 100644 index 000000000..800a8219f --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/ParamVo.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.api.vo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author: Lucky + * @date: 2019/04/28 + *

+ * 公共参数 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParamVo implements Serializable { + + private static final long serialVersionUID = 1L; + /** + * 公共参数键 + */ + private String publicKey; + /** + * 公共参数值 + */ + private String publicValue; + /** + * 公共参数名 + */ + private String publicName; +} \ No newline at end of file diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/DynamicParamInitRunner.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/DynamicParamInitRunner.java new file mode 100644 index 000000000..aa6b7a684 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/DynamicParamInitRunner.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.config; + +import com.pig4cloud.pigx.admin.api.vo.ParamVo; +import com.pig4cloud.pigx.admin.service.SysPublicParamService; +import com.pig4cloud.pigx.admin.support.DynamicParamInitEvent; +import com.pig4cloud.pigx.common.core.constant.CommonConstants; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.EventListener; +import org.springframework.core.annotation.Order; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.scheduling.annotation.Async; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author lucky + * @date 2019/4/28 + *

+ * 启动后保存配置文件里面的公共参数信息到Redis + */ +@Slf4j +@Configuration +@AllArgsConstructor +public class DynamicParamInitRunner { + private final RedisTemplate redisTemplate; + private final SysPublicParamService sysPublicParamService; + public static final String PIG_PUBLIC_PARAM_KEY = CommonConstants.PIG_PUBLIC_PARAM_KEY; + @Async + @Order + @EventListener({WebServerInitializedEvent.class, DynamicParamInitEvent.class}) + public R initPrope() { + log.info("初始化公共参数配置 {} ", PIG_PUBLIC_PARAM_KEY); + //列信息 + List paramVoList = new ArrayList<>(); + sysPublicParamService.querySysPublicParam().forEach(param -> { + ParamVo paramVo = new ParamVo(); + String publicKey = param.getPublicKey(); + paramVo.setPublicKey(publicKey); + paramVo.setPublicValue(param.getPublicValue()); + paramVo.setPublicName(param.getPublicName()); + log.info("加载公共参数ID:{},{}", publicKey, paramVo); + redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(ParamVo.class)); + redisTemplate.opsForHash().put(PIG_PUBLIC_PARAM_KEY, publicKey, paramVo); + paramVoList.add(paramVo); + }); + log.debug("初始化公共参数配置结束 "); + return new R<>(paramVoList); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysPublicParamController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysPublicParamController.java new file mode 100644 index 000000000..20074bc05 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysPublicParamController.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.controller; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.pig4cloud.pigx.admin.api.entity.SysPublicParam; +import com.pig4cloud.pigx.common.core.util.R; +import com.pig4cloud.pigx.admin.service.SysPublicParamService; +import com.pig4cloud.pigx.common.log.annotation.SysLog; +import com.pig4cloud.pigx.common.security.annotation.Inner; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang.StringUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + + +/** + * 公共参数 + * + * @author Lucky + * @date 2019-04-29 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/param" ) +@Api(value = "param", tags = "公共参数配置") +public class SysPublicParamController { + + private final SysPublicParamService sysPublicParamService; + + /** + * 通过key查询公共参数值 + * @param publicKey + * @return + * @throws Exception + */ + @Inner(value = false) + @ApiOperation(value = "查询公共参数值",notes = "根据key查询公共参数值") + @ApiImplicitParams({@ApiImplicitParam(name = "publicKey",value = "键值,譬如:VERSION_INSTRUCTIONS",required = true)}) + @GetMapping("/publicValue/{publicKey}") + public R publicKey(@PathVariable("publicKey") String publicKey) throws Exception { + String publicValue = sysPublicParamService.getSysPublicParamKeyToValue(publicKey); + if(StringUtils.isEmpty(publicValue)){ + return R.builder().code(44005).msg("查询数据内容为空").build(); + } + return new R<>(publicValue); + } + + /** + * 分页查询 + * @param page 分页对象 + * @param sysPublicParam 公共参数 + * @return + */ + @GetMapping("/page" ) + public R getSysPublicParamPage(Page page, SysPublicParam sysPublicParam) { + return new R<>(sysPublicParamService.page(page, Wrappers.query(sysPublicParam))); + } + + + /** + * 通过id查询公共参数 + * @param publicId id + * @return R + */ + @GetMapping("/{publicId}" ) + public R getById(@PathVariable("publicId" ) Long publicId) { + return new R<>(sysPublicParamService.getById(publicId)); + } + + /** + * 新增公共参数 + * @param sysPublicParam 公共参数 + * @return R + */ + @SysLog("新增公共参数" ) + @PostMapping + @PreAuthorize("@pms.hasPermission('admin_syspublicparam_add')" ) + public R save(@RequestBody SysPublicParam sysPublicParam) { + return new R<>(sysPublicParamService.save(sysPublicParam)); + } + + /** + * 修改公共参数 + * @param sysPublicParam 公共参数 + * @return R + */ + @SysLog("修改公共参数" ) + @PutMapping + @PreAuthorize("@pms.hasPermission('admin_syspublicparam_edit')" ) + public R updateById(@RequestBody SysPublicParam sysPublicParam) { + return new R<>(sysPublicParamService.updateById(sysPublicParam)); + } + + /** + * 通过id删除公共参数 + * @param publicId id + * @return R + */ + @SysLog("删除公共参数" ) + @DeleteMapping("/{publicId}" ) + @PreAuthorize("@pms.hasPermission('admin_syspublicparam_del')" ) + public R removeById(@PathVariable Long publicId) { + return new R<>(sysPublicParamService.removeById(publicId)); + } + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysPublicParamMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysPublicParamMapper.java new file mode 100644 index 000000000..542590821 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysPublicParamMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysPublicParam; + +/** + * 公共参数配置 + * + * @author Lucky + * @date 2019-04-29 + */ +public interface SysPublicParamMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysPublicParamService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysPublicParamService.java new file mode 100644 index 000000000..f03c43824 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysPublicParamService.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysPublicParam; + +import java.util.List; + +/** + * 公共参数配置 + * + * @author Lucky + * @date 2019-04-29 + */ +public interface SysPublicParamService extends IService { + + /** + * 查询所有 + * @return + */ + List querySysPublicParam(); + + /** + * 通过key查询公共参数指定值 + * @param publicKey + * @return + */ + String getSysPublicParamKeyToValue(String publicKey); +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysPublicParamServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysPublicParamServiceImpl.java new file mode 100644 index 000000000..6fa485120 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysPublicParamServiceImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysPublicParam; +import com.pig4cloud.pigx.admin.api.vo.ParamVo; +import com.pig4cloud.pigx.admin.mapper.SysPublicParamMapper; +import com.pig4cloud.pigx.admin.service.SysPublicParamService; +import com.pig4cloud.pigx.common.core.constant.CommonConstants; +import lombok.AllArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 公共参数配置 + * + * @author Lucky + * @date 2019-04-29 + */ +@Service +@AllArgsConstructor +public class SysPublicParamServiceImpl extends ServiceImpl implements SysPublicParamService { + + private final RedisTemplate redisTemplate; + + @Override + public List querySysPublicParam() { + List paramList = baseMapper.selectList(Wrappers.emptyWrapper()); + return paramList; + } + + @Override + public String getSysPublicParamKeyToValue(String publicKey) { + String groupName = CommonConstants.PIG_PUBLIC_PARAM_KEY; + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(ParamVo.class)); + //List values = redisTemplate.opsForHash().values(groupName); + ParamVo mapValue = (ParamVo) redisTemplate.opsForHash().get(groupName, publicKey); + + if(ObjectUtil.isNull(mapValue)){ + return ""; + } + return mapValue.getPublicValue(); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/support/DynamicParamInitEvent.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/support/DynamicParamInitEvent.java new file mode 100644 index 000000000..b38c5638d --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/support/DynamicParamInitEvent.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.support; + +import org.springframework.context.ApplicationEvent; + +/** + * @author lucky + * @date 2019/2/23 + *

+ * 公共参数初始化事件 + */ +public class DynamicParamInitEvent extends ApplicationEvent { + public DynamicParamInitEvent(Object source) { + super(source); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysPublicParamMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysPublicParamMapper.xml new file mode 100644 index 000000000..0d6b65d47 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysPublicParamMapper.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + +