From 64630b1c7e26583fb2c21d0d219c817e02c34dcd Mon Sep 17 00:00:00 2001 From: lbw Date: Tue, 20 Jun 2023 16:00:22 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=9A=84=E4=B8=BB=E5=AD=90=E8=A1=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/2pigxx.sql | 2 +- db/8pigxx_codegen.sql | 75 +++++++------------ .../controller/GenTableController.java | 10 +++ .../pigx/codegen/entity/GenTable.java | 21 ++++++ .../pigx/codegen/mapper/GeneratorMapper.java | 7 ++ .../codegen/service/GenFormConfService.java | 3 +- .../pigx/codegen/service/GenTableService.java | 7 +- .../service/impl/GenFormConfServiceImpl.java | 71 +++++++++++++----- .../service/impl/GenTableServiceImpl.java | 20 ++++- .../service/impl/GeneratorServiceImpl.java | 39 +++++++++- .../pig4cloud/pigx/codegen/util/GenKit.java | 2 +- .../pigx/codegen/util/NamingCaseTool.java | 4 + .../pigx/codegen/util/VFormConfigConsts.java | 25 +++++++ .../pigx/codegen/util/VFormTypeEnum.java | 22 ++++++ 14 files changed, 233 insertions(+), 75 deletions(-) create mode 100644 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormConfigConsts.java create mode 100644 pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormTypeEnum.java diff --git a/db/2pigxx.sql b/db/2pigxx.sql index 088285163..0cb2e36e2 100644 --- a/db/2pigxx.sql +++ b/db/2pigxx.sql @@ -752,7 +752,7 @@ CREATE TABLE `sys_role` ( -- ---------------------------- BEGIN; INSERT INTO `sys_role` VALUES (1, '管理员', 'ROLE_ADMIN', '管理员', '0', '', '', 'edg134', '2017-10-29 15:45:51', '2023-04-06 14:03:28', '0', 1); -INSERT INTO `sys_role` VALUES (2, '普通用户', 'GENERAL_USER', '普通用户', '0', '', '', 'admin', '2022-03-31 17:03:15', '2023-04-03 02:28:51', '1', 1); +INSERT INTO `sys_role` VALUES (2, '普通用户', 'GENERAL_USER', '普通用户', '0', '', '', 'admin', '2022-03-31 17:03:15', '2023-04-03 02:28:51', '0', 1); COMMIT; -- ---------------------------- diff --git a/db/8pigxx_codegen.sql b/db/8pigxx_codegen.sql index 214f213f3..2fbe7206e 100644 --- a/db/8pigxx_codegen.sql +++ b/db/8pigxx_codegen.sql @@ -233,24 +233,24 @@ CREATE TABLE `gen_template` ( -- Records of gen_template -- ---------------------------- BEGIN; -INSERT INTO `gen_template` VALUES (1, 'template/plus/vform/vform.json.vm', '/', '表单设计器初始化json模板', '#set($key=${dateTool.getSystemTime()})\n{\n \"widgetList\": [\n {\n \"key\": $key,\n \"type\": \"grid\",\n \"category\": \"container\",\n \"icon\": \"grid\",\n \"cols\": [\n#foreach($field in $formList)\n#if($field.attrName != ${pk.attrName})\n {\n \"type\": \"grid-col\",\n \"category\": \"container\",\n \"icon\": \"grid-col\",\n \"internal\": true,\n \"widgetList\": [\n {\n \"key\": ${math.add($key,${foreach.index})},\n #if($field.formType == \'text\')\n \"type\": \"input\",\n \"icon\": \"text-field\",\n #elseif($field.formType == \'number\')\n \"type\": \"number\",\n \"icon\": \"number-field\",\n #elseif($field.formType == \'textarea\')\n \"type\": \"textarea\",\n \"icon\": \"textarea-field\",\n #elseif($field.formType == \'select\' && ${field.fieldDict})\n \"type\": \"select\",\n \"icon\": \"select-field\",\n #elseif($field.formType == \'radio\' && ${field.fieldDict})\n \"type\": \"radio\",\n \"icon\": \"radio-field\",\n #elseif($field.formType == \'checkbox\' && ${field.fieldDict} )\n \"type\": \"checkbox\",\n \"icon\": \"checkbox-field\",\n #elseif($field.formType == \'date\')\n \"type\": \"date\",\n \"icon\": \"date-field\",\n #elseif($field.formType == \'datetime\')\n \"type\": \"time\",\n \"icon\": \"time-field\",\n #elseif($field.formType == \'upload-file\')\n \"type\": \"file-upload\",\n \"icon\": \"file-upload-field\",\n #elseif($field.formType == \'upload-img\')\n \"type\": \"picture-upload\",\n \"icon\": \"picture-upload-field\",\n #elseif($field.formType == \'editor\')\n \"type\": \"rich-editor\",\n \"icon\": \"rich-editor-field\",\n #else\n \"type\": \"input\",\n \"icon\": \"text-field\",\n #end\n \"formItemFlag\": true,\n \"options\": {\n \"name\": \"${field.attrName}\",\n \"label\": \"#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end\",\n #if(($field.formType == \'select\' || $field.formType == \'radio\' || $field.formType == \'checkbox\') && ${field.fieldDict})\n \"optionItemsDictType\": \"${field.fieldDict}\",\n #end\n \"placeholder\": \"请输入#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end\"\n },\n #if($field.formRequired)\n \"required\": true,\n #end\n \"id\": \"input${math.add($key,${foreach.index})}\"\n }\n ],\n \"options\": {\n \"name\": \"gridCol${math.add($key,${foreach.index})}\",\n \"hidden\": false,\n \"offset\": 0,\n \"push\": 0,\n \"pull\": 0,\n #if($formLayout == 1)\n \"span\": 24,\n #elseif($formLayout == 2)\n \"span\": 12,\n #end\n \"responsive\": false\n },\n \"id\": \"grid-col-${math.add($key,${foreach.index})}\"\n }#if($foreach.hasNext),#end\n#end\n#end\n ],\n \"options\": {\n \"name\": \"grid${functionName}\",\n \"hidden\": false,\n \"gutter\": 12\n },\n \"id\": \"grid${functionName}\"\n }\n ],\n \"formConfig\": {\n \"modelName\": \"form\",\n \"refName\": \"form\",\n \"rulesName\": \"rules\",\n \"labelWidth\": 80,\n \"labelPosition\": \"left\",\n \"labelAlign\": \"label-left-align\",\n \"layoutType\": \"PC\",\n \"jsonVersion\": 3\n }\n}', '2023-02-23 04:33:16', '2023-03-13 03:17:21', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (2, 'template/plus/vform/vform.vue.vm', '/', '表单设计器生成sfc模板', '\n\n', '2023-02-23 04:33:52', '2023-04-02 17:27:47', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (3, 'template/Controller.java.vm', '${backendPath}/src/main/java/${packagePath}/${moduleName}/controller/${ClassName}Controller.java', '后台controller', '/*\n * Copyright (c) 2018-2025, lengleng All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * Neither the name of the pig4cloud.com developer nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n * Author: lengleng (wangiegie@gmail.com)\n */\n\npackage ${package}.${moduleName}.controller;\n\n#if($queryList)\nimport cn.hutool.core.util.StrUtil;\n#end\nimport cn.hutool.core.collection.CollUtil;\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}.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;\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;\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(Page page, ${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.queryType == \'=\')\n wrapper.eq(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'like\' )\n wrapper.like(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'!-\' )\n wrapper.ne(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>\' )\n wrapper.gt(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<\' )\n wrapper.lt(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>=\' )\n wrapper.ge(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<=\' )\n wrapper.le(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'left like\' )\n wrapper.likeLeft(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'right like\' )\n wrapper.likeRight(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#end\n#end\n return R.ok(${className}Service.page(page, wrapper));\n }\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.getById(${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.save(${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.updateById(${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.removeBatchByIds(CollUtil.toList(ids)));\n }\n\n\n /**\n * 导出excel 表格\n * @param ${className} 查询条件\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}) {\n return ${className}Service.list(Wrappers.query(${className}));\n }\n}', '2023-02-23 01:16:17', '2023-02-23 12:13:31', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (4, 'template/Service.java.vm', '${backendPath}/src/main/java/${packagePath}/${moduleName}/service/${ClassName}Service.java', 'Service', '/*\n * Copyright (c) 2018-2025, lengleng All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * Neither the name of the pig4cloud.com developer nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n * Author: lengleng (wangiegie@gmail.com)\n */\n\npackage ${package}.${moduleName}.service;\n\nimport com.baomidou.mybatisplus.extension.service.IService;\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\n\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\npublic interface ${ClassName}Service extends IService<${ClassName}Entity> {\n\n}', '2023-02-23 01:16:53', '2023-02-23 12:13:33', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (5, 'template/ServiceImpl.java.vm', '${backendPath}/src/main/java/${packagePath}/${moduleName}/service/impl/${ClassName}ServiceImpl.java', 'ServiceImpl', '/*\n * Copyright (c) 2018-2025, lengleng All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * Neither the name of the pig4cloud.com developer nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n * Author: lengleng (wangiegie@gmail.com)\n */\npackage ${package}.${moduleName}.service.impl;\n\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\nimport ${package}.${moduleName}.mapper.${ClassName}Mapper;\nimport ${package}.${moduleName}.service.${ClassName}Service;\nimport org.springframework.stereotype.Service;\n\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\n@Service\npublic class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}Entity> implements ${ClassName}Service {\n\n}', '2023-02-23 01:17:36', '2023-02-23 12:13:35', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (6, 'template/Entity.java.vm', '${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ClassName}Entity.java', 'Entity', '/*\n * Copyright (c) 2018-2025, lengleng All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * Neither the name of the pig4cloud.com developer nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n * Author: lengleng (wangiegie@gmail.com)\n */\n\npackage ${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;\nimport java.io.Serializable;\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(\"${tableName}\")\n@EqualsAndHashCode(callSuper = true)\n@Schema(description = \"${tableComment}\")\npublic class ${ClassName}Entity extends Model<${ClassName}Entity> {\n\n private static final long serialVersionUID = 1L;\n\n#foreach ($field in $fieldList)\n#if(${field.fieldComment})#set($comment=${field.fieldComment})#else #set($comment=${field.attrName})#end\n\n /**\n * $comment\n */\n#if($field.primaryPk)\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#end\n @Schema(description=\"$comment\"#if($field.hidden),hidden=$field.hidden#end)\n private $field.attrType $field.attrName;\n#end\n\n}', '2023-02-23 01:17:53', '2023-02-23 12:13:38', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (7, 'template/Mapper.java.vm', '${backendPath}/src/main/java/${packagePath}/${moduleName}/mapper/${ClassName}Mapper.java', 'Mapper', '/*\n * Copyright (c) 2018-2025, lengleng All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * Redistributions of source code must retain the above copyright notice,\n * this list of conditions and the following disclaimer.\n * Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * Neither the name of the pig4cloud.com developer nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n * Author: lengleng (wangiegie@gmail.com)\n */\n\npackage ${package}.${moduleName}.mapper;\n\nimport com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\nimport org.apache.ibatis.annotations.Mapper;\n\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\n@Mapper\npublic interface ${ClassName}Mapper extends PigxBaseMapper<${ClassName}Entity> {\n\n}', '2023-02-23 01:18:18', '2023-02-23 12:13:40', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (8, 'template/Mapper.xml.vm', '${backendPath}/src/main/resources/mapper/${ClassName}Mapper.xml', 'Mapper.xml', '\n\n\n\n\n \n#foreach ($field in $fieldList)\n #if($field.primaryPk)\n \n #end\n #if(!$field.primaryPk)\n \n #end\n#end\n \n', '2023-02-23 01:18:35', '2023-02-23 12:13:44', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (9, 'template/menu.sql.vm', '${backendPath}/menu/${functionName}_menu.sql', 'menu.sql', '-- 该脚本不要直接执行, 注意维护菜单的父节点ID 默认 父节点-1 , 默认租户 1\n#set($menuId=${dateTool.getSystemTime()})\n\n -- 菜单SQL\n insert into `sys_menu` ( `menu_id`,`parent_id`, `path`, `permission`, `menu_type`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${menuId}, \'-1\', \'/${moduleName}/${functionName}/index\', \'\', \'0\', \'icon-bangzhushouji\', \'0\', null , \'8\', null , \'${tableComment}管理\', 1);\n\n-- 按钮父菜单ID\n set @parentId = @@identity;\n\n-- 菜单对应按钮SQL\n insert into `sys_menu` ( `menu_id`,`parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,1)},${menuId}, \'${moduleName}_${functionName}_view\', \'1\', null, \'1\', \'0\', null, \'0\', null, \'${tableComment}查看\', 1);\n\n insert into `sys_menu` ( `menu_id`,`parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,2)},${menuId}, \'${moduleName}_${functionName}_add\', \'1\', null, \'1\', \'0\', null, \'1\', null, \'${tableComment}新增\', 1);\n\n insert into `sys_menu` (`menu_id`, `parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,3)},${menuId}, \'${moduleName}_${functionName}_edit\', \'1\', null, \'1\', \'0\', null, \'2\', null, \'${tableComment}修改\', 1);\n\n insert into `sys_menu` (`menu_id`, `parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,4)},${menuId}, \'${moduleName}_${functionName}_del\', \'1\', null, \'1\', \'0\', null, \'3\', null, \'${tableComment}删除\', 1);\n\n insert into `sys_menu` ( `menu_id`,`parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,5)},${menuId}, \'${moduleName}_${functionName}_export\', \'1\', null, \'1\', \'0\', null, \'3\', null, \'导入导出\', 1);', '2023-02-23 01:19:08', '2023-02-23 12:13:47', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (10, 'template/plus/api.ts.vm', '${frontendPath}/src/api/${moduleName}/${functionName}.ts', 'vue3 版本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}', '2023-02-23 01:19:23', '2023-02-23 12:13:49', '0', 1, ' ', ' '); -INSERT INTO `gen_template` VALUES (11, 'template/plus/index.vue.vm', '${frontendPath}/src/views/${moduleName}/${functionName}/index.vue', 'vue3版本页面不含i18n', '\n\n', '2023-02-23 01:19:35', '2023-04-27 21:02:59', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (12, 'template/plus/form.vue.vm', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', 'vue3版本表单弹窗不含i18n', '\n\n', '2023-02-23 01:19:48', '2023-04-10 22:57:27', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (13, 'template/plus/i18n/index.vue.vm', '${frontendPath}/src/views/${moduleName}/${functionName}/index.vue', 'vue3列表页面含i18n', '\n\n', '2023-02-23 01:20:01', '2023-04-27 21:02:24', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (14, 'template/plus/i18n/form.vue.vm', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', 'vue3表单弹窗页面含i18n', '\n\n', '2023-02-23 01:20:13', '2023-04-10 22:56:03', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (15, 'template/plus/i18n/en.ts.vm', '${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-04-03 18:21:30', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (16, 'template/plus/i18n/zh-cn.ts.vm', '${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-04-03 18:21:42', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (17, 'template/plus/i18n/form-drawer.vue.vm', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', 'vue3表单抽屉页面含i18n', '\n\n', '2023-02-23 12:15:08', '2023-04-10 23:00:16', '0', 1, '', 'admin'); -INSERT INTO `gen_template` VALUES (18, 'template/plus/form-drawer.vue.vm', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', 'vue3表单抽屉页面不含i18n', '\n\n', '2023-02-23 12:17:00', '2023-04-10 23:03:31', '0', 1, '', 'admin'); +INSERT INTO `gen_template` VALUES (1, 'vform.json', '/', '表单设计器初始化json模板', '#set($key=${dateTool.getSystemTime()})\n{\n \"widgetList\": [\n {\n \"key\": $key,\n \"type\": \"grid\",\n \"category\": \"container\",\n \"icon\": \"grid\",\n \"cols\": [\n#foreach($field in $formList)\n#if($field.attrName != ${pk.attrName})\n {\n \"type\": \"grid-col\",\n \"category\": \"container\",\n \"icon\": \"grid-col\",\n \"internal\": true,\n \"widgetList\": [\n {\n \"key\": ${math.add($key,${foreach.index})},\n #if($field.formType == \'text\')\n \"type\": \"input\",\n \"icon\": \"text-field\",\n #elseif($field.formType == \'number\')\n \"type\": \"number\",\n \"icon\": \"number-field\",\n #elseif($field.formType == \'textarea\')\n \"type\": \"textarea\",\n \"icon\": \"textarea-field\",\n #elseif($field.formType == \'select\' && ${field.fieldDict})\n \"type\": \"select\",\n \"icon\": \"select-field\",\n #elseif($field.formType == \'radio\' && ${field.fieldDict})\n \"type\": \"radio\",\n \"icon\": \"radio-field\",\n #elseif($field.formType == \'checkbox\' && ${field.fieldDict} )\n \"type\": \"checkbox\",\n \"icon\": \"checkbox-field\",\n #elseif($field.formType == \'date\')\n \"type\": \"date\",\n \"icon\": \"date-field\",\n #elseif($field.formType == \'datetime\')\n \"type\": \"time\",\n \"icon\": \"time-field\",\n #elseif($field.formType == \'upload-file\')\n \"type\": \"file-upload\",\n \"icon\": \"file-upload-field\",\n #elseif($field.formType == \'upload-img\')\n \"type\": \"picture-upload\",\n \"icon\": \"picture-upload-field\",\n #elseif($field.formType == \'editor\')\n \"type\": \"rich-editor\",\n \"icon\": \"rich-editor-field\",\n #else\n \"type\": \"input\",\n \"icon\": \"text-field\",\n #end\n \"formItemFlag\": true,\n \"options\": {\n \"name\": \"${field.attrName}\",\n \"label\": \"#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end\",\n #if(($field.formType == \'select\' || $field.formType == \'radio\' || $field.formType == \'checkbox\') && ${field.fieldDict})\n \"optionItemsDictType\": \"${field.fieldDict}\",\n #end\n \"placeholder\": \"请输入#if(${field.fieldComment})${field.fieldComment}#else ${field.attrName}#end\"\n },\n #if($field.formRequired)\n \"required\": true,\n #end\n \"id\": \"input${math.add($key,${foreach.index})}\"\n }\n ],\n \"options\": {\n \"name\": \"gridCol${math.add($key,${foreach.index})}\",\n \"hidden\": false,\n \"offset\": 0,\n \"push\": 0,\n \"pull\": 0,\n #if($formLayout == 1)\n \"span\": 24,\n #elseif($formLayout == 2)\n \"span\": 12,\n #end\n \"responsive\": false\n },\n \"id\": \"grid-col-${math.add($key,${foreach.index})}\"\n }#if($foreach.hasNext),#end\n#end\n#end\n ],\n \"options\": {\n \"name\": \"grid${functionName}\",\n \"hidden\": false,\n \"gutter\": 12\n },\n \"id\": \"grid${functionName}\"\n }\n ],\n \"formConfig\": {\n \"modelName\": \"form\",\n \"refName\": \"form\",\n \"rulesName\": \"rules\",\n \"labelWidth\": 80,\n \"labelPosition\": \"left\",\n \"labelAlign\": \"label-left-align\",\n \"layoutType\": \"PC\",\n \"jsonVersion\": 3\n }\n}', '2023-02-23 04:33:16', '2023-06-04 10:35:51', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (2, 'vform.vue', '/', '表单设计器生成sfc模板', '\n\n', '2023-02-23 04:33:52', '2023-06-07 16:41:21', '0', 1, '', 'admin'); +INSERT INTO `gen_template` VALUES (3, 'Controller', '${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.collection.CollUtil;\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}.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;\nimport org.springdoc.api.annotations.ParameterObject;\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;\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.queryType == \'=\')\n wrapper.eq(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'like\' )\n wrapper.like(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'!-\' )\n wrapper.ne(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>\' )\n wrapper.gt(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<\' )\n wrapper.lt(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>=\' )\n wrapper.ge(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<=\' )\n wrapper.le(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'left like\' )\n wrapper.likeLeft(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'right like\' )\n wrapper.likeRight(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#end\n#end\n return R.ok(${className}Service.page(page, wrapper));\n }\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.getById(${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.save(${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.updateById(${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.removeBatchByIds(CollUtil.toList(ids)));\n }\n\n\n /**\n * 导出excel 表格\n * @param ${className} 查询条件\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}) {\n return ${className}Service.list(Wrappers.query(${className}));\n }\n}', '2023-02-23 01:16:17', '2023-06-06 17:20:06', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (4, 'Service', '${backendPath}/src/main/java/${packagePath}/${moduleName}/service/${ClassName}Service.java', 'Service', 'package ${package}.${moduleName}.service;\n\n#if($ChildClassName)\nimport com.github.yulichang.extension.mapping.base.MPJDeepService;\nimport ${package}.${moduleName}.entity.${ChildClassName}Entity;\n#else\nimport com.baomidou.mybatisplus.extension.service.IService;\n#end\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\n\n#if($ChildClassName)\npublic interface ${ClassName}Service extends MPJDeepService<${ClassName}Entity> {\n Boolean saveDeep(${ClassName}Entity ${className});\n\n Boolean updateDeep(${ClassName}Entity ${className});\n\n Boolean removeDeep(Long[] ids);\n\n Boolean removeChild(Long[] ids);\n#else\npublic interface ${ClassName}Service extends IService<${ClassName}Entity> {\n#end\n\n}', '2023-02-23 01:16:53', '2023-06-04 10:35:25', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (5, 'ServiceImpl', '${backendPath}/src/main/java/${packagePath}/${moduleName}/service/impl/${ClassName}ServiceImpl.java', 'ServiceImpl', 'package ${package}.${moduleName}.service.impl;\n\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport ${package}.${moduleName}.entity.${ClassName}Entity;\nimport ${package}.${moduleName}.mapper.${ClassName}Mapper;\nimport ${package}.${moduleName}.service.${ClassName}Service;\nimport org.springframework.stereotype.Service;\n#if($ChildClassName)\nimport cn.hutool.core.collection.CollUtil;\nimport com.baomidou.mybatisplus.core.toolkit.Wrappers;\nimport ${package}.${moduleName}.entity.${ChildClassName}Entity;\nimport ${package}.${moduleName}.mapper.${ChildClassName}Mapper;\nimport org.springframework.transaction.annotation.Transactional;\nimport lombok.RequiredArgsConstructor;\nimport java.util.Objects;\n#end\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\n@Service\n#if($ChildClassName)\n@RequiredArgsConstructor\n#end\npublic class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}Entity> implements ${ClassName}Service {\n#if($ChildClassName)\n private final ${ChildClassName}Mapper ${childClassName}Mapper;\n\n @Override\n @Transactional(rollbackFor = Exception.class)\n public Boolean saveDeep(${ClassName}Entity ${className}) {\n baseMapper.insert(${className});\n for (${ChildClassName}Entity ${childClassName} : ${className}.get${ChildClassName}List()) {\n ${childClassName}.$str.setProperty($childField)(${className}.$str.getProperty($mainField)());\n ${childClassName}Mapper.insert( ${childClassName});\n }\n\n return Boolean.TRUE;\n }\n\n @Override\n @Transactional(rollbackFor = Exception.class)\n public Boolean updateDeep(${ClassName}Entity ${className}) {\n baseMapper.updateById(${className});\n for (${ChildClassName}Entity ${childClassName} : ${className}.get${ChildClassName}List()) {\n#foreach ($field in $childFieldList)\n#if($field.primaryPk)\n#set($getChildPkName=$str.getProperty($field.attrName))\n#end\n#end\n if (Objects.isNull(${childClassName}.$getChildPkName())) {\n ${childClassName}.$str.setProperty($childField)(${className}.getId());\n ${childClassName}Mapper.insert(${childClassName});\n } else {\n ${childClassName}Mapper.updateById(${childClassName});\n }\n }\n return Boolean.TRUE;\n }\n\n @Override\n @Transactional(rollbackFor = Exception.class)\n public Boolean removeDeep(Long[] ids) {\n baseMapper.deleteBatchIds(CollUtil.toList(ids));\n ${childClassName}Mapper.delete(Wrappers.<${ChildClassName}Entity>lambdaQuery().in(${ChildClassName}Entity::$str.getProperty($childField), ids));\n return Boolean.TRUE;\n }\n\n @Override\n @Transactional(rollbackFor = Exception.class)\n public Boolean removeChild(Long[] ids) {\n ${childClassName}Mapper.deleteBatchIds(CollUtil.toList(ids));\n return Boolean.TRUE;\n }\n#end\n}', '2023-02-23 01:17:36', '2023-06-04 10:35:21', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (6, '实体', '${backendPath}/src/main/java/${packagePath}/${moduleName}/entity/${ClassName}Entity.java', 'Entity', '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#if($ChildClassName)\nimport com.alibaba.excel.annotation.ExcelIgnore;\nimport com.github.yulichang.annotation.EntityMapping;\nimport java.util.List;\n#end\n\n/**\n * ${tableComment}\n *\n * @author ${author}\n * @date ${datetime}\n */\n@Data\n@TableName(\"${tableName}\")\n@EqualsAndHashCode(callSuper = true)\n@Schema(description = \"${tableComment}\")\npublic class ${ClassName}Entity extends Model<${ClassName}Entity> {\n\n#foreach ($field in $fieldList)\n#if(${field.fieldComment})#set($comment=${field.fieldComment})#else #set($comment=${field.attrName})#end\n\n /**\n * $comment\n */\n#if($field.primaryPk)\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 private $field.attrType $field.attrName;\n#end\n#if($ChildClassName)\n @ExcelIgnore\n @TableField(exist = false)\n @EntityMapping(thisField = \"$mainField\", joinField = \"$childField\")\n private List<${ChildClassName}Entity> ${childClassName}List;\n#end\n}', '2023-02-23 01:17:53', '2023-06-04 10:45:15', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (7, 'Mapper', '${backendPath}/src/main/java/${packagePath}/${moduleName}/mapper/${ClassName}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-06-04 10:41:36', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (8, 'Mapper.xml', '${backendPath}/src/main/resources/mapper/${ClassName}Mapper.xml', 'Mapper.xml', '\n\n\n\n\n \n#foreach ($field in $fieldList)\n #if($field.primaryPk)\n \n #end\n #if(!$field.primaryPk)\n \n #end\n#end\n \n', '2023-02-23 01:18:35', '2023-06-04 10:34:56', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (9, '权限菜单', '${backendPath}/menu/${functionName}_menu.sql', 'menu.sql', '-- 该脚本不要直接执行, 注意维护菜单的父节点ID 默认 父节点-1 , 默认租户 1\n#set($menuId=${dateTool.getSystemTime()})\n\n -- 菜单SQL\n insert into `sys_menu` ( `menu_id`,`parent_id`, `path`, `permission`, `menu_type`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${menuId}, \'-1\', \'/${moduleName}/${functionName}/index\', \'\', \'0\', \'icon-bangzhushouji\', \'0\', null , \'8\', null , \'${tableComment}管理\', 1);\n\n-- 按钮父菜单ID\n set @parentId = @@identity;\n\n-- 菜单对应按钮SQL\n insert into `sys_menu` ( `menu_id`,`parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,1)},${menuId}, \'${moduleName}_${functionName}_view\', \'1\', null, \'1\', \'0\', null, \'0\', null, \'${tableComment}查看\', 1);\n\n insert into `sys_menu` ( `menu_id`,`parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,2)},${menuId}, \'${moduleName}_${functionName}_add\', \'1\', null, \'1\', \'0\', null, \'1\', null, \'${tableComment}新增\', 1);\n\n insert into `sys_menu` (`menu_id`, `parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,3)},${menuId}, \'${moduleName}_${functionName}_edit\', \'1\', null, \'1\', \'0\', null, \'2\', null, \'${tableComment}修改\', 1);\n\n insert into `sys_menu` (`menu_id`, `parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,4)},${menuId}, \'${moduleName}_${functionName}_del\', \'1\', null, \'1\', \'0\', null, \'3\', null, \'${tableComment}删除\', 1);\n\n insert into `sys_menu` ( `menu_id`,`parent_id`, `permission`, `menu_type`, `path`, `icon`, `del_flag`, `create_time`, `sort_order`, `update_time`, `name`, `tenant_id`)\n values (${math.add($menuId,5)},${menuId}, \'${moduleName}_${functionName}_export\', \'1\', null, \'1\', \'0\', null, \'3\', null, \'导入导出\', 1);', '2023-02-23 01:19:08', '2023-06-04 10:34:26', '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-06-04 11:24:15', '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-06-07 16:41:05', '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)\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 private $field.attrType $field.attrName;\n#end\n}\n', '2023-06-01 11:07:14', '2023-06-04 10:49:31', '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 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;\nimport org.springdoc.api.annotations.ParameterObject;\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;\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.queryType == \'=\')\n wrapper.eq(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'like\' )\n wrapper.like(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'!-\' )\n wrapper.ne(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>\' )\n wrapper.gt(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<\' )\n wrapper.lt(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'>=\' )\n wrapper.ge(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'<=\' )\n wrapper.le(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'left like\' )\n wrapper.likeLeft(StrUtil.isNotBlank($var),${ClassName}Entity::$getAttrName,$var);\n#elseif( $field.queryType == \'right like\' )\n wrapper.likeRight(StrUtil.isNotBlank($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 * @return excel 文件流\n */\n @ResponseExcel\n @GetMapping(\"/export\")\n @PreAuthorize(\"@pms.hasPermission(\'${moduleName}_${functionName}_export\')\" )\n public List<${ClassName}Entity> export(${ClassName}Entity ${className}) {\n return ${className}Service.list(Wrappers.query(${className}));\n }\n}', '2023-06-01 11:25:28', '2023-06-06 17:20:42', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (17, '主子表单', '${frontendPath}/src/views/${moduleName}/${functionName}/form.vue', '子表表单', '\n\n', '2023-06-01 15:42:46', '2023-06-07 16:40:32', '0', 1, ' ', ' '); +INSERT INTO `gen_template` VALUES (18, '主子表格', '${frontendPath}/src/views/${moduleName}/${functionName}/index.vue', '子表单表格', '\n\n\n', '2023-06-01 15:43:31', '2023-06-04 10:49:42', '0', 1, ' ', ' '); COMMIT; -- ---------------------------- @@ -258,8 +258,8 @@ COMMIT; -- ---------------------------- DROP TABLE IF EXISTS `gen_template_group`; CREATE TABLE `gen_template_group` ( - `group_id` bigint(11) NOT NULL COMMENT '分组id', - `template_id` bigint(20) NOT NULL COMMENT '模板id', + `group_id` bigint NOT NULL COMMENT '分组id', + `template_id` bigint NOT NULL COMMENT '模板id', PRIMARY KEY (`group_id`,`template_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='模板分组关联表'; @@ -275,11 +275,8 @@ INSERT INTO `gen_template_group` VALUES (1, 7); INSERT INTO `gen_template_group` VALUES (1, 8); INSERT INTO `gen_template_group` VALUES (1, 9); INSERT INTO `gen_template_group` VALUES (1, 10); -INSERT INTO `gen_template_group` VALUES (1, 13); -INSERT INTO `gen_template_group` VALUES (1, 14); -INSERT INTO `gen_template_group` VALUES (1, 15); -INSERT INTO `gen_template_group` VALUES (1, 16); -INSERT INTO `gen_template_group` VALUES (2, 3); +INSERT INTO `gen_template_group` VALUES (1, 11); +INSERT INTO `gen_template_group` VALUES (1, 12); INSERT INTO `gen_template_group` VALUES (2, 4); INSERT INTO `gen_template_group` VALUES (2, 5); INSERT INTO `gen_template_group` VALUES (2, 6); @@ -287,30 +284,10 @@ INSERT INTO `gen_template_group` VALUES (2, 7); INSERT INTO `gen_template_group` VALUES (2, 8); INSERT INTO `gen_template_group` VALUES (2, 9); INSERT INTO `gen_template_group` VALUES (2, 10); -INSERT INTO `gen_template_group` VALUES (2, 11); -INSERT INTO `gen_template_group` VALUES (2, 12); -INSERT INTO `gen_template_group` VALUES (3, 3); -INSERT INTO `gen_template_group` VALUES (3, 4); -INSERT INTO `gen_template_group` VALUES (3, 5); -INSERT INTO `gen_template_group` VALUES (3, 6); -INSERT INTO `gen_template_group` VALUES (3, 7); -INSERT INTO `gen_template_group` VALUES (3, 8); -INSERT INTO `gen_template_group` VALUES (3, 9); -INSERT INTO `gen_template_group` VALUES (3, 10); -INSERT INTO `gen_template_group` VALUES (3, 13); -INSERT INTO `gen_template_group` VALUES (3, 15); -INSERT INTO `gen_template_group` VALUES (3, 16); -INSERT INTO `gen_template_group` VALUES (3, 17); -INSERT INTO `gen_template_group` VALUES (4, 3); -INSERT INTO `gen_template_group` VALUES (4, 4); -INSERT INTO `gen_template_group` VALUES (4, 5); -INSERT INTO `gen_template_group` VALUES (4, 6); -INSERT INTO `gen_template_group` VALUES (4, 7); -INSERT INTO `gen_template_group` VALUES (4, 8); -INSERT INTO `gen_template_group` VALUES (4, 9); -INSERT INTO `gen_template_group` VALUES (4, 10); -INSERT INTO `gen_template_group` VALUES (4, 11); -INSERT INTO `gen_template_group` VALUES (4, 18); +INSERT INTO `gen_template_group` VALUES (2, 15); +INSERT INTO `gen_template_group` VALUES (2, 16); +INSERT INTO `gen_template_group` VALUES (2, 17); +INSERT INTO `gen_template_group` VALUES (2, 18); COMMIT; SET FOREIGN_KEY_CHECKS = 1; diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java index 93d94984c..4c5d79aa8 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java @@ -123,6 +123,16 @@ public class GenTableController { return tableService.list(Wrappers.query(table)); } + @GetMapping("/list/{dsName}") + public R listTable(@PathVariable("dsName") String dsName) { + return R.ok(tableService.queryDsAllTable(dsName)); + } + + @GetMapping("/column/{dsName}/{tableName}") + public R column(@PathVariable("dsName") String dsName, @PathVariable String tableName) { + return R.ok(tableService.queryColumn(dsName, tableName)); + } + /** * 获取表信息 * @param dsName 数据源 diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTable.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTable.java index 207ee564e..76012d6b3 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTable.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTable.java @@ -157,12 +157,33 @@ public class GenTable extends Model { */ private Long style; + /** + * 子表名称 + */ + private String childTableName; + + /** + * 主表关联键 + */ + private String mainField; + + /** + * 子表关联键 + */ + private String childField; + /** * 字段列表 */ @TableField(exist = false) private List fieldList; + /** + * 子表字段列表 + */ + @TableField(exist = false) + private List childFieldList; + /** * 代码风格(模版分组信息) */ diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java index 331a03b97..0c687d83c 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/mapper/GeneratorMapper.java @@ -36,6 +36,13 @@ import java.util.Map; */ public interface GeneratorMapper extends PigxBaseMapper { + /** + * 查询全部的表 + * @return + */ + @InterceptorIgnore(tenantLine = "true") + List> queryTable(); + /** * 分页查询表格 * @param page 分页信息 diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java index 5712098ed..7780fe84b 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenFormConfService.java @@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.pig4cloud.pigx.codegen.entity.GenFormConf; import java.util.List; +import java.util.Map; /** * 表单管理 @@ -36,6 +37,6 @@ public interface GenFormConfService extends IService { * @param formInfo json * @return 字段 */ - List parse(String formInfo); + Map> parse(String formInfo); } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java index 79c31fea1..ac8b3b4ef 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java @@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.pig4cloud.pigx.codegen.entity.GenTable; +import java.util.List; import java.util.Map; /** @@ -37,10 +38,14 @@ public interface GenTableService extends IService { * @param path 配置文件路径 * @return */ - Map getGeneratorConfig(String path); + Map getGeneratorConfig(); IPage list(Page page, GenTable table); GenTable queryOrBuildTable(String dsName, String tableName); + List> queryDsAllTable(String dsName); + + List> queryColumn(String dsName, String tableName); + } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java index 327e89ec8..9135ef12e 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java @@ -16,17 +16,19 @@ */ package com.pig4cloud.pigx.codegen.service.impl; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.pig4cloud.pigx.codegen.entity.GenFormConf; import com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper; import com.pig4cloud.pigx.codegen.service.GenFormConfService; +import com.pig4cloud.pigx.codegen.util.VFormConfigConsts; +import com.pig4cloud.pigx.codegen.util.VFormTypeEnum; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; /** * 表单管理 @@ -43,25 +45,60 @@ public class GenFormConfServiceImpl extends ServiceImpl parse(String formInfo) { + public Map> parse(String formInfo) { JSONObject jsonObject = JSONUtil.parseObj(formInfo); - List objectList = new ArrayList<>(); - // 使用 Lambda 表达式简化代码 - Optional.ofNullable(jsonObject.getJSONArray("widgetList"))// - .ifPresent(widgetList -> widgetList.forEach(obj -> parseWidgetList((JSONObject) obj, objectList))); - return objectList; + Map> resultMap = new LinkedHashMap<>(); + parseForm(jsonObject, resultMap); + return resultMap; } /** - * 解析部件列表 - * @param jsonObject 部件 json 对象 - * @param objectList 对象列表 + * 解析 form config + * @param json 表单配置 + * @param resultMap 返回结果 */ - private void parseWidgetList(JSONObject jsonObject, List objectList) { - Optional.ofNullable(jsonObject.getJSONArray("cols"))// - .filter(cols -> !cols.isEmpty())// - .ifPresent(cols -> cols.forEach(colObj -> parseWidgetList((JSONObject) colObj, objectList))); - objectList.add(jsonObject); + private void parseForm(JSONObject json, Map> resultMap) { + JSONArray widgetList = json.getJSONArray(VFormConfigConsts.widgetList); + String groupKey = json.getStr(VFormConfigConsts.groupKey, RandomUtil.randomString(5)); + widgetList.stream().map(o -> (JSONObject) o).forEach(jsonObject -> { + String type = jsonObject.getStr(VFormConfigConsts.type); + if (VFormTypeEnum.GRID.getType().equals(type)) { + parseGrid(jsonObject, resultMap); + } + else if (VFormTypeEnum.GRID_COL.getType().equals(type)) { + parseForm(jsonObject, resultMap); + } + else { + int span = Optional.ofNullable(json.getJSONObject(VFormConfigConsts.options)) + .map(options -> options.getInt(VFormConfigConsts.span, 24)).orElse(24); + + jsonObject.set(VFormConfigConsts.span, span); + + List jsonObjects = resultMap.computeIfAbsent(groupKey, k -> new ArrayList<>()); + jsonObjects.add(jsonObject); + } + }); + } + + /** + * 解析 grid 容器 + * @param jsonObject 入参 + * @param resultMap 结果 + */ + private void parseGrid(JSONObject jsonObject, Map> resultMap) { + JSONArray cols = jsonObject.getJSONArray(VFormConfigConsts.cols); + String key = jsonObject.getStr(VFormConfigConsts.key); + cols.stream().map(o -> (JSONObject) o).forEach(col -> { + String colType = col.getStr(VFormConfigConsts.type); + if (VFormTypeEnum.GRID_COL.getType().equals(colType)) { + col.set(VFormConfigConsts.groupKey, key); + parseForm(col, resultMap); + } + + if (VFormTypeEnum.GRID.getType().equals(colType)) { + parseGrid(col, resultMap); + } + }); } } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java index b0f89994e..0687b5475 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java @@ -73,12 +73,26 @@ public class GenTableServiceImpl extends ServiceImpl i * @return */ @Override - public Map getGeneratorConfig(String path) { - ClassPathResource classPathResource = new ClassPathResource(path); + public Map getGeneratorConfig() { + ClassPathResource classPathResource = new ClassPathResource(CONFIG_PATH); JSONObject jsonObject = JSONUtil.parseObj(IoUtil.readUtf8(classPathResource.getStream())); return jsonObject.getRaw(); } + @Override + public List> queryDsAllTable(String dsName) { + GeneratorMapper mapper = GenKit.getMapper(dsName); + // 手动切换数据源 + DynamicDataSourceContextHolder.push(dsName); + return mapper.queryTable(); + } + + @Override + public List> queryColumn(String dsName, String tableName) { + GeneratorMapper mapper = GenKit.getMapper(dsName); + return mapper.selectMapTableColumn(tableName, dsName); + } + @Override public IPage list(Page page, GenTable table) { GeneratorMapper mapper = GenKit.getMapper(table.getDsName()); @@ -126,7 +140,7 @@ public class GenTableServiceImpl extends ServiceImpl i Map queryTable = mapper.queryTable(tableName, dsName); // 获取默认表配置信息 () - Map generatorConfig = getGeneratorConfig(CONFIG_PATH); + Map generatorConfig = getGeneratorConfig(); JSONObject project = (JSONObject) generatorConfig.get("project"); JSONObject developer = (JSONObject) generatorConfig.get("developer"); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java index fef46c170..33a449ee3 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java @@ -21,6 +21,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.text.NamingCase; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import com.pig4cloud.pigx.codegen.entity.GenFormConf; @@ -81,10 +82,17 @@ public class GeneratorServiceImpl implements GeneratorService { GroupVo groupVo = genGroupService.getGroupVoById(style); List templateList = groupVo.getTemplateList(); + Map generatorConfig = tableService.getGeneratorConfig(); + JSONObject project = (JSONObject) generatorConfig.get("project"); + String frontendPath = project.getStr("frontendPath"); + String backendPath = project.getStr("backendPath"); + for (GenTemplateEntity template : templateList) { String templateCode = template.getTemplateCode(); String generatorPath = template.getGeneratorPath(); + dataModel.put("frontendPath", frontendPath); + dataModel.put("backendPath", backendPath); String content = VelocityKit.renderStr(templateCode, dataModel); String path = VelocityKit.renderStr(generatorPath, dataModel); @@ -113,10 +121,18 @@ public class GeneratorServiceImpl implements GeneratorService { // 获取模板列表,Lambda 表达式简化代码 List templateList = genGroupService.getGroupVoById(style).getTemplateList(); + Map generatorConfig = tableService.getGeneratorConfig(); + JSONObject project = (JSONObject) generatorConfig.get("project"); + String frontendPath = project.getStr("frontendPath"); + String backendPath = project.getStr("backendPath"); + return templateList.stream().map(template -> { String templateCode = template.getTemplateCode(); String generatorPath = template.getGeneratorPath(); + // 预览模式下, 使用相对路径展示 + dataModel.put("frontendPath", frontendPath); + dataModel.put("backendPath", backendPath); String content = VelocityKit.renderStr(templateCode, dataModel); String path = VelocityKit.renderStr(generatorPath, dataModel); @@ -194,8 +210,10 @@ public class GeneratorServiceImpl implements GeneratorService { Map dataModel = getDataModel(genTable.getId()); // 解析组件列表 - List widgetList = formConfService.parse(formConf.getFormInfo()); - dataModel.put("widgetList", widgetList); + Map> resultMap = formConfService.parse(formConf.getFormInfo()); + + // 遍历 widgetList + dataModel.put("resultMap", resultMap); // 获取模板信息 GenTemplateEntity genTemplateEntity = Optional @@ -219,6 +237,7 @@ public class GeneratorServiceImpl implements GeneratorService { .eq(GenTableColumnEntity::getDsName, table.getDsName()) .eq(GenTableColumnEntity::getTableName, table.getTableName()).orderByAsc(GenTableColumnEntity::getSort) .list(); + table.setFieldList(fieldList); // 创建数据模型对象 @@ -248,8 +267,24 @@ public class GeneratorServiceImpl implements GeneratorService { dataModel.put("className", StrUtil.lowerFirst(table.getClassName())); dataModel.put("ClassName", table.getClassName()); dataModel.put("fieldList", table.getFieldList()); + dataModel.put("backendPath", table.getBackendPath()); dataModel.put("frontendPath", table.getFrontendPath()); + + // 设置子表 + String childTableName = table.getChildTableName(); + if (StrUtil.isNotBlank(childTableName)) { + List childFieldList = columnService.lambdaQuery() + .eq(GenTableColumnEntity::getDsName, table.getDsName()) + .eq(GenTableColumnEntity::getTableName, table.getChildTableName()).list(); + dataModel.put("childFieldList", childFieldList); + dataModel.put("childTableName", childTableName); + dataModel.put("mainField", NamingCase.toCamelCase(table.getMainField())); + dataModel.put("childField", NamingCase.toCamelCase(table.getChildField())); + dataModel.put("ChildClassName", NamingCase.toPascalCase(childTableName)); + dataModel.put("childClassName", StrUtil.lowerFirst(NamingCase.toPascalCase(childTableName))); + } + return dataModel; } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenKit.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenKit.java index 8aaa45e11..a9605ebf4 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenKit.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenKit.java @@ -22,7 +22,7 @@ import java.util.Map; public class GenKit { /** - * 获取功能名 + * 获取功能名 sys_a_b sysAb * @param tableName 表名 * @return 功能名 */ diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/NamingCaseTool.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/NamingCaseTool.java index 4af050a23..7a1bde8d8 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/NamingCaseTool.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/NamingCaseTool.java @@ -19,6 +19,10 @@ public class NamingCaseTool { return String.format("get%s", NamingCase.toPascalCase(in)); } + public static String setProperty(String in) { + return String.format("set%s", NamingCase.toPascalCase(in)); + } + /** * 首字母大写 * @param in 字段 diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormConfigConsts.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormConfigConsts.java new file mode 100644 index 000000000..9172a99c1 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormConfigConsts.java @@ -0,0 +1,25 @@ +package com.pig4cloud.pigx.codegen.util; + +/** + * vform 的通用变量 + * + * @author lengleng + * @date 2023/6/5 + */ +public interface VFormConfigConsts { + + String widgetList = "widgetList"; + + String groupKey = "groupKey"; + + String type = "type"; + + String options = "options"; + + String span = "span"; + + String cols = "cols"; + + String key = "key"; + +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormTypeEnum.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormTypeEnum.java new file mode 100644 index 000000000..bf9b622d5 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/VFormTypeEnum.java @@ -0,0 +1,22 @@ +package com.pig4cloud.pigx.codegen.util; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * vfrom 字段类型 + * + * @author lengleng + * @date 2023/6/5 + */ +@Getter +@AllArgsConstructor +public enum VFormTypeEnum { + + GRID("grid"), + + GRID_COL("grid-col"); + + private final String type; + +}