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

微调

上级 3af32253
package com.system.api;
import com.system.constants.Constants;
import com.system.transfer.form.FormFieldMappingDetailOutVoRecords;
import com.system.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Inori
*/
@Component
public class CommonHttpApi {
@Autowired
private ThirdPartyLogUtil thirdPartyLogUtil;
public String commonSend(String requestAddress, String json, Map<String, String> config, String queueId) {
String result = "";
try {
if (StringUtil.isNotBlank(json)) {
result = HttpClientUtil.sendPost(config.get("requestAddress"), json);
} else {
result = HttpClientUtil.sendGet(config.get("requestAddress"));
}
} catch (Exception e) {
e.printStackTrace();
}
int flag = 0;
Map<String, Object> response = new HashMap<>(3);
Map<String, Object> map = JsonUtil.toMap(result, String.class, Object.class);
if (!CollectionUtils.isEmpty(map)) {
if (Constants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.SUCCESS_NAME)))) {
List<FormFieldMappingDetailOutVoRecords> recordsList = FormFieldMappingUtil.purchaseMapping(config.get("formFieldMappingDetail"));
List<Map<String, Object>> dataList = new ArrayList<>();
List<Object> objectList = JsonUtil.toList(JsonUtil.toString(map.get("data")), Object.class);
List<Map<String, Object>> tempList = objectList.stream().map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, Object.class)).collect(Collectors.toList());
for (Map<String, Object> temp : tempList) {
Map<String, Object> data = new LinkedHashMap<>(recordsList.size());
for (FormFieldMappingDetailOutVoRecords records : recordsList) {
if (Constants.STRING_NAME.equals(records.getFieldType())) {
if (temp.containsKey(records.getFieldBeforeMapping())) {
data.put(records.getFieldAfterMapping(), String.valueOf(temp.get(records.getFieldBeforeMapping())));
} else {
data.put(records.getFieldAfterMapping(), "");
}
} else if (Constants.INT_NAME.equals(records.getFieldType())) {
if (temp.containsKey(records.getFieldBeforeMapping())) {
try {
data.put(records.getFieldAfterMapping(), Integer.valueOf(String.valueOf(temp.get(records.getFieldBeforeMapping()))));
} catch (NumberFormatException e) {
data.put(records.getFieldAfterMapping(), String.valueOf(temp.get(records.getFieldBeforeMapping())));
}
} else {
data.put(records.getFieldAfterMapping(), "");
}
} else {
data.put(records.getFieldAfterMapping(), temp.get(records.getFieldBeforeMapping()));
}
}
dataList.add(data);
}
flag = 1;
response.put("data", dataList);
response.put("success", true);
}
} else if (!Constants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.SUCCESS_NAME))) && map.containsKey(Constants.ERROR_MESSAGE)) {
response.put("message", map.get(Constants.ERROR_MESSAGE));
response.put("success", false);
} else {
response.put("message", "");
response.put("success", false);
}
thirdPartyLogUtil.thirdPartyLogCreate(config.get("name"), config.get("docType"), queueId, config.get("configureDirection"), StringUtil.isNotBlank(json) ? json : config.get("requestAddress"), result, flag);
return JsonUtil.toString(response);
}
public String commonSendBySync(Map<String, String> config, String json, String queueId) {
try {
String result = HttpClientUtil.sendPost(config.get("responseAddress"), json);
thirdPartyLogUtil.thirdPartyLogCreate(config.get("name"), config.get("docType"), queueId, config.get("configureDirection"), json, result);
return result;
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
}
package com.system.constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.dao.CustomFormConfigMapper;
import com.system.transfer.form.CustomFormConfigListInVo;
import com.system.transfer.form.CustomFormConfigListOutVoRecords;
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;
/**
* @author Inori
*/
@Component
public class CommonGetConstants {
private Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
@Autowired
private CustomFormConfigMapper customFormConfigMapper;
@PostConstruct
public void init() {
List<CustomFormConfigListOutVoRecords> recordsList = customFormConfigMapper.customFormConfigList(new Page<>(0, 10000), new CustomFormConfigListInVo(1));
for (CustomFormConfigListOutVoRecords records : recordsList) {
this.map.put(records.getDocType(), this.purchaseCustomFormConfig(records));
}
}
public Map<String, String> get(String docType) {
if (CollectionUtils.isEmpty(this.map)) {
return new HashMap<>(1);
}
return this.map.get(docType);
}
/**
* 封装自定义表单配置
*/
private Map<String, String> purchaseCustomFormConfig(CustomFormConfigListOutVoRecords records) {
Map<String, String> result = new HashMap<>(10);
result.put("docType", records.getDocType());
result.put("name", records.getName());
result.put("configureDirection", records.getConfigureDirection());
result.put("operation", records.getOperation() == 1 ? "Get" : "Post");
result.put("requestAddress", records.getRequestAddress());
result.put("responseAddress", records.getResponseAddress());
result.put("customSql", records.getCustomSql());
result.put("formFieldMappingDetail", records.getFormFieldMappingDetail());
return result;
}
}
package com.system.constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.dao.CustomFormConfigMapper;
import com.system.transfer.form.CustomFormConfigListInVo;
import com.system.transfer.form.CustomFormConfigListOutVoRecords;
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;
/**
* @author Inori
*/
@Component
public class CommonPostConstants {
private Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
@Autowired
private CustomFormConfigMapper customFormConfigMapper;
@PostConstruct
public void init() {
List<CustomFormConfigListOutVoRecords> recordsList = customFormConfigMapper.customFormConfigList(new Page<>(0, 10000), new CustomFormConfigListInVo(2));
for (CustomFormConfigListOutVoRecords records : recordsList) {
this.map.put(records.getDocType(), this.purchaseCustomFormConfig(records));
}
}
public Map<String, String> get(String docType) {
if (CollectionUtils.isEmpty(this.map)) {
return new HashMap<>(1);
}
return this.map.get(docType);
}
/**
* 封装自定义表单配置
*/
private Map<String, String> purchaseCustomFormConfig(CustomFormConfigListOutVoRecords records) {
Map<String, String> result = new HashMap<>(10);
result.put("docType", records.getDocType());
result.put("name", records.getName());
result.put("configureDirection", records.getConfigureDirection());
result.put("operation", records.getOperation() == 1 ? "Get" : "Post");
result.put("customSql", records.getCustomSql());
result.put("formFieldMappingDetail", records.getFormFieldMappingDetail());
return result;
}
}
......@@ -20,7 +20,16 @@ public interface Constants {
String SUCCESS_NAME = "success";
String ERROR_MESSAGE = "message";
String SUCCESS_CODE = "true";
String STRING_NAME = "字符";
String INT_NAME = "数值";
}
package com.system.dao;
import java.util.List;
import java.util.Map;
/**
* @author Inori
*/
public interface SynchronizationOperationMapper {
/**
* 同步操作列表
*
* @param jobClassName 任务类名
* @return 列表
*/
List<Map<String, Object>> synchronizationOperationList(String jobClassName);
}
......@@ -7,7 +7,8 @@
<select id="customFormConfigList" parameterType="com.system.transfer.form.CustomFormConfigListInVo" resultType="com.system.transfer.form.CustomFormConfigListOutVoRecords">
SELECT
id, doc_type, `name`, request_address, configure_direction, operation, custom_sql, create_time
id, doc_type, `name`, configure_direction, operation, request_address,
response_address, custom_sql, form_field_mapping_detail, create_time
FROM tb_custom_form_config
</select>
......@@ -17,9 +18,9 @@
<insert id="customFormConfigCreate" parameterType="com.system.transfer.form.CustomFormConfigCreateInVo" useGeneratedKeys="true" keyProperty="id">
INSERT INTO tb_custom_form_config (
doc_type, `name`, request_address, configure_direction, operation, custom_sql
doc_type, `name`, configure_direction, operation, request_address, response_address, custom_sql, form_field_mapping_detail
) VALUES (
#{docType}, #{name}, #{requestAddress}, #{configureDirection}, #{operation}, #{customSql}
#{docType}, #{name}, #{configureDirection}, #{operation}, #{requestAddress}, #{responseAddress}, #{customSql}, #{formFieldMappingDetail}
)
</insert>
......@@ -29,8 +30,8 @@
<update id="customFormConfigUpdate" parameterType="com.system.transfer.form.CustomFormConfigUpdateInVo">
UPDATE tb_custom_form_config SET
doc_type = #{docType}, `name` = #{name}, request_address = #{requestAddress},
configure_direction = #{configureDirection}, operation = #{operation}, custom_sql = #{customSql}
doc_type = #{docType}, `name` = #{name}, configure_direction = #{configureDirection}, operation = #{operation}, request_address = #{requestAddress},
response_address = #{responseAddress}, custom_sql = #{customSql}, form_field_mapping_detail = #{formFieldMappingDetail}
WHERE id = #{id}
</update>
......
<?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.SynchronizationOperationMapper">
<select id="synchronizationOperationList" resultType="java.util.Map">
SELECT id, job_class_name, doc_type FROM tb_synchronization_operation WHERE job_class_name = #{jobClassName}
</select>
</mapper>
......@@ -29,7 +29,7 @@ public class SynchronizationJob implements Job {
e.printStackTrace();
}
//synchronizationService.synchronization();
synchronizationService.synchronization();
}
......
......@@ -2,16 +2,12 @@ package com.system.serivce.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.dao.CustomFormConfigMapper;
import com.system.dao.FormFieldMappingDetailMapper;
import com.system.serivce.ICustomFormConfigService;
import com.system.transfer.form.*;
import com.system.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Inori
......@@ -22,16 +18,13 @@ public class CustomFormConfigServiceImpl implements ICustomFormConfigService {
@Autowired
private CustomFormConfigMapper customFormConfigMapper;
@Autowired
private FormFieldMappingDetailMapper formFieldMappingDetailMapper;
@Override
public CustomFormConfigListOutVo customFormConfigList(CustomFormConfigListInVo inVo) {
Page<CustomFormConfigListOutVoRecords> page = new Page<>(inVo.getPageNo(), inVo.getPageSize());
List<CustomFormConfigListOutVoRecords> recordsList = customFormConfigMapper.customFormConfigList(page, inVo);
List<Integer> idList = recordsList.stream().map(CustomFormConfigListOutVoRecords::getId).collect(Collectors.toList());
/*List<Integer> idList = recordsList.stream().map(CustomFormConfigListOutVoRecords::getId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(idList)) {
List<FormFieldMappingDetailOutVoRecords> tempList = formFieldMappingDetailMapper.formFieldMappingDetailList(new FormFieldMappingDetailListInVo(idList));
recordsList.forEach(m -> {
......@@ -40,7 +33,7 @@ public class CustomFormConfigServiceImpl implements ICustomFormConfigService {
m.setFormFieldMappingDetail(JsonUtil.toString(collectList));
}
});
}
}*/
CustomFormConfigListOutVo outVo = new CustomFormConfigListOutVo();
outVo.setTotal((int) page.getTotal());
......
package com.system.serivce.impl;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.system.api.CommonHttpApi;
import com.system.constants.CommonGetConstants;
import com.system.constants.Constants;
import com.system.dao.SynchronizationOperationMapper;
import com.system.serivce.IDockingDistributionService;
import com.system.serivce.IDockingShoppingMallService;
import com.system.serivce.ISynchronizationService;
import com.system.utils.JsonUtil;
import com.system.utils.SnowFlakeIdUtil;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
......@@ -39,40 +40,33 @@ public class SynchronizationServiceImpl implements ISynchronizationService {
@Autowired
private IDockingDistributionService dockingDistributionService;
@Autowired
private SynchronizationOperationMapper synchronizationOperationMapper;
@Autowired
private CommonGetConstants commonGetConstants;
@Autowired
private CommonHttpApi commonHttpApi;
@Override
public void synchronization() {
List<Map<String, Object>> tempList = synchronizationOperationMapper.synchronizationOperationList("com.system.quartz.job.SynchronizationJob");
for (Map<String, Object> temp : tempList) {
threadPool.execute(() -> {
Map<String, String> config = commonGetConstants.get(String.valueOf(temp.get("doc_type")));
String queueId = SnowFlakeIdUtil.generateId().toString();
Map<String, Object> request = new HashMap<>(3);
String result = commonHttpApi.commonSend(config.get("requestAddress"), "", config, queueId);
String result = dockingShoppingMallService.shoppingMallMemberList(queueId);
Map<String, Object> map = JsonUtil.toMap(result, String.class, Object.class);
if (!CollectionUtils.isEmpty(map) && Constants.SUCCESS_CODE.equals(String.valueOf(map.get(Constants.SUCCESS_NAME)))) {
Map<String, Object> data = JsonUtil.toMap(JsonUtil.toString(map.get("data")), String.class, Object.class);
List<Object> objectList = JsonUtil.toList(JsonUtil.toString(data.get("records")), Object.class);
if (!CollectionUtils.isEmpty(objectList)) {
for (Object o : objectList) {
Map<String, Object> temp = JsonUtil.toMap(JsonUtil.toString(o), String.class, Object.class);
request.put("disUserId", temp.get("userId").toString());
request.put("disUserName", temp.get("nickName"));
if (temp.containsKey("referrerId") && StringUtil.isNotBlank(String.valueOf(temp.get("referrerId")))) {
request.put("disParentId", temp.get("referrerId"));
request.put("disPlatformId", "");
} else {
request.put("disParentId", "");
request.put("disPlatformId", "test");
}
request.put("disNote", "");
}
}
}
if (!CollectionUtils.isEmpty(request)) {
dockingDistributionService.dockingDistributionMemberCreate(queueId, request);
List<Object> objectList = JsonUtil.toList(JsonUtil.toString(map.get("data")), Object.class);
commonHttpApi.commonSendBySync(config, JsonUtil.toString(JsonUtil.toMap(JsonUtil.toString(objectList.get(0)), String.class, Object.class)), queueId);
}
});
}
}
}
......@@ -27,12 +27,6 @@ public class CustomFormConfigCreateInVo {
/**
* 请求地址
*/
private String requestAddress;
/**
* 配置方向
*/
private String configureDirection;
......@@ -45,9 +39,27 @@ public class CustomFormConfigCreateInVo {
/**
* 请求地址
*/
private String requestAddress;
/**
* 发送地址
*/
private String responseAddress;
/**
* 自定义Sql
*/
private String customSql;
/**
* 表单字段映射明细
*/
private String formFieldMappingDetail;
}
......@@ -9,6 +9,12 @@ import lombok.Data;
public class CustomFormConfigListInVo {
/**
* 操作(1-查询 2-创建)
*/
private Integer operation;
/**
* 页码
*/
private Integer pageNo = 1;
......@@ -20,4 +26,12 @@ public class CustomFormConfigListInVo {
private Integer pageSize = 20;
public CustomFormConfigListInVo() {
}
public CustomFormConfigListInVo(Integer operation) {
this.operation = operation;
}
}
......@@ -27,12 +27,6 @@ public class CustomFormConfigListOutVoRecords {
/**
* 请求地址
*/
private String requestAddress;
/**
* 配置方向
*/
private String configureDirection;
......@@ -45,6 +39,18 @@ public class CustomFormConfigListOutVoRecords {
/**
* 请求地址
*/
private String requestAddress;
/**
* 发送地址
*/
private String responseAddress;
/**
* 自定义Sql
*/
private String customSql;
......
......@@ -27,12 +27,6 @@ public class CustomFormConfigUpdateInVo {
/**
* 请求地址
*/
private String requestAddress;
/**
* 配置方向
*/
private String configureDirection;
......@@ -45,9 +39,27 @@ public class CustomFormConfigUpdateInVo {
/**
* 请求地址
*/
private String requestAddress;
/**
* 发送地址
*/
private String responseAddress;
/**
* 自定义Sql
*/
private String customSql;
/**
* 表单字段映射明细
*/
private String formFieldMappingDetail;
}
......@@ -10,11 +10,9 @@ import java.util.stream.Collectors;
*/
public class FormFieldMappingUtil {
public static List<FormFieldMappingDetailOutVoRecords> purchaseMapping(Integer id, String formFieldMappingDetail) {
public static List<FormFieldMappingDetailOutVoRecords> purchaseMapping(String formFieldMappingDetail) {
List<Object> objectList = JsonUtil.toList(formFieldMappingDetail, Object.class);
List<FormFieldMappingDetailOutVoRecords> recordsList = objectList.stream().map(m -> JsonUtil.toBean(JsonUtil.toString(m), FormFieldMappingDetailOutVoRecords.class)).collect(Collectors.toList());
recordsList.forEach(m -> m.setCustomFormConfigId(id));
return recordsList;
return objectList.stream().map(m -> JsonUtil.toBean(JsonUtil.toString(m), FormFieldMappingDetailOutVoRecords.class)).collect(Collectors.toList());
}
......
package com.system.utils;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Matcher;
......
......@@ -42,5 +42,18 @@ public class ThirdPartyLogUtil {
thirdPartyLogMapper.thirdPartyLogCreate(inVo);
}
public void thirdPartyLogCreate(String name, String docType, String queueId, String direction, String request, String response, Integer flag) {
ThirdPartyLogCreateInVo inVo = new ThirdPartyLogCreateInVo();
inVo.setName(name);
inVo.setCode(docType);
inVo.setQueueId(queueId);
inVo.setDirection(direction);
inVo.setRequest(request);
inVo.setResponse(response);
inVo.setFlag(flag);
thirdPartyLogMapper.thirdPartyLogCreate(inVo);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论