Commit 147770e0e387dc72842639368b317abc0b9bfaab
1 parent
a8e3989a
Exists in
master
modify resources
Showing
24 changed files
with
683 additions
and
680 deletions
Show diff stats
.gitignore
build/classes/java/main/com/taover/codegenerate/bazhuayun/GenerateCode.class
No preview for this file type
build/libs/code-generater-sources.jar
No preview for this file type
build/libs/code-generater.jar
No preview for this file type
build/libs/com-taover-codegenerater-sources.jar
No preview for this file type
build/libs/com-taover-codegenerater.jar
No preview for this file type
settings.gradle
@@ -7,4 +7,4 @@ | @@ -7,4 +7,4 @@ | ||
7 | * in the user guide at https://docs.gradle.org/4.5.1/userguide/multi_project_builds.html | 7 | * in the user guide at https://docs.gradle.org/4.5.1/userguide/multi_project_builds.html |
8 | */ | 8 | */ |
9 | 9 | ||
10 | -rootProject.name = 'com-taover-codegenerater' | 10 | +rootProject.name = 'com-taover-codegenerate' |
src/main/java/com/taover/codegenerate/bazhuayun/GenerateCode.java
@@ -21,7 +21,7 @@ import freemarker.template.Template; | @@ -21,7 +21,7 @@ import freemarker.template.Template; | ||
21 | public class GenerateCode { | 21 | public class GenerateCode { |
22 | public static void main(String args[]){ | 22 | public static void main(String args[]){ |
23 | try { | 23 | try { |
24 | - //generate("com.taover.wxorder", "ALL", "D:"+File.separator+"dblist", "127.0.0.1", "3306", "tylife", "lexi365", "8zyun_wxorder"); | 24 | + generate("com.taover.wxorder", "ALL", "D:"+File.separator+"dblist", "127.0.0.1", "3306", "tylife", "lexi365", "8zyun_wxorder"); |
25 | } catch (Exception e) { | 25 | } catch (Exception e) { |
26 | e.printStackTrace(); | 26 | e.printStackTrace(); |
27 | } | 27 | } |
@@ -94,9 +94,11 @@ public class GenerateCode { | @@ -94,9 +94,11 @@ public class GenerateCode { | ||
94 | } | 94 | } |
95 | 95 | ||
96 | public static String renderByTemplate(String templateName, ApiModel apiModel) throws Exception{ | 96 | public static String renderByTemplate(String templateName, ApiModel apiModel) throws Exception{ |
97 | - File f = new File(Tools.getPath()+File.separator+"com"+File.separator+"taover"+File.separator+"codegenerate"+File.separator+"bazhuayun"+File.separator+"template"); | ||
98 | Configuration cfg = new Configuration(); | 97 | Configuration cfg = new Configuration(); |
99 | - cfg.setDirectoryForTemplateLoading(f); | 98 | + //String comPath = GenerateCode.class.getResource("/").getPath(); |
99 | + //File f = new File(comPath+File.separator+"com"+File.separator+"taover"+File.separator+"codegenerate"+File.separator+"bazhuayun"+File.separator+"template"); | ||
100 | + //cfg.setDirectoryForTemplateLoading(f); | ||
101 | + cfg.setClassForTemplateLoading(GenerateCode.class, "/template/bazhuayun"); | ||
100 | Template template = cfg.getTemplate(templateName); | 102 | Template template = cfg.getTemplate(templateName); |
101 | StringWriter out = new StringWriter(); | 103 | StringWriter out = new StringWriter(); |
102 | template.process(apiModel, out); | 104 | template.process(apiModel, out); |
src/main/java/com/taover/codegenerate/bazhuayun/template/DtoTemplate.ftl
@@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
1 | -package ${basePackage}.bean.dto; | ||
2 | - | ||
3 | -import java.io.Serializable; | ||
4 | -import java.math.BigDecimal; | ||
5 | -import java.sql.Timestamp; | ||
6 | -import java.util.Date; | ||
7 | - | ||
8 | -/** | ||
9 | - <#if version?exists> | ||
10 | - * @version ${version} | ||
11 | - </#if> | ||
12 | - */ | ||
13 | -public class ${dtoClassSimpleName} implements Serializable { | ||
14 | - | ||
15 | - private static final long serialVersionUID = 1L; | ||
16 | - | ||
17 | - <#--变量 ,get,set方法--> | ||
18 | -<#if tablemodel.columnlist?exists> | ||
19 | - <#list tablemodel.columnlist as clist> | ||
20 | - | ||
21 | - <#if clist.columnRemarks?exists> | ||
22 | - /** | ||
23 | - * ${clist.columnRemarks} | ||
24 | - */ | ||
25 | - </#if> | ||
26 | - private ${clist.columnJAVAType} ${clist.columnName}; | ||
27 | - | ||
28 | - public ${clist.columnJAVAType} get${clist.columnMethodName}(){ | ||
29 | - return ${clist.columnName}; | ||
30 | - } | ||
31 | - public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){ | ||
32 | - this.${clist.columnName} = ${clist.columnName}; | ||
33 | - } | ||
34 | - </#list> | ||
35 | -</#if> | ||
36 | - | ||
37 | -} | ||
38 | \ No newline at end of file | 0 | \ No newline at end of file |
src/main/java/com/taover/codegenerate/bazhuayun/template/EntityTemplate.ftl
@@ -1,52 +0,0 @@ | @@ -1,52 +0,0 @@ | ||
1 | -package ${basePackage}.bean.entity; | ||
2 | - | ||
3 | -import java.io.Serializable; | ||
4 | -import java.math.BigDecimal; | ||
5 | -import java.sql.Timestamp; | ||
6 | -import java.util.Date; | ||
7 | - | ||
8 | -import javax.persistence.Entity; | ||
9 | -import javax.persistence.Table; | ||
10 | -import javax.persistence.Id; | ||
11 | -import javax.persistence.Column; | ||
12 | - | ||
13 | -/** | ||
14 | - <#if version?exists> | ||
15 | - * @version ${version} | ||
16 | - </#if> | ||
17 | - */ | ||
18 | -@Entity | ||
19 | -@Table(name="${tablemodel.tableName}", catalog="${tablemodel.schemeName}") | ||
20 | -public class ${entityClassSimpleName} implements Serializable { | ||
21 | - | ||
22 | - private static final long serialVersionUID = 1L; | ||
23 | - | ||
24 | - <#--变量 ,get,set方法--> | ||
25 | -<#if tablemodel.columnlist?exists> | ||
26 | - <#list tablemodel.columnlist as clist> | ||
27 | - | ||
28 | - <#if clist.columnRemarks?exists> | ||
29 | - /** | ||
30 | - * ${clist.columnRemarks} | ||
31 | - */ | ||
32 | - </#if> | ||
33 | - <#if clist.primaryKey == true> | ||
34 | - @Id | ||
35 | - </#if> | ||
36 | - @Column(name="${clist.columnUName}") | ||
37 | - private ${clist.columnJAVAType} ${clist.columnName}; | ||
38 | - | ||
39 | - public ${clist.columnJAVAType} get${clist.columnMethodName}(){ | ||
40 | - return ${clist.columnName}; | ||
41 | - } | ||
42 | - public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){ | ||
43 | - this.${clist.columnName} = ${clist.columnName}; | ||
44 | - } | ||
45 | - </#list> | ||
46 | -</#if> | ||
47 | - | ||
48 | - @Override | ||
49 | - public String toString() { | ||
50 | - return "${entityClassSimpleName}: ${toStringMethodBody}; | ||
51 | - } | ||
52 | - } | ||
53 | \ No newline at end of file | 0 | \ No newline at end of file |
src/main/java/com/taover/codegenerate/bazhuayun/template/ManageControllerTemplate.ftl
@@ -1,135 +0,0 @@ | @@ -1,135 +0,0 @@ | ||
1 | -package ${basePackage}.controller.manage; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | - | ||
5 | -import javax.annotation.Resource; | ||
6 | -import javax.servlet.http.HttpServletRequest; | ||
7 | - | ||
8 | -import org.apache.commons.lang.StringUtils; | ||
9 | -import org.springframework.web.bind.annotation.DeleteMapping; | ||
10 | -import org.springframework.web.bind.annotation.GetMapping; | ||
11 | -import org.springframework.web.bind.annotation.PostMapping; | ||
12 | -import org.springframework.web.bind.annotation.PutMapping; | ||
13 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | -import org.springframework.web.bind.annotation.RestController; | ||
15 | - | ||
16 | -import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
17 | -import ${basePackage}.constants.GlobalConstants; | ||
18 | -import ${basePackage}.service.${serviceClassSimpleName}; | ||
19 | - | ||
20 | -import com.taover.util.UtilHttpRequestMap; | ||
21 | -import com.taover.util.bean.ResultInfo; | ||
22 | - | ||
23 | -@Controller("manage.${controllerMap}") | ||
24 | -@RequestMapping("/manage/${controllerMap}") | ||
25 | -public class ${controllerClassName} { | ||
26 | - @Resource | ||
27 | - private ${serviceClassSimpleName} ${serviceClassFieldName}; | ||
28 | - | ||
29 | - /** | ||
30 | - * @apiDefine ResultInfo | ||
31 | - * @apiSuccess {string} | ||
32 | - * @apiSuccessExample {json} Success-Response: | ||
33 | - * { | ||
34 | - * code:ok, | ||
35 | - * error:null | ||
36 | - * } | ||
37 | - * @apiError ThrowException 出现异常 | ||
38 | - * @apiErrorExample | ||
39 | - * { | ||
40 | - * code:fail, | ||
41 | - * error:null exception | ||
42 | - * } | ||
43 | - */ | ||
44 | - | ||
45 | - /** | ||
46 | - * @api {GET} /manage/${controllerMap} 查询${controllerMap}列表 | ||
47 | - * @apiDescription 查询${controllerMap}列表数据 | ||
48 | - * 返回分页结果 | ||
49 | - * | ||
50 | - * @apiGroup ${controllerMap} | ||
51 | - * @apiName ${controllerMap}列表 | ||
52 | - * @apiVersion 1.0.0 | ||
53 | - * @apiHeader Authorization | ||
54 | - * | ||
55 | - * @apiUse ResultInfo | ||
56 | - */ | ||
57 | - @GetMapping | ||
58 | - public ResultInfo get(HttpServletRequest request){ | ||
59 | - String pageStr = request.getParameter("page"); | ||
60 | - if(StringUtils.isEmpty(pageStr)){ | ||
61 | - pageStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE; | ||
62 | - } | ||
63 | - String sizeStr = request.getParameter("size"); | ||
64 | - if(StringUtils.isEmpty(sizeStr)){ | ||
65 | - sizeStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE_SIZE; | ||
66 | - } | ||
67 | - List<Object[]> condition = UtilHttpRequestMap.getSqlConditionListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, "page,size"); | ||
68 | - return this.${serviceClassFieldName}.getListManage(condition, Integer.valueOf(pageStr), Integer.valueOf(sizeStr)); | ||
69 | - } | ||
70 | - | ||
71 | - /** | ||
72 | - * @api {GET} /manage/${controllerMap}/{ssid} 查询ssid对应的${controllerMap} | ||
73 | - * @apiDescription 查询ssid对应${controllerMap}数据 | ||
74 | - * | ||
75 | - * @apiGroup ${controllerMap} | ||
76 | - * @apiName get实体数据 | ||
77 | - * @apiVersion 1.0.0 | ||
78 | - * @apiHeader Authorization | ||
79 | - * | ||
80 | - * @apiUse ResultInfo | ||
81 | - */ | ||
82 | - @GetMapping("/{ssid}") | ||
83 | - public ResultInfo get(String ssid){ | ||
84 | - return this.${serviceClassFieldName}.getOneManage(ssid); | ||
85 | - } | ||
86 | - | ||
87 | - /** | ||
88 | - * @api {POST} /manage/${controllerMap} 创建${controllerMap} | ||
89 | - * @apiDescription 创建${controllerMap} | ||
90 | - * | ||
91 | - * @apiGroup ${controllerMap} | ||
92 | - * @apiName get实体数据 | ||
93 | - * @apiVersion 1.0.0 | ||
94 | - * @apiHeader Authorization | ||
95 | - * | ||
96 | - * @apiUse ResultInfo | ||
97 | - */ | ||
98 | - @PostMapping | ||
99 | - public ResultInfo post(HttpServletRequest request){ | ||
100 | - return this.${serviceClassFieldName}.postManage(UtilHttpRequestMap.getMapValueStringByRequestMap(request.getParameterMap())); | ||
101 | - } | ||
102 | - | ||
103 | - /** | ||
104 | - * @api {DELETE} /manage/${controllerMap}/{ssid} 删除ssid对应的${controllerMap} | ||
105 | - * @apiDescription 删除ssid对应的${controllerMap}数据 | ||
106 | - * | ||
107 | - * @apiGroup ${controllerMap} | ||
108 | - * @apiName 删除实体数据 | ||
109 | - * @apiVersion 1.0.0 | ||
110 | - * @apiHeader Authorization | ||
111 | - * | ||
112 | - * @apiUse ResultInfo | ||
113 | - */ | ||
114 | - @DeleteMapping("/{ssid}") | ||
115 | - public ResultInfo delete(String ssid){ | ||
116 | - return this.${serviceClassFieldName}.deleteManage(ssid); | ||
117 | - } | ||
118 | - | ||
119 | - /** | ||
120 | - * @api {PUT} /manage/${controllerMap}/{ssid} 修改${controllerMap}数据 | ||
121 | - * @apiDescription 修改${controllerMap}数据 | ||
122 | - * | ||
123 | - * @apiGroup ${controllerMap} | ||
124 | - * @apiName 修改实体数据 | ||
125 | - * @apiVersion 1.0.0 | ||
126 | - * @apiHeader Authorization | ||
127 | - * | ||
128 | - * @apiUse ResultInfo | ||
129 | - */ | ||
130 | - @PutMapping("/{ssid}") | ||
131 | - public ResultInfo put(String ssid, HttpServletRequest request){ | ||
132 | - return this.${serviceClassFieldName}.putManage(ssid, UtilHttpRequestMap.getUpdateListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, null)); | ||
133 | - } | ||
134 | - | ||
135 | -} |
src/main/java/com/taover/codegenerate/bazhuayun/template/RepositoryTemplate.ftl
@@ -1,74 +0,0 @@ | @@ -1,74 +0,0 @@ | ||
1 | -package ${basePackage}.repository; | ||
2 | - | ||
3 | -import java.math.BigInteger; | ||
4 | -import java.util.ArrayList; | ||
5 | -import java.util.Base64; | ||
6 | -import java.util.List; | ||
7 | -import java.util.Map; | ||
8 | - | ||
9 | -import org.msgpack.MessagePack; | ||
10 | -import org.springframework.stereotype.Repository; | ||
11 | - | ||
12 | -import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
13 | -import ${basePackage}.bean.vo.${voClassSimpleName}; | ||
14 | -import com.taover.repository.CustomJdbcTemplate; | ||
15 | -import com.taover.util.UtilHttpRequestMap; | ||
16 | -import com.taover.util.UtilObject; | ||
17 | - | ||
18 | -@Repository | ||
19 | -public class ${repositoryClassSimpleName} extends CustomJdbcTemplate<${entityClassSimpleName}, Integer>{ | ||
20 | - | ||
21 | - public ${repositoryClassSimpleName}() throws Exception { | ||
22 | - super(); | ||
23 | - } | ||
24 | - | ||
25 | - public String getSsidById(Integer id) throws Exception{ | ||
26 | - MessagePack pack = new MessagePack(); | ||
27 | - return Base64.getEncoder().encodeToString(pack.write(new Integer[]{id, id, id})); | ||
28 | - } | ||
29 | - | ||
30 | - public Integer getIdBySsid(String ssid) throws Exception{ | ||
31 | - MessagePack pack = new MessagePack(); | ||
32 | - return pack.read(Base64.getDecoder().decode(ssid), Integer[].class)[0]; | ||
33 | - } | ||
34 | - | ||
35 | - public Map<String, Object> getVoPage(List<Object[]> condition, Integer page, Integer size) throws Exception{ | ||
36 | - Map<String, Object> entityData = this.findPageByCondition(condition, page, size); | ||
37 | - List<${entityClassSimpleName}> entityList = (List<${entityClassSimpleName}>) entityData.get("rows"); | ||
38 | - List<${voClassSimpleName}> voList = new ArrayList<${voClassSimpleName}>(); | ||
39 | - for(int i=0; i<entityList.size(); ++i){ | ||
40 | - voList.add(this.getVoByEntity(entityList.get(i))); | ||
41 | - } | ||
42 | - entityData.put("rows", voList); | ||
43 | - return entityData; | ||
44 | - } | ||
45 | - | ||
46 | - public ${voClassSimpleName} getVoBySsid(String ssid) throws Exception{ | ||
47 | - return this.getVoByEntity(this.findEntityByID(this.getIdBySsid(ssid))); | ||
48 | - } | ||
49 | - | ||
50 | - public ${voClassSimpleName} getVoByEntity(${entityClassSimpleName} entity) throws Exception{ | ||
51 | - ${voClassSimpleName} voObj = null; | ||
52 | - try { | ||
53 | - voObj = UtilObject.fieldCopy(entity, ${voClassSimpleName}.class, true, new String[]{"id"}); | ||
54 | - } catch (Exception e) { | ||
55 | - throw new Exception("对象转换失败"); | ||
56 | - } | ||
57 | - voObj.setSsid(this.getSsidById(entity.getId())); | ||
58 | - return voObj; | ||
59 | - } | ||
60 | - | ||
61 | - public void updateEntityBySsid(String ssid, List<Object[]> updateList) throws Exception{ | ||
62 | - this.updateEntityById(updateList, this.getIdBySsid(ssid)); | ||
63 | - } | ||
64 | - | ||
65 | - public void deleteEntityBySsid(String ssid) throws Exception{ | ||
66 | - this.deleteEntityByID(this.getIdBySsid(ssid)); | ||
67 | - } | ||
68 | - | ||
69 | - public ${voClassSimpleName} addEntityByMap(Map<String, Object> data) throws Exception{ | ||
70 | - ${entityClassSimpleName} entityObj = UtilHttpRequestMap.getBeanByMap(data, ${entityClassSimpleName}.class, false, "id"); | ||
71 | - BigInteger resultId = this.addEntityForAutoincrementId(entityObj); | ||
72 | - return this.getVoByEntity(this.findEntityByID(resultId.intValue())); | ||
73 | - } | ||
74 | -} |
src/main/java/com/taover/codegenerate/bazhuayun/template/ServiceImplTemplate.ftl
@@ -1,124 +0,0 @@ | @@ -1,124 +0,0 @@ | ||
1 | -package ${basePackage}.service.impl; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | -import java.util.Map; | ||
5 | - | ||
6 | -import javax.annotation.Resource; | ||
7 | - | ||
8 | -import org.springframework.stereotype.Service; | ||
9 | - | ||
10 | -import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
11 | -import ${basePackage}.repository.${repositoryClassSimpleName}; | ||
12 | -import ${basePackage}.service.${serviceClassSimpleName}; | ||
13 | -import com.taover.util.UtilLog; | ||
14 | -import com.taover.util.bean.ResultInfo; | ||
15 | -import com.taover.util.bean.UtilResultInfo; | ||
16 | - | ||
17 | -@Service | ||
18 | -public class ${serviceImplClassSimpleName} implements ${serviceClassSimpleName} { | ||
19 | - @Resource | ||
20 | - private ${repositoryClassSimpleName} ${repositoryClassFieldName}; | ||
21 | - | ||
22 | - @Override | ||
23 | - public ResultInfo getListV1(List<Object[]> condition, Integer page, Integer size) { | ||
24 | - try { | ||
25 | - return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoPage(condition, page, size)); | ||
26 | - } catch (Exception e) { | ||
27 | - UtilLog.errorForException(e, this.getClass()); | ||
28 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
29 | - } | ||
30 | - } | ||
31 | - | ||
32 | - @Override | ||
33 | - public ResultInfo getOneV1(String ssid) { | ||
34 | - try { | ||
35 | - return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoBySsid(ssid)); | ||
36 | - } catch (Exception e) { | ||
37 | - UtilLog.errorForException(e, this.getClass()); | ||
38 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
39 | - } | ||
40 | - } | ||
41 | - | ||
42 | - @Override | ||
43 | - public ResultInfo putV1(String ssid, List<Object[]> updateList) { | ||
44 | - try{ | ||
45 | - this.${repositoryClassFieldName}.updateEntityBySsid(ssid, updateList); | ||
46 | - }catch(Exception e){ | ||
47 | - UtilLog.errorForException(e, this.getClass()); | ||
48 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
49 | - } | ||
50 | - return UtilResultInfo.getSuccess("更新成功"); | ||
51 | - } | ||
52 | - | ||
53 | - @Override | ||
54 | - public ResultInfo deleteV1(String ssid) { | ||
55 | - try{ | ||
56 | - this.${repositoryClassFieldName}.deleteEntityBySsid(ssid); | ||
57 | - }catch(Exception e){ | ||
58 | - UtilLog.errorForException(e, this.getClass()); | ||
59 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
60 | - } | ||
61 | - return UtilResultInfo.getSuccess("删除成功"); | ||
62 | - } | ||
63 | - | ||
64 | - @Override | ||
65 | - public ResultInfo postV1(Map<String, Object> data) { | ||
66 | - try { | ||
67 | - return UtilResultInfo.getSuccess("创建成功", this.${repositoryClassFieldName}.addEntityByMap(data)); | ||
68 | - } catch (Exception e) { | ||
69 | - UtilLog.errorForException(e, this.getClass()); | ||
70 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
71 | - } | ||
72 | - } | ||
73 | - | ||
74 | - @Override | ||
75 | - public ResultInfo getListManage(List<Object[]> condition, Integer page, Integer size) { | ||
76 | - try { | ||
77 | - return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoPage(condition, page, size)); | ||
78 | - } catch (Exception e) { | ||
79 | - UtilLog.errorForException(e, this.getClass()); | ||
80 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
81 | - } | ||
82 | - } | ||
83 | - | ||
84 | - @Override | ||
85 | - public ResultInfo getOneManage(String ssid) { | ||
86 | - try { | ||
87 | - return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoBySsid(ssid)); | ||
88 | - } catch (Exception e) { | ||
89 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
90 | - } | ||
91 | - } | ||
92 | - | ||
93 | - @Override | ||
94 | - public ResultInfo putManage(String ssid, List<Object[]> updateList) { | ||
95 | - try{ | ||
96 | - this.${repositoryClassFieldName}.updateEntityBySsid(ssid, updateList); | ||
97 | - }catch(Exception e){ | ||
98 | - UtilLog.errorForException(e, this.getClass()); | ||
99 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
100 | - } | ||
101 | - return UtilResultInfo.getSuccess("更新成功"); | ||
102 | - } | ||
103 | - | ||
104 | - @Override | ||
105 | - public ResultInfo deleteManage(String ssid) { | ||
106 | - try{ | ||
107 | - this.${repositoryClassFieldName}.deleteEntityBySsid(ssid); | ||
108 | - }catch(Exception e){ | ||
109 | - UtilLog.errorForException(e, this.getClass()); | ||
110 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
111 | - } | ||
112 | - return UtilResultInfo.getSuccess("删除成功"); | ||
113 | - } | ||
114 | - | ||
115 | - @Override | ||
116 | - public ResultInfo postManage(Map<String, Object> data) { | ||
117 | - try { | ||
118 | - return UtilResultInfo.getSuccess("创建成功", this.${repositoryClassFieldName}.addEntityByMap(data)); | ||
119 | - } catch (Exception e) { | ||
120 | - UtilLog.errorForException(e, this.getClass()); | ||
121 | - return UtilResultInfo.getFailure(e.getMessage()); | ||
122 | - } | ||
123 | - } | ||
124 | -} |
src/main/java/com/taover/codegenerate/bazhuayun/template/ServiceTemplate.ftl
@@ -1,82 +0,0 @@ | @@ -1,82 +0,0 @@ | ||
1 | -package ${basePackage}.service; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | -import java.util.Map; | ||
5 | - | ||
6 | -import com.taover.util.bean.ResultInfo; | ||
7 | - | ||
8 | -public interface ${serviceClassSimpleName} { | ||
9 | - /** | ||
10 | - * 获取列表 | ||
11 | - * @param condition | ||
12 | - * @param page | ||
13 | - * @param size | ||
14 | - * @return | ||
15 | - */ | ||
16 | - public ResultInfo getListV1(List<Object[]> condition, Integer page, Integer size); | ||
17 | - | ||
18 | - /** | ||
19 | - * 获取ssid对应的数据 | ||
20 | - * @param ssid | ||
21 | - * @return | ||
22 | - */ | ||
23 | - public ResultInfo getOneV1(String ssid); | ||
24 | - | ||
25 | - /** | ||
26 | - * 修改ssid对应的数据 | ||
27 | - * @param ssid | ||
28 | - * @return | ||
29 | - */ | ||
30 | - public ResultInfo putV1(String ssid, List<Object[]> updateList); | ||
31 | - | ||
32 | - /** | ||
33 | - * 删除ssid对应的数据 | ||
34 | - * @param ssid | ||
35 | - * @return | ||
36 | - */ | ||
37 | - public ResultInfo deleteV1(String ssid); | ||
38 | - | ||
39 | - /** | ||
40 | - * 创建数据 | ||
41 | - * @param ssid | ||
42 | - * @return | ||
43 | - */ | ||
44 | - public ResultInfo postV1(Map<String, Object> data); | ||
45 | - | ||
46 | - /** | ||
47 | - * 获取列表 | ||
48 | - * @param condition | ||
49 | - * @param page | ||
50 | - * @param size | ||
51 | - * @return | ||
52 | - */ | ||
53 | - public ResultInfo getListManage(List<Object[]> condition, Integer page, Integer size); | ||
54 | - | ||
55 | - /** | ||
56 | - * 获取ssid对应的数据 | ||
57 | - * @param ssid | ||
58 | - * @return | ||
59 | - */ | ||
60 | - public ResultInfo getOneManage(String ssid); | ||
61 | - | ||
62 | - /** | ||
63 | - * 修改ssid对应的数据 | ||
64 | - * @param ssid | ||
65 | - * @return | ||
66 | - */ | ||
67 | - public ResultInfo putManage(String ssid, List<Object[]> updateList); | ||
68 | - | ||
69 | - /** | ||
70 | - * 删除ssid对应的数据 | ||
71 | - * @param ssid | ||
72 | - * @return | ||
73 | - */ | ||
74 | - public ResultInfo deleteManage(String ssid); | ||
75 | - | ||
76 | - /** | ||
77 | - * 创建数据 | ||
78 | - * @param ssid | ||
79 | - * @return | ||
80 | - */ | ||
81 | - public ResultInfo postManage(Map<String, Object> data); | ||
82 | -} |
src/main/java/com/taover/codegenerate/bazhuayun/template/V1ControllerTemplate.ftl
@@ -1,135 +0,0 @@ | @@ -1,135 +0,0 @@ | ||
1 | -package ${basePackage}.controller.v1; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | - | ||
5 | -import javax.annotation.Resource; | ||
6 | -import javax.servlet.http.HttpServletRequest; | ||
7 | - | ||
8 | -import org.apache.commons.lang.StringUtils; | ||
9 | -import org.springframework.web.bind.annotation.DeleteMapping; | ||
10 | -import org.springframework.web.bind.annotation.GetMapping; | ||
11 | -import org.springframework.web.bind.annotation.PostMapping; | ||
12 | -import org.springframework.web.bind.annotation.PutMapping; | ||
13 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | -import org.springframework.web.bind.annotation.RestController; | ||
15 | - | ||
16 | -import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
17 | -import ${basePackage}.constants.GlobalConstants; | ||
18 | -import ${basePackage}.service.${serviceClassSimpleName}; | ||
19 | - | ||
20 | -import com.taover.util.UtilHttpRequestMap; | ||
21 | -import com.taover.util.bean.ResultInfo; | ||
22 | - | ||
23 | -@Controller("v1.${controllerMap}") | ||
24 | -@RequestMapping("/v1/${controllerMap}") | ||
25 | -public class ${controllerClassName} { | ||
26 | - @Resource | ||
27 | - private ${serviceClassSimpleName} ${serviceClassFieldName}; | ||
28 | - | ||
29 | - /** | ||
30 | - * @apiDefine ResultInfo | ||
31 | - * @apiSuccess {string} | ||
32 | - * @apiSuccessExample {json} Success-Response: | ||
33 | - * { | ||
34 | - * code:ok, | ||
35 | - * error:null | ||
36 | - * } | ||
37 | - * @apiError ThrowException 出现异常 | ||
38 | - * @apiErrorExample | ||
39 | - * { | ||
40 | - * code:fail, | ||
41 | - * error:null exception | ||
42 | - * } | ||
43 | - */ | ||
44 | - | ||
45 | - /** | ||
46 | - * @api {GET} /v1/${controllerMap} 查询${controllerMap}列表 | ||
47 | - * @apiDescription 查询${controllerMap}列表数据 | ||
48 | - * 返回分页结果 | ||
49 | - * | ||
50 | - * @apiGroup ${controllerMap} | ||
51 | - * @apiName ${controllerMap}列表 | ||
52 | - * @apiVersion 1.0.0 | ||
53 | - * @apiHeader Authorization | ||
54 | - * | ||
55 | - * @apiUse ResultInfo | ||
56 | - */ | ||
57 | - @GetMapping | ||
58 | - public ResultInfo get(HttpServletRequest request){ | ||
59 | - String pageStr = request.getParameter("page"); | ||
60 | - if(StringUtils.isEmpty(pageStr)){ | ||
61 | - pageStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE; | ||
62 | - } | ||
63 | - String sizeStr = request.getParameter("size"); | ||
64 | - if(StringUtils.isEmpty(sizeStr)){ | ||
65 | - sizeStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE_SIZE; | ||
66 | - } | ||
67 | - List<Object[]> condition = UtilHttpRequestMap.getSqlConditionListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, "page,size"); | ||
68 | - return this.${serviceClassFieldName}.getListV1(condition, Integer.valueOf(pageStr), Integer.valueOf(sizeStr)); | ||
69 | - } | ||
70 | - | ||
71 | - /** | ||
72 | - * @api {GET} /v1/${controllerMap}/{ssid} 查询ssid对应的${controllerMap} | ||
73 | - * @apiDescription 查询ssid对应${controllerMap}数据 | ||
74 | - * | ||
75 | - * @apiGroup ${controllerMap} | ||
76 | - * @apiName get实体数据 | ||
77 | - * @apiVersion 1.0.0 | ||
78 | - * @apiHeader Authorization | ||
79 | - * | ||
80 | - * @apiUse ResultInfo | ||
81 | - */ | ||
82 | - @GetMapping("/{ssid}") | ||
83 | - public ResultInfo get(String ssid){ | ||
84 | - return this.${serviceClassFieldName}.getOneV1(ssid); | ||
85 | - } | ||
86 | - | ||
87 | - /** | ||
88 | - * @api {POST} /v1/${controllerMap} 创建${controllerMap} | ||
89 | - * @apiDescription 创建${controllerMap} | ||
90 | - * | ||
91 | - * @apiGroup ${controllerMap} | ||
92 | - * @apiName get实体数据 | ||
93 | - * @apiVersion 1.0.0 | ||
94 | - * @apiHeader Authorization | ||
95 | - * | ||
96 | - * @apiUse ResultInfo | ||
97 | - */ | ||
98 | - @PostMapping | ||
99 | - public ResultInfo post(HttpServletRequest request){ | ||
100 | - return this.${serviceClassFieldName}.postV1(UtilHttpRequestMap.getMapValueStringByRequestMap(request.getParameterMap())); | ||
101 | - } | ||
102 | - | ||
103 | - /** | ||
104 | - * @api {DELETE} /v1/${controllerMap}/{ssid} 删除ssid对应的${controllerMap} | ||
105 | - * @apiDescription 删除ssid对应的${controllerMap}数据 | ||
106 | - * | ||
107 | - * @apiGroup ${controllerMap} | ||
108 | - * @apiName 删除实体数据 | ||
109 | - * @apiVersion 1.0.0 | ||
110 | - * @apiHeader Authorization | ||
111 | - * | ||
112 | - * @apiUse ResultInfo | ||
113 | - */ | ||
114 | - @DeleteMapping("/{ssid}") | ||
115 | - public ResultInfo delete(String ssid){ | ||
116 | - return this.${serviceClassFieldName}.deleteV1(ssid); | ||
117 | - } | ||
118 | - | ||
119 | - /** | ||
120 | - * @api {PUT} /v1/${controllerMap}/{ssid} 修改${controllerMap}数据 | ||
121 | - * @apiDescription 修改${controllerMap}数据 | ||
122 | - * | ||
123 | - * @apiGroup ${controllerMap} | ||
124 | - * @apiName 修改实体数据 | ||
125 | - * @apiVersion 1.0.0 | ||
126 | - * @apiHeader Authorization | ||
127 | - * | ||
128 | - * @apiUse ResultInfo | ||
129 | - */ | ||
130 | - @PutMapping("/{ssid}") | ||
131 | - public ResultInfo put(String ssid, HttpServletRequest request){ | ||
132 | - return this.${serviceClassFieldName}.putV1(ssid, UtilHttpRequestMap.getUpdateListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, null)); | ||
133 | - } | ||
134 | - | ||
135 | -} |
src/main/java/com/taover/codegenerate/bazhuayun/template/VoTemplate.ftl
@@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
1 | -package ${basePackage}.bean.vo; | ||
2 | - | ||
3 | -import java.io.Serializable; | ||
4 | -import java.math.BigDecimal; | ||
5 | -import java.sql.Timestamp; | ||
6 | -import java.util.Date; | ||
7 | - | ||
8 | -/** | ||
9 | - <#if version?exists> | ||
10 | - * @version ${version} | ||
11 | - </#if> | ||
12 | - */ | ||
13 | -public class ${voClassSimpleName} implements Serializable { | ||
14 | - | ||
15 | - private static final long serialVersionUID = 1L; | ||
16 | - | ||
17 | - <#--变量 ,get,set方法--> | ||
18 | -<#if tablemodel.columnlist?exists> | ||
19 | - <#list tablemodel.columnlist as clist> | ||
20 | - | ||
21 | - <#if clist.columnRemarks?exists> | ||
22 | - /** | ||
23 | - * ${clist.columnRemarks} | ||
24 | - */ | ||
25 | - </#if> | ||
26 | - private ${clist.columnJAVAType} ${clist.columnName}; | ||
27 | - | ||
28 | - public ${clist.columnJAVAType} get${clist.columnMethodName}(){ | ||
29 | - return ${clist.columnName}; | ||
30 | - } | ||
31 | - public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){ | ||
32 | - this.${clist.columnName} = ${clist.columnName}; | ||
33 | - } | ||
34 | - </#list> | ||
35 | -</#if> | ||
36 | - | ||
37 | -} | ||
38 | \ No newline at end of file | 0 | \ No newline at end of file |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +package ${basePackage}.bean.dto; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.math.BigDecimal; | ||
5 | +import java.sql.Timestamp; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +/** | ||
9 | + <#if version?exists> | ||
10 | + * @version ${version} | ||
11 | + </#if> | ||
12 | + */ | ||
13 | +public class ${dtoClassSimpleName} implements Serializable { | ||
14 | + | ||
15 | + private static final long serialVersionUID = 1L; | ||
16 | + | ||
17 | + <#--变量 ,get,set方法--> | ||
18 | +<#if tablemodel.columnlist?exists> | ||
19 | + <#list tablemodel.columnlist as clist> | ||
20 | + | ||
21 | + <#if clist.columnRemarks?exists> | ||
22 | + /** | ||
23 | + * ${clist.columnRemarks} | ||
24 | + */ | ||
25 | + </#if> | ||
26 | + private ${clist.columnJAVAType} ${clist.columnName}; | ||
27 | + | ||
28 | + public ${clist.columnJAVAType} get${clist.columnMethodName}(){ | ||
29 | + return ${clist.columnName}; | ||
30 | + } | ||
31 | + public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){ | ||
32 | + this.${clist.columnName} = ${clist.columnName}; | ||
33 | + } | ||
34 | + </#list> | ||
35 | +</#if> | ||
36 | + | ||
37 | +} | ||
0 | \ No newline at end of file | 38 | \ No newline at end of file |
src/main/resources/template/bazhuayun/EntityTemplate.ftl
0 → 100644
@@ -0,0 +1,52 @@ | @@ -0,0 +1,52 @@ | ||
1 | +package ${basePackage}.bean.entity; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.math.BigDecimal; | ||
5 | +import java.sql.Timestamp; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +import javax.persistence.Entity; | ||
9 | +import javax.persistence.Table; | ||
10 | +import javax.persistence.Id; | ||
11 | +import javax.persistence.Column; | ||
12 | + | ||
13 | +/** | ||
14 | + <#if version?exists> | ||
15 | + * @version ${version} | ||
16 | + </#if> | ||
17 | + */ | ||
18 | +@Entity | ||
19 | +@Table(name="${tablemodel.tableName}", catalog="${tablemodel.schemeName}") | ||
20 | +public class ${entityClassSimpleName} implements Serializable { | ||
21 | + | ||
22 | + private static final long serialVersionUID = 1L; | ||
23 | + | ||
24 | + <#--变量 ,get,set方法--> | ||
25 | +<#if tablemodel.columnlist?exists> | ||
26 | + <#list tablemodel.columnlist as clist> | ||
27 | + | ||
28 | + <#if clist.columnRemarks?exists> | ||
29 | + /** | ||
30 | + * ${clist.columnRemarks} | ||
31 | + */ | ||
32 | + </#if> | ||
33 | + <#if clist.primaryKey == true> | ||
34 | + @Id | ||
35 | + </#if> | ||
36 | + @Column(name="${clist.columnUName}") | ||
37 | + private ${clist.columnJAVAType} ${clist.columnName}; | ||
38 | + | ||
39 | + public ${clist.columnJAVAType} get${clist.columnMethodName}(){ | ||
40 | + return ${clist.columnName}; | ||
41 | + } | ||
42 | + public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){ | ||
43 | + this.${clist.columnName} = ${clist.columnName}; | ||
44 | + } | ||
45 | + </#list> | ||
46 | +</#if> | ||
47 | + | ||
48 | + @Override | ||
49 | + public String toString() { | ||
50 | + return "${entityClassSimpleName}: ${toStringMethodBody}; | ||
51 | + } | ||
52 | + } | ||
0 | \ No newline at end of file | 53 | \ No newline at end of file |
src/main/resources/template/bazhuayun/ManageControllerTemplate.ftl
0 → 100644
@@ -0,0 +1,135 @@ | @@ -0,0 +1,135 @@ | ||
1 | +package ${basePackage}.controller.manage; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import javax.annotation.Resource; | ||
6 | +import javax.servlet.http.HttpServletRequest; | ||
7 | + | ||
8 | +import org.apache.commons.lang.StringUtils; | ||
9 | +import org.springframework.web.bind.annotation.DeleteMapping; | ||
10 | +import org.springframework.web.bind.annotation.GetMapping; | ||
11 | +import org.springframework.web.bind.annotation.PostMapping; | ||
12 | +import org.springframework.web.bind.annotation.PutMapping; | ||
13 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | +import org.springframework.web.bind.annotation.RestController; | ||
15 | + | ||
16 | +import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
17 | +import ${basePackage}.constants.GlobalConstants; | ||
18 | +import ${basePackage}.service.${serviceClassSimpleName}; | ||
19 | + | ||
20 | +import com.taover.util.UtilHttpRequestMap; | ||
21 | +import com.taover.util.bean.ResultInfo; | ||
22 | + | ||
23 | +@Controller("manage.${controllerMap}") | ||
24 | +@RequestMapping("/manage/${controllerMap}") | ||
25 | +public class ${controllerClassName} { | ||
26 | + @Resource | ||
27 | + private ${serviceClassSimpleName} ${serviceClassFieldName}; | ||
28 | + | ||
29 | + /** | ||
30 | + * @apiDefine ResultInfo | ||
31 | + * @apiSuccess {string} | ||
32 | + * @apiSuccessExample {json} Success-Response: | ||
33 | + * { | ||
34 | + * code:ok, | ||
35 | + * error:null | ||
36 | + * } | ||
37 | + * @apiError ThrowException 出现异常 | ||
38 | + * @apiErrorExample | ||
39 | + * { | ||
40 | + * code:fail, | ||
41 | + * error:null exception | ||
42 | + * } | ||
43 | + */ | ||
44 | + | ||
45 | + /** | ||
46 | + * @api {GET} /manage/${controllerMap} 查询${controllerMap}列表 | ||
47 | + * @apiDescription 查询${controllerMap}列表数据 | ||
48 | + * 返回分页结果 | ||
49 | + * | ||
50 | + * @apiGroup ${controllerMap} | ||
51 | + * @apiName ${controllerMap}列表 | ||
52 | + * @apiVersion 1.0.0 | ||
53 | + * @apiHeader Authorization | ||
54 | + * | ||
55 | + * @apiUse ResultInfo | ||
56 | + */ | ||
57 | + @GetMapping | ||
58 | + public ResultInfo get(HttpServletRequest request){ | ||
59 | + String pageStr = request.getParameter("page"); | ||
60 | + if(StringUtils.isEmpty(pageStr)){ | ||
61 | + pageStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE; | ||
62 | + } | ||
63 | + String sizeStr = request.getParameter("size"); | ||
64 | + if(StringUtils.isEmpty(sizeStr)){ | ||
65 | + sizeStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE_SIZE; | ||
66 | + } | ||
67 | + List<Object[]> condition = UtilHttpRequestMap.getSqlConditionListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, "page,size"); | ||
68 | + return this.${serviceClassFieldName}.getListManage(condition, Integer.valueOf(pageStr), Integer.valueOf(sizeStr)); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * @api {GET} /manage/${controllerMap}/{ssid} 查询ssid对应的${controllerMap} | ||
73 | + * @apiDescription 查询ssid对应${controllerMap}数据 | ||
74 | + * | ||
75 | + * @apiGroup ${controllerMap} | ||
76 | + * @apiName get实体数据 | ||
77 | + * @apiVersion 1.0.0 | ||
78 | + * @apiHeader Authorization | ||
79 | + * | ||
80 | + * @apiUse ResultInfo | ||
81 | + */ | ||
82 | + @GetMapping("/{ssid}") | ||
83 | + public ResultInfo get(String ssid){ | ||
84 | + return this.${serviceClassFieldName}.getOneManage(ssid); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * @api {POST} /manage/${controllerMap} 创建${controllerMap} | ||
89 | + * @apiDescription 创建${controllerMap} | ||
90 | + * | ||
91 | + * @apiGroup ${controllerMap} | ||
92 | + * @apiName get实体数据 | ||
93 | + * @apiVersion 1.0.0 | ||
94 | + * @apiHeader Authorization | ||
95 | + * | ||
96 | + * @apiUse ResultInfo | ||
97 | + */ | ||
98 | + @PostMapping | ||
99 | + public ResultInfo post(HttpServletRequest request){ | ||
100 | + return this.${serviceClassFieldName}.postManage(UtilHttpRequestMap.getMapValueStringByRequestMap(request.getParameterMap())); | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * @api {DELETE} /manage/${controllerMap}/{ssid} 删除ssid对应的${controllerMap} | ||
105 | + * @apiDescription 删除ssid对应的${controllerMap}数据 | ||
106 | + * | ||
107 | + * @apiGroup ${controllerMap} | ||
108 | + * @apiName 删除实体数据 | ||
109 | + * @apiVersion 1.0.0 | ||
110 | + * @apiHeader Authorization | ||
111 | + * | ||
112 | + * @apiUse ResultInfo | ||
113 | + */ | ||
114 | + @DeleteMapping("/{ssid}") | ||
115 | + public ResultInfo delete(String ssid){ | ||
116 | + return this.${serviceClassFieldName}.deleteManage(ssid); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * @api {PUT} /manage/${controllerMap}/{ssid} 修改${controllerMap}数据 | ||
121 | + * @apiDescription 修改${controllerMap}数据 | ||
122 | + * | ||
123 | + * @apiGroup ${controllerMap} | ||
124 | + * @apiName 修改实体数据 | ||
125 | + * @apiVersion 1.0.0 | ||
126 | + * @apiHeader Authorization | ||
127 | + * | ||
128 | + * @apiUse ResultInfo | ||
129 | + */ | ||
130 | + @PutMapping("/{ssid}") | ||
131 | + public ResultInfo put(String ssid, HttpServletRequest request){ | ||
132 | + return this.${serviceClassFieldName}.putManage(ssid, UtilHttpRequestMap.getUpdateListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, null)); | ||
133 | + } | ||
134 | + | ||
135 | +} |
src/main/resources/template/bazhuayun/RepositoryTemplate.ftl
0 → 100644
@@ -0,0 +1,74 @@ | @@ -0,0 +1,74 @@ | ||
1 | +package ${basePackage}.repository; | ||
2 | + | ||
3 | +import java.math.BigInteger; | ||
4 | +import java.util.ArrayList; | ||
5 | +import java.util.Base64; | ||
6 | +import java.util.List; | ||
7 | +import java.util.Map; | ||
8 | + | ||
9 | +import org.msgpack.MessagePack; | ||
10 | +import org.springframework.stereotype.Repository; | ||
11 | + | ||
12 | +import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
13 | +import ${basePackage}.bean.vo.${voClassSimpleName}; | ||
14 | +import com.taover.repository.CustomJdbcTemplate; | ||
15 | +import com.taover.util.UtilHttpRequestMap; | ||
16 | +import com.taover.util.UtilObject; | ||
17 | + | ||
18 | +@Repository | ||
19 | +public class ${repositoryClassSimpleName} extends CustomJdbcTemplate<${entityClassSimpleName}, Integer>{ | ||
20 | + | ||
21 | + public ${repositoryClassSimpleName}() throws Exception { | ||
22 | + super(); | ||
23 | + } | ||
24 | + | ||
25 | + public String getSsidById(Integer id) throws Exception{ | ||
26 | + MessagePack pack = new MessagePack(); | ||
27 | + return Base64.getEncoder().encodeToString(pack.write(new Integer[]{id, id, id})); | ||
28 | + } | ||
29 | + | ||
30 | + public Integer getIdBySsid(String ssid) throws Exception{ | ||
31 | + MessagePack pack = new MessagePack(); | ||
32 | + return pack.read(Base64.getDecoder().decode(ssid), Integer[].class)[0]; | ||
33 | + } | ||
34 | + | ||
35 | + public Map<String, Object> getVoPage(List<Object[]> condition, Integer page, Integer size) throws Exception{ | ||
36 | + Map<String, Object> entityData = this.findPageByCondition(condition, page, size); | ||
37 | + List<${entityClassSimpleName}> entityList = (List<${entityClassSimpleName}>) entityData.get("rows"); | ||
38 | + List<${voClassSimpleName}> voList = new ArrayList<${voClassSimpleName}>(); | ||
39 | + for(int i=0; i<entityList.size(); ++i){ | ||
40 | + voList.add(this.getVoByEntity(entityList.get(i))); | ||
41 | + } | ||
42 | + entityData.put("rows", voList); | ||
43 | + return entityData; | ||
44 | + } | ||
45 | + | ||
46 | + public ${voClassSimpleName} getVoBySsid(String ssid) throws Exception{ | ||
47 | + return this.getVoByEntity(this.findEntityByID(this.getIdBySsid(ssid))); | ||
48 | + } | ||
49 | + | ||
50 | + public ${voClassSimpleName} getVoByEntity(${entityClassSimpleName} entity) throws Exception{ | ||
51 | + ${voClassSimpleName} voObj = null; | ||
52 | + try { | ||
53 | + voObj = UtilObject.fieldCopy(entity, ${voClassSimpleName}.class, true, new String[]{"id"}); | ||
54 | + } catch (Exception e) { | ||
55 | + throw new Exception("对象转换失败"); | ||
56 | + } | ||
57 | + voObj.setSsid(this.getSsidById(entity.getId())); | ||
58 | + return voObj; | ||
59 | + } | ||
60 | + | ||
61 | + public void updateEntityBySsid(String ssid, List<Object[]> updateList) throws Exception{ | ||
62 | + this.updateEntityById(updateList, this.getIdBySsid(ssid)); | ||
63 | + } | ||
64 | + | ||
65 | + public void deleteEntityBySsid(String ssid) throws Exception{ | ||
66 | + this.deleteEntityByID(this.getIdBySsid(ssid)); | ||
67 | + } | ||
68 | + | ||
69 | + public ${voClassSimpleName} addEntityByMap(Map<String, Object> data) throws Exception{ | ||
70 | + ${entityClassSimpleName} entityObj = UtilHttpRequestMap.getBeanByMap(data, ${entityClassSimpleName}.class, false, "id"); | ||
71 | + BigInteger resultId = this.addEntityForAutoincrementId(entityObj); | ||
72 | + return this.getVoByEntity(this.findEntityByID(resultId.intValue())); | ||
73 | + } | ||
74 | +} |
src/main/resources/template/bazhuayun/ServiceImplTemplate.ftl
0 → 100644
@@ -0,0 +1,124 @@ | @@ -0,0 +1,124 @@ | ||
1 | +package ${basePackage}.service.impl; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | +import java.util.Map; | ||
5 | + | ||
6 | +import javax.annotation.Resource; | ||
7 | + | ||
8 | +import org.springframework.stereotype.Service; | ||
9 | + | ||
10 | +import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
11 | +import ${basePackage}.repository.${repositoryClassSimpleName}; | ||
12 | +import ${basePackage}.service.${serviceClassSimpleName}; | ||
13 | +import com.taover.util.UtilLog; | ||
14 | +import com.taover.util.bean.ResultInfo; | ||
15 | +import com.taover.util.bean.UtilResultInfo; | ||
16 | + | ||
17 | +@Service | ||
18 | +public class ${serviceImplClassSimpleName} implements ${serviceClassSimpleName} { | ||
19 | + @Resource | ||
20 | + private ${repositoryClassSimpleName} ${repositoryClassFieldName}; | ||
21 | + | ||
22 | + @Override | ||
23 | + public ResultInfo getListV1(List<Object[]> condition, Integer page, Integer size) { | ||
24 | + try { | ||
25 | + return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoPage(condition, page, size)); | ||
26 | + } catch (Exception e) { | ||
27 | + UtilLog.errorForException(e, this.getClass()); | ||
28 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
29 | + } | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public ResultInfo getOneV1(String ssid) { | ||
34 | + try { | ||
35 | + return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoBySsid(ssid)); | ||
36 | + } catch (Exception e) { | ||
37 | + UtilLog.errorForException(e, this.getClass()); | ||
38 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public ResultInfo putV1(String ssid, List<Object[]> updateList) { | ||
44 | + try{ | ||
45 | + this.${repositoryClassFieldName}.updateEntityBySsid(ssid, updateList); | ||
46 | + }catch(Exception e){ | ||
47 | + UtilLog.errorForException(e, this.getClass()); | ||
48 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
49 | + } | ||
50 | + return UtilResultInfo.getSuccess("更新成功"); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public ResultInfo deleteV1(String ssid) { | ||
55 | + try{ | ||
56 | + this.${repositoryClassFieldName}.deleteEntityBySsid(ssid); | ||
57 | + }catch(Exception e){ | ||
58 | + UtilLog.errorForException(e, this.getClass()); | ||
59 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
60 | + } | ||
61 | + return UtilResultInfo.getSuccess("删除成功"); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public ResultInfo postV1(Map<String, Object> data) { | ||
66 | + try { | ||
67 | + return UtilResultInfo.getSuccess("创建成功", this.${repositoryClassFieldName}.addEntityByMap(data)); | ||
68 | + } catch (Exception e) { | ||
69 | + UtilLog.errorForException(e, this.getClass()); | ||
70 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
71 | + } | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public ResultInfo getListManage(List<Object[]> condition, Integer page, Integer size) { | ||
76 | + try { | ||
77 | + return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoPage(condition, page, size)); | ||
78 | + } catch (Exception e) { | ||
79 | + UtilLog.errorForException(e, this.getClass()); | ||
80 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public ResultInfo getOneManage(String ssid) { | ||
86 | + try { | ||
87 | + return UtilResultInfo.getSuccess("查询成功", this.${repositoryClassFieldName}.getVoBySsid(ssid)); | ||
88 | + } catch (Exception e) { | ||
89 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
90 | + } | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public ResultInfo putManage(String ssid, List<Object[]> updateList) { | ||
95 | + try{ | ||
96 | + this.${repositoryClassFieldName}.updateEntityBySsid(ssid, updateList); | ||
97 | + }catch(Exception e){ | ||
98 | + UtilLog.errorForException(e, this.getClass()); | ||
99 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
100 | + } | ||
101 | + return UtilResultInfo.getSuccess("更新成功"); | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public ResultInfo deleteManage(String ssid) { | ||
106 | + try{ | ||
107 | + this.${repositoryClassFieldName}.deleteEntityBySsid(ssid); | ||
108 | + }catch(Exception e){ | ||
109 | + UtilLog.errorForException(e, this.getClass()); | ||
110 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
111 | + } | ||
112 | + return UtilResultInfo.getSuccess("删除成功"); | ||
113 | + } | ||
114 | + | ||
115 | + @Override | ||
116 | + public ResultInfo postManage(Map<String, Object> data) { | ||
117 | + try { | ||
118 | + return UtilResultInfo.getSuccess("创建成功", this.${repositoryClassFieldName}.addEntityByMap(data)); | ||
119 | + } catch (Exception e) { | ||
120 | + UtilLog.errorForException(e, this.getClass()); | ||
121 | + return UtilResultInfo.getFailure(e.getMessage()); | ||
122 | + } | ||
123 | + } | ||
124 | +} |
src/main/resources/template/bazhuayun/ServiceTemplate.ftl
0 → 100644
@@ -0,0 +1,82 @@ | @@ -0,0 +1,82 @@ | ||
1 | +package ${basePackage}.service; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | +import java.util.Map; | ||
5 | + | ||
6 | +import com.taover.util.bean.ResultInfo; | ||
7 | + | ||
8 | +public interface ${serviceClassSimpleName} { | ||
9 | + /** | ||
10 | + * 获取列表 | ||
11 | + * @param condition | ||
12 | + * @param page | ||
13 | + * @param size | ||
14 | + * @return | ||
15 | + */ | ||
16 | + public ResultInfo getListV1(List<Object[]> condition, Integer page, Integer size); | ||
17 | + | ||
18 | + /** | ||
19 | + * 获取ssid对应的数据 | ||
20 | + * @param ssid | ||
21 | + * @return | ||
22 | + */ | ||
23 | + public ResultInfo getOneV1(String ssid); | ||
24 | + | ||
25 | + /** | ||
26 | + * 修改ssid对应的数据 | ||
27 | + * @param ssid | ||
28 | + * @return | ||
29 | + */ | ||
30 | + public ResultInfo putV1(String ssid, List<Object[]> updateList); | ||
31 | + | ||
32 | + /** | ||
33 | + * 删除ssid对应的数据 | ||
34 | + * @param ssid | ||
35 | + * @return | ||
36 | + */ | ||
37 | + public ResultInfo deleteV1(String ssid); | ||
38 | + | ||
39 | + /** | ||
40 | + * 创建数据 | ||
41 | + * @param ssid | ||
42 | + * @return | ||
43 | + */ | ||
44 | + public ResultInfo postV1(Map<String, Object> data); | ||
45 | + | ||
46 | + /** | ||
47 | + * 获取列表 | ||
48 | + * @param condition | ||
49 | + * @param page | ||
50 | + * @param size | ||
51 | + * @return | ||
52 | + */ | ||
53 | + public ResultInfo getListManage(List<Object[]> condition, Integer page, Integer size); | ||
54 | + | ||
55 | + /** | ||
56 | + * 获取ssid对应的数据 | ||
57 | + * @param ssid | ||
58 | + * @return | ||
59 | + */ | ||
60 | + public ResultInfo getOneManage(String ssid); | ||
61 | + | ||
62 | + /** | ||
63 | + * 修改ssid对应的数据 | ||
64 | + * @param ssid | ||
65 | + * @return | ||
66 | + */ | ||
67 | + public ResultInfo putManage(String ssid, List<Object[]> updateList); | ||
68 | + | ||
69 | + /** | ||
70 | + * 删除ssid对应的数据 | ||
71 | + * @param ssid | ||
72 | + * @return | ||
73 | + */ | ||
74 | + public ResultInfo deleteManage(String ssid); | ||
75 | + | ||
76 | + /** | ||
77 | + * 创建数据 | ||
78 | + * @param ssid | ||
79 | + * @return | ||
80 | + */ | ||
81 | + public ResultInfo postManage(Map<String, Object> data); | ||
82 | +} |
src/main/resources/template/bazhuayun/V1ControllerTemplate.ftl
0 → 100644
@@ -0,0 +1,135 @@ | @@ -0,0 +1,135 @@ | ||
1 | +package ${basePackage}.controller.v1; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import javax.annotation.Resource; | ||
6 | +import javax.servlet.http.HttpServletRequest; | ||
7 | + | ||
8 | +import org.apache.commons.lang.StringUtils; | ||
9 | +import org.springframework.web.bind.annotation.DeleteMapping; | ||
10 | +import org.springframework.web.bind.annotation.GetMapping; | ||
11 | +import org.springframework.web.bind.annotation.PostMapping; | ||
12 | +import org.springframework.web.bind.annotation.PutMapping; | ||
13 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | +import org.springframework.web.bind.annotation.RestController; | ||
15 | + | ||
16 | +import ${basePackage}.bean.entity.${entityClassSimpleName}; | ||
17 | +import ${basePackage}.constants.GlobalConstants; | ||
18 | +import ${basePackage}.service.${serviceClassSimpleName}; | ||
19 | + | ||
20 | +import com.taover.util.UtilHttpRequestMap; | ||
21 | +import com.taover.util.bean.ResultInfo; | ||
22 | + | ||
23 | +@RestController("v1.${controllerMap}") | ||
24 | +@RequestMapping("/v1/${controllerMap}") | ||
25 | +public class ${controllerClassName} { | ||
26 | + @Resource | ||
27 | + private ${serviceClassSimpleName} ${serviceClassFieldName}; | ||
28 | + | ||
29 | + /** | ||
30 | + * @apiDefine ResultInfo | ||
31 | + * @apiSuccess {string} | ||
32 | + * @apiSuccessExample {json} Success-Response: | ||
33 | + * { | ||
34 | + * code:ok, | ||
35 | + * error:null | ||
36 | + * } | ||
37 | + * @apiError ThrowException 出现异常 | ||
38 | + * @apiErrorExample | ||
39 | + * { | ||
40 | + * code:fail, | ||
41 | + * error:null exception | ||
42 | + * } | ||
43 | + */ | ||
44 | + | ||
45 | + /** | ||
46 | + * @api {GET} /v1/${controllerMap} 查询${controllerMap}列表 | ||
47 | + * @apiDescription 查询${controllerMap}列表数据 | ||
48 | + * 返回分页结果 | ||
49 | + * | ||
50 | + * @apiGroup ${controllerMap} | ||
51 | + * @apiName ${controllerMap}列表 | ||
52 | + * @apiVersion 1.0.0 | ||
53 | + * @apiHeader Authorization | ||
54 | + * | ||
55 | + * @apiUse ResultInfo | ||
56 | + */ | ||
57 | + @GetMapping | ||
58 | + public ResultInfo get(HttpServletRequest request){ | ||
59 | + String pageStr = request.getParameter("page"); | ||
60 | + if(StringUtils.isEmpty(pageStr)){ | ||
61 | + pageStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE; | ||
62 | + } | ||
63 | + String sizeStr = request.getParameter("size"); | ||
64 | + if(StringUtils.isEmpty(sizeStr)){ | ||
65 | + sizeStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE_SIZE; | ||
66 | + } | ||
67 | + List<Object[]> condition = UtilHttpRequestMap.getSqlConditionListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, "page,size"); | ||
68 | + return this.${serviceClassFieldName}.getListV1(condition, Integer.valueOf(pageStr), Integer.valueOf(sizeStr)); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * @api {GET} /v1/${controllerMap}/{ssid} 查询ssid对应的${controllerMap} | ||
73 | + * @apiDescription 查询ssid对应${controllerMap}数据 | ||
74 | + * | ||
75 | + * @apiGroup ${controllerMap} | ||
76 | + * @apiName get实体数据 | ||
77 | + * @apiVersion 1.0.0 | ||
78 | + * @apiHeader Authorization | ||
79 | + * | ||
80 | + * @apiUse ResultInfo | ||
81 | + */ | ||
82 | + @GetMapping("/{ssid}") | ||
83 | + public ResultInfo get(String ssid){ | ||
84 | + return this.${serviceClassFieldName}.getOneV1(ssid); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * @api {POST} /v1/${controllerMap} 创建${controllerMap} | ||
89 | + * @apiDescription 创建${controllerMap} | ||
90 | + * | ||
91 | + * @apiGroup ${controllerMap} | ||
92 | + * @apiName get实体数据 | ||
93 | + * @apiVersion 1.0.0 | ||
94 | + * @apiHeader Authorization | ||
95 | + * | ||
96 | + * @apiUse ResultInfo | ||
97 | + */ | ||
98 | + @PostMapping | ||
99 | + public ResultInfo post(HttpServletRequest request){ | ||
100 | + return this.${serviceClassFieldName}.postV1(UtilHttpRequestMap.getMapValueStringByRequestMap(request.getParameterMap())); | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * @api {DELETE} /v1/${controllerMap}/{ssid} 删除ssid对应的${controllerMap} | ||
105 | + * @apiDescription 删除ssid对应的${controllerMap}数据 | ||
106 | + * | ||
107 | + * @apiGroup ${controllerMap} | ||
108 | + * @apiName 删除实体数据 | ||
109 | + * @apiVersion 1.0.0 | ||
110 | + * @apiHeader Authorization | ||
111 | + * | ||
112 | + * @apiUse ResultInfo | ||
113 | + */ | ||
114 | + @DeleteMapping("/{ssid}") | ||
115 | + public ResultInfo delete(String ssid){ | ||
116 | + return this.${serviceClassFieldName}.deleteV1(ssid); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * @api {PUT} /v1/${controllerMap}/{ssid} 修改${controllerMap}数据 | ||
121 | + * @apiDescription 修改${controllerMap}数据 | ||
122 | + * | ||
123 | + * @apiGroup ${controllerMap} | ||
124 | + * @apiName 修改实体数据 | ||
125 | + * @apiVersion 1.0.0 | ||
126 | + * @apiHeader Authorization | ||
127 | + * | ||
128 | + * @apiUse ResultInfo | ||
129 | + */ | ||
130 | + @PutMapping("/{ssid}") | ||
131 | + public ResultInfo put(String ssid, HttpServletRequest request){ | ||
132 | + return this.${serviceClassFieldName}.putV1(ssid, UtilHttpRequestMap.getUpdateListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, null)); | ||
133 | + } | ||
134 | + | ||
135 | +} |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +package ${basePackage}.bean.vo; | ||
2 | + | ||
3 | +import java.io.Serializable; | ||
4 | +import java.math.BigDecimal; | ||
5 | +import java.sql.Timestamp; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +/** | ||
9 | + <#if version?exists> | ||
10 | + * @version ${version} | ||
11 | + </#if> | ||
12 | + */ | ||
13 | +public class ${voClassSimpleName} implements Serializable { | ||
14 | + | ||
15 | + private static final long serialVersionUID = 1L; | ||
16 | + | ||
17 | + <#--变量 ,get,set方法--> | ||
18 | +<#if tablemodel.columnlist?exists> | ||
19 | + <#list tablemodel.columnlist as clist> | ||
20 | + | ||
21 | + <#if clist.columnRemarks?exists> | ||
22 | + /** | ||
23 | + * ${clist.columnRemarks} | ||
24 | + */ | ||
25 | + </#if> | ||
26 | + private ${clist.columnJAVAType} ${clist.columnName}; | ||
27 | + | ||
28 | + public ${clist.columnJAVAType} get${clist.columnMethodName}(){ | ||
29 | + return ${clist.columnName}; | ||
30 | + } | ||
31 | + public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){ | ||
32 | + this.${clist.columnName} = ${clist.columnName}; | ||
33 | + } | ||
34 | + </#list> | ||
35 | +</#if> | ||
36 | + | ||
37 | +} | ||
0 | \ No newline at end of file | 38 | \ No newline at end of file |