package com.izouma.wenlvju.web.performance; import cn.hutool.core.util.ObjectUtil; import com.izouma.wenlvju.domain.ArtType; import com.izouma.wenlvju.domain.performance.Programme; import com.izouma.wenlvju.dto.*; import com.izouma.wenlvju.enums.SignedIn; import com.izouma.wenlvju.exception.BusinessException; import com.izouma.wenlvju.repo.ArtTypeRepo; import com.izouma.wenlvju.repo.performance.ProgrammeRepo; import com.izouma.wenlvju.service.UserService; import com.izouma.wenlvju.service.performance.ProgrammeService; import com.izouma.wenlvju.utils.ObjUtils; import com.izouma.wenlvju.utils.SecurityUtils; import com.izouma.wenlvju.utils.excel.ExcelUtils; import com.izouma.wenlvju.web.BaseController; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; import java.util.Map; @Slf4j @RestController @RequestMapping("/programme") @AllArgsConstructor public class ProgrammeController extends BaseController { private ProgrammeService programmeService; private ProgrammeRepo programmeRepo; private ArtTypeRepo artTypeRepo; private UserService userService; //@PreAuthorize("hasRole('ADMIN')") @PostMapping("/save") public Programme save(@RequestBody Programme record) { if (record.getId() != null) { Programme orig = programmeRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录")); ObjUtils.merge(orig, record); return programmeRepo.save(orig); } return programmeRepo.save(record); } //@PreAuthorize("hasRole('ADMIN')") @PostMapping("/all") public Page all(@RequestBody PageQuery pageQuery) { return programmeService.all(pageQuery); } @PostMapping("/backAll") public Page backAll(@RequestBody PageQuery pageQuery) { return programmeService.backAll(pageQuery); } @GetMapping("/get/{id}") public Programme get(@PathVariable Long id) { return programmeRepo.findById(id).orElseThrow(new BusinessException("无记录")); } @PostMapping("/del/{id}") public void del(@PathVariable Long id) { programmeRepo.softDelete(id); } @GetMapping("/excel") @ResponseBody public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException { List data = programmeService.toDTOList(all(pageQuery).getContent()); ExcelUtils.export(response, data); } @GetMapping(value = "/excelTemp", produces = "application/vnd.ms-excel;charset=utf-8") public void excelTemp(HttpServletResponse response) throws IOException { // ExcelUtils.export1(response, ProgrammeDTO.class); programmeService.excelTemp(response); } @PostMapping("/upload") public void uploadFile(@RequestParam("file") MultipartFile file) { try { programmeService.upload(file, SecurityUtils.getAuthenticatedUser().getId()); } catch (IOException e) { log.error("上传失败", e); throw new BusinessException("上传失败", e.getMessage()); } } @ApiOperation("移出分组") @PostMapping("/removeGroup/{id}") public void removeGroup(@PathVariable Long id) { programmeService.removeArrange(id); } @ApiOperation("加入分组") @PostMapping("/intoGroup") public void intoGroup(@RequestParam Long id, @RequestParam Long arrangeId) { programmeService.add(id, arrangeId); } @ApiOperation("未分组") @PostMapping("/unGrouped") public List unGrouped(@RequestParam Long performanceId) { return programmeService.ungrouped(performanceId); } @ApiOperation("签到列表") @PostMapping("/byArrange") public Page byArrange(@RequestBody PageQuery pageQuery) { pageQuery.setSort("allSigned,asc;arrangeId,desc;gradingOrganizationId,asc;organizationId,asc;"); // Map query = pageQuery.getQuery(); // query.put("status", 2); return programmeService.byArrange(pageQuery); } @ApiOperation("签到") @PostMapping("/signIn") public void signIn(@RequestParam Long id, @RequestParam SignedIn signedIn, String description) { programmeService.signIn(id, signedIn, description); } @PostMapping("/byExpert") @ApiOperation("专家手机端查看") public Page byExpert(@RequestBody PageQuery pageQuery) { return programmeService.byExpert(pageQuery, SecurityUtils.getAuthenticatedUser().getId()); } @PostMapping("/byScore") @ApiOperation("专家电脑端查看") public Page byScore(@RequestBody PageQuery pageQuery) { return programmeService.byScore(pageQuery, SecurityUtils.getAuthenticatedUser().getId()); } @PostMapping("/getDTO/{id}") @ApiOperation("专家手机端查看详情") public ProgrammeScoreDTO getDTO(@PathVariable Long id) { return programmeService.getDTO(id, SecurityUtils.getAuthenticatedUser().getId()); } @PostMapping("/firstAudit") @ApiOperation("考级机构初审") public void firstAudit(@RequestParam Long id, boolean pass) { programmeService.firstAudit(id, pass); } @GetMapping("/getShow/{id}") @ApiOperation("考级机构查看节目信息") public ProgrammeShowDTO getShow(@PathVariable Long id) { return programmeService.showByGO(id); } @ApiOperation("获取手机号/token") @PostMapping("/getAuth") public Map getAuth(@RequestParam Long id, @RequestParam String phone) { Programme apply = programmeRepo.findById(id).orElseThrow(new BusinessException("无记录")); return userService.getAuth(id, phone, apply.getPhone()); } @GetMapping("/getScore/{id}") public Programme get(@PathVariable Long id, String phone) { Programme apply = programmeRepo.findById(id).orElseThrow(new BusinessException("无记录")); if (ObjectUtil.isNotNull(apply.getSpecialtyId())) { ArtType artType = artTypeRepo.findById(apply.getSpecialtyId()).orElseThrow(new BusinessException("无此专业")); apply.setSpecialty(artType.getName()); } userService.getAuth(id, phone, apply.getPhone()); return apply; } }