Просмотр исходного кода

Merge branch 'Regulation' of http://git.izouma.com/licailing/wenlvju into Regulation

xuqiang 4 лет назад
Родитель
Сommit
746546adfe

+ 10 - 0
src/main/java/com/izouma/wenlvju/domain/performance/Participant.java

@@ -2,6 +2,7 @@ package com.izouma.wenlvju.domain.performance;
 
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.izouma.wenlvju.domain.BaseEntity;
+import com.izouma.wenlvju.dto.ProgUploadDTO;
 import com.izouma.wenlvju.dto.ProgrammeDTO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -52,4 +53,13 @@ public class Participant extends BaseEntity {
         this.certificate = dto.getCertificate();
         this.phone = dto.getParticipantPhone();
     }
+
+    public Participant(ProgUploadDTO dto) {
+        this.name = dto.getParticipantName();
+        this.sex = dto.getParticipantSex();
+        this.img = dto.getImg();
+        this.idNo = dto.getIdNo();
+        this.certificate = dto.getCertificate();
+        this.phone = dto.getParticipantPhone();
+    }
 }

+ 11 - 0
src/main/java/com/izouma/wenlvju/domain/performance/Programme.java

@@ -6,6 +6,7 @@ import com.izouma.wenlvju.annotations.SearchableOne;
 import com.izouma.wenlvju.converter.VideoObjectConverter;
 import com.izouma.wenlvju.domain.BaseEntity;
 import com.izouma.wenlvju.domain.VideoObject;
+import com.izouma.wenlvju.dto.ProgUploadDTO;
 import com.izouma.wenlvju.dto.ProgrammeDTO;
 import com.izouma.wenlvju.enums.SignedIn;
 import com.izouma.wenlvju.enums.CompetitionGroup;
@@ -54,6 +55,9 @@ public class Programme extends BaseEntity {
     @ApiModelProperty(value = "指导老师")
     private String instructor;
 
+    @ApiModelProperty(value = "指导老师电话")
+    private String instructorPhone;
+
     @ApiModelProperty(value = "联系人")
     private String contact;
 
@@ -74,6 +78,10 @@ public class Programme extends BaseEntity {
     @ApiModelProperty(value = "节目视频")
     private VideoObject video;
 
+    @Column(columnDefinition = "TEXT")
+    @ApiModelProperty(value = "节目文件附件")
+    private String annex;
+
     @ApiModelProperty(value = "分组id")
     private Long arrangeId;
 
@@ -121,4 +129,7 @@ public class Programme extends BaseEntity {
         BeanUtil.copyProperties(dto, this);
     }
 
+    public Programme(ProgUploadDTO dto) {
+        BeanUtil.copyProperties(dto, this);
+    }
 }

+ 98 - 0
src/main/java/com/izouma/wenlvju/dto/ProgUploadDTO.java

@@ -0,0 +1,98 @@
+package com.izouma.wenlvju.dto;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.izouma.wenlvju.annotations.EnumFormat;
+import com.izouma.wenlvju.domain.performance.Participant;
+import com.izouma.wenlvju.domain.performance.Programme;
+import com.izouma.wenlvju.enums.CompetitionGroup;
+import com.izouma.wenlvju.utils.excel.EnumExcelConverter;
+import com.izouma.wenlvju.utils.excel.LocalDateConverter;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import java.time.LocalDate;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel(value = "Programme")
+public class ProgUploadDTO {
+
+    @ExcelProperty(value = "节目名称")
+    private String name;
+
+    @ExcelProperty(value = "参赛专业")
+    private String specialty;
+
+    @EnumFormat(value = CompetitionGroup.class,
+            fromExcel = {"个人", "集体"},
+            toJavaEnum = {"SINGLE", "COLLECTIVE"})
+    @ExcelProperty(value = "参赛组别", converter = EnumExcelConverter.class)
+    @Enumerated(EnumType.STRING)
+    @ApiModelProperty(value = "参赛组别")
+    private CompetitionGroup competitionGroup;
+
+    @ExcelProperty(value = "参赛级别")
+    private String level;
+
+    @ExcelProperty(value = "作品时长")
+    private int durationOfWork;
+
+    @ExcelProperty(value = "指导老师")
+    private String instructor;
+
+    @ApiModelProperty(value = "指导老师电话")
+    private String instructorPhone;
+
+    @ExcelProperty(value = "参赛视频")
+    private String video;
+
+    @ExcelProperty(value = "考级机构")
+    private String gradingOrganization;
+
+    @ExcelProperty(value = "承办单位")
+    private String organization;
+
+    @ExcelProperty(value = "考级点")
+    private String examPoint;
+
+    @ExcelProperty(value = "联系人")
+    private String contact;
+
+    @ExcelProperty(value = "联系电话")
+    private String phone;
+
+    @ExcelProperty(value = "参赛人数")
+    private int quantity;
+
+    @ExcelProperty(value = "参赛人员姓名")
+    private String participantName;
+
+    @ExcelProperty(value = "参赛人员性别")
+    private String participantSex;
+
+    @ExcelProperty(value = "参赛人员出生年月")
+    private String participantBirthday;
+
+    @ExcelProperty(value = "参赛人员联系方式")
+    private String participantPhone;
+
+    @ExcelProperty(value = "证件号码")
+    @ApiModelProperty(value = "证件号码")
+    private String idNo;
+
+    @ExcelProperty(value = "证件照")
+    private String img;
+
+    @ExcelProperty(value = "考级证书")
+    private String certificate;
+}

+ 16 - 13
src/main/java/com/izouma/wenlvju/dto/ProgrammeDTO.java

@@ -40,7 +40,7 @@ public class ProgrammeDTO {
     private String specialty;
 
     @EnumFormat(value = CompetitionGroup.class,
-            fromExcel = {"人", "集体"},
+            fromExcel = {"人", "集体"},
             toJavaEnum = {"SINGLE", "COLLECTIVE"})
     @ExcelProperty(value = "参赛组别", converter = EnumExcelConverter.class)
     @Enumerated(EnumType.STRING)
@@ -56,11 +56,8 @@ public class ProgrammeDTO {
     @ExcelProperty(value = "指导老师")
     private String instructor;
 
-    @ExcelProperty(value = "联系人")
-    private String contact;
-
-    @ExcelProperty(value = "联系电话")
-    private String phone;
+    @ApiModelProperty(value = "指导老师电话")
+    private String instructorPhone;
 
     @ExcelProperty(value = "考级机构")
     private String gradingOrganization;
@@ -71,18 +68,21 @@ public class ProgrammeDTO {
     @ExcelProperty(value = "考级点")
     private String examPoint;
 
+    @ExcelProperty(value = "联系人")
+    private String contact;
+
+    @ExcelProperty(value = "联系电话")
+    private String phone;
+
     @ExcelProperty(value = "参赛人数")
     private int quantity;
 
-    @ExcelProperty(value = "参赛视频")
+    @ExcelIgnore
     private String video;
 
     @ExcelIgnore
     private int status;
 
-    @ExcelProperty(value = "照片")
-    private String img;
-
     @ExcelProperty(value = "参赛人员姓名")
     private String participantName;
 
@@ -95,16 +95,19 @@ public class ProgrammeDTO {
     @ExcelProperty(value = "参赛人员联系方式")
     private String participantPhone;
 
-    @ExcelProperty(value = "证件号码")
+    @ExcelProperty(value = "参赛人员证件号码")
     @ApiModelProperty(value = "证件号码")
     private String idNo;
 
-    @ExcelProperty(value = "证书")
+    @ExcelIgnore
+    private String img;
+
+    @ExcelIgnore
     private String certificate;
 
     public ProgrammeDTO(Programme programme) {
         BeanUtil.copyProperties(programme, this);
-        if (programme.getVideo() != null){
+        if (programme.getVideo() != null) {
             this.video = programme.getVideo().getSrc();
         }
 

+ 7 - 0
src/main/java/com/izouma/wenlvju/repo/performance/PerformanceRepo.java

@@ -7,6 +7,8 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.time.LocalDate;
+import java.util.List;
 
 public interface PerformanceRepo extends JpaRepository<Performance, Long>, JpaSpecificationExecutor<Performance> {
     @Query("update Performance t set t.del = true where t.id = ?1")
@@ -18,4 +20,9 @@ public interface PerformanceRepo extends JpaRepository<Performance, Long>, JpaSp
 
     @Query(nativeQuery = true, value = "select * from Performance order by `year` desc limit 0,1")
     Performance findLastYear();
+
+    List<Performance> findAllByPublishTrue();
+
+    @Query(nativeQuery = true, value = "select id from Performance where start_date <= ?1 and end_date >= ?1 and del=0")
+    Long findNow(LocalDate now);
 }

+ 50 - 36
src/main/java/com/izouma/wenlvju/service/performance/ProgrammeService.java

@@ -7,12 +7,10 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.ZipUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSONObject;
+import com.izouma.wenlvju.config.DateConfig;
 import com.izouma.wenlvju.domain.*;
 import com.izouma.wenlvju.domain.performance.*;
-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.dto.*;
 import com.izouma.wenlvju.enums.CompetitionGroup;
 import com.izouma.wenlvju.enums.SignedIn;
 import com.izouma.wenlvju.exception.BusinessException;
@@ -41,9 +39,10 @@ import javax.servlet.http.HttpServletResponse;
 import javax.transaction.Transactional;
 import java.io.*;
 import java.nio.charset.StandardCharsets;
-import java.nio.file.Paths;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -98,7 +97,7 @@ public class ProgrammeService {
         List<Long> settingIds = new ArrayList<>();
         content.forEach(programme -> settingIds.add(programme.getLevelSettingId()));
 
-        Map<Long, String> performanceMap = performanceRepo.findAll()
+        Map<Long, String> performanceMap = performanceRepo.findAllByPublishTrue()
                 .stream()
                 .collect(Collectors.toMap(Performance::getId, Performance::getName));
 
@@ -186,6 +185,10 @@ public class ProgrammeService {
     @Transactional(rollbackOn = Exception.class)
     public void upload(MultipartFile file, Long userId) throws IOException {
         Organization organization = organizationRepo.findByUserId(userId).orElseThrow(new BusinessException("无记录"));
+        Long performance = performanceRepo.findNow(LocalDate.now());
+        if (ObjectUtil.isNull(performance)) {
+            throw new BusinessException("没有正在报名中的展演活动");
+        }
 
         File destDir = TempFile.createTempDirectory("import");
         ZipUtil.unzip(file.getInputStream(), destDir, StandardCharsets.UTF_8);
@@ -201,12 +204,12 @@ public class ProgrammeService {
 
 
         InputStream indicatorStream = new FileInputStream(xlsxFile);
-        UploadDataListener<ProgrammeDTO> listener = new UploadDataListener<>();
-        List<ProgrammeDTO> dtos = EasyExcel.read(indicatorStream, ProgrammeDTO.class, listener).sheet().doReadSync();
+        UploadDataListener<ProgUploadDTO> listener = new UploadDataListener<>();
+        List<ProgUploadDTO> dtos = EasyExcel.read(indicatorStream, ProgUploadDTO.class, listener).sheet().doReadSync();
 
-        Map<String, Long> performanceMap = performanceRepo.findAll()
-                .stream()
-                .collect(Collectors.toMap(Performance::getName, Performance::getId));
+//        Map<String, Long> performanceMap = performanceRepo.findAll()
+//                .stream()
+//                .collect(Collectors.toMap(Performance::getName, Performance::getId));
 
         Map<Integer, Map<String, Long>> mapMap = settingRepo.findAllByFlagIn(CollUtil.newArrayList(3, 4))
                 .stream()
@@ -223,12 +226,12 @@ public class ProgrammeService {
 
         List<Participant> participants = new ArrayList<>();
         Long pid = null;
-        for (ProgrammeDTO dto : dtos) {
+        for (ProgUploadDTO dto : dtos) {
             if (dto.getName() != null && dto.getSpecialty() != null) {
                 Programme programme = new Programme(dto);
                 programme.setOrganizationId(organization.getId());
                 programme.setGradingOrganizationId(gradeMap.get(dto.getGradingOrganization()));
-                programme.setPerformanceId(performanceMap.get(dto.getPerformance()));
+                programme.setPerformanceId(performance);
                 programme.setSpecialtyId(artTypeMap.get(dto.getSpecialty()));
                 String level = dto.getLevel();
                 if (StrUtil.isNotBlank(level)) {
@@ -240,39 +243,49 @@ public class ProgrammeService {
                     programme.setLevelSettingId(mapMap.get(4).get(level));
                 }
 
+                File uploadFile = FileUtils.findByName(destDir, dto.getName());
                 if (dto.getVideo() != null) {
-                    File uploadFile = new File(destDir, dto.getVideo());
-                    if (uploadFile.exists()) {
-                        // 上传
-                        String videoPath = "video/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
-                                + RandomStringUtils.randomAlphabetic(8)
-                                + "." + FilenameUtils.getExtension(uploadFile.getName());
-                        String url = storageService.uploadFromInputStream(new FileInputStream(uploadFile), videoPath);
-                        VideoObject vo = new VideoObject();
-//                        vo.setPoster(posterUrl);
-                        vo.setSrc(url);
-                        programme.setVideo(vo);
-                    }
+//                    File uploadFile = new File(destDir, dto.getVideo());
+                    uploadFile = FileUtils.findByName(destDir, dto.getVideo());
+                }
+                if (ObjectUtil.isNotNull(uploadFile) && uploadFile.exists()) {
+                    // 上传
+                    String videoPath = "video/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
+                            + RandomStringUtils.randomAlphabetic(8)
+                            + "." + FilenameUtils.getExtension(uploadFile.getName());
+                    String url = storageService.uploadFromInputStream(new FileInputStream(uploadFile), videoPath);
+                    VideoObject vo = new VideoObject();
+                    vo.setSrc(url);
+                    programme.setVideo(vo);
                 }
 
                 pid = programmeRepo.save(programme).getId();
             }
 
             Participant participant = new Participant(dto);
+            LocalDate birthday = LocalDate.parse(dto.getParticipantBirthday(), DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT));
+            participant.setBirthday(birthday);
             participant.setProgrammeId(pid);
             participants.add(participant);
-
+            File uploadImg;
             if (dto.getImg() != null) {
-                File uploadFile = new File(destDir, dto.getImg());
-                if (uploadFile.exists()) {
-                    participant.setImg(this.saveImg(uploadFile));
-                }
+//                File uploadFile = new File(destDir, dto.getImg());
+                uploadImg = FileUtils.findByName(destDir, dto.getImg());
+            } else {
+                uploadImg = FileUtils.findByName(destDir, dto.getIdNo() + "证件照");
+            }
+            if (ObjectUtil.isNotNull(uploadImg) && uploadImg.exists()) {
+                participant.setImg(this.saveImg(uploadImg));
             }
+
+            File uploadCertificate;
             if (dto.getCertificate() != null) {
-                File uploadFile = new File(destDir, dto.getCertificate());
-                if (uploadFile.exists()) {
-                    participant.setCertificate(this.saveImg(uploadFile));
-                }
+                uploadCertificate = FileUtils.findByName(destDir, dto.getCertificate());
+            } else {
+                uploadCertificate = FileUtils.findByName(destDir, dto.getIdNo() + "证书");
+            }
+            if (ObjectUtil.isNotNull(uploadCertificate) && uploadCertificate.exists()) {
+                participant.setCertificate(this.saveImg(uploadCertificate));
             }
         }
 
@@ -288,9 +301,10 @@ public class ProgrammeService {
 
     public void excelTemp(HttpServletResponse response) throws IOException {
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        File file = new File(this.getClass().getResource("/templates/Programme.xlsx").getPath());
-        InputStream is = new FileInputStream(file);
+//        File file = new File(this.getClass().getResource("/templates/Programme.xlsx").getPath());
+//        InputStream is = new FileInputStream(file);
 
+        InputStream is = getClass().getResourceAsStream("/templates/Programme.xlsx");
         byte[] buffer = new byte[1024];
         int len;
         while ((len = is.read(buffer)) > -1) {

+ 11 - 0
src/main/java/com/izouma/wenlvju/utils/FileUtils.java

@@ -218,6 +218,17 @@ public class FileUtils {
         return null;
     }
 
+    public static File findByName(File dir,String fileName) {
+        if (!(dir.exists() && dir.isDirectory())) return null;
+        for (File file : dir.listFiles()) {
+            String name = file.getName().toLowerCase();
+            if (name.contains(fileName)){
+                return file;
+            }
+        }
+        return null;
+    }
+
     public static File findExcel1(File dir) {
         if (!(dir.exists() && dir.isDirectory())) return null;
         for (File file : dir.listFiles()) {

BIN
src/main/resources/templates/Programme.xlsx


+ 8 - 1
src/test/java/com/izouma/wenlvju/repo/performance/PerformanceRepoTest.java

@@ -5,13 +5,20 @@ import com.izouma.wenlvju.ApplicationTests;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.time.LocalDate;
+
 public class PerformanceRepoTest extends ApplicationTests {
     @Autowired
     private PerformanceRepo performanceRepo;
 
     @Test
-    public void test(){
+    public void test() {
         System.out.println(performanceRepo.findLastYear());
     }
 
+    @Test
+    public void test1() {
+        System.out.println(performanceRepo.findNow(LocalDate.now()));
+    }
+
 }