deleted
This commit is contained in:
@@ -8,6 +8,7 @@ import com.cool.store.dto.enterprise.SysDepartmentDTO;
|
||||
import com.cool.store.dto.login.UserIdInfoDTO;
|
||||
import com.cool.store.dto.response.ResultDTO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.mq.util.HttpRestTemplateService;
|
||||
import com.cool.store.request.EnterpriseUserRequest;
|
||||
import com.cool.store.utils.RestTemplateUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -34,10 +36,8 @@ public class ISVHttpRequest {
|
||||
|
||||
@Value("${isv.domain:null}")
|
||||
private String isvDomain;
|
||||
|
||||
@Value("${get.user.id.by.code:null}")
|
||||
private String getUserIdByCode;
|
||||
|
||||
@Resource
|
||||
private HttpRestTemplateService httpRestTemplateService;
|
||||
|
||||
public UserIdInfoDTO getUserIdByCode(String paramStr){
|
||||
String url = isvDomain + "/isv/user/getUserIdByCode?" + paramStr;
|
||||
@@ -54,18 +54,16 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public EnterpriseUserDTO getUserDetailByUserId(String corpId, String userId, String appType){
|
||||
public EnterpriseUserDTO getUserDetailByUserId(String userId){
|
||||
String url = isvDomain + "/isv/user/getUserDetail";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("userId", userId);
|
||||
requestMap.put("appType", appType);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), EnterpriseUserDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), EnterpriseUserDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -73,17 +71,15 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getAdminUserList(String corpId, String appType){
|
||||
public List<String> getAdminUserList(){
|
||||
String url = isvDomain + "/isv/corp/getAdminUserList";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getBody().getData()), String.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getData()), String.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -91,17 +87,15 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public AuthInfoDTO getAuthInfo(String corpId, String appType){
|
||||
public AuthInfoDTO getAuthInfo(){
|
||||
String url = isvDomain + "/isv/corp/getAuthInfo";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), AuthInfoDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), AuthInfoDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -109,18 +103,16 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SysDepartmentDTO> getDepartments(String corpId, String appType, String parentId){
|
||||
public List<SysDepartmentDTO> getDepartments(String parentId){
|
||||
String url = isvDomain + "/isv/corp/getDepartments";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
requestMap.put("parentId", parentId);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getBody().getData()), SysDepartmentDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getData()), SysDepartmentDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -128,17 +120,15 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public AuthScopeDTO getAuthScope(String corpId, String appType){
|
||||
public AuthScopeDTO getAuthScope(){
|
||||
String url = isvDomain + "/isv/corp/getAuthScope";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), AuthScopeDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), AuthScopeDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -146,18 +136,16 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<EnterpriseUserDTO> getDepartmentUsers(String corpId, String appType, String deptId){
|
||||
public List<EnterpriseUserDTO> getDepartmentUsers(String deptId){
|
||||
String url = isvDomain + "/isv/corp/getDepartmentUsers";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
requestMap.put("deptId", deptId);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getBody().getData()), EnterpriseUserDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getData()), EnterpriseUserDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -165,18 +153,16 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<EnterpriseUserDTO> getUserDetailByUserIds(String corpId, List<String> userIdList, String appType) {
|
||||
public List<EnterpriseUserDTO> getUserDetailByUserIds(List<String> userIdList) {
|
||||
String url = isvDomain + "/isv/corp/getDepartmentUsers";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
requestMap.put("userIds", userIdList);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getBody().getData()), EnterpriseUserDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getData()), EnterpriseUserDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -184,19 +170,17 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SysDepartmentDTO> getSubDepartments(String corpId, String appType, String parentId, Boolean fetchChild) {
|
||||
public List<SysDepartmentDTO> getSubDepartments(String parentId, Boolean fetchChild) {
|
||||
String url = isvDomain + "/isv/corp/getSubDepartments";
|
||||
HashMap requestMap = new HashMap();
|
||||
requestMap.put("corpId", corpId);
|
||||
requestMap.put("appType", appType);
|
||||
requestMap.put("parentId", parentId);
|
||||
requestMap.put("fetchChild", fetchChild);
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
ResultDTO responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.get(url, ResultDTO.class, requestMap);
|
||||
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getBody().getData()), SysDepartmentDTO.class);
|
||||
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getData()), SysDepartmentDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
@@ -204,8 +188,8 @@ public class ISVHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<EnterpriseUserRequest> getDeptUsers(String corpId, String deptId, String appType) {
|
||||
List<EnterpriseUserDTO> departmentUsers = getDepartmentUsers(corpId, deptId, appType);
|
||||
public List<EnterpriseUserRequest> getDeptUsers(String deptId) {
|
||||
List<EnterpriseUserDTO> departmentUsers = getDepartmentUsers(deptId);
|
||||
if (CollectionUtils.isEmpty(departmentUsers)){
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
@@ -217,10 +201,10 @@ public class ISVHttpRequest {
|
||||
enterpriseUser.setRemark(enterpriseUserDTO.getRemark());
|
||||
enterpriseUser.setUserId(enterpriseUserDTO.getUserId());
|
||||
if (enterpriseUserDTO.getIsLeaderInDepts() != null) {
|
||||
enterpriseUser.setIsLeaderInDepts(JSONObject.toJSONString(enterpriseUserDTO.getIsLeaderInDepts()));
|
||||
//enterpriseUser.setIsLeaderInDepts(JSONObject.toJSONString(enterpriseUserDTO.getIsLeaderInDepts()));
|
||||
}
|
||||
EnterpriseUserRequest enterpriseUserRequest = new EnterpriseUserRequest();
|
||||
enterpriseUserRequest.setEnterpriseUserDO(enterpriseUser);
|
||||
//enterpriseUserRequest.setEnterpriseUserDO(enterpriseUser);
|
||||
if (CollectionUtils.isNotEmpty(enterpriseUserDTO.getDepartmentLists())) {
|
||||
enterpriseUserRequest.setDepartment(JSONObject.toJSONString(enterpriseUserDTO.getDepartmentLists()));
|
||||
}
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
package com.cool.store.mq.consumer.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.openservices.ons.api.Action;
|
||||
import com.aliyun.openservices.ons.api.ConsumeContext;
|
||||
import com.aliyun.openservices.ons.api.Message;
|
||||
import com.aliyun.openservices.ons.api.MessageListener;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dto.enterprise.EnterpriseInitDTO;
|
||||
import com.cool.store.enums.AppTypeEnum;
|
||||
import com.cool.store.enums.EnterpriseStatusEnum;
|
||||
import com.cool.store.service.EnterpriseInitService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 企业开通初始化
|
||||
*
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.cool.store.mq.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class HttpRestTemplateService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* 获取请求实体对象
|
||||
*
|
||||
* @param object
|
||||
* @param tenantAccessToken
|
||||
* @return
|
||||
*/
|
||||
private HttpEntity getHttpEntity(Object object, String tenantAccessToken) {
|
||||
return new HttpEntity(object, this.getHeaders(tenantAccessToken));
|
||||
}
|
||||
|
||||
public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables , Map<String, String> headMap) {
|
||||
logger.info("getForObject start:url={},responseType={},uriVariables={}", url, responseType.getName(),
|
||||
JSONObject.toJSONString(uriVariables));
|
||||
ResponseEntity<T> result = null;
|
||||
try {
|
||||
//封装请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headMap.forEach((k, v)->{
|
||||
headers.add(k, v);
|
||||
});
|
||||
HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers);
|
||||
result = exchange(url, HttpMethod.GET, formEntity, responseType, uriVariables);
|
||||
} catch (RestClientException e) {
|
||||
logger.error("getForObject error:{}", e);
|
||||
throw new ServiceException(ErrorCodeEnum.UNKNOWN);
|
||||
}
|
||||
logger.info("getForObject end:result={}", JSONObject.toJSONString(result));
|
||||
return result.getBody();
|
||||
}
|
||||
|
||||
public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||
logger.info("getForObject start:url={},responseType={},uriVariables={}", url, responseType.getName(), JSONObject.toJSONString(uriVariables));
|
||||
T result = null;
|
||||
try {
|
||||
result = restTemplate.getForObject(transUrl(url, uriVariables), responseType, uriVariables);
|
||||
} catch (RestClientException e) {
|
||||
logger.error("getForObject error:{}", e);
|
||||
throw new ServiceException(ErrorCodeEnum.UNKNOWN);
|
||||
}
|
||||
logger.info("getForObject end:result={}", JSONObject.toJSONString(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
private String transUrl(String url, Map<String, ?> uriVariables) {
|
||||
StringBuilder finalUrl = new StringBuilder(url);
|
||||
if (Objects.isNull(uriVariables)) {
|
||||
return finalUrl.toString();
|
||||
}
|
||||
if (StringUtils.isNotBlank(url)) {
|
||||
if (url.contains("?")) {
|
||||
if (url.endsWith("?")) {
|
||||
finalUrl.append("1=1");
|
||||
}
|
||||
} else {
|
||||
finalUrl.append("?1=1");
|
||||
}
|
||||
uriVariables.forEach((k, v) -> {
|
||||
finalUrl.append("&").append(k).append("={").append(k).append("}");
|
||||
});
|
||||
|
||||
}
|
||||
return finalUrl.toString();
|
||||
}
|
||||
|
||||
|
||||
public <T> T postForObject(String url, Object request, Class<T> responseType) {
|
||||
logger.info("postForObject start:url={},request={},responseType={}",
|
||||
url, JSONObject.toJSONString(request), responseType.getName());
|
||||
T result = null;
|
||||
try {
|
||||
result = restTemplate.postForObject(url, getHttpEntity(request, null), responseType);
|
||||
} catch (RestClientException e) {
|
||||
logger.error("postForObject error:{}", e);
|
||||
throw e;
|
||||
}
|
||||
logger.info("postForObject end:result={}", JSONObject.toJSONString(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
public <T> T postForObject(String url, Object request, String tenantAccessToken, Class<T> responseType) {
|
||||
logger.info("postForObject start:url={},request={},responseType={}, tenantAccessToken:{}",
|
||||
url, JSONObject.toJSONString(request), responseType.getName(), tenantAccessToken);
|
||||
T result = null;
|
||||
try {
|
||||
result = restTemplate.postForObject(url, getHttpEntity(request, tenantAccessToken), responseType);
|
||||
} catch (RestClientException e) {
|
||||
logger.error("postForObject error:{}", JSONObject.toJSONString(result));
|
||||
logger.error("postForObject error:{}", e);
|
||||
throw e;
|
||||
}
|
||||
logger.info("postForObject end:result={}", JSONObject.toJSONString(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Headers
|
||||
*
|
||||
* @param tenantAccessToken
|
||||
* @return
|
||||
*/
|
||||
private MultiValueMap<String, String> getHeaders(String tenantAccessToken) {
|
||||
MultiValueMap<String, String> headers = new LinkedMultiValueMap();
|
||||
if (StringUtils.isNotEmpty(tenantAccessToken)) {
|
||||
headers.add("Authorization", "Bearer " + tenantAccessToken);
|
||||
}
|
||||
headers.add("Content-Type", "application/json");
|
||||
return headers;
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(String uri, HttpMethod httpMethod, HttpEntity httpEntity,
|
||||
Class<T> responseEntity, Map<String, ?> params) {
|
||||
List<String> queryStrings = Lists.newArrayList();
|
||||
if (!CollectionUtils.isEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
queryStrings.add(k + "=" + v);
|
||||
});
|
||||
}
|
||||
String queryString = null;
|
||||
if (!CollectionUtils.isEmpty(queryStrings)) {
|
||||
queryString = String.join("&", queryStrings);
|
||||
}
|
||||
if (StringUtils.isNotBlank(queryString)) {
|
||||
uri = uri + "?" + queryString;
|
||||
}
|
||||
ResponseEntity<T> exchange = null;
|
||||
logger.info("start exchange=uri:{},httpMethod:{},httpEntity:{},responseEntity:{},params:{}", uri,
|
||||
httpMethod.toString(), httpEntity.toString(), responseEntity.toString(),
|
||||
Objects.nonNull(params) ? params.toString() : null);
|
||||
try {
|
||||
exchange = restTemplate.exchange(uri, httpMethod, httpEntity, responseEntity);
|
||||
} catch (HttpStatusCodeException e) {
|
||||
logger.error("exchange err, resp={}", e.getResponseBodyAsString());
|
||||
} catch (Exception e) {
|
||||
logger.error("exchange err:", e);
|
||||
}
|
||||
logger.info("end exchange=exchange:{},", exchange);
|
||||
return exchange;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
|
||||
import com.cool.store.entity.EnterpriseConfigDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface EnterpriseConfigService {
|
||||
|
||||
EnterpriseConfigDO selectByEnterpriseId();
|
||||
|
||||
/**
|
||||
* 根据dbName获取dbServer
|
||||
* @param dbName
|
||||
* @return
|
||||
*/
|
||||
EnterpriseConfigDO getDbInfoByDbName(String dbName);
|
||||
|
||||
/**
|
||||
* 获取dbServer
|
||||
* @return
|
||||
*/
|
||||
List<EnterpriseConfigDO> getDistinctDbServer();
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.dto.enterprise.EnterpriseOpenMsg;
|
||||
import com.cool.store.enums.AppTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: EnterpriseInitService
|
||||
* @Description:
|
||||
* @date 2023-05-29 15:43
|
||||
*/
|
||||
public interface EnterpriseInitService {
|
||||
|
||||
void sync(String userName, String userId, Long regionId);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: EnterpriseInitService
|
||||
* @Description:
|
||||
* @date 2023-05-29 15:43
|
||||
*/
|
||||
public interface EnterpriseSyncService {
|
||||
|
||||
void syncAll();
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.request.EnterpriseUserRequest;
|
||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
||||
@@ -23,14 +22,6 @@ public interface EnterpriseUserService {
|
||||
|
||||
List<String> initUserRole(List<EnterpriseUserPageVO> enterpriseUserList);
|
||||
|
||||
/**
|
||||
* 获取人员所属部门
|
||||
* @param enterpriseId
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getUserRegion(List<String> userIdList);
|
||||
|
||||
/**
|
||||
* 更新用户的部门全路径
|
||||
* @param user
|
||||
@@ -38,6 +29,6 @@ public interface EnterpriseUserService {
|
||||
*/
|
||||
void updateUserDeptPath(EnterpriseUserRequest user, Map<String, String> deptIdMap);
|
||||
|
||||
EnterpriseUserDO selectByUserIdIgnoreActive(String userId);
|
||||
EnterpriseUserDO getUserInfoByUserId(String userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.service.EnterpriseConfigService;
|
||||
import com.cool.store.dao.EnterpriseConfigDAO;
|
||||
import com.cool.store.entity.EnterpriseConfigDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName EnterpriseConfigServiceImpl
|
||||
* @Description 用一句话描述什么
|
||||
*/
|
||||
@Service(value = "enterpriseConfigService")
|
||||
@Slf4j
|
||||
public class EnterpriseConfigServiceImpl implements EnterpriseConfigService {
|
||||
|
||||
@Resource
|
||||
private EnterpriseConfigDAO enterpriseConfigDAO;
|
||||
|
||||
@Override
|
||||
public EnterpriseConfigDO selectByEnterpriseId() {
|
||||
//return enterpriseConfigDAO.selectByEnterpriseId(enterpriseId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnterpriseConfigDO getDbInfoByDbName(String dbName) {
|
||||
return enterpriseConfigDAO.getDbInfoByDbName(dbName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnterpriseConfigDO> getDistinctDbServer() {
|
||||
return enterpriseConfigDAO.getDistinctDbServer();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dto.enterprise.*;
|
||||
import com.cool.store.http.ISVHttpRequest;
|
||||
import com.cool.store.service.EnterpriseSyncService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: EnterpriseInitService
|
||||
* @Description: 企业初始化
|
||||
* @date 2023-05-26 16:28
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
||||
@Resource
|
||||
private ISVHttpRequest isvHttpRequest;
|
||||
|
||||
@Override
|
||||
public void syncAll() {
|
||||
//同步部门
|
||||
List<SysDepartmentDTO> departments = isvHttpRequest.getSubDepartments(CommonConstants.ROOT_DEPT_ID_STR, true);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.dao.*;
|
||||
@@ -9,14 +8,10 @@ import com.cool.store.entity.*;
|
||||
import com.cool.store.request.EnterpriseUserRequest;
|
||||
import com.cool.store.service.EnterpriseUserService;
|
||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.collections4.SetUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -95,68 +90,15 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
}
|
||||
enterpriseUserList.add(enterpriseUserDO);
|
||||
}
|
||||
enterpriseUserDAO.batchUpdateDiffUserDiffRegionIds(enterpriseUserList);
|
||||
//enterpriseUserDAO.batchUpdateDiffUserDiffRegionIds(enterpriseUserList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnterpriseUserPageVO> listUser(String userName, String deptId,
|
||||
String orderBy, String orderRule,
|
||||
Long roleId, Integer userStatus, Integer pageNum, Integer pageSize, String jobNumber, String regionId, Boolean hasPage) {
|
||||
if (hasPage){
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
}
|
||||
List<EnterpriseUserDO> enterpriseUserList = new ArrayList<>();
|
||||
//企微用户 用户名在数据表中加密,需要再次请求企业端接口根据名称去筛选数据
|
||||
if(roleId!=null){
|
||||
enterpriseUserList = enterpriseUserDAO.fuzzyUsersByDepartment(deptId, roleId, orderBy, orderRule, userName, jobNumber, userStatus, null,regionId);
|
||||
}else {
|
||||
enterpriseUserList= enterpriseUserDAO.fuzzyUsersByNotRole(deptId, orderBy, orderRule, userName, jobNumber, userStatus, null,regionId);
|
||||
}
|
||||
List<EnterpriseUserPageVO> resultList = new ArrayList<>();
|
||||
if(CollectionUtils.isEmpty(enterpriseUserList)){
|
||||
return resultList;
|
||||
}
|
||||
resultList = EnterpriseUserPageVO.transUserDOToVO(enterpriseUserList);
|
||||
//填充角色信息如果存在角色信息
|
||||
List<String> userIdList = initUserRole(resultList);
|
||||
//根据人员查询该人员所在部门集合
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(userIdList);
|
||||
//regionids 集合
|
||||
List<String> regionIds = ListUtils.emptyIfNull(userRegionMappingDOS).stream().map(UserRegionMappingDO::getRegionId).distinct().collect(Collectors.toList());
|
||||
|
||||
List<RegionDO> regionDOs = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(regionIds)){
|
||||
regionDOs = regionDAO.getRegionByRegionIds(regionIds);
|
||||
}
|
||||
//部门map KV key-部门id value-部门名称
|
||||
Map<String, String> regionMap = ListUtils.emptyIfNull(regionDOs)
|
||||
.stream()
|
||||
.filter(a->a.getId()!=null&&a.getName()!=null)
|
||||
.collect(Collectors.toMap(data->data.getId().toString(), RegionDO::getName, (a, b) -> a));
|
||||
//人员所在部门map key-人员id value-部门set集合(set去重)
|
||||
Map<String, Set<String>> userRegionMap = ListUtils.emptyIfNull(userRegionMappingDOS)
|
||||
.stream().filter(a->a.getId()!=null&&a.getRegionId()!=null)
|
||||
.collect(Collectors.groupingBy(UserRegionMappingDO::getUserId,
|
||||
Collectors.mapping(UserRegionMappingDO::getRegionId, Collectors.toSet())));
|
||||
|
||||
resultList.stream()
|
||||
.forEach(data->{
|
||||
if(MapUtils.isNotEmpty(userRegionMap)&&MapUtils.isNotEmpty(regionMap)) {
|
||||
Set<String> regions = userRegionMap.get(data.getUserId());
|
||||
String deptNames = SetUtils.emptyIfNull(regions)
|
||||
.stream()
|
||||
.map(dept -> regionMap.get(dept.toString()))
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.joining(CommonConstants.COMMA));
|
||||
data.setDepartment(deptNames);
|
||||
}
|
||||
});
|
||||
// 添加至常用联系人
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
List<String> userIds = enterpriseUserList.stream().map(EnterpriseUserDO::getUserId).collect(Collectors.toList());
|
||||
//lruService.putRecentUseUser(enterpriseId, UserHolder.getUser().getUserId(), userIds);
|
||||
}
|
||||
return resultList;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addUserRegionMappingDO(String userId,String regionId,CurrentUser currentUser){
|
||||
@@ -212,45 +154,6 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
return userIdList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getUserRegion(List<String> userIdList) {
|
||||
Map<String, String> resultMap = Maps.newHashMap();
|
||||
//根据人员查询该人员所在部门集合
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(userIdList);
|
||||
//regionids 集合
|
||||
List<String> regionIds = ListUtils.emptyIfNull(userRegionMappingDOS).stream()
|
||||
.map(UserRegionMappingDO::getRegionId).distinct().collect(Collectors.toList());
|
||||
|
||||
List<RegionDO> regionDOs = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(regionIds)){
|
||||
regionDOs = regionDAO.getRegionByRegionIds(regionIds);
|
||||
}
|
||||
//部门map KV key-部门id value-部门名称
|
||||
Map<String, String> regionMap = ListUtils.emptyIfNull(regionDOs)
|
||||
.stream()
|
||||
.filter(a->a.getId()!=null&&a.getName()!=null)
|
||||
.collect(Collectors.toMap(data->data.getId().toString(), RegionDO::getName, (a, b) -> a));
|
||||
//人员所在部门map key-人员id value-部门set集合(set去重)
|
||||
Map<String, Set<String>> userRegionMap = ListUtils.emptyIfNull(userRegionMappingDOS)
|
||||
.stream().filter(a->a.getId()!=null&&a.getRegionId()!=null)
|
||||
.collect(Collectors.groupingBy(UserRegionMappingDO::getUserId,
|
||||
Collectors.mapping(UserRegionMappingDO::getRegionId, Collectors.toSet())));
|
||||
userIdList.stream()
|
||||
.forEach(userId->{
|
||||
if(MapUtils.isNotEmpty(userRegionMap)&&MapUtils.isNotEmpty(regionMap)) {
|
||||
Set<String> regions = userRegionMap.get(userId);
|
||||
|
||||
String deptNames = SetUtils.emptyIfNull(regions)
|
||||
.stream()
|
||||
.map(dept -> regionMap.get(dept.toString()))
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.joining(CommonConstants.COMMA));
|
||||
resultMap.put(userId, deptNames);
|
||||
}
|
||||
});
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserDeptPath(EnterpriseUserRequest user, Map<String, String> deptIdMap) {
|
||||
List<String> departmentLists = user.getDepartmentLists();
|
||||
@@ -271,12 +174,11 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
deptList.add(data);
|
||||
});
|
||||
user.setDepartments("[" + String.join(",", deptList) + "]");
|
||||
user.getEnterpriseUserDO().setDepartments("[" + String.join(",", deptList) + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnterpriseUserDO selectByUserIdIgnoreActive(String userId) {
|
||||
return enterpriseUserDAO.selectByUserIdIgnoreActive(userId);
|
||||
public EnterpriseUserDO getUserInfoByUserId(String userId) {
|
||||
return enterpriseUserDAO.getUserInfoById(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.context.DataSourceContext;
|
||||
import com.cool.store.dao.*;
|
||||
import com.cool.store.dto.login.RefreshUser;
|
||||
import com.cool.store.entity.EnterpriseConfigDO;
|
||||
import com.cool.store.entity.EnterpriseDO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
@@ -34,11 +32,6 @@ import java.util.Objects;
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LoginServiceImpl implements LoginService {
|
||||
|
||||
@Resource
|
||||
private EnterpriseConfigDAO enterpriseConfigDAO;
|
||||
@Resource
|
||||
private EnterpriseDAO enterpriseDAO;
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
@@ -58,28 +51,13 @@ public class LoginServiceImpl implements LoginService {
|
||||
if (StringUtils.isEmpty(corpId)) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_NOT_EXIST);
|
||||
}
|
||||
EnterpriseConfigDO enterpriseConfig = enterpriseConfigDAO.getConfigByCorpIdAndAppType(corpId, appType);
|
||||
if (enterpriseConfig == null) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_INIT);
|
||||
}
|
||||
EnterpriseDO enterprise = enterpriseDAO.getEnterpriseById();
|
||||
if (enterprise == null || enterprise.getStatus() == CommonConstants.ZERO) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_INIT);
|
||||
}
|
||||
CurrentUser currentUser = new CurrentUser();
|
||||
RefreshUser refreshUser = new RefreshUser();
|
||||
String dbName = enterpriseConfig.getDbName();
|
||||
// 切到企业库
|
||||
DataSourceContext.setDataSourceType(dbName);
|
||||
// 查企业用户
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(userId);
|
||||
if(enterpriseUser == null){
|
||||
throw new ServiceException(ErrorCodeEnum.NOT_AUTH);
|
||||
}
|
||||
//冻结登录 超登用户过滤
|
||||
if (enterprise.getStatus() == CommonConstants.HUNDRED && !StringUtils.equals(enterpriseUser.getUserId(), "a100000001")) {
|
||||
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR.getCode(), "企业被冻结");
|
||||
}
|
||||
SysRoleDO sysRole = sysRoleDAO.getHighestPrioritySysRoleDoByUserId(userId);
|
||||
if(Objects.isNull(sysRole)){
|
||||
log.info("当前用户没角色:{}", userId);
|
||||
@@ -97,19 +75,15 @@ public class LoginServiceImpl implements LoginService {
|
||||
enterpriseUser.setAvatar(finalAvatar);
|
||||
enterpriseUser.setFaceUrl(finalAvatar);
|
||||
currentUser.setUserId(enterpriseUser.getUserId());
|
||||
currentUser.setDbName(enterpriseConfig.getDbName());
|
||||
currentUser.setIsAdmin(enterpriseUser.getIsAdmin());
|
||||
currentUser.setMainCorpId(enterpriseConfig.getMainCorpId());
|
||||
//设置当前登录人使用的企业相关信息
|
||||
currentUser.setRoleAuth(sysRole.getRoleAuth());
|
||||
currentUser.setSysRoleDO(sysRole);
|
||||
currentUser.setEnterpriseId(enterprise.getId());
|
||||
//生成令牌
|
||||
RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
|
||||
String token = randomNumberGenerator.nextBytes().toHex();
|
||||
String refreshToken = randomNumberGenerator.nextBytes().toHex();
|
||||
currentUser.setName(enterpriseUser.getName());
|
||||
currentUser.setDingCorpId(enterpriseConfig.getDingCorpId());
|
||||
currentUser.setAccessToken(token);
|
||||
currentUser.setAppType(appType);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
Reference in New Issue
Block a user