Blame view

src/main/resources/templates/vm/java/Controller.java.vm 7.26 KB
mahuandong authored
1
package ${packageName}.controller;
tangying authored
2
周峰 authored
3
4
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
5
import com.huaheng.common.utils.Wrappers;
周峰 authored
6
7
8
9
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
mahuandong authored
10
import com.huaheng.common.utils.StringUtils;
tangying authored
11
12
13
14
15
16
17
18
19
20
21
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
mahuandong authored
22
23
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
tangying authored
24
25
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
周峰 authored
26
import com.huaheng.common.support.Convert;
mahuandong authored
27
import javax.annotation.Resource;
周峰 authored
28
29
import java.util.Arrays;
import java.util.Date;
tangying authored
30
31
32
import java.util.List;

/**
mahuandong authored
33
34
 * ${functionName} 信息操作处理
 *
tangying authored
35
36
37
38
 * @author ${author}
 * @date ${datetime}
 */
@Controller
mahuandong authored
39
40
@RequestMapping("/${moduleName}/${className}")
public class ${ClassName}Controller extends BaseController {
周峰 authored
41
    private String prefix = "${moduleName}/${className}";
mahuandong authored
42
43
44
45
46

	@Resource
	private I${ClassName}Service ${className}Service;

	@RequiresPermissions("${moduleName}:${className}:view")
tangying authored
47
	@GetMapping()
mahuandong authored
48
49
	public String ${className}() {
	    return prefix + "/${className}";
tangying authored
50
	}
mahuandong authored
51
tangying authored
52
	/**
mahuandong authored
53
	 * 查询${functionName}列表
tangying authored
54
	 */
mahuandong authored
55
	@RequiresPermissions("${moduleName}:${className}:list")
tangying authored
56
57
	@PostMapping("/list")
	@ResponseBody
mahuandong authored
58
59
60
61
62
63
64
	public TableDataInfo list(${ClassName} ${className}) {
		LambdaQueryWrapper<${ClassName}> lambdaQueryWrapper = Wrappers.lambdaQuery();
		lambdaQueryWrapper
		#foreach( ${column} in ${columns})
			#if(${column.isQuery} == 1)
				#if(${column.queryType} == "EQ")
					#if(${column.javaType} == "String")
周峰 authored
65
							.eq(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
66
						#else
周峰 authored
67
							.eq(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
68
69
70
					#end
				#elseif(${column.queryType} == "NE")
					#if(${column.javaType} == "String")
周峰 authored
71
						.ne(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
72
					#else
周峰 authored
73
						.ne(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
74
75
76
					#end
				#elseif(${column.queryType} == "GT")
					#if(${column.javaType} == "String")
周峰 authored
77
						.gt(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
78
					#else
周峰 authored
79
						.gt(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
80
81
82
					#end
				#elseif(${column.queryType} == "GTE")
					#if(${column.javaType} == "String")
周峰 authored
83
						.ge(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
84
					#else
周峰 authored
85
						.ge(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
86
87
88
					#end
				#elseif(${column.queryType} == "LT")
					#if(${column.javaType} == "String")
周峰 authored
89
						.lt(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
90
					#else
周峰 authored
91
						.lt(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
92
93
94
					#end
				#elseif(${column.queryType} == "LTE")
					.#if(${column.javaType} == "String")
周峰 authored
95
						.le(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
96
					#else
周峰 authored
97
						.le(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
98
99
100
					#end
				#elseif(${column.queryType} == "LIKE")
					#if(${column.javaType} == "String")
周峰 authored
101
						.like(StringUtils.isNotEmpty(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
102
					#else
周峰 authored
103
						.like(StringUtils.isNotNull(${className}.get${column.CapColumnName}()), ${ClassName}::get${column.CapColumnName}, ${className}.get${column.CapColumnName}())
mahuandong authored
104
105
106
					#end
				#end
			#end
周峰 authored
107
		#end;
mahuandong authored
108
109
110
111
112
113
		PageDomain pageDomain = TableSupport.buildPageRequest();
		Integer pageNum = pageDomain.getPageNum();
		Integer pageSize = pageDomain.getPageSize();
		if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
			/*使用分页查询*/
			Page<${ClassName}> page = new Page<>(pageNum, pageSize);
周峰 authored
114
			IPage<${ClassName}> iPage = ${className}Service.page(page, lambdaQueryWrapper);
mahuandong authored
115
116
117
118
119
			return getMpDataTable(iPage.getRecords(), iPage.getTotal());
		} else {
			List<${ClassName}> list = ${className}Service.list(lambdaQueryWrapper);
			return getDataTable(list);
		}
tangying authored
120
	}
mahuandong authored
121
tangying authored
122
	/**
mahuandong authored
123
	 * 新增${functionName}
tangying authored
124
125
	 */
	@GetMapping("/add")
mahuandong authored
126
	public String add() {
tangying authored
127
128
	    return prefix + "/add";
	}
mahuandong authored
129
tangying authored
130
	/**
mahuandong authored
131
	 * 新增保存${functionName}
tangying authored
132
	 */
mahuandong authored
133
134
	@RequiresPermissions("${moduleName}:${className}:add")
	@Log(title = "${functionName}", action = BusinessType.INSERT)
tangying authored
135
136
	@PostMapping("/add")
	@ResponseBody
mahuandong authored
137
	public AjaxResult addSave(${ClassName} ${className}) {
周峰 authored
138
		return toAjax(${className}Service.save(${className}));
tangying authored
139
140
141
	}

	/**
mahuandong authored
142
	 * 修改${functionName}
tangying authored
143
	 */
mahuandong authored
144
145
146
147
	@GetMapping("/edit/{${pkColumn.javaField}}")
	public String edit(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}, ModelMap mmap) {
		${ClassName} ${className} = ${className}Service.getById(${pkColumn.javaField});
		mmap.put("${className}", ${className});
tangying authored
148
149
	    return prefix + "/edit";
	}
mahuandong authored
150
tangying authored
151
	/**
mahuandong authored
152
	 * 修改保存${functionName}
tangying authored
153
	 */
mahuandong authored
154
155
	@RequiresPermissions("${moduleName}:${className}:edit")
	@Log(title = "${functionName}", action = BusinessType.UPDATE)
tangying authored
156
157
	@PostMapping("/edit")
	@ResponseBody
mahuandong authored
158
	public AjaxResult editSave(${ClassName} ${className}) {
周峰 authored
159
		return toAjax(${className}Service.updateById(${className}));
tangying authored
160
	}
mahuandong authored
161
tangying authored
162
	/**
mahuandong authored
163
	 * 删除${functionName}
tangying authored
164
	 */
mahuandong authored
165
	@RequiresPermissions("${moduleName}:${className}:remove")
周峰 authored
166
	@Log(title = "${functionName}", action = BusinessType.DELETE)
tangying authored
167
168
	@PostMapping( "/remove")
	@ResponseBody
mahuandong authored
169
170
171
172
173
	public AjaxResult remove(String ids) {
		if (StringUtils.isEmpty(ids)){
			return AjaxResult.error("id不能为空");
		}
		return toAjax(${className}Service.removeByIds(Arrays.asList(Convert.toIntArray(ids))));
tangying authored
174
	}
mahuandong authored
175
tangying authored
176
}