定时job生成
continuous-integration/drone/push Build is passing Details

沃森川job同步飞书
YXY 1 year ago
parent b4300cc19f
commit aef8481db4

@ -21,4 +21,9 @@ public class RedisConstants {
*/
public static final String MULTIPLE_TABLE_RECORD = "MULTIPLE_TABLE_RECORD";
/**
* ticketkey
*/
public static final String CJT_TICKET_CACHE_KEY = "TICKET_KEY";
}

@ -49,6 +49,10 @@ public class RedisCache
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
}
public Long getExpireTime(String key){
return redisTemplate.getExpire(key);
}
/**
*
*

@ -1,7 +1,9 @@
package com.ruoyi.flyingbook.controller;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.RedisConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.PdfUtils;
import com.ruoyi.flyingbook.LarkHelper.LarkFileHelper;
import com.ruoyi.flyingbook.domain.EventLog;
@ -20,6 +22,7 @@ import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@Slf4j
@RestController
@ -35,7 +38,8 @@ public class EdiController extends BaseController {
ResourceLoader resourceLoader;
@Autowired
private IEventLogService iEventLogService;
@Autowired
private RedisCache redisCache;
/**
*
*/
@ -65,7 +69,11 @@ public class EdiController extends BaseController {
byte[] bytes = Base64.decodeBase64(request.getEncryptMsg());
bytes = cipher.doFinal(bytes);
String encryptMsg = new String(bytes, StandardCharsets.UTF_8);
log.error("receiveWscTicket encryptMsg:{}",encryptMsg);
log.info("receiveWscTicket encryptMsg:{}",encryptMsg);
JSONObject jsonObject = JSONObject.parseObject(encryptMsg);
JSONObject bizContent = jsonObject.getJSONObject("bizContent");
String appTicket = bizContent.getString("appTicket");
redisCache.setCacheObject(RedisConstants.CJT_TICKET_CACHE_KEY,appTicket,10, TimeUnit.MINUTES);
}catch (Exception e){
log.error("receiveWscTicket error request:{}",JSONObject.toJSONString(request),e);
}

@ -0,0 +1,22 @@
package com.ruoyi.flyingbook.domain;
import lombok.Data;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* erp_lark_relation
*
* @author ruoyi
* @date 2023-07-17
*/
@Data
public class ErpLarkRelation extends BaseEntity {
private Long id;
private String key;
private String method;
private Long flag;
}

@ -0,0 +1,67 @@
package com.ruoyi.flyingbook.mapper;
import com.ruoyi.flyingbook.domain.ErpLarkRelation;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Mapper
*
* @author ruoyi
* @date 2023-07-17
*/
public interface ErpLarkRelationMapper
{
/**
*
*
* @param id ID
* @return
*/
public ErpLarkRelation selectErpLarkRelationById(Long id);
/**
*
*
* @param erpLarkRelation
* @return
*/
public List<ErpLarkRelation> selectErpLarkRelationList(ErpLarkRelation erpLarkRelation);
/**
*
*
* @param erpLarkRelation
* @return
*/
public int insertErpLarkRelation(ErpLarkRelation erpLarkRelation);
/**
*
*
* @param erpLarkRelation
* @return
*/
public int updateErpLarkRelation(ErpLarkRelation erpLarkRelation);
/**
*
*
* @param id ID
* @return
*/
public int deleteErpLarkRelationById(Long id);
/**
*
*
* @param ids ID
* @return
*/
public int deleteErpLarkRelationByIds(Long[] ids);
public List<ErpLarkRelation> queryListByKeyList(@Param("keyList") List<String> keyList,@Param("method") String method);
}

@ -0,0 +1,63 @@
package com.ruoyi.flyingbook.service;
import com.ruoyi.flyingbook.domain.ErpLarkRelation;
import java.util.List;
/**
* Service
*
* @author ruoyi
* @date 2023-07-17
*/
public interface IErpLarkRelationService
{
/**
*
*
* @param id ID
* @return
*/
public ErpLarkRelation selectErpLarkRelationById(Long id);
/**
*
*
* @param erpLarkRelation
* @return
*/
public List<ErpLarkRelation> selectErpLarkRelationList(ErpLarkRelation erpLarkRelation);
/**
*
*
* @param erpLarkRelation
* @return
*/
public int insertErpLarkRelation(ErpLarkRelation erpLarkRelation);
/**
*
*
* @param erpLarkRelation
* @return
*/
public int updateErpLarkRelation(ErpLarkRelation erpLarkRelation);
/**
*
*
* @param ids ID
* @return
*/
public int deleteErpLarkRelationByIds(Long[] ids);
/**
*
*
* @param id ID
* @return
*/
public int deleteErpLarkRelationById(Long id);
}

@ -0,0 +1,97 @@
package com.ruoyi.flyingbook.service.impl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.flyingbook.domain.ErpLarkRelation;
import com.ruoyi.flyingbook.mapper.ErpLarkRelationMapper;
import com.ruoyi.flyingbook.service.IErpLarkRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Service
*
* @author ruoyi
* @date 2023-07-17
*/
@Service
public class ErpLarkRelationServiceImpl implements IErpLarkRelationService
{
@Autowired
private ErpLarkRelationMapper erpLarkRelationMapper;
/**
*
*
* @param id ID
* @return
*/
@Override
public ErpLarkRelation selectErpLarkRelationById(Long id)
{
return erpLarkRelationMapper.selectErpLarkRelationById(id);
}
/**
*
*
* @param erpLarkRelation
* @return
*/
@Override
public List<ErpLarkRelation> selectErpLarkRelationList(ErpLarkRelation erpLarkRelation)
{
return erpLarkRelationMapper.selectErpLarkRelationList(erpLarkRelation);
}
/**
*
*
* @param erpLarkRelation
* @return
*/
@Override
public int insertErpLarkRelation(ErpLarkRelation erpLarkRelation)
{
erpLarkRelation.setCreateTime(DateUtils.getNowDate());
return erpLarkRelationMapper.insertErpLarkRelation(erpLarkRelation);
}
/**
*
*
* @param erpLarkRelation
* @return
*/
@Override
public int updateErpLarkRelation(ErpLarkRelation erpLarkRelation)
{
erpLarkRelation.setUpdateTime(DateUtils.getNowDate());
return erpLarkRelationMapper.updateErpLarkRelation(erpLarkRelation);
}
/**
*
*
* @param ids ID
* @return
*/
@Override
public int deleteErpLarkRelationByIds(Long[] ids)
{
return erpLarkRelationMapper.deleteErpLarkRelationByIds(ids);
}
/**
*
*
* @param id ID
* @return
*/
@Override
public int deleteErpLarkRelationById(Long id)
{
return erpLarkRelationMapper.deleteErpLarkRelationById(id);
}
}

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.flyingbook.mapper.ErpLarkRelationMapper">
<resultMap type="com.ruoyi.flyingbook.domain.ErpLarkRelation" id="ErpLarkRelationResult">
<result property="id" column="id"/>
<result property="key" column="key"/>
<result property="method" column="method"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="flag" column="flag"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectErpLarkRelationVo">
select id, key, method, create_by, create_time, update_by, update_time, flag, remark
from erp_lark_relation
</sql>
<select id="selectErpLarkRelationList" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation"
resultMap="ErpLarkRelationResult">
<include refid="selectErpLarkRelationVo"/>
<where>
<if test="key != null and key != ''">and key = #{key}</if>
<if test="method != null and method != ''">and method = #{method}</if>
<if test="flag != null ">and flag = #{flag}</if>
</where>
</select>
<select id="selectErpLarkRelationById" parameterType="Long" resultMap="ErpLarkRelationResult">
<include refid="selectErpLarkRelationVo"/>
where id = #{id}
</select>
<select id="queryListByKeyList" resultMap="ErpLarkRelationResult">
select `key`, `method`
from erp_lark_relation
where `method` = #{method} and `key` in
<foreach collection="keyList" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
<insert id="insertErpLarkRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation"
useGeneratedKeys="true" keyProperty="id">
insert into erp_lark_relation
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="key != null">key,</if>
<if test="method != null">method,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="flag != null">flag,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="key != null">#{key},</if>
<if test="method != null">#{method},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="flag != null">#{flag},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateErpLarkRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation">
update erp_lark_relation
<trim prefix="SET" suffixOverrides=",">
<if test="key != null">key = #{key},</if>
<if test="method != null">method = #{method},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="flag != null">flag = #{flag},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteErpLarkRelationById" parameterType="Long">
delete
from erp_lark_relation
where id = #{id}
</delete>
<delete id="deleteErpLarkRelationByIds" parameterType="String">
delete from erp_lark_relation where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

@ -98,7 +98,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.authorizeRequests()
// 对于登录login 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/captchaImage", "/approval","/syncEmail","/scheduledReminders",
"/robot/callback", "/sync2Table", "/createPdf", "/cjtTicket").anonymous()
"/robot/callback", "/sync2Table", "/createPdf", "/cjtTicket").anonymous()
.antMatchers(
HttpMethod.GET,
"/*.html",

@ -0,0 +1,41 @@
package com.ruoyi.quartz.domain;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* @author yuxiangyong
* @create 2023-07-17 20:31
*/
@Data
@NoArgsConstructor
public class CJTJobContext implements Serializable {
private String appKey;
private String appSecret;
private String contentType;
public CJTJobContext(String appKey, String appSecret) {
this.appKey = appKey;
this.appSecret = appSecret;
this.contentType = "application/json";
}
/**
* ticket
*/
private String ticket;
/**
* token
*/
private String openToken;
/**
*
*/
private List<String> keyList;
}

@ -0,0 +1,8 @@
package com.ruoyi.quartz.domain;
/**
* @author yuxiangyong
* @create 2023-07-17 20:31
*/
public class CJTJobRequest extends JobRequest{
}

@ -0,0 +1,93 @@
package com.ruoyi.quartz.domain;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import okhttp3.Headers;
import org.springframework.util.StringUtils;
import java.io.Serializable;
/**
* @author yuxiangyong
* @create 2023-07-17 20:31
*/
@Data
@NoArgsConstructor
public class CJTRequest implements Serializable {
/**
*
*/
private String url;
/**
*
*/
private String appKey;
private String appSecret;
/**
* ticketcertificate token
*/
private String appTicket;
private String certificate;
/**
* token
*/
private String openToken;
/**
*
*/
private JSONObject body;
/**
* ticket
*/
public CJTRequest(String url, String appKey, String appSecret) {
this.url = url;
this.appKey = appKey;
this.appSecret = appSecret;
}
/**
* token
*/
public CJTRequest(String url, String appKey, String appSecret, String appTicket, String certificate) {
this.url = url;
this.appKey = appKey;
this.appSecret = appSecret;
this.appTicket = appTicket;
this.certificate = certificate;
}
/**
*
*/
public CJTRequest(String url, String appKey, String appSecret, String openToken) {
this.url = url;
this.appKey = appKey;
this.appSecret = appSecret;
this.openToken = openToken;
}
public Headers buildHeaders(){
Headers.Builder builder = new Headers.Builder();
builder.add("appKey",appKey);
builder.add("appSecret",appSecret);
builder.add("Content-Type","application/json");
if (!StringUtils.isEmpty(openToken)) {
builder.add("openToken", appKey);
}
return builder.build();
}
/**
* tokenbody
*/
public void buildGenerateBody(){
JSONObject body = new JSONObject();
body.put("appTicket",appKey);
body.put("certificate",certificate);
this.body = body;
}
}

@ -0,0 +1,10 @@
package com.ruoyi.quartz.domain;
import java.io.Serializable;
/**
* @author yuxiangyong
* @create 2023-07-17 20:30
*/
public class JobRequest implements Serializable {
}

@ -1,11 +1,10 @@
package com.ruoyi.quartz.helper;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.quartz.domain.CJTRequest;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
@ -25,26 +24,53 @@ public class OkHttpHelper {
public static void post(String url, String body) {
public static JSONObject post(CJTRequest req) {
String body = req.getBody() == null ? "{}" : req.getBody().toJSONString();
Request request = new Request.Builder()
.method("POST", RequestBody.create(MediaType.get("application/json"),body.getBytes(StandardCharsets.UTF_8)))
.url(url)
.headers(req.buildHeaders())
.method("POST",
RequestBody.create(MediaType.get("application/json"),
body.getBytes(StandardCharsets.UTF_8)))
.url(req.getUrl())
.build();
try {
client.newCall(request).execute();
Response execute = client.newCall(request).execute();
ResponseBody responseBody = execute.body();
if (responseBody != null){
return JSONObject.parseObject(responseBody.string());
}
} catch (Exception e) {
log.error("http get 请求失败--{}", e);
}
return null;
}
public static void main(String[] args) {
post("https://open.feishu.cn/open-apis/bot/v2/hook/77f1c976-2418-4e03-bc96-7f14c2c2898e",
"{\n" +
"\t\"msg_type\": \"text\",\n" +
"\t\"content\": {\n" +
"\t\t\"text\": \"<at user_id = \\\"ou_cd09481727e91fce1f12b7b0ed1500d2\\\">YXY</at> text content\"\n" +
"\t}\n" +
"}");
resetTicket();
// getToken();
}
private static void resetTicket(){
CJTRequest cjtRequest = new CJTRequest("https://openapi.chanjet.com/auth/appTicket/resend"
,"wwjSb5Vl"
,"C661F71361CC4C5636396480FF08BBA4");
JSONObject post = post(cjtRequest);
int i = 0;
}
/**
* {"result":false,"error":{"code":"4041","msg":"appTicket已失效","hint":""},"value":null,"traceId":null}
* @return
*/
@SneakyThrows
private static String getToken(){
CJTRequest cjtRequest = new CJTRequest("https://openapi.chanjet.com/v1/common/auth/selfBuiltApp/generateToken"
,"wwjSb5Vl"
,"C661F71361CC4C5636396480FF08BBA4"
,"t-57e995a18de84b588349084cb4e5dc68"
,"OXYwHSWAc22UPHxfIUM0SSFZwziCLmBfOzBaN+PCNp0SNfV3ewYIaWLJCCrYToCU46x3PJO8t4TXV57bGpbiqClld5DiAkQ3EX1qqxoyaE9J0HAsfnp/PkPurKMQewBHICM2oEPRyLU5GUQjTCucfLvO4xT3DKlelbjBsIkKLqs=");
cjtRequest.buildGenerateBody();
JSONObject post = post(cjtRequest);
return null;
}
}

@ -0,0 +1,41 @@
package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.quartz.domain.CJTJobContext;
import com.ruoyi.quartz.domain.CJTRequest;
import com.ruoyi.quartz.helper.OkHttpHelper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Component("ManufactureOrder")
public class ManufactureOrderSyncJob extends SyncAccountsJobAbstract{
private static final String urlPath = "/tplus/api/v2/ManufactureOrderOpenApi/FindVoucherList";
@Override
protected void sync(CJTJobContext context) {
CJTRequest cjtRequest = buildCJTRequest(context);
JSONObject post = OkHttpHelper.post(cjtRequest);
List<JSONObject> result = new ArrayList<>();
List<String> keyList = new ArrayList<>();
Map<String, String> existKeyMap = getExistKeyMap(keyList);
}
@Override
protected void fieldMapping() {
}
@Override
protected String getRequestUrl() {
return REQUEST_ROOT_PATH + urlPath;
}
}

@ -0,0 +1,41 @@
package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.quartz.domain.CJTJobContext;
import com.ruoyi.quartz.domain.CJTRequest;
import com.ruoyi.quartz.helper.OkHttpHelper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Component("PurchaseArrivalOpen")
public class PurchaseArrivalOpenSyncJob extends SyncAccountsJobAbstract{
private static final String urlPath = "/tplus/api/v2/PurchaseArrivalOpenApi/FindVoucherList";
@Override
protected void sync(CJTJobContext context) {
CJTRequest cjtRequest = buildCJTRequest(context);
JSONObject post = OkHttpHelper.post(cjtRequest);
List<JSONObject> result = new ArrayList<>();
List<String> keyList = new ArrayList<>();
Map<String, String> existKeyMap = getExistKeyMap(keyList);
}
@Override
protected void fieldMapping() {
}
@Override
protected String getRequestUrl() {
return REQUEST_ROOT_PATH + urlPath;
}
}

@ -0,0 +1,41 @@
package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.quartz.domain.CJTJobContext;
import com.ruoyi.quartz.domain.CJTRequest;
import com.ruoyi.quartz.helper.OkHttpHelper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Component("PurchaseOrder")
public class PurchaseOrderSyncJob extends SyncAccountsJobAbstract{
private static final String urlPath = "/tplus/api/v2/PurchaseOrderOpenApi/FindVoucherList";
@Override
protected void sync(CJTJobContext context) {
CJTRequest cjtRequest = buildCJTRequest(context);
JSONObject post = OkHttpHelper.post(cjtRequest);
List<JSONObject> result = new ArrayList<>();
List<String> keyList = new ArrayList<>();
Map<String, String> existKeyMap = getExistKeyMap(keyList);
}
@Override
protected void fieldMapping() {
}
@Override
protected String getRequestUrl() {
return REQUEST_ROOT_PATH + urlPath;
}
}

@ -0,0 +1,41 @@
package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.quartz.domain.CJTJobContext;
import com.ruoyi.quartz.domain.CJTRequest;
import com.ruoyi.quartz.helper.OkHttpHelper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Component("SaleDelivery")
public class SaleDeliverySyncJob extends SyncAccountsJobAbstract{
private static final String urlPath = "/tplus/api/v2/SaleDeliveryOpenApi/FindVoucherList";
@Override
protected void sync(CJTJobContext context) {
CJTRequest cjtRequest = buildCJTRequest(context);
JSONObject post = OkHttpHelper.post(cjtRequest);
List<JSONObject> result = new ArrayList<>();
List<String> keyList = new ArrayList<>();
Map<String, String> existKeyMap = getExistKeyMap(keyList);
}
@Override
protected void fieldMapping() {
}
@Override
protected String getRequestUrl() {
return REQUEST_ROOT_PATH + urlPath;
}
}

@ -0,0 +1,41 @@
package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.quartz.domain.CJTJobContext;
import com.ruoyi.quartz.domain.CJTRequest;
import com.ruoyi.quartz.helper.OkHttpHelper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Component("SaleOrderSync")
public class SaleOrderSyncJob extends SyncAccountsJobAbstract{
private static final String urlPath = "/tplus/api/v2/SaleOrderOpenApi/FindVoucherList";
@Override
protected void sync(CJTJobContext context) {
CJTRequest cjtRequest = buildCJTRequest(context);
JSONObject post = OkHttpHelper.post(cjtRequest);
List<JSONObject> result = new ArrayList<>();
List<String> keyList = new ArrayList<>();
Map<String, String> existKeyMap = getExistKeyMap(keyList);
}
@Override
protected void fieldMapping() {
}
@Override
protected String getRequestUrl() {
return REQUEST_ROOT_PATH + urlPath;
}
}

@ -0,0 +1,155 @@
package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.RedisConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.flyingbook.domain.ErpLarkRelation;
import com.ruoyi.flyingbook.mapper.ErpLarkRelationMapper;
import com.ruoyi.quartz.domain.CJTJobContext;
import com.ruoyi.quartz.domain.CJTJobRequest;
import com.ruoyi.quartz.domain.CJTRequest;
import com.ruoyi.quartz.helper.OkHttpHelper;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.ruoyi.quartz.helper.OkHttpHelper.post;
/**
*
* @author yuxiangyong
* @create 2023-07-17 20:29
*/
@Slf4j
public abstract class SyncAccountsJobAbstract {
@Autowired
protected ErpLarkRelationMapper erpLarkRelationMapper;
@Autowired
private RedisCache redisCache;
private static final String CJT_APP_KEY = "wwjSb5Vl";
private static final String CJT_APP_SECRET = "C661F71361CC4C5636396480FF08BBA4";
/**
*
*/
protected static final String REQUEST_ROOT_PATH = "https://openapi.chanjet.com";
/**
* ticket
*/
private static final String REQUEST_RESET_TICKET_PATH = REQUEST_ROOT_PATH + "/auth/appTicket/resend";
/**
* token
*/
private static final String REQUEST_GENERATE_TOKEN_PATH = REQUEST_ROOT_PATH + "/v1/common/auth/selfBuiltApp/generateToken";
/**
*
*/
private static final String CERTIFICATE = "OXYwHSWAc22UPHxfIUM0SSFZwziCLmBfOzBaN+PCNp0SNfV3ewYIaWLJCCrYToCU46x3PJO8t4TXV57bGpbiqClld5DiAkQ3EX1qqxoyaE9J0HAsfnp/PkPurKMQewBHICM2oEPRyLU5GUQjTCucfLvO4xT3DKlelbjBsIkKLqs=";
public void executeSync(CJTJobRequest req){
CJTJobContext context = new CJTJobContext(CJT_APP_KEY,CJT_APP_SECRET);
try {
//重置ticket
resetTicket(context);
//获取token
generateToken(context);
//执行分页同步
sync(context);
}catch (Exception e){
log.error("{} 执行失败 request:{}"
,getClassName()
, JSONObject.toJSONString(req)
,e);
}
}
/**
* url
*/
protected abstract String getRequestUrl();
/**
*
*/
protected String getClassName(){
return this.getClass().getSimpleName();
};
protected abstract void sync(CJTJobContext context);
/**
* 使key
*/
protected Map<String, String> getExistKeyMap(List<String> keyList){
if (CollectionUtils.isEmpty(keyList)){
return new HashMap<>();
}
return erpLarkRelationMapper.queryListByKeyList(keyList, getRequestUrl())
.stream().collect(Collectors.toMap(ErpLarkRelation::getKey, ErpLarkRelation::getMethod, (k1, k2) -> k1));
}
/**
*
*/
protected abstract void fieldMapping();
/**
* ticket,
*/
private void resetTicket(CJTJobContext context){
Long expireTime = redisCache.getExpireTime(RedisConstants.CJT_TICKET_CACHE_KEY);
//重置ticket存在响应时间提前十秒重置
if (expireTime == null || expireTime < 10){
CJTRequest cjtRequest = new CJTRequest(REQUEST_RESET_TICKET_PATH
,context.getAppKey()
,context.getAppSecret());
post(cjtRequest);
}
String ticket = (String)redisCache.getCacheObject(RedisConstants.CJT_TICKET_CACHE_KEY);
context.setTicket(ticket);
}
/**
* token
*/
private void generateToken(CJTJobContext context){
CJTRequest cjtRequest = new CJTRequest(REQUEST_GENERATE_TOKEN_PATH
,context.getAppKey()
,context.getAppSecret()
,context.getTicket()
,CERTIFICATE);
cjtRequest.buildGenerateBody();
JSONObject body = post(cjtRequest);
JSONObject value = body.getJSONObject("value");
String token = value.getString("accessToken");
context.setOpenToken(token);
}
/**
*
*/
protected CJTRequest buildCJTRequest(CJTJobContext context){
CJTRequest req = new CJTRequest(getRequestUrl(), context.getAppKey(), context.getAppSecret(), context.getOpenToken());
buildCJTRequestBody(req);
return req;
}
/**
*
*/
protected void buildCJTRequestBody(CJTRequest request){
JSONObject jsonObject = new JSONObject();
request.setBody(jsonObject);
}
}
Loading…
Cancel
Save