controller.java.vm 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package ${packageName}.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import java.util.List;
  4. import java.util.Arrays;
  5. import com.ruoyi.common.utils.StringUtils;
  6. import lombok.RequiredArgsConstructor;
  7. import org.springframework.security.access.prepost.PreAuthorize;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.PutMapping;
  12. import org.springframework.web.bind.annotation.DeleteMapping;
  13. import org.springframework.web.bind.annotation.PathVariable;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.ruoyi.common.annotation.Log;
  18. import com.ruoyi.common.core.controller.BaseController;
  19. import com.ruoyi.common.core.domain.AjaxResult;
  20. import com.ruoyi.common.enums.BusinessType;
  21. import ${packageName}.domain.${ClassName};
  22. import ${packageName}.service.I${ClassName}Service;
  23. import com.ruoyi.common.utils.poi.ExcelUtil;
  24. #if($table.crud)
  25. import com.ruoyi.common.core.page.TableDataInfo;
  26. #elseif($table.tree)
  27. #end
  28. /**
  29. * ${functionName}Controller
  30. *
  31. * @author ${author}
  32. * @date ${datetime}
  33. */
  34. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  35. @RestController
  36. @RequestMapping("/${moduleName}/${businessName}" )
  37. public class ${ClassName}Controller extends BaseController {
  38. private final I${ClassName}Service i${ClassName}Service;
  39. /**
  40. * 查询${functionName}列表
  41. */
  42. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
  43. @GetMapping("/list")
  44. #if($table.crud)
  45. public TableDataInfo list(${ClassName} ${className})
  46. {
  47. startPage();
  48. LambdaQueryWrapper<${ClassName}> lqw = new LambdaQueryWrapper<${ClassName}>();
  49. #foreach($column in $columns)
  50. #set($queryType=$column.queryType)
  51. #set($javaField=$column.javaField)
  52. #set($javaType=$column.javaType)
  53. #set($columnName=$column.columnName)
  54. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  55. #if($column.query)
  56. #if($column.queryType == "EQ")
  57. #if($javaType == 'String')
  58. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  59. lqw.eq(${ClassName}::get$AttrName ,${className}.get$AttrName());
  60. }
  61. #else
  62. if (${className}.get$AttrName() != null){
  63. lqw.eq(${ClassName}::get$AttrName ,${className}.get$AttrName());
  64. }
  65. #end
  66. #elseif($queryType == "NE")
  67. #if($javaType == 'String')
  68. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  69. lqw.ne(${ClassName}::get$AttrName ,${className}.get$AttrName());
  70. }
  71. #else
  72. if (${className}.get$AttrName() != null){
  73. lqw.ne(${ClassName}::get$AttrName ,${className}.get$AttrName());
  74. }
  75. #end
  76. #elseif($queryType == "GT")
  77. #if($javaType == 'String')
  78. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  79. lqw.gt(${ClassName}::get$AttrName ,${className}.get$AttrName());
  80. }
  81. #else
  82. if (${className}.get$AttrName() != null){
  83. lqw.gt(${ClassName}::get$AttrName ,${className}.get$AttrName());
  84. }
  85. #end
  86. #elseif($queryType == "GTE")
  87. #if($javaType == 'String')
  88. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  89. lqw.ge(${ClassName}::get$AttrName ,${className}.get$AttrName());
  90. }
  91. #else
  92. if (${className}.get$AttrName() != null){
  93. lqw.ge(${ClassName}::get$AttrName ,${className}.get$AttrName());
  94. }
  95. #end
  96. #elseif($queryType == "LT")
  97. #if($javaType == 'String')
  98. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  99. lqw.lt(${ClassName}::get$AttrName ,${className}.get$AttrName());
  100. }
  101. #else
  102. if (${className}.get$AttrName() != null){
  103. lqw.lt(${ClassName}::get$AttrName ,${className}.get$AttrName());
  104. }
  105. #end
  106. #elseif($queryType == "LTE")
  107. #if($javaType == 'String')
  108. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  109. lqw.le(${ClassName}::get$AttrName ,${className}.get$AttrName());
  110. }
  111. #else
  112. if (${className}.get$AttrName() != null){
  113. lqw.le(${ClassName}::get$AttrName ,${className}.get$AttrName());
  114. }
  115. #end
  116. #elseif($queryType == "LIKE")
  117. #if($javaType == 'String')
  118. if (StringUtils.isNotBlank(${className}.get$AttrName())){
  119. lqw.like(${ClassName}::get$AttrName ,${className}.get$AttrName());
  120. }
  121. #else
  122. if (${className}.get$AttrName() != null){
  123. lqw.like(${ClassName}::get$AttrName ,${className}.get$AttrName());
  124. }
  125. #end
  126. #elseif($queryType == "BETWEEN")
  127. #end
  128. #end
  129. #end
  130. List<${ClassName}> list = i${ClassName}Service.list(lqw);
  131. return getDataTable(list);
  132. }
  133. #elseif($table.tree)
  134. public AjaxResult list(${ClassName} ${className}) {
  135. List<${ClassName}> list = i${ClassName}Service.list(lqw);
  136. return AjaxResult.success(list);
  137. }
  138. #end
  139. /**
  140. * 导出${functionName}列表
  141. */
  142. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')" )
  143. @Log(title = "${functionName}" , businessType = BusinessType.EXPORT)
  144. @GetMapping("/export" )
  145. public AjaxResult export(${ClassName} ${className}) {
  146. LambdaQueryWrapper<${ClassName}> lqw = new LambdaQueryWrapper<${ClassName}>(${className});
  147. List<${ClassName}> list = i${ClassName}Service.list(lqw);
  148. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}. class);
  149. return util.exportExcel(list, "${businessName}" );
  150. }
  151. /**
  152. * 获取${functionName}详细信息
  153. */
  154. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')" )
  155. @GetMapping(value = "/{${pkColumn.javaField}}" )
  156. public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}" ) ${pkColumn.javaType} ${pkColumn.javaField}) {
  157. return AjaxResult.success(i${ClassName}Service.getById(${pkColumn.javaField}));
  158. }
  159. /**
  160. * 新增${functionName}
  161. */
  162. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')" )
  163. @Log(title = "${functionName}" , businessType = BusinessType.INSERT)
  164. @PostMapping
  165. public AjaxResult add(@RequestBody ${ClassName} ${className}) {
  166. return toAjax(i${ClassName}Service.save(${className}) ? 1 : 0);
  167. }
  168. /**
  169. * 修改${functionName}
  170. */
  171. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')" )
  172. @Log(title = "${functionName}" , businessType = BusinessType.UPDATE)
  173. @PutMapping
  174. public AjaxResult edit(@RequestBody ${ClassName} ${className}) {
  175. return toAjax(i${ClassName}Service.updateById(${className}) ? 1 : 0);
  176. }
  177. /**
  178. * 删除${functionName}
  179. */
  180. @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')" )
  181. @Log(title = "${functionName}" , businessType = BusinessType.DELETE)
  182. @DeleteMapping("/{${pkColumn.javaField}s}" )
  183. public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) {
  184. return toAjax(i${ClassName}Service.removeByIds(Arrays.asList(${pkColumn.javaField}s)) ? 1 : 0);
  185. }
  186. }