提交 07e00455 authored 作者: inroi's avatar inroi

创建

上级
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
FROM anapsix/alpine-java:8_server-jre_unlimited
MAINTAINER Inori
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN mkdir -p /kingdee-adapter
WORKDIR /kingdee-adapter
EXPOSE 8090
ADD ./target/kingdee-adapter.jar /kingdee-adapter
CMD sleep 15;java -Djava.security.egd=file:/dev/./urandom -jar kingdee-adapter.jar
\ No newline at end of file
version: '2'
services:
kingdee-adapter:
build:
context: ./
restart: always
container_name: kingdee-adapter
image: kingdee-adapter
ports:
- 12001:12001
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>kingdee-adapter</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<swagger.version>2.9.2</swagger.version>
<swagger.bootstrap.version>1.9.6</swagger.bootstrap.version>
<druid.version>1.2.8</druid.version>
<mybatis.version>3.4.3</mybatis.version>
<fastjson.version>1.2.73</fastjson.version>
<json.lib.version>2.4</json.lib.version>
</properties>
<dependencies>
<!-- SpringBoot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- SpringBoot -->
<!-- Mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- Mysql -->
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger.bootstrap.version}</version>
</dependency>
<!-- Swagger -->
<!-- Common -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${json.lib.version}</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- Common -->
</dependencies>
<build>
<finalName>kingdee-adapter</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- 避免font文件的二进制文件格式压缩破坏 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
</project>
\ No newline at end of file
package com.system;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author Inori
*/
@MapperScan("com.system.dao")
@SpringBootApplication
public class SystemApplication {
public static void main(String[] args) {
SpringApplication.run(SystemApplication.class, args);
}
}
差异被折叠。
package com.system.api;
import com.system.config.ThreadLocalConfig;
import com.system.constants.Constants;
import com.system.constants.KingDeeConstants;
import com.system.serializer.SerializerProxy;
import com.system.utils.HttpUtil;
import com.system.utils.JsonUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Inori
*/
public class KingDeeApiClient {
/**
* 金蝶地址
*/
private String serverUrl;
/**
* Cookie
*/
private String cookieStore;
/**
* 金蝶后缀
*/
private static final String HTTP_SUFFIX = ".common.kdsvc";
public KingDeeApiClient(String serverUrl) {
this.serverUrl = serverUrl;
}
@SuppressWarnings("unchecked")
public <T> T execute(String serviceName, Object[] parameters, Class<T> returnType) throws Exception {
Map<String, Object> header = new HashMap<>(1);
header.put("cookie", cookieStore);
Map<String, Object> request = new HashMap<>(1);
request.put("parameters", parameters);
String url = serverUrl + serviceName + HTTP_SUFFIX;
System.out.println("------------>" + url);
long start = System.currentTimeMillis();
ResponseEntity<String> responseEntity = HttpUtil.httpPost(url, header, JsonUtil.toString(request));
long costTime = System.currentTimeMillis() - start;
Map<String, Object> map = ThreadLocalConfig.get();
map.put("costTime", costTime);
ThreadLocalConfig.set(map);
return (T) (new SerializerProxy()).deserialize(responseEntity.getBody(), returnType);
}
public Boolean login(String dbId, String userName, String password, int lcid) {
try {
Map<String, Object> request = new HashMap<>(1);
request.put("parameters", new Object[]{dbId, userName, password, lcid});
String url = serverUrl + "Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser" + HTTP_SUFFIX;
ResponseEntity<String> responseEntity = HttpUtil.httpPost(url, JsonUtil.toString(request));
System.out.println(responseEntity.getBody());
if (responseEntity.getStatusCode() == HttpStatus.OK) {
Map<String, Object> map = JsonUtil.toMap(responseEntity.getBody(), String.class, Object.class);
if (!CollectionUtils.isEmpty(map) && Constants.ONE.equals(String.valueOf(map.get(KingDeeConstants.LOGIN_RESULT_TYPE)))) {
this.cookieStore = this.getCookieStore(responseEntity);
return true;
} else {
return false;
}
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private String getCookieStore(ResponseEntity<String> responseEntity) {
String cookieStore = "";
Set<String> keys = responseEntity.getHeaders().keySet();
for (String key : keys) {
if (key.equalsIgnoreCase(KingDeeConstants.KING_DEE_COOKIE_NAME)) {
List<String> cookieList = responseEntity.getHeaders().get(key);
if (!CollectionUtils.isEmpty(cookieList)) {
for (String cookie : cookieList) {
if (cookie.startsWith(KingDeeConstants.KING_DEE_SESSION_NAME)) {
cookieStore = cookie;
break;
}
}
}
}
}
return cookieStore;
}
}
package com.system.api;
import com.system.utils.JsonUtil;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author Inori
*/
public class KingDeeK3CloudApi extends KingDeeApiClient {
public KingDeeK3CloudApi(String serverUrl) {
super(serverUrl);
}
public String excuteOperation(String formid, String opNumber, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExcuteOperation", new Object[]{formid, opNumber, data}, Object.class);
return JsonUtil.toString(execute);
}
public String save(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public String batchSave(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public String audit(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public String delete(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public String unAudit(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public String submit(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public String view(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
public List<List<Object>> executeBillQuery(String data) throws Exception {
List execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", new Object[]{data}, ArrayList.class);
if (CollectionUtils.isEmpty(execute)) {
execute = new ArrayList<>();
}
return execute;
}
public String draft(String formid, String data) throws Exception {
Object execute = this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Draft", new Object[]{formid, data}, Object.class);
return JsonUtil.toString(execute);
}
}
package com.system.config;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 快捷获取HttpServletRequest,HttpServletResponse
*
* @author Inori
*/
public class HttpContext {
/**
* 获取当前请求的Request对象
*
*/
public static HttpServletRequest getRequest() {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
return null;
} else {
return requestAttributes.getRequest();
}
}
/**
* 获取当前请求的Response对象
*
*/
public static HttpServletResponse getResponse() {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
return null;
} else {
return requestAttributes.getResponse();
}
}
}
package com.system.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Inori
*/
@Configuration
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
//乐观锁mybatis插件
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
}
\ No newline at end of file
package com.system.config;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author Inori
*/
public class ThreadLocalConfig {
private static ThreadLocal<Map<String, Object>> THREAD_LOCAL = new ThreadLocal<>();
public static Map<String, Object> get() {
if (CollectionUtils.isEmpty(THREAD_LOCAL.get())) {
ThreadLocalConfig.set(new HashMap<>());
}
return THREAD_LOCAL.get();
}
public static void set(Map<String, Object> map) {
THREAD_LOCAL.set(map);
}
public static void remove() {
THREAD_LOCAL.remove();
}
}
package com.system.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.system.constants.SpringContextHolder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.ArrayList;
import java.util.List;
/**
* @author Inori
*/
@EnableWebMvc
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//创建fastJson消息转换器
FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
//创建配置类
FastJsonConfig fastJsonConfig = new FastJsonConfig();
//过滤并修改配置返回内容
fastJsonConfig.setSerializerFeatures(
//List字段如果为null,输出为[],而非null
SerializerFeature.WriteNullListAsEmpty,
//字符类型字段如果为null,输出为"",而非null
SerializerFeature.WriteNullStringAsEmpty,
//消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环)
SerializerFeature.DisableCircularReferenceDetect,
//是否输出值为null的字段,默认为false。
SerializerFeature.WriteMapNullValue
);
//处理中文乱码问题
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
fastMediaTypes.add(MediaType.parseMediaType(MediaType.TEXT_PLAIN_VALUE + ";charset=ISO-8859-1"));
fastJsonConverter.setSupportedMediaTypes(fastMediaTypes);
fastJsonConverter.setFastJsonConfig(fastJsonConfig);
converters.add(0, fastJsonConverter);
}
@Bean
public SpringContextHolder springContextHolder() {
return new SpringContextHolder();
}
}
\ No newline at end of file
package com.system.constants;
/**
* @author Inori
*/
public interface Constants {
String ZERO = "0";
String ONE = "1";
String TWO = "2";
String THREE = "3";
String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
String FILE_FORMAT = "lic.tmp";
String EFFECTIVE_TIME = "effectiveTime";
String VERIFICATION_INTERVAL = "verificationInterval";
String CODE_NAME = "code";
String DATA_NAME = "data";
}
package com.system.constants;
import com.system.dao.DatabaseTableMapper;
import com.system.transfer.configure.TableStructureListOutVoRecords;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
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 FormTableStructureConstants {
private Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
@Autowired
private DatabaseTableMapper databaseTableMapper;
@PostConstruct
public void init() {
List<TableStructureListOutVoRecords> recordsList = databaseTableMapper.tableStructureList();
for (TableStructureListOutVoRecords records : recordsList) {
this.map.put(records.getFormId(), this.purchaseFormTable(records));
}
}
public Map<String, String> get(String formId) {
return this.map.get(formId);
}
public void refresh(String formId) {
this.map.remove(formId);
TableStructureListOutVoRecords records = databaseTableMapper.tableStructureOne(formId);
if (StringUtil.isNotNull(records)) {
this.map.put(records.getFormId(), this.purchaseFormTable(records));
}
}
private Map<String, String> purchaseFormTable(TableStructureListOutVoRecords records) {
Map<String, String> temp = new HashMap<>(6);
temp.put("formId", records.getFormId());
temp.put("dbTableName", records.getDbTableName());
temp.put("dbTableCommon", records.getDbTableComment());
temp.put("formJson", records.getFormJson());
return temp;
}
}
package com.system.constants;
import com.system.dao.KingDeeCommonConfigMapper;
import com.system.transfer.kingdee.KingDeeCommonConfigOneInVo;
import com.system.transfer.kingdee.KingdeeCommonConfigListOutVoRecords;
import com.system.utils.StringUtil;
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 KingDeeCommonPushConstants {
private Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
@Autowired
private KingDeeCommonConfigMapper kingDeeCommonConfigMapper;
@PostConstruct
public void init() {
List<KingdeeCommonConfigListOutVoRecords> recordsList = kingDeeCommonConfigMapper.kingDeeCommonConfigList(1);
for (KingdeeCommonConfigListOutVoRecords records : recordsList) {
this.map.put(records.getDocType(), this.getKingDeeCommonConfigDetail(records));
}
}
public Map<String, String> get(String formId) {
if (CollectionUtils.isEmpty(this.map)) {
return new HashMap<>(1);
}
return this.map.get(formId);
}
public void refresh(String docType) {
this.map.remove(docType);
KingdeeCommonConfigListOutVoRecords records = kingDeeCommonConfigMapper.kingDeeCommonConfigOne(new KingDeeCommonConfigOneInVo("", docType, 1));
if (StringUtil.isNotNull(records)) {
this.map.put(records.getDocType(), this.getKingDeeCommonConfigDetail(records));
}
}
private Map<String, String> getKingDeeCommonConfigDetail(KingdeeCommonConfigListOutVoRecords records) {
Map<String, String> result = new HashMap<>(10);
result.put("docType", records.getDocType());
result.put("sFormId", records.getSFormId());
result.put("kingDeeLogName", records.getName());
result.put("entryName", records.getEntryName());
result.put("fathersFormId", records.getFathersFormId());
result.put("fatherEntryName", records.getFatherEntryName());
result.put("pushRule", records.getPushRule());
result.put("isInTransaction", String.valueOf(records.getIsInTransaction()));
result.put("isAutoPerform", String.valueOf(records.getIsAutoPerform()));
result.put("kingDeeFiledDetail", records.getKingdeeFiledDetail());
result.put("plugInUrl", records.getPlugInUrl());
result.put("customSql", records.getCustomSql());
return result;
}
}
package com.system.constants;
import com.system.dao.KingDeeCommonConfigMapper;
import com.system.transfer.kingdee.KingDeeCommonConfigOneInVo;
import com.system.transfer.kingdee.KingdeeCommonConfigListOutVoRecords;
import com.system.utils.JsonUtil;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Inori
*/
@Component
public class KingDeeCommonSyncConstants {
private Map<String, Map<String, String>> map = new ConcurrentHashMap<>();
@Autowired
private KingDeeCommonConfigMapper kingDeeCommonConfigMapper;
@PostConstruct
public void init() {
List<KingdeeCommonConfigListOutVoRecords> recordsList = kingDeeCommonConfigMapper.kingDeeCommonConfigList(-1);
for (KingdeeCommonConfigListOutVoRecords records : recordsList) {
this.map.put(records.getSFormId(), this.purchaseKingDeeSyn(records));
}
}
public Map<String, String> get(String sFormId) {
return this.map.get(sFormId);
}
public Map<String, String> getKingDee(String docType) {
KingdeeCommonConfigListOutVoRecords records = kingDeeCommonConfigMapper.kingDeeCommonConfigOne(new KingDeeCommonConfigOneInVo("", docType, -1));
if (StringUtil.isNull(records)) {
return new HashMap<>(0);
}
return this.map.get(records.getSFormId());
}
public void refresh(String sFormId) {
this.map.remove(sFormId);
KingdeeCommonConfigListOutVoRecords records = kingDeeCommonConfigMapper.kingDeeCommonConfigOne(new KingDeeCommonConfigOneInVo(sFormId, "", -1));
if (records != null) {
this.map.put(records.getSFormId(), this.purchaseKingDeeSyn(records));
}
}
private Map<String, String> purchaseKingDeeSyn(KingdeeCommonConfigListOutVoRecords records) {
Map<String, String> temp = new HashMap<>(6);
temp.put("sFormId", records.getSFormId());
temp.put("docType", records.getDocType());
temp.put("name", records.getName());
temp.put("primaryKeyField", records.getPrimaryKeyField());
temp.put("mesEntryName", records.getMesEntryName());
temp.put("kingdeeFiledDetail", records.getKingdeeFiledDetail());
temp.put("plugInUrl", records.getPlugInUrl());
temp.put("customSql", records.getCustomSql());
return temp;
}
/**
* 封装金蝶字段
*/
public static Map<String, String> purchaseKingDee(List<Map<String, String>> fieldList) {
Map<String, String> key = new LinkedHashMap<>();
for (Map<String, String> map : fieldList) {
String kingDeeField = map.get("kingdeeField");
String indexField = map.get("indexField");
if (StringUtil.isNotBlank(indexField)) {
kingDeeField = kingDeeField + "." + indexField;
}
key.put(kingDeeField, kingDeeField);
}
return key;
}
/**
* 封装第三方字段
*/
public static void purchaseIms(List<List<Object>> list, List<Map<String, String>> fieldList, Map<String, Object> map, List<Map<String, Object>> imsList) {
for (List<Object> objectList : list) {
Map<String, Object> temp = new HashMap<>(fieldList.size());
for (int i = 0; i < fieldList.size(); i++) {
//是否是明细字段
if ("true".equals(fieldList.get(i).get("isDetailField"))) {
temp.put(fieldList.get(i).get("thirdPartyField"), objectList.get(i));
} else {
map.put(fieldList.get(i).get("thirdPartyField"), objectList.get(i));
}
}
if (!CollectionUtils.isEmpty(temp)) {
imsList.add(temp);
}
}
}
/**
* 封装第三方字段
*/
public static void purchaseSqlIms(List<Object> list, List<Map<String, String>> fieldList, Map<String, Object> map) {
List<Map<String, Object>> imsList = new ArrayList<>();
for (Object object : list) {
Map<String, Object> temp = JsonUtil.toMap(JsonUtil.toString(object), String.class, Object.class);
Map<String, Object> request = new LinkedHashMap<>();
for (Map<String, String> temp02Map : fieldList) {
if ("true".equals(temp02Map.get("isDetailField"))) {
request.put(temp02Map.get("thirdPartyField"), temp.get(temp02Map.get("kingdeeField")));
} else {
map.put(temp02Map.get("thirdPartyField"), temp.get(temp02Map.get("kingdeeField")));
}
}
if (!CollectionUtils.isEmpty(request)) {
imsList.add(request);
}
}
map.put("children", imsList);
}
}
package com.system.constants;
/**
* @author Inori
*/
public interface KingDeeConstants {
String KING_DEE_COOKIE_NAME = "Set-Cookie";
String KING_DEE_SESSION_NAME = "kdservice-sessionid";
String LOGIN_RESULT_TYPE = "LoginResultType";
String CODE_NAME = "resultCode";
String MSG_NAME = "resultMsg";
String SUCCESS_CODE = "0000";
String ERROR_CODE = "0002";
String OVERTIME_CODE = "0101";
String NOT_LOGGED_IN_CODE = "0010";
String DATA_NAME = "data";
}
package com.system.constants;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* 静态获取spring容器中的bean
*
* @author Inori
*/
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextHolder.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
assertApplicationContext();
return applicationContext;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String beanName) {
assertApplicationContext();
return (T) applicationContext.getBean(beanName);
}
public static <T> T getBean(Class<T> requiredType) {
assertApplicationContext();
return applicationContext.getBean(requiredType);
}
private static void assertApplicationContext() {
if (SpringContextHolder.applicationContext == null) {
throw new RuntimeException("applicationContext属性为null,请检查是否注入了SpringContextHolder!");
}
}
}
package com.system.controller;
import com.system.service.IFormTableStructureService;
import com.system.transfer.configure.FormTableStructureConfigRefreshInVo;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Inori
*/
@Api(tags = "表单配置")
@RestController
@RequestMapping("/api")
public class FormTableStructureController {
@Autowired
private IFormTableStructureService formTableStructureService;
@ApiOperation("表单配置刷新")
@PostMapping("/form/table/structure/config/refresh")
public RestResponse formTableStructureConfigRefresh(@RequestBody FormTableStructureConfigRefreshInVo inVo) {
formTableStructureService.formTableStructureConfigRefresh(inVo);
return RestResponse.success();
}
}
package com.system.controller;
import com.system.service.IKingDeeCommonGetService;
import com.system.transfer.kingdee.KingDeeDataListInVo;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Inori
*/
@Api(tags = "金蝶查询")
@RestController
@RequestMapping("/api")
public class KingDeeGetController {
@Autowired
private IKingDeeCommonGetService kingDeeCommonGetService;
@ApiOperation("金蝶通用查询")
@PostMapping("/kingdee/data/list")
public RestResponse kingDeeDataList(@RequestBody @Validated KingDeeDataListInVo inVo) {
return kingDeeCommonGetService.kingDeeDataList(inVo);
}
}
package com.system.controller;
import com.system.service.IKingDeeCommonPushService;
import com.system.transfer.kingdee.KingDeeUpdateThirdDataInVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Inori
*/
@Api(tags = "金蝶更新数据")
@RestController
@RequestMapping("/api")
public class KingDeePushController {
@Autowired
private IKingDeeCommonPushService kingDeeCommonPushService;
@ApiOperation("金蝶下推创建")
@PostMapping("/kingdee/updateThirdData")
public Object kingDeeUpdateThirdData(@RequestBody @Validated KingDeeUpdateThirdDataInVo inVo) {
return kingDeeCommonPushService.kingDeeUpdateThirdData(inVo);
}
}
package com.system.controller;
import com.system.service.IKingDeeSyncConfigService;
import com.system.transfer.configure.InitConnectParamCheckInVo;
import com.system.transfer.configure.InitConnectParamCreateInVo;
import com.system.transfer.kingdee.KingdeeConfigRefreshInVo;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author Inori
*/
@Api(tags = "金蝶同步配置相关")
@RestController
@RequestMapping("/api")
public class KingDeeSyncConfigController {
@Autowired
private IKingDeeSyncConfigService kingDeeSyncConfigService;
@ApiOperation("保存金蝶参数")
@PostMapping("/kingdee/init/connect/param/create")
public RestResponse initConnectParamCreate(@RequestBody @Validated InitConnectParamCreateInVo inVo) {
return kingDeeSyncConfigService.initConnectParamCreate(inVo);
}
@ApiOperation("校验金蝶参数")
@PostMapping("/kingdee/init/connect/param/check")
public RestResponse initConnectParamCheck(@RequestBody @Validated InitConnectParamCheckInVo inVo) {
return kingDeeSyncConfigService.initConnectParamCheck(inVo);
}
@ApiOperation("金蝶配置刷新")
@PostMapping("/kingdee/config/refresh")
public RestResponse kingdeeConfigRefresh(@RequestBody KingdeeConfigRefreshInVo inVo) {
kingDeeSyncConfigService.kingdeePushConfigRefresh(inVo);
return RestResponse.success();
}
}
package com.system.controller;
import com.system.service.ISynchronizationService;
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;
/**
* @author Inori
*/
@Api("金蝶同步")
@RestController
@RequestMapping("/api")
public class KingDeeSyncController {
@Autowired
private ISynchronizationService synchronizationService;
@ApiOperation("金蝶同步")
@GetMapping("/kingdee/synchronization")
public RestResponse kingdeeSynchronization() {
synchronizationService.kingdeeSynchronization();
return RestResponse.success();
}
@ApiOperation("金蝶失败同步")
@GetMapping("/kingdee/manual/synchronization")
public RestResponse manualSynchronization() {
synchronizationService.kingdeeManualSynchronization();
return RestResponse.success();
}
}
package com.system.dao;
import com.system.transfer.configure.TableStructureListOutVoRecords;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* @author Inori
*/
@Mapper
public interface DatabaseTableMapper {
/**
* 表单表结构列表
*
* @return 列表
*/
List<TableStructureListOutVoRecords> tableStructureList();
/**
* 表单配置
*
* @param formId 表单标识
* @return 表单配置
*/
TableStructureListOutVoRecords tableStructureOne(String formId);
/**
* 数据库表数据创建
*
* @param dbTableName 数据库表名称
* @param dbFiledList 数据库表字段列表
* @param dataList 数据库表数据列表
*/
void databaseTableDataCreate(@Param("dbTableName") String dbTableName, @Param("dbFiledList") List<String> dbFiledList, @Param("dataList") List<Map<String, Object>> dataList);
/**
* 数据库表数据删除
*
* @param dbTableName 数据库表名称
* @param queueId 唯一标识
*/
void databaseTableDataDelete(@Param("dbTableName") String dbTableName, @Param("queueId") String queueId);
}
package com.system.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.system.model.InitConnectParam;
/**
* @author Inori
*/
public interface InitConnectParamMapper extends BaseMapper<InitConnectParam> {
}
package com.system.dao;
import com.system.transfer.kingdee.KingDeeCommonConfigOneInVo;
import com.system.transfer.kingdee.KingdeeCommonConfigListOutVoRecords;
import java.util.List;
/**
* @author Inori
*/
public interface KingDeeCommonConfigMapper {
/**
* 金蝶通用配置列表
*
* @param flag 配置方向
* @return 列表
*/
List<KingdeeCommonConfigListOutVoRecords> kingDeeCommonConfigList(Integer flag);
/**
* 金蝶通用配置
*
* @param inVo 条件
* @return 金蝶通用配置
*/
KingdeeCommonConfigListOutVoRecords kingDeeCommonConfigOne(KingDeeCommonConfigOneInVo inVo);
}
package com.system.dao;
import com.system.transfer.kingdee.KingDeeLogCreateInVo;
/**
* @author Inori
*/
public interface KingDeeLogMapper {
/**
* 金蝶日志创建
*
* @param inVo 条件
*/
void kingDeeLogCreate(KingDeeLogCreateInVo inVo);
}
package com.system.dao;
import com.system.transfer.kingdee.SynchronizationRecordsDeleteInVo;
import com.system.transfer.kingdee.SynchronizationRecordsListOutVoRecords;
import com.system.transfer.kingdee.SynchronizationRecordsUpdateInVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* @author Inori
*/
public interface SynchronizationRecordsMapper {
/**
* 金蝶同步记录列表
*
* @param statusList 状态列表
* @return 同步记录
*/
List<SynchronizationRecordsListOutVoRecords> synchronizationRecordsListByStatus(@Param("statusList") List<Integer> statusList);
/**
* 金蝶同步临时记录创建
*
* @param tempList 数据
*/
void synchronizationRecordsTempCreate(@Param("tempList") List<Map<String, Object>> tempList);
/**
* 金蝶同步临时记录列表
*
* @return 列表
*/
List<Map<String, Object>> synchronizationRecordsTempList();
/**
* 金蝶同步记录创建
*
* @param tempList 数据
*/
void synchronizationRecordsCreate(@Param("tempList") List<Map<String, Object>> tempList);
/**
* 根据ID删除数据
*
* @param idList ID列表
*/
void synchronizationRecordsTempDelete(@Param("idList") List<Integer> idList);
/**
* 根据ID更新金蝶同步记录状态
*
* @param idList ID列表
*/
void synchronizationRecordsUpdateByIdList(@Param("idList") List<Integer> idList);
/**
* 金蝶同步记录更新
*
* @param inVo 条件
*/
void synchronizationRecordsUpdate(SynchronizationRecordsUpdateInVo inVo);
/**
* 金蝶同步记录删除
*
* @param inVo 条件
*/
void synchronizationRecordsDelete(SynchronizationRecordsDeleteInVo inVo);
}
package com.system.dao;
import com.system.transfer.kingdee.ThirdPartyLogCreateInVo;
import com.system.transfer.kingdee.ThirdPartyLogUpdateInVo;
/**
* @author Inori
*/
public interface ThirdPartyLogMapper {
/**
* 唯一标识是否存在
*
* @param queueId 唯一标识
* @return 是否存在
*/
Integer getThirdPartyLogByQueueId(String queueId);
/**
* 第三方日志创建
*
* @param inVo 条件
*/
void thirdPartyLogCreate(ThirdPartyLogCreateInVo inVo);
/**
* 第三方日志更新
*
* @param inVo 条件
*/
void thirdPartyLogUpdate(ThirdPartyLogUpdateInVo inVo);
}
<?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.DatabaseTableMapper">
<select id="tableStructureList" resultType="com.system.transfer.configure.TableStructureListOutVoRecords">
SELECT
id, form_id, db_table_name, db_table_comment, form_json
FROM tb_form_table_structure
</select>
<select id="tableStructureOne" parameterType="java.lang.String" resultType="com.system.transfer.configure.TableStructureListOutVoRecords">
SELECT
id, form_id, db_table_name, db_table_comment, form_json
FROM tb_form_table_structure WHERE form_id = #{formId}
</select>
<insert id="databaseTableDataCreate" parameterType="java.lang.Object">
INSERT INTO ${dbTableName} (
<foreach collection="dbFiledList" item="item" separator=",">
${item}
</foreach>
) VALUES
<foreach collection="dataList" item="item" separator=",">
<foreach collection="item.values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</foreach>
</insert>
<delete id="databaseTableDataDelete" parameterType="java.lang.String">
DELETE FROM ${dbTableName} WHERE queue_id = #{queueId}
</delete>
</mapper>
\ No newline at end of file
<?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.InitConnectParamMapper">
</mapper>
<?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.KingDeeCommonConfigMapper">
<select id="kingDeeCommonConfigList" parameterType="java.lang.Integer" resultType="com.system.transfer.kingdee.KingdeeCommonConfigListOutVoRecords">
SELECT
id, doc_type, s_form_id, `name`, flag, primary_key_field, mes_entry_name, entry_name, fathers_form_id, father_entry_name,
push_rule, is_in_transaction, is_auto_perform, kingdee_filed_detail, plug_in_url, custom_sql, create_time
FROM tb_kingdee_common_config WHERE flag = #{flag}
</select>
<select id="kingDeeCommonConfigOne" parameterType="com.system.transfer.kingdee.KingDeeCommonConfigOneInVo" resultType="com.system.transfer.kingdee.KingdeeCommonConfigListOutVoRecords">
SELECT
id, doc_type, s_form_id, `name`, flag, primary_key_field, mes_entry_name, entry_name, fathers_form_id, father_entry_name,
push_rule, is_in_transaction, is_auto_perform, kingdee_filed_detail, plug_in_url, custom_sql
FROM tb_kingdee_common_config
<where>
<if test="docType != null and docType != ''">
doc_type = #{docType}
</if>
<if test="sFormId != null and sFormId != ''">
AND s_form_id = #{sFormId}
</if>
<if test="flag != null">
AND flag = #{flag}
</if>
</where>
</select>
</mapper>
<?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.KingDeeLogMapper">
<insert id="kingDeeLogCreate" parameterType="com.system.transfer.kingdee.KingDeeLogCreateInVo">
INSERT INTO tb_kingdee_log (
`name`, queue_id, request, flag, response, message, cost_time
) VALUES (
#{name}, #{queueId}, #{request}, #{flag}, #{response}, #{message}, #{costTime}
)
</insert>
</mapper>
<?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.SynchronizationRecordsMapper">
<select id="synchronizationRecordsListByStatus" parameterType="java.lang.Integer" resultType="com.system.transfer.kingdee.SynchronizationRecordsListOutVoRecords">
SELECT
id, fid, data_id, entry_id, s_form_id
FROM tb_synchronization_record WHERE status IN
<foreach collection="statusList" item="item" separator=", " open="(" close=")">
#{item}
</foreach>
ORDER BY create_time ASC, id ASC
</select>
<insert id="synchronizationRecordsTempCreate" parameterType="java.util.List">
INSERT INTO tb_synchronization_record_temp (fid, data_id, entry_id, s_form_id) VALUES
<foreach collection="tempList" item="item" separator=",">
(#{item.fid}, #{item.dataId}, #{item.entryId}, #{item.sFormId})
</foreach>
ON DUPLICATE KEY UPDATE
fid = VALUES (fid), data_id = VALUES (data_id), entry_id = VALUES (entry_id), s_form_id = VALUES (s_form_id)
</insert>
<select id="synchronizationRecordsTempList" resultType="java.util.Map">
SELECT id, fid, data_id AS dataId, entry_id AS entryId, s_form_id AS sFormId FROM tb_synchronization_record_temp
</select>
<insert id="synchronizationRecordsCreate" parameterType="java.util.List">
INSERT INTO tb_synchronization_record (fid, data_id, entry_id, s_form_id) VALUES
<foreach collection="tempList" item="item" separator=",">
(#{item.fid}, #{item.dataId}, #{item.entryId}, #{item.sFormId})
</foreach>
ON DUPLICATE KEY UPDATE
fid = VALUES (fid), data_id = VALUES (data_id), entry_id = VALUES (entry_id), s_form_id = VALUES (s_form_id)
</insert>
<delete id="synchronizationRecordsTempDelete" parameterType="java.util.List">
DELETE FROM tb_synchronization_record_temp WHERE id IN
<foreach collection="idList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</delete>
<update id="synchronizationRecordsUpdateByIdList" parameterType="java.util.List">
UPDATE tb_synchronization_record SET
<foreach collection="idList" item="item" open="status= CASE id" close="END">
WHEN #{item} THEN 1
</foreach>
WHERE id IN
<foreach collection="idList" item="item" separator=", " open="(" close=")">
#{item}
</foreach>
</update>
<update id="synchronizationRecordsUpdate" parameterType="com.system.transfer.kingdee.SynchronizationRecordsUpdateInVo">
UPDATE tb_synchronization_record SET queue_id = #{queueId}, message = #{message}, status = #{status} WHERE id = #{id} LIMIT 1
</update>
<delete id="synchronizationRecordsDelete" parameterType="com.system.transfer.kingdee.SynchronizationRecordsDeleteInVo">
DELETE FROM tb_synchronization_record WHERE id = #{id}
</delete>
</mapper>
<?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.ThirdPartyLogMapper">
<select id="getThirdPartyLogByQueueId" parameterType="java.lang.String" resultType="java.lang.Integer">
SELECT COUNT(*) FROM tb_third_party_log WHERE queue_id = #{queueId} LIMIT 1
</select>
<insert id="thirdPartyLogCreate" parameterType="com.system.transfer.kingdee.ThirdPartyLogCreateInVo" useGeneratedKeys="true" keyProperty="id">
INSERT INTO tb_third_party_log (
`name`, code, queue_id, request, flag, response, message
) VALUES (
#{name}, #{code}, #{queueId}, #{request}, #{flag}, #{response}, #{message}
)
</insert>
<update id="thirdPartyLogUpdate" parameterType="com.system.transfer.kingdee.ThirdPartyLogCreateInVo">
UPDATE tb_third_party_log SET flag = #{flag}, response = #{response}, message = #{message} WHERE id = #{id}
</update>
</mapper>
package com.system.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 金蝶云连接异常
*
* @author Inori
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class KingDeeConnectException extends RuntimeException {
private String result;
public KingDeeConnectException(String message) {
super(message);
this.result = message;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
package com.system.handler;
import com.system.config.HttpContext;
import com.system.transfer.response.ErrorResponseData;
import com.system.transfer.response.RestResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 全局的的异常拦截器
*
* @author Inori
*/
@Order(-1)
@ControllerAdvice
public class CommonExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(CommonExceptionHandler.class);
/**
* 参数校验异常
*/
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public RestResponse handlerMethodArgumentNotValidException(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
// 所有参数异常信息
List<ObjectError> allErrors = bindingResult.getAllErrors();
List<String> errorsMessageList = new ArrayList<>();
allErrors.forEach(error -> {
errorsMessageList.add(error.getDefaultMessage());
});
String errorMsg = String.join(";", errorsMessageList);
return RestResponse.fail(errorMsg);
}
/**
* 拦截未知的运行时异常
*/
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ErrorResponseData notFount(RuntimeException e) {
log.error("运行时异常:", e);
return new ErrorResponseData(500, e.getMessage(), "Internal Server Error", Objects.requireNonNull(HttpContext.getRequest()).getRequestURI());
}
}
package com.system.handler;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;
import javax.validation.constraints.NotNull;
/**
* @author Inori
*/
public class FacePlusThrowErrorHandler implements ResponseErrorHandler {
@Override
public boolean hasError(@NotNull ClientHttpResponse response) {
return false;
}
@Override
public void handleError(@NotNull ClientHttpResponse response) {
}
}
package com.system.kingdee;
import com.system.api.KingDeeApi;
import com.system.constants.KingDeeCommonSyncConstants;
import com.system.utils.KingDeeUtil;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* @author Inori
*/
@Component
public class KingDeeCommonGetApi {
@Autowired
private KingDeeApi kingDeeApi;
public List<Map<String, Object>> getKingDeeData(String sFormId, String queueId, String mesEntryName, List<Map<String, String>> fieldList, Map<String, String> where, String kingDeeLogName) {
Map<String, String> key = KingDeeCommonSyncConstants.purchaseKingDee(fieldList);
List<List<Object>> result = kingDeeApi.getKingDeeData(sFormId, queueId, key, where, kingDeeLogName);
return purchaseIms(result, fieldList, mesEntryName);
}
/**
* 封装第三方字段
*/
private List<Map<String, Object>> purchaseIms(List<List<Object>> list, List<Map<String, String>> fieldList, String mesEntryName) {
List<Map<String, Object>> result = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
String errorName = "Errors";
if (!list.get(0).get(0).toString().contains(errorName)) {
Map<String, Object> map = new HashMap<>(fieldList.size());
List<Map<String, Object>> imsList = new ArrayList<>();
KingDeeCommonSyncConstants.purchaseIms(list, fieldList, map, imsList);
if (!StringUtil.isNotBlank(mesEntryName)) {
map.put(mesEntryName, imsList);
} else {
map.put("children", imsList);
}
result.add(map);
} else {
//如果有错误信息则返回
String message = KingDeeUtil.getMessage(list.get(0).get(0));
Map<String, Object> resultMap = new HashMap<>(1);
resultMap.put("false", message);
result.add(resultMap);
}
}
return result;
}
}
package com.system.kingdee;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.system.api.KingDeeApi;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* @author Inori
*/
@Component
public class KingDeeCommonPushApi {
@Autowired
private KingDeeApi kingDeeApi;
public String kingDeeUpdateThirdData(List<Map<String, Object>> tempList, List<Map<String, String>> fieldList, Map<String, Object> data, String entryName, String kingDeeLogName, String queueId) {
data.put("Model", thirdPartyFieldToKingDee(tempList, fieldList, entryName));
return kingDeeApi.kingDeeDataPush(data, kingDeeLogName, queueId);
}
/**
* thirdPartyField字段转换成金蝶云待添加(其实都是下推后修改)字段
*/
public Map<String, Object> thirdPartyFieldToKingDee(List<Map<String, Object>> dataList, List<Map<String, String>> fieldList, String entryName) {
Map<String, Object> modelMap = new LinkedHashMap<>(2);
List<Map<String, Object>> list = new ArrayList<>();
for (Map<String, Object> map : dataList) {
Map<String, Object> entityMap = new LinkedHashMap<>(10);
for (Map<String, String> field : fieldList) {
if ("true".equals(field.get("isDetailField"))) {
this.populateThirdPartyData(entityMap, map, field);
if (map.containsKey("ERP_SIC")) {
entityMap.put("ERP_SIC", map.get("ERP_SIC"));
}
if (map.containsKey("MES_CODE")) {
entityMap.put("MES_CODE", map.get("MES_CODE"));
}
} else {
this.populateThirdPartyData(modelMap, map, field);
}
}
list.add(entityMap);
}
modelMap.put(entryName, list);
return modelMap;
}
private void populateThirdPartyData(Map<String, Object> temp, Map<String, Object> map, Map<String, String> field) {
String kingDeeField = field.get("kingdeeField");
String thirdPartyField = field.get("thirdPartyField");
String indexField = field.get("indexField");
if (!Constants.NULL.equals(String.valueOf(map.get(thirdPartyField)))) {
if (StringUtil.isNotBlank(indexField)) {
temp.put(kingDeeField, new HashMap<String, Object>(1) {{
put(indexField, map.get(thirdPartyField));
}});
} else {
temp.put(kingDeeField, map.get(thirdPartyField));
}
}
}
public String kingDeeUpdateBySql(String sql, String kingDeeLogName, String queueId) {
return kingDeeApi.kingDeeUpdateBySql(sql, kingDeeLogName, queueId);
}
public String sendPlugInUnit(String plugInUrl, String json) {
return kingDeeApi.sendPlugInUnit(plugInUrl, json, 1);
}
}
package com.system.kingdee;
import com.system.api.KingDeeApi;
import com.system.constants.FormTableStructureConstants;
import com.system.constants.KingDeeCommonSyncConstants;
import com.system.dao.DatabaseTableMapper;
import com.system.transfer.configure.TableStructureCreateInVoRecords;
import com.system.utils.JsonUtil;
import com.system.utils.KingDeeUtil;
import com.system.utils.TableStructureUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Inori
*/
@Component
public class KingDeeCommonSyncApi {
@Autowired
private KingDeeApi kingDeeApi;
@Autowired
private FormTableStructureConstants formTableStructureConstants;
@Autowired
private DatabaseTableMapper databaseTableMapper;
/**
* 获取金蝶云数据
*/
public List<Map<String, Object>> synchronization(String sFormId, String mesEntryName, List<Map<String, String>> fieldList, Map<String, String> where, String kingDeeLogName, String queueId) {
Map<String, String> key = KingDeeCommonSyncConstants.purchaseKingDee(fieldList);
List<List<Object>> result = kingDeeApi.synchronization(sFormId, key, where, kingDeeLogName, queueId);
this.databaseTableDataCreate(sFormId, result, fieldList, queueId);
return purchaseIms(mesEntryName, result, fieldList, queueId);
}
/**
* 封装第三方字段
*/
private List<Map<String, Object>> purchaseIms(String mesEntryName, List<List<Object>> list, List<Map<String, String>> fieldList, String queueId) {
List<Map<String, Object>> result = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
String errorName = "Errors";
if (!list.get(0).get(0).toString().contains(errorName)) {
Map<String, Object> map = new HashMap<>(fieldList.size());
List<Map<String, Object>> mesList = new ArrayList<>();
map.put("QUEUE_ID", queueId);
KingDeeCommonSyncConstants.purchaseIms(list, fieldList, map, mesList);
if (!CollectionUtils.isEmpty(mesList)) {
map.put(mesEntryName, mesList);
}
result.add(map);
} else {
//如果有错误信息则返回
String message = KingDeeUtil.getMessage(list.get(0).get(0));
Map<String, Object> resultMap = new HashMap<>(1);
resultMap.put("false", message);
result.add(resultMap);
}
}
return result;
}
/**
* 数据库表数据创建
*/
private void databaseTableDataCreate(String sFormId, List<List<Object>> result, List<Map<String, String>> fieldList, String queueId) {
Map<String, String> temp = formTableStructureConstants.get(sFormId);
if (!CollectionUtils.isEmpty(temp)) {
if (!CollectionUtils.isEmpty(result)) {
String errorName = "Errors";
if (!result.get(0).get(0).toString().contains(errorName)) {
List<Map<String, Object>> dataList = new ArrayList<>();
for (List<Object> objectList : result) {
Map<String, Object> map = new LinkedHashMap<>();
for (int i = 0; i < fieldList.size(); i++) {
map.put(fieldList.get(i).get("thirdPartyField"), objectList.get(i));
}
map.put("queue_id", queueId);
dataList.add(map);
}
this.createData(sFormId, queueId, temp, dataList);
}
}
}
}
/**
* SQL查询结果: 数据库表数据创建
*/
public void databaseTableDataCreateBySql(String sFormId, List<Object> result, List<Map<String, String>> fieldList, String queueId) {
Map<String, String> temp = formTableStructureConstants.get(sFormId);
if (!CollectionUtils.isEmpty(temp)) {
List<Map<String, Object>> dataList = new ArrayList<>();
for (Object object : result) {
Map<String, Object> map = JsonUtil.toMap(JsonUtil.toString(object), String.class, Object.class);
Map<String, Object> request = new LinkedHashMap<>();
for (Map<String, String> temp02Map : fieldList) {
request.put(temp02Map.get("thirdPartyField"), map.get(temp02Map.get("kingdeeField")));
}
dataList.add(request);
}
this.createData(sFormId, queueId, temp, dataList);
}
}
private void createData(String sFormId, String queueId, Map<String, String> temp, List<Map<String, Object>> dataList) {
List<TableStructureCreateInVoRecords> recordsList = TableStructureUtil.getFieldList(temp.get("formJson"));
List<String> dbFieldList = recordsList.stream().map(TableStructureCreateInVoRecords::getDbFieldName).collect(Collectors.toList());
List<Map<String, Object>> tempList = new ArrayList<>();
Map<String, Object> map = new LinkedHashMap<>();
for (Map<String, Object> data : dataList) {
for (String dbFiledName : dbFieldList) {
map.put(dbFiledName, data.get(dbFiledName));
}
tempList.add(map);
}
if (!CollectionUtils.isEmpty(tempList)) {
try {
databaseTableMapper.databaseTableDataCreate(sFormId.toLowerCase(), dbFieldList, dataList);
} catch (Exception e) {
System.out.println("数据库表: " + sFormId.toLowerCase() + " 唯一标识: " + queueId + " 的数据创建失败");
}
}
}
/**
* 数据库表数据删除
*/
public void databaseTableDataDelete(String sFormId, String queueId) {
databaseTableMapper.databaseTableDataDelete(sFormId.toLowerCase(), queueId);
}
public String sendThirdParty(String json) {
return kingDeeApi.sendThirdParty(json, 1);
}
public String sendPlugInUnit(String plugInUrl, String json) {
return kingDeeApi.sendPlugInUnit(plugInUrl, json, 1);
}
public String kingDeeSelectBySql(String sql, String kingDeeName, String queueId) {
return kingDeeApi.kingDeeSelectBySql(sql, kingDeeName, queueId);
}
}
package com.system.kingdee;
import com.system.api.KingDeeApi;
import com.system.utils.JsonUtil;
import com.system.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
/**
* @author Inori
*/
@Component
public class KingDeeSynchronizationApi {
private final static String S_FORM_ID = "LQKJ_IMSSync";
private Map<String, String> key = new LinkedHashMap<>();
@Autowired
private KingDeeApi kingDeeApi;
public KingDeeSynchronizationApi() {
/* 单据头实体主键 */
this.key.put("FID", "FID");
/* 同步记录数据内码 */
this.key.put("F_LQKJ_SyncDataId", "F_LQKJ_SyncDataId");
/* 同步记录数据分录内码 */
this.key.put("F_LQKJ_SyncDataEntryId", "F_LQKJ_SyncDataEntryId");
/* 同步记录表单 */
this.key.put("F_LQKJ_Syncbill", "F_LQKJ_Syncbill");
/* 同步 */
this.key.put("F_LQKJ_SyncCheck", "F_LQKJ_SyncCheck");
}
/**
* 查询同步为0的数据
*/
public List<Map<String, Object>> synchronization() {
//查询未同步数据
List<List<Object>> list = kingDeeApi.getKingDeeData(S_FORM_ID, "", key, new HashMap<String, String>(1) {{
put("F_LQKJ_SyncCheck", "0");
}}, "");
return purchaseTo(list);
}
/**
* 将查询到的数据封装成本地字段
*/
private List<Map<String, Object>> purchaseTo(List<List<Object>> tempList) {
List<Map<String, Object>> result = new ArrayList<>();
if (!CollectionUtils.isEmpty(tempList)) {
String errorName = "Errors";
if (!tempList.get(0).get(0).toString().contains(errorName)) {
for (List<Object> list : tempList) {
Map<String, Object> map = new HashMap<>(4);
map.put("fid", list.get(0));
map.put("dataId", list.get(1));
map.put("entryId", StringUtil.isNotBlank((String) list.get(2)) ? list.get(2) : null);
map.put("sFormId", list.get(3));
map.put("synchronization", list.get(4));
result.add(map);
}
}
}
return result;
}
public void batchAdd(List<Map<String, Object>> tempList) {
kingDeeApi.batchAdd(S_FORM_ID, JsonUtil.toString(tempList));
}
}
package com.system.model;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
/**
* @author Inori
*/
public class DelayedElement implements Delayed {
private long mills;
public DelayedElement(Integer min) {
this.mills = System.currentTimeMillis() / 1000 + (60 * min);
}
/**
* 当方法返回小于或等于0的数值时, 元素将会被消耗
*/
@Override
public long getDelay(TimeUnit unit) {
return mills - (System.currentTimeMillis() / 1000);
}
/**
* DelayQueue底层是优先队列,需要实现compareTo方法,
* 用于在入列的时候与容器中的数据进行比较,以便确定元素位置。
*/
@Override
public int compareTo(Delayed o) {
return (int) (mills - ((DelayedElement) o).getMills());
}
public long getMills() {
return mills;
}
public void setMills(long mills) {
this.mills = mills;
}
}
package com.system.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
/**
* 金蝶配置表
*
* @author Inori
*/
@TableName("tb_init_connect_param")
public class InitConnectParam {
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 金蝶地址
*/
private String k3CloudUrl;
/**
* 金蝶账套ID
*/
private String dbid;
/**
* 用户名
*/
private String uid;
/**
* 密码
*/
private String pwd;
/**
* 端口
*/
private int lang;
/**
* 是否提交审核
*/
private boolean isAutoSubmit;
/**
* 第三方路径
*/
private String thirdPartyUrl;
/**
* 定时任务时长/分钟
*/
private Integer duration;
/**
* Lic密文
*/
private String licCipherText;
/**
* 创建时间
*/
private String createTime;
/**
* 更新时间
*/
private String updateTime;
public InitConnectParam() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getK3CloudUrl() {
return k3CloudUrl;
}
public void setK3CloudUrl(String k3CloudUrl) {
this.k3CloudUrl = k3CloudUrl;
}
public String getDbid() {
return dbid;
}
public void setDbid(String dbid) {
this.dbid = dbid;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public int getLang() {
return lang;
}
public void setLang(int lang) {
this.lang = lang;
}
public String getThirdPartyUrl() {
return thirdPartyUrl;
}
public void setThirdPartyUrl(String thirdPartyUrl) {
this.thirdPartyUrl = thirdPartyUrl;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
public String getLicCipherText() {
return licCipherText;
}
public void setLicCipherText(String licCipherText) {
this.licCipherText = licCipherText;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}
package com.system.scheduler;
import com.system.api.KingDeeApi;
import com.system.api.KingDeeK3CloudApi;
import com.system.model.InitConnectParam;
import com.system.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
/**
* @author Inori
*/
@Configuration
@EnableScheduling
public class KingDeeLoginScheduler {
private static final Logger log = LoggerFactory.getLogger(KingDeeLoginScheduler.class);
@Autowired
private KingDeeApi kingDeeApi;
@Scheduled(fixedRate = 1000 * 60 * 10)
public void configureTasks() {
InitConnectParam initConnectParam = kingDeeApi.getInitConnectParam();
if (StringUtil.isNotNull(initConnectParam)) {
KingDeeK3CloudApi kingDeeK3CloudApi = new KingDeeK3CloudApi(initConnectParam.getK3CloudUrl());
Boolean flag;
try {
flag = kingDeeK3CloudApi.login(initConnectParam.getDbid(), initConnectParam.getUid(), initConnectParam.getPwd(), initConnectParam.getLang());
} catch (Exception e) {
flag = false;
log.info("金蝶云登录失败!");
}
if (flag) {
log.info("金蝶云登录成功!");
} else {
log.info("金蝶云登录失败!");
}
kingDeeApi.setFlag(flag);
kingDeeApi.setKingDeeK3CloudApi(kingDeeK3CloudApi);
} else {
kingDeeApi.setFlag(false);
}
}
}
package com.system.serializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
/**
* @author Inori
*/
public class SerializerProxy {
public Object deserialize(String content, Class<?> type) {
if (content != null && content.length() != 0) {
return "java.lang.string".equalsIgnoreCase(type.getName()) ? content : this.toDeserialize(content, type);
} else if (!type.isPrimitive()) {
return type;
} else {
return "java.lang.String".equalsIgnoreCase(type.getName()) ? content : null;
}
}
public Object toDeserialize(String content, Class<?> type) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(content, type);
} catch (IOException var6) {
var6.printStackTrace();
}
return null;
}
}
\ No newline at end of file
package com.system.service;
import com.system.transfer.configure.FormTableStructureConfigRefreshInVo;
/**
* @author Inori
*/
public interface IFormTableStructureService {
/**
* 表单配置刷新
*
* @param inVo 条件
*/
void formTableStructureConfigRefresh(FormTableStructureConfigRefreshInVo inVo);
}
package com.system.service;
import com.system.transfer.kingdee.KingDeeDataListInVo;
import com.system.transfer.response.RestResponse;
/**
* @author Inori
*/
public interface IKingDeeCommonGetService {
/**
* 金蝶通用查询
*
* @param inVo 条件
* @return 列表
*/
RestResponse kingDeeDataList(KingDeeDataListInVo inVo);
}
package com.system.service;
import com.system.transfer.kingdee.KingDeeUpdateThirdDataInVo;
/**
* @author Inori
*/
public interface IKingDeeCommonPushService {
/**
* 金蝶下推
*
* @param inVo 条件
* @return 结果
*/
Object kingDeeUpdateThirdData(KingDeeUpdateThirdDataInVo inVo);
}
package com.system.service;
/**
* @author Inori
*/
public interface IKingDeeCommonSyncService {
/**
* 金蝶同步
*
* @param id ID
* @param sFormId 金蝶标识
* @param dataId 金蝶标识ID
*/
void synchronization(Integer id, String sFormId, Integer dataId);
}
package com.system.service;
import com.system.transfer.configure.InitConnectParamCheckInVo;
import com.system.transfer.configure.InitConnectParamCreateInVo;
import com.system.transfer.kingdee.KingdeeConfigRefreshInVo;
import com.system.transfer.response.RestResponse;
/**
* @author Inori
*/
public interface IKingDeeSyncConfigService {
/**
* 保存金蝶配置
*
* @param inVo 条件
* @return 结果
*/
RestResponse initConnectParamCreate(InitConnectParamCreateInVo inVo);
/**
* 校验金蝶参数
*
* @param inVo 条件
* @return 结果
*/
RestResponse initConnectParamCheck(InitConnectParamCheckInVo inVo);
/**
* 金蝶下推配置刷新
*
* @param inVo 条件
*/
void kingdeePushConfigRefresh(KingdeeConfigRefreshInVo inVo);
}
package com.system.service;
/**
* @author Inori
*/
public interface ISynchronizationService {
/**
* 金蝶同步
*/
void kingdeeSynchronization();
/**
* 金蝶失败同步
*/
void kingdeeManualSynchronization();
}
package com.system.service.impl;
import com.system.constants.FormTableStructureConstants;
import com.system.service.IFormTableStructureService;
import com.system.transfer.configure.FormTableStructureConfigRefreshInVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author Inori
*/
@Service
public class FormTableStructureServiceImpl implements IFormTableStructureService {
@Autowired
private FormTableStructureConstants formTableStructureConstants;
@Override
public void formTableStructureConfigRefresh(FormTableStructureConfigRefreshInVo inVo) {
formTableStructureConstants.refresh(inVo.getFormId());
}
}
package com.system.service.impl;
import com.system.constants.KingDeeCommonSyncConstants;
import com.system.kingdee.KingDeeCommonGetApi;
import com.system.service.IKingDeeCommonGetService;
import com.system.transfer.kingdee.KingDeeDataListInVo;
import com.system.transfer.response.RestResponse;
import com.system.utils.JsonUtil;
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.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Inori
*/
@Service
public class KingDeeCommonGetServiceImpl implements IKingDeeCommonGetService {
@Autowired
private KingDeeCommonSyncConstants kingDeeCommonSyncConstants;
@Autowired
private KingDeeCommonGetApi kingDeeCommonGetApi;
@Autowired
private ThirdPartyLogUtil thirdPartyLogUtil;
@Override
public RestResponse kingDeeDataList(KingDeeDataListInVo inVo) {
String queueId = inVo.getQueueId();
Map<String, String> map = kingDeeCommonSyncConstants.getKingDee(inVo.getDocType());
if (CollectionUtils.isEmpty(map)) {
return RestResponse.fail("自定义查询失败! docType为: " + inVo.getDocType() + " 的表单ERP-MES标识不存在");
}
Integer id = thirdPartyLogUtil.thirdPartyLogCreate(map.get("name"), inVo.getDocType(), queueId, JsonUtil.toString(inVo.getData()), null, 0);
List<Object> tempList = JsonUtil.toList(map.get("kingdeeFiledDetail"), Object.class);
List<Map<String, String>> fieldList = tempList.stream().map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, String.class)).collect(Collectors.toList());
Map<String, String> where = new HashMap<>(5);
if (!CollectionUtils.isEmpty(inVo.getData())) {
for (Map.Entry<String, Object> entry : inVo.getData().entrySet()) {
where.put(entry.getKey(), String.valueOf(entry.getValue()));
}
}
List<Map<String, Object>> result = kingDeeCommonGetApi.getKingDeeData(map.get("sFormId"), queueId, map.get("mesEntryName"), fieldList, where, map.get("name"));
if (!CollectionUtils.isEmpty(result)) {
String temp = "false";
if (result.get(0).containsKey(temp)) {
thirdPartyLogUtil.toThirdPartyLogUpdate(id, JsonUtil.toString(result), String.valueOf(result.get(0).get(temp)));
return RestResponse.fail(String.valueOf(result.get(0).get(temp)));
}
}
thirdPartyLogUtil.toThirdPartyLogUpdate(id, JsonUtil.toString(result), "");
return RestResponse.success(result);
}
}
package com.system.service.impl;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.system.constants.KingDeeCommonSyncConstants;
import com.system.constants.KingDeeConstants;
import com.system.dao.SynchronizationRecordsMapper;
import com.system.kingdee.KingDeeCommonSyncApi;
import com.system.service.IKingDeeCommonSyncService;
import com.system.transfer.kingdee.SynchronizationRecordsUpdateInVo;
import com.system.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Inori
*/
@Service
public class KingDeeCommonSyncServiceImpl implements IKingDeeCommonSyncService {
@Autowired
private KingDeeCommonSyncConstants kingDeeCommonSyncConstants;
@Autowired
private KingDeeCommonSyncApi kingDeeCommonSyncApi;
@Autowired
private SynchronizationRecordsMapper synchronizationRecordsMapper;
@Autowired
private KingDeeLogUtil kingDeeLogUtil;
@Autowired
private ThirdPartyLogUtil thirdPartyLogUtil;
@Override
public void synchronization(Integer id, String sFormId, Integer dataId) {
String queueId = SnowFlakeIdUtil.generateId().toString();
//查询表单
Map<String, String> map = kingDeeCommonSyncConstants.get(sFormId);
if (CollectionUtils.isEmpty(map)) {
kingDeeLogUtil.kingDeePushLogCreate("自定义同步失败", queueId, "sFormId为: " + sFormId + " 的表单不存在", null);
synchronizationRecordsMapper.synchronizationRecordsUpdate(new SynchronizationRecordsUpdateInVo(id, queueId, "sFormId为: " + sFormId + " 的表单不存在", 2));
return;
}
List<Object> tempList = JsonUtil.toList(map.get("kingdeeFiledDetail"), Object.class);
List<Map<String, String>> fieldList = tempList.stream().map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, String.class)).collect(Collectors.toList());
List<Map<String, Object>> list = new ArrayList<>();
String customSql = map.get("customSql");
List<Object> objectList = new ArrayList<>();
if (StringUtil.isNotBlank(customSql)) {
customSql = customSql.replaceAll("@" + map.get("primaryKeyField"), String.valueOf(dataId));
//DES加密
customSql = DesHelperUtil.encrypt(customSql, StandardCharsets.UTF_8, "MES&&DES");
String customSqlResult = kingDeeCommonSyncApi.kingDeeSelectBySql(customSql, map.get("name") + "执行SQL", queueId);
Map<String, Object> temp = JsonUtil.toMap(customSqlResult, String.class, Object.class);
if (!CollectionUtils.isEmpty(temp)) {
if (temp.containsKey(KingDeeConstants.CODE_NAME) && KingDeeConstants.SUCCESS_CODE.equals(temp.get(KingDeeConstants.CODE_NAME))) {
objectList = JsonUtil.toList(JsonUtil.toString(temp.get("data")), Object.class);
if (!CollectionUtils.isEmpty(objectList)) {
Map<String, Object> request = new LinkedHashMap<>();
KingDeeCommonSyncConstants.purchaseSqlIms(objectList, fieldList, request);
list.add(request);
kingDeeCommonSyncApi.databaseTableDataCreateBySql(sFormId, objectList, fieldList, queueId);
}
} else {
synchronizationRecordsMapper.synchronizationRecordsUpdate(new SynchronizationRecordsUpdateInVo(id, queueId, customSqlResult, 2));
return;
}
} else {
synchronizationRecordsMapper.synchronizationRecordsUpdate(new SynchronizationRecordsUpdateInVo(id, queueId, customSqlResult, 2));
return;
}
} else {
//设置需要同步的主键
Map<String, String> where = new HashMap<>(1);
where.put(map.get("primaryKeyField"), dataId.toString());
list = kingDeeCommonSyncApi.synchronization(map.get("sFormId"), map.get("mesEntryName"), fieldList, where, map.get("name"), queueId);
if (list.get(0).containsKey(Constants.FALSE)) {
synchronizationRecordsMapper.synchronizationRecordsUpdate(new SynchronizationRecordsUpdateInVo(id, queueId, list.get(0).get(Constants.FALSE).toString(), 2));
return;
}
}
String plugInUrl = map.get("plugInUrl");
if (StringUtil.isNotBlank(plugInUrl)) {
Map<String, Object> request = new HashMap<>(1);
if (!CollectionUtils.isEmpty(objectList)) {
request.put("data", objectList);
} else {
request.put("data", list);
}
String plugInUrlResult = kingDeeCommonSyncApi.sendPlugInUnit(plugInUrl, JsonUtil.toString(request));
thirdPartyLogUtil.thirdPartyLogCreate(map.get("name") + "执行插件", map.get("docType"), queueId, JsonUtil.toString(request), plugInUrlResult, 1);
List<Object> temp01List = JsonUtil.toList(plugInUrlResult, Object.class);
if (!CollectionUtils.isEmpty(temp01List)) {
list = temp01List.stream().map(m -> JsonUtil.toMap(JsonUtil.toString(m), String.class, Object.class)).collect(Collectors.toList());
}
}
this.purchaseIms(map, list, id, queueId);
}
/**
* 同步至MES
*/
private void purchaseIms(Map<String, String> map, List<Map<String, Object>> list, Integer id, String queueId) {
//将数据包装成IMS格式
Map<String, Object> request = new LinkedHashMap<>(3);
request.put("docType", map.get("docType"));
request.put("updateType", "UPDATE");
request.put("data", list);
String json = JsonUtil.toString(request);
String result = kingDeeCommonSyncApi.sendThirdParty(json);
//记录IMS日志
thirdPartyLogUtil.sendThirdPartyLogCreate(map.get("name"), map.get("docType"), queueId, json, result, id);
Map<String, Object> temp = JsonUtil.toMap(result, String.class, Object.class);
if (!CollectionUtils.isEmpty(temp)) {
if (!KingDeeConstants.SUCCESS_CODE.equals(temp.get(KingDeeConstants.CODE_NAME))) {
kingDeeCommonSyncApi.databaseTableDataDelete(map.get("sFormId"), queueId);
}
if (KingDeeConstants.OVERTIME_CODE.equals(temp.get(KingDeeConstants.CODE_NAME))) {
Thread.currentThread().interrupt();
}
} else {
kingDeeCommonSyncApi.databaseTableDataDelete(map.get("sFormId"), queueId);
}
}
}
package com.system.service.impl;
import com.system.api.KingDeeApi;
import com.system.api.KingDeeK3CloudApi;
import com.system.constants.KingDeeCommonPushConstants;
import com.system.constants.KingDeeCommonSyncConstants;
import com.system.model.InitConnectParam;
import com.system.service.IKingDeeSyncConfigService;
import com.system.transfer.configure.InitConnectParamCheckInVo;
import com.system.transfer.configure.InitConnectParamCreateInVo;
import com.system.transfer.kingdee.KingdeeConfigRefreshInVo;
import com.system.transfer.response.RestResponse;
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.Map;
/**
* @author Inori
*/
@Service
public class KingDeeSyncConfigServiceImpl implements IKingDeeSyncConfigService {
@Autowired
private KingDeeApi kingDeeApi;
@Autowired
private KingDeeCommonPushConstants kingDeeCommonPushConstants;
@Autowired
private KingDeeCommonSyncConstants kingDeeCommonSyncConstants;
@Override
public RestResponse initConnectParamCreate(InitConnectParamCreateInVo inVo) {
KingDeeK3CloudApi kingDeeK3CloudApi = new KingDeeK3CloudApi(inVo.getK3CloudUrl());
Boolean flag;
try {
flag = kingDeeK3CloudApi.login(inVo.getDbid(), inVo.getUid(), inVo.getPwd(), inVo.getLang());
} catch (Exception e) {
e.printStackTrace();
flag = false;
}
kingDeeApi.setFlag(flag);
kingDeeApi.setKingDeeK3CloudApi(kingDeeK3CloudApi);
kingDeeApi.setThirdPartyUrl(inVo.getThirdPartyUrl());
if (!flag) {
return RestResponse.fail("参数错误,金蝶登陆失败!");
}
InitConnectParam initConnectParam = new InitConnectParam();
initConnectParam.setId(1);
initConnectParam.setK3CloudUrl(inVo.getK3CloudUrl());
initConnectParam.setDbid(inVo.getDbid());
initConnectParam.setLang(inVo.getLang());
initConnectParam.setUid(inVo.getUid());
initConnectParam.setPwd(inVo.getPwd());
initConnectParam.setThirdPartyUrl(inVo.getThirdPartyUrl());
initConnectParam.setDuration(inVo.getDuration());
kingDeeApi.setInitConnectParam(initConnectParam);
return RestResponse.success();
}
@Override
public RestResponse initConnectParamCheck(InitConnectParamCheckInVo inVo) {
KingDeeK3CloudApi kingDeeK3CloudApi = new KingDeeK3CloudApi(inVo.getK3CloudUrl());
boolean flag = false;
try {
Object[] data = new Object[]{inVo.getDbid(), inVo.getUid(), inVo.getPwd(), inVo.getLang()};
String result = kingDeeK3CloudApi.execute("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser", data, String.class);
Map<String, Object> map = JsonUtil.toMap(result, String.class, Object.class);
if (!CollectionUtils.isEmpty(map)) {
flag = map.containsKey("LoginResultType") && Integer.parseInt(String.valueOf(map.get("LoginResultType"))) == 1;
}
} catch (Exception e) {
flag = false;
}
if (flag) {
return RestResponse.success("参数正确,金蝶云登陆成功");
} else {
return RestResponse.fail("参数错误,金蝶云登陆失败");
}
}
@Override
public void kingdeePushConfigRefresh(KingdeeConfigRefreshInVo inVo) {
if (inVo.getFlag() == 1) {
kingDeeCommonPushConstants.refresh(inVo.getDocType());
} else {
kingDeeCommonSyncConstants.refresh(inVo.getSFormId());
}
}
}
package com.system.service.impl;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.system.dao.SynchronizationRecordsMapper;
import com.system.kingdee.KingDeeSynchronizationApi;
import com.system.service.IKingDeeCommonSyncService;
import com.system.service.ISynchronizationService;
import com.system.transfer.kingdee.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.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author Inori
*/
@Service
public class SynchronizationServiceImpl implements ISynchronizationService {
private ExecutorService threadPool = new ThreadPoolExecutor(5, 5,
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024),
new ThreadFactoryBuilder().setNameFormat("sync-pool-%d").build(),
new ThreadPoolExecutor.AbortPolicy());
@Autowired
private IKingDeeCommonSyncService kingDeeCommonSyncService;
@Autowired
private KingDeeSynchronizationApi kingDeeSynchronizationApi;
@Autowired
private SynchronizationRecordsMapper synchronizationRecordsMapper;
@Override
public void kingdeeSynchronization() {
threadPool.execute(this::synchronization);
}
@Override
public void kingdeeManualSynchronization() {
threadPool.execute(() -> {
List<SynchronizationRecordsListOutVoRecords> recordsList = synchronizationRecordsMapper.synchronizationRecordsListByStatus(Stream.of(1, 2).collect(Collectors.toList()));
for (SynchronizationRecordsListOutVoRecords records : recordsList) {
if (!"LQKJ_IMSSync".equals(records.getSFormId())) {
kingDeeCommonSyncService.synchronization(records.getId(), records.getSFormId(), records.getDataId());
}
}
});
}
@Transactional(rollbackFor = Exception.class)
public void synchronization() {
List<Map<String, Object>> tempList = kingDeeSynchronizationApi.synchronization();
if (!CollectionUtils.isEmpty(tempList)) {
synchronizationRecordsMapper.synchronizationRecordsTempCreate(tempList);
}
List<Map<String, Object>> uList = new ArrayList<>();
List<String> collect = tempList.stream()
.filter(m -> !"LQKJ_IMSSync".equals(m.get("sFormId")))
.map(m -> String.valueOf(m.get("fid")))
.collect(Collectors.toList());
collect.forEach(item -> {
//将金蝶云的数据同步该成1
Map<String, Object> result = new HashMap<>(3);
result.put("FID", item);
result.put("F_LQKJ_SyncCheck", "1");
result.put("F_LQKJ_SyndDatetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
uList.add(result);
});
if (!CollectionUtils.isEmpty(uList)) {
//修改金蝶云是否同步
kingDeeSynchronizationApi.batchAdd(uList);
}
List<Map<String, Object>> mapList = synchronizationRecordsMapper.synchronizationRecordsTempList();
if (!CollectionUtils.isEmpty(mapList)) {
synchronizationRecordsMapper.synchronizationRecordsCreate(mapList);
List<Integer> idList = mapList.stream().map(m -> Integer.parseInt(m.get("id").toString())).collect(Collectors.toList());
synchronizationRecordsMapper.synchronizationRecordsTempDelete(idList);
}
threadPool.execute(() -> {
List<SynchronizationRecordsListOutVoRecords> recordsList = synchronizationRecordsMapper.synchronizationRecordsListByStatus(Stream.of(0).collect(Collectors.toList()));
List<Integer> idList = recordsList.stream().map(SynchronizationRecordsListOutVoRecords::getId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(idList)) {
synchronizationRecordsMapper.synchronizationRecordsUpdateByIdList(idList);
}
for (SynchronizationRecordsListOutVoRecords records : recordsList) {
if (!"LQKJ_IMSSync".equals(records.getSFormId())) {
kingDeeCommonSyncService.synchronization(records.getId(), records.getSFormId(), records.getDataId());
}
if (Thread.currentThread().isInterrupted()) {
break;
}
}
});
}
}
package com.system.transfer.configure;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class FormTableStructureConfigRefreshInVo {
/**
* 表单标识
*/
private String formId;
}
package com.system.transfer.configure;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author Inori
*/
@Data
public class InitConnectParamCheckInVo {
/**
* 金蝶地址
*/
@NotBlank(message = "参数k3CloudUrl缺失")
private String k3CloudUrl;
/**
* 金蝶账套ID
*/
@NotBlank(message = "参数dbid缺失")
private String dbid;
/**
* 用户名
*/
@NotBlank(message = "参数uid缺失")
private String uid;
/**
* 密码
*/
@NotBlank(message = "参数pwd缺失")
private String pwd;
/**
* 端口
*/
@NotNull(message = "参数lang缺失")
private int lang;
}
package com.system.transfer.configure;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author Inori
*/
@Data
public class InitConnectParamCreateInVo {
/**
* 金蝶地址
*/
@NotBlank(message = "参数k3CloudUrl缺失")
private String k3CloudUrl;
/**
* 金蝶账套ID
*/
@NotBlank(message = "参数dbid缺失")
private String dbid;
/**
* 用户名
*/
@NotBlank(message = "参数uid缺失")
private String uid;
/**
* 密码
*/
@NotBlank(message = "参数pwd缺失")
private String pwd;
/**
* 端口
*/
@NotNull(message = "参数lang缺失")
private int lang;
/**
* 第三方路径
*/
@NotBlank(message = "参数thirdPartyUrl缺失")
private String thirdPartyUrl;
/**
* 分钟
*/
@NotNull(message = "参数duration缺失")
private Integer duration;
}
package com.system.transfer.configure;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class InitConnectParamOutVo {
/**
* ID
*/
private Integer id;
/**
* 金蝶地址
*/
private String k3CloudUrl;
/**
* 金蝶账套ID
*/
private String dbid;
/**
* 用户名
*/
private String uid;
/**
* 密码
*/
private String pwd;
/**
* 端口
*/
private int lang;
/**
* 第三方路径
*/
private String thirdPartyUrl;
/**
* 定时任务时长/分钟
*/
private int duration;
/**
* 创建时间
*/
private String createTime;
}
package com.system.transfer.configure;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class TableStructureCreateInVoRecords {
/**
* 标识
*/
private String key;
/**
* 数据库表名称
*/
private String dbTableName;
/**
* 数据库表字段名称
*/
private String dbFieldName;
/**
* 旧数据库表字段名称
*/
private String oldDbFileName;
/**
* 数据库表字段类型
*/
private String dbFieldType;
/**
* 数据库表字段默认值
*/
private String dbFieldDefault;
/**
* 数据库表字段注释
*/
private String dbFieldComment;
}
package com.system.transfer.configure;
import lombok.Data;
/**
* 表单记录
*
* @author Inori
*/
@Data
public class TableStructureListOutVoRecords {
/**
* ID
*/
private Integer id;
/**
* 表单标识
*/
private String formId;
/**
* 数据库表名称
*/
private String dbTableName;
/**
* 数据库表注释
*/
private String dbTableComment;
/**
* 前端表单Json
*/
private String formJson;
}
\ No newline at end of file
package com.system.transfer.kingdee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Inori
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KingDeeCommonConfigOneInVo {
/**
* 金蝶标识
*/
private String sFormId;
/**
* 第三方标识
*/
private String docType;
/**
* 配置方向(-1-ERP/MES 1-MES/ERP)
*/
private Integer flag;
}
package com.system.transfer.kingdee;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;
/**
* @author Inori
*/
@Data
public class KingDeeDataListInVo {
/**
* 标识
*/
@NotBlank(message = "参数docType缺失")
private String docType;
/**
* 唯一标识
*/
private String queueId;
/**
* 查询参数
*/
@NotNull(message = "参数data缺失")
private Map<String, Object> data;
}
package com.system.transfer.kingdee;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class KingDeeLogCreateInVo {
/**
* 业务名称
*/
private String name;
/**
* 唯一标识
*/
private String queueId;
/**
* 请求参数
*/
private String request;
/**
* 是否成功(0-失败,1-成功)
*/
private Integer flag;
/**
* 响应信息
*/
private String response;
/**
* 错误原因
*/
private String message;
/**
* 耗时
*/
private Integer costTime;
}
package com.system.transfer.kingdee;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
/**
* @author Inori
*/
@Data
public class KingDeeUpdateThirdDataInVo {
/**
* 标识
*/
@NotBlank(message = "参数docType缺失")
private String docType;
/**
* 数据
*/
@NotNull(message = "参数data缺失")
private List<Map<String, Object>> data;
}
package com.system.transfer.kingdee;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class KingdeeCommonConfigListOutVoRecords {
/**
* ID
*/
private Integer id;
/**
* 第三方标识
*/
private String docType;
/**
* 金蝶标识
*/
private String sFormId;
/**
* 日志名称
*/
private String name;
/**
* 配置方向(-1-ERP/MES 1-MES/ERP)
*/
private Integer flag;
/**
* 单据主键字段
*/
private String primaryKeyField;
/**
* MES分录标识
*/
private String mesEntryName;
/**
* 分录标识
*/
private String entryName;
/**
* 源单标识
*/
private String fathersFormId;
/**
* 源单分录标识
*/
private String fatherEntryName;
/**
* 下推规则
*/
private String pushRule;
/**
* 是否在事务中
*/
private Integer isInTransaction;
/**
* 执行步骤(0-暂存,1-保存,2-提交,3-审核)
*/
private Integer isAutoPerform;
/**
* 金蝶字段相关明细
*/
private String kingdeeFiledDetail;
/**
* 插件地址
*/
private String plugInUrl;
/**
* 自定义Sql
*/
private String customSql;
/**
* 创建时间
*/
private String createTime;
}
\ No newline at end of file
package com.system.transfer.kingdee;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class KingdeeConfigRefreshInVo {
/**
* 第三方标识
*/
private String docType;
/**
* 金蝶标识
*/
private String sFormId;
/**
* 配置方向(-1-ERP/MES 1-MES/ERP)
*/
private Integer flag;
}
package com.system.transfer.kingdee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Inori
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SynchronizationRecordsDeleteInVo {
/**
* ID
*/
private Integer id;
}
package com.system.transfer.kingdee;
import com.system.utils.StringUtil;
/**
* @author Inori
*/
public class SynchronizationRecordsListInVo {
/**
* 同步记录主键
*/
private String fid;
/**
* 金蝶标识
*/
private String sFormId;
/**
* 唯一标识
*/
private String queueId;
/**
* 同步状态(0-未同步,1-同步中,2-同步成功,3-同步失败)
*/
private Integer status;
/**
* 页码
*/
private Integer pageNo;
/**
* 每页数量
*/
private Integer pageSize;
private static final Integer DEFAULT_PAGE_NO = 1;
private static final Integer DEFAULT_PAGE_SIZE = 20;
public SynchronizationRecordsListInVo() {
}
public SynchronizationRecordsListInVo(Integer status) {
this.status = status;
}
public String getFid() {
return fid;
}
public void setFid(String fid) {
this.fid = fid;
}
public String getsFormId() {
return sFormId;
}
public void setsFormId(String sFormId) {
this.sFormId = sFormId;
}
public String getQueueId() {
return queueId;
}
public void setQueueId(String queueId) {
this.queueId = queueId;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getPageNo() {
if (StringUtil.isNull(pageNo) || pageNo == -1) {
return DEFAULT_PAGE_NO;
}
return pageNo;
}
public void setPageNo(Integer pageNo) {
this.pageNo = pageNo;
}
public Integer getPageSize() {
if (StringUtil.isNull(pageSize) || pageSize == -1) {
return DEFAULT_PAGE_SIZE;
}
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
package com.system.transfer.kingdee;
import lombok.Data;
import java.util.List;
/**
* @author Inori
*/
@Data
public class SynchronizationRecordsListOutVo {
/**
* 总数
*/
private Integer total;
/**
* 记录
*/
private List<SynchronizationRecordsListOutVoRecords> records;
}
package com.system.transfer.kingdee;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class SynchronizationRecordsListOutVoRecords {
/**
* ID
*/
private Integer id;
/**
* 同步记录主键
*/
private String fid;
/**
* 同步记录数据内码
*/
private Integer dataId;
/**
* 同步记录数据分录内码
*/
private Integer entryId;
/**
* 金蝶标识
*/
private String sFormId;
/**
* 唯一标识
*/
private String queueId;
/**
* 错误信息
*/
private String message;
/**
* 同步状态(0-未同步,1-同步中,2-同步成功,3-同步失败)
*/
private Integer status;
/**
* 创建时间
*/
private String createTime;
}
package com.system.transfer.kingdee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Inori
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SynchronizationRecordsUpdateInVo {
/**
* ID
*/
private Integer id;
/**
* 唯一标识
*/
private String queueId;
/**
* 错误原因
*/
private String message;
/**
* 同步状态(0-未同步,1-同步中,2-同步失败,3-同步成功)
*/
private Integer status;
}
package com.system.transfer.kingdee;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class ThirdPartyLogCreateInVo {
/**
* ID
*/
private Integer id;
/**
* 业务名称
*/
private String name;
/**
* 业务标识
*/
private String code;
/**
* 唯一标识
*/
private String queueId;
/**
* 请求参数
*/
private String request;
/**
* 是否成功(0-失败,1-成功)
*/
private Integer flag;
/**
* 响应信息
*/
private String response;
/**
* 错误原因
*/
private String message;
}
package com.system.transfer.kingdee;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class ThirdPartyLogUpdateInVo {
/**
* ID
*/
private Integer id;
/**
* 是否成功(0-失败,1-成功)
*/
private Integer flag;
/**
* 响应信息
*/
private String response;
/**
* 错误原因
*/
private String message;
}
package com.system.transfer.log;
import lombok.Data;
/**
* @author Inori
*/
@Data
public class KingDeeLogCreateInVo {
/**
* 业务名称
*/
private String name;
/**
* 唯一标识
*/
private String queueId;
/**
* 请求参数
*/
private String request;
/**
* 是否成功(0-失败,1-成功)
*/
private Integer flag;
/**
* 响应信息
*/
private String response;
/**
* 错误原因
*/
private String message;
/**
* 耗时
*/
private Integer costTime;
}
package com.system.transfer.response;
import lombok.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 请求失败的返回
*
* @author stylefeng
* @Date 2018/1/4 22:39
*/
@Data
public class ErrorResponseData {
/**
* 响应时间
*/
private String timestamp;
/**
* 响应状态码
*/
private Integer code;
/**
* 响应信息
*/
private String message;
/**
* 异常的具体类名称
*/
private String error;
/**
* 路径
*/
private String path;
public ErrorResponseData(Integer code, String message, String error, String path) {
this.timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
this.code = code;
this.message = message;
this.error = error;
this.path = path;
}
}
package com.system.transfer.response;
/**
* @author Inori
*/
public class RestResponse {
public static final int CODE_SUCCESS = 200;
public static final int CODE_VERSION_NONSUPPORT = 305;
public static final int CODE_PARAM_ERROR = 400;
public static final int CODE_TOKEN_EXPIRED = 402;
public static final int CODE_TOKEN_NOTFOUND = 403;
public static final int CODE_FORBIDDEN = 406;
public static final int CODE_SERVER_ERROR = 500;
private int code;
private String message;
private Object data = null;
public static RestResponse success() {
RestResponse restResponse = new RestResponse();
restResponse.setCode(200);
restResponse.setData(new Object());
return restResponse;
}
public static RestResponse success(Object data) {
RestResponse restResponse = new RestResponse();
restResponse.setCode(200);
restResponse.setData(data);
return restResponse;
}
public static RestResponse fail(int code, String msg) {
RestResponse restResponse = new RestResponse();
restResponse.setCode(code);
restResponse.setMessage(msg);
return restResponse;
}
public static RestResponse fail(String msg) {
return fail(CODE_PARAM_ERROR, msg);
}
public static RestResponse fail(String msg, Object data) {
RestResponse restResponse = new RestResponse();
restResponse.setCode(CODE_PARAM_ERROR);
restResponse.setMessage(msg);
restResponse.setData(data);
return restResponse;
}
public static RestResponse error(String msg) {
RestResponse restResponse = new RestResponse();
restResponse.setCode(CODE_SERVER_ERROR);
restResponse.setMessage(msg);
return restResponse;
}
public boolean isSuccess() {
return CODE_SUCCESS == this.code;
}
public int getCode() {
return code;
}
public RestResponse setCode(int code) {
this.code = code;
return this;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
if (data == null) {
return new Object();
}
return data;
}
public void setData(Object data) {
this.data = data;
}
}
package com.system.utils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.nio.charset.Charset;
/**
* @author Inori
*/
public class DesHelperUtil {
/**
* 加密
*/
public static String encrypt(String srcStr, Charset charset, String sKey) {
byte[] src = srcStr.getBytes(charset);
byte[] buf = encrypt(src, sKey);
return parseByte2HexStr(buf);
}
/**
* 解密
*/
public static String decrypt(String hexStr, Charset charset, String sKey) throws Exception {
byte[] src = parseHexStr2Byte(hexStr);
byte[] buf = decrypt(src, sKey);
return new String(buf, charset);
}
/**
* 加密
*/
public static byte[] encrypt(byte[] data, String sKey) {
try {
byte[] key = sKey.getBytes();
// 初始化向量
IvParameterSpec iv = new IvParameterSpec(key);
DESKeySpec desKey = new DESKeySpec(key);
// 创建一个密匙工厂,然后用它把DESKeySpec转换成securekey
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
// 用密匙初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, securekey, iv);
// 现在,获取数据并加密
// 正式执行加密操作
return cipher.doFinal(data);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
/**
* 解密
*/
public static byte[] decrypt(byte[] src, String sKey) throws Exception {
byte[] key = sKey.getBytes();
// 初始化向量
IvParameterSpec iv = new IvParameterSpec(key);
// 创建一个DESKeySpec对象
DESKeySpec desKey = new DESKeySpec(key);
// 创建一个密匙工厂
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
// 将DESKeySpec对象转换成SecretKey对象
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成解密操作
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
// 用密匙初始化Cipher对象
cipher.init(Cipher.DECRYPT_MODE, securekey, iv);
// 真正开始解密操作
return cipher.doFinal(src);
}
/**
* 将二进制转换成16进制
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 将16进制转换为二进制
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1) return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
}
\ No newline at end of file
package com.system.utils;
import com.system.handler.FacePlusThrowErrorHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
import java.util.Set;
/**
* @author Inori
*/
public class HttpUtil {
private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);
/**
* 连接超时时间
*/
private static final int CONN_TIMEOUT = 10000;
/**
* 请求超时时间
*/
private static final int READ_TIMEOUT = 10000;
/**
* 请求工具
*/
private static RestTemplate restTemplate;
static {
//设置超时时间
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(CONN_TIMEOUT);
requestFactory.setReadTimeout(READ_TIMEOUT);
restTemplate = new RestTemplate(requestFactory);
restTemplate.setErrorHandler(new FacePlusThrowErrorHandler());
}
/**
* 设置header公共参数
*/
private static HttpHeaders initHeader() {
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Type", "application/json; charset=UTF-8");
return headers;
}
/**
* 设置header参数
*/
private static void setHeaderParam(HttpHeaders httpHeaders, Map<String, Object> headers) {
if (!CollectionUtils.isEmpty(headers)) {
Set<String> keys = headers.keySet();
for (String key : keys) {
httpHeaders.add(key, headers.get(key).toString());
}
}
}
/**
* 发送Get请求
*/
public static ResponseEntity<String> httpGet(String url) {
//初始化header公共参数
HttpHeaders httpHeaders = initHeader();
//发送请求
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
return restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
}
/**
* 发送Get请求
*/
public static ResponseEntity<String> httpGet(String url, Map<String, Object> param) {
//初始化header公共参数
HttpHeaders httpHeaders = initHeader();
//组装查询参数
url = setParam(url, param);
//发送请求
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
log.info("【Get请求】Url: {}", url);
return restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
}
private static String setParam(String url, Map<String, Object> param) {
Set<String> keys = param.keySet();
StringBuilder builder = new StringBuilder();
builder.append("?");
for (String key : keys) {
builder.append(key).append("=").append(param.get(key)).append("&");
}
builder.deleteCharAt(builder.lastIndexOf("&"));
url = url + builder.toString();
return url;
}
/**
* 发送Get请求
*/
public static ResponseEntity<String> httpGet(String url, Map<String, Object> headers, Map<String, Object> param) {
//如果查询参数为空,则调用不带参数的Get请求
if (CollectionUtils.isEmpty(param)) {
return httpGet(url, headers);
}
//组装查询参数
url = setParam(url, param);
//发送请求
log.info("【Get请求】Url: {}", url);
return httpGet(url, headers);
}
/**
* 发送Post请求
*/
public static ResponseEntity<String> httpPost(String url, String json) {
//初始化header公共参数
HttpHeaders httpHeaders = initHeader();
//发送请求
log.info("【Post请求】Url: {}", url);
return toPost(url, httpHeaders, json);
}
/**
* 发送Post请求
*/
public static ResponseEntity<String> httpPost(String url, Map<String, Object> header, String json) {
//初始化header公共参数
HttpHeaders httpHeaders = initHeader();
setHeaderParam(httpHeaders, header);
//发送请求
log.info("【Post请求】Url: {}", url);
return toPost(url, httpHeaders, json);
}
/**
* 发送请求
*/
private static ResponseEntity<String> toPost(String url, HttpHeaders httpHeaders, String json) {
HttpEntity<String> httpEntity = new HttpEntity<>(json, httpHeaders);
return restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
}
}
\ No newline at end of file
package com.system.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Inori
*/
@Slf4j
public class JsonUtil {
private static final ObjectMapper MAPPER = new ObjectMapper();
public static String toString(Object obj) {
if (obj == null) {
return null;
}
if (obj.getClass() == String.class) {
return (String) obj;
}
try {
return MAPPER.writeValueAsString(obj);
} catch (JsonProcessingException e) {
log.error("Json解析出错: JsonUtil.toString(), Json: " + obj);
return "";
}
}
public static <T> T toBean(String json, Class<T> tClass) {
try {
return MAPPER.readValue(json, tClass);
} catch (IOException e) {
log.error("Json解析出错: JsonUtil.toBean(), Json: " + json);
T t = null;
try {
t = tClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
ex.printStackTrace();
}
return t;
}
}
public static <T> String listToJson(List<T> list) {
if (null != list && list.size() > 0) {
JSONArray jsonArray = JSONArray.fromObject(list);
return jsonArray.toString();
}
return "";
}
public static <E> List<E> toList(String json, Class<E> eClass) {
try {
return MAPPER.readValue(json, MAPPER.getTypeFactory().constructCollectionType(List.class, eClass));
} catch (IOException e) {
log.error("Json解析出错: JsonUtil.toList(), Json: " + json);
return new ArrayList<>();
}
}
public static <K, V> Map<K, V> toMap(String json, Class<K> kClass, Class<V> vClass) {
try {
return MAPPER.readValue(json, MAPPER.getTypeFactory().constructMapType(Map.class, kClass, vClass));
} catch (IOException e) {
log.error("Json解析出错: JsonUtil.toMap(), Json: " + json);
return new HashMap<>(10);
}
}
public static <T> T nativeRead(String json, TypeReference<T> type) {
try {
return MAPPER.readValue(json, type);
} catch (IOException e) {
log.error("Json解析出错: JsonUtil.nativeRead(), Json: " + json);
return null;
}
}
}
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论