Compare commits

...

2 Commits
master ... 2.0

Author SHA1 Message Date
linjj 3955445ac7 中山医院接口 2 years ago
linrf 64c230113f 2.0 2 years ago

@ -2,11 +2,7 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>framework</artifactId>
<groupId>com.docus</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.docus</groupId>
<artifactId>docus-soap-api-client</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
@ -24,58 +20,72 @@
<name>docus-soap-api-client</name>
<properties>
<java.version>1.8</java.version>
<spring.version>5.0.2.RELEASE</spring.version>
<spring-ws.version>3.0.10.RELEASE</spring-ws.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>${spring-ws.version}</version>
</dependency>
<dependency>
<groupId>com.docus</groupId>
<artifactId>docus-tool-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>

@ -1,13 +0,0 @@
package com.docus.soap.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DocusSoapApplication {
public static void main(String[] args) {
SpringApplication.run(DocusSoapApplication.class, args);
}
}

@ -7,8 +7,9 @@ public class EnableSoapAPIClientSelector extends AdviceModeImportSelector<Enable
@Override
protected String[] selectImports(AdviceMode adviceMode) {
if (adviceMode != AdviceMode.PROXY)
if (adviceMode != AdviceMode.PROXY) {
throw new IllegalStateException("@EnableSoapAPIClient only support PROXY advice mode.");
}
return new String[]{SoapAPIConfig.class.getName()};
}
}

@ -1,6 +1,6 @@
package com.docus.soap.api;
import com.docus.soap.api.service.ComplaintAPIService;
import com.docus.soap.api.service.XMZSYYQRCodeAPIService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@ -83,8 +83,8 @@ public class SoapAPIConfig {
}
@Bean
public ComplaintAPIService complaintApiService() {
ComplaintAPIService complaintApiService = new ComplaintAPIService();
public XMZSYYQRCodeAPIService complaintApiService() {
XMZSYYQRCodeAPIService complaintApiService = new XMZSYYQRCodeAPIService();
complaintApiService.setWebServiceClient(soapApiClient());
return complaintApiService;
}

@ -0,0 +1,31 @@
package com.docus.soap.api;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import java.io.IOException;
import java.util.Properties;
public class SoapAppContextInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
@Override
public void initialize(ConfigurableWebApplicationContext context) {
PropertyLoader propertyLoader = new PropertyLoader();
try {
propertyLoader.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:*.properties"));
context.getEnvironment().setIgnoreUnresolvableNestedPlaceholders(true);
context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("properties", propertyLoader.loadProperties()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static class PropertyLoader extends PropertySourcesPlaceholderConfigurer {
Properties loadProperties() throws IOException {
return mergeProperties();
}
}
}

@ -1,53 +0,0 @@
package com.docus.soap.api.request.complain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public enum ComplaintProcessStatus {
/*受理中*/
RECEIVED(0),
/*网友已给出方案*/
BUYER_GIVE_SOLUTION(1),
/*商家已给出方案*/
SELLER_GIVE_SOLUTION(2),
/*安排监理上门*/
SUPERVISOR_CALL(3),
/*双方达成协议*/
REACH_AGREEMENT(4),
/*协调未果*/
CONSULTATION_NO_RESULT(5),
/*无理投诉*/
UNJUSTIFIABLE_COMPLAINT(6),
/*处理完成*/
FINISH(7),
/*节后处理*/
PROCESS_AFTER_HOLIDAY(8);
private static final Logger LOGGER = LoggerFactory.getLogger(ComplaintProcessStatus.class);
private int value;
ComplaintProcessStatus(int value) {
this.value = value;
}
@JsonValue
public int getValue() {
return value;
}
@JsonCreator
public static ComplaintProcessStatus fromValue(int code) {
for (ComplaintProcessStatus status : ComplaintProcessStatus.values()) {
if (status.value == code) {
return status;
}
}
LOGGER.warn(ComplaintProcessStatus.class.getName() + " can not find value :" + code);
return null;
}
}

@ -1,72 +0,0 @@
package com.docus.soap.api.request.complain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "GetTableByIdDateDataRequest")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetTableByIdDateDataRequest {
@XmlElement(name = "store_id")
private int storeId;
@XmlElement(name = "startDate")
private String startDate;
@XmlElement(name = "endDate")
private String endDate;
@XmlElement(name = "complaintGrade")
private Integer complaintGrade;
@XmlElement(name = "currentpage")
private int currentpage;
@XmlElement(name = "pagesize")
private int pagesize;
public int getStoreId() {
return storeId;
}
public void setStoreId(int storeId) {
this.storeId = storeId;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public Integer getComplaintGrade() {
return complaintGrade;
}
public void setComplaintGrade(Integer complaintGrade) {
this.complaintGrade = complaintGrade;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage) {
this.currentpage = currentpage;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
}

@ -0,0 +1,28 @@
package com.docus.soap.api.request.zsyy;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@Data
@XmlRootElement(name = "SOF_LoginWithAccountInfo", namespace = "http://webservice.platform.jhsec.com.cn/")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetLoginInfoRequest {
@XmlElement(name = "sys")
private String sys;
@XmlElement(name = "accountType")
private String accountType;
@XmlElement(name = "account")
private String account;
@XmlElement(name = "password")
private String password;
}

@ -1,4 +1,4 @@
package com.docus.soap.api.request.complain;
package com.docus.soap.api.request.zsyy;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "SOF_GetQRCodeBySys", namespace = "http://webservice.qrcode.pki.jhsec.com.cn/")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetTableByIdDateRequest {
public class GetQRCodeBySysRequest {
@XmlElement(name = "sys")
private String sys;

@ -0,0 +1,22 @@
package com.docus.soap.api.request.zsyy;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "SOF_QueryQRCode", namespace = "http://webservice.qrcode.pki.jhsec.com.cn/")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetQueryQRCodeRequest {
@XmlElement(name = "qrCode")
private String qrCode;
public String getQrCode() {
return qrCode;
}
public void setQrCode(String qrCode) {
this.qrCode = qrCode;
}
}

@ -1,22 +0,0 @@
package com.docus.soap.api.response.complain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "GetComplaintListResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetComplaintListResponse {
@XmlElement(name = "GetComplaintListResult")
private String complaintListResult;
public String getComplaintListResult() {
return complaintListResult;
}
public void setComplaintListResult(String complaintListResult) {
this.complaintListResult = complaintListResult;
}
}

@ -1,5 +1,6 @@
package com.docus.soap.api.response.complain;
import com.docus.soap.api.response.zsyy.DataItem;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;

@ -1,4 +1,4 @@
package com.docus.soap.api.response.complain;
package com.docus.soap.api.response.zsyy;
import lombok.Data;

@ -1,4 +1,4 @@
package com.docus.soap.api.response.complain;
package com.docus.soap.api.response.zsyy;
import javax.xml.bind.annotation.*;
import java.util.List;

@ -0,0 +1,42 @@
package com.docus.soap.api.response.zsyy;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class GetLoginInfoResponse {
@XmlElement(name = "data")
private String data;
@XmlElement(name = "code")
private String code;
@XmlElement(name = "msg")
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

@ -0,0 +1,20 @@
package com.docus.soap.api.response.zsyy;
import javax.xml.bind.annotation.*;
import java.util.List;
@XmlRootElement(name = "SOF_LoginWithAccountInfoResponse" ,namespace = "http://webservice.platform.jhsec.com.cn/")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetLoginInfoResultResponse {
@XmlAnyElement
public List<Object> results;
public List<Object> getResults() {
return results;
}
public void setResults(List<Object> results) {
this.results = results;
}
}

@ -1,11 +1,15 @@
package com.docus.soap.api.response.complain;
package com.docus.soap.api.response.zsyy;
import lombok.Data;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class ComplaintListResult {
public class GetQRCodeBySysResponse {
@XmlElement(name = "data")
private DataItem data;
@ -16,13 +20,7 @@ public class ComplaintListResult {
@XmlElement(name = "msg")
private String msg;
public DataItem getData() {
return data;
}
public void setData(DataItem data) {
this.data = data;
}
public String getCode() {
return code;

@ -1,4 +1,4 @@
package com.docus.soap.api.response.complain;
package com.docus.soap.api.response.zsyy;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -8,7 +8,7 @@ import java.util.List;
@XmlRootElement(name = "SOF_GetQRCodeBySysResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetTableByIdDateResponse {
public class GetQRCodeBySysResultResponse {
@XmlAnyElement
public List<Object> results;

@ -0,0 +1,42 @@
package com.docus.soap.api.response.zsyy;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class GetQueryQRCodeResponse {
@XmlElement(name = "data")
private QueryQRCodeData data;
@XmlElement(name = "code")
private String code;
@XmlElement(name = "msg")
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

@ -0,0 +1,23 @@
package com.docus.soap.api.response.zsyy;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "SOF_QueryQRCodeResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class GetQueryQRCodeResultResponse {
@XmlAnyElement
public List<Object> results;
public List<Object> getResults() {
return results;
}
public void setResults(List<Object> results) {
this.results = results;
}
}

@ -0,0 +1,37 @@
package com.docus.soap.api.response.zsyy;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import java.io.Serializable;
@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class QueryQRCodeData implements Serializable {
private static final long serialVersionUID = 2657976429770220410L;
@XmlElement(name = "resultCode")
private String resultCode;
@XmlElement(name = "qrCodeStatus")
private String qrCodeStatus;
@XmlElement(name = "userName")
private String userName;
@XmlElement(name = "userIdCardNum")
private String userIdCardNum;
@XmlElement(name = "userPhoneNum")
private String userPhoneNum;
@XmlElement(name = "resultMsg")
private String resultMsg;
@XmlElement(name = "userJobNum")
private String userJobNum;
}

@ -1,5 +1,5 @@
@XmlSchema(namespace = "http://webservice.qrcode.pki.jhsec.com.cn/", elementFormDefault = XmlNsForm.QUALIFIED)
package com.docus.soap.api.response.complain;
package com.docus.soap.api.response.zsyy;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

@ -1,23 +0,0 @@
package com.docus.soap.api.service;
import com.docus.core.util.json.JSON;
import com.docus.soap.api.SoapAPIClient;
import com.docus.soap.api.SoapAPISettings;
import com.docus.soap.api.request.complain.GetTableByIdDateRequest;
import com.docus.soap.api.response.complain.ComplaintListResult;
import com.docus.soap.api.response.complain.GetTableByIdDateResponse;
import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
public class ComplaintAPIService {
private SoapAPIClient soapAPIClient;
public ComplaintListResult getTableByIdDate(GetTableByIdDateRequest targetRequest, SoapAPISettings soapAPISettings) {
GetTableByIdDateResponse response = (GetTableByIdDateResponse) soapAPIClient.soapCall(targetRequest, soapAPISettings.getAction(), soapAPISettings.getUri());
ComplaintListResult complaintListResult = JSON.fromJSON((((ElementNSImpl) response.getResults().get(0)).getFirstChild().getTextContent()), ComplaintListResult.class);
return complaintListResult;
}
public void setWebServiceClient(SoapAPIClient webServiceClient) {
this.soapAPIClient = webServiceClient;
}
}

@ -0,0 +1,45 @@
package com.docus.soap.api.service;
import com.docus.soap.api.SoapAPIClient;
import com.docus.soap.api.SoapAPISettings;
import com.docus.soap.api.request.zsyy.GetLoginInfoRequest;
import com.docus.soap.api.request.zsyy.GetQRCodeBySysRequest;
import com.docus.soap.api.request.zsyy.GetQueryQRCodeRequest;
import com.docus.soap.api.response.zsyy.*;
import com.docus.soap.api.util.JSON;
import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
public class XMZSYYQRCodeAPIService {
private SoapAPIClient soapAPIClient;
/**
*
*/
public GetQRCodeBySysResponse getQRCodeBySys(GetQRCodeBySysRequest targetRequest, SoapAPISettings soapAPISettings) {
GetQRCodeBySysResultResponse response = (GetQRCodeBySysResultResponse) soapAPIClient.soapCall(targetRequest, soapAPISettings.getAction(), soapAPISettings.getUri());
return JSON.fromJSON((((ElementNSImpl) response.getResults().get(0)).getFirstChild().getTextContent()), GetQRCodeBySysResponse.class);
}
/**
* @description:
* @author linjj
* @date: 2023/5/24 11:46
*/
public GetQueryQRCodeResponse getQueryQRCode(GetQueryQRCodeRequest queryQRCodeRequest, SoapAPISettings soapAPISettings){
GetQueryQRCodeResultResponse response = (GetQueryQRCodeResultResponse) soapAPIClient.soapCall(queryQRCodeRequest, soapAPISettings.getAction(), soapAPISettings.getUri());
return JSON.fromJSON((((ElementNSImpl) response.getResults().get(0)).getFirstChild().getTextContent()), GetQueryQRCodeResponse.class);
}
/**
* @description:
* @author linjj
* @date: 2023/5/25 11:33
*/
public GetLoginInfoResponse getLoginInfo(GetLoginInfoRequest getLoginInfoRequest, SoapAPISettings soapAPISettings){
GetLoginInfoResultResponse response = (GetLoginInfoResultResponse) soapAPIClient.soapCall(getLoginInfoRequest, soapAPISettings.getAction(), soapAPISettings.getUri());
return JSON.fromJSON((((ElementNSImpl) response.getResults().get(0)).getFirstChild().getTextContent()), GetLoginInfoResponse.class);
}
public void setWebServiceClient(SoapAPIClient webServiceClient) {
this.soapAPIClient = webServiceClient;
}
}

@ -0,0 +1,126 @@
package com.docus.soap.api.util;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public final class Convert {
public static final String DATE_FORMAT_DATE = "MM/dd/yyyy";
public static final String DATE_FORMAT_DATETIME = "MM/dd/yyyy'T'HH:mm:ss";
public static final String DATA_FORMAT_DATETIME_SLASH = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_FORMAT_ISO_WITH_TIMEZONE = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
public static Integer toInt(String text, Integer defaultValue) {
if (!StringUtils.hasText(text)) {
return defaultValue;
}
try {
return Integer.parseInt(text);
} catch (NumberFormatException e) {
return defaultValue;
}
}
public static Long toLong(String text, Long defaultValue) {
if (!StringUtils.hasText(text)) {
return defaultValue;
}
try {
return Long.parseLong(text);
} catch (NumberFormatException e) {
return defaultValue;
}
}
public static Double toDouble(String text, Double defaultValue) {
if (!StringUtils.hasText(text)) {
return defaultValue;
}
try {
return Double.parseDouble(text);
} catch (NumberFormatException e) {
return defaultValue;
}
}
// since DateFormat is not thread safe, we create for each parsing
public static Date toDate(String date, String formatPattern, Date defaultValue) {
if (!StringUtils.hasText(date)) {
return defaultValue;
}
try {
SimpleDateFormat format = new SimpleDateFormat(formatPattern);
return format.parse(date);
} catch (ParseException e) {
return defaultValue;
}
}
public static Date toDate(String date, String formatPattern) {
try {
SimpleDateFormat format = new SimpleDateFormat(formatPattern);
return format.parse(date);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
public static Date toDate(String date, Date defaultValue) {
return toDate(date, DATE_FORMAT_DATE, defaultValue);
}
public static Date toDateTime(String date, Date defaultValue) {
return toDate(date, DATE_FORMAT_DATETIME, defaultValue);
}
public static Date toISODateTime(String date, Date defaultValue) {
return toDate(date, DATE_FORMAT_ISO_WITH_TIMEZONE, defaultValue);
}
public static String toString(Date date, String format) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
}
public static String toString(Date date, String format, TimeZone timeZone) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setTimeZone(timeZone);
return dateFormat.format(date);
}
public static XMLGregorianCalendar toXMLGregorianCalendar(Date date) {
DatatypeFactory factory;
try {
factory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
throw new IllegalStateException(e);
}
XMLGregorianCalendar result = factory.newXMLGregorianCalendar();
Calendar calendar = DateUtils.calendar(date);
result.setYear(calendar.get(Calendar.YEAR));
result.setMonth(calendar.get(Calendar.MONTH) + 1);
result.setDay(calendar.get(Calendar.DAY_OF_MONTH));
result.setTime(calendar.get(Calendar.HOUR), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
return result;
}
public static <T extends Enum<T>> T toEnum(String value, Class<T> enumClass, T defaultValue) {
if (!StringUtils.hasText(value)) {
return defaultValue;
}
try {
return Enum.valueOf(enumClass, value);
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
private Convert() {
}
}

@ -0,0 +1,117 @@
package com.docus.soap.api.util;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* Date should be considered as immutable object (e.g. String), all methods in
* this util return new instance
*/
public final class DateUtils {
public static Date date(int year, int month, int day) {
return date(year, month, day, 0, 0, 0);
}
public static Date date(int year, int month, int day, int hour, int minute, int second) {
Calendar calendar = Calendar.getInstance();
calendar.setLenient(false);
calendar.set(year, month, day, hour, minute, second);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
public static Calendar calendar(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
}
public static Date add(Date date, int field, int value) {
Calendar calendar = calendar(date);
calendar.add(field, value);
return calendar.getTime();
}
public static int get(Date date, int field) {
Calendar calendar = calendar(date);
return calendar.get(field);
}
public static Date withField(Date date, int field, int value) {
Calendar calendar = calendar(date);
calendar.set(field, value);
return calendar.getTime();
}
public static int getYear(Date date) {
return get(date, Calendar.YEAR);
}
public static int getMonth(Date date) {
return get(date, Calendar.MONTH);
}
public static int getDay(Date date) {
return get(date, Calendar.DATE);
}
public static int getHour(Date date) {
return get(date, Calendar.HOUR_OF_DAY);
}
public static int getMinute(Date date) {
return get(date, Calendar.MINUTE);
}
public static Date withHour(Date date, int value) {
return withField(date, Calendar.HOUR_OF_DAY, value);
}
public static Date withMinute(Date date, int value) {
return withField(date, Calendar.MINUTE, value);
}
public static Date toCurrentTimeZone(Date targetDate, TimeZone targetTimeZone) {
Calendar target = calendar(targetDate);
Calendar result = Calendar.getInstance(targetTimeZone);
result.set(Calendar.YEAR, target.get(Calendar.YEAR));
result.set(Calendar.MONTH, target.get(Calendar.MONTH));
result.set(Calendar.DATE, target.get(Calendar.DATE));
result.set(Calendar.HOUR_OF_DAY, target.get(Calendar.HOUR_OF_DAY));
result.set(Calendar.MINUTE, target.get(Calendar.MINUTE));
result.set(Calendar.SECOND, target.get(Calendar.SECOND));
result.set(Calendar.MILLISECOND, target.get(Calendar.MILLISECOND));
return result.getTime();
}
public static boolean isWeekDay(Date targetDate) {
Calendar calendar = calendar(targetDate);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
return dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY;
}
public static boolean isDateValid(int year, int month, int day) {
try {
date(year, month, day);
return true;
} catch (Exception e) {
return false;
}
}
public static Date truncateTime(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
private DateUtils() {
}
}

@ -0,0 +1,68 @@
package com.docus.soap.api.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import java.io.IOException;
public class JSON {
public static String toJSON(Object obj) {
return toJSON(ObjectMapperBuilder.defaultObjectMapper(), obj);
}
public static String toJSON(ObjectMapperBuilder builder, Object obj) {
try {
return builder.get().writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeIOException(e);
}
}
public static <T> T fromJSON(String json, Class<T> exceptClass) {
return fromJSON(ObjectMapperBuilder.defaultObjectMapper(), json, exceptClass);
}
public static <T> T fromJSON(ObjectMapperBuilder builder, String json, Class<T> exceptClass) {
try {
return builder.get().readValue(json, exceptClass);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
public static <T> T fromJSONWithGeneric(String json, TypeReference<T> genericType) {
return fromJSONWithGeneric(ObjectMapperBuilder.defaultObjectMapper(), json, genericType);
}
/**
* exampleList<T> jsonList = JSON.fromJSONWithGeneric(JSON.toJSON(list), new TypeReference<List<T>>(){})
*/
public static <T> T fromJSONWithGeneric(ObjectMapperBuilder builder, String json, TypeReference<T> genericType) {
try {
return builder.get().readValue(json, genericType);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
public static <T> T fromJSONWithGeneric(String json, JavaType javaType) {
return fromJSONWithGeneric(ObjectMapperBuilder.defaultObjectMapper(), json, javaType);
}
/**
* @param builder {@see ObjectMapperBuilder}
* @param json value
* @param javaType {@link com.fasterxml.jackson.databind.type.TypeFactory#constructParametricType} or {@link com.fasterxml.jackson.databind.ObjectMapper#constructType}
* @param <T> result Type
* @return result
*/
public static <T> T fromJSONWithGeneric(ObjectMapperBuilder builder, String json, JavaType javaType) {
try {
return builder.get().readValue(json, javaType);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
}

@ -0,0 +1,55 @@
package com.docus.soap.api.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
@Deprecated
public final class JSONBinder<T> {
static final ObjectMapper DEFAULT_OBJECT_MAPPER;
static {
DEFAULT_OBJECT_MAPPER = ObjectMapperBuilder.defaultObjectMapper().get();
}
public static <T> JSONBinder<T> binder(Class<T> beanClass) {
return new JSONBinder<>(beanClass);
}
public static ObjectMapper getObjectMapper() {
return DEFAULT_OBJECT_MAPPER;
}
ObjectMapper objectMapper;
private final Class<T> beanClass;
private JSONBinder(Class<T> beanClass) {
this.beanClass = beanClass;
this.objectMapper = DEFAULT_OBJECT_MAPPER;
}
public T fromJSON(String json) {
try {
return objectMapper.readValue(json, beanClass);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String toJSON(T object) {
try {
return objectMapper.writeValueAsString(object);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public JSONBinder<T> indentOutput() {
if (DEFAULT_OBJECT_MAPPER.equals(objectMapper)) {
objectMapper = ObjectMapperBuilder.defaultObjectMapper().rebirth().get();
}
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
return this;
}
}

@ -0,0 +1,82 @@
package com.docus.soap.api.util;
import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Date;
public class JSONDateFormat extends DateFormat {
private static final long serialVersionUID = 1L;
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
toAppendTo.append(Convert.toString(date, Convert.DATE_FORMAT_ISO_WITH_TIMEZONE));
return toAppendTo;
}
@Override
public Date parse(String source, ParsePosition pos) {
pos.setIndex(source.length());
if (isContainChar(source, '-')) {
if (Convert.DATA_FORMAT_DATETIME_SLASH.length() == source.length()) {
return Convert.toDate(source, Convert.DATA_FORMAT_DATETIME_SLASH);
} else {
return Convert.toDate(source, getISOPattern(source));
}
}
if ("MM/dd/yyyyTHH:mm:ss".length() == source.length()) {
//TODO: remove legacy format
return Convert.toDate(source, Convert.DATE_FORMAT_DATETIME);
}
return Convert.toDate(source, Convert.DATE_FORMAT_DATE);
}
public boolean isContainChar(String source, char character) {
if (!StringUtils.hasText(source)) {
return false;
}
for (char c : source.toCharArray()) {
if (character == c) {
return true;
}
}
return false;
}
public String getISOPattern(String source) {
StringBuilder b = new StringBuilder("yyyy-MM-dd'T'HH:mm:ss");
int precision = 0;
int state = 0;
for (int i = "yyyy-MM-ddTHH:mm:ss".length(); i < source.length(); i++) {
char c = source.charAt(i);
if (c == '.' && state == 0) {
state = 1;
} else if (c == '-' || c == '+' || c == 'Z') {
if (state > 0) {
b.append('.');
//support million seconds
for (int j = 0; j < precision; j++) {
b.append('S');
}
}
b.append("XXX");
break;
} else if (state == 1) {
precision++;
}
}
return b.toString();
}
@Override
public Object clone() {
return this;
}
}

@ -1,6 +1,5 @@
package com.docus.soap.api.util;
import com.docus.core.util.json.ObjectMapperBuilder;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.type.TypeFactory;

@ -0,0 +1,63 @@
package com.docus.soap.api.util;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
public class ObjectMapperBuilder {
static final ObjectMapper DEFAULT_OBJECT_MAPPER;
static {
DEFAULT_OBJECT_MAPPER = createMapper();
}
public static ObjectMapper getObjectMapper() {
return DEFAULT_OBJECT_MAPPER;
}
private static ObjectMapper createMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(new JSONDateFormat());
AnnotationIntrospector primary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
return mapper;
}
private boolean changed = false;
private ObjectMapper objectMapper;
public ObjectMapperBuilder() {
this.objectMapper = DEFAULT_OBJECT_MAPPER;
}
public ObjectMapper get() {
return objectMapper;
}
public static ObjectMapperBuilder defaultObjectMapper() {
return new ObjectMapperBuilder();
}
public ObjectMapperBuilder rebirth() {
if (!changed && DEFAULT_OBJECT_MAPPER.equals(objectMapper)) {
objectMapper = createMapper();
}
return this;
}
public ObjectMapperBuilder indent() {
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
changed = true;
return this;
}
}

@ -0,0 +1,8 @@
package com.docus.soap.api.util;
public final class RuntimeIOException extends RuntimeException {
public RuntimeIOException(Throwable cause) {
super(cause);
}
}

@ -1,8 +1,5 @@
package com.docus.soap.api.util;
import com.docus.core.util.Convert;
import com.docus.core.util.StringUtils;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.Date;

@ -0,0 +1,69 @@
package com.docus.soap.api.util;
import java.util.regex.Pattern;
public final class StringUtils {
private static final Pattern PATTERN_GUID = Pattern.compile("^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$");
private static final Pattern PATTERN_SAFE_STRING = Pattern.compile("^[.\\-,#&\\p{Alnum}\\p{Space}]*$");
public static boolean isGUID(String input) {
if (!StringUtils.hasText(input)) {
return false;
}
return PATTERN_GUID.matcher(input).matches();
}
public static int compare(String text1, String text2) {
if (text1 == null && text2 == null)
return 0;
if (text1 != null && text2 == null) {
return 1;
}
if (text1 == null) {
return -1;
}
return text1.compareTo(text2);
}
public static boolean hasText(String text) {
if (text == null)
return false;
for (int i = 0; i < text.length(); i++) {
if (!Character.isWhitespace(text.charAt(i)))
return true;
}
return false;
}
public static boolean equals(String text1, String text2) {
if (text1 == null)
return text2 == null;
return text1.equals(text2);
}
public static String truncate(String text, int maxLength) {
if (text == null)
return null;
if (text.length() <= maxLength)
return text;
return text.substring(0, maxLength);
}
public static String trim(String text) {
if (text == null)
return null;
return text.trim();
}
public static boolean isSafeString(String value) {
if (!StringUtils.hasText(value)) {
return true;
}
return PATTERN_SAFE_STRING.matcher(value).matches();
}
private StringUtils() {
}
}

@ -0,0 +1,2 @@
soap.complaint.api.url=http://101.132.67.155:8087/PKIQRCode/services/v1?wsdl
soap.complaint.api.action=SOF_GetQRCodeBySys

@ -1,3 +0,0 @@
soap:
complaint.api.url: http://101.132.67.155:8087/PKIQRCode/services/v1?wsdl
complaint.api.action: SOF_GetQRCodeBySys

@ -1,46 +1,85 @@
package com.docus.soap.api;
import com.docus.core.util.AssertUtils;
import com.docus.soap.api.request.complain.GetTableByIdDateRequest;
import com.docus.soap.api.response.complain.ComplaintListResult;
import com.docus.soap.api.service.ComplaintAPIService;
import com.docus.soap.api.request.zsyy.GetLoginInfoRequest;
import com.docus.soap.api.request.zsyy.GetQRCodeBySysRequest;
import com.docus.soap.api.request.zsyy.GetQueryQRCodeRequest;
import com.docus.soap.api.response.zsyy.GetLoginInfoResponse;
import com.docus.soap.api.response.zsyy.GetQRCodeBySysResponse;
import com.docus.soap.api.response.zsyy.GetQueryQRCodeResponse;
import com.docus.soap.api.service.XMZSYYQRCodeAPIService;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.core.env.Environment;
import javax.inject.Inject;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DocusSoapApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ComplaintAPIServiceTest {
public class ComplaintAPIServiceTest extends SpringTest {
private final Logger logger = LoggerFactory.getLogger(ComplaintAPIServiceTest.class);
@Value("${soap.complaint.api.url}")
public String soapComplaintUrl;
@Value("${soap.complaint.api.action}")
public String soapComplaintAction;
@Inject
private Environment env;
@Inject
private ComplaintAPIService complaintAPIService;
private XMZSYYQRCodeAPIService complaintAPIService;
@Test
@Ignore
public void getTableByIdDateTest() {
GetTableByIdDateRequest request = new GetTableByIdDateRequest();
GetQRCodeBySysRequest request = new GetQRCodeBySysRequest();
request.setSys("JSScan");
ComplaintListResult result = complaintAPIService.getTableByIdDate(request, getTableByIdDateSettings());
AssertUtils.assertNotNull(result, "not null");
GetQRCodeBySysResponse result = complaintAPIService.getQRCodeBySys(request, getTableByIdDateSettings());
Assert.assertNotNull("not null", result);
}
@Test
@Ignore
public void getQueryQRCode() {
GetQueryQRCodeRequest request = new GetQueryQRCodeRequest();
request.setQrCode("二维码状态查询字符串");
GetQueryQRCodeResponse queryQRCode = complaintAPIService.getQueryQRCode(request, queryQRCodeUrlAndName());
Assert.assertNotNull("not null", queryQRCode);
}
@Test
public void getLoginInfo() {
GetLoginInfoRequest request = new GetLoginInfoRequest();
request.setSys("JSScan");
request.setAccountType("IdCardNumber");
request.setAccount("350301200008100057");
request.setPassword("lin123456");
GetLoginInfoResponse loginInfo = complaintAPIService.getLoginInfo(request, getLoginUserInfo());
Assert.assertNotNull("not null", loginInfo);
}
private SoapAPISettings getTableByIdDateSettings() {
SoapAPISettings soapAPISettings = new SoapAPISettings();
soapAPISettings.setAction(soapComplaintAction);
soapAPISettings.setUri(soapComplaintUrl);
soapAPISettings.setAction(env.getProperty("soap.complaint.api.action"));
soapAPISettings.setUri(env.getProperty("soap.complaint.api.url"));
return soapAPISettings;
}
private SoapAPISettings queryQRCodeUrlAndName() {
SoapAPISettings soapAPISettings = new SoapAPISettings();
soapAPISettings.setAction("SOF_QueryQRCode");
soapAPISettings.setUri("http://101.132.67.155:8087/PKIQRCode/services/v1?wsdl");
return soapAPISettings;
}
private SoapAPISettings getLoginUserInfo() {
SoapAPISettings soapAPISettings = new SoapAPISettings();
soapAPISettings.setAction("SOF_LoginWithAccountInfo");
soapAPISettings.setUri("http://101.132.67.155:8087/pkis/services/v1?wsdl");
return soapAPISettings;
}
}

@ -0,0 +1,15 @@
package com.docus.soap.api;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestEnvironmentConfig.class}, initializers = SoapAppContextInitializer.class)
@ActiveProfiles("test")
@WebAppConfiguration
public abstract class SpringTest {
}

@ -0,0 +1,12 @@
package com.docus.soap.api;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
@Profile("test")
@Configuration
@Import(SoapAPIConfig.class)
public class TestEnvironmentConfig {
}

@ -0,0 +1,2 @@
soap.complaint.api.url=http://101.132.67.155:8087/PKIQRCode/services/v1?wsdl
soap.complaint.api.action=SOF_GetQRCodeBySys

@ -1,3 +0,0 @@
soap:
complaint.api.url: http://101.132.67.155:8087/PKIQRCode/services/v1?wsdl
complaint.api.action: SOF_GetQRCodeBySys
Loading…
Cancel
Save