| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package com.izouma.wenlvju.web.performance;
- import com.izouma.wenlvju.domain.performance.Programme;
- import com.izouma.wenlvju.dto.ArrangeProgrammeDTO;
- import com.izouma.wenlvju.dto.PageQuery;
- import com.izouma.wenlvju.dto.ProgrammeDTO;
- import com.izouma.wenlvju.dto.ProgrammeScoreDTO;
- import com.izouma.wenlvju.enums.SignedIn;
- import com.izouma.wenlvju.exception.BusinessException;
- import com.izouma.wenlvju.repo.performance.ProgrammeRepo;
- 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.io.InputStream;
- import java.util.List;
- import java.util.Map;
- @Slf4j
- @RestController
- @RequestMapping("/programme")
- @AllArgsConstructor
- public class ProgrammeController extends BaseController {
- private ProgrammeService programmeService;
- private ProgrammeRepo programmeRepo;
- //@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<Programme> all(@RequestBody PageQuery pageQuery) {
- return programmeService.all(pageQuery);
- }
- @PostMapping("/backAll")
- public Page<ProgrammeDTO> 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<ProgrammeDTO> data = programmeService.toDTOList(all(pageQuery).getContent());
- ExcelUtils.export(response, data);
- }
- @PostMapping("/upload")
- public void uploadFile(@RequestParam("file") MultipartFile file) {
- InputStream is;
- try {
- is = file.getInputStream();
- programmeService.upload(is, 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<Programme> unGrouped(@RequestParam Long performanceId) {
- return programmeService.ungrouped(performanceId);
- }
- @ApiOperation("签到列表")
- @PostMapping("/byArrange")
- public Page<ArrangeProgrammeDTO> byArrange(@RequestBody PageQuery pageQuery) {
- pageQuery.setSort("allSigned,asc;arrangeId,desc;gradingOrganizationId,asc;organizationId,asc;");
- // Map<String, Object> 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<ProgrammeScoreDTO> byExpert(@RequestBody PageQuery pageQuery) {
- return programmeService.byExpert(pageQuery, SecurityUtils.getAuthenticatedUser().getId());
- }
- @PostMapping("/byScore")
- @ApiOperation("专家电脑端查看")
- public Page<ProgrammeScoreDTO> 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());
- }
- }
|