0b49e0a376abe47f4bca80f2a8718173f2d58863.svn-base 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package ${bussiPackage}.${entityPackage}.controller;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.stream.Collectors;
  6. import java.io.IOException;
  7. import java.io.UnsupportedEncodingException;
  8. import java.net.URLDecoder;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.jeecg.common.api.vo.Result;
  12. import org.jeecg.common.system.query.QueryGenerator;
  13. import org.jeecg.common.util.oConvertUtils;
  14. import ${bussiPackage}.${entityPackage}.entity.${entityName};
  15. import ${bussiPackage}.${entityPackage}.service.I${entityName}Service;
  16. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  17. import com.baomidou.mybatisplus.core.metadata.IPage;
  18. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.jeecgframework.poi.excel.ExcelImportUtil;
  21. import org.jeecgframework.poi.excel.def.NormalExcelConstants;
  22. import org.jeecgframework.poi.excel.entity.ExportParams;
  23. import org.jeecgframework.poi.excel.entity.ImportParams;
  24. import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
  25. import org.jeecg.common.system.base.controller.JeecgController;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import org.springframework.web.multipart.MultipartHttpServletRequest;
  30. import org.springframework.web.servlet.ModelAndView;
  31. import com.alibaba.fastjson.JSON;
  32. import io.swagger.annotations.Api;
  33. import io.swagger.annotations.ApiOperation;
  34. import org.jeecg.common.aspect.annotation.AutoLog;
  35. /**
  36. * @Description: ${tableVo.ftlDescription}
  37. * @Author: jeecg-boot
  38. * @Date: ${.now?string["yyyy-MM-dd"]}
  39. * @Version: V1.0
  40. */
  41. <#assign pidFieldName = "">
  42. <#list originalColumns as po>
  43. <#if po.fieldDbName == tableVo.extendParams.pidField>
  44. <#assign pidFieldName = po.fieldName>
  45. </#if>
  46. </#list>
  47. @Api(tags="${tableVo.ftlDescription}")
  48. @RestController
  49. @RequestMapping("/${entityPackage}/${entityName?uncap_first}")
  50. @Slf4j
  51. public class ${entityName}Controller extends JeecgController<${entityName}, I${entityName}Service>{
  52. @Autowired
  53. private I${entityName}Service ${entityName?uncap_first}Service;
  54. /**
  55. * 分页列表查询
  56. *
  57. * @param ${entityName?uncap_first}
  58. * @param pageNo
  59. * @param pageSize
  60. * @param req
  61. * @return
  62. */
  63. @AutoLog(value = "${tableVo.ftlDescription}-分页列表查询")
  64. @ApiOperation(value="${tableVo.ftlDescription}-分页列表查询", notes="${tableVo.ftlDescription}-分页列表查询")
  65. @GetMapping(value = "/rootList")
  66. public Result<?> queryPageList(${entityName} ${entityName?uncap_first},
  67. @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
  68. @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
  69. HttpServletRequest req) {
  70. String hasQuery = req.getParameter("hasQuery");
  71. if(hasQuery != null && "true".equals(hasQuery)){
  72. QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first}, req.getParameterMap());
  73. List<${entityName}> list = ${entityName?uncap_first}Service.queryTreeListNoPage(queryWrapper);
  74. IPage<${entityName}> pageList = new Page<>(1, 10, list.size());
  75. pageList.setRecords(list);
  76. return Result.OK(pageList);
  77. }else{
  78. String parentId = ${entityName?uncap_first}.get${pidFieldName?cap_first}();
  79. if (oConvertUtils.isEmpty(parentId)) {
  80. parentId = "0";
  81. }
  82. ${entityName?uncap_first}.set${pidFieldName?cap_first}(null);
  83. QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first}, req.getParameterMap());
  84. // 使用 eq 防止模糊查询
  85. queryWrapper.eq("${Format.humpToUnderline(pidFieldName)}", parentId);
  86. Page<${entityName}> page = new Page<${entityName}>(pageNo, pageSize);
  87. IPage<${entityName}> pageList = ${entityName?uncap_first}Service.page(page, queryWrapper);
  88. return Result.OK(pageList);
  89. }
  90. }
  91. /**
  92. * 获取子数据
  93. * @param ${entityName?uncap_first}
  94. * @param req
  95. * @return
  96. */
  97. @AutoLog(value = "${tableVo.ftlDescription}-获取子数据")
  98. @ApiOperation(value="${tableVo.ftlDescription}-获取子数据", notes="${tableVo.ftlDescription}-获取子数据")
  99. @GetMapping(value = "/childList")
  100. public Result<?> queryPageList(${entityName} ${entityName?uncap_first},HttpServletRequest req) {
  101. QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first}, req.getParameterMap());
  102. List<${entityName}> list = ${entityName?uncap_first}Service.list(queryWrapper);
  103. IPage<${entityName}> pageList = new Page<>(1, 10, list.size());
  104. pageList.setRecords(list);
  105. return Result.OK(pageList);
  106. }
  107. /**
  108. * 批量查询子节点
  109. * @param parentIds 父ID(多个采用半角逗号分割)
  110. * @return 返回 IPage
  111. * @param parentIds
  112. * @return
  113. */
  114. @AutoLog(value = "${tableVo.ftlDescription}-批量获取子数据")
  115. @ApiOperation(value="${tableVo.ftlDescription}-批量获取子数据", notes="${tableVo.ftlDescription}-批量获取子数据")
  116. @GetMapping("/getChildListBatch")
  117. public Result getChildListBatch(@RequestParam("parentIds") String parentIds) {
  118. try {
  119. QueryWrapper<${entityName}> queryWrapper = new QueryWrapper<>();
  120. List<String> parentIdList = Arrays.asList(parentIds.split(","));
  121. queryWrapper.in("${Format.humpToUnderline(pidFieldName)}", parentIdList);
  122. List<${entityName}> list = ${entityName?uncap_first}Service.list(queryWrapper);
  123. IPage<${entityName}> pageList = new Page<>(1, 10, list.size());
  124. pageList.setRecords(list);
  125. return Result.OK(pageList);
  126. } catch (Exception e) {
  127. log.error(e.getMessage(), e);
  128. return Result.error("批量查询子节点失败:" + e.getMessage());
  129. }
  130. }
  131. /**
  132. * 添加
  133. *
  134. * @param ${entityName?uncap_first}
  135. * @return
  136. */
  137. @AutoLog(value = "${tableVo.ftlDescription}-添加")
  138. @ApiOperation(value="${tableVo.ftlDescription}-添加", notes="${tableVo.ftlDescription}-添加")
  139. @PostMapping(value = "/add")
  140. public Result<?> add(@RequestBody ${entityName} ${entityName?uncap_first}) {
  141. ${entityName?uncap_first}Service.add${entityName}(${entityName?uncap_first});
  142. return Result.OK("添加成功!");
  143. }
  144. /**
  145. * 编辑
  146. *
  147. * @param ${entityName?uncap_first}
  148. * @return
  149. */
  150. @AutoLog(value = "${tableVo.ftlDescription}-编辑")
  151. @ApiOperation(value="${tableVo.ftlDescription}-编辑", notes="${tableVo.ftlDescription}-编辑")
  152. @PostMapping(value = "/edit")
  153. public Result<?> edit(@RequestBody ${entityName} ${entityName?uncap_first}) {
  154. ${entityName?uncap_first}Service.update${entityName}(${entityName?uncap_first});
  155. return Result.OK("编辑成功!");
  156. }
  157. /**
  158. * 通过id删除
  159. *
  160. * @param id
  161. * @return
  162. */
  163. @AutoLog(value = "${tableVo.ftlDescription}-通过id删除")
  164. @ApiOperation(value="${tableVo.ftlDescription}-通过id删除", notes="${tableVo.ftlDescription}-通过id删除")
  165. @PostMapping(value = "/delete")
  166. public Result<?> delete(@RequestParam(name="id",required=true) String id) {
  167. ${entityName?uncap_first}Service.delete${entityName}(id);
  168. return Result.OK("删除成功!");
  169. }
  170. /**
  171. * 批量删除
  172. *
  173. * @param ids
  174. * @return
  175. */
  176. @AutoLog(value = "${tableVo.ftlDescription}-批量删除")
  177. @ApiOperation(value="${tableVo.ftlDescription}-批量删除", notes="${tableVo.ftlDescription}-批量删除")
  178. @PostMapping(value = "/deleteBatch")
  179. public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
  180. this.${entityName?uncap_first}Service.removeByIds(Arrays.asList(ids.split(",")));
  181. return Result.OK("批量删除成功!");
  182. }
  183. /**
  184. * 通过id查询
  185. *
  186. * @param id
  187. * @return
  188. */
  189. @AutoLog(value = "${tableVo.ftlDescription}-通过id查询")
  190. @ApiOperation(value="${tableVo.ftlDescription}-通过id查询", notes="${tableVo.ftlDescription}-通过id查询")
  191. @GetMapping(value = "/queryById")
  192. public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
  193. ${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.getById(id);
  194. if(${entityName?uncap_first}==null) {
  195. return Result.error("未找到对应数据");
  196. }
  197. return Result.OK(${entityName?uncap_first});
  198. }
  199. /**
  200. * 导出excel
  201. *
  202. * @param request
  203. * @param ${entityName?uncap_first}
  204. */
  205. @RequestMapping(value = "/exportXls")
  206. public ModelAndView exportXls(HttpServletRequest request, ${entityName} ${entityName?uncap_first}) {
  207. return super.exportXls(request, ${entityName?uncap_first}, ${entityName}.class, "${tableVo.ftlDescription}");
  208. }
  209. /**
  210. * 通过excel导入数据
  211. *
  212. * @param request
  213. * @param response
  214. * @return
  215. */
  216. @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  217. public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
  218. return super.importExcel(request, response, ${entityName}.class);
  219. }
  220. }