主子Contoller 6.2 KB

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