畅捷通报表
continuous-integration/drone/push Build is passing Details

畅捷通报表
YXY 1 year ago
parent 4b74756d9c
commit 75dd0d70e1

@ -62,9 +62,11 @@ public interface ErpLarkTempRelationMapper
*/ */
public int deleteErpLarkTempRelationByIds(Long[] ids); public int deleteErpLarkTempRelationByIds(Long[] ids);
public int updateByMethod(@Param("method") String method, @Param("flag") Long flag); public Long selectMaxId(@Param("method") String method, @Param("flag") Long flag,@Param("key") String key);
public int deleteByMethod(@Param("method") String method,@Param("flag") Long flag); public int updateByMethod(@Param("method") String method, @Param("flag") Long flag,@Param("id") Long id,@Param("key") String key);
public int deleteByMethod(@Param("method") String method,@Param("flag") Long flag,@Param("id") Long id,@Param("key") String key);
public int batchInsert(@Param("erpLarkTempRelationList") List<ErpLarkTempRelation> erpLarkTempRelationList); public int batchInsert(@Param("erpLarkTempRelationList") List<ErpLarkTempRelation> erpLarkTempRelationList);

@ -1,34 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.flyingbook.mapper.ErpLarkTempRelationMapper"> <mapper namespace="com.ruoyi.flyingbook.mapper.ErpLarkTempRelationMapper">
<resultMap type="com.ruoyi.flyingbook.domain.ErpLarkTempRelation" id="ErpLarkTempRelationResult"> <resultMap type="com.ruoyi.flyingbook.domain.ErpLarkTempRelation" id="ErpLarkTempRelationResult">
<result property="id" column="id" /> <result property="id" column="id"/>
<result property="key" column="key" /> <result property="key" column="key"/>
<result property="larkKey" column="lark_key" /> <result property="larkKey" column="lark_key"/>
<result property="method" column="method" /> <result property="method" column="method"/>
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time"/>
<result property="flag" column="flag" /> <result property="flag" column="flag"/>
<result property="remark" column="remark" /> <result property="remark" column="remark"/>
</resultMap> </resultMap>
<sql id="selectErpLarkTempRelationVo"> <sql id="selectErpLarkTempRelationVo">
select id, key, lark_key, method, create_by, create_time, update_by, update_time, flag, remark from erp_lark_temp_relation select id,
`key`,
lark_key,
method,
create_by,
create_time,
update_by,
update_time,
flag,
remark
from erp_lark_temp_relation
</sql> </sql>
<select id="selectErpLarkTempRelationList" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation" resultMap="ErpLarkTempRelationResult"> <select id="selectErpLarkTempRelationList" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation"
resultMap="ErpLarkTempRelationResult">
<include refid="selectErpLarkTempRelationVo"/> <include refid="selectErpLarkTempRelationVo"/>
<where> <where>
<if test="key != null and key != ''"> and key = #{key}</if> <if test="key != null and key != ''">and `key` = #{key}</if>
<if test="larkKey != null and larkKey != ''"> and lark_key = #{larkKey}</if> <if test="larkKey != null and larkKey != ''">and lark_key = #{larkKey}</if>
<if test="method != null and method != ''"> and method = #{method}</if> <if test="method != null and method != ''">and method = #{method}</if>
<if test="flag != null "> and flag = #{flag}</if> <if test="flag != null ">and flag = #{flag}</if>
</where> </where>
order by id
</select> </select>
<select id="selectErpLarkTempRelationById" parameterType="Long" resultMap="ErpLarkTempRelationResult"> <select id="selectErpLarkTempRelationById" parameterType="Long" resultMap="ErpLarkTempRelationResult">
@ -36,7 +48,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id} where id = #{id}
</select> </select>
<insert id="insertErpLarkTempRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation" useGeneratedKeys="true" keyProperty="id"> <insert id="insertErpLarkTempRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation"
useGeneratedKeys="true" keyProperty="id">
insert into erp_lark_temp_relation insert into erp_lark_temp_relation
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="key != null">key,</if> <if test="key != null">key,</if>
@ -48,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="flag != null">flag,</if> <if test="flag != null">flag,</if>
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="key != null">#{key},</if> <if test="key != null">#{key},</if>
<if test="larkKey != null">#{larkKey},</if> <if test="larkKey != null">#{larkKey},</if>
@ -59,7 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="flag != null">#{flag},</if> <if test="flag != null">#{flag},</if>
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
</trim> </trim>
</insert> </insert>
<update id="updateErpLarkTempRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation"> <update id="updateErpLarkTempRelation" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation">
@ -79,7 +92,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<delete id="deleteErpLarkTempRelationById" parameterType="Long"> <delete id="deleteErpLarkTempRelationById" parameterType="Long">
delete from erp_lark_temp_relation where id = #{id} delete
from erp_lark_temp_relation
where id = #{id}
</delete> </delete>
<delete id="deleteErpLarkTempRelationByIds" parameterType="String"> <delete id="deleteErpLarkTempRelationByIds" parameterType="String">
@ -89,27 +104,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</delete> </delete>
<select id="selectMaxId" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation" resultType="java.lang.Long">
select id
from erp_lark_temp_relation
where `method` = #{method} and flag = #{flag} and `key` = #{key}
order by id desc
limit 1
</select>
<update id="updateByMethod" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation"> <update id="updateByMethod" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation">
update erp_lark_relation update erp_lark_temp_relation
set flag = #{flag} set flag = #{flag}
where method = #{method} where method = #{method} and `key` = #{key}
and #{id} >= id
</update> </update>
<update id="deleteByMethod" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation"> <update id="deleteByMethod" parameterType="com.ruoyi.flyingbook.domain.ErpLarkRelation">
delete from erp_lark_relation delete
where method = #{method} and flag = #{flag} from erp_lark_temp_relation
where method = #{method}
and flag = #{flag}
and `key` = #{key}
and #{id} >= id
</update> </update>
<insert id="batchInsert" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation" useGeneratedKeys="true" keyProperty="id"> <insert id="batchInsert" parameterType="com.ruoyi.flyingbook.domain.ErpLarkTempRelation" useGeneratedKeys="true"
insert into erp_lark_temp_relation(lark_key,`method`,create_by,create_time,flag) keyProperty="id">
values <foreach collection="erpLarkTempRelationList" item="item" separator=","> insert into erp_lark_temp_relation(`key`,lark_key,`method`,create_by,create_time,flag)
( values
#{item.larkKey}, <foreach collection="erpLarkTempRelationList" item="item" separator=",">
#{item.method}, (
#{item.createBy}, #{item.key},
#{item.createTime}, #{item.larkKey},
#{item.flag} #{item.method},
) #{item.createBy},
</foreach> #{item.createTime},
#{item.flag}
)
</foreach>
</insert> </insert>
</mapper> </mapper>

@ -50,4 +50,6 @@ public class CJTJobContext implements Serializable {
private LarkCompanyRelation companyRelation; private LarkCompanyRelation companyRelation;
private LarkTableRelation tableRelation; private LarkTableRelation tableRelation;
private Long erpLarkTempRelationMaxId;
} }

@ -39,6 +39,8 @@ public class CJTRequest implements Serializable {
*/ */
private JSONObject jsonBody; private JSONObject jsonBody;
private String taskSessionId;
/** /**
* *
*/ */

@ -20,10 +20,11 @@ import com.ruoyi.flyingbook.mapper.LarkCompanyRelationMapper;
import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper; import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper;
import com.ruoyi.quartz.domain.*; import com.ruoyi.quartz.domain.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -37,6 +38,7 @@ import static com.ruoyi.quartz.helper.OkHttpHelper.post;
* @create 2023-07-17 20:29 * @create 2023-07-17 20:29
*/ */
@Slf4j @Slf4j
@Component("syncReportJob")
public class SyncReportJob { public class SyncReportJob {
@Autowired @Autowired
@ -174,7 +176,7 @@ public class SyncReportJob {
protected void sync(CJTJobContext context) { protected void sync(CJTJobContext context) {
List<String> errorMessageList = new ArrayList<>(); List<String> errorMessageList = new ArrayList<>();
JSONObject cjtRequestReport = new JSONObject(); JSONObject cjtRequestReport = new JSONObject();
CJTRequestReportBody cjtRequestBody = new CJTRequestReportBody(0, PAGE_SIZE, getReportName(), getQueryFields()); CJTRequestReportBody cjtRequestBody = new CJTRequestReportBody(1, PAGE_SIZE, getReportName(), getQueryFields());
cjtRequestReport.put("request", cjtRequestBody); cjtRequestReport.put("request", cjtRequestBody);
CJTRequest cjtRequest = buildCJTRequest(context, cjtRequestReport); CJTRequest cjtRequest = buildCJTRequest(context, cjtRequestReport);
@ -191,6 +193,7 @@ public class SyncReportJob {
log.error("{} exception", this.getClassName(), e); log.error("{} exception", this.getClassName(), e);
pageList.add(cjtRequestBody.getPageIndex()); pageList.add(cjtRequestBody.getPageIndex());
} finally { } finally {
cjtRequestBody.setTaskSessionID(cjtRequest.getTaskSessionId());
cjtRequestBody.addPage(); cjtRequestBody.addPage();
} }
} while (flag); } while (flag);
@ -208,11 +211,21 @@ public class SyncReportJob {
} }
private void preSync(CJTJobContext context) { private void preSync(CJTJobContext context) {
erpLarkTempRelationMapper.updateByMethod(getReportName(), FlagStatus.DELETED.getCode()); CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt());
if (cjtAccountEnum == null){
return;
}
Long maxId = erpLarkTempRelationMapper.selectMaxId(getReportName(), FlagStatus.OK.getCode(),cjtAccountEnum.getAppKey());
context.setErpLarkTempRelationMaxId(maxId);
erpLarkTempRelationMapper.updateByMethod(getReportName(), FlagStatus.DELETED.getCode(),maxId,cjtAccountEnum.getAppKey());
} }
private void finish(CJTJobContext context) { private void finish(CJTJobContext context) {
try { try {
CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt());
if (cjtAccountEnum == null){
return;
}
LarkCompanyRelation companyRelation = context.getCompanyRelation(); LarkCompanyRelation companyRelation = context.getCompanyRelation();
LarkTableRelation tableRelation = context.getTableRelation(); LarkTableRelation tableRelation = context.getTableRelation();
LarkTableRequest request = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableRelation.getToTableId()); LarkTableRequest request = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableRelation.getToTableId());
@ -233,7 +246,7 @@ public class SyncReportJob {
larkKeyList = new ArrayList<>(); larkKeyList = new ArrayList<>();
} }
} }
erpLarkTempRelationMapper.deleteByMethod(getReportName(), FlagStatus.DELETED.getCode()); erpLarkTempRelationMapper.deleteByMethod(getReportName(), FlagStatus.DELETED.getCode(),context.getErpLarkTempRelationMaxId(),cjtAccountEnum.getAppKey());
} catch (Exception e) { } catch (Exception e) {
log.info("Sync report job finish error", e); log.info("Sync report job finish error", e);
} }
@ -243,6 +256,9 @@ public class SyncReportJob {
cjtRequest.setOpenToken(generateToken(context)); cjtRequest.setOpenToken(generateToken(context));
//请求接口并序列化数据 //请求接口并序列化数据
CJTResponseReportBodyDetail bodyDetail = request(cjtRequest); CJTResponseReportBodyDetail bodyDetail = request(cjtRequest);
if (bodyDetail == null){
return Boolean.FALSE;
}
//实际返回数据 //实际返回数据
List<CJTResponseReportBodyDetailRow> rows = bodyDetail.getRows(); List<CJTResponseReportBodyDetailRow> rows = bodyDetail.getRows();
if (CollectionUtils.isNotEmpty(rows)) { if (CollectionUtils.isNotEmpty(rows)) {
@ -253,15 +269,15 @@ public class SyncReportJob {
throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey)); throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey));
} }
} }
return CollectionUtils.isNotEmpty(rows); return CollectionUtils.isNotEmpty(rows) && StringUtils.isNotBlank(cjtRequest.getTaskSessionId());
} }
protected Map<String, Object> buildLarkBody(CJTResponseReportBodyDetailRow rowDetail) { protected Map<String, Object> buildLarkBody(CJTResponseReportBodyDetailRow rowDetail) {
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("仓库", rowDetail.getWarehouse()); body.put("仓库", rowDetail.getWarehouse());
body.put("存货编码", rowDetail.getInventoryCode()); body.put("存货编码", rowDetail.getInventoryCode());
body.put("现存量", rowDetail.getBaseQuantity()); body.put("现存量", StringUtils.isNotBlank(rowDetail.getBaseQuantity()) ? Double.valueOf(rowDetail.getBaseQuantity()) : 0D);
body.put("可用量", rowDetail.getCanuseBaseQuantity()); body.put("可用量", StringUtils.isNotBlank(rowDetail.getCanuseBaseQuantity()) ? Double.valueOf(rowDetail.getCanuseBaseQuantity()) : 0D);
return body; return body;
} }
@ -286,7 +302,7 @@ public class SyncReportJob {
//在飞书创建一行并根据创建返回的行id在本地保留一条映射纪律 //在飞书创建一行并根据创建返回的行id在本地保留一条映射纪律
BatchCreateAppTableRecordRespBody resp = larkTableHelper.addTableRecordBatch(addRecordRequest); BatchCreateAppTableRecordRespBody resp = larkTableHelper.addTableRecordBatch(addRecordRequest);
for (AppTableRecord record : resp.getRecords()) { for (AppTableRecord record : resp.getRecords()) {
buildTempList(waitCreateList,record.getRecordId()); buildTempList(waitCreateList,record.getRecordId(),cjt);
} }
if (CollectionUtils.isNotEmpty(waitCreateList)){ if (CollectionUtils.isNotEmpty(waitCreateList)){
erpLarkTempRelationMapper.batchInsert(waitCreateList); erpLarkTempRelationMapper.batchInsert(waitCreateList);
@ -298,13 +314,18 @@ public class SyncReportJob {
return errorKey; return errorKey;
} }
private void buildTempList(List<ErpLarkTempRelation> waitCreateList,String recordId){ private void buildTempList(List<ErpLarkTempRelation> waitCreateList,String recordId, String cjt){
CjtAccountEnum byCode = CjtAccountEnum.getByCode(cjt);
if (byCode == null){
return;
}
ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation(); ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();
erpLarkTempRelation.setCreateTime(new Date()); erpLarkTempRelation.setCreateTime(new Date());
erpLarkTempRelation.setCreateBy("System"); erpLarkTempRelation.setCreateBy("System");
erpLarkTempRelation.setMethod(getReportName()); erpLarkTempRelation.setMethod(getReportName());
erpLarkTempRelation.setFlag(FlagStatus.OK.getCode()); erpLarkTempRelation.setFlag(FlagStatus.OK.getCode());
erpLarkTempRelation.setLarkKey(recordId); erpLarkTempRelation.setLarkKey(recordId);
erpLarkTempRelation.setKey(byCode.getAppKey());
waitCreateList.add(erpLarkTempRelation); waitCreateList.add(erpLarkTempRelation);
} }
@ -401,10 +422,11 @@ public class SyncReportJob {
protected CJTResponseReportBodyDetail request(CJTRequest req) { protected CJTResponseReportBodyDetail request(CJTRequest req) {
String post = post(req); String post = post(req);
CJTResponseReportBody responseBody = JSONObject.parseObject(post, CJTResponseReportBody.class); CJTResponseReportBody responseBody = JSONObject.parseObject(post, CJTResponseReportBody.class);
if (!"0".equals(responseBody.getStatus())) { if (responseBody.getStatus() != 0) {
log.error("{} exception", this.getClassName(), responseBody.getErrorMessage()); log.error("{} exception", this.getClassName(), responseBody.getErrorMessage());
throw new RuntimeException(buildErrorBody(req, Arrays.asList(responseBody.getErrorMessage()))); throw new RuntimeException(buildErrorBody(req, Arrays.asList(responseBody.getErrorMessage())));
} }
req.setTaskSessionId(responseBody.getTaskSessionID());
return responseBody.getDataSource(); return responseBody.getDataSource();
} }

Loading…
Cancel
Save