package ${bussiPackage}.${entityPackage}.controller;
|
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.List;
|
import javax.servlet.http.HttpServletRequest;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import cn.besteam.common.api.vo.Result;
|
import cn.besteam.common.aspect.annotation.AutoLog;
|
import cn.besteam.common.util.oConvertUtils;
|
import ${bussiPackage}.${entityPackage}.entity.${entityName};
|
import ${bussiPackage}.${entityPackage}.service.I${entityName}Service;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* @Title: Controller
|
* @Description: ${tableVo.ftlDescription}
|
* @author: besteam
|
* @date: ${.now?string["yyyy-MM-dd"]}
|
* @version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/${entityPackage}/${entityName?uncap_first}")
|
@Slf4j
|
@Api(description = "${tableVo.ftlDescription}")
|
public class ${entityName}Controller {
|
|
@Autowired
|
private I${entityName}Service ${entityName?uncap_first}Service;
|
|
/**
|
* 分页列表查询
|
* @param ${entityName?uncap_first}
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取${tableVo.ftlDescription}数据列表", notes = "获取所有${tableVo.ftlDescription}数据列表", produces = "application/json")
|
public Result<IPage<${entityName}>> queryPageList(${entityName} ${entityName?uncap_first}, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
|
Result<IPage<${entityName}>> result = new Result<IPage<${entityName}>>();
|
QueryWrapper<${entityName}> queryWrapper = new QueryWrapper<${entityName}>(${entityName?uncap_first});
|
Page<${entityName}> page = new Page<${entityName}>(pageNo, pageSize);
|
//排序逻辑 处理
|
String column = req.getParameter("column");
|
String order = req.getParameter("order");
|
if(oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
|
if("asc".equals(order)) {
|
queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
|
}else {
|
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
}
|
}
|
IPage<${entityName}> pageList = ${entityName?uncap_first}Service.page(page, queryWrapper);
|
//log.debug("查询当前页:"+pageList.getCurrent());
|
//log.debug("查询当前页数量:"+pageList.getSize());
|
//log.debug("查询结果数量:"+pageList.getRecords().size());
|
//log.debug("数据总数:"+pageList.getTotal());
|
result.setSuccess(true);
|
result.setResult(pageList);
|
return result;
|
}
|
|
/**
|
* 添加
|
* @param ${entityName?uncap_first}
|
* @return
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加${tableVo.ftlDescription}")
|
@ApiOperation(value = "添加${tableVo.ftlDescription}", notes = "添加${tableVo.ftlDescription}", produces = "application/json")
|
public Result<${entityName}> add(@RequestBody ${entityName} ${entityName?uncap_first}) {
|
|
Result<${entityName}> result = new Result<${entityName}>();
|
try {
|
${entityName?uncap_first}Service.save(${entityName?uncap_first});
|
result.success("添加成功!");
|
} catch (Exception e) {
|
log.error("", e);
|
result.error500("操作失败");
|
}
|
return result;
|
}
|
|
/**
|
* 编辑
|
* @param ${entityName?uncap_first}
|
* @return
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑${tableVo.ftlDescription}")
|
@ApiOperation(value = "编辑${tableVo.ftlDescription}", notes = "编辑${tableVo.ftlDescription}", produces = "application/json")
|
public Result<${entityName}> edit(@RequestBody ${entityName} ${entityName?uncap_first}) {
|
|
Result<${entityName}> result = new Result<${entityName}>();
|
${entityName} ${entityName?uncap_first}Entity = ${entityName?uncap_first}Service.getById(${entityName?uncap_first}.getId());
|
if(${entityName?uncap_first}Entity==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = ${entityName?uncap_first}Service.updateById(${entityName?uncap_first});
|
//TODO 返回false说明什么?
|
if(ok) {
|
result.success("修改成功!");
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 通过id删除
|
* @param id
|
* @return
|
*/
|
@PostMapping(value = "/delete")
|
@AutoLog(value = "删除${tableVo.ftlDescription}")
|
@ApiOperation(value = "删除${tableVo.ftlDescription}", notes = "删除${tableVo.ftlDescription}", produces = "application/json")
|
public Result<${entityName}> delete(@RequestParam(name="id",required=true) String id) {
|
|
Result<${entityName}> result = new Result<${entityName}>();
|
${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.getById(id);
|
if(${entityName?uncap_first}==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = ${entityName?uncap_first}Service.removeById(id);
|
if(ok) {
|
result.success("删除成功!");
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@PostMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除${tableVo.ftlDescription}")
|
@ApiOperation(value = "批量删除${tableVo.ftlDescription}", notes = "批量删除${tableVo.ftlDescription}", produces = "application/json")
|
public Result<${entityName}> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
Result<${entityName}> result = new Result<${entityName}>();
|
if(ids==null || "".equals(ids.trim())) {
|
result.error500("参数不识别!");
|
}else {
|
this.${entityName?uncap_first}Service.removeByIds(Arrays.asList(ids.split(",")));
|
result.success("删除成功!");
|
}
|
return result;
|
}
|
|
/**
|
* 通过id查询
|
* @param id
|
* @return
|
*/
|
@GetMapping(value = "/queryById")
|
@ApiOperation(value = "通过id查询${tableVo.ftlDescription}", notes = "通过id查询${tableVo.ftlDescription}", produces = "application/json")
|
public Result<${entityName}> queryById(@RequestParam(name="id",required=true) String id) {
|
|
Result<${entityName}> result = new Result<${entityName}>();
|
${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.getById(id);
|
if(${entityName?uncap_first}==null) {
|
result.error500("未找到对应实体");
|
}else {
|
result.setResult(${entityName?uncap_first});
|
result.setSuccess(true);
|
}
|
return result;
|
}
|
|
}
|