Browse Source

删除部分本地临时文件

wangliang 4 years ago
parent
commit
18381f2959

+ 7 - 0
1

@@ -0,0 +1,7 @@
+Merge branch 'dev' into release
+merge
+# Please enter a commit message to explain why this merge is necessary,
+# especially if it merges an updated upstream into a topic branch.
+#
+# Lines starting with '#' will be ignored, and an empty message aborts
+# the commit.

+ 255 - 0
distributed-print/src/test/java/com/qmth/distributed/print/BasicDataImportTest.java

@@ -0,0 +1,255 @@
+package com.qmth.distributed.print;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.itextpdf.text.log.SysoCounter;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
+import com.qmth.distributed.print.business.service.*;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler;
+import org.junit.Test;
+import org.junit.platform.commons.util.StringUtils;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 用户数据导入、课程导入、组织机构导入
+ */
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class BasicDataImportTest {
+    @Autowired
+    private BasicCourseService basicCourseService;
+    @Autowired
+    private SysUserService sysUserService;
+    @Autowired
+    private SysOrgService sysOrgService;
+    @Autowired
+    private BasicUserCourseService basicUserCourseService;
+    @Autowired
+    private SysRoleService sysRoleService;
+    @Autowired
+    private SysUserRoleService sysUserRoleService;
+    @Autowired
+    private SysRolePrivilegeService sysRolePrivilegeService;
+
+    // 学校Id
+    private Long schoolId = 1l;
+
+    // 用户数据文件
+    String userFile = "D:\\20210508140918-1.xlsx";
+    // 课程数据文件
+    String courseFile = "D:\\20210508140918-2.xlsx";
+
+
+    @Test
+    public void importBasicCourse() throws Exception {
+        List<BasicCourse> courses = readCourseFile();
+        for (BasicCourse cours : courses) {
+            QueryWrapper<BasicCourse> queryWrapper = new QueryWrapper<>();
+            queryWrapper.lambda().eq(BasicCourse::getCode, cours.getCode());
+            BasicCourse basicCourse = basicCourseService.getOne(queryWrapper);
+            if (basicCourse != null) {
+                if (basicCourse.getName().equals(cours.getName())) {
+                    continue;
+                } else {
+                    throw new Exception(String.format("s%代码已存在,名称不一致,数据库:s%,文件中:s%", cours.getCode(), basicCourse.getName(), cours.getName()));
+                }
+            }
+
+            cours.setId(SystemConstant.getDbUuid());
+            cours.setSchoolId(schoolId);
+            basicCourseService.save(cours);
+        }
+    }
+
+    @Test
+//    @Transactional
+    public void importBasicUser() throws Exception {
+        List<Map<String, String>> users = readUserFile();
+        for (Map<String, String> userMap : users) {
+            // sys_org
+            String orgCode = userMap.get("orgCode");
+            String orgName = userMap.get("orgName");
+            QueryWrapper<SysOrg> orgQueryWrapper = new QueryWrapper<>();
+            orgQueryWrapper.lambda().eq(SysOrg::getSchoolId, schoolId).eq(SysOrg::getCode, orgCode);
+            SysOrg sysOrg = sysOrgService.getOne(orgQueryWrapper);
+            if (sysOrg != null) {
+                if (!sysOrg.getName().equals(orgName)) {
+                    throw new Exception(String.format("s%代码已存在,名称不一致,数据库:s%,文件中:s%", orgCode, sysOrg.getName(), orgName));
+                }
+            } else {
+                sysOrg = new SysOrg();
+                sysOrg.setId(SystemConstant.getDbUuid());
+                sysOrg.setSchoolId(schoolId);
+                sysOrg.setCode(orgCode);
+                sysOrg.setName(orgName);
+                sysOrg.setParentId(100l);
+                sysOrgService.save(sysOrg);
+            }
+
+            // sys_user
+            String loginName = userMap.get("loginName");
+            String realName = userMap.get("realName");
+            String mobileNumber = userMap.get("mobileNumber");
+            String password = userMap.get("password");
+            QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
+            userQueryWrapper.lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getLoginName, loginName);
+            SysUser sysUser = sysUserService.getOne(userQueryWrapper);
+            if(sysUser == null){
+                sysUser = new SysUser();
+                sysUser.setId(SystemConstant.getDbUuid());
+                sysUser.setSchoolId(schoolId);
+                sysUser.setLoginName(loginName);
+                sysUser.setRealName(realName);
+                sysUser.setPassword(password);
+                sysUser.setMobileNumber(mobileNumber);
+                sysUser.setOrgId(sysOrg.getId());
+                sysUserService.save(sysUser);
+            }
+
+            // sys_user_role
+            String roleType = userMap.get("roleType");
+            QueryWrapper<SysRole> roleQueryWrapper = new QueryWrapper<>();
+            roleQueryWrapper.lambda().eq(SysRole::getType, roleType);
+            SysRole sysRole = sysRoleService.getOne(roleQueryWrapper);
+            if (sysRole == null) {
+                throw new Exception("角色不存在");
+            }
+            QueryWrapper<SysRolePrivilege> rolePrivilegeQueryWrapper = new QueryWrapper<>();
+            rolePrivilegeQueryWrapper.lambda().eq(SysRolePrivilege::getRoleId, sysRole.getId()).eq(SysRolePrivilege::getEnable, true);
+            List<SysRolePrivilege> rolePrivileges = sysRolePrivilegeService.list(rolePrivilegeQueryWrapper);
+            List<SysUserRole> userRoles = new ArrayList<>();
+            for (SysRolePrivilege rolePrivilege : rolePrivileges) {
+                SysUserRole sysUserRole = new SysUserRole();
+                sysUserRole.setId(SystemConstant.getDbUuid());
+                sysUserRole.setUserId(sysUser.getId());
+                sysUserRole.setRoleId(rolePrivilege.getRoleId());
+                sysUserRole.setPrivilegeId(rolePrivilege.getPrivilegeId());
+                sysUserRole.setEnable(true);
+                userRoles.add(sysUserRole);
+            }
+            sysUserRoleService.saveBatch(userRoles);
+
+            // sys_user_course
+            String courseCodeses = userMap.get("courseCode");
+            if(roleType.equals(RoleTypeEnum.QUESTION_TEACHER.name())){
+                if(StringUtils.isBlank(courseCodeses)){
+                    throw new Exception("命题老师课程不能为空");
+                }
+
+                List<BasicUserCourse> userCourses = new ArrayList<>();
+                String[] courseCodes = courseCodeses.split(",");
+                for (String courseCode : courseCodes) {
+                    String[] coursees = courseCode.split("/");
+                    QueryWrapper<BasicCourse> basicCourseQueryWrapper = new QueryWrapper<>();
+                    basicCourseQueryWrapper.lambda().eq(BasicCourse::getSchoolId, schoolId).eq(BasicCourse::getCode, coursees[0]);
+                    BasicCourse basicCourse = basicCourseService.getOne(basicCourseQueryWrapper);
+                    if(basicCourse == null){
+                        throw new Exception("命题老师对应课程不存在");
+                    }
+                    BasicUserCourse basicUserCourse = new BasicUserCourse();
+                    basicUserCourse.setId(SystemConstant.getDbUuid());
+                    basicUserCourse.setUserId(sysUser.getId());
+                    basicUserCourse.setCourseId(basicCourse.getId());
+                    userCourses.add(basicUserCourse);
+                }
+                basicUserCourseService.saveBatch(userCourses);
+            }
+        }
+    }
+
+    /**
+     * 读取课程数据文件
+     *
+     * @return
+     * @throws Exception
+     */
+    private List<BasicCourse> readCourseFile() throws Exception {
+        File file = new File(courseFile);
+        if (!file.exists()) {
+            throw new Exception("课程数据文件不存在");
+        }
+        FileInputStream fileInputStream = new FileInputStream(file);
+        XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
+        XSSFSheet sheet = workbook.getSheetAt(0);
+
+        List<BasicCourse> courseList = new ArrayList<>();
+        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
+            BasicCourse basicCourse = new BasicCourse();
+            Row row = sheet.getRow(i);
+            // 用户名
+            Cell cell0 = row.getCell(0);
+            basicCourse.setCode(cell0 == null ? null : cell0.getStringCellValue());
+            // 姓名
+            Cell cell1 = row.getCell(1);
+            basicCourse.setName(cell1 == null ? null : cell1.getStringCellValue());
+            courseList.add(basicCourse);
+        }
+        return courseList;
+    }
+
+    /**
+     * 读取用户数据文件
+     *
+     * @return
+     * @throws Exception
+     */
+    private List<Map<String, String>> readUserFile() throws Exception {
+        File file = new File(userFile);
+        if (!file.exists()) {
+            throw new Exception("用户数据文件不存在");
+        }
+        FileInputStream fileInputStream = new FileInputStream(file);
+        XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
+        XSSFSheet sheet = workbook.getSheetAt(0);
+
+        List<Map<String, String>> userList = new ArrayList<>();
+        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
+            Map<String, String> map = new HashMap<>();
+            Row row = sheet.getRow(i);
+            // 用户名
+            Cell cell0 = row.getCell(0);
+            map.put("loginName", cell0 == null ? null : cell0.getStringCellValue());
+            // 姓名
+            Cell cell1 = row.getCell(1);
+            map.put("realName", cell1 == null ? null : cell1.getStringCellValue());
+            // 手机号
+            Cell cell2 = row.getCell(2);
+            map.put("mobileNumber", cell2 == null ? null : cell2.getStringCellValue());
+            // 密码
+            Cell cell4 = row.getCell(4);
+            map.put("password", cell4 == null ? null : cell4.getStringCellValue());
+            // 角色Code
+            Cell cell5 = row.getCell(5);
+            map.put("roleType", cell5 == null ? null : cell5.getStringCellValue());
+            // 机构code
+            Cell cell8 = row.getCell(8);
+            map.put("orgCode", cell8 == null ? null : cell8.getStringCellValue());
+            // 机构名称
+            Cell cell9 = row.getCell(9);
+            map.put("orgName", cell9 == null ? null : cell9.getStringCellValue());
+            // 命题老师可操作课程代码
+            Cell cell10 = row.getCell(10);
+            map.put("courseCode", cell10 == null ? null : cell10.getStringCellValue());
+            userList.add(map);
+        }
+
+        return userList;
+    }
+
+}

+ 73 - 0
hs_err_pid10539.log

@@ -0,0 +1,73 @@
+#
+# A fatal error has been detected by the Java Runtime Environment:
+#
+#  SIGBUS (0xa) at pc=0x00007fff5f969f49, pid=10539, tid=0x0000000000012f07
+#
+# JRE version: Java(TM) SE Runtime Environment (8.0_131-b11) (build 1.8.0_131-b11)
+# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode bsd-amd64 compressed oops)
+# Problematic frame:
+# C  [libsystem_platform.dylib+0x4f49]  _platform_memmove$VARIANT$Haswell+0x29
+#
+# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
+#
+# If you would like to submit a bug report, please visit:
+#   http://bugreport.java.com/bugreport/crash.jsp
+#
+
+---------------  T H R E A D  ---------------
+
+Current thread (0x00007ffc4a704800):  JavaThread "arbitrateThreadPool5" [_thread_in_vm, id=77575, stack(0x000070000e4dc000,0x000070000e5dc000)]
+
+siginfo: si_signo: 10 (SIGBUS), si_code: 2 (BUS_ADRERR), si_addr: 0x000000012adde040
+
+Registers:
+RAX=0x0000000796a1b150, RBX=0x0000000000000010, RCX=0x000000000000f382, RDX=0x00000000000171c5
+RSP=0x000070000e5d8e80, RBP=0x000070000e5d8e80, RSI=0x000000012adde040, RDI=0x0000000796a22f93
+R8 =0x00000007c00007a8, R9 =0x0000000000000010, R10=0x000000010f5289e7, R11=0x000000066bc44f53
+R12=0x0000000000000000, R13=0x00007ffc4a704800, R14=0x000070000e5d8f10, R15=0x000000012add61fd
+RIP=0x00007fff5f969f49, EFLAGS=0x0000000000010206, ERR=0x0000000000000004
+  TRAPNO=0x000000000000000e
+
+Top of Stack: (sp=0x000070000e5d8e80)
+0x000070000e5d8e80:   000070000e5d8e90 00000001051e698f
+0x000070000e5d8e90:   000070000e5d8ee0 000000010558323d
+0x000070000e5d8ea0:   32343820372e3039 00007ffc4a704800
+0x000070000e5d8eb0:   00007ffc4a704800 00000000000171c5
+0x000070000e5d8ec0:   0000000000000000 0000000796a068b0
+0x000070000e5d8ed0:   0000000796a04cb8 00007ffc4a704800
+0x000070000e5d8ee0:   000070000e5d8f30 000000010f528a61
+0x000070000e5d8ef0:   00000000000171c5 0000000740113598
+0x000070000e5d8f00:   0000000000000000 6761502f65707954
+0x000070000e5d8f10:   0000000796a1b140 5220302033373120
+0x000070000e5d8f20:   626f646e650a3e3e 2030203437310a6a
+0x000070000e5d8f30:   000070000e5da918 000000010f547684
+0x000070000e5d8f40:   4d2f522030203732 5b786f4261696465
+0x000070000e5d8f50:   3039313120302030 2f5d32343820372e
+0x000070000e5d8f60:   656372756f736552 477478452f3c3c73
+0x000070000e5d8f70:   2f3c3c6574617453 3020332033315347
+0x000070000e5d8f80:   6e6f462f3e3e5220 343154462f3c3c74
+0x000070000e5d8f90:   00000000000171c5 00000000000171c5
+0x000070000e5d8fa0:   000000012add61fd 0000000000000010
+0x000070000e5d8fb0:   0000000796a1b140 542f3e3e3e3e5220
+0x000070000e5d8fc0:   000070000e5da918 00000001108ad484
+0x000070000e5d8fd0:   3e52203020333731 6a626f646e650a3e
+0x000070000e5d8fe0:   6f2030203537310a 6f432f3c3c0a6a62
+0x000070000e5d8ff0:   322073746e65746e 64654d2f52203020
+0x000070000e5d9000:   20305b786f426169 372e303931312030
+0x000070000e5d9010:   65522f5d32343820 3c73656372756f73
+0x000070000e5d9020:   7453477478452f3c 53472f3c3c657461
+0x000070000e5d9030:   5220302033203331 3c746e6f462f3e3e
+0x000070000e5d9040:   3420343154462f3c 3154462f52203020
+0x000070000e5d9050:   5220302030312039 000171c50000c1fd
+0x000070000e5d9060:   00000007969d73a0 3e52203020303220
+0x000070000e5d9070:   657079542f3e3e3e 61502f656761502f 
+
+Instructions: (pc=0x00007fff5f969f49)
+0x00007fff5f969f29:   f3 48 89 f8 49 39 d3 72 1b 48 83 fa 60 76 2f 48
+0x00007fff5f969f39:   81 fa 00 40 00 00 0f 82 cb 00 00 00 48 89 d1 fc
+0x00007fff5f969f49:   f3 a4 5d c3 48 39 fe 74 f9 48 01 d6 48 01 d7 48
+0x00007fff5f969f59:   83 fa 60 0f 82 8c 01 00 00 e9 a9 01 00 00 48 83 
+
+Register to memory mapping:
+
+RAX=0x0000000796a1b150 is an oop