主子Contoller.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package ${package}.${moduleName}.controller;
  2. #if($queryList)
  3. import cn.hutool.core.util.StrUtil;
  4. #end
  5. import cn.hutool.core.util.ArrayUtil;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import ${package}.common.core.util.R;
  10. import ${package}.common.log.annotation.SysLog;
  11. #if($opensource)
  12. import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
  13. #else
  14. import ${package}.common.excel.annotation.ResponseExcel;
  15. #end
  16. import ${package}.${moduleName}.entity.${ClassName}Entity;
  17. import ${package}.${moduleName}.entity.${ChildClassName}Entity;
  18. import ${package}.${moduleName}.service.${ClassName}Service;
  19. import io.swagger.v3.oas.annotations.security.SecurityRequirement;
  20. #if($isSpringBoot3)
  21. import ${package}.common.security.annotation.HasPermission;
  22. import org.springdoc.core.annotations.ParameterObject;
  23. #else
  24. import org.springframework.security.access.prepost.PreAuthorize;
  25. import org.springdoc.api.annotations.ParameterObject;
  26. #end
  27. import org.springframework.http.HttpHeaders;
  28. import io.swagger.v3.oas.annotations.tags.Tag;
  29. import io.swagger.v3.oas.annotations.Operation;
  30. import lombok.RequiredArgsConstructor;
  31. import org.springframework.web.bind.annotation.*;
  32. import java.util.List;
  33. import java.util.Objects;
  34. /**
  35. * ${tableComment}
  36. *
  37. * @author ${author}
  38. * @date ${datetime}
  39. */
  40. @RestController
  41. @RequiredArgsConstructor
  42. @RequestMapping("/${functionName}" )
  43. @Tag(description = "${functionName}" , name = "${tableComment}管理" )
  44. @SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
  45. public class ${ClassName}Controller {
  46. private final ${ClassName}Service ${className}Service;
  47. /**
  48. * 分页查询
  49. * @param page 分页对象
  50. * @param ${className} ${tableComment}
  51. * @return
  52. */
  53. @Operation(summary = "分页查询" , description = "分页查询" )
  54. @GetMapping("/page" )
  55. #if($isSpringBoot3)
  56. @HasPermission("${moduleName}_${functionName}_view")
  57. #else
  58. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
  59. #end
  60. public R get${ClassName}Page(@ParameterObject Page page, @ParameterObject ${ClassName}Entity ${className}) {
  61. LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
  62. #foreach ($field in $queryList)
  63. #set($getAttrName=$str.getProperty($field.attrName))
  64. #set($var="${className}.$getAttrName()")
  65. #if($field.attrType == 'String')
  66. #set($expression="StrUtil.isNotBlank")
  67. #else
  68. #set($expression="Objects.nonNull")
  69. #end
  70. #if($field.queryType == '=')
  71. wrapper.eq($expression($var),${ClassName}Entity::$getAttrName,$var);
  72. #elseif( $field.queryType == 'like' )
  73. wrapper.like($expression($var),${ClassName}Entity::$getAttrName,$var);
  74. #elseif( $field.queryType == '!-' )
  75. wrapper.ne($expression($var),${ClassName}Entity::$getAttrName,$var);
  76. #elseif( $field.queryType == '>' )
  77. wrapper.gt($expression($var),${ClassName}Entity::$getAttrName,$var);
  78. #elseif( $field.queryType == '<' )
  79. wrapper.lt($expression($var),${ClassName}Entity::$getAttrName,$var);
  80. #elseif( $field.queryType == '>=' )
  81. wrapper.ge($expression($var),${ClassName}Entity::$getAttrName,$var);
  82. #elseif( $field.queryType == '<=' )
  83. wrapper.le($expression($var),${ClassName}Entity::$getAttrName,$var);
  84. #elseif( $field.queryType == 'left like' )
  85. wrapper.likeLeft($expression($var),${ClassName}Entity::$getAttrName,$var);
  86. #elseif( $field.queryType == 'right like' )
  87. wrapper.likeRight($expression($var),${ClassName}Entity::$getAttrName,$var);
  88. #end
  89. #end
  90. return R.ok(${className}Service.page(page, wrapper));
  91. }
  92. /**
  93. * 通过条件查询${tableComment}
  94. * @param ${className} 查询条件
  95. * @return R 对象列表
  96. */
  97. @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
  98. @GetMapping("/details" )
  99. #if($isSpringBoot3)
  100. @HasPermission("${moduleName}_${functionName}_view")
  101. #else
  102. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
  103. #end
  104. public R getDetails(@ParameterObject ${ClassName}Entity ${className}) {
  105. return R.ok(${className}Service.listDeep(Wrappers.query(${className})));
  106. }
  107. /**
  108. * 新增${tableComment}
  109. * @param ${className} ${tableComment}
  110. * @return R
  111. */
  112. @Operation(summary = "新增${tableComment}" , description = "新增${tableComment}" )
  113. @SysLog("新增${tableComment}" )
  114. @PostMapping
  115. #if($isSpringBoot3)
  116. @HasPermission("${moduleName}_${functionName}_add")
  117. #else
  118. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_add')" )
  119. #end
  120. public R save(@RequestBody ${ClassName}Entity ${className}) {
  121. return R.ok(${className}Service.saveDeep(${className}));
  122. }
  123. /**
  124. * 修改${tableComment}
  125. * @param ${className} ${tableComment}
  126. * @return R
  127. */
  128. @Operation(summary = "修改${tableComment}" , description = "修改${tableComment}" )
  129. @SysLog("修改${tableComment}" )
  130. @PutMapping
  131. #if($isSpringBoot3)
  132. @HasPermission("${moduleName}_${functionName}_edit")
  133. #else
  134. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_edit')" )
  135. #end
  136. public R updateById(@RequestBody ${ClassName}Entity ${className}) {
  137. return R.ok(${className}Service.updateDeep(${className}));
  138. }
  139. /**
  140. * 通过id删除${tableComment}
  141. * @param ids ${pk.attrName}列表
  142. * @return R
  143. */
  144. @Operation(summary = "通过id删除${tableComment}" , description = "通过id删除${tableComment}" )
  145. @SysLog("通过id删除${tableComment}" )
  146. @DeleteMapping
  147. #if($isSpringBoot3)
  148. @HasPermission("${moduleName}_${functionName}_del")
  149. #else
  150. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )
  151. #end
  152. public R removeById(@RequestBody ${pk.attrType}[] ids) {
  153. return R.ok(${className}Service.removeDeep(ids));
  154. }
  155. /**
  156. * 通过id删除${tableComment}子表数据
  157. * @param ids ${pk.attrName}列表
  158. * @return R
  159. */
  160. @Operation(summary = "通过id删除${tableComment}子表数据" , description = "通过id删除${tableComment}子表数据" )
  161. @SysLog("通过id删除${tableComment}子表数据" )
  162. @DeleteMapping("/child")
  163. #if($isSpringBoot3)
  164. @HasPermission("${moduleName}_${functionName}_del")
  165. #else
  166. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )
  167. #end
  168. public R removeChild(@RequestBody ${pk.attrType}[] ids) {
  169. return R.ok(${className}Service.removeChild(ids));
  170. }
  171. /**
  172. * 导出excel 表格
  173. * @param ${className} 查询条件
  174. * @param ids 导出指定ID
  175. * @return excel 文件流
  176. */
  177. @ResponseExcel
  178. @GetMapping("/export")
  179. #if($isSpringBoot3)
  180. @HasPermission("${moduleName}_${functionName}_export")
  181. #else
  182. @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_export')" )
  183. #end public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {
  184. return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));
  185. }
  186. }