From 6c5136603ec50ca93c8d74005bc9304c518d248a Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Sat, 15 Feb 2020 23:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=A1=A8=E5=8D=95=E9=9D=99=E6=80=81=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controller/apis/ApiController.ftl | 104 ++++++ .../controller/app/apis/AppController.ftl | 119 +++++++ .../resources/ResourceController.ftl | 114 ++++++ .../codetemplate/default/dao/IDao.ftl | 66 ++++ .../codetemplate/default/mapper/mapper.ftl | 116 ++++++ .../codetemplate/default/pojo/dto.ftl | 61 ++++ .../codetemplate/default/pojo/vo.ftl | 61 ++++ .../codetemplate/default/route/list.ftl | 331 ++++++++++++++++++ .../codetemplate/default/service/IService.ftl | 112 ++++++ .../default/service/ServiceImpl.ftl | 146 ++++++++ .../codetemplate/default/sql/sql.ftl | 29 ++ .../dynamic/form/save-dynamic-form.html | 2 +- .../dynamic/form/update-dynamic-form.html | 27 +- .../form/update-dynamic-join-form.html | 28 +- 14 files changed, 1272 insertions(+), 44 deletions(-) create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/apis/ApiController.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/app/apis/AppController.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/resources/ResourceController.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/dao/IDao.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/mapper/mapper.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/dto.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/vo.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/route/list.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/IService.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/ServiceImpl.ftl create mode 100644 cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/sql/sql.ftl diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/apis/ApiController.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/apis/ApiController.ftl new file mode 100644 index 0000000..30bf9fc --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/apis/ApiController.ftl @@ -0,0 +1,104 @@ +package ${basePackage}.controller.apis.${lowerTableName}; + +import com.cm.common.annotation.CheckRequestBodyAnnotation; +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.RemoveException; +import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultList; +import ${basePackage}.pojo.dtos.IdNameDTO; +import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO; +import ${basePackage}.pojo.vos.IdsVO; +import ${basePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO; +import ${basePackage}.service.${lowerTableName}.I${firstUpperTableName}Service; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: ${firstUpperTableName}Controller + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "${tableExplain}接口") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/${lowerTableName}") +public class ${firstUpperTableName}Controller extends AbstractController { + + @Autowired + private I${firstUpperTableName}Service ${firstLowerTableName}Service; + + @ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save${lowerTableName}") + @CheckRequestBodyAnnotation + public SuccessResult save${firstUpperTableName}(@RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + return ${firstLowerTableName}Service.save${firstUpperTableName}(${firstLowerTableName}VO); + } + + @ApiOperation(value = "删除${tableExplain}(id列表)", notes = "删除${tableExplain}(id列表)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @DeleteMapping("remove${lowerTableName}/{ids}") + public SuccessResult remove${firstUpperTableName}(@PathVariable("ids") String ids) throws RemoveException { + return ${firstLowerTableName}Service.remove${firstUpperTableName}(ids); + } + + @ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("update${lowerTableName}/{${firstLowerTableName}Id}") + @CheckRequestBodyAnnotation + public SuccessResult update${firstUpperTableName}(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, + @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + return ${firstLowerTableName}Service.update${firstUpperTableName}(${firstLowerTableName}Id, ${firstLowerTableName}VO); + } + + @ApiOperation(value = "${tableExplain}详情(通过ID)", notes = "${tableExplain}详情(通过ID)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("get${lowerTableName}byid/{${firstLowerTableName}Id}") + public ${firstUpperTableName}DTO get${firstUpperTableName}ById(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) throws SearchException { + return ${firstLowerTableName}Service.get${firstUpperTableName}ById(${firstLowerTableName}Id); + } + + @ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("list${lowerTableName}") + public List<${firstUpperTableName}DTO> list${firstUpperTableName}() throws SearchException { + Map params = requestParams(); + return ${firstLowerTableName}Service.list${firstUpperTableName}(params); + } + + @ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "form", dataType = "Integer", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "form", dataType = "Integer", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "form", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpage${lowerTableName}") + public SuccessResultList> listPage${firstUpperTableName}(ListPage page) throws SearchException { + Map params = requestParams(); + page.setParams(params); + return ${firstLowerTableName}Service.listPage${firstUpperTableName}(page); + } + +} \ No newline at end of file diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/app/apis/AppController.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/app/apis/AppController.ftl new file mode 100644 index 0000000..2aedfec --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/app/apis/AppController.ftl @@ -0,0 +1,119 @@ +package ${basePackage}.controller.app.apis.${lowerTableName}; + +import com.cm.common.annotation.CheckRequestBodyAnnotation; +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.RemoveException; +import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultList; +import ${basePackage}.pojo.dtos.IdNameDTO; +import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO; +import ${basePackage}.pojo.vos.IdsVO; +import ${basePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO; +import ${basePackage}.service.${lowerTableName}.I${firstUpperTableName}Service; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: ${firstUpperTableName}AppController + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "${tableExplain}接口") +@RestController +@RequestMapping(ISystemConstant.APP_PREFIX + "/${lowerTableName}") +public class ${firstUpperTableName}AppController extends AbstractController { + + @Autowired + private I${firstUpperTableName}Service ${firstLowerTableName}Service; + + @ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save${lowerTableName}") + @CheckRequestBodyAnnotation + public SuccessResult save${firstUpperTableName}(@RequestHeader("token") String token, + @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + return ${firstLowerTableName}Service.save${firstUpperTableName}ByToken(token, ${firstLowerTableName}VO); + } + + @ApiOperation(value = "删除${tableExplain}(id列表)", notes = "删除${tableExplain}(id列表)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @DeleteMapping("remove${lowerTableName}/{ids}") + public SuccessResult remove${firstUpperTableName}(@RequestHeader("token") String token, + @PathVariable("ids") String ids) throws RemoveException { + return ${firstLowerTableName}Service.remove${firstUpperTableName}ByToken(token, ids); + } + + @ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("update${lowerTableName}/{${firstLowerTableName}Id}") + @CheckRequestBodyAnnotation + public SuccessResult update${firstUpperTableName}(@RequestHeader("token") String token, + @PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, + @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + return ${firstLowerTableName}Service.update${firstUpperTableName}ByToken(token, ${firstLowerTableName}Id, ${firstLowerTableName}VO); + } + + @ApiOperation(value = "${tableExplain}详情(通过ID)", notes = "${tableExplain}详情(通过ID)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("get${lowerTableName}byid/{${firstLowerTableName}Id}") + public ${firstUpperTableName}DTO get${firstUpperTableName}ById(@RequestHeader("token") String token + @PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) throws SearchException { + return ${firstLowerTableName}Service.get${firstUpperTableName}ById(token, ${firstLowerTableName}Id); + } + + @ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("list${lowerTableName}") + public List<${firstUpperTableName}DTO> list${firstUpperTableName}(@RequestHeader("token") String token) throws SearchException { + Map params = requestParams(); + return ${firstLowerTableName}Service.list${firstUpperTableName}(params); + } + + @ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "token", value = "token", paramType = "header"), + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "form", dataType = "Integer", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "form", dataType = "Integer", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "form", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpage${lowerTableName}") + public SuccessResultList> listPage${firstUpperTableName}(@RequestHeader("token") String token, + ListPage page) throws SearchException { + Map params = requestParams(); + page.setParams(params); + return ${firstLowerTableName}Service.listPage${firstUpperTableName}(page); + } + +} \ No newline at end of file diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/resources/ResourceController.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/resources/ResourceController.ftl new file mode 100644 index 0000000..ea95105 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/controller/resources/ResourceController.ftl @@ -0,0 +1,114 @@ +package ${basePackage}.controller.app.apis.${lowerTableName}; + +import com.cm.common.annotation.CheckRequestBodyAnnotation; +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.RemoveException; +import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultList; +import ${basePackage}.pojo.dtos.IdNameDTO; +import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO; +import ${basePackage}.pojo.vos.IdsVO; +import ${basePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO; +import ${basePackage}.service.${lowerTableName}.I${firstUpperTableName}Service; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: ${firstUpperTableName}ResourceController + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "${tableExplain}接口") +@RestController +@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/${lowerTableName}") +public class ${firstUpperTableName}ResourceController extends AbstractController { + + @Autowired + private I${firstUpperTableName}Service ${firstLowerTableName}Service; + + @ApiOperation(value = "新增${tableExplain}", notes = "新增${tableExplain}接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save${lowerTableName}") + @CheckRequestBodyAnnotation + public SuccessResult save${firstUpperTableName}(@RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + return ${firstLowerTableName}Service.save${firstUpperTableName}(${firstLowerTableName}VO); + } + + @ApiOperation(value = "删除${tableExplain}(id列表)", notes = "删除${tableExplain}(id列表)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"), + @ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @DeleteMapping("remove${lowerTableName}/{ids}") + public SuccessResult remove${firstUpperTableName}(@PathVariable("ids") String ids) throws RemoveException { + return ${firstLowerTableName}Service.remove${firstUpperTableName}(ids); + } + + @ApiOperation(value = "修改${tableExplain}", notes = "修改${tableExplain}接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"), + @ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("update${lowerTableName}/{${firstLowerTableName}Id}") + @CheckRequestBodyAnnotation + public SuccessResult update${firstUpperTableName}(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id, + @RequestBody ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + return ${firstLowerTableName}Service.update${firstUpperTableName}(${firstLowerTableName}Id, ${firstLowerTableName}VO); + } + + @ApiOperation(value = "${tableExplain}详情(通过ID)", notes = "${tableExplain}详情(通过ID)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"), + @ApiImplicitParam(name = "${firstLowerTableName}Id", value = "${tableExplain}ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("get${lowerTableName}byid/{${firstLowerTableName}Id}") + public ${firstUpperTableName}DTO get${firstUpperTableName}ById(@PathVariable("${firstLowerTableName}Id") String ${firstLowerTableName}Id) throws SearchException { + return ${firstLowerTableName}Service.get${firstUpperTableName}ById(${firstLowerTableName}Id); + } + + @ApiOperation(value = "${tableExplain}列表", notes = "${tableExplain}列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("list${lowerTableName}") + public List<${firstUpperTableName}DTO> list${firstUpperTableName}() throws SearchException { + Map params = requestParams(); + return ${firstLowerTableName}Service.list${firstUpperTableName}(params); + } + + @ApiOperation(value = "${tableExplain}分页列表", notes = "${tableExplain}分页列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query"), + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "form", dataType = "Integer", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "form", dataType = "Integer", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "form", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "form", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpage${lowerTableName}") + public SuccessResultList> listPage${firstUpperTableName}(ListPage page) throws SearchException { + Map params = requestParams(); + page.setParams(params); + return ${firstLowerTableName}Service.listPage${firstUpperTableName}(page); + } + +} \ No newline at end of file diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/dao/IDao.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/dao/IDao.ftl new file mode 100644 index 0000000..afb6505 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/dao/IDao.ftl @@ -0,0 +1,66 @@ +package ${basePackage}.dao.${lowerTableName}; + +import com.cm.common.exception.RemoveException; +import com.cm.common.exception.SaveException; +import com.cm.common.exception.SearchException; +import com.cm.common.exception.UpdateException; +import com.cm.common.result.SuccessResultList; +import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName: I${firstUpperTableName}Dao + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@Repository +public interface I${firstUpperTableName}Dao { + + /** + * 新增${tableExplain} + * + * @param params + * @throws SaveException + */ + void save${firstUpperTableName}(Map params) throws SaveException; + + /** + * 删除${tableExplain} + * + * @param params + * @throws RemoveException + */ + void remove${firstUpperTableName}(Map params) throws RemoveException; + + /** + * 修改${tableExplain} + * + * @param params + * @throws UpdateException + */ + void update${firstUpperTableName}(Map params) throws UpdateException; + + /** + * ${tableExplain}详情 + * + * @param params + * @return + * @throws SearchException + */ + ${firstUpperTableName}DTO get${firstUpperTableName}(Map params) throws SearchException; + + /** + * ${tableExplain}列表 + * + * @param params + * @return + * @throws SearchException + */ + List<${firstUpperTableName}DTO> list${firstUpperTableName}(Map params) throws SearchException; + +} diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/mapper/mapper.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/mapper/mapper.ftl new file mode 100644 index 0000000..33465e3 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/mapper/mapper.ftl @@ -0,0 +1,116 @@ + + + + + + + <#list fieldList! as field> + + + + + + + INSERT INTO ${tablePrefix}${underLineTableName}( + ${underLineTableName}_id, + <#list fieldList! as field> + ${field.underLineTableName}, + + creator, + gmt_create, + modifier, + gmt_modified, + is_delete + ) VALUES( + ${r"#{"}${firstLowerTableName}Id${r"}"}, + <#list fieldList! as field> + ${r"#{"}${field.fieldName}${r"}"}, + + ${r"#{creator}"}, + ${r"#{gmtCreate}"}, + ${r"#{modifier}"}, + ${r"#{gmtModified}"}, + ${r"#{isDelete}"} + ) + + + + + UPDATE + ${tablePrefix}${underLineTableName} + SET + is_delete = 1, + modifier = ${r"#{modifier}"}, + gmt_modified = ${r"#{gmtModified}"} + WHERE + ${underLineTableName}_id IN + + ${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"} + + + + + + UPDATE + ${tablePrefix}${underLineTableName} + SET + <#list fieldList! as field> + <#if field.fieldType == "number" || field.fieldType == "double"> + + ${field.underLineTableName} = ${r"#{"}${field.fieldName}${r"}"}, + + <#else> + + ${field.underLineTableName} = ${r"#{"}${field.fieldName}${r"}"}, + + + + modifier = ${r"#{modifier}"}, + gmt_modified = ${r"#{gmtModified}"} + WHERE + ${underLineTableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"} + + + + + + + + + \ No newline at end of file diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/dto.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/dto.ftl new file mode 100644 index 0000000..9dbb6f8 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/dto.ftl @@ -0,0 +1,61 @@ +package ${basePackage}.pojo.vos.${lowerTableName}; + +import com.cm.common.annotation.CheckEmptyAnnotation; +import com.cm.common.annotation.CheckNumberAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * + * @ClassName: ${firstUpperTableName}DTO + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@ApiModel +public class ${firstUpperTableName}VO { + + <#list fieldList! as field> + @ApiModelProperty(name = "${field.fieldName}", value = "${field.fieldExplain}") + <#if field.fieldType == "number"> + private Integer ${field.fieldName}; + <#elseif field.fieldType == "double"> + private Double ${field.fieldName}; + <#else> + private String ${field.fieldName}; + + + + <#list fieldList! as field> + <#if field.fieldType == "number"> + public Integer get${field.firstUpperFieldName}() { + return ${field.fieldName} == null ? 0 : ${field.fieldName}; + } + + public void set${field.firstUpperFieldName}(Integer ${field.fieldName}) { + this.${field.fieldName} = ${field.fieldName}; + } + + <#elseif field.fieldType == "double"> + public Double get${field.firstUpperFieldName}() { + return ${field.fieldName} == null ? 0D : ${field.fieldName}; + } + + public void set${field.firstUpperFieldName}(String ${field.fieldName}) { + this.${field.fieldName} = ${field.fieldName}; + } + + <#else> + public String get${field.firstUpperFieldName}() { + return ${field.fieldName} == null ? "" : ${field.fieldName}; + } + + public void set${field.firstUpperFieldName}(String ${field.fieldName}) { + this.${field.fieldName} = ${field.fieldName}; + } + + + + +} diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/vo.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/vo.ftl new file mode 100644 index 0000000..e9ac9cf --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/pojo/vo.ftl @@ -0,0 +1,61 @@ +package ${basePackage}.pojo.vos.${lowerTableName}; + +import com.cm.common.annotation.CheckEmptyAnnotation; +import com.cm.common.annotation.CheckNumberAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * + * @ClassName: ${firstUpperTableName}VO + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@ApiModel +public class ${firstUpperTableName}VO { + + <#list fieldList! as field> + @ApiModelProperty(name = "${field.fieldName}", value = "${field.fieldExplain}") + <#if field.fieldType == "number"> + private Integer ${field.fieldName}; + <#elseif field.fieldType == "double"> + private Double ${field.fieldName}; + <#else> + private String ${field.fieldName}; + + + + <#list fieldList! as field> + <#if field.fieldType == "number"> + public Integer get${field.firstUpperFieldName}() { + return ${field.fieldName} == null ? 0 : ${field.fieldName}; + } + + public void set${field.firstUpperFieldName}(Integer ${field.fieldName}) { + this.${field.fieldName} = ${field.fieldName}; + } + + <#elseif field.fieldType == "double"> + public Double get${field.firstUpperFieldName}() { + return ${field.fieldName} == null ? 0D : ${field.fieldName}; + } + + public void set${field.firstUpperFieldName}(String ${field.fieldName}) { + this.${field.fieldName} = ${field.fieldName}; + } + + <#else> + public String get${field.firstUpperFieldName}() { + return ${field.fieldName} == null ? "" : ${field.fieldName}; + } + + public void set${field.firstUpperFieldName}(String ${field.fieldName}) { + this.${field.fieldName} = ${field.fieldName}; + } + + + + +} diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/route/list.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/route/list.ftl new file mode 100644 index 0000000..56cdb61 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/route/list.ftl @@ -0,0 +1,331 @@ + + + + + + + + + + + + + +
+
+
+
+
+
+
+ +
+
+ +
+
+ +
+ +
+
+ + +
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/IService.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/IService.ftl new file mode 100644 index 0000000..38e16dd --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/IService.ftl @@ -0,0 +1,112 @@ +package ${basePackage}.service.${lowerTableName}; + +import com.cm.common.exception.RemoveException; +import com.cm.common.exception.SaveException; +import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; +import com.cm.common.result.SuccessResultList; +import ${basePackage}.pojo.dtos.IdNameDTO; +import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO; +import ${basePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName: I${firstUpperTableName}Service + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +public interface I${firstUpperTableName}Service { + + /** + * 新增${tableExplain} + * + * @param ${firstLowerTableName}VO + * @return + * @throws Exception + */ + SuccessResult save${firstUpperTableName}(${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception; + + /** + * 新增${tableExplain}(APP) + * + * @param token + * @param ${firstLowerTableName}VO + * @return + * @throws Exception + */ + SuccessResult save${firstUpperTableName}ByToken(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception; + + /** + * 删除${tableExplain} + * + * @param ids + * @return + * @throws RemoveException + */ + SuccessResult remove${firstUpperTableName}(String ids) throws RemoveException; + + /** + * 删除${tableExplain}(APP) + * + * @param token + * @param ids + * @return + * @throws RemoveException + */ + SuccessResult remove${firstUpperTableName}ByToken(String token, String ids) throws RemoveException; + + /** + * 修改${tableExplain} + * + * @param ${firstLowerTableName}Id + * @param ${firstLowerTableName}VO + * @return + * @throws Exception + */ + SuccessResult update${firstUpperTableName}(String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception; + + /** + * 修改${tableExplain}(APP) + * + * @param token + * @param ${firstLowerTableName}Id + * @param ${firstLowerTableName}VO + * @return + * @throws Exception + */ + SuccessResult update${firstUpperTableName}ByToken(String token, String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception; + + /** + * ${tableExplain}详情(通过ID) + * + * @param ${firstLowerTableName}Id + * @return + * @throws SearchException + */ + ${firstUpperTableName}DTO get${firstUpperTableName}ById(String ${firstLowerTableName}Id) throws SearchException; + + /** + * ${tableExplain}列表 + * + * @param params + * @return + * @throws SearchException + */ + List<${firstUpperTableName}DTO> list${firstUpperTableName}(Map params) throws SearchException; + + /** + * ${tableExplain}分页列表 + * + * @param page + * @return + * @throws SearchException + */ + SuccessResultList> listPage${firstUpperTableName}(ListPage page) throws SearchException; + +} diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/ServiceImpl.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/ServiceImpl.ftl new file mode 100644 index 0000000..6086bb3 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/service/ServiceImpl.ftl @@ -0,0 +1,146 @@ +package ${basePackage}.service.${lowerTableName}.impl; + +import com.cm.common.exception.RemoveException; +import com.cm.common.exception.SaveException; +import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultList; +import com.cm.common.utils.HashMapUtil; +import com.cm.common.utils.UUIDUtil; +import ${basePackage}.dao.${lowerTableName}.I${firstUpperTableName}Dao; +import ${basePackage}.pojo.dtos.IdNameDTO; +import ${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO; +import ${basePackage}.pojo.vos.${lowerTableName}.${firstUpperTableName}VO; +import ${basePackage}.service.BaseService; +import ${basePackage}.service.${lowerTableName}.I${firstUpperTableName}Service; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * @ClassName: ${firstUpperTableName}ServiceImpl + * @Description: ${tableExplain} + * @Author: ${author} + * @Date: ${date} + * @Version: ${version} + **/ +@Service +public class ${firstUpperTableName}ServiceImpl extends BaseService implements I${firstUpperTableName}Service { + + @Autowired + private I${firstUpperTableName}Dao ${firstLowerTableName}Dao; + + @Override + public SuccessResult save${firstUpperTableName}(${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + save${firstUpperTableName}Info(null, ${firstLowerTableName}VO); + return new SuccessResult(); + } + + @Override + public SuccessResult save${firstUpperTableName}ByToken(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + save${firstUpperTableName}Info(token, ${firstLowerTableName}VO); + return new SuccessResult(); + } + + /** + * 新增${tableExplain} + * + * @param token + * @param ${firstLowerTableName}VO + * @throws Exception + */ + private void save${firstUpperTableName}Info(String token, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + Map params = HashMapUtil.beanToMap(${firstLowerTableName}VO); + params.put("${firstLowerTableName}Id", UUIDUtil.getUUID()); + if (token != null) { + setSaveInfo(token, params); + } else { + setSaveInfo(params); + } + ${firstLowerTableName}Dao.save${firstUpperTableName}(params); + } + + @Override + public SuccessResult remove${firstUpperTableName}(String ids) throws RemoveException { + remove${firstUpperTableName}Info(null, ids) + return new SuccessResult(); + } + + @Override + public SuccessResult remove${firstUpperTableName}ByToken(String token, String ids) throws RemoveException { + remove${firstUpperTableName}Info(token, ids) + return new SuccessResult(); + } + + /** + * 删除${tableExplain} + * + * @param token + * @param ids + */ + private void remove${firstUpperTableName}Info(token, ids) { + Map params = getHashMap(3); + params.put("${firstLowerTableName}Ids", Arrays.asList(ids.split("_"))); + if (token != null) { + setUpdateInfo(token, params); + } else { + setUpdateInfo(params); + } + ${firstLowerTableName}Dao.remove${firstUpperTableName}(params); + } + + @Override + public SuccessResult update${firstUpperTableName}(String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + update${firstUpperTableName}Info(null, ${firstLowerTableName}VO); + return new SuccessResult(); + } + + @Override + public SuccessResult update${firstUpperTableName}(String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) throws Exception { + update${firstUpperTableName}Info(token, ${firstLowerTableName}VO); + return new SuccessResult(); + } + + /** + * 修改${tableExplain} + * + * @param token + * @param ${firstLowerTableName}Id + * @param ${firstLowerTableName}VO + */ + private void update${firstUpperTableName}Info(String token, String ${firstLowerTableName}Id, ${firstUpperTableName}VO ${firstLowerTableName}VO) { + Map params = HashMapUtil.beanToMap(${firstLowerTableName}VO); + params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id); + if (token != null) { + setUpdateInfo(token, params); + } else { + setUpdateInfo(params); + } + ${firstLowerTableName}Dao.update${firstUpperTableName}(params); + } + + @Override + public ${firstUpperTableName}DTO get${firstUpperTableName}ById(String ${firstLowerTableName}Id) throws SearchException { + Map params = super.getHashMap(1); + params.put("${firstLowerTableName}Id", ${firstLowerTableName}Id); + return ${firstLowerTableName}Dao.get${firstUpperTableName}(params); + } + + @Override + public List<${firstUpperTableName}DTO> list${firstUpperTableName}(Map params) throws SearchException { + return ${firstLowerTableName}Dao.list${firstUpperTableName}(params); + } + + @Override + public SuccessResultList> listPage${firstUpperTableName}(ListPage page) throws SearchException { + PageHelper.startPage(page.getPage(), page.getRows()); + List<${firstUpperTableName}DTO> ${firstLowerTableName}DTOs = ${firstLowerTableName}Dao.list${firstUpperTableName}(page.getParams()); + PageInfo<${firstUpperTableName}DTO> pageInfo = new PageInfo<>(${firstLowerTableName}DTOs); + return new SuccessResultList<>(${firstLowerTableName}DTOs, pageInfo.getPageNum(), pageInfo.getTotal()); + } + +} diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/sql/sql.ftl b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/sql/sql.ftl new file mode 100644 index 0000000..b139584 --- /dev/null +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/sql/sql.ftl @@ -0,0 +1,29 @@ +CREATE TABLE `${tablePrefix}`.`${underLineTableName}`( + `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `${underLineTableName}_id` CHAR(36) NOT NULL COMMENT '主键', + <#list fieldList! as field> + <#if field.fieldType == "number"> + `${field.underLineFieldName}` INT(11)<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#elseif field.fieldType == "double"> + `${field.underLineFieldName}` DOUBLE(11, 2)<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#elseif field.fieldType == "date"> + `${field.underLineFieldName}` VARCHAR(40)<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#elseif field.fieldType == "datetime"> + `${field.underLineFieldName}` VARCHAR(50)<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#elseif field.fieldType == "text"> + `${field.underLineFieldName}` TEXT DEFAULT NULL<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#elseif field.fieldType == "richText"> + `${field.underLineFieldName}` LONGTEXT DEFAULT NULL<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#elseif field.fieldType == "currentUser" || field.fieldType == "currentDepartment" || field.fieldType == "currentRole" || field.fieldType == "currentGroup" || field.fieldType == "currentPosition"> + `${field.underLineFieldName}` VARCHAR(500) DEFAULT NULL<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + <#else> + `${field.underLineFieldName}` VARCHAR(255)<#if field.fieldDefault!> DEFAULT ${field.fieldDefault} COMMENT '${field.fieldExplain}', + + + `creator` CHAR(36) DEFAULT NULL, + `gmt_create` datetime DEFAULT NULL, + `modifier` CHAR(36) DEFAULT NULL, + `gmt_modified` datetime DEFAULT NULL, + `is_delete` int(1) DEFAULT '0', + PRIMARY KEY (`id`, `${underLineTableName}_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/save-dynamic-form.html b/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/save-dynamic-form.html index 23b9986..7d01728 100644 --- a/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/save-dynamic-form.html +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/save-dynamic-form.html @@ -225,7 +225,7 @@ // 初始化 function initData() { - for(var i = 0, item = formFieldList[i]; item = formFieldList[i++];) { + for(var i = 0, item; item = formFieldList[i++];) { if(item.fieldType === 'date') { laydate.render({ elem: '#'+ item.fieldName, diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-form.html b/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-form.html index f2a2b36..4c93c8a 100644 --- a/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-form.html +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-form.html @@ -235,7 +235,7 @@ } form.val('dataForm', dataFormData); // 处理checkbox - for(var i = 0, item = formFieldList[i]; item = formFieldList[i++];) { + for(var i = 0, item; item = formFieldList[i++];) { if(item.fieldType === 'checkbox') { if(typeof(data[item.fieldName]) === 'undefined') { continue; @@ -470,50 +470,35 @@ } else if(item.fieldType === 'currentUser') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentUser'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentDepartment') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentDepartment'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentRole') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentRole'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentGroup') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentGroup'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentPosition') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentPosition'] = nameValue; form.val('dataForm', formData); diff --git a/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-join-form.html b/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-join-form.html index e1af10d..417be4c 100644 --- a/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-join-form.html +++ b/cloud-common-plugin-dynamic/src/main/resources/templates/dynamic/form/update-dynamic-join-form.html @@ -248,7 +248,7 @@ } } form.render(null, 'dataForm'); - for(var i = 0, item = formFieldList[i]; item = formFieldList[i++];) { + for(var i = 0, item; item = formFieldList[i++];) { if(item.fieldType === 'date') { laydate.render({ elem: '#'+ item.fieldName, @@ -469,51 +469,35 @@ } else if(item.fieldType === 'currentUser') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - console.log(idAndNameValue) - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentUser'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentDepartment') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentDepartment'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentRole') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentRole'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentGroup') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentGroup'] = nameValue; form.val('dataForm', formData); } else if(item.fieldType === 'currentPosition') { var formData = {}; var idAndNameValue = dataFormData[item.fieldName]; - var nameValue = idAndNameValue != null && idAndNameValue != '' ? idAndNameValue.split('|')[1] : ''; - if(nameValue === '') { - return; - } + var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : ''; formData[item.fieldName] = idAndNameValue; formData[item.fieldName +'CurrentPosition'] = nameValue; form.val('dataForm', formData);