Преглед изворни кода

Merge remote-tracking branch 'origin/master' into dev_1.0.1

# Conflicts:
#	src/main/java/com/qmth/exam/reserve/bean/stdapply/MaterialTitleInfo.java
#	src/main/java/com/qmth/exam/reserve/service/impl/StudentImportAsyncServiceImpl.java
deason пре 8 месеци
родитељ
комит
3dcfc84361

+ 24 - 2
install/mysql/init/exam_reserve_db.sql

@@ -35,6 +35,7 @@ create table t_user
     mobile      varchar(20) comment '联系方式',
     mobile      varchar(20) comment '联系方式',
     category_id bigint comment '所属教学点ID,角色为教学点管理员,必填',
     category_id bigint comment '所属教学点ID,角色为教学点管理员,必填',
     org_id      bigint      not null comment '所属机构ID(学校)',
     org_id      bigint      not null comment '所属机构ID(学校)',
+    first_login bit(1)      comment '第一次修改密码标志',
     PRIMARY KEY (id),
     PRIMARY KEY (id),
     UNIQUE KEY IDX_01 (org_id, login_name),
     UNIQUE KEY IDX_01 (org_id, login_name),
     KEY IDX_02 (role),
     KEY IDX_02 (role),
@@ -217,7 +218,28 @@ values (1, 'CATEGORY_LEVEL', '[{"level":1,"title":"城市"},{"level":2,"title":"
         unix_timestamp() * 1000);
         unix_timestamp() * 1000);
 
 
 insert into t_user (org_id, role, name, login_name, password, mobile, category_id, enable, create_time, update_time)
 insert into t_user (org_id, role, name, login_name, password, mobile, category_id, enable, create_time, update_time)
-values (1, 'ADMIN', '学校管理员', 'admin', UPPER(SHA2('123456', 256)), null, null, 1, unix_timestamp() * 1000,
+values (1, 'ADMIN', '学校管理员', 'admin', UPPER(SHA2('qmty87863577', 256)), null, null, 1, unix_timestamp() * 1000,
         unix_timestamp() * 1000);
         unix_timestamp() * 1000);
 
 
-
+-- 城市初始化
+INSERT INTO t_category VALUES (1, 1717121654419, 1717121654419, b'1', 1, 0, '4401', '广州市', 1, 0);
+INSERT INTO t_category VALUES (2, 1717121654419, 1717121654419, b'1', 1, 0, '4402', '韶关市', 1, 0);
+INSERT INTO t_category VALUES (3, 1717121654419, 1717121654419, b'1', 1, 0, '4403', '深圳市', 1, 0);
+INSERT INTO t_category VALUES (4, 1717121654419, 1717121654419, b'1', 1, 0, '4404', '珠海市', 1, 0);
+INSERT INTO t_category VALUES (5, 1717121654419, 1717121654419, b'1', 1, 0, '4405', '汕头市', 1, 0);
+INSERT INTO t_category VALUES (6, 1717121654419, 1717121654419, b'1', 1, 0, '4406', '佛山市', 1, 0);
+INSERT INTO t_category VALUES (7, 1717121654419, 1717121654419, b'1', 1, 0, '4407', '江门市', 1, 0);
+INSERT INTO t_category VALUES (8, 1717121654419, 1717121654419, b'1', 1, 0, '4408', '湛江市', 1, 0);
+INSERT INTO t_category VALUES (9, 1717121654419, 1717121654419, b'1', 1, 0, '4409', '茂名市', 1, 0);
+INSERT INTO t_category VALUES (10, 1717121654419, 1717121654419, b'1', 1, 0, '4412', '肇庆市', 1, 0);
+INSERT INTO t_category VALUES (11, 1717121654419, 1717121654419, b'1', 1, 0, '4413', '惠州市', 1, 0);
+INSERT INTO t_category VALUES (12, 1717121654419, 1717121654419, b'1', 1, 0, '4414', '梅州市', 1, 0);
+INSERT INTO t_category VALUES (13, 1717121654419, 1717121654419, b'1', 1, 0, '4415', '汕尾市', 1, 0);
+INSERT INTO t_category VALUES (14, 1717121654419, 1717121654419, b'1', 1, 0, '4416', '河源市', 1, 0);
+INSERT INTO t_category VALUES (15, 1717121654419, 1717121654419, b'1', 1, 0, '4417', '阳江市', 1, 0);
+INSERT INTO t_category VALUES (16, 1717121654419, 1717121654419, b'1', 1, 0, '4418', '清远市', 1, 0);
+INSERT INTO t_category VALUES (17, 1717121654419, 1717121654419, b'1', 1, 0, '4419', '东莞市', 1, 0);
+INSERT INTO t_category VALUES (18, 1717121654419, 1717121654419, b'1', 1, 0, '4420', '中山市', 1, 0);
+INSERT INTO t_category VALUES (19, 1717121654419, 1717121654419, b'1', 1, 0, '4451', '潮州市', 1, 0);
+INSERT INTO t_category VALUES (20, 1717121654419, 1717121654419, b'1', 1, 0, '4452', '揭阳市', 1, 0);
+INSERT INTO t_category VALUES (21, 1717121654419, 1717121654419, b'1', 1, 0, '4453', '云浮市', 1, 0);

+ 3 - 0
src/main/java/com/qmth/exam/reserve/bean/login/LoginUser.java

@@ -44,6 +44,9 @@ public class LoginUser implements AccessEntity, IModel {
     @ApiModelProperty(value = "鉴权信息")
     @ApiModelProperty(value = "鉴权信息")
     private String token;
     private String token;
 
 
+    @ApiModelProperty(value = "第一次登录标志")
+    private Boolean firstLogin;
+
     @Override
     @Override
     @JsonIgnore
     @JsonIgnore
     @ApiModelProperty(hidden = true)
     @ApiModelProperty(hidden = true)

+ 2 - 0
src/main/java/com/qmth/exam/reserve/bean/stdapply/MaterialTitleInfo.java

@@ -30,4 +30,6 @@ public class MaterialTitleInfo implements IModel {
     @ApiModelProperty("考场名称")
     @ApiModelProperty("考场名称")
     private String roomName;
     private String roomName;
 
 
+
+
 }
 }

+ 9 - 9
src/main/java/com/qmth/exam/reserve/cache/impl/ApplyTaskCacheService.java

@@ -121,17 +121,17 @@ public class ApplyTaskCacheService implements CacheConstants {
      * 获取某考点某时段的“已预约数量”
      * 获取某考点某时段的“已预约数量”
      */
      */
     public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
     public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
-        String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
-        if (redisClient.exist(cacheKey)) {
-            return (int) redisClient.getRedissonClient().getAtomicLong(cacheKey).get();
-        }
-
-        RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
+        // String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
+        // if (redisClient.exist(cacheKey)) {
+        //     return (int) redisClient.getRedissonClient().getAtomicLong(cacheKey).get();
+        // }
+        //
+        // RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
 
 
         int value = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
         int value = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
-        atomic.set(value);
-        atomic.expire(30, TimeUnit.DAYS);
-        log.info("SET cacheKey:{} value:{}", cacheKey, value);
+        // atomic.set(value);
+        // atomic.expire(30, TimeUnit.DAYS);
+        // log.info("SET cacheKey:{} value:{}", cacheKey, value);
 
 
         return value;
         return value;
     }
     }

+ 10 - 4
src/main/java/com/qmth/exam/reserve/controller/admin/UserLoginController.java

@@ -8,13 +8,11 @@ import com.qmth.exam.reserve.controller.BaseController;
 import com.qmth.exam.reserve.service.AuthService;
 import com.qmth.exam.reserve.service.AuthService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 
 @RestController
 @RestController
 @Api(tags = "【管理端】用户登录相关接口")
 @Api(tags = "【管理端】用户登录相关接口")
@@ -40,4 +38,12 @@ public class UserLoginController extends BaseController {
         authService.logout(curLoginUser());
         authService.logout(curLoginUser());
     }
     }
 
 
+    @Aac(strict = false, auth = true)
+    @ApiOperation(value = "用户修改密码")
+    @PostMapping(value = "/password/modify")
+    public void modify(@ApiParam("用户密码") @RequestParam String password) {
+        LoginUser loginUser = curLoginUser();
+        authService.modifyPassword(loginUser.getId(), password);
+    }
+
 }
 }

+ 5 - 0
src/main/java/com/qmth/exam/reserve/entity/UserEntity.java

@@ -53,4 +53,9 @@ public class UserEntity extends BaseEntity {
      */
      */
     private Boolean enable;
     private Boolean enable;
 
 
+    /**
+     * 第一次登录标志
+     */
+    private Boolean firstLogin;
+
 }
 }

+ 1 - 1
src/main/java/com/qmth/exam/reserve/job/AutoArrangeExamJob.java

@@ -12,7 +12,7 @@ public class AutoArrangeExamJob {
     @Autowired
     @Autowired
     private StudentApplyService studentApplyService;
     private StudentApplyService studentApplyService;
 
 
-    @Scheduled(cron = "0 * 2 * * ?")
+    @Scheduled(cron = "0 0 1 * * ?")
     public void autoArrangeExam() {
     public void autoArrangeExam() {
         studentApplyService.autoLayout(null);
         studentApplyService.autoLayout(null);
     }
     }

+ 1 - 0
src/main/java/com/qmth/exam/reserve/service/AuthService.java

@@ -14,4 +14,5 @@ public interface AuthService {
 
 
     void logout(LoginUser user);
     void logout(LoginUser user);
 
 
+    void modifyPassword(Long id, String password);
 }
 }

+ 27 - 0
src/main/java/com/qmth/exam/reserve/service/impl/AuthServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.exam.reserve.service.impl;
 package com.qmth.exam.reserve.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.security.annotation.AuthorizationComponent;
 import com.qmth.boot.core.security.annotation.AuthorizationComponent;
 import com.qmth.boot.core.security.service.AuthorizationService;
 import com.qmth.boot.core.security.service.AuthorizationService;
@@ -27,6 +28,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 
 @Service
 @Service
 @AuthorizationComponent
 @AuthorizationComponent
@@ -90,6 +92,7 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
 
 
         loginUser.setSessionId(LoginSessionManager.USER_LOGIN + user.getId());
         loginUser.setSessionId(LoginSessionManager.USER_LOGIN + user.getId());
         loginUser.setToken(FastUUID.get());
         loginUser.setToken(FastUUID.get());
+        loginUser.setFirstLogin(user.getFirstLogin() == null ? Boolean.TRUE : user.getFirstLogin());
         loginSessionManager.addLoginSession(loginUser);
         loginSessionManager.addLoginSession(loginUser);
 
 
         log.info("[USER_LOGIN] success! account:{} {} {}", loginUser.getAccount(), loginUser.getName(), loginUser.getRole());
         log.info("[USER_LOGIN] success! account:{} {} {}", loginUser.getAccount(), loginUser.getName(), loginUser.getRole());
@@ -188,6 +191,30 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
         log.warn("[LOGOUT] account:{} {}", loginUser.getAccount(), loginUser.getName());
         log.warn("[LOGOUT] account:{} {}", loginUser.getAccount(), loginUser.getName());
     }
     }
 
 
+    @Transactional
+    @Override
+    public void modifyPassword(Long id, String password) {
+        if (StringUtils.isBlank(password)) {
+            throw new StatusException("密码不能为空");
+        }
+        String regex = "^[a-zA-Z0-9]{6,12}$";
+        if (!password.matches(regex)) {
+            throw new StatusException("密码必须为:6-12位的大小写字母或者数字");
+        }
+        String encodePassword = DigestUtils.sha256Hex(password).toUpperCase();
+        UserEntity user = userService.getById(id);
+        if (user.getPassword().equals(encodePassword)) {
+            throw new StatusException("修改的密码不能和原密码相同");
+        }
+        userService.update(new UpdateWrapper<UserEntity>().lambda().set(UserEntity::getPassword, encodePassword).eq(UserEntity::getId, id));
+        //更新修改密码标志
+        if (user.getFirstLogin() == null || user.getFirstLogin()) {
+            userService.update(
+                    new UpdateWrapper<UserEntity>().lambda().set(UserEntity::getFirstLogin, Boolean.FALSE).eq(UserEntity::getId, id));
+        }
+    }
+
+
     @Override
     @Override
     public LoginUser findByIdentity(String identity, SignatureType type, String path) {
     public LoginUser findByIdentity(String identity, SignatureType type, String path) {
         return loginSessionManager.getLoginSession(identity);
         return loginSessionManager.getLoginSession(identity);

+ 21 - 12
src/main/java/com/qmth/exam/reserve/service/impl/MaterialGenerateServiceImpl.java

@@ -38,8 +38,8 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
             File file = File.createTempFile("Material" + FastUUID.get(), ".tmp");
             File file = File.createTempFile("Material" + FastUUID.get(), ".tmp");
             doc = pageModel.prepareDocument(file);
             doc = pageModel.prepareDocument(file);
             doc.setMargins(20, 20, 20, 20);
             doc.setMargins(20, 20, 20, 20);
-
-            Paragraph p1 = new Paragraph(title.getTaskName()).setFontSize(18).setBold()
+//            title.getTaskName()
+            Paragraph p1 = new Paragraph("签到表").setFontSize(18).setBold()
                     .setTextAlignment(TextAlignment.CENTER).setMarginTop(-2);
                     .setTextAlignment(TextAlignment.CENTER).setMarginTop(-2);
             doc.add(p1);
             doc.add(p1);
             int fontSize = 12;
             int fontSize = 12;
@@ -68,12 +68,16 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
     private void createSignInTable(List<StudentApplyVO> tempList, Document doc) {
     private void createSignInTable(List<StudentApplyVO> tempList, Document doc) {
         Table tableTitle = tableTitle();
         Table tableTitle = tableTitle();
         int number = Math.min(tempList.size(), LINE_NUMBER);
         int number = Math.min(tempList.size(), LINE_NUMBER);
+        int nameFontSize = FONT_SIZE;
         for (int i = 0; i < number; i++) {
         for (int i = 0; i < number; i++) {
             StudentApplyVO result = null;
             StudentApplyVO result = null;
             if (tempList.size() >= i + 1) {
             if (tempList.size() >= i + 1) {
                 result = tempList.get(i);
                 result = tempList.get(i);
+                if (result != null && result.getName().length() > 4) {
+                    nameFontSize = 10;
+                }
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getName() : " ").setTextAlignment(TextAlignment.CENTER)
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getName() : " ").setTextAlignment(TextAlignment.CENTER)
-                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setHeight(LINE_HEIGHT));
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(nameFontSize).setHeight(LINE_HEIGHT));
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getStudentCode() : " ").setTextAlignment(TextAlignment.CENTER)
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getStudentCode() : " ").setTextAlignment(TextAlignment.CENTER)
                         .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setHeight(LINE_HEIGHT));
                         .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setHeight(LINE_HEIGHT));
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getSeatNumber() : " ").setTextAlignment(TextAlignment.CENTER)
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getSeatNumber() : " ").setTextAlignment(TextAlignment.CENTER)
@@ -97,8 +101,11 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
             }
             }
             if (tempList.size() >= i + number + 1) {
             if (tempList.size() >= i + number + 1) {
                 result = tempList.get(i + 30);
                 result = tempList.get(i + 30);
+                if (result != null && result.getName().length() > 4) {
+                    nameFontSize = 10;
+                }
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getName() : " ").setTextAlignment(TextAlignment.CENTER)
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getName() : " ").setTextAlignment(TextAlignment.CENTER)
-                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setHeight(LINE_HEIGHT));
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(nameFontSize).setHeight(LINE_HEIGHT));
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getStudentCode() : " ").setTextAlignment(TextAlignment.CENTER)
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getStudentCode() : " ").setTextAlignment(TextAlignment.CENTER)
                         .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setHeight(LINE_HEIGHT));
                         .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setHeight(LINE_HEIGHT));
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getSeatNumber() : " ").setTextAlignment(TextAlignment.CENTER)
                 tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getSeatNumber() : " ").setTextAlignment(TextAlignment.CENTER)
@@ -126,19 +133,20 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
 
 
     private Table subHead(MaterialTitleInfo title, int studentSize, int titleFontSize) {
     private Table subHead(MaterialTitleInfo title, int studentSize, int titleFontSize) {
         Table table = new Table(new float[] { 1.2f, 1f }).setWidthPercent(100);
         Table table = new Table(new float[] { 1.2f, 1f }).setWidthPercent(100);
-        table.addCell(new Cell(1, 1).add("考点名称:" + title.getSiteName()).setTextAlignment(TextAlignment.LEFT)
-                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize).setMarginLeft(20f));
-        table.addCell(new Cell(1, 1).add("考试时间:" + title.getTimePeriod()).setTextAlignment(TextAlignment.LEFT)
-                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize).setMarginLeft(40f));
-        String address = title.getAddress();
+        String address = title.getRoomName();
         int fontSize = titleFontSize;
         int fontSize = titleFontSize;
-        if(address != null && address.length()>17) {
+        if(address != null && address.length()>18) {
             fontSize = 10;
             fontSize = 10;
         }
         }
-        table.addCell(new Cell(1, 1).add("考场名称:" + address).setTextAlignment(TextAlignment.LEFT)
+        table.addCell(new Cell(1, 1).add("考点名称:" + title.getSiteName()).setTextAlignment(TextAlignment.LEFT)
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(fontSize).setMarginLeft(20f));
+        table.addCell(new Cell(1, 1).add("考试时间:" + title.getTimePeriod()).setTextAlignment(TextAlignment.LEFT)
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(fontSize).setMarginLeft(40f));
+
+        table.addCell(new Cell(1, 1).add("考场名称:" + title.getRoomCode() + address).setTextAlignment(TextAlignment.LEFT)
                 .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(fontSize).setMarginLeft(20f));
                 .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(fontSize).setMarginLeft(20f));
         table.addCell(new Cell(1, 1).add("考生数量:" + studentSize).setTextAlignment(TextAlignment.LEFT)
         table.addCell(new Cell(1, 1).add("考生数量:" + studentSize).setTextAlignment(TextAlignment.LEFT)
-                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize).setMarginLeft(40f));
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(fontSize).setMarginLeft(40f));
         return table;
         return table;
     }
     }
 
 
@@ -161,4 +169,5 @@ public class MaterialGenerateServiceImpl implements MaterialGenerateService {
         return signTable;
         return signTable;
     }
     }
 
 
+
 }
 }

+ 55 - 105
src/main/java/com/qmth/exam/reserve/service/impl/StudentImportAsyncServiceImpl.java

@@ -1,41 +1,42 @@
 package com.qmth.exam.reserve.service.impl;
 package com.qmth.exam.reserve.service.impl;
 
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.tools.excel.model.DataMap;
 import com.qmth.boot.tools.excel.model.DataMap;
-import com.qmth.exam.reserve.bean.studentimport.StudentImportInfo;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.entity.CategoryEntity;
 import com.qmth.exam.reserve.entity.CategoryEntity;
-import com.qmth.exam.reserve.entity.StudentCourseEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.entity.StudentImportTaskEntity;
 import com.qmth.exam.reserve.entity.StudentImportTaskEntity;
 import com.qmth.exam.reserve.enums.CategoryLevel;
 import com.qmth.exam.reserve.enums.CategoryLevel;
 import com.qmth.exam.reserve.enums.ImportStatus;
 import com.qmth.exam.reserve.enums.ImportStatus;
-import com.qmth.exam.reserve.service.*;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
+import com.qmth.exam.reserve.service.CategoryService;
+import com.qmth.exam.reserve.service.StudentImportAsyncService;
+import com.qmth.exam.reserve.service.StudentImportTaskService;
+import com.qmth.exam.reserve.service.StudentService;
 
 
 @Service
 @Service
 public class StudentImportAsyncServiceImpl implements StudentImportAsyncService {
 public class StudentImportAsyncServiceImpl implements StudentImportAsyncService {
 
 
     private final static Logger log = LoggerFactory.getLogger(StudentImportAsyncServiceImpl.class);
     private final static Logger log = LoggerFactory.getLogger(StudentImportAsyncServiceImpl.class);
 
 
-    private static final String[] EXCEL_HEADER = new String[] { "学号", "姓名", "证件号", "所属教学点代码", "所属教学点名称", "科目名称", "科目代码" };
+    private static final String[] EXCEL_HEADER = new String[] { "学号", "姓名", "证件号", "所属教学点代码", "所属教学点名称", "可约时段数" };
 
 
     @Autowired
     @Autowired
     private CategoryService categoryService;
     private CategoryService categoryService;
@@ -49,20 +50,17 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
     @Autowired
     @Autowired
     private ApplyTaskCacheService cacheService;
     private ApplyTaskCacheService cacheService;
 
 
-    @Autowired
-    private StudentCourseService studentCourseService;
-
     @Async
     @Async
     @Transactional
     @Transactional
     @Override
     @Override
     public void asyncImportStudent(StudentImportTaskEntity task, Long orgId, List<DataMap> lineList) {
     public void asyncImportStudent(StudentImportTaskEntity task, Long orgId, List<DataMap> lineList) {
         Map<String, CategoryEntity> teachingCache = getTeachingCache();
         Map<String, CategoryEntity> teachingCache = getTeachingCache();
-        List<StudentImportInfo> studentList = new ArrayList<>();
+        List<StudentEntity> studentList = new ArrayList<StudentEntity>();
         List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
         List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
         for (int i = 0; i < lineList.size(); i++) {
         for (int i = 0; i < lineList.size(); i++) {
             DataMap line = lineList.get(i);
             DataMap line = lineList.get(i);
             StringBuilder msg = new StringBuilder();
             StringBuilder msg = new StringBuilder();
-            StudentImportInfo student = new StudentImportInfo();
+            StudentEntity student = new StudentEntity();
             String studentCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[0]));
             String studentCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[0]));
             if (StringUtils.isBlank(studentCode)) {
             if (StringUtils.isBlank(studentCode)) {
                 msg.append(" 学号不能为空");
                 msg.append(" 学号不能为空");
@@ -112,21 +110,16 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
                 student.setOrgId(orgId);
                 student.setOrgId(orgId);
                 student.setApplyTaskId(task.getApplyTaskId());
                 student.setApplyTaskId(task.getApplyTaskId());
             }
             }
-
-            String courseName = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
-            if (StringUtils.isBlank(courseName)) {
-                msg.append(" 科目名称不能为空");
-            } else {
-                student.setCourseName(courseName);
-            }
-
-            String courseCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[6]));
-            if (StringUtils.isBlank(courseCode)) {
-                msg.append(" 科目代码不能为空");
-            } else {
-                student.setCourseCode(courseCode);
+            try {
+                String applyNumber = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
+                if (StringUtils.isBlank(applyNumber)) {
+                    msg.append(" 可约时段数不能为空");
+                } else {
+                    student.setApplyNumber(Integer.parseInt(applyNumber));
+                }
+            } catch (Exception e) {
+                msg.append(" 可约时段只能为数字");
             }
             }
-
             if (msg.length() > 0) {
             if (msg.length() > 0) {
                 failRecords.add(newError(i + 1, msg.toString()));
                 failRecords.add(newError(i + 1, msg.toString()));
             } else {
             } else {
@@ -138,67 +131,10 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
             updateStudentImportTask(task, ImportStatus.FAILURE.toString(), failRecords);
             updateStudentImportTask(task, ImportStatus.FAILURE.toString(), failRecords);
             return;
             return;
         }
         }
-
-        //更新和保存考生以及考生的考试科目
-        long start = System.currentTimeMillis();
         for (int i = 0; i < studentList.size(); i++) {
         for (int i = 0; i < studentList.size(); i++) {
-            StudentImportInfo studentInfo = studentList.get(i);
+            StudentEntity studentEntity = studentList.get(i);
             try {
             try {
-                //考生信息
-                StudentEntity studentEntity = new StudentEntity();
-                BeanUtils.copyProperties(studentInfo, studentEntity);
-
-                //考生的考试科目
-                StudentCourseEntity studentCourseEntity = new StudentCourseEntity();
-                studentCourseEntity.setCourseCode(studentInfo.getCourseCode());
-                studentCourseEntity.setCourseName(studentInfo.getCourseName());
-
-                LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<StudentEntity>()
-                        .eq(StudentEntity::getStudentCode, studentEntity.getStudentCode())
-                        .eq(StudentEntity::getApplyTaskId, studentEntity.getApplyTaskId());
-                StudentEntity existStudent = studentService.getOne(wrapper);
-
-                LambdaQueryWrapper<StudentCourseEntity> studentCourseQueryWrapper = new LambdaQueryWrapper<>();
-                studentCourseQueryWrapper.eq(StudentCourseEntity::getCourseCode, studentCourseEntity.getCourseCode());
-
-                Long studentId;
-                if (existStudent != null) {
-                    studentId = existStudent.getId();
-                    existStudent.setName(studentEntity.getName());
-                    existStudent.setIdentityNumber(studentEntity.getIdentityNumber());
-                    existStudent.setCategoryId(studentEntity.getCategoryId());
-                    studentService.updateById(existStudent);
-
-                    studentCourseQueryWrapper.eq(StudentCourseEntity::getStudentId, studentId);
-                    StudentCourseEntity existStudentCourse = studentCourseService.getOne(studentCourseQueryWrapper);
-
-                    //更新考生的考试科目
-                    if(existStudentCourse != null) {
-                        existStudentCourse.setCourseName(studentCourseEntity.getCourseName());
-                        studentCourseService.updateById(existStudentCourse);
-                    } else {
-                        studentCourseEntity.setStudentId(existStudent.getId());
-                        studentCourseService.save(studentCourseEntity);
-                    }
-                } else {
-                    studentEntity.setApplyFinished(Boolean.FALSE);
-                    studentEntity.setApplyNumber(0);
-                    studentEntity.setPhotoPath(studentEntity.getIdentityNumber()+".jpg");
-                    studentService.save(studentEntity);
-
-                    studentId = studentEntity.getId();
-
-                    //保存考生科目
-                    studentCourseEntity.setStudentId(studentId);
-                    studentCourseService.save(studentCourseEntity);
-                }
-
-                //更新考生的预约次数
-                studentService.updateStudentApplyNumber(studentId);
-
-                // 清空缓存
-                cacheService.clearStudentApplyNumberCache(studentId);
-
+                saveStudent(studentEntity);
             } catch (StatusException e) {
             } catch (StatusException e) {
                 failRecords.add(newError(i + 1, e.getMessage()));
                 failRecords.add(newError(i + 1, e.getMessage()));
             } catch (Exception e) {
             } catch (Exception e) {
@@ -208,13 +144,7 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
                 return;
                 return;
             }
             }
         }
         }
-        long end = System.currentTimeMillis();
-        log.warn("[耗时]{}ms", end - start);
-
-        //更新成功标志
-        task.setMessage(failRecords.isEmpty() ? null : failRecords.toString());
-        task.setStatus(ImportStatus.SUCCESS.toString());
-        importTaskService.saveOrUpdate(task);
+        updateStudentImportTask(task, ImportStatus.SUCCESS.toString(), failRecords);
     }
     }
 
 
     private void updateStudentImportTask(StudentImportTaskEntity task, String status,
     private void updateStudentImportTask(StudentImportTaskEntity task, String status,
@@ -224,6 +154,26 @@ public class StudentImportAsyncServiceImpl implements StudentImportAsyncService
         importTaskService.saveOrUpdate(task);
         importTaskService.saveOrUpdate(task);
     }
     }
 
 
+    private void saveStudent(StudentEntity studentEntity) {
+        LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<StudentEntity>()
+                .eq(StudentEntity::getStudentCode, studentEntity.getStudentCode())
+                .eq(StudentEntity::getApplyTaskId, studentEntity.getApplyTaskId());
+        StudentEntity existStudent = studentService.getOne(wrapper);
+        if (existStudent != null) {
+            existStudent.setName(studentEntity.getName());
+            existStudent.setIdentityNumber(studentEntity.getIdentityNumber());
+            existStudent.setCategoryId(studentEntity.getCategoryId());
+            existStudent.setApplyNumber(studentEntity.getApplyNumber());
+            studentService.updateById(existStudent);
+            // 清空缓存
+            cacheService.clearStudentApplyNumberCache(existStudent.getId());
+        } else {
+            studentEntity.setApplyFinished(Boolean.FALSE);
+            studentEntity.setPhotoPath(studentEntity.getIdentityNumber()+".JPG");
+            studentService.save(studentEntity);
+        }
+    }
+
     private String trimAndNullIfBlank(String s) {
     private String trimAndNullIfBlank(String s) {
         if (StringUtils.isBlank(s)) {
         if (StringUtils.isBlank(s)) {
             return null;
             return null;

+ 3 - 2
src/main/java/com/qmth/exam/reserve/weixin/AbstractRequest.java

@@ -89,12 +89,13 @@ public abstract class AbstractRequest<T extends WxResponseJson, K, V> {
         if (jsonEntity != null) {
         if (jsonEntity != null) {
             if (jsonEntity.getErrcode() == 40001 || jsonEntity.getErrcode() == 40014 || jsonEntity.getErrcode() == 40029
             if (jsonEntity.getErrcode() == 40001 || jsonEntity.getErrcode() == 40014 || jsonEntity.getErrcode() == 40029
                     || jsonEntity.getErrcode() == 42001) {
                     || jsonEntity.getErrcode() == 42001) {
+                log.warn("error_code:{}; err_message:{}", jsonEntity.getErrcode(), jsonEntity.getErrmsg());
                 if (this.requestTotal < 5) {
                 if (this.requestTotal < 5) {
                     this.requestTotal++;
                     this.requestTotal++;
                     this.request();
                     this.request();
                 } else {
                 } else {
-                    log.info("error_code:" + jsonEntity.getErrcode() + ";err_message:" + jsonEntity.getErrmsg()
-                            + ";weixin_json:" + jsonEntity.getWeixin_json());
+                    log.error("error_code:{};err_message:{};weixin_json:{}", jsonEntity.getErrcode(), jsonEntity.getErrmsg(),
+                            jsonEntity.getWeixin_json());
                     throw new StatusException("无法获取openId");
                     throw new StatusException("无法获取openId");
                 }
                 }
             }
             }