master
taylor.dang 5 years ago
parent fb436d375a
commit 1155160248

@ -1,18 +1,17 @@
package au.com.royalpay.payment.manage.dev.core;
import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean;
import au.com.royalpay.payment.manage.dev.bean.AliExcel;
import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public interface AliforexcelService {
JSONObject listClients(HttpServletResponse httpResponse, JSONObject manager, AliExcel query);
JSONObject registerAlipayOnlineMerchant();
void registerWechatMerchant();
JSONObject registerRangeAlipayOnlineMerchant(int start,int end);
JSONObject registerAlipayMerchant();

@ -3,16 +3,16 @@ package au.com.royalpay.payment.manage.dev.core.impl;
import au.com.royalpay.payment.channels.alipay.config.AlipayConfig;
import au.com.royalpay.payment.channels.alipay.config.AlipayEnvironment;
import au.com.royalpay.payment.channels.alipay.runtime.AlipayClient;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.mappers.PmtOrderMapper;
import au.com.royalpay.payment.channels.wechat.runtime.WxPayClient;
import au.com.royalpay.payment.channels.wechat.runtime.beans.SubMerchantInfo;
import au.com.royalpay.payment.manage.dev.bean.AliExcel;
import au.com.royalpay.payment.manage.dev.core.AliforexcelService;
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
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.SysWxMerchantApplyMapper;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import com.alibaba.fastjson.JSONObject;
import com.yeepay.shade.org.apache.commons.lang3.StringUtils;
import org.apache.commons.io.IOUtils;
@ -32,6 +32,7 @@ import java.io.OutputStream;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service
@ -46,42 +47,46 @@ public class AliforexcelServiceImpl implements AliforexcelService {
private AlipayClient alipayClient;
@Resource
private OrderMapper orderMapper;
@Resource
private WxPayClient wxPayClient;
@Resource
private SysWxMerchantApplyMapper sysWxMerchantApplyMapper;
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public JSONObject listClients(HttpServletResponse httpResponse,JSONObject manager, AliExcel query) {
public JSONObject listClients(HttpServletResponse httpResponse, JSONObject manager, AliExcel query) {
OutputStream ous = null;
try{
try {
JSONObject params = query.toJsonParam();
List<JSONObject> partners = clientMapper.passPartners(params);
httpResponse.setContentType("application/octet-stream;");
httpResponse.setCharacterEncoding("utf-8");
String fileName = "支付宝进件专用--";
String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
httpResponse.addHeader("Content-Disposition", "attachment; filename=" + codedFileName +query.getDatefrom() + "~" +query.getDateto() + ".xls");
httpResponse.addHeader("Content-Disposition", "attachment; filename=" + codedFileName + query.getDatefrom() + "~" + query.getDateto() + ".xls");
ous = httpResponse.getOutputStream();
HSSFWorkbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("支付宝进件专用" );
Sheet sheet = wb.createSheet("支付宝进件专用");
sheet.createFreezePane(1, 2);
sheet.setDefaultColumnWidth((short) 25);
int rowNum = 0;
Row row = sheet.createRow(rowNum);
String[] title = {"Company name", "Store name", "Partner Code","Industry","Store address","Business hours","Contact information","Video link (optional)","Store description","Tags","Logo","Company Photo"};
String[] title = {"Company name", "Store name", "Partner Code", "Industry", "Store address", "Business hours", "Contact information", "Video link (optional)", "Store description", "Tags", "Logo", "Company Photo"};
for (int i = 0; i < title.length; i++) {
row.createCell(i, Cell.CELL_TYPE_STRING).setCellValue(title[i]);
}
for(JSONObject partner : partners){
for (JSONObject partner : partners) {
row = sheet.createRow(++rowNum);
row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("company_name"));
row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("short_name"));
if (!"".equals(partner.getString("ali_sub_merchant_id"))) {
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("ali_sub_merchant_id"));
}else {
} else {
row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("client_moniker"));
}
row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("alipayindustry"));
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("address")+","+partner.getString("suburb") + "," + partner.getString("state") + "," + partner.getString("postcode"));
row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("address") + "," + partner.getString("suburb") + "," + partner.getString("state") + "," + partner.getString("postcode"));
row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("business_hours"));
row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("company_phone"));
row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(partner.getString(""));
@ -94,7 +99,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
ous.flush();
}catch (IOException e){
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(ous);
}
@ -109,7 +114,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
List<String> registerSuccessMerchant = new ArrayList<>();
List<JSONObject> registerFailMerchant = new ArrayList<>();
List<JSONObject> lessInfoMerchant = new ArrayList<>();
List<Integer> useAlipayOnlineMerchant = clientMapper.listUseAlipayMerchant(0,10000);
List<Integer> useAlipayOnlineMerchant = clientMapper.listUseAlipayMerchant(0, 10000);
for (int clientId : useAlipayOnlineMerchant) {
JSONObject client = clientMapper.findClient(clientId);
if (client == null) {
@ -118,9 +123,9 @@ public class AliforexcelServiceImpl implements AliforexcelService {
try {
needRegisterMerchant.add(client.getString("client_moniker"));
if (StringUtils.isBlank(client.getString("company_website"))) {
client.put("company_website", client.getString("ali_sub_merchant_id")+".royalpay.com.au");
client.put("company_website", client.getString("ali_sub_merchant_id") + ".royalpay.com.au");
}
checkPartnerInfo(client,"online");
checkPartnerInfo(client, "online");
} catch (InvalidParameterException e) {
JSONObject exception = new JSONObject();
exception.put("client_moniker", client.getString("client_moniker"));
@ -159,10 +164,39 @@ public class AliforexcelServiceImpl implements AliforexcelService {
result.put("success_register_merchant", registerSuccessMerchant);
result.put("fail_register_merchant", registerFailMerchant);
result.put("less_info_merchant", lessInfoMerchant);
logger.info("-------AlipayOnline Gms end----fail_register_merchant"+registerFailMerchant.toString());
logger.info("-------AlipayOnline Gms end----fail_register_merchant" + registerFailMerchant.toString());
return result;
}
@Override
public void registerWechatMerchant() {
List<JSONObject> apClients = clientMapper.findApClient();
apClients.forEach(client -> {
JSONObject params = new JSONObject();
params.put("merchant_name", client.getString("company_name"));
params.put("merchant_shortname", client.getString("short_name"));
params.put("office_phone", client.getString("contact_phone"));
params.put("contact_phone", client.getString("contact_phone"));
params.put("contact_email", client.getString("contact_email"));
params.put("business_category", "392");
params.put("merchant_remark", client.getString("client_moniker"));
params.put("website", client.getString("website"));
SubMerchantInfo subMerchantInfo = JSONObject.toJavaObject(params, SubMerchantInfo.class);
params.put("merchant_id", client.getString("merchant_id"));
params.put("client_id", client.getString("client_id"));
params.put("create_time", new Date());
params.put("operator", "System");
Element elem = wxPayClient.subMerchantApplication(client.getString("merchant_id"), subMerchantInfo);
String sub_merchant_id = elem.elementText("sub_mch_id");
if (StringUtils.isNotEmpty(sub_merchant_id)) {
params.put("sub_merchant_id", sub_merchant_id);
sysWxMerchantApplyMapper.insertWxMerchantApply(params);
} else {
throw new BadRequestException(elem.elementText("return_msg"));
}
});
}
@Override
public JSONObject registerRangeAlipayOnlineMerchant(int start, int end) {
JSONObject result = new JSONObject();
@ -170,16 +204,12 @@ public class AliforexcelServiceImpl implements AliforexcelService {
List<String> registerSuccessMerchant = new ArrayList<>();
List<JSONObject> registerFailMerchant = new ArrayList<>();
List<JSONObject> lessInfoMerchant = new ArrayList<>();
List<Integer> useAlipayOnlineMerchant = clientMapper.listUseAlipayMerchant(start,end);
for (int clientId : useAlipayOnlineMerchant) {
JSONObject client = clientMapper.findClient(clientId);
if (client == null) {
continue;
}
List<JSONObject> alipayApClients = clientMapper.findApClient();
alipayApClients.forEach(client -> {
try {
needRegisterMerchant.add(client.getString("client_moniker"));
if (StringUtils.isBlank(client.getString("company_website"))) {
client.put("company_website", client.getString("ali_sub_merchant_id")+".royalpay.com.au");
client.put("company_website", client.getString("ali_sub_merchant_id") + ".royalpay.com.au");
}
if (StringUtils.isBlank(client.getString("alipayindustry"))) {
client.put("alipayindustry", "5311");
@ -187,14 +217,13 @@ public class AliforexcelServiceImpl implements AliforexcelService {
if (StringUtils.isBlank(client.getString("business_structure"))) {
client.put("business_structure", "da");
}
checkPartnerInfo(client,"online");
checkPartnerInfo(client, "online");
} catch (InvalidParameterException e) {
JSONObject exception = new JSONObject();
exception.put("client_moniker", client.getString("client_moniker"));
exception.put("return_msg", e.getMessage());
exception.put("bd_name", client.getString("bd_user_name"));
lessInfoMerchant.add(exception);
continue;
}
try {
AlipayConfig.AlipayMerchant mch = AlipayEnvironment.getEnv().getAlipayOnlineMerchant();
@ -204,7 +233,6 @@ public class AliforexcelServiceImpl implements AliforexcelService {
exception.put("client_moniker", client.getString("client_moniker"));
exception.put("return_msg", resultElement.elementText("error"));
registerFailMerchant.add(exception);
continue;
}
Element responseElement = resultElement.element("response").element("alipay");
if (!StringUtils.equalsIgnoreCase("SUCCESS", responseElement.elementText("result_code"))) {
@ -212,7 +240,6 @@ public class AliforexcelServiceImpl implements AliforexcelService {
exception.put("client_moniker", client.getString("client_moniker"));
exception.put("return_msg", resultElement.elementText("error"));
registerFailMerchant.add(exception);
continue;
}
registerSuccessMerchant.add(client.getString("client_moniker"));
} catch (Exception e) {
@ -221,12 +248,12 @@ public class AliforexcelServiceImpl implements AliforexcelService {
exception.put("return_msg", e.getMessage());
registerFailMerchant.add(exception);
}
}
});
result.put("need_register_merchant", needRegisterMerchant);
result.put("success_register_merchant", registerSuccessMerchant);
result.put("fail_register_merchant", registerFailMerchant);
result.put("less_info_merchant", lessInfoMerchant);
logger.info("-------AlipayOnline Gms end----fail_register_merchant"+registerFailMerchant.toString());
logger.info("-------AlipayOnline Gms end----fail_register_merchant" + registerFailMerchant.toString());
return result;
}
@ -237,23 +264,17 @@ public class AliforexcelServiceImpl implements AliforexcelService {
List<String> registerSuccessMerchant = new ArrayList<>();
List<JSONObject> registerFailMerchant = new ArrayList<>();
List<JSONObject> lessInfoMerchant = new ArrayList<>();
String alipayOfflineMerchantsStr = "FORE,RAYI,AASO,BGWI,HYMQ,LIFE,TWTA,AMYW,CCTM,JCYA,JICH,ADGJ,MAGL,TOMA,MCNE,LILC,YOTR,PENG,CASM,SHAO,SWCG,TMCF,BPAR,DNLG,OVAU,SJZH,VWPA,BCOL,MOLI,LIYA,TST3,AUKN,MMEK,GINF,EZE2,GOTR,CJKD,QR12,NJHI,WHAP,HOTO,OMNI,UGGM,JJTV,HHPL,BSPL,TOUR,AUMG,AYUC,BFLI,WAOR,SUTR,LTEA,BRAV,BTTC,FATT,VFPL,LEOH,BHHO,ISSP,JOLP,SUNH,NEVC,QR56,GNH9,SHFO,4UBW,ZZAO,B12H,QUMA,MAYH,FMPS,OWPL,CUDE,I2MI,FAGO,FADA,ZHHS,MANT,DOMU,NTTB,SDCN,8QNF,BHLW,KNIT,U4N9,WNNN";
String[] alipayOfflineMerchants = alipayOfflineMerchantsStr.split(",");
for (String clientMoniker : alipayOfflineMerchants) {
JSONObject client = clientMapper.findClientByMoniker(clientMoniker);
if (client == null) {
continue;
}
List<JSONObject> alipayApClients = clientMapper.findApClient();
alipayApClients.forEach(client -> {
try {
needRegisterMerchant.add(client.getString("client_moniker"));
checkPartnerInfo(client,"offline");
checkPartnerInfo(client, "offline");
} catch (InvalidParameterException e) {
JSONObject exception = new JSONObject();
exception.put("client_moniker", client.getString("client_moniker"));
exception.put("return_msg", e.getMessage());
exception.put("bd_name", client.getString("bd_user_name"));
lessInfoMerchant.add(exception);
continue;
}
AlipayConfig.AlipayMerchant mch = AlipayEnvironment.getEnv().getAlipayRetailMerchant();
Element resultElement = alipayClient.registerGmsPortal(mch.getPid(), client);
@ -262,7 +283,6 @@ public class AliforexcelServiceImpl implements AliforexcelService {
exception.put("client_moniker", client.getString("client_moniker"));
exception.put("return_msg", resultElement.elementText("error"));
registerFailMerchant.add(exception);
continue;
}
Element responseElement = resultElement.element("response").element("alipay");
if (!StringUtils.equalsIgnoreCase("SUCCESS", responseElement.elementText("result_code"))) {
@ -270,10 +290,9 @@ public class AliforexcelServiceImpl implements AliforexcelService {
exception.put("client_moniker", client.getString("client_moniker"));
exception.put("return_msg", resultElement.elementText("error"));
registerFailMerchant.add(exception);
continue;
}
registerSuccessMerchant.add(client.getString("client_moniker"));
}
});
result.put("need_register_merchant", needRegisterMerchant);
result.put("success_register_merchant", registerSuccessMerchant);
result.put("fail_register_merchant", registerFailMerchant);
@ -314,7 +333,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
client.put("company_photo", client.getString("logo_url"));
}
}
checkPartnerInfo(client,"offline");
checkPartnerInfo(client, "offline");
} catch (InvalidParameterException e) {
JSONObject exception = new JSONObject();
exception.put("client_moniker", client.getString("client_moniker"));
@ -371,9 +390,9 @@ public class AliforexcelServiceImpl implements AliforexcelService {
client.put("business_structure", "da");
}
if (StringUtils.isBlank(client.getString("company_website"))) {
client.put("company_website", client.getString("ali_sub_merchant_id")+".royalpay.com.au");
client.put("company_website", client.getString("ali_sub_merchant_id") + ".royalpay.com.au");
}
checkPartnerInfo(client,"online");
checkPartnerInfo(client, "online");
} catch (InvalidParameterException e) {
JSONObject exception = new JSONObject();
exception.put("client_moniker", client.getString("client_moniker"));
@ -419,7 +438,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
continue;
}
try {
checkPartnerInfo(client,"online");
checkPartnerInfo(client, "online");
} catch (InvalidParameterException e) {
JSONObject exception = new JSONObject();
exception.put("client_moniker", client.getString("client_moniker"));
@ -432,12 +451,12 @@ public class AliforexcelServiceImpl implements AliforexcelService {
return result;
}
private void checkPartnerInfo(JSONObject client,String type) {
private void checkPartnerInfo(JSONObject client, String type) {
if ("online".equals(type)) {
if (!client.containsKey("company_website") || StringUtils.isBlank(client.getString("company_website"))) {
client.put("company_website", "https://www.royalpay.com.au/");
}
}else {
} else {
if (!client.containsKey("store_photo") && !client.containsKey("company_photo")) {
throw new InvalidParameterException("store photo cannot be empty ");
}
@ -459,7 +478,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
@Override
public void initClientPayType(int begin,int end) {
public void initClientPayType(int begin, int end) {
List<JSONObject> merchants = clientMapper.clientPayTypeInfoByClientIdRange(begin, end);
for (JSONObject partner : merchants) {
JSONObject clientConfig = new JSONObject();
@ -502,7 +521,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
types.add("1");
}
if (descs.contains("6") || descs.contains("7") || descs.contains("8") || descs.contains("9") ||
descs.contains("10") || descs.contains("11") || descs.contains("12") ||descs.contains("13")) {
descs.contains("10") || descs.contains("11") || descs.contains("12") || descs.contains("13")) {
types.add("2");
}
clientConfig.put("client_pay_type", StringUtils.join(types, ','));
@ -511,7 +530,7 @@ public class AliforexcelServiceImpl implements AliforexcelService {
}
}
private void unOrdersPartner(JSONObject partner,JSONObject clientConfig) {
private void unOrdersPartner(JSONObject partner, JSONObject clientConfig) {
if (StringUtils.isBlank(partner.getString("client_pay_type"))) {
clientConfig.put("client_pay_type", "2");
clientConfig.put("client_pay_desc", "6");

@ -500,6 +500,12 @@ public class TestController implements ApplicationEventPublisherAware {
return aliforexcelService.registerAlipayOnlineMerchant();
}
@ManagerMapping(value = "/register/wechatGms", role = ManagerRole.DEVELOPER, method = RequestMethod.POST)
public void registerWechatMerchant() {
aliforexcelService.registerWechatMerchant();
}
@ManagerMapping(value = "/register/alipayOnlineGms", role = ManagerRole.DEVELOPER, method = RequestMethod.GET)
public JSONObject registerRangeAlipayOnlineMerchant(@RequestParam int start, @RequestParam int end) {
return aliforexcelService.registerRangeAlipayOnlineMerchant(start, end);
@ -592,9 +598,9 @@ public class TestController implements ApplicationEventPublisherAware {
String declareResp;
if (StringUtils.equals("Wechat", report.getString("channel"))) {
declareResp = XmlFormatUtils.formatXml(wxPayClient.declareCustomQuery(order.getString("merchant_id"), report,null,false));
declareResp = XmlFormatUtils.formatXml(wxPayClient.declareCustomQuery(order.getString("merchant_id"), report, null, false));
} else if (StringUtils.equals("Alipay", report.getString("channel"))) {
declareResp = XmlFormatUtils.formatXml(alipayClient.queryCustomStatus(order.getString("merchant_id"), report,null,false));
declareResp = XmlFormatUtils.formatXml(alipayClient.queryCustomStatus(order.getString("merchant_id"), report, null, false));
} else {
throw new BadRequestException("Invalid Channel:" + report.getString("channel"));
}

@ -23,6 +23,10 @@ public interface ClientMapper {
@AdvanceSelect(addonWhereClause = "is_valid=1")
JSONObject findClient(@Param("client_id") int clientId);
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1 and length( client_moniker ) > 5")
List<JSONObject> findApClient();
List<JSONObject> listValidClient();
List<JSONObject> listValidClientFor30Days();
@ -139,7 +143,7 @@ public interface ClientMapper {
@Select("select client_id from sys_clients where parent_client_id=#{parent_client_id}")
List<Integer> childClientId(@Param("parent_client_id") int parent_client_id);
List<JSONObject> createClientsByGroup(@Param("start_date") Date start_date,@Param("end_date") Date end_date,@Param("start_date_month") Date start_date_month);
List<JSONObject> createClientsByGroup(@Param("start_date") Date start_date, @Param("end_date") Date end_date, @Param("start_date_month") Date start_date_month);
List<JSONObject> clientPayTypeInfoByClientIdRange(@Param("begin") int begin, @Param("end") int end);

Loading…
Cancel
Save