BaseStudentScholarshipReleaseController.java 8.8 KB

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