commit
64318e5ce1
@ -0,0 +1,9 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.advice;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Gtw2Ctrl {
|
||||||
|
}
|
@ -0,0 +1,164 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.advice;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.InvalidGatewayShortIdException;
|
||||||
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import au.com.royalpay.payment.core.exceptions.SignInvalidException;
|
||||||
|
import au.com.royalpay.payment.manage.mappers.system.OrgSignInfoMapper;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.server.ServletServerHttpRequest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.context.request.*;
|
||||||
|
import org.springframework.web.servlet.View;
|
||||||
|
import org.springframework.web.util.UriComponents;
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.*;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import static au.com.royalpay.payment.tools.codec.RSACrypt.loadPrivateKey;
|
||||||
|
import static au.com.royalpay.payment.tools.codec.RSACrypt.loadPublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author taylor
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class Gtw2SignAspect {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
private static final String V2_SIGN_TYPE = "RSA2";
|
||||||
|
@Resource
|
||||||
|
private OrgSignInfoMapper orgSignRsaMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Pointcut("within(au.com.royalpay.payment.manage.gateway.web..*) && " +
|
||||||
|
"!execution(* au.com.royalpay.payment.manage.gateway.web.*.handlePartner*(..))")
|
||||||
|
private void anyMethod() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Around(value = "anyMethod()")
|
||||||
|
public JSONObject aroundHandleRequest(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
||||||
|
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
||||||
|
UriComponents components = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(sra.getRequest())).build();
|
||||||
|
String requestUrl = UriComponentsBuilder.fromHttpUrl(components.toUriString()).replaceQuery(null).toUriString();
|
||||||
|
MultiValueMap<String, String> requireParams = components.getQueryParams();
|
||||||
|
if (!requireParams.containsKey("nonce_str")) {
|
||||||
|
throw new ParamInvalidException("nonce_str", "error.payment.valid.param_missing");
|
||||||
|
}
|
||||||
|
if (!requireParams.containsKey("sign")) {
|
||||||
|
throw new ParamInvalidException("sign", "error.payment.valid.param_missing");
|
||||||
|
}
|
||||||
|
if (!requireParams.containsKey("sign_type")) {
|
||||||
|
throw new ParamInvalidException("sign_type", "error.payment.valid.param_missing");
|
||||||
|
}
|
||||||
|
if (!StringUtils.equals(V2_SIGN_TYPE, requireParams.getFirst("sign_type"))) {
|
||||||
|
throw new ParamInvalidException("sign_type", "error.payment.valid.invalid_param");
|
||||||
|
}
|
||||||
|
NativeWebRequest webRequest = new ServletWebRequest(sra.getRequest());
|
||||||
|
Map<String, String> pathVariables = (Map<String, String>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
|
||||||
|
if (!pathVariables.containsKey("shortId")) {
|
||||||
|
throw new InvalidShortIdException();
|
||||||
|
}
|
||||||
|
Object[] requestArgs = pjp.getArgs();
|
||||||
|
JSONObject requestBody = null;
|
||||||
|
for (Object arg : requestArgs) {
|
||||||
|
try {
|
||||||
|
if (arg instanceof JSONObject) {
|
||||||
|
requestBody = JSONObject.parseObject(arg.toString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ParamInvalidException("Request Body", "error.payment.valid.invalid_param");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!StringUtils.equals("GET", sra.getRequest().getMethod()) && requestBody == null
|
||||||
|
&& !requestUrl.contains("/attachment/files")) {
|
||||||
|
throw new ParamInvalidException("Request Body", "error.payment.valid.invalid_param");
|
||||||
|
}
|
||||||
|
AtomicBoolean isTrueSign = new AtomicBoolean(buildSign(pathVariables.get("shortId"),
|
||||||
|
requestBody == null ? new JSONObject() : requestBody,
|
||||||
|
requestUrl,
|
||||||
|
requireParams.getFirst("nonce_str"),
|
||||||
|
requireParams.getFirst("sign")));
|
||||||
|
if (!isTrueSign.get()) {
|
||||||
|
throw new SignInvalidException();
|
||||||
|
}
|
||||||
|
Object result = pjp.proceed();
|
||||||
|
JSONObject data = JSONObject.parseObject(result.toString());
|
||||||
|
return buildResponseData(pathVariables.get("shortId"), requestUrl, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSONObject buildResponseData(String clientMoniker, String requestUrl, JSONObject data) {
|
||||||
|
data.put("nonce_str", RandomStringUtils.random(15, true, true));
|
||||||
|
data.put("sign_type", V2_SIGN_TYPE);
|
||||||
|
data.put("url", requestUrl);
|
||||||
|
JSONObject signInfo = orgSignRsaMapper.findOrgSignInfo(clientMoniker);
|
||||||
|
String signStr = sign(JSONObject.toJSONBytes(data, SerializerFeature.MapSortField), signInfo.getString("platform_private_key"));
|
||||||
|
JSONObject respJson = new JSONObject();
|
||||||
|
respJson.put("data", data);
|
||||||
|
respJson.put("sign", signStr);
|
||||||
|
logger.info("ApiV2 Response : {}", JSONObject.toJSONString(respJson, SerializerFeature.MapSortField));
|
||||||
|
return respJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean buildSign(String clientMoniker, JSONObject requestData, String url, String nonceStr, String requestSign) {
|
||||||
|
requestData.put("url", url);
|
||||||
|
requestData.put("sign_type", V2_SIGN_TYPE);
|
||||||
|
requestData.put("nonce_str", nonceStr);
|
||||||
|
logger.info("ApiV2 Request : {}, RequestSign : {}", JSONObject.toJSONString(requestData, SerializerFeature.MapSortField), requestSign);
|
||||||
|
JSONObject signInfo = orgSignRsaMapper.findOrgSignInfo(clientMoniker);
|
||||||
|
if (signInfo == null) {
|
||||||
|
throw new InvalidGatewayShortIdException();
|
||||||
|
}
|
||||||
|
if (!signInfo.containsKey("mch_public_key")) {
|
||||||
|
throw new ServerErrorException("error.payment.valid.invalid.mch_public_key");
|
||||||
|
}
|
||||||
|
// return checkSign(JSONObject.toJSONBytes(requestData, SerializerFeature.MapSortField), requestSign, signInfo.getString("mch_public_key"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sign(byte[] source, String privateKey) {
|
||||||
|
try {
|
||||||
|
PrivateKey priKey = loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
||||||
|
signature.initSign(priKey);
|
||||||
|
signature.update(source);
|
||||||
|
byte[] signed = signature.sign();
|
||||||
|
return Base64.encodeBase64URLSafeString(signed);
|
||||||
|
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
|
||||||
|
//shall never happen
|
||||||
|
throw new ServerErrorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkSign(byte[] source, String sign, String publicKey) {
|
||||||
|
try {
|
||||||
|
PublicKey pubKey = loadPublicKey(new ByteArrayInputStream(publicKey.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
||||||
|
signature.initVerify(pubKey);
|
||||||
|
signature.update(source);
|
||||||
|
return signature.verify(Base64.decodeBase64(sign));
|
||||||
|
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
|
||||||
|
//shall never happen
|
||||||
|
throw new ServerErrorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClientCompanyConfig {
|
||||||
|
|
||||||
|
@JSONField(name = "company_name")
|
||||||
|
private String companyName;
|
||||||
|
@JSONField(name = "short_name")
|
||||||
|
private String shortName;
|
||||||
|
@JSONField(name = "store_name")
|
||||||
|
private String storeName;
|
||||||
|
@JSONField(name = "business_name")
|
||||||
|
private String businessName;
|
||||||
|
@JSONField(name = "business_structure")
|
||||||
|
private String businessStructure;
|
||||||
|
private String abn;
|
||||||
|
private String acn;
|
||||||
|
@JSONField(name = "company_phone")
|
||||||
|
private String companyPhone;
|
||||||
|
@JSONField(name = "logo_url")
|
||||||
|
private String logoId;
|
||||||
|
|
||||||
|
private static String[] WHITE_LIST = {"businessName","abn", "acn"};
|
||||||
|
|
||||||
|
|
||||||
|
public void checkParamsInvalid() throws IllegalAccessException {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null && !Arrays.asList(WHITE_LIST).contains(field.getName())) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.equalsIgnoreCase(businessStructure, "Company")) {
|
||||||
|
if (StringUtils.isBlank(acn) || acn.length() != 9) {
|
||||||
|
throw new ParamInvalidException("acn", "Required Param acn not found");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (StringUtils.isBlank(abn)) {
|
||||||
|
throw new ParamInvalidException("abn", "Required Param abn not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public JSONObject basicInfo() {
|
||||||
|
return (JSONObject) JSON.toJSON(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClientComplianceFileConfig {
|
||||||
|
@JSONField(name = "id_type")
|
||||||
|
private String idType;
|
||||||
|
@JSONField(name = "id_title")
|
||||||
|
private String idTitle;
|
||||||
|
@JSONField(name = "id_title_description")
|
||||||
|
private String idTitleDesc;
|
||||||
|
@JSONField(name = "bank_statement")
|
||||||
|
private String bankStatement;
|
||||||
|
@JSONField(name = "certificate_of_registration")
|
||||||
|
private String certOfRegistration;
|
||||||
|
@JSONField(name = "id_file")
|
||||||
|
private String id;
|
||||||
|
@JSONField(name = "utility_bill")
|
||||||
|
private String utilityBill;
|
||||||
|
|
||||||
|
private static String[] WHITE_LIST = {"utility_bill","id_title_description"};
|
||||||
|
|
||||||
|
public void checkParamsInvalid() throws IllegalAccessException {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null && !Arrays.asList(WHITE_LIST).contains(field.getName())) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!StringUtils.equalsIgnoreCase(idTitle, "Ultimate beneficiary owner")) {
|
||||||
|
if (StringUtils.isBlank(idTitleDesc)) {
|
||||||
|
throw new ParamInvalidException("id_title_description", "error.payment.valid.param_missing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClientContactConfig {
|
||||||
|
@JSONField(name = "contact_person")
|
||||||
|
private String contactPerson;
|
||||||
|
@JSONField(name = "contact_phone")
|
||||||
|
private String contactPhone;
|
||||||
|
@JSONField(name = "contact_email")
|
||||||
|
private String contactEmail;
|
||||||
|
@JSONField(name = "contact_job")
|
||||||
|
private String contactJob;
|
||||||
|
private String address;
|
||||||
|
private String suburb;
|
||||||
|
private String postcode;
|
||||||
|
private String state;
|
||||||
|
private String country;
|
||||||
|
@JSONField(name = "registered_address")
|
||||||
|
private String registeredAddress;
|
||||||
|
@JSONField(name = "registered_suburb")
|
||||||
|
private String registeredSuburb;
|
||||||
|
@JSONField(name = "registered_postcode")
|
||||||
|
private String registeredPostcode;
|
||||||
|
@JSONField(name = "registered_state")
|
||||||
|
private String registeredState;
|
||||||
|
private String timezone;
|
||||||
|
|
||||||
|
private static java.util.regex.Pattern TIMEZONE_PATTERN = java.util.regex.Pattern.compile("^((Australia/West)|(Australia/Eucla)|(Australia/North)|(Australia/South)|(Australia/Brisbane)|(Australia/Melbourne)|(Australia/LHI))$");
|
||||||
|
|
||||||
|
public void checkParamsInvalid() throws IllegalAccessException {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Matcher matcher = TIMEZONE_PATTERN.matcher(timezone);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
throw new BadRequestException("PARAM_ERROR:Timezone not acceptable!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject contractInfo() {
|
||||||
|
JSONObject contract = (JSONObject) JSON.toJSON(this);
|
||||||
|
if (StringUtils.equalsIgnoreCase(state, "OTHER")) {
|
||||||
|
contract.put("state", "其他(Other)");
|
||||||
|
}
|
||||||
|
return contract;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject legalAddressInfo() {
|
||||||
|
JSONObject address = new JSONObject();
|
||||||
|
address.put("address", registeredAddress);
|
||||||
|
address.put("suburb", registeredSuburb);
|
||||||
|
address.put("postcode", registeredPostcode);
|
||||||
|
if (StringUtils.equalsIgnoreCase(registeredState, "OTHER")) {
|
||||||
|
address.put("state", "其他(Other)");
|
||||||
|
}
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClientLegalConfig {
|
||||||
|
|
||||||
|
@JSONField(name = "legal_representative_person")
|
||||||
|
private String representativePerson ;
|
||||||
|
@JSONField(name = "legal_representative_phone")
|
||||||
|
private String representativePhone;
|
||||||
|
@JSONField(name = "legal_representative_email")
|
||||||
|
private String representativeEmail;
|
||||||
|
@JSONField(name = "legal_representative_job")
|
||||||
|
private String representativeJobTitle;
|
||||||
|
|
||||||
|
public void checkParamsInvalid() throws IllegalAccessException {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject clientLegalInfo() {
|
||||||
|
JSONObject legal = new JSONObject();
|
||||||
|
legal.put("representative_person", representativePerson);
|
||||||
|
legal.put("job_title", representativeJobTitle);
|
||||||
|
legal.put("phone", representativePhone);
|
||||||
|
legal.put("email", representativeEmail);
|
||||||
|
return legal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClientPayConfig {
|
||||||
|
@JSONField(name = "client_pay_type")
|
||||||
|
private String clientPayType;
|
||||||
|
@JSONField(name = "client_pay_desc")
|
||||||
|
private String clientPayDesc;
|
||||||
|
@JSONField(name = "royalpay_industry")
|
||||||
|
private String royalpayindustry;
|
||||||
|
@JSONField(name = "wechat_industry")
|
||||||
|
private String wechatindustry;
|
||||||
|
@JSONField(name = "alipay_industry")
|
||||||
|
private String alipayindustry;
|
||||||
|
@JSONField(name = "company_photo")
|
||||||
|
private String companyPhoto;
|
||||||
|
@JSONField(name = "store_photo")
|
||||||
|
private String storePhoto;
|
||||||
|
@JSONField(name = "company_website")
|
||||||
|
private String companyWebsite;
|
||||||
|
|
||||||
|
private static String[] WHITE_LIST = {"companyWebsite","store_photo", "company_photo"};
|
||||||
|
|
||||||
|
|
||||||
|
public void checkParamsInvalid() throws IllegalAccessException {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null && !Arrays.asList(WHITE_LIST).contains(field.getName())) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clientPayType.indexOf("1") != -1) {
|
||||||
|
if (StringUtils.isBlank(companyWebsite)) {
|
||||||
|
throw new ParamInvalidException("company_website", "Required Param company_website not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clientPayType.indexOf("2") != -1) {
|
||||||
|
if (StringUtils.isBlank(companyPhoto)) {
|
||||||
|
throw new ParamInvalidException("company_photo", "Required Param company_photo not found");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(storePhoto)) {
|
||||||
|
throw new ParamInvalidException("store_photo", "Required Param store_photo not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject payConfig() {
|
||||||
|
JSONObject config = (JSONObject) JSON.toJSON(this);
|
||||||
|
config.put("alipayindustry", alipayindustry);
|
||||||
|
config.put("industry", wechatindustry);
|
||||||
|
config.put("royalpayindustry", royalpayindustry);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by yixian on 2016-06-29.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ClientRegisterInfo {
|
||||||
|
private org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
@JSONField(name = "apply_id")
|
||||||
|
private String applyId;
|
||||||
|
@JSONField(name = "parent_partner_code")
|
||||||
|
private String parentPartnerCode;
|
||||||
|
@JSONField(name = "notify_url")
|
||||||
|
private String notifyUrl;
|
||||||
|
@JSONField(name = "company_info")
|
||||||
|
private ClientCompanyConfig companyConfig;
|
||||||
|
@JSONField(name = "contact_info")
|
||||||
|
private ClientContactConfig contactConfig;
|
||||||
|
@JSONField(name = "legal_info")
|
||||||
|
private ClientLegalConfig legalConfig;
|
||||||
|
@JSONField(name = "pay_info")
|
||||||
|
private ClientPayConfig payConfig;
|
||||||
|
@JSONField(name = "settle_info")
|
||||||
|
private ClientSettleConfig settleConfig;
|
||||||
|
@JSONField(name = "compliance_file_info")
|
||||||
|
private ClientComplianceFileConfig complianceFileConfig;
|
||||||
|
|
||||||
|
private static String[] WHITE_LIST = {"parentPartnerCode", "notifyUrl"};
|
||||||
|
|
||||||
|
public void checkParamsInvalid() {
|
||||||
|
try {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null && !Arrays.asList(WHITE_LIST).contains(field.getName())) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
companyConfig.checkParamsInvalid();
|
||||||
|
contactConfig.checkParamsInvalid();
|
||||||
|
legalConfig.checkParamsInvalid();
|
||||||
|
payConfig.checkParamsInvalid();
|
||||||
|
settleConfig.checkParamsInvalid();
|
||||||
|
complianceFileConfig.checkParamsInvalid();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
logger.error("gateway api register client error : {}", e.getMessage());
|
||||||
|
throw new BadRequestException("Params Format Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject insertClientInfo(String clientMoniker, String bdUserName, boolean hasParentBoolean, int parentClientId) {
|
||||||
|
JSONObject client = new JSONObject();
|
||||||
|
client.putAll(companyConfig.basicInfo());
|
||||||
|
client.put("logo_thumbnail", companyConfig.getLogoId());
|
||||||
|
client.putAll(contactConfig.contractInfo());
|
||||||
|
client.putAll(payConfig.payConfig());
|
||||||
|
client.put("create_time", new Date());
|
||||||
|
client.put("ali_sub_merchant_id", clientMoniker);
|
||||||
|
client.put("credential_code", RandomStringUtils.random(32, true, true));
|
||||||
|
client.put("creator", applyId);
|
||||||
|
client.put("bd_user", applyId);
|
||||||
|
client.put("bd_user_name", bdUserName);
|
||||||
|
client.put("client_moniker", clientMoniker);
|
||||||
|
if (hasParentBoolean && parentClientId != 0) {
|
||||||
|
client.put("parent_client_id", parentClientId);
|
||||||
|
}
|
||||||
|
client.put("source", 5);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject insertClientConfigInfo(int clientId, String clientMoniker) {
|
||||||
|
JSONObject clientConfig = new JSONObject();
|
||||||
|
clientConfig.putAll(payConfig.payConfig());
|
||||||
|
clientConfig.put("notify_url", notifyUrl);
|
||||||
|
clientConfig.put("client_id", clientId);
|
||||||
|
clientConfig.put("client_moniker", clientMoniker);
|
||||||
|
return clientConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject insertClientLegalInfo(int clientId) {
|
||||||
|
JSONObject clientLegalInfo = new JSONObject();
|
||||||
|
clientLegalInfo.putAll(legalConfig.clientLegalInfo());
|
||||||
|
clientLegalInfo.putAll(contactConfig.legalAddressInfo());
|
||||||
|
clientLegalInfo.put("client_id", clientId);
|
||||||
|
return clientLegalInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject insertBankInfo(int clientId) {
|
||||||
|
JSONObject bankInfo = settleConfig.insertBankInfo();
|
||||||
|
bankInfo.put("client_id", clientId);
|
||||||
|
return bankInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientAuthFilesInfo insertClientComplianceInfo() {
|
||||||
|
ClientAuthFilesInfo file = new ClientAuthFilesInfo();
|
||||||
|
file.setFile_bank_info(complianceFileConfig.getBankStatement());
|
||||||
|
file.setFile_id_info(complianceFileConfig.getId());
|
||||||
|
file.setFile_company_info(complianceFileConfig.getCertOfRegistration());
|
||||||
|
file.setUtility_bill_info(complianceFileConfig.getUtilityBill());
|
||||||
|
file.setId_type(complianceFileConfig.getIdType());
|
||||||
|
file.setBeneficiary_id_title(complianceFileConfig.getIdTitle());
|
||||||
|
file.setOther_id_title_desc(complianceFileConfig.getIdTitleDesc());
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject insertClientRateInfo(JSONObject defaultRateConfig) {
|
||||||
|
JSONObject rate = new JSONObject();
|
||||||
|
rate.put("clean_days", settleConfig.getCleanDays());
|
||||||
|
rate.put("active_time", settleConfig.getActiveTime());
|
||||||
|
rate.put("expiry_time", settleConfig.getExpireTime());
|
||||||
|
rate.put("wechat_rate_value", settleConfig.getWechatRate());
|
||||||
|
rate.put("alipay_rate_value", settleConfig.getAlipayRate());
|
||||||
|
rate.put("alipayonline_rate_value", settleConfig.getAlipayOnlineRate());
|
||||||
|
rate.put("bestpay_rate_value", getDefaultRate(defaultRateConfig, String.valueOf(settleConfig.getCleanDays()),"Bestpay"));
|
||||||
|
rate.put("jd_rate_value", getDefaultRate(defaultRateConfig, String.valueOf(settleConfig.getCleanDays()),"JDpay"));
|
||||||
|
rate.put("Rpay_rate_value", getDefaultRate(defaultRateConfig, String.valueOf(settleConfig.getCleanDays()),"Rpay"));
|
||||||
|
rate.put("cb_bankpay_rate_value", getDefaultRate(defaultRateConfig, String.valueOf(settleConfig.getCleanDays()),"CB_Bankpay"));
|
||||||
|
return rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDefaultRate(JSONObject defaultRateConfig, String cleanDays, String rateKey) {
|
||||||
|
JSONObject config = defaultRateConfig.getJSONObject("t" + cleanDays);
|
||||||
|
return config.getString(rateKey);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.beans;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ClientSettleConfig {
|
||||||
|
@JSONField(name = "swift_code")
|
||||||
|
private String swiftCode;
|
||||||
|
@JSONField(name = "bsb_no")
|
||||||
|
private String bsbNo;
|
||||||
|
private String bank;
|
||||||
|
private String city;
|
||||||
|
private String address;
|
||||||
|
private String system;
|
||||||
|
private String postcode;
|
||||||
|
private String state;
|
||||||
|
private String branch;
|
||||||
|
@JSONField(name = "account_no")
|
||||||
|
private String accountNo;
|
||||||
|
@JSONField(name = "account_name")
|
||||||
|
private String accountName;
|
||||||
|
@JSONField(name = "clean_days")
|
||||||
|
private int cleanDays;
|
||||||
|
@JSONField(name = "wechat_rate")
|
||||||
|
private String wechatRate;
|
||||||
|
@JSONField(name = "alipay_rate")
|
||||||
|
private String alipayRate;
|
||||||
|
@JSONField(name = "alipay_online_rate")
|
||||||
|
private String alipayOnlineRate;
|
||||||
|
@JSONField(name = "transaction_fee")
|
||||||
|
private String transactionFee;
|
||||||
|
@JSONField(name = "active_time")
|
||||||
|
private String activeTime;
|
||||||
|
@JSONField(name = "expire_time")
|
||||||
|
private String expireTime;
|
||||||
|
|
||||||
|
|
||||||
|
private static Pattern ACCOUNT_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9 &]+$");
|
||||||
|
|
||||||
|
public void checkParamsInvalid() throws IllegalAccessException {
|
||||||
|
for (Field field : getClass().getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.get(this) == null) {
|
||||||
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject insertBankInfo() {
|
||||||
|
JSONObject bankInfo = new JSONObject();
|
||||||
|
if (swiftCode.length() > 12) {
|
||||||
|
throw new BadRequestException("PARAM_ERROR:Switft code must be less than 12 characters");
|
||||||
|
}
|
||||||
|
if (bsbNo.length() > 6) {
|
||||||
|
throw new BadRequestException("PARAM_ERROR:BSB No must be less than 6 characters");
|
||||||
|
}
|
||||||
|
if (accountNo.length() > 20) {
|
||||||
|
throw new BadRequestException("PARAM_ERROR:Account No must be less than 20 characters");
|
||||||
|
}
|
||||||
|
if (accountName.length() > 50) {
|
||||||
|
throw new BadRequestException("PARAM_ERROR:Account Name must be less than 50 characters");
|
||||||
|
}
|
||||||
|
Matcher matcher = ACCOUNT_NAME_PATTERN.matcher(accountName);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
throw new BadRequestException("PARAM_ERROR:Invalid Account Name format");
|
||||||
|
}
|
||||||
|
bankInfo.put("swift_code", swiftCode);
|
||||||
|
bankInfo.put("bsb_no", bsbNo);
|
||||||
|
bankInfo.put("account_no", accountNo);
|
||||||
|
bankInfo.put("account_name", accountName);
|
||||||
|
bankInfo.put("bank", bank);
|
||||||
|
bankInfo.put("city", city);
|
||||||
|
bankInfo.put("address", address);
|
||||||
|
bankInfo.put("system", system);
|
||||||
|
bankInfo.put("postcode", postcode);
|
||||||
|
bankInfo.put("state", state);
|
||||||
|
bankInfo.put("branch", branch);
|
||||||
|
return bankInfo;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.core;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
public interface GatewayMerchantApply {
|
||||||
|
|
||||||
|
JSONObject validOrgV200(String shortId);
|
||||||
|
|
||||||
|
JSONObject applicationMerchant(JSONObject org, JSONObject registerInfo);
|
||||||
|
|
||||||
|
JSONObject getMerchantStatus(JSONObject org, String clientMoniker);
|
||||||
|
|
||||||
|
void notifyOrgMerchantStatus(JSONObject client);
|
||||||
|
}
|
@ -0,0 +1,255 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.core.impls;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
||||||
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||||
|
import au.com.royalpay.payment.manage.gateway.beans.ClientRegisterInfo;
|
||||||
|
import au.com.royalpay.payment.manage.gateway.core.GatewayMerchantApply;
|
||||||
|
import au.com.royalpay.payment.manage.management.sysconfig.core.impls.PermissionPartnerManagerImpl;
|
||||||
|
import au.com.royalpay.payment.manage.mappers.log.GatewayClientApplyNotifyLogMapper;
|
||||||
|
import au.com.royalpay.payment.manage.mappers.system.*;
|
||||||
|
import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo;
|
||||||
|
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
||||||
|
import au.com.royalpay.payment.manage.system.core.impl.ClientContractServiceImpl;
|
||||||
|
import au.com.royalpay.payment.tools.env.SysConfigManager;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
||||||
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
||||||
|
import au.com.royalpay.payment.tools.threadpool.RoyalThreadPoolExecutor;
|
||||||
|
import cn.yixblog.platform.http.HttpRequestGenerator;
|
||||||
|
import cn.yixblog.platform.http.HttpRequestResult;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static au.com.royalpay.payment.tools.codec.RSACrypt.loadPrivateKey;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GatewayMerchantApplyImpl implements GatewayMerchantApply {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrgMapper orgMapper;
|
||||||
|
@Resource
|
||||||
|
private OrgSignInfoMapper orgSignRsaMapper;
|
||||||
|
@Resource
|
||||||
|
private ClientMapper clientMapper;
|
||||||
|
@Resource
|
||||||
|
private ManagerMapper managerMapper;
|
||||||
|
@Resource
|
||||||
|
private ClientConfigMapper clientConfigMapper;
|
||||||
|
@Resource
|
||||||
|
private SysClientLegalPersonMapper sysClientLegalPersonMapper;
|
||||||
|
@Resource
|
||||||
|
private PermissionPartnerManagerImpl permissionPartnerManagerImpl;
|
||||||
|
@Resource
|
||||||
|
private ClientBDMapper clientBDMapper;
|
||||||
|
@Resource
|
||||||
|
private ClientBankAccountMapper clientBankAccountMapper;
|
||||||
|
@Resource
|
||||||
|
private ClientManager clientManager;
|
||||||
|
@Resource
|
||||||
|
private SysConfigManager sysConfigManager;
|
||||||
|
@Resource
|
||||||
|
private RoyalThreadPoolExecutor royalThreadPoolExecutor;
|
||||||
|
@Resource
|
||||||
|
private GatewayClientApplyNotifyLogMapper gatewayClientApplyNotifyLogMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject validOrgV200(String shortId) {
|
||||||
|
JSONObject orgSignJson = orgSignRsaMapper.findOrgSignInfo(shortId);
|
||||||
|
JSONObject org = orgMapper.findOne(orgSignJson.getInteger("org_id"));
|
||||||
|
if (org == null) {
|
||||||
|
throw new InvalidShortIdException();
|
||||||
|
}
|
||||||
|
return org;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public JSONObject applicationMerchant(JSONObject org, JSONObject registerInfo) {
|
||||||
|
ClientRegisterInfo registerBean = JSONObject.toJavaObject(registerInfo, ClientRegisterInfo.class);
|
||||||
|
registerBean.checkParamsInvalid();
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
JSONObject manager = managerMapper.findAvailableByLoginId(registerBean.getApplyId());
|
||||||
|
if (manager == null) {
|
||||||
|
throw new ParamInvalidException("applyId","applyId is invalid");
|
||||||
|
}
|
||||||
|
boolean hasParentBoolean = StringUtils.isNotBlank(registerBean.getParentPartnerCode());
|
||||||
|
int parentClientId = 0;
|
||||||
|
if (hasParentBoolean) {
|
||||||
|
JSONObject parentClient = clientMapper.findClientByMoniker(registerBean.getParentPartnerCode());
|
||||||
|
if (parentClient == null) {
|
||||||
|
throw new ParamInvalidException("parentPartnerCode","parentPartnerCode is invalid");
|
||||||
|
}
|
||||||
|
parentClientId = parentClient.getIntValue("client_id");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONObject client = registerBean.insertClientInfo(clientManager.initMerchantCode(), manager.getString("display_name"), hasParentBoolean, parentClientId);
|
||||||
|
client.put("org_id", org.getString("org_id"));
|
||||||
|
clientMapper.save(client);
|
||||||
|
clientConfigMapper.save(registerBean.insertClientConfigInfo(client.getIntValue("client_id"),client.getString("client_moniker")));
|
||||||
|
sysClientLegalPersonMapper.save(registerBean.insertClientLegalInfo(client.getIntValue("client_id")));
|
||||||
|
permissionPartnerManagerImpl.permissionClientModuleSave(client.getIntValue("client_id"), client.getString("client_moniker"));
|
||||||
|
JSONObject clientBd = new JSONObject();
|
||||||
|
clientBd.put("client_id", client.getIntValue("client_id"));
|
||||||
|
clientBd.put("bd_id", manager.getString("manager_id"));
|
||||||
|
clientBd.put("bd_name", manager.getString("display_name"));
|
||||||
|
clientBd.put("create_time", new Date());
|
||||||
|
clientBd.put("create_id", manager.getString("manager_id"));
|
||||||
|
clientBd.put("start_date", new Date());
|
||||||
|
clientBd.put("proportion", 1);
|
||||||
|
clientBDMapper.saveBD(clientBd);
|
||||||
|
clientBankAccountMapper.save(registerBean.insertBankInfo(client.getIntValue("client_id")));
|
||||||
|
//todo 合规文件待增加source_agree_file
|
||||||
|
ClientAuthFilesInfo clientAuthFilesInfo = registerBean.insertClientComplianceInfo();
|
||||||
|
clientManager.uploadAuthFiles(manager, client.getString("client_moniker"), clientAuthFilesInfo);
|
||||||
|
JSONObject rateConfig = registerBean.insertClientRateInfo(JSONObject.parseObject(sysConfigManager.getSysConfig().getString("sys_rates")));
|
||||||
|
clientManager.newConfigRate(manager, client.getString("client_moniker"), rateConfig);
|
||||||
|
clientManager.commitToCompliance(client.getString("client_moniker"), manager);
|
||||||
|
result.put("parnter_code", client.getString("client_moniker"));
|
||||||
|
result.put("credential_code", client.getString("credential_code"));
|
||||||
|
result.put("company_name", client.getString("company_name"));
|
||||||
|
result.put("short_name", client.getString("short_name"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("gateway api register fail :{}", e.getMessage());
|
||||||
|
throw new BadRequestException("PARAM_ERROR:Params length too long");
|
||||||
|
}
|
||||||
|
result.put("partner_status", "PROCESSING");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject getMerchantStatus(JSONObject org, String clientMoniker) {
|
||||||
|
JSONObject client = clientMapper.findClientByMoniker(clientMoniker);
|
||||||
|
if (client == null) {
|
||||||
|
throw new InvalidShortIdException();
|
||||||
|
}
|
||||||
|
if (client.getIntValue("org_id") != org.getIntValue("org_id")) {
|
||||||
|
logger.error("This client was not belong to your organization,queryClient:{},orgID:{}", clientMoniker, org.getIntValue("org_id"));
|
||||||
|
throw new InvalidShortIdException();
|
||||||
|
}
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
result.put("partner_code", clientMoniker);
|
||||||
|
result.put("credential_code", client.getString("credential_code"));
|
||||||
|
result.put("company_name", client.getString("company_name"));
|
||||||
|
result.put("short_name", client.getString("short_name"));
|
||||||
|
result.put("apply_time", DateFormatUtils.format(client.getDate("create_time"), "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
result.put("apply_id", client.getString("creator"));
|
||||||
|
int approveResult = client.getIntValue("approve_result");
|
||||||
|
String clientStatus = "";
|
||||||
|
switch (approveResult) {
|
||||||
|
case 1:
|
||||||
|
clientStatus = "PASS";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
clientStatus = "PROCESSING";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
clientStatus = "REFUSED";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
clientStatus = "PROCESSING";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result.put("partner_status", clientStatus);
|
||||||
|
if ( approveResult == 1 || approveResult == 5) {
|
||||||
|
result.put("approve_time", DateFormatUtils.format(client.getDate("approve_time"), "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
if (approveResult == 5) {
|
||||||
|
result.put("refuse_description", client.getString("refuse_remark"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyOrgMerchantStatus(JSONObject client) {
|
||||||
|
String clientMoniker = client.getString("client_moniker");
|
||||||
|
if (client.getIntValue("source") != 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JSONObject clientConfig = clientConfigMapper.find(client.getIntValue("client_id"));
|
||||||
|
if (StringUtils.isBlank(clientConfig.getString("notify_url"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String notifyUrl = clientConfig.getString("notify_url");
|
||||||
|
|
||||||
|
JSONObject org = orgMapper.findOne(client.getInteger("org_id"));
|
||||||
|
JSONObject merchantStatus = getMerchantStatus(org, clientMoniker);
|
||||||
|
merchantStatus.put("nonce_str", RandomStringUtils.random(15, true, true));
|
||||||
|
merchantStatus.put("sign_type", "RSA2");
|
||||||
|
merchantStatus.put("url", notifyUrl);
|
||||||
|
JSONObject signInfo = orgSignRsaMapper.findByOrgId(org.getInteger("org_id"));
|
||||||
|
String signStr = sign(JSONObject.toJSONBytes(merchantStatus, SerializerFeature.MapSortField), signInfo.getString("platform_private_key"));
|
||||||
|
JSONObject respJson = new JSONObject();
|
||||||
|
respJson.put("data", merchantStatus);
|
||||||
|
respJson.put("sign", signStr);
|
||||||
|
logger.info("ApiV2 Response : {}", JSONObject.toJSONString(respJson, SerializerFeature.MapSortField));
|
||||||
|
JSONObject log = preInsertServerNotifyLog(client, notifyUrl);
|
||||||
|
royalThreadPoolExecutor.execute(() -> {
|
||||||
|
logger.debug("开始推送商户状态[{}]异步通知[{}]:", clientMoniker, notifyUrl);
|
||||||
|
HttpRequestGenerator gen = new HttpRequestGenerator(notifyUrl, RequestMethod.POST);
|
||||||
|
gen.setJSONEntity(respJson);
|
||||||
|
HttpRequestResult result = gen.execute();
|
||||||
|
if (result.isSuccess()) {
|
||||||
|
log.put("success", true);
|
||||||
|
log.put("http_code", result.getStatusCode());
|
||||||
|
log.put("updatetime", new Date());
|
||||||
|
gatewayClientApplyNotifyLogMapper.update(log);
|
||||||
|
logger.debug("商户状态[{}]异步通知[{}]推送完成:[{}]", clientMoniker, notifyUrl, result.getStatusCode());
|
||||||
|
}else {
|
||||||
|
Throwable exp = result.getException();
|
||||||
|
log.put("success", false);
|
||||||
|
log.put("http_code", result.getStatusCode());
|
||||||
|
log.put("err_msg", exp == null ? null : exp.getMessage());
|
||||||
|
log.put("updatetime", new Date());
|
||||||
|
gatewayClientApplyNotifyLogMapper.update(log);
|
||||||
|
logger.debug("商户状态[{}]异步通知[{}]推送失败:[{}]-[{}]", clientMoniker, notifyUrl, result.getStatusCode(), exp.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSONObject preInsertServerNotifyLog(JSONObject client,String notifyUrl) {
|
||||||
|
int clientId = client.getIntValue("client_id");
|
||||||
|
JSONObject log = gatewayClientApplyNotifyLogMapper.findHistoryByClientId(clientId);
|
||||||
|
if (log == null) {
|
||||||
|
log = new JSONObject();
|
||||||
|
log.put("org_id", client.getString("org_id"));
|
||||||
|
log.put("client_id", clientId);
|
||||||
|
log.put("notify_url", notifyUrl);
|
||||||
|
log.put("addtime", new Date());
|
||||||
|
log.put("success", 0);
|
||||||
|
log.put("http_code", 0);
|
||||||
|
gatewayClientApplyNotifyLogMapper.saveLog(log);
|
||||||
|
}
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String sign(byte[] source, String privateKey) {
|
||||||
|
try {
|
||||||
|
PrivateKey priKey = loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
||||||
|
signature.initSign(priKey);
|
||||||
|
signature.update(source);
|
||||||
|
byte[] signed = signature.sign();
|
||||||
|
return Base64.encodeBase64URLSafeString(signed);
|
||||||
|
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
|
||||||
|
//shall never happen
|
||||||
|
throw new ServerErrorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package au.com.royalpay.payment.manage.gateway.web;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
||||||
|
import au.com.royalpay.payment.core.utils.PaymentValidUtils;
|
||||||
|
import au.com.royalpay.payment.manage.gateway.advice.Gtw2Ctrl;
|
||||||
|
import au.com.royalpay.payment.manage.gateway.core.GatewayMerchantApply;
|
||||||
|
import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author taylor
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1.0/gateway/partners/{shortId}")
|
||||||
|
@Gtw2Ctrl
|
||||||
|
public class GtwPayController {
|
||||||
|
@Resource
|
||||||
|
private GatewayMerchantApply gatewayMerchantApply;
|
||||||
|
@Resource
|
||||||
|
private AttachmentClient attachmentClient;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/merchant/application")
|
||||||
|
public JSONObject applicationMerchant(@RequestBody JSONObject registerInfo, Errors errors,
|
||||||
|
@PathVariable String shortId) {
|
||||||
|
JSONObject org = gatewayMerchantApply.validOrgV200(shortId);
|
||||||
|
PaymentValidUtils.handleValidErrors(errors);
|
||||||
|
return gatewayMerchantApply.applicationMerchant(org, registerInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/merchant/{partner_code}/status")
|
||||||
|
public JSONObject getMerchantStatus(@PathVariable String shortId,
|
||||||
|
@PathVariable String partner_code) {
|
||||||
|
JSONObject org = gatewayMerchantApply.validOrgV200(shortId);
|
||||||
|
return gatewayMerchantApply.getMerchantStatus(org, partner_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/attachment/files")
|
||||||
|
public JSONObject uploadFile(@PathVariable String shortId,@RequestParam MultipartFile file) throws Exception {
|
||||||
|
JSONObject org = gatewayMerchantApply.validOrgV200(shortId);
|
||||||
|
if (org == null) {
|
||||||
|
throw new InvalidShortIdException();
|
||||||
|
}
|
||||||
|
JSONObject fileInfo = attachmentClient.uploadFile(file, false);
|
||||||
|
fileInfo.put("file_type", fileInfo.getString("filetype"));
|
||||||
|
fileInfo.remove("filepath");
|
||||||
|
fileInfo.remove("length");
|
||||||
|
fileInfo.remove("fileid");
|
||||||
|
fileInfo.remove("filetype");
|
||||||
|
fileInfo.put("file_url", fileInfo.getString("url"));
|
||||||
|
return fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package au.com.royalpay.payment.manage.mappers.log;
|
||||||
|
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by davep on 2016-07-22.
|
||||||
|
*/
|
||||||
|
@AutoMapper(tablename = "gateway_clientApply_notify_log", pkName = "id")
|
||||||
|
public interface GatewayClientApplyNotifyLogMapper {
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.INSERT)
|
||||||
|
void saveLog(JSONObject log);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.UPDATE)
|
||||||
|
void update(JSONObject notice);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.SELECT)
|
||||||
|
@AdvanceSelect(addonWhereClause = "success=0 and addtime(`addtime`,'24:00:00')>now()")
|
||||||
|
List<JSONObject> listErrorLogsIn24Hour();
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.SELECT)
|
||||||
|
JSONObject findHistoryByClientId(@Param("client_id") int clientId);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package au.com.royalpay.payment.manage.mappers.log;
|
||||||
|
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create by davep at 2020-02-04 11:40
|
||||||
|
*/
|
||||||
|
@AutoMapper(tablename = "log_presettle_task",pkName = "task_id")
|
||||||
|
public interface PreSettleTaskMapper {
|
||||||
|
|
||||||
|
void resetClearStatus(@Param("clearing_id") int clearingId);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package au.com.royalpay.payment.manage.mappers.system;
|
||||||
|
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||||
|
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
|
||||||
|
|
||||||
|
@AutoMapper(tablename = "org_sign_info", pkName = "org_id", keyGenerator = Jdbc3KeyGenerator.class)
|
||||||
|
public interface OrgSignInfoMapper {
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.SELECT)
|
||||||
|
JSONObject findByOrgId(@Param("org_id") int orgId);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.SELECT)
|
||||||
|
JSONObject findOrgSignInfo(@Param("gateway_short_id") String orgId);
|
||||||
|
|
||||||
|
int getPartnercode(@Param("codes") String codes);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.UPDATE)
|
||||||
|
void update(JSONObject signInfo);
|
||||||
|
|
||||||
|
@AutoSql(type = SqlType.INSERT)
|
||||||
|
void insert(JSONObject signInfo);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?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="au.com.royalpay.payment.manage.mappers.log.PreSettleTaskMapper">
|
||||||
|
<update id="resetClearStatus">
|
||||||
|
update log_presettle_task p
|
||||||
|
inner join log_clearing_detail cd on cd.clear_detail_id = p.clear_detail_id
|
||||||
|
set p.clear_detail_id=null,
|
||||||
|
p.finish_flag=0
|
||||||
|
where cd.clearing_id = #{clearing_id}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
@ -0,0 +1,9 @@
|
|||||||
|
<?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="au.com.royalpay.payment.manage.mappers.system.OrgSignInfoMapper">
|
||||||
|
<select id="getPartnercode" resultType="int">
|
||||||
|
SELECT count(1)
|
||||||
|
FROM org_sign_info
|
||||||
|
where gateway_short_id = #{codes};
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -1,628 +0,0 @@
|
|||||||
package au.com.royalpay.payment.manage.apps.core.impls;
|
|
||||||
|
|
||||||
import au.com.royalpay.payment.manage.analysis.core.WeekReporter;
|
|
||||||
import au.com.royalpay.payment.manage.citypartner.core.CityPartnerPrizeService;
|
|
||||||
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
|
|
||||||
import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper;
|
|
||||||
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
||||||
import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
|
|
||||||
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
|
||||||
import au.com.royalpay.payment.manage.notice.core.MailService;
|
|
||||||
import au.com.royalpay.payment.tools.mail.MailGunClient;
|
|
||||||
import au.com.royalpay.payment.tools.mail.SendMail;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.data.redis.core.BoundListOperations;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import cn.yixblog.platform.http.HttpRequestGenerator;
|
|
||||||
import cn.yixblog.platform.http.HttpRequestResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by wangning on 05/01/2018.
|
|
||||||
*/
|
|
||||||
// @SpringBootTest
|
|
||||||
// @ActiveProfiles({ "local", "alipay", "wechat", "jd", "bestpay" })
|
|
||||||
// @RunWith(SpringRunner.class)
|
|
||||||
public class CustomerImpressionImplTest {
|
|
||||||
@Resource
|
|
||||||
private OrderMapper orderMapper;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
|
||||||
@Resource
|
|
||||||
private ClientMapper clientMapper;
|
|
||||||
@Resource
|
|
||||||
private OrgMapper orgMapper;
|
|
||||||
@Resource
|
|
||||||
private MailGunClient mailGunClient;
|
|
||||||
@Resource
|
|
||||||
private ClientConfigMapper clientConfigMapper;
|
|
||||||
@Resource
|
|
||||||
private ClientManager clientManager;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MailService mailService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private WeekReporter weekReporter;
|
|
||||||
@Resource
|
|
||||||
private CityPartnerPrizeService cityPartnerPrizeService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void redisQueue() {
|
|
||||||
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
|
|
||||||
JSONObject order = orderMapper.find("00009201711300930013961422");
|
|
||||||
for (int i = 0; i < 10000; i++) {
|
|
||||||
ops.rightPush(order.toJSONString());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void excel1() {
|
|
||||||
try {
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx")));
|
|
||||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
||||||
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
||||||
Row row = null;
|
|
||||||
Cell cell = null;
|
|
||||||
Map<String, Map<String, String>> result = new HashMap<>();
|
|
||||||
while (rowIterator.hasNext()) {
|
|
||||||
row = rowIterator.next();
|
|
||||||
cell = row.getCell(0);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
|
|
||||||
String amount = cell.getStringCellValue().trim();
|
|
||||||
cell = row.getCell(1);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String dateStr = cell.getStringCellValue();
|
|
||||||
|
|
||||||
cell = row.getCell(2);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String clientId = cell.getStringCellValue();
|
|
||||||
|
|
||||||
if (result.containsKey(clientId)) {
|
|
||||||
result.get(clientId).put(dateStr, amount);
|
|
||||||
} else {
|
|
||||||
Map<String, String> ele = new HashMap<>();
|
|
||||||
ele.put(dateStr, amount);
|
|
||||||
result.put(clientId, ele);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<String> clients = new HashSet<>();
|
|
||||||
|
|
||||||
result.entrySet().parallelStream().forEach(p -> {
|
|
||||||
|
|
||||||
p.getValue().entrySet().parallelStream().forEach(o -> {
|
|
||||||
BigDecimal insAvg = BigDecimal.valueOf(Double.valueOf(o.getValue()));
|
|
||||||
BigDecimal pastTotal = BigDecimal.ZERO;
|
|
||||||
for (int i = 1; i < 4; i++) {
|
|
||||||
if (i == 1) {
|
|
||||||
pastTotal = BigDecimal.ZERO;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Date tmp = DateUtils.addMonths(DateUtils.parseDate(o.getKey(), "YYYYMM"), (-i + 1));
|
|
||||||
String pastKey = String.valueOf(tmp.getYear() + 1900) + String.valueOf(tmp.getMonth());
|
|
||||||
|
|
||||||
if (p.getValue().containsKey(String.valueOf(pastKey))) {
|
|
||||||
BigDecimal pastAvgtmp = BigDecimal.valueOf(Double.parseDouble(p.getValue().get(String.valueOf(pastKey))));
|
|
||||||
pastTotal = pastTotal.add(pastAvgtmp);
|
|
||||||
} else {
|
|
||||||
i = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 3) {
|
|
||||||
try {
|
|
||||||
BigDecimal pastAvg = pastTotal.divide(BigDecimal.valueOf(3L), 5, BigDecimal.ROUND_HALF_DOWN);
|
|
||||||
if (pastAvg.compareTo(BigDecimal.ZERO) > 0) {
|
|
||||||
if (insAvg.divide(pastAvg, 5, BigDecimal.ROUND_HALF_DOWN).intValue() > 3) {
|
|
||||||
clients.add(p.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ParseException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
clients.forEach(p -> {
|
|
||||||
System.out.println(p);
|
|
||||||
});
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
|
|
||||||
OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx");
|
|
||||||
workbook.write(out);
|
|
||||||
workbook.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void excel2() {
|
|
||||||
try {
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/qwe.xlsx")));
|
|
||||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
||||||
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
||||||
Row row = null;
|
|
||||||
Cell cell = null;
|
|
||||||
Map<String, LinkedHashMap<String, String>> result = new HashMap<>();
|
|
||||||
while (rowIterator.hasNext()) {
|
|
||||||
row = rowIterator.next();
|
|
||||||
cell = row.getCell(3);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String orders = cell.getStringCellValue().trim();
|
|
||||||
|
|
||||||
cell = row.getCell(1);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String dateStr = cell.getStringCellValue();
|
|
||||||
|
|
||||||
cell = row.getCell(2);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String clientId = cell.getStringCellValue();
|
|
||||||
|
|
||||||
if (result.containsKey(clientId)) {
|
|
||||||
result.get(clientId).put(dateStr, orders);
|
|
||||||
} else {
|
|
||||||
LinkedHashMap<String, String> ele = new LinkedHashMap<>();
|
|
||||||
ele.put(dateStr, orders);
|
|
||||||
result.put(clientId, ele);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<String> clients = new HashSet<>();
|
|
||||||
|
|
||||||
for (Map.Entry<String, LinkedHashMap<String, String>> p : result.entrySet()) {
|
|
||||||
int count = 1;
|
|
||||||
for (Map.Entry<String, String> o : p.getValue().entrySet()) {
|
|
||||||
count += 1;
|
|
||||||
for (int i = 1; i < 4; i++) {
|
|
||||||
if (p.getValue().size() < 4 && count == p.getValue().size()) {
|
|
||||||
try {
|
|
||||||
if (DateUtils.addMonths(DateUtils.parseDate(o.getKey(), "YYYYMM"), 3).compareTo(new Date()) < 0) {
|
|
||||||
clients.add(p.getKey());
|
|
||||||
}
|
|
||||||
} catch (ParseException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Date tmp = null;
|
|
||||||
try {
|
|
||||||
tmp = DateUtils.addMonths(DateUtils.parseDate(o.getKey(), "YYYYMM"), i);
|
|
||||||
String pastKey = String.valueOf(tmp.getYear() + 1900) + String.valueOf(tmp.getMonth());
|
|
||||||
if (p.getValue().containsKey(String.valueOf(pastKey))) {
|
|
||||||
i = 10;
|
|
||||||
} else {
|
|
||||||
if (i == 3 && (Integer.valueOf(o.getValue()) > 99)) {
|
|
||||||
clients.add(p.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
System.out.println(clients.size());
|
|
||||||
|
|
||||||
// OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx");
|
|
||||||
// workbook.write(out);
|
|
||||||
workbook.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void excel3() {
|
|
||||||
|
|
||||||
List<JSONObject> clients = clientMapper.listValidClient();
|
|
||||||
Map<String,JSONObject> clientMap = new HashMap<>();
|
|
||||||
clients.parallelStream().forEach(p->{
|
|
||||||
clientMap.put(p.getString("client_id"),p);
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/e4.xlsx")));
|
|
||||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
||||||
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
||||||
Row row = null;
|
|
||||||
Cell cell = null;
|
|
||||||
Map<String, LinkedHashMap<String, String>> result = new HashMap<>();
|
|
||||||
while (rowIterator.hasNext()) {
|
|
||||||
row = rowIterator.next();
|
|
||||||
cell = row.getCell(0);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String orderCounts = cell.getStringCellValue().trim();
|
|
||||||
|
|
||||||
cell = row.getCell(1);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String clientId = cell.getStringCellValue().trim();
|
|
||||||
|
|
||||||
cell = row.getCell(2);
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String dateStr = cell.getStringCellValue().trim();
|
|
||||||
|
|
||||||
if (result.containsKey(clientId)) {
|
|
||||||
result.get(clientId).put(dateStr, orderCounts);
|
|
||||||
} else {
|
|
||||||
LinkedHashMap<String, String> ele = new LinkedHashMap<>();
|
|
||||||
ele.put(dateStr, orderCounts);
|
|
||||||
result.put(clientId, ele);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<String> resultClients = new HashSet<>();
|
|
||||||
Date now = new Date();
|
|
||||||
for (Map.Entry<String, LinkedHashMap<String, String>> p : result.entrySet()) {
|
|
||||||
JSONObject tmpClient = clientMap.get(p.getKey());
|
|
||||||
if(tmpClient==null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(DateUtils.addMonths(tmpClient.getDate("create_time"), 7).compareTo(now)>-1){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, String> o : p.getValue().entrySet()) {
|
|
||||||
LinkedHashMap<String,String> resultEle = p.getValue();
|
|
||||||
int compareCount = 0;
|
|
||||||
for (int i = 1; i < 7; i++) {
|
|
||||||
compareCount+=1;
|
|
||||||
if(DateUtils.addMonths(DateUtils.parseDate(o.getKey(), "YYYY-MM"), 7).compareTo(now)>-1){
|
|
||||||
i=10;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Date compareDate = DateUtils.addMonths(DateUtils.parseDate(o.getKey(), "YYYY-MM"), i);
|
|
||||||
String compareKey = DateFormatUtils.format(compareDate,"YYYY-MM");
|
|
||||||
if(resultEle.containsKey(compareKey)){
|
|
||||||
i=10;
|
|
||||||
}
|
|
||||||
if(compareCount==6){
|
|
||||||
resultClients.add(p.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("0---"+resultClients.size());
|
|
||||||
|
|
||||||
resultClients.forEach(p->{
|
|
||||||
System.out.println(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// OutputStream out = new FileOutputStream("/Users/wangning/Desktop/春节活动报名结果通知(包含BD名称).xlsx");
|
|
||||||
// workbook.write(out);
|
|
||||||
workbook.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sendSimpleMessage() throws Exception {
|
|
||||||
String url = "https://api.mailgun.net/v3/dev.showcodes.com/messages?from=postmaster@mail.royalpay.com.au&to=164851225@qq.com,1029811920@qq.com&subject=啊是记录&text=暗杀苏&v:my-custom-data={\"key\":\"value\"}";
|
|
||||||
String asd = "王宁测试标题";
|
|
||||||
HttpRequestGenerator generator = new HttpRequestGenerator(url, RequestMethod.POST).addHeader("Authorization", getHeader());
|
|
||||||
|
|
||||||
HttpRequestResult res = null;
|
|
||||||
try {
|
|
||||||
res = generator.execute();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println(res.getException());
|
|
||||||
System.out.println();
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.out.println(res.getResponseContentJSONObj().toJSONString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sendSimeMessage() throws Exception {
|
|
||||||
String url = "https://api.mailgun.net/v3/dev.showcodes.com/events";
|
|
||||||
HttpRequestGenerator generator = new HttpRequestGenerator(url, RequestMethod.POST).addHeader("Authorization", getHeader());
|
|
||||||
|
|
||||||
generator.addQueryString("ascending", "yes");
|
|
||||||
generator.addQueryString("v:my-custom-data", "123456789");
|
|
||||||
generator.addQueryString("limit", "12");
|
|
||||||
System.out.println(String.valueOf(DateUtils.addDays(new Date(), 1)));
|
|
||||||
HttpRequestResult res = null;
|
|
||||||
try {
|
|
||||||
res = generator.execute();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println(res.getException());
|
|
||||||
System.out.println();
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.out.println(res.getResponseContentJSONObj().toJSONString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getHeader() {
|
|
||||||
String auth = "api:key-96fa3b5866ace125b8ec5a9d27e19353";
|
|
||||||
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
|
|
||||||
String authHeader = "Basic " + new String(encodedAuth);
|
|
||||||
return authHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sendSimpleMessages() throws Exception {
|
|
||||||
SendMail sendMail = new SendMail();
|
|
||||||
sendMail.setFrom("info@mail.royalpay.com.au");
|
|
||||||
sendMail.setContent("<html><p>Hi</p ></html>");
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
list.add("testTag");
|
|
||||||
// sendMail.setTags(list);
|
|
||||||
Set<String> mailCCs = new HashSet<>();
|
|
||||||
mailCCs.add("asd1159111@163.com");
|
|
||||||
sendMail.setMailCcs(mailCCs);
|
|
||||||
Set<String> mailtos = new HashSet<>();
|
|
||||||
mailtos.add("eason.qian@royalpay.com.au");
|
|
||||||
sendMail.setMailTos(mailtos);
|
|
||||||
sendMail.setTitle("Final Test");
|
|
||||||
|
|
||||||
JSONObject result = mailGunClient.sendMail(sendMail);
|
|
||||||
System.out.println(result.toJSONString());
|
|
||||||
System.out.println(result.toJSONString());
|
|
||||||
System.out.println(result.toJSONString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void asd() {
|
|
||||||
JSONObject client = clientMapper.findClient(9);
|
|
||||||
JSONObject var = new JSONObject();
|
|
||||||
var.put("client_moniker", client.getString("client_moniker"));
|
|
||||||
var.put("short_name", client.getString("short_name"));
|
|
||||||
JSONObject result = mailGunClient.addListMember(client.getString("contact_email"), "merchants@mail.royalpay.com.au", client.getString("contact_person"),
|
|
||||||
"", var);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void fd() {
|
|
||||||
List<String> asd12eq = new ArrayList<>();
|
|
||||||
asd12eq.add("9");
|
|
||||||
JSONObject asd = clientManager.getByEmail("164851225@qq.com", 1, 1, asd12eq);
|
|
||||||
JSONArray qwe = asd.getJSONArray("data");
|
|
||||||
System.out.println(asd.getJSONArray("data"));
|
|
||||||
System.out.println(qwe);
|
|
||||||
System.out.println(asd);
|
|
||||||
System.out.println(asd);
|
|
||||||
System.out.println(asd);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addMailUnsub() {
|
|
||||||
try {
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx")));
|
|
||||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
||||||
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
||||||
Row row = null;
|
|
||||||
Cell cell = null;
|
|
||||||
|
|
||||||
while (rowIterator.hasNext()) {
|
|
||||||
row = rowIterator.next();
|
|
||||||
cell = row.getCell(1);
|
|
||||||
if (cell == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
CellStyle cellStyle = cell.getCellStyle();
|
|
||||||
if (cellStyle.getFillForegroundColor() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String clientMonikers = cell.getStringCellValue().trim();
|
|
||||||
if (clientMonikers.contains("/")) {
|
|
||||||
String[] clientMonikerArr = clientMonikers.split("/");
|
|
||||||
for (String s : clientMonikerArr) {
|
|
||||||
String tmp = s.trim().toUpperCase();
|
|
||||||
if (tmp.length() > 4 || tmp.length() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
mailService.addUnsub(s.trim().toUpperCase());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String tmp = clientMonikers.trim().toUpperCase();
|
|
||||||
if (tmp.length() > 4 || tmp.length() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
mailService.addUnsub(clientMonikers.trim().toUpperCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void zxc() {
|
|
||||||
weekReporter.generateReport("2018-06-04", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void royalpayIndustryTransform() {
|
|
||||||
String json = "[\n" + " {\n" + " \"children\": [\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"机票\",\n"
|
|
||||||
+ " \"mccCode\": \"10001\"\n" + " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"旅游行业\",\n"
|
|
||||||
+ " \"mccCode\": \"10002\"\n" + " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"私人定制旅游\",\n"
|
|
||||||
+ " \"mccCode\": \"10003\"\n" + " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"租车\",\n"
|
|
||||||
+ " \"mccCode\": \"10004\"\n" + " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"巴士\",\n"
|
|
||||||
+ " \"mccCode\": \"10005\"\n" + " }\n" + " ],\n" + " \"label\": \"旅游出行\",\n" + " \"mccCode\": \"1\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"饭店\",\n" + " \"mccCode\": \"20001\"\n"
|
|
||||||
+ " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"奶茶店\",\n" + " \"mccCode\": \"20002\"\n"
|
|
||||||
+ " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"烧烤\",\n" + " \"mccCode\": \"20003\"\n"
|
|
||||||
+ " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"火锅\",\n" + " \"mccCode\": \"20004\"\n"
|
|
||||||
+ " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"Coffee\",\n" + " \"mccCode\": \"20005\"\n"
|
|
||||||
+ " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"酒吧\",\n" + " \"mccCode\": \"20006\"\n" + " }\n"
|
|
||||||
+ " ],\n" + " \"label\": \"餐饮\",\n" + " \"mccCode\": \"2\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"培训类\",\n" + " \"mccCode\": \"30001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"移民留学\",\n" + " \"mccCode\": \"30002\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"私人幼儿园\",\n" + " \"mccCode\": \"30003\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"教育\",\n" + " \"mccCode\": \"3\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"换汇\",\n" + " \"mccCode\": \"40001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"房产\",\n" + " \"mccCode\": \"40002\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"商务咨询\",\n" + " \"mccCode\": \"4\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"公众号服务商\",\n" + " \"mccCode\": \"50001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"各种媒体类宣传\",\n" + " \"mccCode\": \"50002\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"传媒\",\n" + " \"mccCode\": \"5\",\n"
|
|
||||||
+ " \"value\": \"{\\\"category\\\":\\\"SERVICE\\\",\\\"code\\\":\\\"7542\\\",\\\"description\\\":\\\"Car Washes\\\",\\\"parentCode\\\":\\\"S10\\\"}\"\n"
|
|
||||||
+ " },\n" + " {\n" + " \"children\": [\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"美容院\",\n"
|
|
||||||
+ " \"mccCode\": \"60001\"\n" + " },\n" + " {\n" + " \"children\": [],\n" + " \"label\": \"医疗美容\",\n"
|
|
||||||
+ " \"mccCode\": \"60002\"\n" + " }\n" + " ],\n" + " \"label\": \"医美\",\n" + " \"mccCode\": \"6\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [\n" + " {\n" + " \"label\": \"超市\",\n" + " \"mccCode\": \"70001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"服装店\",\n" + " \"mccCode\": \"70002\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"鞋店\",\n" + " \"mccCode\": \"70003\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"珠宝店\",\n" + " \"mccCode\": \"70004\"\n" + " },{\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"箱包\",\n" + " \"mccCode\": \"70005\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"零售\",\n" + " \"mccCode\": \"7\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"桌游吧\",\n" + " \"mccCode\": \"80001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"演唱会\",\n" + " \"mccCode\": \"80002\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"马术训练\",\n" + " \"mccCode\": \"80003\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"瑜伽\",\n" + " \"mccCode\": \"80004\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"健身\",\n" + " \"mccCode\": \"80005\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"社团\",\n" + " \"mccCode\": \"80006\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"网吧\",\n" + " \"mccCode\": \"80007\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"KTV\",\n" + " \"mccCode\": \"80008\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"电影\",\n" + " \"mccCode\": \"80009\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"休闲娱乐\",\n" + " \"mccCode\": \"8\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"摄影\",\n" + " \"mccCode\": \"90001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"massage\",\n" + " \"mccCode\": \"90002\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"通讯运营商\",\n" + " \"mccCode\": \"90003\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"车行\",\n" + " \"mccCode\": \"90004\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children:\":[],\n" + " \"label\":\"软件服务\",\n" + " \"mccCode\":\"90005\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"其他服务类\",\n" + " \"mccCode\": \"9\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"Hotel\",\n" + " \"mccCode\": \"100001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"Motel\",\n" + " \"mccCode\": \"100002\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"酒店\",\n" + " \"mccCode\": \"10\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"代购\",\n" + " \"mccCode\": \"110001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"物流(大宗出口贸易)\",\n" + " \"mccCode\": \"110002\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"红酒出口\",\n" + " \"mccCode\": \"110003\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"综合电商\",\n" + " \"mccCode\": \"110004\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"出口贸易\",\n" + " \"mccCode\": \"11\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"建材\",\n" + " \"mccCode\": \"120001\"\n" + " },\n" + " {\n"
|
|
||||||
+ " \"children\": [],\n" + " \"label\": \"家居\",\n" + " \"mccCode\": \"120002\"\n" + " }\n" + " ],\n"
|
|
||||||
+ " \"label\": \"家居建材\",\n" + " \"mccCode\": \"12\"\n" + " }\n" + "]";
|
|
||||||
|
|
||||||
JSONArray jsonArray = JSONObject.parseArray(json);
|
|
||||||
|
|
||||||
try {
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/Users/wangning/Desktop/asd.xlsx")));
|
|
||||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
||||||
Iterator<Row> rowIterator = sheet.rowIterator();
|
|
||||||
Row row = null;
|
|
||||||
Cell cell = null;
|
|
||||||
while (rowIterator.hasNext()) {
|
|
||||||
row = rowIterator.next();
|
|
||||||
cell = row.getCell(2);
|
|
||||||
if (cell == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
||||||
String industryChinese = recursionIndustry(jsonArray, cell.getStringCellValue());
|
|
||||||
cell.setCellValue(industryChinese);
|
|
||||||
|
|
||||||
}
|
|
||||||
OutputStream out = new FileOutputStream("/Users/wangning/Desktop/qwe.xlsx");
|
|
||||||
workbook.write(out);
|
|
||||||
workbook.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String recursionIndustry(JSONArray jsonArray, String mccCode) {
|
|
||||||
String result = "";
|
|
||||||
for (Object o : jsonArray) {
|
|
||||||
if (StringUtils.isNotEmpty(result)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
JSONObject tmp = (JSONObject) o;
|
|
||||||
if (tmp.getString("mccCode").equals(mccCode)) {
|
|
||||||
result = tmp.getString("label");
|
|
||||||
} else {
|
|
||||||
if (tmp.getJSONArray("children") != null) {
|
|
||||||
result = recursionIndustry(tmp.getJSONArray("children"), mccCode);
|
|
||||||
} else {
|
|
||||||
result = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void zxcs(){
|
|
||||||
cityPartnerPrizeService.generateSenior("2018-02");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue