فهرست منبع

新增命题统计

wangliang 3 سال پیش
والد
کامیت
5c1889a216

+ 70 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncStatisticsDataImportService.java

@@ -0,0 +1,70 @@
+package com.qmth.distributed.print.business.templete.execute;
+
+import cn.hutool.core.date.DateUtil;
+import com.qmth.boot.api.exception.ApiException;
+import com.qmth.distributed.print.business.templete.importData.AsyncImportTaskTemplete;
+import com.qmth.distributed.print.business.templete.service.TaskLogicService;
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.TBTask;
+import com.qmth.teachcloud.common.enums.TaskResultEnum;
+import com.qmth.teachcloud.common.enums.TaskStatusEnum;
+import com.qmth.teachcloud.common.service.TBTaskService;
+import com.qmth.teachcloud.common.util.Result;
+import com.qmth.teachcloud.common.util.ResultUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.StringJoiner;
+
+/**
+ * @Description: 命题统计导入
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/9/9
+ */
+@Service
+public class AsyncStatisticsDataImportService extends AsyncImportTaskTemplete {
+    private final static Logger log = LoggerFactory.getLogger(AsyncStatisticsDataImportService.class);
+
+    public static final String OBJ_TITLE = "命题统计导入";
+
+    @Override
+    public Result importTask(Map<String, Object> map) throws IOException, Exception {
+        TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
+        InputStream inputStream = super.getUploadFileInputStream(tbTask);
+        map.put("inputStream", inputStream);
+        StringJoiner stringJoinerSummary = new StringJoiner("\n")
+                .add(MessageFormat.format("{0}{1}{2}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), BEGIN_TITLE, OBJ_TITLE));
+        tbTask.setStatus(TaskStatusEnum.RUNNING);
+        TBTaskService tbTaskService = SpringContextHolder.getBean(TBTaskService.class);
+        tbTaskService.updateById(tbTask);
+        try {
+            TaskLogicService taskLogicService = SpringContextHolder.getBean(TaskLogicService.class);
+            // 执行导入
+            Map<String, Object> result = taskLogicService.executeImportStatisticsLogic(map);
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), FINISH_TITLE, Long.valueOf(String.valueOf(result.get("dataCount"))), FINISH_SIZE));
+            tbTask.setResult(TaskResultEnum.SUCCESS);
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), EXCEPTION_TITLE, EXCEPTION_DATA, e.getMessage()));
+            tbTask.setResult(TaskResultEnum.ERROR);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        } finally {//生成txt文件
+            tbTask.setSummary(stringJoinerSummary.toString());
+            super.createTxt(tbTask);
+        }
+        return ResultUtil.ok(map);
+    }
+}

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncSysUserDataImportService.java

@@ -30,7 +30,7 @@ import java.util.StringJoiner;
  */
 @Service
 public class AsyncSysUserDataImportService extends AsyncImportTaskTemplete {
-    private final static Logger log = LoggerFactory.getLogger(AsyncCourseDataImportService.class);
+    private final static Logger log = LoggerFactory.getLogger(AsyncSysUserDataImportService.class);
 
     public static final String OBJ_TITLE = "用户基本信息";
 

+ 17 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/TaskLogicService.java

@@ -65,33 +65,46 @@ public interface TaskLogicService {
 
     /**
      * 处理导入考生数据
+     *
      * @param map 数据源
      * @return 结果
      * @throws Exception 异常
      */
-    Map<String,Object> executeImportBasicStudentLogic(Map<String,Object> map) throws Exception;
+    Map<String, Object> executeImportBasicStudentLogic(Map<String, Object> map) throws Exception;
 
     /**
      * 处理导入课程数据
+     *
      * @param map 数据源
      * @return 结果
      * @throws Exception 异常
      */
-    Map<String,Object> executeImportBasicCourseLogic(Map<String,Object> map) throws Exception;
+    Map<String, Object> executeImportBasicCourseLogic(Map<String, Object> map) throws Exception;
 
     /**
      * 处理导入用户数据
+     *
      * @param map 数据源
      * @return 结果
      * @throws Exception 异常
      */
-    Map<String,Object> executeImportSysUserLogic(Map<String,Object> map) throws Exception;
+    Map<String, Object> executeImportSysUserLogic(Map<String, Object> map) throws Exception;
 
     /**
      * 处理导入基础班级数据
+     *
+     * @param map 数据源
+     * @return 结果
+     * @throws Exception 异常
+     */
+    Map<String, Object> executeImportBasicClazzLogic(Map<String, Object> map) throws Exception;
+
+    /**
+     * 处理命题统计导入数据
+     *
      * @param map 数据源
      * @return 结果
      * @throws Exception 异常
      */
-    Map<String,Object> executeImportBasicClazzLogic(Map<String,Object> map) throws Exception;
+    Map<String, Object> executeImportStatisticsLogic(Map<String, Object> map) throws Exception;
 }

+ 29 - 10
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -12,9 +12,6 @@ import com.google.common.collect.Lists;
 import com.itextpdf.text.DocumentException;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.*;
-import com.qmth.teachcloud.common.bean.dto.excel.BasicClazzImportDto;
-import com.qmth.teachcloud.common.bean.dto.excel.BasicCourseImportDto;
-import com.qmth.teachcloud.common.bean.dto.excel.BasicStudentImportDto;
 import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.cache.CreatePdfCacheUtil;
 import com.qmth.distributed.print.business.entity.*;
@@ -24,8 +21,7 @@ import com.qmth.distributed.print.business.templete.service.TaskLogicService;
 import com.qmth.distributed.print.business.util.CreatePdfUtil;
 import com.qmth.distributed.print.business.util.HtmlToPdfUtil;
 import com.qmth.teachcloud.common.annotation.ExcelDBFieldDesc;
-import com.qmth.teachcloud.common.bean.dto.excel.DescribeImportDto;
-import com.qmth.teachcloud.common.bean.dto.excel.SysUserImportDto;
+import com.qmth.teachcloud.common.bean.dto.excel.*;
 import com.qmth.teachcloud.common.bean.params.ArraysParams;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
@@ -1105,7 +1101,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     public Map<String, Object> executeImportBasicStudentLogic(Map<String, Object> map) throws Exception {
         InputStream inputStream = (InputStream) map.get("inputStream");
         System.out.println(inputStream);
-        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicStudentImportDto.class,DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
+        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicStudentImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
             List<ExcelError> excelErrorTemp = new ArrayList<>();
             Map<String, String> checkCodeMap = new HashMap<>();
             Map<String, String> checkPhoneMap = new HashMap<>();
@@ -1113,7 +1109,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
                 List<Object> basicStudentImportDtoList = excelMap.get(i);
                 assert basicStudentImportDtoList != null;
-                if (basicStudentImportDtoList.get(0) instanceof DescribeImportDto){
+                if (basicStudentImportDtoList.get(0) instanceof DescribeImportDto) {
                     continue;
                 }
                 for (int y = 0; y < Objects.requireNonNull(basicStudentImportDtoList).size(); y++) {
@@ -1131,7 +1127,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         checkCodeMap.put(studentCode, studentName);
                     }
                     // 如果电话有值则检验电话excel中唯一性
-                    if (SystemConstant.strNotNull(phoneNumber)){
+                    if (SystemConstant.strNotNull(phoneNumber)) {
                         if (checkPhoneMap.containsKey(phoneNumber)) {
                             throw ExceptionResultEnum.ERROR.exception("导入的excel中包含在重复的【电话号码】:" + phoneNumber);
                         } else {
@@ -1274,14 +1270,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     public Map<String, Object> executeImportBasicClazzLogic(Map<String, Object> map) throws Exception {
         InputStream inputStream = (InputStream) map.get("inputStream");
         System.out.println(inputStream);
-        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicClazzImportDto.class,DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
+        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(BasicClazzImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
             List<ExcelError> excelErrorTemp = new ArrayList<>();
             Map<String, String> checkNameMap = new HashMap<>();
             for (int i = 0; i < finalExcelList.size(); i++) {
                 LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
                 List<Object> basicClazzImportDtoList = excelMap.get(i);
                 assert basicClazzImportDtoList != null;
-                if (basicClazzImportDtoList.get(0) instanceof DescribeImportDto){
+                if (basicClazzImportDtoList.get(0) instanceof DescribeImportDto) {
                     continue;
                 }
                 for (int y = 0; y < Objects.requireNonNull(basicClazzImportDtoList).size(); y++) {
@@ -1311,6 +1307,29 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return basicClazzService.executeBasicClazzImportLogic(finalList, map);
     }
 
+    /**
+     * 处理命题统计导入数据
+     *
+     * @param map 数据源
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public Map<String, Object> executeImportStatisticsLogic(Map<String, Object> map) throws Exception {
+        InputStream inputStream = (InputStream) map.get("inputStream");
+        List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(StatisticsImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
+            // 只允许导入一个sheet
+            if (finalExcelList.size() > 1) {
+                throw ExceptionResultEnum.ERROR.exception("excel中只允许有一个sheet");
+            }
+            if (finalExcelErrorList.size() > 0) {
+                throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(finalExcelErrorList));
+            }
+            return finalExcelList;
+        });
+        return map;
+    }
+
 
     public String createTempNumber(SerialNumberParams serialNumberParams) {
         return convertUtil.getIncre(serialNumberParams.getPrefix(), serialNumberParams.getModel(), serialNumberParams.getDigit());

+ 23 - 4
distributed-print/src/main/java/com/qmth/distributed/print/api/TCStatisticsController.java

@@ -1,10 +1,18 @@
 package com.qmth.distributed.print.api;
 
 
+import com.qmth.boot.api.annotation.Aac;
+import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.distributed.print.business.bean.result.EditResult;
 import com.qmth.distributed.print.business.entity.TCStatistics;
 import com.qmth.distributed.print.business.enums.StatisticsStatusEnum;
+import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.distributed.print.business.service.TCStatisticsService;
+import com.qmth.distributed.print.business.templete.execute.AsyncStatisticsDataImportService;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.TBTask;
+import com.qmth.teachcloud.common.enums.TaskTypeEnum;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import io.swagger.annotations.*;
@@ -17,6 +25,8 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * <p>
@@ -29,18 +39,27 @@ import javax.annotation.Resource;
 @Api(tags = "命题统计Controller")
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.statistics}")
-//@Aac(auth = BOOL.FALSE, strict = BOOL.FALSE)
+@Aac(auth = BOOL.FALSE, strict = BOOL.FALSE)
 public class TCStatisticsController {
     private final static Logger log = LoggerFactory.getLogger(TCStatisticsController.class);
 
     @Resource
     TCStatisticsService tcStatisticsService;
 
+    @Resource
+    PrintCommonService printCommonService;
+
+    @Resource
+    AsyncStatisticsDataImportService asyncStatisticsDataImportService;
+
     @ApiOperation(value = "命题计划统计-导入")
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Result.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
     @RequestMapping(value = "/import", method = RequestMethod.POST)
-    public Result dataImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) {
-        return ResultUtil.ok();
+    public Result dataImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws Exception {
+        Map<String, Object> map = printCommonService.saveTask(file, TaskTypeEnum.STATISTICS_IMPORT);
+        asyncStatisticsDataImportService.importTask(map);
+        TBTask tbTask = Objects.nonNull(map.get(SystemConstant.TASK)) ? (TBTask) map.get(SystemConstant.TASK) : null;
+        return Objects.nonNull(tbTask) ? ResultUtil.ok(tbTask.getId()) : ResultUtil.error("创建任务失败");
     }
 
     @ApiOperation(value = "命题计划统计-列表")

+ 2 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/excel/BasicClazzImportDto.java

@@ -3,13 +3,14 @@ package com.qmth.teachcloud.common.bean.dto.excel;
 import com.qmth.teachcloud.common.annotation.ExcelNote;
 
 import javax.validation.constraints.NotNull;
+import java.io.Serializable;
 
 /**
  * @Description: 基础课程导入
  * @Author: CaoZixuan
  * @Date: 2021-08-28
  */
-public class BasicClazzImportDto {
+public class BasicClazzImportDto implements Serializable {
     @ExcelNote(value = "班级名称")
     @NotNull
     private String clazzName;

+ 2 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/excel/BasicCourseImportDto.java

@@ -3,13 +3,14 @@ package com.qmth.teachcloud.common.bean.dto.excel;
 import com.qmth.teachcloud.common.annotation.ExcelNote;
 
 import javax.validation.constraints.NotNull;
+import java.io.Serializable;
 
 /**
  * @Description: 基础课程数据导入类
  * @Author: CaoZixuan
  * @Date: 2021-08-06
  */
-public class BasicCourseImportDto {
+public class BasicCourseImportDto implements Serializable {
     @ExcelNote(value = "课程名称")
     @NotNull
     private String courseName;

+ 2 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/excel/BasicStudentImportDto.java

@@ -3,13 +3,14 @@ package com.qmth.teachcloud.common.bean.dto.excel;
 import com.qmth.teachcloud.common.annotation.ExcelNote;
 
 import javax.validation.constraints.NotNull;
+import java.io.Serializable;
 
 /**
  * @Description: 基础学生数据导入类
  * @Author: CaoZixuan
  * @Date: 2021-08-05
  */
-public class BasicStudentImportDto {
+public class BasicStudentImportDto implements Serializable {
     @ExcelNote(value = "姓名")
     @NotNull
     private String studentName;

+ 3 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/excel/DescribeImportDto.java

@@ -2,12 +2,14 @@ package com.qmth.teachcloud.common.bean.dto.excel;
 
 import com.qmth.teachcloud.common.annotation.ExcelNote;
 
+import java.io.Serializable;
+
 /**
  * @Description: excel导入说明sheet
  * @Author: CaoZixuan
  * @Date: 2021-08-23
  */
-public class DescribeImportDto {
+public class DescribeImportDto implements Serializable {
 
     @ExcelNote(value = "说明")
     private String describe;

+ 88 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/excel/StatisticsImportDto.java

@@ -0,0 +1,88 @@
+package com.qmth.teachcloud.common.bean.dto.excel;
+
+import com.qmth.teachcloud.common.annotation.ExcelNote;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * @Description: 命题统计导入
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/9/9
+ */
+public class StatisticsImportDto implements Serializable {
+
+    @ExcelNote(value = "开课学院")
+    @NotNull
+    private String collegeName;
+
+    @ExcelNote(value = "开课部门")
+    @NotNull
+    private String teachingRoomName;
+
+    @ExcelNote(value = "课程名称")
+    @NotNull
+    private String courseName;
+
+    @ExcelNote(value = "课程代码")
+    @NotNull
+    private String courseCode;
+
+    @ExcelNote(value = "任课老师")
+    @NotNull
+    private String teacherName;
+
+    @ExcelNote(value = "任课老师")
+    @NotNull
+    private String clazzName;
+
+    public String getCollegeName() {
+        return collegeName;
+    }
+
+    public void setCollegeName(String collegeName) {
+        this.collegeName = collegeName;
+    }
+
+    public String getTeachingRoomName() {
+        return teachingRoomName;
+    }
+
+    public void setTeachingRoomName(String teachingRoomName) {
+        this.teachingRoomName = teachingRoomName;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getTeacherName() {
+        return teacherName;
+    }
+
+    public void setTeacherName(String teacherName) {
+        this.teacherName = teacherName;
+    }
+
+    public String getClazzName() {
+        return clazzName;
+    }
+
+    public void setClazzName(String clazzName) {
+        this.clazzName = clazzName;
+    }
+}

+ 2 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/excel/SysUserImportDto.java

@@ -3,13 +3,14 @@ package com.qmth.teachcloud.common.bean.dto.excel;
 import com.qmth.teachcloud.common.annotation.ExcelNote;
 
 import javax.validation.constraints.NotNull;
+import java.io.Serializable;
 
 /**
  * @Description: 系统用户导入Dto
  * @Author: CaoZixuan
  * @Date: 2021-08-12
  */
-public class SysUserImportDto {
+public class SysUserImportDto implements Serializable {
 
     @ExcelNote(value = "姓名")
     @NotNull