1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package ${packageName}.web;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import ${packageName}.model.${ClassName}Entity;
import ${packageName}.service.${ClassName}Service;
<#if table.tplCategory=="tree">
import ${packageName}.model.${ClassName}Query;
import ${packageName}.model.${ClassName}TreeSelect;
</#if>
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* ${functionName}
*
* @author ${author}
* @date ${datetime}
*/
@RestController
@RequestMapping("${RequestMapping}")
public class ${ClassName}Controller extends BaseCRUDJsonBodyMappingController<${ClassName}Service,${ClassName}Entity,${pkColumn.javaType}> {
@Autowired
private ParamService paramService;
public ${ClassName}Controller(){
super.setModuleDesc( "${functionName}");
}
@Override
protected void init(Map<String, Object> model, Context context) {
<#list columns as column>
<#if column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5>
this.addDict(model, "${column.javaField}", paramService.getParamBySecondOrganize("${ClassName}","${column.javaField}"));
</#if>
</#list>
super.init(model, context);
}
<#if table.tplCategory=="tree">
@PostMapping("list/exclude")
public String excludeList(${ClassName}Entity query) {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
${pkColumn.javaType} id = query.get${pkColumn.javaField?cap_first}();
int code=VALUE_RESULT_SUCCESS;
try {
Set<${pkColumn.javaType}> idSet = new HashSet<>();
idSet.add(query.get${pkColumn.javaField?cap_first}());
List<${ClassName}Entity> collect = this.service.find(new ${ClassName}Query()).stream().map(item -> {
if(idSet.contains(item.getget${pkColumn.javaField?cap_first}())) return null;
return item;
}).filter(f -> f != null).collect(Collectors.toList());
model.put("result", collect);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 获取站点下拉树列表
*/
@PostMapping("treeselect")
public String treeselect(${ClassName}Entity query) {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
int code=VALUE_RESULT_SUCCESS;
try {
List<${ClassName}Entity> list = this.service.find(new ${ClassName}Query());
List<${ClassName}TreeSelect> treeSelects = this.service.build${ClassName}TreeSelect(list);
model.put("result", treeSelects);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 根据parentId查询子信息
*/
@GetMapping(value = "getListByParentId")
public String getListByParentId(${treeParentCodeType} parentId) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc()+"子节点";
try {
List<${ClassName}TreeSelect> treeList = this.service.getListByParentId(parentId, getContext());
model.put(RESULT_KEY,treeList);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
recordSysLog(request, busiDesc+"【成功】");
} catch (Exception e) {
log.error("根据parentId查询子信息错误", e);
this.doException(request, busiDesc, model, e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
return ret.toJSONString();
}
</#if>
}