|
@@ -1,5 +1,6 @@
|
|
|
package com.nokia.task;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.jcraft.jsch.JSchException;
|
|
|
import com.jcraft.jsch.SftpException;
|
|
|
import com.nokia.common.exception.MyRuntimeException;
|
|
@@ -7,7 +8,9 @@ import com.nokia.common.gpload.GploadUtil;
|
|
|
import com.nokia.common.gpload.entity.GploadResult;
|
|
|
import com.nokia.common.ssh.SSHUtil;
|
|
|
import com.nokia.dao.AreaDao;
|
|
|
+import com.nokia.dao.UserDao;
|
|
|
import com.nokia.pojo.Area;
|
|
|
+import com.nokia.vo.UserVo;
|
|
|
import com.xxl.job.core.context.XxlJobHelper;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.Data;
|
|
@@ -50,9 +53,11 @@ public class SyncTask {
|
|
|
private final DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH");
|
|
|
private SSHUtil sshUtil;
|
|
|
private final AreaDao areaDao;
|
|
|
+ private final UserDao userDao;
|
|
|
|
|
|
- public SyncTask(AreaDao areaDao) {
|
|
|
+ public SyncTask(AreaDao areaDao, UserDao userDao) {
|
|
|
this.areaDao = areaDao;
|
|
|
+ this.userDao = userDao;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -127,6 +132,7 @@ public class SyncTask {
|
|
|
XxlJobHelper.log("文件 {} 去重", filename);
|
|
|
String inputFilePath = downloadDir + filename;
|
|
|
Path inputPath = Paths.get(inputFilePath);
|
|
|
+ List<Integer> modifiedUsers = new ArrayList<>();
|
|
|
try (CSVParser parser = CSVFormat.DEFAULT.builder().build()
|
|
|
.parse(new InputStreamReader(Files.newInputStream(inputPath), "gbk"));
|
|
|
OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(Paths.get(distinctFilename)),
|
|
@@ -145,6 +151,10 @@ public class SyncTask {
|
|
|
if (CollectionUtils.isEmpty(map)) {
|
|
|
throw new MyRuntimeException("数据为空");
|
|
|
}
|
|
|
+ // 查询所有用户
|
|
|
+ List<UserVo> allUsers = userDao.baseList();
|
|
|
+ Map<String, UserVo> userMap = new HashMap<>();
|
|
|
+ allUsers.forEach(t -> userMap.put(t.getLoginName(), t));
|
|
|
// 查询地区
|
|
|
List<Area> areas = areaDao.getAll();
|
|
|
Map<String, Area> cityMap = new HashMap<>();
|
|
@@ -169,7 +179,7 @@ public class SyncTask {
|
|
|
String phone = t.get(5);
|
|
|
String employeeCode = t.get(6);
|
|
|
Integer provinceId = -1;
|
|
|
- Integer cityId = null;
|
|
|
+ Integer cityId = -1;
|
|
|
Integer areaId = null;
|
|
|
for (Map.Entry<String, Area> tt : cityMap.entrySet()) {
|
|
|
// 匹配地市
|
|
@@ -187,16 +197,35 @@ public class SyncTask {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- printer.printRecord(loginName, orgId, orgName, userId, userName, phone, employeeCode, provinceId, cityId, areaId);
|
|
|
+ printer.printRecord(loginName, orgId, orgName, userId, userName, phone, employeeCode, provinceId,
|
|
|
+ cityId, areaId);
|
|
|
+ // 检查用户信息变化
|
|
|
+ UserVo user = userMap.get(loginName);
|
|
|
+ if (user != null && !cityId.equals(user.getCityId())) {
|
|
|
+ modifiedUsers.add(user.getUserId());
|
|
|
+ log.debug("用户 {} 地市变化: {} -> {}", user.getUserId(), user.getCityId(), cityId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("文件 {} 去重完成", filename);
|
|
|
+ XxlJobHelper.log("文件 {} 去重完成", filename);
|
|
|
+ // 删除本地源文件
|
|
|
+ Files.deleteIfExists(inputPath);
|
|
|
+ log.info("删除本地源文件 {}", filename);
|
|
|
+ XxlJobHelper.log("删除本地源文件 {}", filename);
|
|
|
+ // 检查删除用户
|
|
|
+ List<Integer> deletedUsers = userDao.loginNameNotIn(map.keySet());
|
|
|
+ if (!CollectionUtils.isEmpty(deletedUsers)) {
|
|
|
+ log.error("已删除用户: {}", JSON.toJSONString(deletedUsers));
|
|
|
+ }
|
|
|
+ // 检查权限地市
|
|
|
+ List<Integer> diffUsers = userDao.roleCityDiff();
|
|
|
+ if (!CollectionUtils.isEmpty(diffUsers)) {
|
|
|
+ log.error("权限地市不一致用户: {}", JSON.toJSONString(diffUsers));
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(modifiedUsers)) {
|
|
|
+ log.error("地市变化用户: {}", JSON.toJSONString(modifiedUsers));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- log.info("文件 {} 去重完成", filename);
|
|
|
- XxlJobHelper.log("文件 {} 去重完成", filename);
|
|
|
- // 删除本地源文件
|
|
|
- Files.deleteIfExists(inputPath);
|
|
|
- log.info("删除本地源文件 {}", filename);
|
|
|
- XxlJobHelper.log("删除本地源文件 {}", filename);
|
|
|
}
|
|
|
|
|
|
public void gpload() throws IOException {
|