提交 d4ac15df authored 作者: inroi's avatar inroi

微调

上级 303f56ee
......@@ -9,7 +9,7 @@ import com.system.model.DelayedElement;
import com.system.model.InitConnectParam;
import com.system.utils.HttpUtil;
import com.system.utils.JsonUtil;
import com.system.utils.MallLogUtil;
import com.system.utils.ProductLogUtil;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -45,13 +45,12 @@ public class CommonHttpApi {
private InitConnectParamMapper initConnectParamMapper;
@Autowired
private MallLogUtil mallLogUtil;
private ProductLogUtil productLogUtil;
@PostConstruct
public void init() {
initConnectParam = initConnectParamMapper.selectOne(new QueryWrapper<InitConnectParam>().last("LIMIT 1"));
System.out.println("++++++" + initConnectParam);
if (StringUtil.isNotNull(initConnectParam)) {
mallAddress = initConnectParam.getMallAddress();
}
......@@ -113,22 +112,20 @@ public class CommonHttpApi {
}
}
public String commonHttpGet(Map<String, String> config, String queueId, String name, List<String> keyList, Map<String, Object> where) {
public String commonHttpSyncData(Map<String, String> config, String queueId, String name, List<String> keyList, Map<String, Object> where) {
Map<String, Object> request = new HashMap<>(3);
request.put("formId", config.get("sFormId"));
request.put("fieldKeys", String.join(",", keyList));
request.put("filterString", this.stringWhere(where));
request.put("form", config.get("sFormId"));
request.put("fields", String.join(",", keyList));
request.putAll(where);
String response;
try {
response = HttpUtil.httpPost("", JsonUtil.toString(request)).getBody();
mallLogUtil.mallLogCreate(name, config.get("docType"), queueId, Integer.valueOf(config.get("operation")), JsonUtil.toString(request), response);
String response = HttpUtil.httpPost("http://192.168.0.9:8089/wx/" + "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) {
e.printStackTrace();
throw new MallCommonException(LOGIN_MESSAGE);
}
return response;
}
public String sendThirdParty(String receiveAddress, String data, int index) {
......@@ -154,7 +151,7 @@ public class CommonHttpApi {
}
//TODO 开启同步
HttpUtil.httpGet("http://integrate-system:8090/integrate/api/start/synchronization");
//HttpUtil.httpGet("http://integrate-system:8090/integrate/api/start/synchronization");
});
}
......
......@@ -20,6 +20,9 @@ public interface Constants {
String SUCCESS_NAME = "success";
String CODE_NAME = "code";
String DATE_NAME = "data";
......
......@@ -7,7 +7,8 @@
<select id="mallCommonConfigList" parameterType="java.lang.Integer" resultType="com.system.transfer.form.MallCommonConfigListOutVoRecords">
SELECT
id, platform_product_relation_id, doc_type, s_form_id, `name`,direction, operation, entry_name, custom_sql, create_time
id, platform_product_relation_id, doc_type, s_form_id, `name`, direction,
operation, encapsulation_format, entry_name, custom_sql, create_time
FROM tb_mall_common_config WHERE operation = #{operation}
</select>
......@@ -17,7 +18,8 @@
<select id="mallCommonConfigGetList" resultType="com.system.transfer.form.MallCommonConfigListOutVoRecords">
SELECT
m1.id, m1.platform_product_relation_id, m1.doc_type, m1.s_form_id, m1.name, m1.direction, m1.operation, m1.entry_name, m1.custom_sql, m1.create_time
m1.id, m1.platform_product_relation_id, m1.doc_type, m1.s_form_id, m1.name, m1.direction,
m1.operation, m1.encapsulation_format, m1.entry_name, m1.custom_sql, m1.create_time
FROM tb_mall_common_config AS m1 INNER JOIN (
SELECT
platform_product_relation_id, s_form_id, MIN(operation) AS operation
......@@ -31,7 +33,8 @@
<select id="getMallCommonConfigById" parameterType="java.lang.Integer" resultType="com.system.transfer.form.MallCommonConfigListOutVoRecords">
SELECT
id, platform_product_relation_id, doc_type, s_form_id, `name`,direction, operation, entry_name, custom_sql, create_time
id, platform_product_relation_id, doc_type, s_form_id, `name`, direction,
operation, encapsulation_format, entry_name, custom_sql, create_time
FROM tb_mall_common_config WHERE id = #{id}
</select>
......
......@@ -8,9 +8,9 @@
SELECT
s.id, s.platform_product_relation_id, s.job_class_name, s.common_config_id,
k.doc_type, k.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
LEFT JOIN tb_kingdee_common_config AS k ON s.common_config_id = k.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"
</select>
......
......@@ -22,7 +22,7 @@
INSERT INTO tb_mall_synchronization_record_temp (fid, data_id, entry_id, form, operation) VALUES
<foreach collection="tempList" item="item" separator=",">
(#{item.fid}, #{item.dataId}, #{item.entryId}, #{item.sFormId}, #{item.operation})
(#{item.id}, #{item.dataId}, #{item.entryId}, #{item.form}, #{item.operation})
</foreach>
ON DUPLICATE KEY UPDATE
fid = VALUES (fid), data_id = VALUES (data_id), entry_id = VALUES (entry_id),
......@@ -46,7 +46,7 @@
INSERT INTO tb_mall_synchronization_record (fid, data_id, entry_id, form, operation) VALUES
<foreach collection="tempList" item="item" separator=",">
(#{item.fid}, #{item.dataId}, #{item.entryId}, #{item.sFormId}, #{item.operation})
(#{item.id}, #{item.dataId}, #{item.entryId}, #{item.form}, #{item.operation})
</foreach>
ON DUPLICATE KEY UPDATE
fid = VALUES (fid), data_id = VALUES (data_id), entry_id = VALUES (entry_id),
......
......@@ -25,6 +25,7 @@ public class MallCommonApi {
public List<Map<String, Object>> getSynchronizationRecords() {
try {
String response = commonHttpApi.commonHttpSync();
System.out.println("同步记录: " + response);
List<Object> objectList = JsonUtil.toList(response, Object.class);
if (!CollectionUtils.isEmpty(objectList)) {
......
......@@ -3,6 +3,7 @@ package com.system.mall;
import com.system.api.CommonApi;
import com.system.api.CommonHttpApi;
import com.system.constants.Constants;
import com.system.constants.MallConstants;
import com.system.transfer.form.MallFieldMappingListOutVoRecords;
import com.system.utils.FormFieldMappingUtil;
import com.system.utils.JsonUtil;
......@@ -30,18 +31,19 @@ public class MallCommonSyncApi {
List<MallFieldMappingListOutVoRecords> fieldList = FormFieldMappingUtil.encapsulationMapping(config.get("formFieldMappingDetail"));
List<String> keyList = fieldList.stream().map(MallFieldMappingListOutVoRecords::getFieldBeforeMapping).collect(Collectors.toList());
String response = commonHttpApi.commonHttpGet(config, queueId, name, keyList, where);
String response = commonHttpApi.commonHttpSyncData(config, queueId, name, keyList, where);
System.out.println("同步记录详细数据: " + response);
Map<String, Object> map = JsonUtil.toMap(response, String.class, Object.class);
if (!CollectionUtils.isEmpty(map)) {
if (Constants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.SUCCESS_NAME)))) {
if (MallConstants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.CODE_NAME)))) {
List<Object> objectList = JsonUtil.toList(JsonUtil.toString(map.get("data")), Object.class);
List<Map<String, Object>> dataList = objectList.stream().map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, Object.class)).collect(Collectors.toList());
result.put("data", CommonApi.encapsulationData(config, queueId, dataList, fieldList));
result.put("success", true);
}
} else if (!Constants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.SUCCESS_NAME))) && map.containsKey(Constants.ERROR_MESSAGE)) {
} else if (!MallConstants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.CODE_NAME))) && map.containsKey(Constants.ERROR_MESSAGE)) {
result.put("message", map.get(Constants.ERROR_MESSAGE));
result.put("success", false);
} else {
......
......@@ -45,7 +45,7 @@ public class IMallSyncServiceImpl implements IMallSyncService {
@Override
public void synchronization(Integer id, String sFormId, Integer dataId, Integer entryId) {
List<Map<String, String>> configList = mallCommonSyncConstants.get(sFormId);
if (!CollectionUtils.isEmpty(configList)) {
if (CollectionUtils.isEmpty(configList)) {
synchronizationRecordsMapper.synchronizationRecordsUpdate(new SynchronizationRecordsUpdateInVo(id, SnowFlakeIdUtil.generateId().toString(), "商城同步失败! sFormId为: " + sFormId + " 的商城表单不存在", 2));
return;
}
......@@ -61,7 +61,6 @@ public class IMallSyncServiceImpl implements IMallSyncService {
}
Map<String, Object> where = new HashMap<>(3);
where.put("form", sFormId);
where.put("dataId", dataId);
if (StringUtil.isNotNull(entryId)) {
where.put("entryId", entryId);
......@@ -78,10 +77,10 @@ public class IMallSyncServiceImpl implements IMallSyncService {
}
private void encapsulationRequest(Map<String, String> config, Map<String, String> operation, String queueId, Integer id, Map<String, Object> data) {
Map<String, Object> request = new HashMap<>();
Map<String, Object> request = new HashMap<>(3);
request.put("docType", config.get("docType"));
request.put("updateType", "update");
request.put("data", data.get(Constants.DATE_NAME));
request.put("data", JsonUtil.toList(JsonUtil.toString(data.get(Constants.DATE_NAME)), Object.class));
String response = mallCommonSyncApi.sendThirdParty(operation.get("receiveAddress"), JsonUtil.toString(request));
//记录第三方日志
productLogUtil.productHttpLogCreate(Integer.valueOf(config.get("productId")), queueId, id, config.get("name"), config.get("docType"), config.get("direction"), JsonUtil.toString(request), response);
......
......@@ -74,8 +74,8 @@ public class SynchronizationServiceImpl implements ISynchronizationService {
}
for (SynchronizationRecordsListOutVoRecords records : recordsList) {
if (!"LQKJ_IMSSync".equals(records.getSFormId())) {
mallSyncService.synchronization(records.getId(), records.getSFormId(), records.getDataId(), records.getEntryId());
if (!"LQKJ_IMSSync".equals(records.getForm())) {
mallSyncService.synchronization(records.getId(), records.getForm(), records.getDataId(), records.getEntryId());
}
if (Thread.currentThread().isInterrupted()) {
break;
......
......@@ -33,9 +33,9 @@ public class SynchronizationRecordsListOutVoRecords {
/**
* 金蝶标识
* 商城标识
*/
private String sFormId;
private String form;
/**
......
......@@ -72,6 +72,7 @@ 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);
}
......
......@@ -126,6 +126,12 @@ public class ProductLogUtil {
encapsulationOperation(response, inVo);
}
public void productSyncLogCreate(Integer productId, String queueId, String name, String code, String direction, String request, String response) {
ProductLogCreateInVo inVo = this.encapsulationInVo(productId, queueId, name, code, direction, request, response);
productLogMapper.productLogCreate(inVo);
}
public void productSyncErrorLogCreate(Integer productId, String queueId, String name, String code, String direction, String request, String message) {
ProductLogCreateInVo inVo = this.encapsulationInVo(productId, queueId, name, code, direction, request, message);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论