licailing hace 4 años
padre
commit
56e651503b

+ 39 - 24
src/main/java/com/izouma/wenlvju/dto/RecordDTO.java

@@ -1,7 +1,11 @@
 package com.izouma.wenlvju.dto;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.izouma.wenlvju.domain.Record;
+import com.izouma.wenlvju.domain.RecordSpecialty;
 import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -13,73 +17,84 @@ import java.time.LocalDate;
 @Builder
 @AllArgsConstructor
 @NoArgsConstructor
-@ApiModel("备案管理")
+@ApiModel(value = "备案管理")
 public class RecordDTO {
-    @ApiModelProperty(value = "考级活动名称")
+    @ExcelProperty(value = "考级活动名称")
     private String examinationName;
 
-    @ApiModelProperty(value = "考级活动时间")
+    @ExcelProperty(value = "考级活动时间")
     private LocalDate examinationStartTime;
 
-    @ApiModelProperty(value = "考级活动时间")
+    @ExcelProperty(value = "考级活动时间")
     private LocalDate examinationEndTime;
 
-    @ApiModelProperty(value = "考级机构名称")
+    @ExcelProperty(value = "考级机构名称")
     private String examinationAgency;
 
-    @ApiModelProperty(value = "单位类别")
+    @ExcelProperty(value = "单位类别")
     private String category;
 
-    @ApiModelProperty(value = "承办单位名称")
+    @ExcelProperty(value = "承办单位名称")
     private String organizer;
 
-    @ApiModelProperty(value = "统一社会信用代码")
+    @ExcelProperty(value = "统一社会信用代码")
     private String uscc;
 
+    @ExcelProperty(value = "考级地址")
     private String district;
 
-    @ApiModelProperty(value = "考级详细地址")
+    @ExcelProperty(value = "考级详细地址")
     private String examinationAddress;
 
-    @ApiModelProperty(value = "考场数量")
+    @ExcelProperty(value = "考场数量")
     private int examCenterQuantity;
 
-    @ApiModelProperty(value = "报考人数")
+    @ExcelProperty(value = "报考人数")
     private int examQuantity;
 
-    @ApiModelProperty(value = "考官人数")
+    @ExcelProperty(value = "考官人数")
     private int examinerQuantity;
 
-    @ApiModelProperty(value = "考点负责人名称")
+    @ExcelProperty(value = "考点负责人名称")
     private String examOwner;
 
-    @ApiModelProperty(value = "考点负责人手机号")
+    @ExcelProperty(value = "考点负责人手机号")
     private String examOwnerPhone;
 
-    @ApiModelProperty(value = "安全负责人名称")
+    @ExcelProperty(value = "安全负责人名称")
     private String securityOwner;
 
-    @ApiModelProperty(value = "安全负责人手机号")
+    @ExcelProperty(value = "安全负责人手机号")
     private String securityOwnerPhone;
 
-    @ApiModelProperty(value = "备案时间")
+    @ExcelProperty(value = "备案时间")
     private LocalDate recordTime;
 
-    @ApiModelProperty(value = "考试简章")
+    @ExcelProperty(value = "考试简章")
     private String examinationGuide;
 
-    @ApiModelProperty(value = "专业名称")
+    @ExcelProperty(value = "考级专业名称")
     private String name;
 
-    @ApiModelProperty(value = "专业代码")
+    @ExcelProperty(value = "考级专业代码")
     private String code;
 
-    @ApiModelProperty(value = "总级数")
+    @ExcelProperty(value = "考级专业总级数")
     private String level;
 
-    @ApiModelProperty(value = "考场数量")
+    @ExcelProperty(value = "考级专业考场数量")
     private int numOfExam;
 
-    @ApiModelProperty(value = "考官人数")
+    @ExcelProperty(value = "考级专业考官人数")
     private int speExaQuantity;
+
+    public RecordDTO(Record record, RecordSpecialty specialty) {
+        BeanUtil.copyProperties(record, this);
+        this.examinerQuantity = record.getExaminerQuantity();
+
+        if (ObjectUtil.isNotEmpty(specialty)){
+            BeanUtil.copyProperties(specialty, this);
+            this.speExaQuantity = specialty.getExaminerQuantity();
+        }
+    }
 }

+ 16 - 2
src/main/java/com/izouma/wenlvju/service/RecordService.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
 import com.izouma.wenlvju.domain.Record;
 import com.izouma.wenlvju.domain.RecordSpecialty;
 import com.izouma.wenlvju.dto.PageQuery;
+import com.izouma.wenlvju.dto.RecordDTO;
 import com.izouma.wenlvju.repo.RecordRepo;
 import com.izouma.wenlvju.repo.RecordSpecialtyRepo;
 import com.izouma.wenlvju.utils.JpaUtils;
@@ -74,13 +75,26 @@ public class RecordService {
     /*
     导出
      */
-    public void excel(List<Record> data) throws IOException {
+    public List<RecordDTO> excel(List<Record> data) throws IOException {
         List<Long> ids = data.stream().map(Record::getId).collect(Collectors.toList());
         if (CollUtil.isEmpty(ids)) {
-            return;
+            return null;
         }
         List<RecordSpecialty> specialties = recordSpecialtyRepo.findAllByRecordIdIn(ids);
+        Map<Long, List<RecordSpecialty>> listMap = specialties.stream()
+                .collect(Collectors.groupingBy(RecordSpecialty::getRecordId));
 
+        List<RecordDTO> dtos = new ArrayList<>();
+        data.forEach(record -> {
+            List<RecordSpecialty> specialtyList = listMap.get(record.getId());
+            if (CollUtil.isEmpty(specialtyList)) {
+                dtos.add(new RecordDTO(record, null));
+            } else {
+                specialtyList.forEach(specialty -> dtos.add(new RecordDTO(record,specialty)));
+            }
+        });
+
+        return dtos;
     }
 
 

+ 6 - 1
src/main/java/com/izouma/wenlvju/web/RecordController.java

@@ -1,8 +1,10 @@
 package com.izouma.wenlvju.web;
 
+import cn.hutool.core.collection.CollUtil;
 import com.izouma.wenlvju.domain.Record;
 import com.izouma.wenlvju.domain.User;
 import com.izouma.wenlvju.dto.PageQuery;
+import com.izouma.wenlvju.dto.RecordDTO;
 import com.izouma.wenlvju.dto.RecordExcelDTO;
 import com.izouma.wenlvju.enums.AuthorityName;
 import com.izouma.wenlvju.exception.BusinessException;
@@ -71,7 +73,10 @@ public class RecordController extends BaseController {
     @ResponseBody
     public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
         List<Record> data = all(pageQuery).getContent();
-        List<RecordExcelDTO> collect = data.stream().map(RecordExcelDTO::new).collect(Collectors.toList());
+        List<RecordDTO> collect = recordService.excel(data);
+        if (CollUtil.isEmpty(collect)){
+            return;
+        }
         ExcelUtils.export(response, collect);
     }
 

+ 1 - 0
src/main/java/com/izouma/wenlvju/web/SettingController.java

@@ -90,6 +90,7 @@ public class SettingController extends BaseController {
         return settingRepo.findById(id).orElseThrow(new BusinessException("无记录"));
     }
 
+    @PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/del/{id}")
     public void del(@PathVariable Long id) {
         settingRepo.softDelete(id);

+ 1 - 0
src/main/java/com/izouma/wenlvju/web/SysConfigController.java

@@ -41,6 +41,7 @@ public class SysConfigController extends BaseController {
         return sysConfigRepo.findByName(id).orElseThrow(new BusinessException("无记录"));
     }
 
+    @PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/del/{id}")
     public void del(@PathVariable String id) {
         sysConfigRepo.deleteById(id);