|
|
|
|
@ -3,37 +3,29 @@ package ${package}.${moduleName}.controller;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.zbkj.common.request.PageParamRequest;
|
|
|
|
|
import com.zbkj.common.response.CommonResult;
|
|
|
|
|
import com.zbkj.common.page.CommonPage;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
|
|
|
|
|
import ${package}.${moduleName}.entity.${className}Entity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import ${package}.${moduleName}.entity.${className};
|
|
|
|
|
import ${package}.${moduleName}.service.${className}Service;
|
|
|
|
|
import ${mainPath}.common.utils.PageUtils;
|
|
|
|
|
import ${mainPath}.common.utils.R;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ${comments} 控制器
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
* | Author: ${author}
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
* | @date ${datetime}
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
* | @date ${email}
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("${moduleName}/${pathName}")
|
|
|
|
|
@ -41,14 +33,53 @@ public class ${className}Controller {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ${className}Service ${classname}Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表信息
|
|
|
|
|
* 条件设置
|
|
|
|
|
* 根据实体类字段自动生成查询条件
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/list")
|
|
|
|
|
@PreAuthorize("${moduleName}:${pathName}:list")
|
|
|
|
|
public CommonResult<CommonPage<${classname}>> list(@RequestParam Map<String, Object> params){
|
|
|
|
|
CommonPage<${classname}> page = CommonPage.restPag(${classname}Service.queryPage(params));
|
|
|
|
|
private void condition(LambdaQueryWrapper<${className}> queryWrapper, ${className} request) {
|
|
|
|
|
if (request == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据实体类字段自动生成查询条件
|
|
|
|
|
#foreach ($column in $columns)
|
|
|
|
|
#set ($getter = "get" + ${column.attrname.substring(0, 1).toUpperCase()} + ${column.attrname.substring(1)})
|
|
|
|
|
#set ($fieldType = $column.attrType)
|
|
|
|
|
#if ($fieldType == "String")
|
|
|
|
|
|
|
|
|
|
// $column.comments
|
|
|
|
|
if (StrUtil.isNotBlank(request.${getter}())) {
|
|
|
|
|
queryWrapper.eq(${className}::${getter}, request.${getter}());
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// $column.comments
|
|
|
|
|
if (request.${getter}() != null) {
|
|
|
|
|
queryWrapper.eq(${className}::${getter}, request.${getter}());
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页显示${comments}
|
|
|
|
|
* @param request 搜索条件
|
|
|
|
|
* @param pageParamRequest 分页参数
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "分页列表")
|
|
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
|
public CommonResult<CommonPage<${className}>> getList(@Validated ${className} request, @Validated PageParamRequest pageParamRequest) {
|
|
|
|
|
LambdaQueryWrapper<${className}> queryWrapper = new LambdaQueryWrapper();
|
|
|
|
|
|
|
|
|
|
// 应用搜索条件
|
|
|
|
|
condition(queryWrapper, request);
|
|
|
|
|
|
|
|
|
|
CommonPage<${className}> page = CommonPage.restPage(${classname}Service.pageList(queryWrapper, pageParamRequest));
|
|
|
|
|
return CommonResult.success(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -57,9 +88,8 @@ public class ${className}Controller {
|
|
|
|
|
* 详情数据
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/info/{${pk.attrname}}")
|
|
|
|
|
@PreAuthorize("${moduleName}:${pathName}:info")
|
|
|
|
|
public CommonResult<${classname}> info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
|
|
|
|
|
${className}Entity ${classname} = ${classname}Service.getById(${pk.attrname});
|
|
|
|
|
public CommonResult<${className}> info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){
|
|
|
|
|
${className} ${classname} = ${classname}Service.getById(${pk.attrname});
|
|
|
|
|
|
|
|
|
|
return CommonResult.success(${classname});
|
|
|
|
|
}
|
|
|
|
|
@ -68,8 +98,7 @@ public class ${className}Controller {
|
|
|
|
|
* 新增数据
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/save")
|
|
|
|
|
@PreAuthorize("${moduleName}:${pathName}:save")
|
|
|
|
|
public CommonResult<String> save(@RequestBody ${className}Entity ${classname}){
|
|
|
|
|
public CommonResult<String> save(@RequestBody ${className} ${classname}){
|
|
|
|
|
if (${classname}Service.save(${classname})) {
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
}
|
|
|
|
|
@ -80,8 +109,7 @@ public class ${className}Controller {
|
|
|
|
|
* 修改数据
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
@PreAuthorize("${moduleName}:${pathName}:update")
|
|
|
|
|
public CommonResult<String> update(@RequestBody ${className}Entity ${classname}){
|
|
|
|
|
public CommonResult<String> update(@RequestBody ${className} ${classname}){
|
|
|
|
|
if (${classname}Service.updateById(${classname})) {
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
}
|
|
|
|
|
@ -92,9 +120,8 @@ public class ${className}Controller {
|
|
|
|
|
* 删除:根据id集合
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/delete")
|
|
|
|
|
@PreAuthorize("${moduleName}:${pathName}:delete")
|
|
|
|
|
public CommonResult<String> delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){
|
|
|
|
|
if (${classname}Service.removeByIds(Arrays.asList(${pk.attrname}))) {
|
|
|
|
|
if (${classname}Service.removeByIds(Arrays.asList(${pk.attrname}s))) {
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
}
|
|
|
|
|
return CommonResult.failed();
|
|
|
|
|
|