BaseStudentScholarshipReleaseController.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package com.xjrsoft.module.student.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  8. import com.xjrsoft.common.model.result.RT;
  9. import com.xjrsoft.common.page.ConventPage;
  10. import com.xjrsoft.common.page.PageOutput;
  11. import com.xjrsoft.common.utils.VoToColumnUtil;
  12. import com.xjrsoft.module.organization.service.IUserService;
  13. import com.xjrsoft.module.student.dto.AddBaseStudentScholarshipReleaseDto;
  14. import com.xjrsoft.module.student.dto.AddStudentScholarshipDto;
  15. import com.xjrsoft.module.student.dto.BaseStudentScholarshipReleasePageDto;
  16. import com.xjrsoft.module.student.dto.UpdateBaseStudentScholarshipReleaseDto;
  17. import com.xjrsoft.module.student.entity.BaseStudentScholarshipApplicant;
  18. import com.xjrsoft.module.student.entity.BaseStudentScholarshipRelease;
  19. import com.xjrsoft.module.student.service.IBaseStudentScholarshipApplicantService;
  20. import com.xjrsoft.module.student.service.IBaseStudentScholarshipReleaseService;
  21. import com.xjrsoft.module.student.vo.BaseStudentScholarshipReleasePageVo;
  22. import com.xjrsoft.module.student.vo.BaseStudentScholarshipReleaseRecordVo;
  23. import com.xjrsoft.module.student.vo.BaseStudentScholarshipReleaseVo;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiOperation;
  26. import lombok.AllArgsConstructor;
  27. import org.springframework.web.bind.annotation.DeleteMapping;
  28. import org.springframework.web.bind.annotation.GetMapping;
  29. import org.springframework.web.bind.annotation.PostMapping;
  30. import org.springframework.web.bind.annotation.PutMapping;
  31. import org.springframework.web.bind.annotation.RequestBody;
  32. import org.springframework.web.bind.annotation.RequestMapping;
  33. import org.springframework.web.bind.annotation.RequestParam;
  34. import org.springframework.web.bind.annotation.RestController;
  35. import org.springframework.web.multipart.MultipartFile;
  36. import javax.validation.Valid;
  37. import java.io.IOException;
  38. import java.util.ArrayList;
  39. import java.util.Date;
  40. import java.util.List;
  41. import java.util.Map;
  42. /**
  43. * @title: 奖学金发放记录表
  44. * @Author dzx
  45. * @Date: 2024-07-25
  46. * @Version 1.0
  47. */
  48. @RestController
  49. @RequestMapping("/student" + "/baseStudentScholarshipRelease")
  50. @Api(value = "/student" + "/baseStudentScholarshipRelease",tags = "奖学金发放记录表代码")
  51. @AllArgsConstructor
  52. public class BaseStudentScholarshipReleaseController {
  53. private final IBaseStudentScholarshipApplicantService applicantService;
  54. private final IBaseStudentScholarshipReleaseService releaseService;
  55. private final IUserService userService;
  56. @GetMapping(value = "/page")
  57. @ApiOperation(value = "奖学金发放记录表列表(分页)")
  58. @SaCheckPermission("basestudentscholarshiprelease:detail")
  59. public RT<PageOutput<BaseStudentScholarshipReleasePageVo>> page(@Valid BaseStudentScholarshipReleasePageDto dto) {
  60. Page<BaseStudentScholarshipReleasePageVo> page = releaseService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
  61. PageOutput<BaseStudentScholarshipReleasePageVo> pageOutput = ConventPage.getPageOutput(page, BaseStudentScholarshipReleasePageVo.class);
  62. return RT.ok(pageOutput);
  63. }
  64. @GetMapping(value = "/record")
  65. @ApiOperation(value = "奖学金发放记录表列表(分页)")
  66. @SaCheckPermission("basestudentscholarshiprelease:detail")
  67. public RT<PageOutput<BaseStudentScholarshipReleaseRecordVo>> record(@Valid BaseStudentScholarshipReleasePageDto dto) {
  68. IPage<BaseStudentScholarshipReleaseRecordVo> page = releaseService.selectJoinListPage(ConventPage.getPage(dto), BaseStudentScholarshipReleaseRecordVo.class,
  69. new MPJLambdaWrapper<BaseStudentScholarshipRelease>()
  70. .select(BaseStudentScholarshipRelease::getId)
  71. .select(BaseStudentScholarshipRelease.class,x -> VoToColumnUtil.fieldsToColumns(BaseStudentScholarshipRelease.class).contains(x.getProperty()))
  72. .eq(BaseStudentScholarshipRelease::getBaseStudentScholarshipApplicantId, dto.getApplicantId())
  73. );
  74. PageOutput<BaseStudentScholarshipReleaseRecordVo> pageOutput = ConventPage.getPageOutput(page, BaseStudentScholarshipReleaseRecordVo.class);
  75. return RT.ok(pageOutput);
  76. }
  77. @GetMapping(value = "/info")
  78. @ApiOperation(value = "根据申请id查询奖学金发放记录表信息")
  79. @SaCheckPermission("basestudentscholarshiprelease:detail")
  80. public RT<BaseStudentScholarshipReleaseVo> info(@RequestParam Long id) {
  81. BaseStudentScholarshipApplicant applicant = applicantService.getById(id);
  82. if (applicant == null) {
  83. return RT.error("找不到此数据!");
  84. }
  85. List<BaseStudentScholarshipRelease> list = releaseService.list(
  86. new QueryWrapper<BaseStudentScholarshipRelease>().lambda()
  87. .eq(BaseStudentScholarshipRelease::getBaseStudentScholarshipApplicantId, id)
  88. );
  89. double sum = list.stream().filter(value -> value.getAmount() != null).mapToDouble(value -> value.getAmount()).sum();
  90. BaseStudentScholarshipReleaseVo releaseVo = new BaseStudentScholarshipReleaseVo();
  91. releaseVo.setScholarshipApplicantId(applicant.getBaseStudentScholarshipCategoryId());
  92. releaseVo.setTotalAmount(applicant.getAmount());
  93. releaseVo.setReleaseAmount(sum);
  94. return RT.ok(releaseVo);
  95. }
  96. @PostMapping
  97. @ApiOperation(value = "新增奖学金发放记录表")
  98. @SaCheckPermission("basestudentscholarshiprelease:add")
  99. public RT<Boolean> add(@Valid @RequestBody AddBaseStudentScholarshipReleaseDto dto) {
  100. BaseStudentScholarshipRelease baseStudentScholarshipRelease = BeanUtil.toBean(dto, BaseStudentScholarshipRelease.class);
  101. boolean isSuccess = releaseService.save(baseStudentScholarshipRelease);
  102. return RT.ok(isSuccess);
  103. }
  104. @PutMapping
  105. @ApiOperation(value = "修改奖学金发放记录表")
  106. @SaCheckPermission("basestudentscholarshiprelease:edit")
  107. public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentScholarshipReleaseDto dto) {
  108. BaseStudentScholarshipRelease baseStudentScholarshipRelease = BeanUtil.toBean(dto, BaseStudentScholarshipRelease.class);
  109. return RT.ok(releaseService.updateById(baseStudentScholarshipRelease));
  110. }
  111. @DeleteMapping
  112. @ApiOperation(value = "删除奖学金发放记录表")
  113. @SaCheckPermission("basestudentscholarshiprelease:delete")
  114. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids) {
  115. return RT.ok(releaseService.removeBatchByIds(ids));
  116. }
  117. @PostMapping("add-student")
  118. @ApiOperation(value = "添加学生")
  119. @SaCheckPermission("basestudentscholarshiprelease:add")
  120. public RT<Boolean> addStudent(@Valid @RequestBody AddStudentScholarshipDto dto) {
  121. if(dto.getApplicantIds() != null && !dto.getApplicantIds().isEmpty()){
  122. List<BaseStudentScholarshipApplicant> applicantList = applicantService.list(
  123. new QueryWrapper<BaseStudentScholarshipApplicant>().lambda()
  124. .in(BaseStudentScholarshipApplicant::getId, dto.getApplicantIds())
  125. );
  126. List<BaseStudentScholarshipApplicant> dataList = new ArrayList<>();
  127. List<BaseStudentScholarshipRelease> insertList = new ArrayList<>();
  128. for (BaseStudentScholarshipApplicant applicantVo : applicantList) {
  129. applicantVo.setScholarshipLevel(dto.getScholarshipLevel());
  130. applicantVo.setBaseStudentScholarshipCategoryId(dto.getBaseStudentScholarshipCategoryId());
  131. dataList.add(applicantVo);
  132. insertList.add(
  133. new BaseStudentScholarshipRelease(){{
  134. setAmount(applicantVo.getAmount());
  135. setBaseStudentScholarshipApplicantId(applicantVo.getId());
  136. setReleaseDate(new Date());
  137. }}
  138. );
  139. }
  140. if(!dataList.isEmpty()){
  141. applicantService.updateBatchById(dataList);
  142. }
  143. if(!insertList.isEmpty()){
  144. releaseService.saveBatch(insertList);
  145. }
  146. }
  147. return RT.ok(true);
  148. }
  149. @PostMapping("/import")
  150. @ApiOperation(value = "成绩导入")
  151. public RT<List<Map<String, String>>> scoreImport(@RequestParam MultipartFile file) throws IOException {
  152. List<Map<String, String>> maps = applicantService.importData(file);
  153. return RT.ok(maps);
  154. }
  155. }