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

微调

上级 639a3a9b
......@@ -80,7 +80,7 @@ public class CommonGetApi {
return "";
}
public String commonSync(String responseAddress, String queueId, Map<String, String> config, String json) {
public String commonSync(String responseAddress, Map<String, String> config, String queueId, String json) {
try {
String result = HttpUtil.httpPost(responseAddress, json).getBody();
thirdPartyLogUtil.thirdPartyLogCreate(config.get("name"), config.get("docType"), queueId, config.get("configureDirection"), json, result);
......
package com.system.constants;
import com.system.dao.MallCommonConfigMapper;
import com.system.transfer.form.MallCommonConfigListInVo;
import com.system.transfer.form.MallCommonConfigListOutVoRecords;
import com.system.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,7 +13,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author Inori
......@@ -30,7 +28,7 @@ public class MallCommonGetConstants {
@PostConstruct
public void init() {
List<MallCommonConfigListOutVoRecords> recordsList = mallCommonConfigMapper.mallCommonConfigList(new MallCommonConfigListInVo(Stream.of(1, 3).collect(Collectors.toList())));
List<MallCommonConfigListOutVoRecords> recordsList = mallCommonConfigMapper.mallCommonConfigGetList();
if (!CollectionUtils.isEmpty(recordsList)) {
List<Integer> idList = recordsList.stream().map(MallCommonConfigListOutVoRecords::getId).collect(Collectors.toList());
List<Map<String, Object>> fieldMappingList = mallCommonConfigMapper.mallFieldMappingList(idList);
......@@ -54,9 +52,11 @@ public class MallCommonGetConstants {
private Map<String, String> purchaseCustomFormConfig(MallCommonConfigListOutVoRecords records, List<Map<String, Object>> tempList) {
Map<String, String> result = new HashMap<>(10);
result.put("docType", records.getDocType());
result.put("sFormId", records.getSFormId());
result.put("name", records.getName());
result.put("operation", String.valueOf(records.getOperation()));
result.put("requestAddress", records.getRequestAddress());
result.put("entryName", records.getEntryName());
result.put("customSql", records.getCustomSql());
result.put("formFieldMappingDetail", JsonUtil.toString(tempList));
return result;
......
package com.system.constants;
import com.system.dao.MallCommonConfigMapper;
import com.system.transfer.form.MallCommonConfigListInVo;
import com.system.transfer.form.MallCommonConfigListOutVoRecords;
import com.system.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,7 +13,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author Inori
......@@ -30,7 +28,7 @@ public class MallCommonPostConstants {
@PostConstruct
public void init() {
List<MallCommonConfigListOutVoRecords> recordsList = mallCommonConfigMapper.mallCommonConfigList(new MallCommonConfigListInVo(Stream.of(2).collect(Collectors.toList())));
List<MallCommonConfigListOutVoRecords> recordsList = mallCommonConfigMapper.mallCommonConfigList(2);
if (!CollectionUtils.isEmpty(recordsList)) {
List<Integer> idList = recordsList.stream().map(MallCommonConfigListOutVoRecords::getId).collect(Collectors.toList());
List<Map<String, Object>> fieldMappingList = mallCommonConfigMapper.mallFieldMappingList(idList);
......@@ -54,9 +52,11 @@ public class MallCommonPostConstants {
private Map<String, String> purchaseCustomFormConfig(MallCommonConfigListOutVoRecords records, List<Map<String, Object>> tempList) {
Map<String, String> result = new HashMap<>(10);
result.put("docType", records.getDocType());
result.put("sFormId", records.getSFormId());
result.put("name", records.getName());
result.put("requestAddress", records.getRequestAddress());
result.put("operation", String.valueOf(records.getOperation()));
result.put("requestAddress", records.getRequestAddress());
result.put("entryName", records.getEntryName());
result.put("customSql", records.getCustomSql());
result.put("formFieldMappingDetail", JsonUtil.toString(tempList));
return result;
......
package com.system.constants;
import com.system.dao.MallCommonConfigMapper;
import com.system.transfer.form.MallCommonConfigListOutVoRecords;
import com.system.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* @author Inori
*/
@Component
public class MallCommonSyncConstants {
private Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
@Autowired
private MallCommonConfigMapper mallCommonConfigMapper;
@PostConstruct
public void init() {
List<MallCommonConfigListOutVoRecords> recordsList = mallCommonConfigMapper.mallCommonConfigList(3);
if (!CollectionUtils.isEmpty(recordsList)) {
List<Integer> idList = recordsList.stream().map(MallCommonConfigListOutVoRecords::getId).collect(Collectors.toList());
List<Map<String, Object>> fieldMappingList = mallCommonConfigMapper.mallFieldMappingList(idList);
for (MallCommonConfigListOutVoRecords records : recordsList) {
List<Map<String, Object>> tempList = fieldMappingList.stream().filter(m -> records.getId().equals(m.get("id"))).collect(Collectors.toList());
this.map.put(records.getSFormId(), this.purchaseCustomFormConfig(records, tempList));
}
}
}
public Map<String, String> get(String sFormId) {
if (CollectionUtils.isEmpty(this.map)) {
return new HashMap<>(1);
}
return this.map.get(sFormId);
}
/**
* 封装自定义表单配置
*/
private Map<String, String> purchaseCustomFormConfig(MallCommonConfigListOutVoRecords records, List<Map<String, Object>> tempList) {
Map<String, String> result = new HashMap<>(10);
result.put("docType", records.getDocType());
result.put("sFormId", records.getSFormId());
result.put("name", records.getName());
result.put("operation", String.valueOf(records.getOperation()));
result.put("requestAddress", records.getRequestAddress());
result.put("entryName", records.getEntryName());
result.put("customSql", records.getCustomSql());
result.put("formFieldMappingDetail", JsonUtil.toString(tempList));
return result;
}
}
package com.system.dao;
import com.system.transfer.form.MallCommonConfigListInVo;
import com.system.transfer.form.MallCommonConfigListOutVoRecords;
import java.util.List;
......@@ -14,10 +13,17 @@ public interface MallCommonConfigMapper {
/**
* 商城表单配置列表
*
* @param inVo 条件
* @param operation 操作
* @return 列表
*/
List<MallCommonConfigListOutVoRecords> mallCommonConfigList(MallCommonConfigListInVo inVo);
List<MallCommonConfigListOutVoRecords> mallCommonConfigList(Integer operation);
/**
* 商城Get表单配置列表
*
* @return 列表
*/
List<MallCommonConfigListOutVoRecords> mallCommonConfigGetList();
/**
* 商城通用配置字段映射列表
......
package com.system.dao;
import com.system.transfer.log.MallLogCreateInVo;
/**
* @author Inori
*/
public interface MallLogMapper {
/**
* 商城日志创建
*
* @param inVo 条件
*/
void mallLogCreate(MallLogCreateInVo inVo);
}
......@@ -4,20 +4,25 @@
<select id="mallCommonConfigList" parameterType="com.system.transfer.form.MallCommonConfigListInVo" resultType="com.system.transfer.form.MallCommonConfigListOutVoRecords">
<select id="mallCommonConfigList" parameterType="java.lang.Integer" resultType="com.system.transfer.form.MallCommonConfigListOutVoRecords">
SELECT
m1.id, m1.doc_type, m1.name, m1.request_address, m1.operation, m1.custom_sql, m1.create_time
id, doc_type, s_form_id, name, operation, request_address, entry_name, custom_sql, create_time
FROM tb_mall_common_config WHERE operation = #{operation}
</select>
<select id="mallCommonConfigGetList" resultType="com.system.transfer.form.MallCommonConfigListOutVoRecords">
SELECT
m1.id, m1.doc_type, m1.s_form_id, m1.name, m1.operation, m1.request_address, m1.entry_name, m1.custom_sql, m1.create_time
FROM tb_mall_common_config AS m1 INNER JOIN (
SELECT
doc_type, MIN(operation) AS operation
FROM tb_mall_common_config
GROUP BY doc_type
) AS m2 ON m1.doc_type = m2.doc_type AND m1.operation = m2.operation
WHERE m1.operation IN
<foreach collection="operationList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
s_form_id, MIN(operation) AS operation
FROM tb_mall_common_config WHERE operation IN (1, 3) GROUP BY s_form_id
) AS m2 ON m1.s_form_id = m2.s_form_id AND m1.operation = m2.operation
</select>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.system.dao.MallLogMapper">
<select id="mallLogCreate" parameterType="com.system.transfer.log.MallLogCreateInVo">
INSERT INTO tb_mall_log (
`name`, code, queue_id, operation, request, flag, response, message
) VALUES (
#{name}, #{code}, #{queueId}, #{operation}, #{request}, #{flag}, #{response}, #{message}
)
</select>
</mapper>
package com.system.serivce.impl;
import com.system.api.CommonGetApi;
import com.system.constants.MallCommonGetConstants;
import com.system.constants.Constants;
import com.system.constants.MallCommonSyncConstants;
import com.system.serivce.IMallSyncService;
import com.system.utils.JsonUtil;
import com.system.utils.MallLogUtil;
import com.system.utils.SnowFlakeIdUtil;
import com.system.utils.ThirdPartyLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author Inori
......@@ -13,14 +22,44 @@ import org.springframework.stereotype.Service;
public class IMallSyncServiceImpl implements IMallSyncService {
@Autowired
private MallCommonGetConstants mallCommonGetConstants;
private MallCommonSyncConstants mallCommonSyncConstants;
@Autowired
private CommonGetApi commonGetApi;
@Autowired
private MallLogUtil mallLogUtil;
@Autowired
private ThirdPartyLogUtil thirdPartyLogUtil;
@Override
public void synchronization(Integer id, String sFormId, Integer dataId, Integer entryId) {
String queueId = SnowFlakeIdUtil.generateId().toString();
Map<String, String> config = mallCommonSyncConstants.get(sFormId);
if (!CollectionUtils.isEmpty(config)) {
mallLogUtil.thirdPartyErrorLogCreate("商城同步失败", sFormId, queueId, 3, "", "sFormId为: " + sFormId + " 的商城表单不存在");
return;
}
Map<String, Object> data = new HashMap<>();
String result = commonGetApi.commonGet(config, data, queueId);
Map<String, Object> map = JsonUtil.toMap(result, String.class, Object.class);
if (!CollectionUtils.isEmpty(map)) {
if (!map.containsKey(Constants.SUCCESS_NAME) || !Constants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.SUCCESS_NAME)))) {
return;
}
} else {
return;
}
Map<String, Object> request = new HashMap<>();
request.put("docType", config.get("docType"));
request.put("update", "");
request.put("data", map.get("data"));
//TODO 同步至某某地址
String response = commonGetApi.commonSync("", config, queueId, JsonUtil.toString(request));
/*List<Object> objectList = JsonUtil.toList(responseEntity.getBody(), Object.class);
for (Object object : objectList) {
Map<String, Object> temp = JsonUtil.toMap(JsonUtil.toString(object), String.class, Object.class);
......
package com.system.transfer.form;
import lombok.Data;
import java.util.List;
/**
* @author Inori
*/
@Data
public class MallCommonConfigListInVo {
/**
* 操作(1-查询 2-创建/更新 3-同步)
*/
private List<Integer> operationList;
public MallCommonConfigListInVo() {
}
public MallCommonConfigListInVo(List<Integer> operationList) {
this.operationList = operationList;
}
}
......@@ -18,27 +18,39 @@ public class MallCommonConfigListOutVoRecords {
/**
* 第三方标识
* 第三方唯一标识
*/
private String docType;
/**
* 商城标识
*/
private String sFormId;
/**
* 日志名称
*/
private String name;
/**
* 操作(1-查询 2-创建/更新 3-同步)
*/
private Integer operation;
/**
* 请求地址
*/
private String requestAddress;
/**
* 操作(1-查询 2-创建/更新 3-同步)
* 分类标识
*/
private Integer operation;
private String entryName;
/**
......
package com.system.transfer.log;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class MallLogCreateInVo {
/**
* ID
*/
private Integer id;
/**
* 业务名称
*/
private String name;
/**
* 业务标识
*/
private String code;
/**
* 唯一标识
*/
private String queueId;
/**
* 操作(1-查询 2-创建/更新 3-同步)
*/
private Integer operation;
/**
* 请求参数
*/
private String request;
/**
* 是否成功(0-失败,1-成功)
*/
private Integer flag;
/**
* 响应信息
*/
private String response;
/**
* 错误原因
*/
private String message;
}
package com.system.utils;
import com.system.dao.MallLogMapper;
import com.system.transfer.log.MallLogCreateInVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Inori
*/
@Component
public class MallLogUtil {
@Autowired
private MallLogMapper mallLogMapper;
public void thirdPartyErrorLogCreate(String name, String sFormId, String queueId, Integer operation, String request, String message) {
MallLogCreateInVo inVo = new MallLogCreateInVo();
inVo.setName(name);
inVo.setCode(sFormId);
inVo.setQueueId(queueId);
inVo.setOperation(operation);
inVo.setRequest(request);
inVo.setFlag(0);
inVo.setMessage(message);
mallLogMapper.mallLogCreate(inVo);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论