Commit 0f5c0643 by zhoupeng

提交导入组织架构openapi接口

parent e1bb8058
......@@ -35,12 +35,12 @@ public class QiDianController {
@GetMapping("/toSSOCallback")
@ApiOperation(value = "跳转至企点鉴权地址")
public void toSSOCallback(HttpServletRequest request, HttpServletResponse response) throws IOException {
public String toSSOCallback(HttpServletRequest request, HttpServletResponse response) throws IOException {
String token = request.getParameter("token");
log.info("-------跳转至企点鉴权地址token入参信息-------:{}", token);
// 参数非空校验
ParameterCheckUtils.noNull(ResponseMsg.PARAM_ERROR_TOKEN, token);
response.sendRedirect(qiDianService.getSSOCallback(token));
return qiDianService.getSSOCallback(token);
}
......
......@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@Api(value = "新Cdp同步员工(基础信息)", tags = "新Cdp同步员工(基础信息)")
@RequestMapping(value = "/api/synEmp")
@RequestMapping(value = "/api/synEmpCdp")
public class SyncEmployeCdpController {
@Autowired
......
......@@ -6,9 +6,11 @@ import com.rome.order.domain.constant.RedisConstant;
import com.rome.order.domain.service.OrganizationRedisService;
import com.rome.order.domain.util.PageInfo;
import com.rome.order.domain.util.RedisService;
import com.rome.order.infrastructure.remote.constant.RemoteConstant;
import com.rome.order.infrastructure.remote.dto.res.OrgDTO;
import com.rome.order.infrastructure.remote.facade.OrganizationFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -57,7 +59,7 @@ public class OrganizationRedisServiceImpl implements OrganizationRedisService {
public List<OrgDTO> getAllOrgRedis() {
List<OrgDTO> organizationRedisDTOS = new ArrayList<>();
Object cacheObject = redisService.getValue(RedisConstant.DEPARTMENT_ORGANIZATION);
if (Objects.nonNull(cacheObject)) {
if (Objects.nonNull(cacheObject)&&!RemoteConstant.EMP.equals(cacheObject)) {
organizationRedisDTOS = JSON.parseArray(cacheObject.toString(), OrgDTO.class);
}else{
organizationRedisDTOS = this.getRemoteOrgCdpList();
......
......@@ -14,7 +14,9 @@ import com.rome.order.domain.constant.BaseConstant;
import com.rome.order.domain.constant.QiDianConstant;
import com.rome.order.domain.constant.RedisConstant;
import com.rome.order.domain.service.QiDianService;
import com.rome.order.domain.util.*;
import com.rome.order.domain.util.HttpUtil;
import com.rome.order.domain.util.Md5Utils;
import com.rome.order.domain.util.RedisService;
import com.rome.order.infrastructure.dataobject.SyncOrgDO;
import com.rome.order.infrastructure.remote.constant.QiDianRemoteConstant;
import com.rome.order.infrastructure.remote.constant.RemoteConstant;
......@@ -34,7 +36,10 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
@Slf4j
......@@ -55,6 +60,17 @@ public class QiDianServiceImpl implements QiDianService {
@Value("${qidian.password:}")
private String password;
private String corporationId="0";
private String secret="ajdjhfwjk123";
@Value("${beidou.openapiUrl:}")
private String beidouOpenapiUrl;
private String consoleUrl="https://beidou.test.laiyifen.com/console";
@Override
public String getCacheToken() {
String key = RedisConstant.QIDIAN_TENCENT_ACCESS_TOKEN;
......@@ -73,12 +89,9 @@ public class QiDianServiceImpl implements QiDianService {
@Override
public String getSSOCallback(String code) {
//使用urlencode转义
String redirectUrlEncode = ServletUtils.urlEncode(redirectUrl);
//跳转至企点鉴权地址
String url = QiDianConstant.SKIP_CALLBACK_URL + RemoteConstant.SKIP_SSOCALLBACK_URL + "?code=" + code + "&appid=" + QiDianConstant.APP_ID + "&redirect_url=" + redirectUrlEncode;
log.info("---getSSOCallbackUrl获取的地址为-----:{}", url);
return url;
//三方sso登录
String result = this.login(code);
return result;
}
@Override
......@@ -442,16 +455,12 @@ public class QiDianServiceImpl implements QiDianService {
@Override
public String login(String code) {
try {
String url = String.format(RemoteConstant.SSO_LOGIN_API_URL, code);
Map<String, String> headers = getSSOHeaderMap();
String url = String.format(beidouOpenapiUrl+RemoteConstant.SSO_LOGIN_API_URL, code,consoleUrl);
Map<String, String> headers = HttpUtil.getOpenApiHeaderMap(corporationId, secret);;
log.info("-----第三方sso登录------url:{},headers={}", url, JSONObject.toJSONString(headers));
String result = HttpUtil.httpGet(url, headers);
log.info("-----第三方sso登录,result------:{}", result);
Map map = JSONObject.parseObject(result, Map.class);
if (RemoteConstant.SSO_SUCCESS.equals(Integer.parseInt(map.get("code").toString()))) {
//todo 成功
}
return map.get("msg").toString();
return result;
} catch (Exception e) {
String errorMsg = e.getMessage();
log.error("-----第三方sso登录报错了-------:{}", errorMsg);
......@@ -462,16 +471,12 @@ public class QiDianServiceImpl implements QiDianService {
@Override
public String logout(String account) {
try {
String url = String.format(RemoteConstant.SSO_LOGOUT_API_URL, account);
Map<String, String> headers = getSSOHeaderMap();
String url = String.format(beidouOpenapiUrl+RemoteConstant.SSO_LOGOUT_API_URL, account);
Map<String, String> headers = HttpUtil.getOpenApiHeaderMap(corporationId, secret);
log.info("-----第三方sso用户退出登录------url:{},headers={}", url, JSONObject.toJSONString(headers));
String result = HttpUtil.httpGet(url, headers);
log.info("-----第三方sso用户退出登录,result------:{}", result);
Map map = JSONObject.parseObject(result, Map.class);
if (RemoteConstant.SSO_SUCCESS.equals(Integer.parseInt(map.get("code").toString()))) {
//todo 成功
}
return map.get("msg").toString();
return result;
} catch (Exception e) {
String errorMsg = e.getMessage();
log.error("-----第三方sso登录报错了-------:{}", errorMsg);
......@@ -479,14 +484,5 @@ public class QiDianServiceImpl implements QiDianService {
}
}
private Map<String, String> getSSOHeaderMap() {
Map<String, String> headers = new HashMap<>();
String timestamp = DateUtils.convert(new Date(), DateUtils.YYYYMMDDHHMMSS);
headers.put("corporationId", "0");
headers.put("timestamp", timestamp);
headers.put("sign", HmacSHA256Util.getSign(timestamp));
return headers;
}
}
......@@ -359,6 +359,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return new SimpleDateFormat(dateFormat).format(date);
}
/**
* 获取时间搓
* @return
*/
public static String getUnixTimestamp() {
return String.valueOf(System.currentTimeMillis()/1000);
}
/**
* 推荐使用 getFormatDateTime(Object date)
*
......
......@@ -71,10 +71,9 @@ public class HmacSHA256Util {
* 获取请求头sign
* @return
*/
public static String getSign(String timestamp){
public static String getSign(String secret,String message){
try {
String enterpriseId = "0";
String str = HmacSHA256Util.hmacSHA256(enterpriseId, timestamp);
String str = HmacSHA256Util.hmacSHA256(secret, message);
String encodeStr = Base64.encodeBase64String(str.getBytes());
return encodeStr;
} catch (Exception e) {
......
......@@ -16,6 +16,7 @@ import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -178,4 +179,18 @@ public class HttpUtil {
}
}
public static Map<String, String> getOpenApiHeaderMap(String corporationId,String secret) {
Map<String, String> headers = new HashMap<>();
String timestamp=DateUtils.getUnixTimestamp();
headers.put("corporationId", corporationId);
headers.put("timestamp", timestamp);
String sign = SignUtil.getSign(corporationId,secret,timestamp);
headers.put("sign", sign);
return headers;
}
}
package com.rome.order.domain.util;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
/**
* @Author: zhoupeng
* @createTime: 2023年08月31日 11:49:01
* @version: 1.0
* @Description:
* @copyright:
*/
public class SignUtil {
private static final String SHA265 = "HmacSHA256";
private static final String SHA1 = "HmacSHA1";
/**
* 将加密后的字节数组转换成字符串
*
* @param b 字节数组
* @return 字符串
*/
private static String byteArrayToHexString(byte[] b) {
StringBuilder hs = new StringBuilder();
String stmp;
for (int n = 0; b != null && n < b.length; n++) {
stmp = Integer.toHexString(b[n] & 0XFF);
if (stmp.length() == 1) {
hs.append('0');
}
hs.append(stmp);
}
return hs.toString().toLowerCase();
}
/**
* sha256_HMAC加密
*
* @param source 消息
* @param secret 秘钥
* @param signatureMethod 加密类型
* @return 加密后字符串-base64
*/
private static byte[] sign(String source, String secret, String signatureMethod) {
byte[] bytes = {};
try {
Mac sha256HMAC = Mac.getInstance(signatureMethod);
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), signatureMethod);
sha256HMAC.init(secretKey);
bytes = sha256HMAC.doFinal(source.getBytes());
} catch (Exception e) {
System.out.println("sign error ===========" + e.getMessage());
}
return bytes;
}
// HmacSHA256加密,base64编码
public static String signToBase64BySHA256(String source, String secret) {
byte[] hmacSHA256Bytes = sign(source, secret, SHA265);
return new BASE64Encoder().encode(hmacSHA256Bytes);
}
// HmacSHA256加密,hex编码
public static String signToBaseHexBySHA256(String source, String secret) {
byte[] hmacSHA256Bytes = sign(source, secret, SHA265);
return byteArrayToHexString(hmacSHA256Bytes);
}
public static String getSign(String tenantId,String secret,String timestamp){
String sign = signToBase64BySHA256(tenantId + timestamp, secret);
return sign;
}
public static void main(String[] args) {
String tenantId = "0";
long timestamp = System.currentTimeMillis() / 1000;
System.out.println(timestamp);
String s = signToBase64BySHA256(tenantId + timestamp, "cdpentity123");
System.out.println(s);
}
}
......@@ -52,10 +52,6 @@ public class SyncEmployeeCdpDO {
private String name;
/**
* 性别:1-男,2-女
*/
private Integer gender;
/**
......@@ -70,17 +66,6 @@ public class SyncEmployeeCdpDO {
private String departmentName;
/**
* 手机号
*/
private String mobile;
/**
* 电话号
*/
private String phone;
/**
......
......@@ -26,6 +26,12 @@ public interface SyncEmployeeCdpMapper {
*/
int batchSaveEmpCdp(@Param("empList") List<EmpMainDataResDTO> empList);
/**
* 批量修改同步员工状态信息
* @param empList
* @return
*/
int batchUpdateEmpCdp(@Param("empList") List<EmpMainDataResDTO> empList);
/**
* 根据同步的员工号获取员工信息
......@@ -35,4 +41,12 @@ public interface SyncEmployeeCdpMapper {
*/
List<SyncEmployeeCdpDO> findEmployeeCdpListByUserIds(@Param("userIds") List<Long> userIds);
/**
* 查询所有的邮箱
* @param
* @return
*/
List<String> findEmployeeByEmail();
}
package com.rome.order.infrastructure.remote.dto.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: zhoupeng
* @createTime: 2023年08月31日 13:41:06
* @version: 1.0
* @Description:
* @copyright:
*/
@Data
public class SyncCdpEmpOrgReqDTO {
@ApiModelProperty(value = "导入企业组织架构信息")
List<EmpMainStaffsReqDTO> staffs;
}
......@@ -153,6 +153,7 @@ public class EmpMainDataResDTO {
@ApiModelProperty(value = "是否停用员工 0-企点正常激活 1-企点停用")
private Integer isDisable;
@ApiModelProperty(value = "对应的所有部门")
private String departmentAll;
}
......@@ -61,36 +61,36 @@ elasticjob:
elasticJobClass: com.rome.order.domain.task.SynByStartDateEmpBaseJob
cron: 0 0 0/1 * * ?
shardingTotalCount: 1
SynFailEmployeeJob:
shardingItemParameters: 0=0
elasticJobClass: com.rome.order.domain.task.SynFailEmployeeJob
cron: 0 0/30 * * * ?
shardingTotalCount: 1
SyncAllOrgJob:
shardingItemParameters: 0=0
elasticJobClass: com.rome.order.domain.task.SyncAllOrgJob
cron: 0 0 23 * * ?
shardingTotalCount: 1
SynFailOrgJob:
shardingItemParameters: 0=0
elasticJobClass: com.rome.order.domain.task.SynFailOrgJob
cron: 0 0/30 * * * ?
shardingTotalCount: 1
SyncProductJob:
shardingItemParameters: 0=0
elasticJobClass: com.rome.order.domain.task.SyncProductJob
cron: 0 0 23 * * ?
shardingTotalCount: 1
# SynFailEmployeeJob:
# shardingItemParameters: 0=0
# elasticJobClass: com.rome.order.domain.task.SynFailEmployeeJob
# cron: 0 0/30 * * * ?
# shardingTotalCount: 1
# SyncAllOrgJob:
# shardingItemParameters: 0=0
# elasticJobClass: com.rome.order.domain.task.SyncAllOrgJob
# cron: 0 0 23 * * ?
# shardingTotalCount: 1
# SynFailOrgJob:
# shardingItemParameters: 0=0
# elasticJobClass: com.rome.order.domain.task.SynFailOrgJob
# cron: 0 0/30 * * * ?
# shardingTotalCount: 1
# SyncProductJob:
# shardingItemParameters: 0=0
# elasticJobClass: com.rome.order.domain.task.SyncProductJob
# cron: 0 0 23 * * ?
# shardingTotalCount: 1
reg-center:
max-sleep-time-milliseconds: 8000
server-lists: '10.6.5.66:2181,10.6.5.67:2181,10.6.5.68:2181'
base-sleep-time-milliseconds: 8000
namespace: lyf-qidian-api
namespace: lyf-beidou-cdp-api
rocketmq:
nameServer: '10.6.5.12:9876'
defaultBigRetryNum: 30
producer:
group: lyf-qidian-api
group: lyf-beidou-cdp-api
defaultSmallRetryNum: 20
eureka:
client:
......@@ -158,6 +158,16 @@ tsa:
# 腾讯广告服务地址
remote_address: https://api.e.qq.com/v1.1/
#openapi接口地址
beidou:
openapiUrl: https://beidou.test.laiyifen.com
#企业ID
corporationId: 0
#密钥
secret: ajdjhfwjk123
#是否同步邮件
email: false
......@@ -10,17 +10,15 @@
`employee_number`,
`employee_type`,
`name`,
`gender`,
`department_code`,
`department_name`,
`mobile`,
`phone`,
`company_code`,
`company_name`,
`company_email`,
`is_sync_employee`,
`is_disable`,
`error_msg`,
`department_all`,
`creator`,
`creator_name`,
`updator`,
......@@ -33,17 +31,15 @@
#{item.employeeNumber},
#{item.employeeType},
#{item.name},
#{item.gender},
#{item.departmentCode},
#{item.departmentName},
#{item.mobile},
#{item.phone},
#{item.companyCode},
#{item.companyName},
#{item.companyEmail},
#{item.isSyncEmployee},
#{item.isDisable},
#{item.errorMsg},
#{item.departmentAll},
#{item.creator},
#{item.creatorName},
#{item.updator},
......@@ -52,7 +48,25 @@
</foreach>
</insert>
<!-- 批量修改同步员工信息 -->
<update id="batchUpdateEmpCdp" parameterType="java.util.List">
<foreach close="" collection="empList" index="index" item="item" open="" separator=";">
update sync_employee_cdp
<trim prefix="set" suffixOverrides=","
suffix="where user_id=#{item.userId}">
<if test="item.isSyncEmployee != null">
`is_sync_employee`=#{item.isSyncEmployee},
</if>
<if test="item.departmentAll != null and item.departmentAll!='' ">
`department_all`=#{item.departmentAll},
</if>
<if test="item.errorMsg != null and item.errorMsg!='' ">
`error_msg`=#{item.errorMsg},
</if>
resent_number = resent_number + 1
</trim>
</foreach>
</update>
<!-- 根据同步的员工号获取员工信息 -->
<select id="findEmployeeCdpListByUserIds" parameterType="java.util.List" resultType="com.rome.order.infrastructure.dataobject.SyncEmployeeCdpDO">
......@@ -63,11 +77,8 @@
se.employee_number,
se.employee_type,
se.name,
se.gender,
se.department_code,
se.department_name,
se.mobile,
se.phone,
se.company_code,
se.company_name,
se.company_email,
......@@ -91,5 +102,12 @@
</if>
</select>
<!-- 根据邮箱号进行查询 -->
<select id="findEmployeeByEmail" resultType="java.lang.String">
SELECT
se.company_email
FROM sync_employee_cdp se
where se.is_delete = 0 and se.company_email is not null group by se.company_email
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment