定时用户同步,和组织机构同步
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package com.adc.da.scheduled;
|
||||||
|
|
||||||
|
import com.adc.da.slrs.DataSync.DataSyncController;
|
||||||
|
import com.adc.da.slrs.DataSync.service.IDataSyncService;
|
||||||
|
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时同步用户和组织机构信息
|
||||||
|
*/
|
||||||
|
@EnableScheduling
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class ScheduledSync {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDataSyncService iDataSyncService;
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 */40 * * * ?") //40分钟执行同步一次
|
||||||
|
// @Scheduled(cron="*/5 * * * * ?")
|
||||||
|
@Async
|
||||||
|
public void syncSchedulingTasks() throws Exception {
|
||||||
|
iDataSyncService.orgDataSync(); //时间短
|
||||||
|
iDataSyncService.dataSync(); //时间长
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.adc.da.slrs.DataSync;
|
package com.adc.da.slrs.DataSync;
|
||||||
|
|
||||||
|
import com.adc.da.slrs.DataSync.service.IDataSyncService;
|
||||||
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
||||||
import com.adc.da.slrs.sarInstitution.service.ITsInstitutionService;
|
import com.adc.da.slrs.sarInstitution.service.ITsInstitutionService;
|
||||||
import com.adc.da.slrs.sarInstitution.service.impl.TsInstitutionServiceImpl;
|
import com.adc.da.slrs.sarInstitution.service.impl.TsInstitutionServiceImpl;
|
||||||
@@ -17,9 +18,11 @@ import com.adc.da.sys.service.IOrgEOService;
|
|||||||
import com.adc.da.sys.service.impl.OrgEOServiceImpl;
|
import com.adc.da.sys.service.impl.OrgEOServiceImpl;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
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.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -33,117 +36,22 @@ import java.util.*;
|
|||||||
@RequestMapping("/DataSync")
|
@RequestMapping("/DataSync")
|
||||||
public class DataSyncController {
|
public class DataSyncController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ITsPositionService tsPositionService;
|
private IDataSyncService iDataSyncService;
|
||||||
@Autowired
|
|
||||||
ITsUserService tsUserService;
|
|
||||||
@Autowired
|
|
||||||
ITsInstitutionService tsInstitutionService;
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("同步用户数据")
|
@ApiOperation("同步用户数据")
|
||||||
@PostMapping("/importUserData")
|
@PostMapping("/importUserData")
|
||||||
public String importUserData() throws Exception {
|
public String importUserData() throws Exception {
|
||||||
SyncUserService syncUserService = new SyncUserService();
|
return iDataSyncService.dataSync();
|
||||||
List<String> res = syncUserService.syncFotonUser();
|
|
||||||
//存放岗位信息
|
|
||||||
Map<String, String> positionMap = new HashMap<>();
|
|
||||||
Map<String, String> useDistinct = new HashMap<>();
|
|
||||||
TsPosition position = new TsPosition();
|
|
||||||
position.setCurrent(1);
|
|
||||||
position.setPageSize(100000);
|
|
||||||
IPage<TsPosition> iPage = tsPositionService.getPosition(position);
|
|
||||||
List<TsPosition> positions=iPage.getRecords();
|
|
||||||
if (!positions.isEmpty()) {
|
|
||||||
positions.forEach(tsPosition -> {
|
|
||||||
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for (String s : res) {
|
|
||||||
//获取到所有用户数据
|
|
||||||
List<TsUser> tsUsers = new ArrayList<>();
|
|
||||||
|
|
||||||
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
|
||||||
jsonArray.forEach(object -> {
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
|
||||||
//先获取岗位以及岗位id
|
|
||||||
TsUser tsUser = new TsUser();
|
|
||||||
UserOrgEO userOrgEO = new UserOrgEO();
|
|
||||||
//设置岗位
|
|
||||||
if (null != jsonObject.getString("title")) {
|
|
||||||
if (null == positionMap.get(jsonObject.getString("title"))) {
|
|
||||||
TsPosition tsPosition = new TsPosition();
|
|
||||||
tsPosition.setId(String.valueOf(UUID.randomUUID()));
|
|
||||||
tsPosition.setName(jsonObject.getString("title"));
|
|
||||||
tsPositionService.addPosition(tsPosition);
|
|
||||||
//放入岗位的map集合中
|
|
||||||
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
|
||||||
//放入类中
|
|
||||||
tsUser.setPositionName(tsPosition.getName());
|
|
||||||
tsUser.setPositionId(tsPosition.getId());
|
|
||||||
} else {
|
|
||||||
tsUser.setPositionName(jsonObject.getString("title").trim());
|
|
||||||
tsUser.setPositionId(positionMap.get(jsonObject.getString("title").trim()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//设置其他数据
|
|
||||||
Timestamp createTime = new Timestamp(new Date().getTime());
|
|
||||||
tsUser.setState(jsonObject.getString("userStatus"));
|
|
||||||
tsUser.setUname(null!=jsonObject.getString("name")?jsonObject.getString("name"):"");
|
|
||||||
tsUser.setValidFlag("0");
|
|
||||||
tsUser.setDisableFlag("0");
|
|
||||||
tsUser.setCreationTime(createTime);
|
|
||||||
tsUser.setUserId(jsonObject.getString("userid"));
|
|
||||||
tsUser.setAccount(jsonObject.getString("userid"));
|
|
||||||
tsUser.setInstitutionId(null!=jsonObject.getString("orgNumber")?jsonObject.getString("orgNumber"):"" );
|
|
||||||
tsUser.setInstitutionName(null!=jsonObject.getString("orgName")?jsonObject.getString("orgName"):"" );
|
|
||||||
if (null == useDistinct.get(jsonObject.getString("userid"))) {
|
|
||||||
tsUsers.add(tsUser);
|
|
||||||
|
|
||||||
}
|
|
||||||
useDistinct.put(tsUser.getUserId(),tsUser.getUserId());
|
|
||||||
});
|
|
||||||
tsUserService.saveBatch(tsUsers);
|
|
||||||
}
|
|
||||||
|
|
||||||
return "1";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("同步组织机构")
|
@ApiOperation("同步组织机构")
|
||||||
@PostMapping("/importOrgData")
|
@PostMapping("/importOrgData")
|
||||||
public String importOrgData() throws Exception {
|
public String importOrgData() throws Exception {
|
||||||
SyncUserService syncUserService = new SyncUserService();
|
return iDataSyncService.orgDataSync();
|
||||||
List<String> res = syncUserService.syncFotonOrg();
|
|
||||||
|
|
||||||
//获取到所有用户数据
|
|
||||||
List<String> strings=new ArrayList<>();
|
|
||||||
|
|
||||||
tsInstitutionService.clearData();
|
|
||||||
for (String s : res) {
|
|
||||||
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
|
||||||
jsonArray.forEach(object -> {
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
|
||||||
strings.add(jsonObject.getString("parentOrgNumber"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for (String s : res) {
|
|
||||||
List<TsInstitution> tsInstitutions = new ArrayList<>();
|
|
||||||
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
|
||||||
jsonArray.forEach(object -> {
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
|
||||||
TsInstitution tsInstitution=new TsInstitution();
|
|
||||||
tsInstitution.setId(jsonObject.getString("orgNumber"));
|
|
||||||
tsInstitution.setName(jsonObject.getString("orgName"));
|
|
||||||
tsInstitution.setHasChild(strings.contains(jsonObject.getString("orgNumber"))?"1":"0");
|
|
||||||
tsInstitution.setParentId(jsonObject.getString("parentOrgNumber"));
|
|
||||||
//部门为"null"的数据不保存
|
|
||||||
if (!"null".equals(jsonObject.getString("orgName"))){
|
|
||||||
tsInstitutions.add(tsInstitution);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
tsInstitutionService.saveBatch(tsInstitutions);
|
|
||||||
}
|
|
||||||
return "1";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.adc.da.slrs.DataSync.service;
|
||||||
|
|
||||||
|
public interface IDataSyncService {
|
||||||
|
|
||||||
|
public String dataSync() throws Exception;
|
||||||
|
|
||||||
|
public String orgDataSync() throws Exception;
|
||||||
|
}
|
||||||
+173
@@ -0,0 +1,173 @@
|
|||||||
|
package com.adc.da.slrs.DataSync.service.impl;
|
||||||
|
|
||||||
|
import com.adc.da.slrs.DataSync.service.IDataSyncService;
|
||||||
|
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
||||||
|
import com.adc.da.slrs.sarInstitution.service.ITsInstitutionService;
|
||||||
|
import com.adc.da.slrs.sarPosition.entity.TsPosition;
|
||||||
|
import com.adc.da.slrs.sarPosition.service.ITsPositionService;
|
||||||
|
import com.adc.da.slrs.sarUser.entity.TsUser;
|
||||||
|
import com.adc.da.slrs.sarUser.service.ITsUserService;
|
||||||
|
import com.adc.da.sync.service.SyncUserService;
|
||||||
|
import com.adc.da.sys.entity.UserOrgEO;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DataSyncServiceImpl implements IDataSyncService {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ITsPositionService tsPositionService;
|
||||||
|
@Autowired
|
||||||
|
ITsUserService tsUserService;
|
||||||
|
@Autowired
|
||||||
|
ITsInstitutionService tsInstitutionService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String dataSync() throws Exception {
|
||||||
|
SyncUserService syncUserService = new SyncUserService();
|
||||||
|
List<String> res = syncUserService.syncFotonUser();
|
||||||
|
//存放岗位信息
|
||||||
|
Map<String, String> positionMap = new HashMap<>();
|
||||||
|
Map<String, String> useDistinct = new HashMap<>();
|
||||||
|
TsPosition position = new TsPosition();
|
||||||
|
position.setCurrent(1);
|
||||||
|
position.setPageSize(100000);
|
||||||
|
IPage<TsPosition> iPage = tsPositionService.getPosition(position);
|
||||||
|
List<TsPosition> positions=iPage.getRecords();
|
||||||
|
if (!positions.isEmpty()) {
|
||||||
|
positions.forEach(tsPosition -> {
|
||||||
|
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到数据时,删除系统表中所有用户信息
|
||||||
|
*/
|
||||||
|
if (res.size()>0){
|
||||||
|
tsUserService.deleteUser();
|
||||||
|
}
|
||||||
|
for (String s : res) {
|
||||||
|
//获取到所有用户数据
|
||||||
|
List<TsUser> tsUsers = new ArrayList<>();
|
||||||
|
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
||||||
|
jsonArray.forEach(object -> {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
|
//先获取岗位以及岗位id
|
||||||
|
TsUser tsUser = new TsUser();
|
||||||
|
UserOrgEO userOrgEO = new UserOrgEO();
|
||||||
|
//设置岗位
|
||||||
|
if (null != jsonObject.getString("title")) {
|
||||||
|
//通过岗位名称查询系统表中是否有岗位,有则设定用户的岗位为系统中的岗位,否则新增
|
||||||
|
if (null == positionMap.get(jsonObject.getString("title"))) {
|
||||||
|
TsPosition tsPosition = new TsPosition();
|
||||||
|
tsPosition.setId(String.valueOf(UUID.randomUUID()));
|
||||||
|
tsPosition.setName(jsonObject.getString("title"));
|
||||||
|
tsPositionService.addPosition(tsPosition);
|
||||||
|
//放入岗位的map集合中
|
||||||
|
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
||||||
|
//放入类中
|
||||||
|
tsUser.setPositionName(tsPosition.getName());
|
||||||
|
tsUser.setPositionId(tsPosition.getId());
|
||||||
|
} else {
|
||||||
|
tsUser.setPositionName(jsonObject.getString("title").trim());
|
||||||
|
tsUser.setPositionId(positionMap.get(jsonObject.getString("title").trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//设置其他数据
|
||||||
|
Timestamp createTime = new Timestamp(new Date().getTime());
|
||||||
|
tsUser.setState(jsonObject.getString("userStatus"));
|
||||||
|
tsUser.setUname(null!=jsonObject.getString("name")?jsonObject.getString("name"):"");
|
||||||
|
tsUser.setValidFlag("0");
|
||||||
|
tsUser.setDisableFlag("0");
|
||||||
|
tsUser.setCreationTime(createTime);
|
||||||
|
tsUser.setUserId(jsonObject.getString("userid"));
|
||||||
|
tsUser.setAccount(jsonObject.getString("userid"));
|
||||||
|
tsUser.setInstitutionId(null!=jsonObject.getString("orgNumber")?jsonObject.getString("orgNumber"):"" );
|
||||||
|
tsUser.setInstitutionName(null!=jsonObject.getString("orgName")?jsonObject.getString("orgName"):"" );
|
||||||
|
if (null == useDistinct.get(jsonObject.getString("userid"))) {
|
||||||
|
tsUsers.add(tsUser);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// //测试数据删除
|
||||||
|
// if (! "anbin".equals(jsonObject.getString("userid"))){
|
||||||
|
//
|
||||||
|
// //测试数据修改
|
||||||
|
// if ("anbing".equals(jsonObject.getString("userid"))){
|
||||||
|
// tsUser.setUname("DDDDDD");
|
||||||
|
// tsUsers.add(tsUser);
|
||||||
|
// } else if (null == useDistinct.get(jsonObject.getString("userid"))) {
|
||||||
|
// tsUsers.add(tsUser);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
useDistinct.put(tsUser.getUserId(),tsUser.getUserId());
|
||||||
|
});
|
||||||
|
tsUserService.saveBatch(tsUsers);
|
||||||
|
}
|
||||||
|
|
||||||
|
//测试数据添加
|
||||||
|
// TsUser addUser = new TsUser();
|
||||||
|
// addUser.setState("FFFFFFF");
|
||||||
|
// addUser.setUname("zhaokaiyao");
|
||||||
|
// addUser.setValidFlag("0");
|
||||||
|
// addUser.setDisableFlag("0");
|
||||||
|
// addUser.setCreationTime(new Timestamp(new Date().getTime()));
|
||||||
|
// addUser.setUserId("FFFFFFF");
|
||||||
|
// addUser.setAccount("zhaokaiyao");
|
||||||
|
// addUser.setInstitutionId("10022745");
|
||||||
|
// addUser.setInstitutionName("福田营销其他");
|
||||||
|
//
|
||||||
|
// List<TsUser> addUserList = Arrays.asList(addUser);
|
||||||
|
// tsUserService.saveBatch(addUserList);
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String orgDataSync() throws Exception {
|
||||||
|
SyncUserService syncUserService = new SyncUserService();
|
||||||
|
List<String> res = syncUserService.syncFotonOrg();
|
||||||
|
|
||||||
|
//获取到所有用户数据
|
||||||
|
List<String> strings=new ArrayList<>();
|
||||||
|
|
||||||
|
tsInstitutionService.clearData();
|
||||||
|
for (String s : res) {
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
||||||
|
jsonArray.forEach(object -> {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
|
strings.add(jsonObject.getString("parentOrgNumber"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (String s : res) {
|
||||||
|
List<TsInstitution> tsInstitutions = new ArrayList<>();
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
||||||
|
jsonArray.forEach(object -> {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
|
TsInstitution tsInstitution=new TsInstitution();
|
||||||
|
tsInstitution.setId(jsonObject.getString("orgNumber"));
|
||||||
|
tsInstitution.setName(jsonObject.getString("orgName"));
|
||||||
|
tsInstitution.setHasChild(strings.contains(jsonObject.getString("orgNumber"))?"1":"0");
|
||||||
|
tsInstitution.setParentId(jsonObject.getString("parentOrgNumber"));
|
||||||
|
//部门为"null"的数据不保存
|
||||||
|
if (!"null".equals(jsonObject.getString("orgName"))){
|
||||||
|
tsInstitutions.add(tsInstitution);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tsInstitutionService.saveBatch(tsInstitutions);
|
||||||
|
}
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,10 +3,7 @@ package com.adc.da.slrs.sarUser.dao;
|
|||||||
import com.adc.da.http.ResponseMessage;
|
import com.adc.da.http.ResponseMessage;
|
||||||
import com.adc.da.slrs.sarUser.entity.TsUser;
|
import com.adc.da.slrs.sarUser.entity.TsUser;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Delete;
|
import org.apache.ibatis.annotations.*;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -20,6 +17,9 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface TsUserDao extends BaseMapper<TsUser> {
|
public interface TsUserDao extends BaseMapper<TsUser> {
|
||||||
|
|
||||||
|
@Update("truncate table ts_user")
|
||||||
|
void deleteUser();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户已经绑定的岗位ID
|
* 查询用户已经绑定的岗位ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface ITsUserService extends IService<TsUser> {
|
public interface ITsUserService extends IService<TsUser> {
|
||||||
|
|
||||||
|
void deleteUser();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过机构ID查询人员
|
* 通过机构ID查询人员
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ public class TsUserServiceImpl extends ServiceImpl<TsUserDao, TsUser> implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TsPositionDao tsPositionDao;
|
private TsPositionDao tsPositionDao;
|
||||||
|
|
||||||
|
|
||||||
|
public void deleteUser(){
|
||||||
|
tsUserDao.deleteUser();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过机构ID查询人员
|
* 通过机构ID查询人员
|
||||||
* @return List<TsUser>
|
* @return List<TsUser>
|
||||||
|
|||||||
Reference in New Issue
Block a user