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.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. BaseStudentScholarshipRelease baseStudentScholarshipRelease = BeanUtil.toBean(dto, BaseStudentScholarshipRelease.class);
  99. boolean isSuccess = releaseService.save(baseStudentScholarshipRelease);
  100. return RT.ok(isSuccess);
  101. }
  102. @PutMapping
  103. @ApiOperation(value = "修改奖学金发放记录表")
  104. @SaCheckPermission("basestudentscholarshiprelease:edit")
  105. public RT<Boolean> update(@Valid @RequestBody UpdateBaseStudentScholarshipReleaseDto dto) {
  106. BaseStudentScholarshipRelease baseStudentScholarshipRelease = BeanUtil.toBean(dto, BaseStudentScholarshipRelease.class);
  107. return RT.ok(releaseService.updateById(baseStudentScholarshipRelease));
  108. }
  109. @DeleteMapping
  110. @ApiOperation(value = "删除奖学金发放记录表")
  111. @SaCheckPermission("basestudentscholarshiprelease:delete")
  112. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids) {
  113. return RT.ok(releaseService.remove(ids));
  114. }
  115. @PostMapping("add-student")
  116. @ApiOperation(value = "添加学生")
  117. @SaCheckPermission("basestudentscholarshiprelease:add")
  118. public RT<Boolean> addStudent(@Valid @RequestBody AddStudentScholarshipDto dto) {
  119. if(dto.getApplicantIds() != null && !dto.getApplicantIds().isEmpty()){
  120. List<BaseStudentScholarshipApplicant> applicantList = applicantService.list(
  121. new QueryWrapper<BaseStudentScholarshipApplicant>().lambda()
  122. .in(BaseStudentScholarshipApplicant::getId, dto.getApplicantIds())
  123. );
  124. List<BaseStudentScholarshipApplicant> dataList = new ArrayList<>();
  125. List<BaseStudentScholarshipRelease> insertList = new ArrayList<>();
  126. for (BaseStudentScholarshipApplicant applicantVo : applicantList) {
  127. applicantVo.setScholarshipLevel(dto.getScholarshipLevel());
  128. applicantVo.setBaseStudentScholarshipCategoryId(dto.getBaseStudentScholarshipCategoryId());
  129. applicantVo.setReviewStatus(1);
  130. applicantVo.setAmount(dto.getTotalAmount().doubleValue());
  131. dataList.add(applicantVo);
  132. insertList.add(
  133. new BaseStudentScholarshipRelease(){{
  134. setCreateDate(new Date());
  135. setAmount(applicantVo.getAmount());
  136. setBaseStudentScholarshipApplicantId(applicantVo.getId());
  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. }