主子Contoller.java 6.3 KB

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