|
@@ -2,18 +2,21 @@ package com.persagy.sso.manage;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.persagy.common.exception.BusinessException;
|
|
|
import com.persagy.common.utils.ResponseResult;
|
|
|
import com.persagy.sso.constant.BaseConstant;
|
|
|
import com.persagy.sso.pojo.dto.*;
|
|
|
import com.persagy.sso.service.*;
|
|
|
import com.persagy.sso.util.BaseUtils;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @ClassName : SynUserManage
|
|
@@ -41,6 +44,10 @@ public class SynUserManage {
|
|
|
private IPersonService personService;
|
|
|
@Autowired
|
|
|
private IAccountService accountService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private IWdAccountService wdAccountService;
|
|
|
|
|
|
/***
|
|
|
* @Description: 保存部门信息
|
|
@@ -159,7 +166,7 @@ public class SynUserManage {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Description: 查询部门信息
|
|
|
+ * @Description: 根据条件查询部门信息
|
|
|
* @Author: xgq
|
|
|
* @Date: 2021/4/15 19:51
|
|
|
* @param queryDeptDTO :
|
|
@@ -194,9 +201,7 @@ public class SynUserManage {
|
|
|
public JSONObject queryAccountByCondition(String username, String token) {
|
|
|
AccountDTO accountDTO = new AccountDTO();
|
|
|
accountDTO.setUsername(username);
|
|
|
- //// TODO: 2021/4/19 根据账号名称查询账号信息
|
|
|
-
|
|
|
-
|
|
|
+ accountDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
ResponseResult result = accountService.queryAccountByCondition(accountDTO);
|
|
|
if(!BaseUtils.CheckResult(result)){
|
|
|
throw new BusinessException("query account info error:"+BaseUtils.getMsg(result) );
|
|
@@ -291,7 +296,8 @@ public class SynUserManage {
|
|
|
createDTO.setAppId(BaseConstant.APP_ID_PC);
|
|
|
createDTO.setUsername(user.getUsername());
|
|
|
createDTO.setAccountType(BaseConstant.ACCOUNT_TYPE_NORMAL);
|
|
|
- createDTO.setAccountSource(BaseConstant.VALID_TRUE);
|
|
|
+ //accountSource:万达:201
|
|
|
+ createDTO.setAccountSource(BaseConstant.ACCOUNT_SOURCE_WD);
|
|
|
//账号有效期,0-期内有效,1-永久有效
|
|
|
createDTO.setValidLast(BaseConstant.VALID_TRUE);
|
|
|
createDTO.setValid(Integer.valueOf(BaseConstant.VALID_TRUE));
|
|
@@ -327,10 +333,10 @@ public class SynUserManage {
|
|
|
* @return: com.persagy.common.utils.ResponseResult
|
|
|
**/
|
|
|
public JSONObject queryPersonByCondition(WdUser user, String token) {
|
|
|
- AccountDTO accountDTO = new AccountDTO();
|
|
|
+ QueryPersonDTO queryPersonDTO = new QueryPersonDTO();
|
|
|
String username = user.getUsername();
|
|
|
- accountDTO.setUsername(username);
|
|
|
- ResponseResult result = personService.queryPersonByCondition(accountDTO,token);
|
|
|
+ queryPersonDTO.setUsername(username);
|
|
|
+ ResponseResult result = personService.queryPersonByCondition(queryPersonDTO,token);
|
|
|
if(!BaseUtils.CheckResult(result)){
|
|
|
throw new BusinessException("query user by username error: " +BaseUtils.getMsg(result));
|
|
|
}
|
|
@@ -349,17 +355,11 @@ public class SynUserManage {
|
|
|
* @Description: 根据角色名称查询角色信息
|
|
|
* @Author: xgq
|
|
|
* @Date: 2021/4/17 19:54
|
|
|
- * @param oaJobName :
|
|
|
+ * @param queryJobDTO :
|
|
|
* @param token
|
|
|
* @return: void
|
|
|
**/
|
|
|
- public JSONArray queryJobBuCondition(String oaJobName, String token) {
|
|
|
- QueryJobDTO queryJobDTO = new QueryJobDTO();
|
|
|
- queryJobDTO.setAccountBelong(BaseConstant.ACCOUNT_TYPE_BUSINESS);
|
|
|
- queryJobDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
- queryJobDTO.setAccountId(BaseConstant.SYSTEM_ID);
|
|
|
- queryJobDTO.setAppId(BaseConstant.APP_ID_PC);
|
|
|
- queryJobDTO.setRoleName(oaJobName);
|
|
|
+ public JSONArray queryJobBuCondition(QueryJobDTO queryJobDTO, String token) {
|
|
|
ResponseResult result = jobService.queryJobBuCondition(queryJobDTO,token);
|
|
|
if(!BaseUtils.CheckResult(result)){
|
|
|
throw new BusinessException("query role by name error: " +BaseUtils.getMsg(result));
|
|
@@ -370,4 +370,227 @@ public class SynUserManage {
|
|
|
}
|
|
|
return roleArray;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 查询需要同步的用户信息
|
|
|
+ * @Author: xgq
|
|
|
+ * @Date: 2021/4/28 16:16
|
|
|
+
|
|
|
+ * @return: java.util.List<com.persagy.sso.pojo.dto.WdUser>
|
|
|
+ **/
|
|
|
+ @DS("syn")
|
|
|
+ public List<WdUser> querySynUserList() {
|
|
|
+ LambdaQueryWrapper<WdUser> queryWrapper = new WdUser.Builder().createQueryWrapper().builderQueryWrapper();
|
|
|
+ List<WdUser> userList = userService.list(queryWrapper);
|
|
|
+ return userList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 根据来源查询账号信息
|
|
|
+ * @Author: xgq
|
|
|
+ * @Date: 2021/4/29 10:20
|
|
|
+ * @param token :
|
|
|
+ * @return: com.alibaba.fastjson.JSONObject
|
|
|
+ **/
|
|
|
+ public JSONArray queryAccountListBySource(String token) {
|
|
|
+ AccountDTO accountDTO = new AccountDTO();
|
|
|
+ accountDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
+ accountDTO.setAccountSource(BaseConstant.ACCOUNT_SOURCE_WD);
|
|
|
+ ResponseResult result = accountService.queryAccountListBySource(accountDTO,token);
|
|
|
+ if(!BaseUtils.CheckResult(result)){
|
|
|
+ throw new BusinessException("query account info by resource error:"+BaseUtils.getMsg(result) );
|
|
|
+ }
|
|
|
+ JSONArray array = BaseUtils.getContent2Array(result);
|
|
|
+ if(null == array || (null !=array && array.size()==0)){
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return array;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 保存账号信息
|
|
|
+ * @Author: xgq
|
|
|
+ * @Date: 2021/4/29 10:49
|
|
|
+ * @param user:
|
|
|
+ * @param token:
|
|
|
+ * @return: void
|
|
|
+ **/
|
|
|
+ @Transactional
|
|
|
+ public void saveAccountItem(WdUser user, String token) {
|
|
|
+ //保存账号信息
|
|
|
+ SaasAccountCreateDTO createDTO = new SaasAccountCreateDTO();
|
|
|
+ createDTO.setAccountBelong(BaseConstant.ACCOUNT_TYPE_BUSINESS);
|
|
|
+ createDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
+ createDTO.setAppId(BaseConstant.APP_ID_PC);
|
|
|
+ createDTO.setUsername(user.getUsername());
|
|
|
+ createDTO.setAccountType(BaseConstant.ACCOUNT_TYPE_NORMAL);
|
|
|
+ //accountSource:万达:201
|
|
|
+ createDTO.setAccountSource(BaseConstant.ACCOUNT_SOURCE_WD);
|
|
|
+ //账号有效期,0-期内有效,1-永久有效
|
|
|
+ createDTO.setValidLast(BaseConstant.VALID_TRUE);
|
|
|
+ createDTO.setValid(Integer.valueOf(BaseConstant.VALID_TRUE));
|
|
|
+ // createDTO.setCasType(BaseConstant.CASE_TYPE_MAJOR);
|
|
|
+ // createDTO.setRoles(Arrays.asList(accountDTO));
|
|
|
+ ResponseResult result = accountService.insertAccount(createDTO,token);
|
|
|
+ if (!BaseUtils.CheckResult(result)) {
|
|
|
+ throw new RuntimeException("save account info error:"+BaseUtils.getMsg(result) );
|
|
|
+ }
|
|
|
+ //保存其他信息
|
|
|
+ //账号id
|
|
|
+ String accountId = BaseUtils.getContentStr(result);
|
|
|
+ WdAccount wdAccount = new WdAccount();
|
|
|
+ wdAccount.setAccountId(accountId);
|
|
|
+ wdAccount.setEmployeeId(user.getEmployeeID());
|
|
|
+ wdAccount.setEmployeeCode(user.getEmployeeCode());
|
|
|
+ wdAccount.setEmployeeName(user.getEmployeeName());
|
|
|
+ wdAccount.setGender(user.getGender());
|
|
|
+ wdAccount.setUsername(user.getUsername());
|
|
|
+ wdAccount.setUnitId(user.getUnitID());
|
|
|
+ wdAccount.setUnitName(user.getUnitName());
|
|
|
+ wdAccount.setJobId(user.getJobId());
|
|
|
+ wdAccount.setJobName(user.getJobName());
|
|
|
+ wdAccount.setEmployeeStatusName(user.getEmployeeStatusName());
|
|
|
+ wdAccount.setEmployeeStatus(user.getEmployeeStatus());
|
|
|
+ wdAccount.setStatus(user.getStatus());
|
|
|
+ wdAccount.setCreateIme(new Date());
|
|
|
+ wdAccount.setUpdateTime(new Date());
|
|
|
+ boolean save = wdAccountService.save(wdAccount);
|
|
|
+ if(!save){
|
|
|
+ throw new BusinessException("save account reflex info error..." );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void updateAccountItem(WdAccount wdAccount, WdUser user, String token) {
|
|
|
+ //重新赋值
|
|
|
+ wdAccount.setEmployeeCode(user.getEmployeeCode());
|
|
|
+ wdAccount.setEmployeeName(user.getEmployeeName());
|
|
|
+ wdAccount.setGender(user.getGender());
|
|
|
+ wdAccount.setUsername(user.getUsername());
|
|
|
+ wdAccount.setUnitId(user.getUnitID());
|
|
|
+ wdAccount.setUnitName(user.getUnitName());
|
|
|
+ wdAccount.setJobId(user.getJobId());
|
|
|
+ wdAccount.setJobName(user.getJobName());
|
|
|
+ wdAccount.setEmployeeStatusName(user.getEmployeeStatusName());
|
|
|
+ wdAccount.setEmployeeStatus(user.getEmployeeStatus());
|
|
|
+ wdAccount.setStatus(user.getStatus());
|
|
|
+ wdAccount.setUpdateTime(new Date());
|
|
|
+ boolean save = wdAccountService.updateById(wdAccount);
|
|
|
+ if(!save){
|
|
|
+ throw new BusinessException("update account reflex info error..." );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<WdAccount> queryAllReflexList() {
|
|
|
+ return wdAccountService.list();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteSynAccount(Map<String, WdAccount> reflexAccountMap, String token) {
|
|
|
+ //整理数据
|
|
|
+ List<String> idList = new ArrayList<>();
|
|
|
+ List<String> accountIdList = new ArrayList<>();
|
|
|
+ reflexAccountMap.entrySet().stream().forEach(
|
|
|
+ s->{
|
|
|
+ WdAccount value = s.getValue();
|
|
|
+ if(null !=value){
|
|
|
+ idList.add(value.getId());
|
|
|
+ accountIdList.add(value.getAccountId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ //删除映射表的信息
|
|
|
+ boolean delete = wdAccountService.removeByIds(idList);
|
|
|
+ if(!delete){
|
|
|
+ throw new BusinessException("delete account reflex info error..." );
|
|
|
+ }
|
|
|
+ //删除账号表的信息
|
|
|
+ AccountDTO accountDTO = new AccountDTO();
|
|
|
+ accountDTO.setAccountBelong(BaseConstant.ACCOUNT_TYPE_BUSINESS);
|
|
|
+ accountDTO.setAccountType(BaseConstant.ACCOUNT_TYPE_NORMAL);
|
|
|
+ accountDTO.setAccountSource(BaseConstant.ACCOUNT_SOURCE_WD);
|
|
|
+ accountDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
+ accountDTO.setAppId(BaseConstant.APP_ID_PC);
|
|
|
+ accountDTO.setIds(accountIdList);
|
|
|
+ ResponseResult result = accountService.deleteByIds(accountDTO,token);
|
|
|
+ if(!BaseUtils.CheckResult(result)){
|
|
|
+ throw new BusinessException("delete account info error..." );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void dealDeletedSynAccount(Map<String, WdAccount> reflexAccountMap, String token) throws Exception{
|
|
|
+ //查询之前同步的账号信息
|
|
|
+ JSONArray array = queryAccountListBySource(token);
|
|
|
+ //如果查询的数量比映射表多,说明有垃圾数据没有清除掉
|
|
|
+ if(null != array){
|
|
|
+ int mapCount = reflexAccountMap.size();
|
|
|
+ int arrayCount = array.size();
|
|
|
+ if(arrayCount > mapCount){
|
|
|
+ //获取多出来的数据删除
|
|
|
+ List<String> exitAccountIdList = new ArrayList<>();
|
|
|
+ reflexAccountMap.entrySet().stream().forEach(
|
|
|
+ s->{
|
|
|
+ WdAccount value = s.getValue();
|
|
|
+ if(null !=value){
|
|
|
+ exitAccountIdList.add(value.getAccountId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ // 获取需要删除的
|
|
|
+ List<String> deleteAccountIdList = new ArrayList<>();
|
|
|
+ for (int i = 0; i <array.size(); i++) {
|
|
|
+ JSONObject jsonObject = array.getJSONObject(i);
|
|
|
+ String id = jsonObject.getString("id");
|
|
|
+ if(!exitAccountIdList.contains(id)){
|
|
|
+ deleteAccountIdList.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(deleteAccountIdList)){
|
|
|
+ //删除账号表的信息
|
|
|
+ AccountDTO accountDTO = new AccountDTO();
|
|
|
+ accountDTO.setAccountBelong(BaseConstant.ACCOUNT_TYPE_BUSINESS);
|
|
|
+ accountDTO.setAccountType(BaseConstant.ACCOUNT_TYPE_NORMAL);
|
|
|
+ accountDTO.setAccountSource(BaseConstant.ACCOUNT_SOURCE_WD);
|
|
|
+ accountDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
+ accountDTO.setAppId(BaseConstant.APP_ID_PC);
|
|
|
+ accountDTO.setIds(deleteAccountIdList);
|
|
|
+ ResponseResult result = accountService.deleteByIds(accountDTO,token);
|
|
|
+ if(!BaseUtils.CheckResult(result)){
|
|
|
+ throw new BusinessException("delete account info error..." );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteAccountReflexById(String id) {
|
|
|
+ boolean result = wdAccountService.removeById(id);
|
|
|
+ if(!result){
|
|
|
+ throw new BusinessException("delete account reflex info error ...");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject queryAccountById(String accountId ,String token) {
|
|
|
+ AccountDTO accountDTO = new AccountDTO();
|
|
|
+ accountDTO.setGroupCode(BaseConstant.GROUP_CODE_WD);
|
|
|
+ accountDTO.setAccountSource(BaseConstant.ACCOUNT_SOURCE_WD);
|
|
|
+ accountDTO.setAccountId(accountId);
|
|
|
+ ResponseResult result = accountService.queryAccountById(accountDTO,token);
|
|
|
+ if(!BaseUtils.CheckResult(result)){
|
|
|
+ throw new BusinessException("query account info by resource error:"+BaseUtils.getMsg(result) );
|
|
|
+ }
|
|
|
+ JSONArray array = BaseUtils.getContent2Array(result);
|
|
|
+ if(null == array || (null !=array && array.size()==0)){
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return array.getJSONObject(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|