浏览代码

数据同步

fanxp 3 月之前
父节点
当前提交
7fc567beb9

+ 1 - 1
src/main/java/com/xjrsoft/module/student/controller/StudentManagerController.java

@@ -291,7 +291,7 @@ public class StudentManagerController {
 
     @PostMapping("/import")
     @ApiOperation(value = "导入学生信息")
-    @SaCheckPermission("studentmanager:import")
+//    @SaCheckPermission("studentmanager:import")
     @XjrLog(value = "导入学生信息", saveRequestData = false, saveResponseData = true)
     public RT<List<BaseStudentSompleInfoVo>> importData(@RequestParam("file") MultipartFile file) throws IOException, ParseException {
         List<Map<Integer, Object>> excelDataList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(3).doReadSync();

+ 57 - 21
src/main/java/com/xjrsoft/module/student/service/impl/StudentManagerServiceImpl.java

@@ -37,6 +37,7 @@ import com.xjrsoft.module.organization.mapper.UserMapper;
 import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
 import com.xjrsoft.module.organization.service.IDepartmentService;
 import com.xjrsoft.module.organization.service.IUserDeptRelationService;
+import com.xjrsoft.module.organization.service.IUserRoleRelationService;
 import com.xjrsoft.module.organization.service.IUserService;
 import com.xjrsoft.module.student.dto.AddBaseStudentUserDto;
 import com.xjrsoft.module.student.dto.BaseStudentSimpleInfoDto;
@@ -83,6 +84,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
     private final IBaseStudentService baseStudentService;
     private final BaseClassMapper baseClassMapper;
     private final IBaseStudentContactService studentContactService;
+    private final IUserRoleRelationService userRoleRelationService;
     private final BaseStudentFamilyMapper familyMapper;
     private final BaseStudentFamilyMemberMapper familyMemberMapper;
 
@@ -222,7 +224,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
                         .eq(BaseStudentUser::getCredentialNumber, dto.getCredentialNumber())
                         .ne(BaseStudentUser::getId, dto.getId())
         );
-        if(!studentUserList.isEmpty()){
+        if (!studentUserList.isEmpty()) {
             throw new MyException("该身份证已被其他人占用,请检查是否正确");
         }
         BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
@@ -508,12 +510,12 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
             idNumbers.add(integerObjectMap.get(0).toString());
         }
 
-        List<BaseStudentSompleInfoVo> infos = userMapper.getInfosByParam(new BaseStudentSimpleInfoDto() {{
-            setIdNumberList(idNumbers);
-        }});
-        if(!infos.isEmpty()){
-           return infos;
-        }
+//        List<BaseStudentSompleInfoVo> infos = userMapper.getInfosByParam(new BaseStudentSimpleInfoDto() {{
+//            setIdNumberList(idNumbers);
+//        }});
+//        if(!infos.isEmpty()){
+//           return infos;
+//        }
 
         //查询所有学生的用户信息,组装起来备用
         List<BaseStudentUser> studentUsers = this.selectJoinList(BaseStudentUser.class,
@@ -602,6 +604,12 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
         for (BaseStudentContact el : contactList) {
             contactMap.put(el.getUserId(), el);
         }
+        //查询用户角色
+        List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectList(null);
+        Map<Long, UserRoleRelation> userRoleRelationsMap = new HashMap<>();
+        for (UserRoleRelation el : userRoleRelations) {
+            userRoleRelationsMap.put(el.getUserId(), el);
+        }
 
         List<BaseStudentUser> updateStudentUserList = new ArrayList();
         List<BaseStudent> updateBaseStudentList = new ArrayList();
@@ -609,6 +617,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
         List<BaseStudentSubsidize> updateSubsidizeList = new ArrayList();
         List<BaseStudentFamily> updateFamilyList = new ArrayList();
         List<BaseStudentContact> updateContactList = new ArrayList();
+        List<UserRoleRelation> updateRoleRelationList = new ArrayList();
 
         List<BaseStudentUser> insertStudentUserList = new ArrayList();
         List<BaseStudent> insertBaseStudentList = new ArrayList();
@@ -616,6 +625,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
         List<BaseStudentSubsidize> insertSubsidizeList = new ArrayList();
         List<BaseStudentFamily> insertFamilyList = new ArrayList();
         List<BaseStudentContact> insertContactList = new ArrayList();
+        List<UserRoleRelation> insertRoleRelationList = new ArrayList();
 
         //异动记录
         List<StudentChangeRecord> changeRecordList = new ArrayList();
@@ -635,6 +645,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
             BaseStudentSubsidize subsidize;
             BaseStudentFamily studentFamily;
             BaseStudentContact contact;
+            UserRoleRelation roleRelation;
             long userId = IdUtil.getSnowflakeNextId();
             if (user != null) {
                 userId = user.getId();
@@ -684,6 +695,14 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
                     contact.setCreateDate(LocalDateTime.now());
                 }
                 contact.setDeleteMark(DeleteMark.NODELETE.getCode());
+
+                // 更新角色
+                roleRelation = userRoleRelationsMap.get(user.getId());
+                if (roleRelation == null) {
+                    roleRelation = new UserRoleRelation();
+                    roleRelation.setUserId(userId);
+                    roleRelation.setRoleId(RoleEnum.STUDENT.getCode());
+                }
             } else {
                 user = new BaseStudentUser();
                 user.setId(userId);
@@ -720,6 +739,11 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
                 contact.setUserId(userId);
                 contact.setCreateUserId(createUserId);
                 contact.setCreateDate(LocalDateTime.now());
+
+                // 角色
+                roleRelation = new UserRoleRelation();
+                roleRelation.setUserId(userId);
+                roleRelation.setRoleId(RoleEnum.STUDENT.getCode());
             }
             //设置字段值
             if (dataMaps.get(1) != null && !"".equals(dataMaps.get(1).toString())) {
@@ -884,7 +908,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
             }
             if (dataMaps.get(53) != null && !"".equals(dataMaps.get(53).toString()) && schoolRoll.getId() == null) {
                 schoolRoll.setClassId(classMap.get(dataMaps.get(53).toString()).getId());//班级
-                if(schoolRoll.getMajorSetId() == null){
+                if (schoolRoll.getMajorSetId() == null) {
                     schoolRoll.setMajorSetId(classMap.get(dataMaps.get(53).toString()).getMajorSetId());
                 }
             }
@@ -984,45 +1008,51 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
                 studentFamily.setRailwayStation(dataMaps.get(83).toString());//离家最近火车站
             }
 
-            if(studentUserMap.containsKey(credentialNumber)){
+            if (studentUserMap.containsKey(credentialNumber)) {
                 updateStudentUserList.add(user);
-            }else{
+            } else {
                 insertStudentUserList.add(user);
             }
 
-            if(baseStudent.getId() == null){
+            if (baseStudent.getId() == null) {
                 insertBaseStudentList.add(baseStudent);
-            }else{
+            } else {
                 updateBaseStudentList.add(baseStudent);
             }
 
-            if(schoolRoll.getId() == null){
-                if(schoolRoll.getArchivesStatus() == null){
+            if (schoolRoll.getId() == null) {
+                if (schoolRoll.getArchivesStatus() == null) {
                     schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2901.getCode());
                 }
                 insertSchoolRollList.add(schoolRoll);
-            }else{
+            } else {
                 updateSchoolRollList.add(schoolRoll);
             }
 
-            if(subsidize.getId() == null){
+            if (subsidize.getId() == null) {
                 insertSubsidizeList.add(subsidize);
-            }else{
+            } else {
                 updateSubsidizeList.add(subsidize);
             }
 
-            if(studentFamily.getId() == null){
+            if (studentFamily.getId() == null) {
                 insertFamilyList.add(studentFamily);
-            }else{
+            } else {
                 updateFamilyList.add(studentFamily);
             }
 
-            if(contact.getId() == null){
+            if (contact.getId() == null) {
                 insertContactList.add(contact);
-            }else{
+            } else {
                 updateContactList.add(contact);
             }
 
+            if (roleRelation.getId() == null) {
+                insertRoleRelationList.add(roleRelation);
+            } else {
+                updateRoleRelationList.add(roleRelation);
+            }
+
             row++;
         }
         //批量修改
@@ -1044,6 +1074,9 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
         if (!updateContactList.isEmpty()) {
             studentContactService.updateBatchById(updateContactList);
         }
+        if (!updateRoleRelationList.isEmpty()) {
+            userRoleRelationService.updateBatchById(updateRoleRelationList);
+        }
         //批量新增
         if (!insertStudentUserList.isEmpty()) {
             this.saveBatch(insertStudentUserList);
@@ -1063,6 +1096,9 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
         if (!insertContactList.isEmpty()) {
             studentContactService.saveBatch(insertContactList);
         }
+        if (!insertRoleRelationList.isEmpty()) {
+            userRoleRelationService.saveBatch(insertRoleRelationList);
+        }
         return new ArrayList<>();
     }
 

+ 3 - 0
src/main/java/com/xjrsoft/module/system/service/ILoginService.java

@@ -1,5 +1,6 @@
 package com.xjrsoft.module.system.service;
 
+import com.xjrsoft.module.organization.entity.User;
 import com.xjrsoft.module.system.dto.*;
 import com.xjrsoft.module.system.vo.CreateTokenVo;
 import com.xjrsoft.module.system.vo.ImgCaptchaVo;
@@ -14,6 +15,8 @@ public interface ILoginService {
 
     LoginVo login(LoginDto dto) throws Exception;
 
+    LoginVo getLoginInfo(User loginUser, String loginType);
+
     LoginVo loginByCode(LoginByCodeDto dto) throws Exception;
 
     LoginByCodeVo bindOpenid(LoginByCodeDto dto) throws Exception;

+ 2 - 1
src/main/java/com/xjrsoft/module/system/service/impl/LoginServiceImpl.java

@@ -358,7 +358,8 @@ public class LoginServiceImpl implements ILoginService {
         return sb.toString();
     }
 
-    private LoginVo getLoginInfo(User loginUser, String loginType) throws Exception {
+    @Override
+    public LoginVo getLoginInfo(User loginUser, String loginType) {
         LoginVo result = new LoginVo();
         if (loginUser.getEnabledMark() == EnabledMark.DISABLED.getCode()) {
             throw new MyException("账户未启用");

+ 6 - 6
src/main/resources/application-dev.yml

@@ -5,12 +5,12 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://10.150.10.136:3308/tl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false&testWhileIdle=true
-    username: data_tl
-    password: qwe123QWE
-#    url: jdbc:mysql://219.153.208.37:53256/smart_campus?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false
-#    username: smart_campus
-#    password: W2Xk@8QFe3hYR7QZ?-yY
+#    url: jdbc:mysql://10.150.10.136:3308/tl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false&testWhileIdle=true
+#    username: data_tl
+#    password: qwe123QWE
+    url: jdbc:mysql://219.153.208.37:53256/smart_campus?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false
+    username: smart_campus
+    password: W2Xk@8QFe3hYR7QZ?-yY
     druid:
       # 验证连接的有效性
       test-while-idle: true

+ 17 - 2
src/test/java/com/xjrsoft/module/system/controller/LoginControllerTest.java

@@ -3,6 +3,10 @@ package com.xjrsoft.module.system.controller;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.xjrsoft.common.sms.SmsCtcc;
 import com.xjrsoft.common.utils.RedisUtil;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.service.IUserService;
+import com.xjrsoft.module.system.service.ILoginService;
+import com.xjrsoft.module.system.vo.LoginVo;
 import org.apache.commons.lang3.RandomUtils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,18 +25,29 @@ class LoginControllerTest {
     private RedisUtil redisUtil;
     @Autowired
     private SmsCtcc smsCtcc;
+    @Autowired
+    private ILoginService loginService;
+    @Autowired
+    private IUserService userService;
 
     @Test
-    void test(){
+    void test() {
         String key = "imgCaptcha:15898a7f-984c-402d-806e-b5a0d79845fa";
         System.out.println(redisUtil.get(key));
     }
 
     @Test
-    void test2(){
+    void test2() {
         String code = RandomUtils.nextInt(100000, 999999) + StringPool.EMPTY;
         String mobile = "13389612083";
         smsCtcc.sendCaptcha(mobile, code, true);
     }
 
+    @Test
+    void testToken() {
+        User user = userService.getById("1000000000000000000");
+        LoginVo pc = loginService.getLoginInfo(user, "PC");
+        System.out.println(pc);
+    }
+
 }