feat: 分类树标准法规回写接口定时任务
This commit is contained in:
+6
@@ -1,6 +1,7 @@
|
||||
package com.jero.modules.docking.srms.job;
|
||||
|
||||
import com.jero.modules.docking.srms.service.SrmsApiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
@@ -12,6 +13,7 @@ import javax.annotation.Resource;
|
||||
* @author LQT
|
||||
* @date 2024/2/21 16:01
|
||||
*/
|
||||
@Slf4j
|
||||
public class SyncPartStandardJob implements Job {
|
||||
|
||||
@Resource
|
||||
@@ -19,6 +21,10 @@ public class SyncPartStandardJob implements Job {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info("每日分类树标准法规回写开始");
|
||||
// 同步数据
|
||||
srmsApiService.syncPartStandard();
|
||||
// 发送请求
|
||||
srmsApiService.sendPartStandard();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public interface SrmsApiService {
|
||||
* @param
|
||||
* @return com.jero.common.api.vo.Result<java.lang.String>
|
||||
*/
|
||||
void sendPartStandard();
|
||||
void sendPartStandard() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* E采通获取标准信息
|
||||
|
||||
+41
-27
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.jero.common.api.vo.Result;
|
||||
@@ -131,7 +132,7 @@ public class SrmsApiServiceImpl implements SrmsApiService {
|
||||
@Value("${srms.etton_sys_user}")
|
||||
private String ettonSysUser;
|
||||
@Value("${srms.part_standard_url}")
|
||||
private String partStandardUrl;
|
||||
private String partStandardRewriteUrl;
|
||||
|
||||
@Value("${bindPart.pdm_Ip}")
|
||||
private String pdmIp;
|
||||
@@ -700,24 +701,37 @@ public class SrmsApiServiceImpl implements SrmsApiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPartStandard() {
|
||||
try {
|
||||
List<LawsPartStandard> listLawsPartStandard = lawsPartStandardService.list();
|
||||
public void sendPartStandard() throws InterruptedException {
|
||||
List<LawsPartStandard> listLawsPartStandard = lawsPartStandardService.list();
|
||||
int size = listLawsPartStandard.size();
|
||||
log.info("零部件分类回写总数居条数为:{}", size);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
// 每10000条记录为一个子列表
|
||||
int chunkSize = 10000;
|
||||
List<List<LawsPartStandard>> listOfChunks = new ArrayList<>();
|
||||
|
||||
// 使用for循环和subList方法分割列表
|
||||
for (int i = 0; i < size; i += chunkSize) {
|
||||
int end = Math.min(size, i + chunkSize); // 确保不会超出列表的末尾
|
||||
List<LawsPartStandard> chunk = listLawsPartStandard.subList(i, end);
|
||||
listOfChunks.add(chunk);
|
||||
}
|
||||
String batchId = IdWorker.getIdStr();
|
||||
for (int i = 0; i < listOfChunks.size(); i++) {
|
||||
List<LawsPartStandard> list = listOfChunks.get(i);
|
||||
// 判断数据量是否大于指定大小
|
||||
JSONObject all = new JSONObject();
|
||||
JSONObject messageHeader = new JSONObject();
|
||||
String date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
||||
// todo Interface_ID,UUID
|
||||
messageHeader.put("Interface_ID", "");
|
||||
messageHeader.put("UUID", "");
|
||||
messageHeader.put("MessageId", "");
|
||||
messageHeader.put("Sender", "SRMS");
|
||||
messageHeader.put("Receiver", "PDM");
|
||||
messageHeader.put("SendDate", date.substring(0, 8));
|
||||
messageHeader.put("SendTime", date.substring(8));
|
||||
all.put("MessageHeader", messageHeader);
|
||||
all.put(MESSAGE_HANDLER, getMessageHandler("CNHTC_PO1000400", null));
|
||||
JSONObject requests = new JSONObject();
|
||||
// 批次信息
|
||||
requests.put("BatchId", batchId);
|
||||
requests.put("BatchNo", String.valueOf(i + 1));
|
||||
// rows
|
||||
List<JSONObject> listObj = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(listLawsPartStandard)) {
|
||||
for (LawsPartStandard lawsPartStandard : listLawsPartStandard) {
|
||||
for (LawsPartStandard lawsPartStandard : list) {
|
||||
JSONObject rows = new JSONObject();
|
||||
rows.put(PART_CATEGORY_NUM, lawsPartStandard.getPartCategoryNum());
|
||||
rows.put("StandardPdmType", lawsPartStandard.getStandardPdmType());
|
||||
@@ -728,19 +742,19 @@ public class SrmsApiServiceImpl implements SrmsApiService {
|
||||
listObj.add(rows);
|
||||
}
|
||||
}
|
||||
JSONObject requests = new JSONObject();
|
||||
requests.put("Rows", listObj);
|
||||
all.put(REQUESTS, requests);
|
||||
// todo url
|
||||
JSONObject reData = restTemplate.postForObject(partStandardUrl, all, JSONObject.class);
|
||||
log.info(JSON.toJSONString(reData));
|
||||
if (!Objects.isNull(reData) && reData.containsKey("Success") && Objects.equals("true", reData.getString("Success"))) {
|
||||
log.info("分类树标准法规回写接口成功");
|
||||
} else {
|
||||
log.error("分类树标准法规回写接口失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("分类树标准法规回写接口失败", e);
|
||||
// 创建 HttpEntity 包含请求体和头信息
|
||||
HttpHeaders headers = this.getBasicAuthHeaders();
|
||||
HttpEntity<String> entity = new HttpEntity<>(all.toString(), headers);
|
||||
// 打印完整的请求报文信息
|
||||
log.info("零部件分类回写相关信息");
|
||||
log.info("IP: " + pdmIp + partStandardRewriteUrl);
|
||||
log.info("Headers: " + headers);
|
||||
JSONObject reData = restTemplate.postForObject(pdmIp + partStandardRewriteUrl, entity, JSONObject.class);
|
||||
Thread.sleep(3000);
|
||||
log.info("零部件分类回写请求返回");
|
||||
log.info("返回报文: " + JSON.toJSONString(reData));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user