主子Contoller.java 6.4 KB

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