提交 7ff07322 authored 作者: inroi's avatar inroi

微调

上级 d4ac15df
......@@ -94,9 +94,9 @@ public class CommonHttpApi {
return "";
}
public String commonHttpSync() {
public String commonHttpSync(List<Integer> idList) {
try {
return HttpUtil.httpPost("http://192.168.0.9:8089/wx/" + "api/dataSyn/getSyn", "").getBody();
return HttpUtil.httpPost(mallAddress + "api/dataSyn/getSyn", JsonUtil.toString(idList)).getBody();
} catch (Exception e) {
e.printStackTrace();
throw new MallCommonException(LOGIN_MESSAGE);
......@@ -105,7 +105,7 @@ public class CommonHttpApi {
public String commonHttpPostByUpdate(String data) {
try {
return HttpUtil.httpPost("http://192.168.0.9:8089/wx/" + "api/dataSyn/success", data).getBody();
return HttpUtil.httpPost(mallAddress + "api/dataSyn/success", data).getBody();
} catch (Exception e) {
e.printStackTrace();
throw new MallCommonException(LOGIN_MESSAGE);
......@@ -119,7 +119,7 @@ public class CommonHttpApi {
request.putAll(where);
try {
String response = HttpUtil.httpPost("http://192.168.0.9:8089/wx/" + "api/dataSyn/synData", JsonUtil.toString(request)).getBody();
String response = HttpUtil.httpPost(mallAddress + "api/dataSyn/synData", JsonUtil.toString(request)).getBody();
productLogUtil.productSyncLogCreate(Integer.valueOf(config.get("productId")), queueId, name, config.get("docType"), config.get("direction"), JsonUtil.toString(request), response);
return response;
} catch (Exception e) {
......@@ -136,8 +136,8 @@ public class CommonHttpApi {
if (index != 0) {
this.sendThirdParty(receiveAddress, data, index - 1);
} else {
//TODO 关闭同步
//HttpUtil.httpGet("http://integrate-system:8090/integrate/api/turn/off/synchronization");
//关闭同步
HttpUtil.httpGet("http://integrate-system:8090/integrate/api/quartz/job/pause?jobClassName=com.system.quartz.job.MallSynchronizationJob");
DelayQueue<DelayedElement> delayQueue = new DelayQueue<>();
threadPool.execute(() -> {
......@@ -150,8 +150,8 @@ public class CommonHttpApi {
ex.printStackTrace();
}
//TODO 开启同步
//HttpUtil.httpGet("http://integrate-system:8090/integrate/api/start/synchronization");
//开启同步
HttpUtil.httpGet("http://integrate-system:8090/integrate/api/quartz/job/resume?jobClassName=com.system.quartz.job.MallSynchronizationJob");
});
}
......
package com.system.controller;
import com.system.serivce.ISynchronizationService;
import com.system.transfer.mall.MallTriggerSynchronizationInVo;
import com.system.transfer.response.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @author Inori
......@@ -15,12 +14,19 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "自动同步")
@RestController
@RequestMapping("/api")
public class MallSyncController {
public class MallCommonSyncController {
@Autowired
private ISynchronizationService synchronizationService;
@ApiOperation("触发同步")
@PostMapping("/mall/trigger/synchronization")
public RestResponse mallTriggerSynchronization(@RequestBody MallTriggerSynchronizationInVo inVo) {
synchronizationService.mallTriggerSynchronization(inVo);
return RestResponse.success();
}
@ApiOperation("自动同步")
@GetMapping("/mall/synchronization")
public RestResponse mallSynchronization() {
......
......@@ -11,7 +11,7 @@
m.doc_type, m.s_form_id, s.receive_address, s.create_time
FROM tb_synchronization_operation AS s
LEFT JOIN tb_mall_common_config AS m ON s.common_config_id = m.id
WHERE job_class_name = "com.system.quartz.job.mallSynchronizationJob"
WHERE job_class_name = "com.system.quartz.job.MallSynchronizationJob"
</select>
......
......@@ -7,7 +7,6 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -22,9 +21,9 @@ public class MallCommonApi {
private CommonHttpApi commonHttpApi;
public List<Map<String, Object>> getSynchronizationRecords() {
public List<Map<String, Object>> getSynchronizationRecords(List<Integer> idList) {
try {
String response = commonHttpApi.commonHttpSync();
String response = commonHttpApi.commonHttpSync(idList);
System.out.println("同步记录: " + response);
List<Object> objectList = JsonUtil.toList(response, Object.class);
......@@ -44,10 +43,7 @@ public class MallCommonApi {
if (!CollectionUtils.isEmpty(idList)) {
//修改商城是否同步
Map<String, Object> map = new HashMap<>();
map.put("ids", idList);
String response = commonHttpApi.commonHttpPostByUpdate(JsonUtil.toString(map));
System.out.println("更新订单状态: " + response);
String response = commonHttpApi.commonHttpPostByUpdate(JsonUtil.toString(idList));
}
}
......
package com.system.serivce;
import com.system.transfer.mall.MallTriggerSynchronizationInVo;
/**
* @author Inori
*/
public interface ISynchronizationService {
/**
* 触发同步
*
* @param inVo 条件
*/
void mallTriggerSynchronization(MallTriggerSynchronizationInVo inVo);
/**
* 同步对接
*/
void mallSynchronization();
......
......@@ -60,6 +60,7 @@ public class IMallSyncServiceImpl implements IMallSyncService {
return;
}
Map<String, Object> where = new HashMap<>(3);
where.put("dataId", dataId);
if (StringUtil.isNotNull(entryId)) {
......
......@@ -4,12 +4,14 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.system.dao.SynchronizationRecordsMapper;
import com.system.mall.MallCommonApi;
import com.system.serivce.ISynchronizationService;
import com.system.transfer.mall.MallTriggerSynchronizationInVo;
import com.system.transfer.mall.SynchronizationRecordsListOutVoRecords;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
......@@ -43,13 +45,22 @@ public class SynchronizationServiceImpl implements ISynchronizationService {
@Override
public void mallTriggerSynchronization(MallTriggerSynchronizationInVo inVo) {
threadPool.execute(() -> {
this.synchronization(inVo.getIdList());
});
}
@Override
public void mallSynchronization() {
threadPool.execute(this::synchronization);
threadPool.execute(() -> {
this.synchronization(new ArrayList<>());
});
}
@Transactional(rollbackFor = Exception.class)
public void synchronization() {
List<Map<String, Object>> tempList = mallCommonApi.getSynchronizationRecords();
public void synchronization(List<Integer> request) {
List<Map<String, Object>> tempList = mallCommonApi.getSynchronizationRecords(request);
if (!CollectionUtils.isEmpty(tempList)) {
synchronizationRecordsMapper.synchronizationRecordsTempCreate(tempList);
......@@ -78,7 +89,7 @@ public class SynchronizationServiceImpl implements ISynchronizationService {
mallSyncService.synchronization(records.getId(), records.getForm(), records.getDataId(), records.getEntryId());
}
if (Thread.currentThread().isInterrupted()) {
break;
break;
}
}
});
......
package com.system.transfer.mall;
import lombok.Data;
import java.util.List;
/**
* @author Inori
*/
@Data
public class MallTriggerSynchronizationInVo {
/**
* ID列表
*/
private List<Integer> idList;
}
......@@ -72,7 +72,6 @@ public class JsonUtil {
try {
return MAPPER.readValue(json, MAPPER.getTypeFactory().constructMapType(Map.class, kClass, vClass));
} catch (IOException e) {
e.printStackTrace();
log.error("Json解析出错: JsonUtil.toMap(), Json: " + json);
return new HashMap<>(10);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论