haogh vor 1 Jahr
Ursprung
Commit
6cb39bb4a0

+ 7 - 0
src/main/java/com/qmth/exam/reserve/config/WxProperty.java

@@ -16,4 +16,11 @@ public class WxProperty {
 
     @Value("${wx.app_secret}")
     private String appSecret;
+
+    @Value("${com.qmth.fss.config}")
+    private String config;
+
+    @Value("${com.qmth.fss.server}")
+    private String server;
+
 }

+ 10 - 0
src/main/java/com/qmth/exam/reserve/service/FileUploadService.java

@@ -0,0 +1,10 @@
+package com.qmth.exam.reserve.service;
+
+import java.io.File;
+
+public interface FileUploadService {
+
+    String uploadFile(String dirName, File file);
+
+    String uploadByText(String dirName, String text, String fileName);
+}

+ 57 - 0
src/main/java/com/qmth/exam/reserve/service/impl/FileUploadServiceImpl.java

@@ -0,0 +1,57 @@
+package com.qmth.exam.reserve.service.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.time.Duration;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.qmth.boot.core.fss.store.impl.OssStore;
+import com.qmth.boot.tools.models.ByteArray;
+import com.qmth.exam.reserve.config.WxProperty;
+import com.qmth.exam.reserve.service.FileUploadService;
+
+@Service
+public class FileUploadServiceImpl implements FileUploadService {
+
+    private final static Logger log = LoggerFactory.getLogger(FileUploadServiceImpl.class);
+
+    @Autowired
+    private WxProperty property;
+
+    @Override
+    public String uploadFile(String dirName, File file) {
+        try {
+            OssStore store = new OssStore(property.getServer(), property.getConfig());
+            String filePath = dirName + "/" + file.getName();
+            store.write(filePath, new FileInputStream(file), ByteArray.md5(file).toHexString());
+            String url = store.getPresignedUrl(filePath, Duration.ofMinutes(5));
+            store.close();
+            return url;
+        } catch (Exception e) {
+            log.warn("文件上传出错", e);
+        }
+        return null;
+    }
+
+    @Override
+    public String uploadByText(String dirName, String text, String fileName) {
+        try {
+            OssStore store = new OssStore(property.getServer(), property.getConfig());
+            String filePath = dirName + "/" + fileName;
+            ByteArray data = ByteArray.fromString(text);
+            store.write(filePath, new ByteArrayInputStream(data.value()), ByteArray.md5(data.value()).toHexString());
+            String url = store.getPresignedUrl(filePath, Duration.ofMinutes(5));
+            store.close();
+            return url;
+        } catch (Exception e) {
+            log.warn("文件上传出错", e);
+        }
+        return null;
+    }
+
+}

+ 42 - 12
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -8,7 +8,6 @@ import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
-import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.HashMap;
@@ -17,7 +16,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
-import com.qmth.exam.reserve.entity.base.BaseEntity;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateUtils;
 import org.redisson.api.RLock;
@@ -210,10 +208,13 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             throw new StatusException("Excel无内容");
         }
         ApplyTaskEntity task = getApplyTask();
+        Date openStartTime = new Date(task.getOpenApplyStartTime());
+        Date now = new Date();
         List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
         Map<String, Long> teachingCache = getTeachingCache(level);
         Map<String, Long> agentCache = getAgentCache();
         Map<String, TimePeriodEntity> timeCache = getTimePeriodCache();
+        Map<Long, Long> examSiteCategroyCache = getExamSiteCategroyCache();
         List<StudentImportVO> applyList = new ArrayList<>();
         AgentAndTimeVO agentTime = new AgentAndTimeVO();
         for (int i = 0; i < lineList.size(); i++) {
@@ -257,18 +258,20 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             if (categoryId != null && !student.getCategoryId().equals(categoryId)) {
                 msg.append(" 导入的考生所属教学点和系统中的考生教学点不匹配");
             }
-            // if (categoryId != null && !categoryId.equals(teachingId)) {
-            // msg.append(" 不是本教学点的考生");
-            // }
-
             String agentName1 = trimAndNullIfBlank(line.get(EXCEL_HEADER[4]));
             if (StringUtils.isBlank(agentName1)) {
                 msg.append(" 预约考点1不能为空");
             }
             agentTime = new AgentAndTimeVO();
             Long agentId = agentCache.get(agentName1);
+            Long applyCategoryId = null;
             if (agentId == null) {
                 msg.append(" 预约考点1不存在");
+            } else {
+                applyCategoryId = examSiteCategroyCache.get(agentId);
+                if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
+                    msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
+                }
             }
 
             String timePeriod1 = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
@@ -296,8 +299,14 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 continue;
             } else {
                 agentId = agentCache.get(agentName2);
-                if (agentId == null)
+                if (agentId == null) {
                     msg.append(" 预约考点2不存在");
+                } else {
+                    applyCategoryId = examSiteCategroyCache.get(agentId);
+                    if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
+                        msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
+                    }
+                }
                 try {
                     timePeriod = checkTimePeriod(timePeriod2, timeCache);
                     agentTime = new AgentAndTimeVO();
@@ -320,8 +329,14 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 continue;
             } else {
                 agentId = agentCache.get(agentName3);
-                if (agentId == null)
+                if (agentId == null) {
                     msg.append(" 预约考点3不存在");
+                } else {
+                    applyCategoryId = examSiteCategroyCache.get(agentId);
+                    if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
+                        msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
+                    }
+                }
                 try {
                     timePeriod = checkTimePeriod(timePeriod3, timeCache);
                     agentTime = new AgentAndTimeVO();
@@ -344,8 +359,14 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 continue;
             } else {
                 agentId = agentCache.get(agentName4);
-                if (agentId == null)
+                if (agentId == null) {
                     msg.append(" 预约考点4不存在");
+                } else {
+                    applyCategoryId = examSiteCategroyCache.get(agentId);
+                    if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
+                        msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
+                    }
+                }
                 try {
                     timePeriod = checkTimePeriod(timePeriod4, timeCache);
                     agentTime = new AgentAndTimeVO();
@@ -387,6 +408,17 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
 
     }
 
+    private Map<Long, Long> getExamSiteCategroyCache() {
+        Map<Long, Long> cache = new HashMap<>();
+        LambdaQueryWrapper<ExamSiteEntity> lm = new LambdaQueryWrapper<>();
+        lm.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
+        List<ExamSiteEntity> examSiteList = examSiteService.list(lm);
+        examSiteList.stream().forEach(site -> {
+            cache.put(site.getId(), site.getCategoryId());
+        });
+        return cache;
+    }
+
     private void checkAvailableTimePeriod(List<StudentImportVO> applyList) {
         for (StudentImportVO vo : applyList) {
             List<AgentAndTimeVO> agentTimeList = vo.getAgentTimeList();
@@ -606,7 +638,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return s.trim();
     }
 
-    @Transactional
     @Override
     public void autoAssign(Long taskId, Long userId) {
         checkAfterOpenTime();
@@ -701,6 +732,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                         studentApply.setExamSiteId(siteId);
                         studentApply.setCancel(Boolean.FALSE);
                         studentApply.setTimePeriodId(timeId);
+                        studentApply.setOperateId(userId);
 
                         StudentApplyEntity existStudentApply = findStudentApply(studentApply);
                         if (existStudentApply != null) {
@@ -714,8 +746,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                         num++;
                         if (student.getApplyNumber() - (studentApplyList.size() + 1) == 0) {
                             iterator.remove();
-                            student.setApplyFinished(true);
-                            this.studentService.updateById(student);
                         }
 
                         ApplyRecordCacheBean bean = new ApplyRecordCacheBean();