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

微调

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