|
@@ -1,24 +1,46 @@
|
|
|
package com.ruoyi.web.controller.tool;
|
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
+import com.ruoyi.common.constant.UserConstants;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.core.text.Convert;
|
|
|
+import com.ruoyi.common.utils.ShiroUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
+import com.ruoyi.framework.shiro.service.SysPasswordService;
|
|
|
import com.ruoyi.system.domain.Dangan;
|
|
|
import com.ruoyi.system.domain.SysUserOnline;
|
|
|
import com.ruoyi.system.domain.UserRelate;
|
|
|
+import com.ruoyi.system.mapper.SysDeptMapper;
|
|
|
+import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import com.ruoyi.system.service.IDanganService;
|
|
|
import com.ruoyi.system.service.ISysUserOnlineService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
import com.ruoyi.system.service.IUserRelateService;
|
|
|
+import com.ruoyi.web.controller.system.SysUserController;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.catalina.User;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.apache.shiro.crypto.hash.Md5Hash;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+import static com.ruoyi.common.core.domain.AjaxResult.error;
|
|
|
|
|
|
@Api("用户信息管理")
|
|
|
@RestController
|
|
@@ -48,11 +70,11 @@ public class ActionApi {
|
|
|
logger.info("validateMessage"+validateMessage.toString());
|
|
|
try {
|
|
|
if (!StringUtils.isNotEmpty(validateMessage.getClientKey())) {
|
|
|
- return AjaxResult.error("请求失败!");
|
|
|
+ return error("请求失败!");
|
|
|
|
|
|
}
|
|
|
if (!StringUtils.isNotEmpty(validateMessage.getCid())) {
|
|
|
- return AjaxResult.error("请校验应用id!");
|
|
|
+ return error("请校验应用id!");
|
|
|
}
|
|
|
// List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
|
|
|
|
|
@@ -60,7 +82,7 @@ public class ActionApi {
|
|
|
if (StringUtils.isEmpty(validateMessage.getAuthCode())) {
|
|
|
|
|
|
|
|
|
- return AjaxResult.error("授权码不能为空!");
|
|
|
+ return error("授权码不能为空!");
|
|
|
|
|
|
|
|
|
}
|
|
@@ -85,7 +107,7 @@ public class ActionApi {
|
|
|
long min = diff % nd % nh / nm;
|
|
|
if (min >= 1) {
|
|
|
logger.error("reqid已过期");
|
|
|
- return AjaxResult.error("reqid已过期!");
|
|
|
+ return error("reqid已过期!");
|
|
|
}
|
|
|
newReqid = "newReqid"+reqidlist[1];
|
|
|
}
|
|
@@ -99,7 +121,7 @@ public class ActionApi {
|
|
|
|
|
|
if (StringUtils.isNull(sysUserOnline)) {
|
|
|
logger.error("授权已过期!");
|
|
|
- return AjaxResult.error("授权已过期!");
|
|
|
+ return error("授权已过期!");
|
|
|
}
|
|
|
String authCode = validateMessage.getAuthCode();
|
|
|
Dangan dangan = danganService.selectDanganByDanganName(validateMessage.getCid());
|
|
@@ -113,7 +135,7 @@ public class ActionApi {
|
|
|
logger.info("authHash:"+auth);
|
|
|
if (!auth.equals(authCode)) {
|
|
|
logger.error("授权码错误!");
|
|
|
- return AjaxResult.error("授权码错误!");
|
|
|
+ return error("授权码错误!");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -129,7 +151,7 @@ public class ActionApi {
|
|
|
|
|
|
if (!StringUtils.isNotEmpty(userRelates)) {
|
|
|
logger.error("授权已过期!");
|
|
|
- return AjaxResult.error("授权已过期!");
|
|
|
+ return error("授权已过期!");
|
|
|
}
|
|
|
|
|
|
UserRelate userRelate1 = userRelates.get(0);
|
|
@@ -146,12 +168,206 @@ public class ActionApi {
|
|
|
return ajaxResult;
|
|
|
}catch(Exception ex){
|
|
|
logger.error("异常:"+ex.getLocalizedMessage());
|
|
|
- return AjaxResult.error("异常");
|
|
|
+ return error("异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDeptMapper sysDeptMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysPasswordService passwordService;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
+
|
|
|
+ //TODO 本地使用·批量插入用户
|
|
|
+ @PostMapping("/testUtil")
|
|
|
+ public void testUtil(){
|
|
|
+ try {
|
|
|
+ String path = "D:\\工作文档\\武汉三环科普睿科\\会议笔记\\";
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(path + "人员信息导入.xlsx");
|
|
|
+ // 1.创建一个工作簿。使得excel能操作的,这边他也能操作。
|
|
|
+// Workbook workbook = new HSSFWorkbook(fileInputStream);
|
|
|
+ Workbook workbook = new XSSFWorkbook(fileInputStream);
|
|
|
+
|
|
|
+ // 2.得到表。
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+// // 3.得到行。
|
|
|
+// Row row = sheet.getRow(0);
|
|
|
+// // 4.得到列。
|
|
|
+// Cell cell = row.getCell(0);
|
|
|
+// // 读取值。一定要注意类型,否则会读取失败
|
|
|
+// System.out.println(cell.getStringCellValue());// 字符串类型
|
|
|
+// Cell cell1 = row.getCell(1);
|
|
|
+// System.out.println(cell1.getNumericCellValue());// 数字类型
|
|
|
+ Integer success = 0;//成功数
|
|
|
+ List<String> unDept = new ArrayList<>();//不存在的部门
|
|
|
+ List<String> unUser = new ArrayList<>();//未成功用户
|
|
|
+ List<String> unDoubleUser = new ArrayList<>();//双手机用户
|
|
|
+ for (int i = 0; i < 262; i++) {
|
|
|
+ // 3.得到行。
|
|
|
+ Row row = sheet.getRow(i+1);
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ row.getCell(3).setCellType(CellType.STRING);
|
|
|
+ // 4.得到列。
|
|
|
+ Cell cell = row.getCell(0);//归属机构
|
|
|
+ Cell cell2 = row.getCell(1);//用户姓名
|
|
|
+ Cell cell3 = row.getCell(2);//登录名称
|
|
|
+ Cell cell4 = row.getCell(3);//手机号码
|
|
|
+ Cell cell5 = row.getCell(4);//子系统登录名
|
|
|
+
|
|
|
+ //TODO 查询归属机构的deptId
|
|
|
+ SysDept sysDept = null;
|
|
|
+ String text = cell.getStringCellValue();
|
|
|
+ if(text.indexOf("(")>=0) {
|
|
|
+ Pattern pattern = Pattern.compile("\\((.*?)\\)");
|
|
|
+ Matcher matcher = pattern.matcher(text);
|
|
|
+ while (matcher.find()) {
|
|
|
+ text = matcher.group(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sysDept = sysDeptMapper.selectDeptByName(text);
|
|
|
+ if(sysDept!=null){
|
|
|
+ try {
|
|
|
+ //TODO 插入用户信息接口, 并建立关联
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ sysUser.setUserName(cell2.getStringCellValue());
|
|
|
+ DecimalFormat df = new DecimalFormat("0");
|
|
|
+ sysUser.setLoginName(cell3.getStringCellValue());
|
|
|
+ sysUser.setPhonenumber(cell4.getStringCellValue());
|
|
|
+ sysUser.setPassword("Yining" + cell5 + "@2024!");
|
|
|
+ sysUser.setDeptId(sysDept.getDeptId());
|
|
|
+ sysUser.setParentId(sysDept.getParentId());
|
|
|
+ sysUser.setUserType("00");
|
|
|
+ sysUser.setSex("2");
|
|
|
+ sysUser.setUsbkey("1");
|
|
|
+ Integer result = saveUser(sysUser);
|
|
|
+ if (result > 0) {
|
|
|
+ success = success + 1;
|
|
|
+ }
|
|
|
+ }catch(Exception ex){
|
|
|
+ unDoubleUser.add(cell2.getStringCellValue());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(!unDept.contains(text)){
|
|
|
+ unDept.add(text);
|
|
|
+ }
|
|
|
+ if(!unUser.contains(cell2.getStringCellValue())){
|
|
|
+ unUser.add(cell2.getStringCellValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("未找到部门:"+Arrays.toString(unDept.toArray()));
|
|
|
+ System.out.println("成功数:"+success);
|
|
|
+ System.out.println("未成功数:"+unUser.size());
|
|
|
+ System.out.println("未成功用户:"+Arrays.toString(unUser.toArray()));
|
|
|
+ System.out.println("双手机未成功用户:"+Arrays.toString(unDoubleUser.toArray()));
|
|
|
+
|
|
|
+ // 5.关闭流。
|
|
|
+ fileInputStream.close();
|
|
|
+ }catch(Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //TODO 本地使用·批量插入子系统关联
|
|
|
+ @PostMapping("/testRelate")
|
|
|
+ public void testRelate(){
|
|
|
+ try {
|
|
|
+ String path = "D:\\工作文档\\武汉三环科普睿科\\会议笔记\\";
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(path + "人员信息导入.xlsx");
|
|
|
+ // 1.创建一个工作簿。使得excel能操作的,这边他也能操作。
|
|
|
+// Workbook workbook = new HSSFWorkbook(fileInputStream);
|
|
|
+ Workbook workbook = new XSSFWorkbook(fileInputStream);
|
|
|
|
|
|
+ // 2.得到表。
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
|
|
+ List<Map<String, Object>> danganMap = new ArrayList<>();
|
|
|
+ Map map = new HashMap<>();
|
|
|
+ map.put("danganId", 12);
|
|
|
+ map.put("danganName", "行政办公");
|
|
|
+ Map map1 = new HashMap<>();
|
|
|
+ map1.put("danganId", 13);
|
|
|
+ map1.put("danganName", "人事管理");
|
|
|
+ Map map2 = new HashMap<>();
|
|
|
+ map2.put("danganId", 14);
|
|
|
+ map2.put("danganName", "智慧党建");
|
|
|
+ Map map3 = new HashMap<>();
|
|
|
+ map3.put("danganId", 15);
|
|
|
+ map3.put("danganName", "工程管理");
|
|
|
+ danganMap.add(map);
|
|
|
+ danganMap.add(map1);
|
|
|
+ danganMap.add(map2);
|
|
|
+ danganMap.add(map3);
|
|
|
|
|
|
+ Integer success = 0;
|
|
|
+ for (int i = 0; i < 262; i++) {
|
|
|
+ // 3.得到行。
|
|
|
+ Row row = sheet.getRow(i+1);
|
|
|
+ row.getCell(2).setCellType(CellType.STRING);
|
|
|
+ row.getCell(3).setCellType(CellType.STRING);
|
|
|
+ row.getCell(4).setCellType(CellType.STRING);
|
|
|
+ // 4.得到列。
|
|
|
+ Cell cell = row.getCell(0);//归属机构
|
|
|
+ Cell cell2 = row.getCell(1);//用户姓名
|
|
|
+ Cell cell3 = row.getCell(2);//登录名称
|
|
|
+ Cell cell4 = row.getCell(3);//手机号码
|
|
|
+ Cell cell5 = row.getCell(4);//子系统登录名
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserByLoginName(cell3.getStringCellValue());
|
|
|
+ if(sysUser!=null) {
|
|
|
+ for (Map obj : danganMap) {
|
|
|
+ UserRelate userRelate = new UserRelate();
|
|
|
+ userRelate.setUserId(sysUser.getUserId());
|
|
|
+ userRelate.setUserName(sysUser.getUserName());
|
|
|
+ userRelate.setLoginName(sysUser.getLoginName());
|
|
|
+ userRelate.setDanganId(Long.valueOf(obj.get("danganId").toString()));
|
|
|
+ userRelate.setDanganName(obj.get("danganName").toString());
|
|
|
+ userRelate.setDanganLoginName(cell5.getStringCellValue());
|
|
|
+ userRelate.setStatus("1");
|
|
|
+ userRelate.setRelateTime(new Date());
|
|
|
+ int result = saveRelate(userRelate);
|
|
|
+ if(result>0){
|
|
|
+ success = success+1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("关联成功数:"+success);
|
|
|
+ }catch(Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int saveUser(SysUser user){
|
|
|
+ if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user)))
|
|
|
+ {
|
|
|
+// return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
|
|
+ && UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
|
|
+ {
|
|
|
+// return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ else if (StringUtils.isNotEmpty(user.getEmail())
|
|
|
+ && UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
|
|
+ {
|
|
|
+// return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在").get("code");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ user.setSalt(ShiroUtils.randomSalt());
|
|
|
+ user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
|
|
|
+ user.setCreateBy("admin");
|
|
|
+ return userService.insertUser(user);
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ public int saveRelate(UserRelate userRelate){
|
|
|
+ userRelate.setCreateBy("admin");
|
|
|
+ return userRelateService.insertUserRelate(userRelate);
|
|
|
+ }
|
|
|
}
|