主子Contoller.java 7.2 KB

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