ProgrammeController.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.izouma.wenlvju.web.performance;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.izouma.wenlvju.domain.ArtType;
  4. import com.izouma.wenlvju.domain.performance.Programme;
  5. import com.izouma.wenlvju.dto.*;
  6. import com.izouma.wenlvju.enums.SignedIn;
  7. import com.izouma.wenlvju.exception.BusinessException;
  8. import com.izouma.wenlvju.repo.ArtTypeRepo;
  9. import com.izouma.wenlvju.repo.performance.ProgrammeRepo;
  10. import com.izouma.wenlvju.service.UserService;
  11. import com.izouma.wenlvju.service.performance.ProgrammeService;
  12. import com.izouma.wenlvju.utils.ObjUtils;
  13. import com.izouma.wenlvju.utils.SecurityUtils;
  14. import com.izouma.wenlvju.utils.excel.ExcelUtils;
  15. import com.izouma.wenlvju.web.BaseController;
  16. import io.swagger.annotations.ApiOperation;
  17. import lombok.AllArgsConstructor;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.data.domain.Page;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import javax.servlet.http.HttpServletResponse;
  23. import java.io.IOException;
  24. import java.util.List;
  25. import java.util.Map;
  26. @Slf4j
  27. @RestController
  28. @RequestMapping("/programme")
  29. @AllArgsConstructor
  30. public class ProgrammeController extends BaseController {
  31. private ProgrammeService programmeService;
  32. private ProgrammeRepo programmeRepo;
  33. private ArtTypeRepo artTypeRepo;
  34. private UserService userService;
  35. //@PreAuthorize("hasRole('ADMIN')")
  36. @PostMapping("/save")
  37. public Programme save(@RequestBody Programme record) {
  38. if (record.getId() != null) {
  39. Programme orig = programmeRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  40. ObjUtils.merge(orig, record);
  41. return programmeRepo.save(orig);
  42. }
  43. return programmeRepo.save(record);
  44. }
  45. //@PreAuthorize("hasRole('ADMIN')")
  46. @PostMapping("/all")
  47. public Page<Programme> all(@RequestBody PageQuery pageQuery) {
  48. return programmeService.all(pageQuery);
  49. }
  50. @PostMapping("/backAll")
  51. public Page<ProgrammeDTO> backAll(@RequestBody PageQuery pageQuery) {
  52. return programmeService.backAll(pageQuery);
  53. }
  54. @GetMapping("/get/{id}")
  55. public Programme get(@PathVariable Long id) {
  56. return programmeRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  57. }
  58. @PostMapping("/del/{id}")
  59. public void del(@PathVariable Long id) {
  60. programmeRepo.softDelete(id);
  61. }
  62. @GetMapping("/excel")
  63. @ResponseBody
  64. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  65. List<ProgrammeDTO> data = programmeService.toDTOList(all(pageQuery).getContent());
  66. ExcelUtils.export(response, data);
  67. }
  68. @GetMapping(value = "/excelTemp", produces = "application/vnd.ms-excel;charset=utf-8")
  69. public void excelTemp(HttpServletResponse response) throws IOException {
  70. // ExcelUtils.export1(response, ProgrammeDTO.class);
  71. programmeService.excelTemp(response);
  72. }
  73. @PostMapping("/upload")
  74. public void uploadFile(@RequestParam("file") MultipartFile file) {
  75. try {
  76. programmeService.upload(file, SecurityUtils.getAuthenticatedUser().getId());
  77. } catch (IOException e) {
  78. log.error("上传失败", e);
  79. throw new BusinessException("上传失败", e.getMessage());
  80. }
  81. }
  82. @ApiOperation("移出分组")
  83. @PostMapping("/removeGroup/{id}")
  84. public void removeGroup(@PathVariable Long id) {
  85. programmeService.removeArrange(id);
  86. }
  87. @ApiOperation("加入分组")
  88. @PostMapping("/intoGroup")
  89. public void intoGroup(@RequestParam Long id, @RequestParam Long arrangeId) {
  90. programmeService.add(id, arrangeId);
  91. }
  92. @ApiOperation("未分组")
  93. @PostMapping("/unGrouped")
  94. public List<Programme> unGrouped(@RequestParam Long performanceId) {
  95. return programmeService.ungrouped(performanceId);
  96. }
  97. @ApiOperation("签到列表")
  98. @PostMapping("/byArrange")
  99. public Page<ArrangeProgrammeDTO> byArrange(@RequestBody PageQuery pageQuery) {
  100. pageQuery.setSort("allSigned,asc;arrangeId,desc;gradingOrganizationId,asc;organizationId,asc;");
  101. // Map<String, Object> query = pageQuery.getQuery();
  102. // query.put("status", 2);
  103. return programmeService.byArrange(pageQuery);
  104. }
  105. @ApiOperation("签到")
  106. @PostMapping("/signIn")
  107. public void signIn(@RequestParam Long id, @RequestParam SignedIn signedIn, String description) {
  108. programmeService.signIn(id, signedIn, description);
  109. }
  110. @PostMapping("/byExpert")
  111. @ApiOperation("专家手机端查看")
  112. public Page<ProgrammeScoreDTO> byExpert(@RequestBody PageQuery pageQuery) {
  113. return programmeService.byExpert(pageQuery, SecurityUtils.getAuthenticatedUser().getId());
  114. }
  115. @PostMapping("/byScore")
  116. @ApiOperation("专家电脑端查看")
  117. public Page<ProgrammeScoreDTO> byScore(@RequestBody PageQuery pageQuery) {
  118. return programmeService.byScore(pageQuery, SecurityUtils.getAuthenticatedUser().getId());
  119. }
  120. @PostMapping("/getDTO/{id}")
  121. @ApiOperation("专家手机端查看详情")
  122. public ProgrammeScoreDTO getDTO(@PathVariable Long id) {
  123. return programmeService.getDTO(id, SecurityUtils.getAuthenticatedUser().getId());
  124. }
  125. @PostMapping("/firstAudit")
  126. @ApiOperation("考级机构初审")
  127. public void firstAudit(@RequestParam Long id, boolean pass) {
  128. programmeService.firstAudit(id, pass);
  129. }
  130. @GetMapping("/getShow/{id}")
  131. @ApiOperation("考级机构查看节目信息")
  132. public ProgrammeShowDTO getShow(@PathVariable Long id) {
  133. return programmeService.showByGO(id);
  134. }
  135. @ApiOperation("获取手机号/token")
  136. @PostMapping("/getAuth")
  137. public Map<String, String> getAuth(@RequestParam Long id, @RequestParam String phone) {
  138. Programme apply = programmeRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  139. return userService.getAuth(id, phone, apply.getPhone());
  140. }
  141. @GetMapping("/getScore/{id}")
  142. public Programme get(@PathVariable Long id, String phone) {
  143. Programme apply = programmeRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  144. if (ObjectUtil.isNotNull(apply.getSpecialtyId())) {
  145. ArtType artType = artTypeRepo.findById(apply.getSpecialtyId()).orElseThrow(new BusinessException("无此专业"));
  146. apply.setSpecialty(artType.getName());
  147. }
  148. userService.getAuth(id, phone, apply.getPhone());
  149. return apply;
  150. }
  151. }