controller.java.vm 7.1 KB

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