From 9f9ecbd05f543c49a1a5fc79fe4a7675176cceca Mon Sep 17 00:00:00 2001 From: lbw Date: Thu, 7 Dec 2023 09:35:27 +0800 Subject: [PATCH 1/4] :bookmark: Releasing / Version tags. v5.3 Improving structure / format of the code. --- pigx-visual/pigx-report-platform/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigx-visual/pigx-report-platform/pom.xml b/pigx-visual/pigx-report-platform/pom.xml index 51eb953ee..75537469d 100644 --- a/pigx-visual/pigx-report-platform/pom.xml +++ b/pigx-visual/pigx-report-platform/pom.xml @@ -15,7 +15,7 @@ 基于 GoView 的大屏设计系统 - 0.1.2 + 0.1.3 From 740a9ca2ad8a3ae75fcf5d2e2d227b7610677f98 Mon Sep 17 00:00:00 2001 From: lbw Date: Thu, 7 Dec 2023 13:27:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:card=5Ffile=5Fbox:=20=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9B=B8=E5=85=B3=E7=9A=84=E5=8F=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=BC=98=E5=8C=96=E9=81=BF=E5=85=8D=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=BF=85=E5=A1=AB=E9=A1=B9=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/8pigxx_codegen.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/8pigxx_codegen.sql b/db/8pigxx_codegen.sql index 6e5df567c..36a352949 100644 --- a/db/8pigxx_codegen.sql +++ b/db/8pigxx_codegen.sql @@ -245,12 +245,12 @@ INSERT INTO `gen_template` VALUES (8, 'Mapper.xml', '${backendPath}/src/main/res INSERT INTO `gen_template` VALUES (9, '权限菜单', '${backendPath}/menu/${functionName}_menu.sql', 'menu.sql', '-- 该脚本不要直接执行, 注意维护菜单的父节点ID 默认 父节点-1 , 默认租户 1\n#set($menuId=${dateTool.getSystemTime()})\n\n-- 菜单SQL\ninsert into sys_menu ( menu_id,parent_id, path, permission, menu_type, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)\nvalues (${menuId}, \'-1\', \'/${moduleName}/${functionName}/index\', \'\', \'0\', \'icon-bangzhushouji\', \'0\', null , \'8\', null , \'${tableComment}管理\', 1);\n\n-- 菜单对应按钮SQL\ninsert into sys_menu ( menu_id,parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)\nvalues (${math.add($menuId,1)},${menuId}, \'${moduleName}_${functionName}_view\', \'1\', null, \'1\', \'0\', null, \'0\', null, \'${tableComment}查看\', 1);\n\ninsert into sys_menu ( menu_id,parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)\nvalues (${math.add($menuId,2)},${menuId}, \'${moduleName}_${functionName}_add\', \'1\', null, \'1\', \'0\', null, \'1\', null, \'${tableComment}新增\', 1);\n\ninsert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)\nvalues (${math.add($menuId,3)},${menuId}, \'${moduleName}_${functionName}_edit\', \'1\', null, \'1\', \'0\', null, \'2\', null, \'${tableComment}修改\', 1);\n\ninsert into sys_menu (menu_id, parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)\nvalues (${math.add($menuId,4)},${menuId}, \'${moduleName}_${functionName}_del\', \'1\', null, \'1\', \'0\', null, \'3\', null, \'${tableComment}删除\', 1);\n\ninsert into sys_menu ( menu_id,parent_id, permission, menu_type, path, icon, del_flag, create_time, sort_order, update_time, name, tenant_id)\nvalues (${math.add($menuId,5)},${menuId}, \'${moduleName}_${functionName}_export\', \'1\', null, \'1\', \'0\', null, \'3\', null, \'导入导出\', 1);', '2023-02-23 01:19:08', '2023-08-27 23:16:31', '0', 1, ' ', ' '); INSERT INTO `gen_template` VALUES (10, 'api.ts', '${frontendPath}/src/api/${moduleName}/${functionName}.ts', 'api.ts', 'import request from \"/@/utils/request\"\n\nexport function fetchList(query?: Object) {\n return request({\n url: \'/${moduleName}/${functionName}/page\',\n method: \'get\',\n params: query\n })\n}\n\nexport function addObj(obj?: Object) {\n return request({\n url: \'/${moduleName}/${functionName}\',\n method: \'post\',\n data: obj\n })\n}\n\nexport function getObj(id?: string) {\n return request({\n url: \'/${moduleName}/${functionName}/\' + id,\n method: \'get\'\n })\n}\n\nexport function delObjs(ids?: Object) {\n return request({\n url: \'/${moduleName}/${functionName}\',\n method: \'delete\',\n data: ids\n })\n}\n\nexport function putObj(obj?: Object) {\n return request({\n url: \'/${moduleName}/${functionName}\',\n method: \'put\',\n data: obj\n })\n}\n\n#if($ChildClassName)\nexport function delChildObj(ids?: Object) {\n return request({\n url: \'/${moduleName}/${functionName}/child\',\n method: \'delete\',\n data: ids\n })\n}\n#end', '2023-02-23 01:19:23', '2023-06-04 10:34:17', '0', 1, ' ', ' '); INSERT INTO `gen_template` VALUES (11, '表格', '${frontendPath}/src/views/${moduleName}/${functionName}/index.vue', '表格不含i18n', '\n\n', '2023-02-23 01:19:35', '2023-08-29 14:27:53', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (12, '表单', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', '表单不含i18n', '\n\n', '2023-02-23 01:19:48', '2023-09-12 21:59:33', '0', 1, '', 'admin'); +INSERT INTO `gen_template` VALUES (12, '表单', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', '表单不含i18n', '\n\n', '2023-02-23 01:19:48', '2023-12-07 13:20:22', '0', 1, '', 'admin'); INSERT INTO `gen_template` VALUES (13, 'i18n英文模板', '${frontendPath}/src/views/${moduleName}/${functionName}/i18n/en.ts', 'i18n英文模板', 'export default {\n ${functionName}: {\n index: \'#\',\n import${className}Tip: \'import ${ClassName}\',\n#foreach($field in $fieldList)\n ${field.attrName}: \'${field.attrName}\',\n#end\n#foreach($field in $fieldList)\n input$str.pascalCase(${field.attrName})Tip: \'input ${field.attrName}\',\n#end\n }\n}', '2023-02-23 01:20:25', '2023-06-04 10:49:25', '0', 1, '', 'admin'); INSERT INTO `gen_template` VALUES (14, 'i18n中文模板', '${frontendPath}/src/views/${moduleName}/${functionName}/i18n/zh-cn.ts', 'i18n中文模板', 'export default {\n ${functionName}: {\n index: \'#\',\n import${className}Tip: \'导入${tableComment}\',\n#foreach($field in $fieldList)\n ${field.attrName}: \'#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end\',\n#end\n#foreach($field in $fieldList)\n input$str.pascalCase(${field.attrName})Tip: \'请输入#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end\',\n#end\n }\n}', '2023-02-23 01:20:40', '2023-06-04 10:49:28', '0', 1, '', 'admin'); INSERT INTO `gen_template` VALUES (15, '子实体', '${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ChildClassName}Entity.java', '子表实体对象', 'package ${package}.${moduleName}.entity;\n\nimport com.baomidou.mybatisplus.annotation.*;\nimport com.baomidou.mybatisplus.extension.activerecord.Model;\nimport io.swagger.v3.oas.annotations.media.Schema;\nimport lombok.Data;\nimport lombok.EqualsAndHashCode;\n#foreach($import in $importList)\nimport $import;\n#end\n\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\n@Data\n@TableName(\"${childTableName}\")\n@EqualsAndHashCode(callSuper = true)\n@Schema(description = \"${childTableName}\")\npublic class ${ChildClassName}Entity extends Model<${ChildClassName}Entity> {\n\n#foreach ($field in $childFieldList)\n#if(${field.fieldComment})#set($comment=${field.fieldComment})#else #set($comment=${field.attrName})#end\n /**\n * $comment\n */\n#if($field.primaryPk == \'1\')\n @TableId(type = IdType.ASSIGN_ID)\n#end\n#if($field.autoFill == \'INSERT\')\n @TableField(fill = FieldFill.INSERT)\n#elseif($field.autoFill == \'INSERT_UPDATE\')\n @TableField(fill = FieldFill.INSERT_UPDATE)\n#elseif($field.autoFill == \'UPDATE\')\n @TableField(fill = FieldFill.UPDATE)\n#end\n#if($field.fieldName == \'del_flag\')\n @TableLogic\n @TableField(fill = FieldFill.INSERT)\n#end\n @Schema(description=\"$comment\"#if($field.hidden),hidden=$field.hidden#end)\n#if($field.formType == \'checkbox\')\n private ${field.attrType}[] $field.attrName;\n#else\n private $field.attrType $field.attrName;\n#end \n#end\n}\n', '2023-06-01 11:07:14', '2023-09-12 16:32:33', '0', 1, ' ', ' '); INSERT INTO `gen_template` VALUES (16, '主子Contoller', '${backendPath}/src/main/java/${packagePath}/${moduleName}/controller/${ClassName}Controller.java', '子表Controller对象', 'package ${package}.${moduleName}.controller;\n\n#if($queryList)\nimport cn.hutool.core.util.StrUtil;\n#end\nimport cn.hutool.core.util.ArrayUtil;\nimport com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;\nimport com.baomidou.mybatisplus.core.toolkit.Wrappers;\nimport com.baomidou.mybatisplus.extension.plugins.pagination.Page;\nimport com.pig4cloud.pigx.common.core.util.R;\nimport com.pig4cloud.pigx.common.log.annotation.SysLog;\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\nimport ${package}.${moduleName}.entity.${ChildClassName}Entity;\nimport ${package}.${moduleName}.service.${ClassName}Service;\nimport org.springframework.security.access.prepost.PreAuthorize;\nimport com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;\nimport io.swagger.v3.oas.annotations.security.SecurityRequirement;\n#if($isSpringBoot3)\nimport org.springdoc.core.annotations.ParameterObject;\n#else\nimport org.springdoc.api.annotations.ParameterObject;\n#end\nimport org.springframework.http.HttpHeaders;\nimport io.swagger.v3.oas.annotations.tags.Tag;\nimport io.swagger.v3.oas.annotations.Operation;\nimport lombok.RequiredArgsConstructor;\nimport org.springframework.web.bind.annotation.*;\n\nimport java.util.List;\nimport java.util.Objects;\n\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\n@RestController\n@RequiredArgsConstructor\n@RequestMapping(\"/${functionName}\" )\n@Tag(description = \"${functionName}\" , name = \"${tableComment}管理\" )\n@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)\npublic class ${ClassName}Controller {\n\n private final ${ClassName}Service ${className}Service;\n\n /**\n * 分页查询\n * @param page 分页对象\n * @param ${className} ${tableComment}\n * @return\n */\n @Operation(summary = \"分页查询\" , description = \"分页查询\" )\n @GetMapping(\"/page\" )\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_view\')\" )\n public R get${ClassName}Page(@ParameterObject Page page, @ParameterObject ${ClassName}Entity ${className}) {\n LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();\n#foreach ($field in $queryList)\n#set($getAttrName=$str.getProperty($field.attrName))\n#set($var=\"${className}.$getAttrName()\")\n#if($field.attrType == \'String\')\n#set($expression=\"StrUtil.isNotBlank\")\n#else\n#set($expression=\"Objects.nonNull\")\n#end\n#if($field.queryType == \'=\')\n wrapper.eq($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'like\' )\n wrapper.like($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'!-\' )\n wrapper.ne($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>\' )\n wrapper.gt($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<\' )\n wrapper.lt($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>=\' )\n wrapper.ge($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<=\' )\n wrapper.le($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'left like\' )\n wrapper.likeLeft($expression($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'right like\' )\n wrapper.likeRight($expression($var),${ClassName}Entity::$getAttrName,$var);\n#end\n#end\n return R.ok(${className}Service.page(page, wrapper));\n }\n\n /**\n * 通过id查询${tableComment}\n * @param ${pk.attrName} id\n * @return R\n */\n @Operation(summary = \"通过id查询\" , description = \"通过id查询\" )\n @GetMapping(\"/{${pk.attrName}}\" )\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_view\')\" )\n public R getById(@PathVariable(\"${pk.attrName}\" ) ${pk.attrType} ${pk.attrName}) {\n return R.ok(${className}Service.getByIdDeep(${pk.attrName}));\n }\n\n /**\n * 新增${tableComment}\n * @param ${className} ${tableComment}\n * @return R\n */\n @Operation(summary = \"新增${tableComment}\" , description = \"新增${tableComment}\" )\n @SysLog(\"新增${tableComment}\" )\n @PostMapping\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_add\')\" )\n public R save(@RequestBody ${ClassName}Entity ${className}) {\n return R.ok(${className}Service.saveDeep(${className}));\n }\n\n /**\n * 修改${tableComment}\n * @param ${className} ${tableComment}\n * @return R\n */\n @Operation(summary = \"修改${tableComment}\" , description = \"修改${tableComment}\" )\n @SysLog(\"修改${tableComment}\" )\n @PutMapping\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_edit\')\" )\n public R updateById(@RequestBody ${ClassName}Entity ${className}) {\n return R.ok(${className}Service.updateDeep(${className}));\n }\n\n /**\n * 通过id删除${tableComment}\n * @param ids ${pk.attrName}列表\n * @return R\n */\n @Operation(summary = \"通过id删除${tableComment}\" , description = \"通过id删除${tableComment}\" )\n @SysLog(\"通过id删除${tableComment}\" )\n @DeleteMapping\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_del\')\" )\n public R removeById(@RequestBody ${pk.attrType}[] ids) {\n return R.ok(${className}Service.removeDeep(ids));\n }\n\n /**\n * 通过id删除${tableComment}子表数据\n * @param ids ${pk.attrName}列表\n * @return R\n */\n @Operation(summary = \"通过id删除${tableComment}子表数据\" , description = \"通过id删除${tableComment}子表数据\" )\n @SysLog(\"通过id删除${tableComment}子表数据\" )\n @DeleteMapping(\"/child\")\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_del\')\" )\n public R removeChild(@RequestBody ${pk.attrType}[] ids) {\n return R.ok(${className}Service.removeChild(ids));\n }\n\n /**\n * 导出excel 表格\n * @param ${className} 查询条件\n * @param ids 导出指定ID\n * @return excel 文件流\n */\n @ResponseExcel\n @GetMapping(\"/export\")\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_export\')\" )\n public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {\n return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));\n }\n}', '2023-06-01 11:25:28', '2023-10-29 12:17:52', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (17, '主子表单', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', '子表表单', '\n\n', '2023-06-01 15:42:46', '2023-09-12 21:58:41', '0', 1, '', 'admin'); +INSERT INTO `gen_template` VALUES (17, '主子表单', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', '子表表单', '\n\n', '2023-06-01 15:42:46', '2023-12-07 13:22:29', '0', 1, '', 'admin'); INSERT INTO `gen_template` VALUES (18, '主子表格', '${frontendPath}/src/views/${moduleName}/${functionName}/index.vue', '子表单表格', '\n\n', '2023-06-01 15:43:31', '2023-08-29 10:53:23', '0', 1, ' ', ' '); INSERT INTO `gen_template` VALUES (19, '子Mapper', '${backendPath}/src/main/java/${packagePath}/${moduleName}/mapper/${ChildClassName}Mapper.java', '子Mapper', 'package ${package}.${moduleName}.mapper;\n\nimport com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;\n#if($ChildClassName)\nimport ${package}.${moduleName}.entity.${ChildClassName}Entity;\n#else\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\n#end\nimport org.apache.ibatis.annotations.Mapper;\n\n@Mapper\n#if($ChildClassName)\npublic interface ${ChildClassName}Mapper extends PigxBaseMapper<${ChildClassName}Entity> {\n#else\npublic interface ${ClassName}Mapper extends PigxBaseMapper<${ClassName}Entity> {\n#end\n\n}', '2023-02-23 01:18:18', '2023-08-07 09:54:36', '0', 1, ' ', ' '); COMMIT; From 66b18183c82fc275cc089f85b42f84d9103fd1c1 Mon Sep 17 00:00:00 2001 From: lbw Date: Fri, 8 Dec 2023 11:34:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.?= =?UTF-8?q?=20=E5=90=8C=E6=AD=A5=E8=B7=AF=E7=94=B1=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SysRouteConfController.java | 30 ++-- .../admin/service/SysRouteConfService.java | 6 +- .../service/impl/SysRouteConfServiceImpl.java | 133 +++++++----------- 3 files changed, 74 insertions(+), 95 deletions(-) diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRouteConfController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRouteConfController.java index 182547743..32c1b6967 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRouteConfController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRouteConfController.java @@ -17,7 +17,10 @@ package com.pig4cloud.pigx.admin.controller; -import cn.hutool.json.JSONArray; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.pig4cloud.pigx.admin.api.entity.SysRouteConf; import com.pig4cloud.pigx.admin.service.SysRouteConfService; import com.pig4cloud.pigx.common.core.util.R; import com.pig4cloud.pigx.common.log.annotation.SysLog; @@ -47,19 +50,26 @@ public class SysRouteConfController { * @return */ @GetMapping - public R listRoutes() { - return R.ok(sysRouteConfService.list()); + public R listRoutes(@RequestParam(required = false) String routeId) { + return R.ok(sysRouteConfService.list(Wrappers.lambdaQuery().eq(StrUtil.isNotBlank(routeId), + SysRouteConf::getRouteId, routeId))); + } + + @DeleteMapping("/{routeId}") + public R deleteRoute(@PathVariable String routeId) { + return R.ok( + sysRouteConfService.remove(Wrappers.lambdaQuery().eq(SysRouteConf::getRouteId, routeId))); } /** - * 修改路由 - * @param routes 路由定义 - * @return + * 新增修改路由 + * @param route 路由定义 + * @return success */ - @SysLog("修改路由") - @PutMapping - public R updateRoutes(@RequestBody JSONArray routes) { - return R.ok(sysRouteConfService.updateRoutes(routes)); + @SysLog("新增修改路由") + @PostMapping + public R addOrUpdateRoute(@RequestBody JSONObject route) { + return R.ok(sysRouteConfService.addOrUpdateRoute(route)); } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRouteConfService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRouteConfService.java index c4b8ccc72..0fcd140d2 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRouteConfService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRouteConfService.java @@ -17,7 +17,7 @@ package com.pig4cloud.pigx.admin.service; -import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.extension.service.IService; import com.pig4cloud.pigx.admin.api.entity.SysRouteConf; import reactor.core.publisher.Mono; @@ -32,9 +32,9 @@ public interface SysRouteConfService extends IService { /** * 更新路由信息 - * @param routes 路由信息 + * @param route 路由信息 * @return */ - Mono updateRoutes(JSONArray routes); + Mono addOrUpdateRoute(JSONObject route); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java index 52cef406e..13dc0b5a2 100755 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRouteConfServiceImpl.java @@ -17,15 +17,15 @@ package com.pig4cloud.pigx.admin.service.impl; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.pig4cloud.pigx.admin.api.entity.SysRouteConf; import com.pig4cloud.pigx.admin.mapper.SysRouteConfMapper; import com.pig4cloud.pigx.admin.service.SysRouteConfService; -import com.pig4cloud.pigx.common.core.constant.CacheConstants; -import com.pig4cloud.pigx.common.core.constant.CommonConstants; import com.pig4cloud.pigx.common.gateway.support.DynamicRouteInitEvent; import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo; import lombok.AllArgsConstructor; @@ -33,17 +33,13 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.gateway.filter.FilterDefinition; import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition; import org.springframework.context.ApplicationEventPublisher; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; import java.net.URI; -import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * @author lengleng @@ -57,107 +53,80 @@ import java.util.stream.Collectors; public class SysRouteConfServiceImpl extends ServiceImpl implements SysRouteConfService { - private final RedisTemplate redisTemplate; - private final ApplicationEventPublisher applicationEventPublisher; /** * 更新路由信息 - * @param routes 路由信息 + * @param route 路由信息 * @return */ @Override @Transactional(rollbackFor = Exception.class) - public Mono updateRoutes(JSONArray routes) { - // 清空Redis 缓存 - Boolean result = redisTemplate.delete(CacheConstants.ROUTE_KEY); - log.info("清空网关路由 {} ", result); - - // 遍历修改的routes,保存到Redis - List routeDefinitionVoList = new ArrayList<>(); - + public Mono addOrUpdateRoute(JSONObject route) { try { - routes.forEach(value -> { - log.info("更新路由 ->{}", value); - RouteDefinitionVo vo = new RouteDefinitionVo(); - Map map = (Map) value; + log.info("更新路由 ->{}", route); + RouteDefinitionVo vo = new RouteDefinitionVo(); - Object id = map.get("routeId"); - if (id != null) { - vo.setId(String.valueOf(id)); - } + String id = route.getStr("routeId"); + if (StrUtil.isNotBlank(id)) { + vo.setId(id); + } - Object routeName = map.get("routeName"); - if (routeName != null) { - vo.setRouteName(String.valueOf(routeName)); - } + String routeName = route.getStr("routeName"); + if (StrUtil.isNotBlank(routeName)) { + vo.setRouteName(routeName); + } - Object predicates = map.get("predicates"); - if (predicates != null) { - JSONArray predicatesArray = (JSONArray) predicates; - List predicateDefinitionList = predicatesArray - .toList(PredicateDefinition.class); - vo.setPredicates(predicateDefinitionList); - } + JSONArray predicates = route.getJSONArray("predicates"); + if (predicates != null) { + List predicateDefinitionList = predicates.toList(PredicateDefinition.class); + vo.setPredicates(predicateDefinitionList); + } - Object filters = map.get("filters"); - if (filters != null) { - JSONArray filtersArray = (JSONArray) filters; - List filterDefinitionList = filtersArray.toList(FilterDefinition.class); - vo.setFilters(filterDefinitionList); - } + JSONArray filters = route.getJSONArray("filters"); + if (filters != null) { + List filterDefinitionList = filters.toList(FilterDefinition.class); + vo.setFilters(filterDefinitionList); + } - Object uri = map.get("uri"); - if (uri != null) { - vo.setUri(URI.create(String.valueOf(uri))); - } + Object uri = route.getStr("uri"); + if (uri != null) { + vo.setUri(URI.create(String.valueOf(uri))); + } - Object order = map.get("order"); - if (order != null) { - vo.setOrder(Integer.parseInt(String.valueOf(order))); - } + Integer order = route.getInt("order"); + if (order != null) { + vo.setOrder(order); + } - Object metadata = map.get("metadata"); - if (metadata != null) { - Map metadataMap = JSONUtil.toBean(String.valueOf(metadata), Map.class); - vo.setMetadata(metadataMap); - } + Map metadataMap = route.getBean("metadata", Map.class); + if (metadataMap != null) { + vo.setMetadata(metadataMap); + } - redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(RouteDefinitionVo.class)); - redisTemplate.opsForHash().put(CacheConstants.ROUTE_KEY, vo.getId(), vo); - routeDefinitionVoList.add(vo); - }); - - // 逻辑删除全部 - SysRouteConf condition = new SysRouteConf(); - condition.setDelFlag(CommonConstants.STATUS_NORMAL); - this.remove(new UpdateWrapper<>(condition)); + // 逻辑删除 ,不直接更新避免危险! + this.remove(Wrappers.lambdaQuery().eq(SysRouteConf::getRouteId, id)); // 插入生效路由 - List routeConfList = routeDefinitionVoList.stream().map(vo -> { - SysRouteConf routeConf = new SysRouteConf(); - routeConf.setRouteId(vo.getId()); - routeConf.setRouteName(vo.getRouteName()); - routeConf.setFilters(JSONUtil.toJsonStr(vo.getFilters())); - routeConf.setPredicates(JSONUtil.toJsonStr(vo.getPredicates())); - routeConf.setSortOrder(vo.getOrder()); - routeConf.setUri(vo.getUri().toString()); - routeConf.setMetadata(JSONUtil.toJsonStr(vo.getMetadata())); - return routeConf; - }).collect(Collectors.toList()); - this.saveBatch(routeConfList); + SysRouteConf routeConf = new SysRouteConf(); + routeConf.setRouteId(vo.getId()); + routeConf.setRouteName(vo.getRouteName()); + routeConf.setFilters(JSONUtil.toJsonStr(vo.getFilters())); + routeConf.setPredicates(JSONUtil.toJsonStr(vo.getPredicates())); + routeConf.setSortOrder(vo.getOrder()); + routeConf.setUri(vo.getUri().toString()); + routeConf.setMetadata(JSONUtil.toJsonStr(vo.getMetadata())); + this.save(routeConf); log.debug("更新网关路由结束 "); - - // 通知网关重置路由 - redisTemplate.convertAndSend(CacheConstants.ROUTE_JVM_RELOAD_TOPIC, "路由信息,网关缓存更新"); } catch (Exception e) { log.error("路由配置解析失败", e); - // 回滚路由,重新加载即可 - this.applicationEventPublisher.publishEvent(new DynamicRouteInitEvent(this)); // 抛出异常 throw new RuntimeException(e); } + finally { + this.applicationEventPublisher.publishEvent(new DynamicRouteInitEvent(this)); + } return Mono.empty(); } From 7ba0be3b179e436cf4b8b166ab7cac4ead10413a Mon Sep 17 00:00:00 2001 From: lbw Date: Mon, 4 Mar 2024 21:57:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99=E5=A4=B1=E6=95=88?= =?UTF-8?q?=20SqlInjectionUtils=20Error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resolver/SqlFilterArgumentResolver.java | 105 +++++++++--------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/resolver/SqlFilterArgumentResolver.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/resolver/SqlFilterArgumentResolver.java index a0ce13631..41660cf3b 100644 --- a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/resolver/SqlFilterArgumentResolver.java +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/resolver/SqlFilterArgumentResolver.java @@ -46,66 +46,65 @@ import java.util.stream.Collectors; @Slf4j public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver { - private final static String[] KEYWORDS = { "master", "truncate", "insert", "select", "delete", "update", "declare", - "alter", "drop", "sleep", "extractvalue", "concat" }; - /** - * 判断Controller是否包含page 参数 - * @param parameter 参数 - * @return 是否过滤 - */ - @Override - public boolean supportsParameter(MethodParameter parameter) { - return parameter.getParameterType().equals(Page.class); - } + /** + * 判断Controller是否包含page 参数 + * + * @param parameter 参数 + * @return 是否过滤 + */ + @Override + public boolean supportsParameter(MethodParameter parameter) { + return parameter.getParameterType().equals(Page.class); + } - /** - * @param parameter 入参集合 - * @param mavContainer model 和 view - * @param webRequest web相关 - * @param binderFactory 入参解析 - * @return 检查后新的page对象 - *

- * page 只支持查询 GET .如需解析POST获取请求报文体处理 - */ - @Override - public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { + /** + * @param parameter 入参集合 + * @param mavContainer model 和 view + * @param webRequest web相关 + * @param binderFactory 入参解析 + * @return 检查后新的page对象 + *

+ * page 只支持查询 GET .如需解析POST获取请求报文体处理 + */ + @Override + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { - HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); + HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); - String ascs = request.getParameter("ascs"); - String descs = request.getParameter("descs"); + String ascs = request.getParameter("ascs"); + String descs = request.getParameter("descs"); - String current = request.getParameter("current"); - String size = request.getParameter("size"); + String current = request.getParameter("current"); + String size = request.getParameter("size"); - Page page = new Page(); - if (StrUtil.isNotBlank(current)) { - // 如果current page 小于零 视为不合法数据 - if (CompareUtil.compare(Long.parseLong(current), 0L) < 0) { - throw new CheckedException("current page error"); - } - page.setCurrent(Long.parseLong(current)); - } + Page page = new Page(); + if (StrUtil.isNotBlank(current)) { + // 如果current page 小于零 视为不合法数据 + if (CompareUtil.compare(Long.parseLong(current), 0L) < 0) { + throw new CheckedException("current page error"); + } + page.setCurrent(Long.parseLong(current)); + } - if (StrUtil.isNotBlank(size)) { - page.setSize(Long.parseLong(size)); - } + if (StrUtil.isNotBlank(size)) { + page.setSize(Long.parseLong(size)); + } - List orderItemList = new ArrayList<>(); - Optional.ofNullable(ascs) - .ifPresent(s -> orderItemList.addAll(Arrays.stream(s.split(StrUtil.COMMA)) - .filter(SqlInjectionUtils::check) - .map(OrderItem::asc) - .collect(Collectors.toList()))); - Optional.ofNullable(descs) - .ifPresent(s -> orderItemList.addAll(Arrays.stream(s.split(StrUtil.COMMA)) - .filter(SqlInjectionUtils::check) - .map(OrderItem::desc) - .collect(Collectors.toList()))); - page.addOrder(orderItemList); + List orderItemList = new ArrayList<>(); + Optional.ofNullable(ascs) + .ifPresent(s -> orderItemList.addAll(Arrays.stream(s.split(StrUtil.COMMA)) + .filter(asc -> !SqlInjectionUtils.check(asc)) + .map(OrderItem::asc) + .collect(Collectors.toList()))); + Optional.ofNullable(descs) + .ifPresent(s -> orderItemList.addAll(Arrays.stream(s.split(StrUtil.COMMA)) + .filter(desc -> !SqlInjectionUtils.check(desc)) + .map(OrderItem::desc) + .collect(Collectors.toList()))); + page.addOrder(orderItemList); - return page; - } + return page; + } }