|
|
@ -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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|