BaseStudentPostController.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.xjrsoft.module.student.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import com.alibaba.excel.EasyExcel;
  6. import com.alibaba.excel.support.ExcelTypeEnum;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.metadata.IPage;
  9. import com.github.yulichang.toolkit.MPJWrappers;
  10. import com.xjrsoft.common.annotation.XjrLog;
  11. import com.xjrsoft.common.model.result.RT;
  12. import com.xjrsoft.common.page.ConventPage;
  13. import com.xjrsoft.common.page.PageOutput;
  14. import com.xjrsoft.common.utils.VoToColumnUtil;
  15. import com.xjrsoft.module.student.dto.AddBaseStudentPostDto;
  16. import com.xjrsoft.module.student.dto.BaseStudentPostListDto;
  17. import com.xjrsoft.module.student.dto.BaseStudentPostPageDto;
  18. import com.xjrsoft.module.student.dto.UpdateBaseStudentPostDto;
  19. import com.xjrsoft.module.student.entity.BaseStudentPost;
  20. import com.xjrsoft.module.student.service.IBaseStudentPostService;
  21. import com.xjrsoft.module.student.vo.BaseStudentPostListVo;
  22. import com.xjrsoft.module.student.vo.BaseStudentPostPageVo;
  23. import com.xjrsoft.module.student.vo.BaseStudentPostVo;
  24. import com.xjrsoft.module.system.entity.DictionaryDetail;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import lombok.AllArgsConstructor;
  28. import org.springframework.http.ResponseEntity;
  29. import org.springframework.web.bind.annotation.*;
  30. import javax.validation.Valid;
  31. import java.io.ByteArrayOutputStream;
  32. import java.util.ArrayList;
  33. import java.util.List;
  34. /**
  35. * @title: 学生职务设置
  36. * @Author dzx
  37. * @Date: 2023-11-13
  38. * @Version 1.0
  39. */
  40. @RestController
  41. @RequestMapping("/student" + "/basestudentpost")
  42. @Api(value = "/student" + "/basestudentpost", tags = "学生职务设置代码")
  43. @AllArgsConstructor
  44. public class BaseStudentPostController {
  45. private final IBaseStudentPostService baseStudentPostService;
  46. @GetMapping(value = "/list")
  47. @ApiOperation(value = "学生职务设置列表(不分页)")
  48. @SaCheckPermission("basestudentpost:list")
  49. @XjrLog(value = "学生职务设置列表(不分页)")
  50. public RT<List<BaseStudentPostListVo>> list(@Valid BaseStudentPostListDto dto) {
  51. LambdaQueryWrapper<BaseStudentPost> queryWrapper = new LambdaQueryWrapper<>();
  52. queryWrapper
  53. .select(BaseStudentPost::getId)
  54. .eq(ObjectUtil.isNotNull(dto.getLevel()), BaseStudentPost::getLevel, dto.getLevel())
  55. .eq(BaseStudentPost::getStatus, 1)
  56. .orderByDesc(BaseStudentPost::getId)
  57. .select(BaseStudentPost.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentPostListVo.class).contains(x.getProperty()));
  58. List<BaseStudentPost> list = baseStudentPostService.list(queryWrapper);
  59. List<BaseStudentPostListVo> listVos = BeanUtil.copyToList(list, BaseStudentPostListVo.class);
  60. return RT.ok(listVos);
  61. }
  62. @GetMapping(value = "/page")
  63. @ApiOperation(value = "学生职务设置列表(分页)")
  64. @SaCheckPermission("basestudentpost:page")
  65. @XjrLog(value = "学生职务设置列表(分页)")
  66. public RT<PageOutput<BaseStudentPostPageVo>> page(@Valid BaseStudentPostPageDto dto) {
  67. IPage<BaseStudentPostPageVo> page = baseStudentPostService.selectJoinListPage(ConventPage.getPage(dto), BaseStudentPostPageVo.class,
  68. MPJWrappers.<BaseStudentPost>lambdaJoin()
  69. .orderByAsc(BaseStudentPost::getSortCode)
  70. .selectAs(DictionaryDetail::getName, BaseStudentPostPageVo::getLevelCn)
  71. .select(BaseStudentPost.class, x -> VoToColumnUtil.fieldsToColumns(BaseStudentPostPageVo.class).contains(x.getProperty()))
  72. .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, BaseStudentPost::getLevel)
  73. .select(BaseStudentPost::getId)
  74. .eq(ObjectUtil.isNotNull(dto.getLevel()), BaseStudentPost::getLevel, dto.getLevel())
  75. );
  76. PageOutput<BaseStudentPostPageVo> pageOutput = ConventPage.getPageOutput(page, BaseStudentPostPageVo.class);
  77. return RT.ok(pageOutput);
  78. }
  79. @GetMapping(value = "/info")
  80. @ApiOperation(value = "根据id查询学生职务设置信息")
  81. @SaCheckPermission("basestudentpost:info")
  82. @XjrLog(value = "根据id查询学生职务设置信息", saveResponseData = true)
  83. public RT<BaseStudentPostVo> info(@RequestParam Long id) {
  84. BaseStudentPost baseStudentPost = baseStudentPostService.getById(id);
  85. if (baseStudentPost == null) {
  86. return RT.error("找不到此数据!");
  87. }
  88. return RT.ok(BeanUtil.toBean(baseStudentPost, BaseStudentPostVo.class));
  89. }
  90. @PostMapping
  91. @ApiOperation(value = "新增学生职务设置")
  92. @SaCheckPermission("basestudentpost:add")
  93. @XjrLog(value = "新增学生职务设置", saveResponseData = true)
  94. public RT<Boolean> add(@Valid @RequestBody AddBaseStudentPostDto dto) {
  95. BaseStudentPost baseStudentPost = BeanUtil.toBean(dto, BaseStudentPost.class);
  96. boolean isSuccess = baseStudentPostService.save(baseStudentPost);
  97. return RT.ok(isSuccess);
  98. }
  99. @PutMapping
  100. @ApiOperation(value = "修改学生职务设置")
  101. @SaCheckPermission("basestudentpost:edit")
  102. @XjrLog(value = "修改学生职务设置", saveResponseData = true)
  103. public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentPostDto dto) {
  104. BaseStudentPost baseStudentPost = BeanUtil.toBean(dto, BaseStudentPost.class);
  105. return RT.ok(baseStudentPostService.updateById(baseStudentPost));
  106. }
  107. @DeleteMapping
  108. @ApiOperation(value = "删除学生职务设置")
  109. @SaCheckPermission("basestudentpost:delete")
  110. @XjrLog(value = "删除学生职务设置", saveResponseData = true)
  111. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids) {
  112. return RT.ok(baseStudentPostService.deleteLogicallyBatchByIds(ids));
  113. }
  114. @GetMapping("/export")
  115. @ApiOperation(value = "导出")
  116. @SaCheckPermission("basestudentpost:export")
  117. @XjrLog(value = "导出")
  118. public ResponseEntity<byte[]> exportData(@Valid BaseStudentPostPageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
  119. List<BaseStudentPostPageVo> customerList = isTemplate != null && isTemplate ? new ArrayList<>() : page(dto).getData().getList();
  120. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  121. EasyExcel.write(bot, BaseStudentPostPageVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(customerList);
  122. return RT.fileStream(bot.toByteArray(), "BaseStudentPost" + ExcelTypeEnum.XLSX.getValue());
  123. }
  124. }