a2621e23bc0ba8f9ddd90013490f38ecf3bb9c09.svn-base 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package ${bussiPackage}.controller.${entityPackage};
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.io.IOException;
  6. import java.io.UnsupportedEncodingException;
  7. import java.net.URLDecoder;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import org.jeecg.common.api.vo.Result;
  11. import org.jeecg.common.system.query.QueryGenerator;
  12. import org.jeecg.common.util.oConvertUtils;
  13. import ${bussiPackage}.entity.${entityPackage}.${entityName};
  14. import ${bussiPackage}.service.${entityPackage}.I${entityName}Service;
  15. import org.jeecg.common.system.base.controller.JeecgController;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import org.springframework.web.multipart.MultipartHttpServletRequest;
  20. import org.springframework.web.servlet.ModelAndView;
  21. import org.jeecgframework.poi.excel.ExcelImportUtil;
  22. import org.jeecgframework.poi.excel.def.NormalExcelConstants;
  23. import org.jeecgframework.poi.excel.entity.ExportParams;
  24. import org.jeecgframework.poi.excel.entity.ImportParams;
  25. import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
  26. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  27. import com.baomidou.mybatisplus.core.metadata.IPage;
  28. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  29. import lombok.extern.slf4j.Slf4j;
  30. import com.alibaba.fastjson.JSON;
  31. import io.swagger.annotations.Api;
  32. import io.swagger.annotations.ApiOperation;
  33. import org.jeecg.common.aspect.annotation.AutoLog;
  34. /**
  35. * @Description: ${tableVo.ftlDescription}
  36. * @Author: jeecg-boot
  37. * @Date: ${.now?string["yyyy-MM-dd"]}
  38. * @Version: V1.0
  39. */
  40. @Api(tags="${tableVo.ftlDescription}")
  41. @RestController
  42. @RequestMapping("/${entityPackage}/${entityName?uncap_first}")
  43. @Slf4j
  44. public class ${entityName}Controller extends JeecgController<${entityName}, I${entityName}Service> {
  45. @Autowired
  46. private I${entityName}Service ${entityName?uncap_first}Service;
  47. /**
  48. * 分页列表查询
  49. *
  50. * @param ${entityName?uncap_first}
  51. * @param pageNo
  52. * @param pageSize
  53. * @param req
  54. * @return
  55. */
  56. @AutoLog(value = "${tableVo.ftlDescription}-分页列表查询")
  57. @ApiOperation(value="${tableVo.ftlDescription}-分页列表查询", notes="${tableVo.ftlDescription}-分页列表查询")
  58. @GetMapping(value = "/list")
  59. public Result<?> queryPageList(${entityName} ${entityName?uncap_first},
  60. @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
  61. @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
  62. HttpServletRequest req) {
  63. QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first}, req.getParameterMap());
  64. Page<${entityName}> page = new Page<${entityName}>(pageNo, pageSize);
  65. IPage<${entityName}> pageList = ${entityName?uncap_first}Service.page(page, queryWrapper);
  66. return Result.OK(pageList);
  67. }
  68. /**
  69. * 添加
  70. * @param ${entityName?uncap_first}
  71. * @return
  72. */
  73. @AutoLog(value = "${tableVo.ftlDescription}-添加")
  74. @ApiOperation(value="${tableVo.ftlDescription}-添加", notes="${tableVo.ftlDescription}-添加")
  75. @PostMapping(value = "/add")
  76. public Result<?> add(@RequestBody ${entityName} ${entityName?uncap_first}) {
  77. ${entityName?uncap_first}Service.save(${entityName?uncap_first});
  78. return Result.OK("添加成功!");
  79. }
  80. /**
  81. * 编辑
  82. *
  83. * @param ${entityName?uncap_first}
  84. * @return
  85. */
  86. @AutoLog(value = "${tableVo.ftlDescription}-编辑")
  87. @ApiOperation(value="${tableVo.ftlDescription}-编辑", notes="${tableVo.ftlDescription}-编辑")
  88. @PostMapping(value = "/edit")
  89. public Result<?> edit(@RequestBody ${entityName} ${entityName?uncap_first}) {
  90. ${entityName?uncap_first}Service.updateById(${entityName?uncap_first});
  91. return Result.OK("编辑成功!");
  92. }
  93. /**
  94. * 通过id删除
  95. * @param id
  96. * @return
  97. */
  98. @AutoLog(value = "${tableVo.ftlDescription}-通过id删除")
  99. @ApiOperation(value="${tableVo.ftlDescription}-通过id删除", notes="${tableVo.ftlDescription}-通过id删除")
  100. @PostMapping(value = "/delete")
  101. public Result<?> delete(@RequestParam(name="id",required=true) String id) {
  102. ${entityName?uncap_first}Service.removeById(id);
  103. return Result.OK("删除成功!");
  104. }
  105. /**
  106. * 批量删除
  107. *
  108. * @param ids
  109. * @return
  110. */
  111. @AutoLog(value = "${tableVo.ftlDescription}-批量删除")
  112. @ApiOperation(value="${tableVo.ftlDescription}-批量删除", notes="${tableVo.ftlDescription}-批量删除")
  113. @PostMapping(value = "/deleteBatch")
  114. public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
  115. this.${entityName?uncap_first}Service.removeByIds(Arrays.asList(ids.split(",")));
  116. return Result.OK("批量删除成功!");
  117. }
  118. /**
  119. * 通过id查询
  120. *
  121. * @param id
  122. * @return
  123. */
  124. @AutoLog(value = "${tableVo.ftlDescription}-通过id查询")
  125. @ApiOperation(value="${tableVo.ftlDescription}-通过id查询", notes="${tableVo.ftlDescription}-通过id查询")
  126. @GetMapping(value = "/queryById")
  127. public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
  128. ${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.getById(id);
  129. return Result.OK(${entityName?uncap_first});
  130. }
  131. /**
  132. * 导出excel
  133. *
  134. * @param request
  135. * @param ${entityName?uncap_first}
  136. */
  137. @RequestMapping(value = "/exportXls")
  138. public ModelAndView exportXls(HttpServletRequest request, ${entityName} ${entityName?uncap_first}) {
  139. return super.exportXls(request, ${entityName?uncap_first}, ${entityName}.class, "${tableVo.ftlDescription}");
  140. }
  141. /**
  142. * 通过excel导入数据
  143. *
  144. * @param request
  145. * @param response
  146. * @return
  147. */
  148. @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  149. public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
  150. return super.importExcel(request, response, ${entityName}.class);
  151. }
  152. }