From 239db017696c83db866eb3c222403cf3218e256b Mon Sep 17 00:00:00 2001 From: Yixian Date: Sat, 13 Nov 2021 10:00:04 +0800 Subject: [PATCH] add locker for --- .../manage/dev/web/TestController.java | 288 +++++++++--------- 1 file changed, 149 insertions(+), 139 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java index 27d1a9919..bf0964a66 100644 --- a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestController.java @@ -37,6 +37,7 @@ import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.http.HttpUtils; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; +import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler; import au.com.royalpay.payment.tools.utils.PdfUtils; import au.com.royalpay.payment.tools.utils.TimeZoneUtils; import com.alibaba.fastjson.JSON; @@ -77,6 +78,8 @@ import java.util.Optional; public class TestController { private final Logger logger = LoggerFactory.getLogger(getClass()); @Resource + private SynchronizedScheduler synchronizedScheduler; + @Resource private OrderMapper orderMapper; @Resource private RefundMapper refundMapper; @@ -178,7 +181,8 @@ public class TestController { } /** - * 第二个版本的合同 + * 第二个版本的合同 + * * @param clientMoniker * @param manager * @param httpResponse @@ -186,95 +190,95 @@ public class TestController { */ @ManagerMapping(value = "/{clientMoniker}/export/aggregate/agreepdf", method = RequestMethod.GET, role = {ManagerRole.ADMIN, ManagerRole.DIRECTOR, ManagerRole.OPERATOR}) public void exportAggregateAgreeFile(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse httpResponse) { - logger.info("===>exportAggregateAgreeFile:path:"+aggragatePdfPath); + logger.info("===>exportAggregateAgreeFile:path:" + aggragatePdfPath); httpResponse.setContentType("application/pdf"); httpResponse.setHeader("content-disposition", "attachment;filename=" + clientMoniker + "_AGREEMENT_" + new Date() + ".pdf"); try { - ServletOutputStream sos = httpResponse.getOutputStream(); + ServletOutputStream sos = httpResponse.getOutputStream(); - JSONObject client = clientMapper.findClientByMoniker(clientMoniker); - if (client == null) { - throw new InvalidShortIdException(); - } - String address = client.getString("address").trim(); - if (address.contains(",")) { - client.put("address", address.substring(0, address.lastIndexOf(",")).trim()); - client.put("address_sub", address.substring(address.lastIndexOf(",") + 1).trim()); - } - if (client.getString("acn") != null && !client.getString("acn").equals("")) { - client.put("acn_type", "ACN: (" + client.getString("acn") + ")"); - client.put("company_name_acn", client.getString("company_name") + " (ACN " + client.getString("acn") + ")"); - } else { - client.put("acn_type", "ABN: (" + client.getString("abn") + ")"); - client.put("company_name_acn", client.getString("company_name") + " (ABN " + client.getString("abn") + ")"); - } + JSONObject client = clientMapper.findClientByMoniker(clientMoniker); + if (client == null) { + throw new InvalidShortIdException(); + } + String address = client.getString("address").trim(); + if (address.contains(",")) { + client.put("address", address.substring(0, address.lastIndexOf(",")).trim()); + client.put("address_sub", address.substring(address.lastIndexOf(",") + 1).trim()); + } + if (client.getString("acn") != null && !client.getString("acn").equals("")) { + client.put("acn_type", "ACN: (" + client.getString("acn") + ")"); + client.put("company_name_acn", client.getString("company_name") + " (ACN " + client.getString("acn") + ")"); + } else { + client.put("acn_type", "ABN: (" + client.getString("abn") + ")"); + client.put("company_name_acn", client.getString("company_name") + " (ABN " + client.getString("abn") + ")"); + } - JSONObject weChatRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "Wechat"); - if (weChatRate == null) { - throw new BadRequestException("The Partner's Rate is not config!"); - } - client.put("wechat_rate", weChatRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)); - client.put("clean", "T+"+weChatRate.getString("clean_days")); - client.put("clean_days", weChatRate.getString("clean_days")); - client.put("located_country", "Australia"); - if("1".equalsIgnoreCase(weChatRate.getString("clean_days"))){ + JSONObject weChatRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "Wechat"); + if (weChatRate == null) { + throw new BadRequestException("The Partner's Rate is not config!"); + } + client.put("wechat_rate", weChatRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)); + client.put("clean", "T+" + weChatRate.getString("clean_days")); + client.put("clean_days", weChatRate.getString("clean_days")); + client.put("located_country", "Australia"); + if ("1".equalsIgnoreCase(weChatRate.getString("clean_days"))) { // clean_1 clean_1_friday clean_1_saturday - // second, third or fourth - client.put("clean_1", weChatRate.getString("clean_days")); - client.put("clean_1_friday", "first"); - client.put("clean_1_saturday", "second"); - }else if("2".equalsIgnoreCase(weChatRate.getString("clean_days"))){ - client.put("clean_1", weChatRate.getString("clean_days")); - client.put("clean_1_friday", "second"); - client.put("clean_1_saturday", "third"); - - }else if("3".equalsIgnoreCase(weChatRate.getString("clean_days"))){ - client.put("clean_1", weChatRate.getString("clean_days")); - client.put("clean_1_friday", "third"); - client.put("clean_1_saturday", "fourth"); - } - - try { - JSONObject alipayRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "Alipay"); - if (alipayRate != null) { - client.put("alipay_rate", alipayRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)); + // second, third or fourth + client.put("clean_1", weChatRate.getString("clean_days")); + client.put("clean_1_friday", "first"); + client.put("clean_1_saturday", "second"); + } else if ("2".equalsIgnoreCase(weChatRate.getString("clean_days"))) { + client.put("clean_1", weChatRate.getString("clean_days")); + client.put("clean_1_friday", "second"); + client.put("clean_1_saturday", "third"); + + } else if ("3".equalsIgnoreCase(weChatRate.getString("clean_days"))) { + client.put("clean_1", weChatRate.getString("clean_days")); + client.put("clean_1_friday", "third"); + client.put("clean_1_saturday", "fourth"); } - JSONObject alipayOnlineRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "AlipayOnline"); - if (alipayOnlineRate != null) { - client.put("alipay_online_rate", alipayOnlineRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)); + + try { + JSONObject alipayRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "Alipay"); + if (alipayRate != null) { + client.put("alipay_rate", alipayRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)); + } + JSONObject alipayOnlineRate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "AlipayOnline"); + if (alipayOnlineRate != null) { + client.put("alipay_online_rate", alipayOnlineRate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN)); + } + } catch (Exception ignored) { + //do nothing } - } catch (Exception ignored) { - //do nothing - } - JSONObject account = getBankAccountByClientId(client.getIntValue("client_id")); - if (account == null || account.size() <= 0) { - throw new BadRequestException("The Partner's Account is not config!"); - } + JSONObject account = getBankAccountByClientId(client.getIntValue("client_id")); + if (account == null || account.size() <= 0) { + throw new BadRequestException("The Partner's Account is not config!"); + } - client.put("bank", account.getString("bank")); - client.put("bsb_no", account.getString("bsb_no")); - client.put("account_no", account.getString("account_no")); - client.put("account_name", account.getString("account_name")); - String start_date = DateFormatUtils.format(new Date(), "dd/MM/yyyy"); - client.put("start_date", start_date); - Date endDate = TimeZoneUtils.nextYearByCurrDay(); - String end_date = DateFormatUtils.format(endDate, "dd/MM/yyyy"); - client.put("end_date", end_date); - JSONObject clientLegal = sysClientLegalPersonMapper.findRepresentativeInfo(client.getIntValue("client_id")); - if (clientLegal != null) { - client.put("legal_person", clientLegal.getString("representative_person")); - client.put("legal_job_title", clientLegal.getString("job_title")); - client.put("legal_phone", clientLegal.getString("phone")); - client.put("legal_email", clientLegal.getString("email")); - client.put("client_contract_manager", clientLegal.getString("representative_person"));//client contract manager - } + client.put("bank", account.getString("bank")); + client.put("bsb_no", account.getString("bsb_no")); + client.put("account_no", account.getString("account_no")); + client.put("account_name", account.getString("account_name")); + String start_date = DateFormatUtils.format(new Date(), "dd/MM/yyyy"); + client.put("start_date", start_date); + Date endDate = TimeZoneUtils.nextYearByCurrDay(); + String end_date = DateFormatUtils.format(endDate, "dd/MM/yyyy"); + client.put("end_date", end_date); + JSONObject clientLegal = sysClientLegalPersonMapper.findRepresentativeInfo(client.getIntValue("client_id")); + if (clientLegal != null) { + client.put("legal_person", clientLegal.getString("representative_person")); + client.put("legal_job_title", clientLegal.getString("job_title")); + client.put("legal_phone", clientLegal.getString("phone")); + client.put("legal_email", clientLegal.getString("email")); + client.put("client_contract_manager", clientLegal.getString("representative_person"));//client contract manager + } - PdfUtils pdu = new PdfUtils(); - pdu.setTemplatePdfPath(aggragatePdfPath); - pdu.setPdfTemplate(client); - File file = new File(clientMoniker + "_agreement.pdf"); + PdfUtils pdu = new PdfUtils(); + pdu.setTemplatePdfPath(aggragatePdfPath); + pdu.setPdfTemplate(client); + File file = new File(clientMoniker + "_agreement.pdf"); ByteArrayOutputStream bos = pdu.templetPdfBos(file); @@ -285,6 +289,7 @@ public class TestController { e.printStackTrace(); } } + /** * 制作卡支付合同 * @@ -464,8 +469,15 @@ public class TestController { } @GetMapping(value = "/task/analysisDashboard") - public void analysisDashboard(@RequestParam("date") String date) throws ParseException { - dashboardService.generateCustomersAndOrdersStatistics(DateUtils.parseDate(date, "yyyyMMdd")); + public void analysisDashboard(@RequestParam("date") String date) { + synchronizedScheduler.executeProcess("manage_task:dashboardTask", 120_000, + () -> { + try { + dashboardService.generateCustomersAndOrdersStatistics(DateUtils.parseDate(date, "yyyyMMdd")); + } catch (ParseException e) { + logger.error("invalid input date:{}", date); + } + }); } @@ -567,70 +579,69 @@ public class TestController { /** * 批量更新微信子商户号 */ - @ManagerMapping(value = "/batch_update_wxsubmerchantId", method = RequestMethod.GET, role = {ManagerRole.ADMIN, ManagerRole.DIRECTOR, ManagerRole.OPERATOR, ManagerRole.DEVELOPER}) + @ManagerMapping(value = "/batch_update_wxsubmerchantId", method = RequestMethod.GET, role = {ManagerRole.ADMIN, ManagerRole.DIRECTOR, ManagerRole.OPERATOR, ManagerRole.DEVELOPER}) public void batchUpdateWxSubmerchantId() { - List findSubMerchantIdHistorys=sysWxMerchantApplyMapper.findSubMerchantIdHistorys(); - if(findSubMerchantIdHistorys==null)return; - logger.info("=========>batchUpdateWxSubmerchantId:"+findSubMerchantIdHistorys.size()); + List findSubMerchantIdHistorys = sysWxMerchantApplyMapper.findSubMerchantIdHistorys(); + if (findSubMerchantIdHistorys == null) return; + logger.info("=========>batchUpdateWxSubmerchantId:" + findSubMerchantIdHistorys.size()); findSubMerchantIdHistorys.parallelStream().forEach(jsonObject -> { JSONObject clientJson = clientMapper.findClient(jsonObject.getInteger("client_id")); JSONObject wechatMcc = paymentChannelMccGoodMapper.findWechatPayMccByClientId(jsonObject.getIntValue("client_id")); JSONObject clientConfig = clientConfigMapper.find(jsonObject.getIntValue("client_id")); - if(clientJson==null){ - logger.info("=========>没有查询到client:"+jsonObject.getInteger("client_id")); + if (clientJson == null) { + logger.info("=========>没有查询到client:" + jsonObject.getInteger("client_id")); return; } - if(wechatMcc==null){ - logger.info("=========>没有查询到mcc:"+jsonObject.getInteger("client_id")); + if (wechatMcc == null) { + logger.info("=========>没有查询到mcc:" + jsonObject.getInteger("client_id")); return; } // company_name short_name industry company_phone contact_person contact_phone contact_email 这些字段不能为空 - if(TextUtils.isEmpty(clientJson.getString("short_name"))|| - TextUtils.isEmpty(clientJson.getString("industry"))|| - TextUtils.isEmpty(clientJson.getString("company_phone"))|| - TextUtils.isEmpty(clientJson.getString("contact_phone"))|| - TextUtils.isEmpty(clientJson.getString("contact_person"))|| - TextUtils.isEmpty(clientJson.getString("contact_email"))|| - TextUtils.isEmpty(wechatMcc.getString("mc_code"))){ - logger.error("=======>数据不完整:clientid:"+jsonObject.getInteger("client_id")+""); + if (TextUtils.isEmpty(clientJson.getString("short_name")) || + TextUtils.isEmpty(clientJson.getString("industry")) || + TextUtils.isEmpty(clientJson.getString("company_phone")) || + TextUtils.isEmpty(clientJson.getString("contact_phone")) || + TextUtils.isEmpty(clientJson.getString("contact_person")) || + TextUtils.isEmpty(clientJson.getString("contact_email")) || + TextUtils.isEmpty(wechatMcc.getString("mc_code"))) { + logger.error("=======>数据不完整:clientid:" + jsonObject.getInteger("client_id") + ""); return; } - NewSubMerchantIdApply newSubMerchantIdApply=new NewSubMerchantIdApply(); + NewSubMerchantIdApply newSubMerchantIdApply = new NewSubMerchantIdApply(); newSubMerchantIdApply.setMerchant_id(jsonObject.getString("merchant_id")); newSubMerchantIdApply.setSub_mch_id(jsonObject.getString("sub_merchant_id")); newSubMerchantIdApply.setMerchantRemark(jsonObject.getString("merchant_remark")); - newSubMerchantIdApply.setMerchant_name(cutLength(jsonObject.getString("merchant_name"),50)); - newSubMerchantIdApply.setAddress(cutLength(clientJson.getString("address"),128)); - newSubMerchantIdApply.setMerchant_shortname(cutLength(clientJson.getString("short_name"),64)); + newSubMerchantIdApply.setMerchant_name(cutLength(jsonObject.getString("merchant_name"), 50)); + newSubMerchantIdApply.setAddress(cutLength(clientJson.getString("address"), 128)); + newSubMerchantIdApply.setMerchant_shortname(cutLength(clientJson.getString("short_name"), 64)); newSubMerchantIdApply.setBusiness_category(clientJson.getString("industry")); - newSubMerchantIdApply.setWebsite(cutLength(clientJson.getString("company_website"),100)); - newSubMerchantIdApply.setOffice_phone(cutLength(clientJson.getString("company_phone"),20)); - newSubMerchantIdApply.setContact_phone(cutLength(clientJson.getString("contact_phone"),16)); - newSubMerchantIdApply.setContact_name(cutLength(clientJson.getString("contact_person"),32)); - newSubMerchantIdApply.setContact_email(cutLength(clientJson.getString("contact_email"),50)); - newSubMerchantIdApply.setMcc_code(cutLength(wechatMcc.getString("mc_code"),10)); - - if(!TextUtils.isEmpty(clientConfig.getString("client_pay_type"))){ - if(clientConfig.getString("client_pay_type").indexOf("1")>=0 - &&clientConfig.getString("client_pay_type").indexOf("2")>=0){ + newSubMerchantIdApply.setWebsite(cutLength(clientJson.getString("company_website"), 100)); + newSubMerchantIdApply.setOffice_phone(cutLength(clientJson.getString("company_phone"), 20)); + newSubMerchantIdApply.setContact_phone(cutLength(clientJson.getString("contact_phone"), 16)); + newSubMerchantIdApply.setContact_name(cutLength(clientJson.getString("contact_person"), 32)); + newSubMerchantIdApply.setContact_email(cutLength(clientJson.getString("contact_email"), 50)); + newSubMerchantIdApply.setMcc_code(cutLength(wechatMcc.getString("mc_code"), 10)); + + if (!TextUtils.isEmpty(clientConfig.getString("client_pay_type"))) { + if (clientConfig.getString("client_pay_type").indexOf("1") >= 0 + && clientConfig.getString("client_pay_type").indexOf("2") >= 0) { newSubMerchantIdApply.setBusiness_type("BOTH"); - }else if(clientConfig.getString("client_pay_type").indexOf("1")>=0){ + } else if (clientConfig.getString("client_pay_type").indexOf("1") >= 0) { newSubMerchantIdApply.setBusiness_type("ONLINE"); - } - else if(clientConfig.getString("client_pay_type").indexOf("2")>=0){ + } else if (clientConfig.getString("client_pay_type").indexOf("2") >= 0) { newSubMerchantIdApply.setBusiness_type("OFFLINE"); } - }else{ + } else { newSubMerchantIdApply.setBusiness_type("BOTH"); } if (!TextUtils.isEmpty(clientJson.getString("business_structure"))) { - newSubMerchantIdApply.setMerchant_type(clientJson.getString("business_structure").equals("Registered body(Sole Trader)")?"INDIVIDUAL":"ENTERPRISE") ; - }else{ - newSubMerchantIdApply.setMerchant_type("INDIVIDUAL") ; + newSubMerchantIdApply.setMerchant_type(clientJson.getString("business_structure").equals("Registered body(Sole Trader)") ? "INDIVIDUAL" : "ENTERPRISE"); + } else { + newSubMerchantIdApply.setMerchant_type("INDIVIDUAL"); } - newSubMerchantIdApply.setCompany_register_no(cutLength(TextUtils.isEmpty(clientJson.getString("acn"))?clientJson.getString("abn"):clientJson.getString("acn"),50)); + newSubMerchantIdApply.setCompany_register_no(cutLength(TextUtils.isEmpty(clientJson.getString("acn")) ? clientJson.getString("abn") : clientJson.getString("acn"), 50)); if (!TextUtils.isEmpty(clientJson.getString("certificat_expire_date"))) { newSubMerchantIdApply.setCertificat_expire_date(clientJson.getString("certificat_expire_date")); } else { @@ -638,34 +649,32 @@ public class TestController { } - if("ENTERPRISE".equalsIgnoreCase(newSubMerchantIdApply.getMerchant_type())&&TextUtils.isEmpty(newSubMerchantIdApply.getCompany_register_no())){ - logger.error("=======>公司注册号为空:clientid:"+clientJson.getInteger("client_id")+":"+clientJson.getString("client_moniker")); + if ("ENTERPRISE".equalsIgnoreCase(newSubMerchantIdApply.getMerchant_type()) && TextUtils.isEmpty(newSubMerchantIdApply.getCompany_register_no())) { + logger.error("=======>公司注册号为空:clientid:" + clientJson.getInteger("client_id") + ":" + clientJson.getString("client_moniker")); return; } - if("BOTH".equalsIgnoreCase(newSubMerchantIdApply.getBusiness_type())&&(TextUtils.isEmpty(newSubMerchantIdApply.getAddress())|| - TextUtils.isEmpty(newSubMerchantIdApply.getWebsite()))){ - logger.error("=======>公司类型为BOTH:网址或地址为空:clientid:"+clientJson.getInteger("client_id")+":"+clientJson.getString("client_moniker")); + if ("BOTH".equalsIgnoreCase(newSubMerchantIdApply.getBusiness_type()) && (TextUtils.isEmpty(newSubMerchantIdApply.getAddress()) || + TextUtils.isEmpty(newSubMerchantIdApply.getWebsite()))) { + logger.error("=======>公司类型为BOTH:网址或地址为空:clientid:" + clientJson.getInteger("client_id") + ":" + clientJson.getString("client_moniker")); return; - } - else if("OFFLINE".equalsIgnoreCase(newSubMerchantIdApply.getBusiness_type())&&(TextUtils.isEmpty(newSubMerchantIdApply.getAddress()))){ - logger.error("=======>公司类型为OFFLINE:地址为空:clientid:"+clientJson.getInteger("client_id")+":"+clientJson.getString("client_moniker")); + } else if ("OFFLINE".equalsIgnoreCase(newSubMerchantIdApply.getBusiness_type()) && (TextUtils.isEmpty(newSubMerchantIdApply.getAddress()))) { + logger.error("=======>公司类型为OFFLINE:地址为空:clientid:" + clientJson.getInteger("client_id") + ":" + clientJson.getString("client_moniker")); return; - } - else if("ONLINE".equalsIgnoreCase(newSubMerchantIdApply.getBusiness_type())&& - TextUtils.isEmpty(newSubMerchantIdApply.getWebsite())){ - logger.error("=======>公司类型为ONLINE:网址为空:clientid:"+clientJson.getInteger("client_id")+":"+clientJson.getString("client_moniker")); + } else if ("ONLINE".equalsIgnoreCase(newSubMerchantIdApply.getBusiness_type()) && + TextUtils.isEmpty(newSubMerchantIdApply.getWebsite())) { + logger.error("=======>公司类型为ONLINE:网址为空:clientid:" + clientJson.getInteger("client_id") + ":" + clientJson.getString("client_moniker")); return; } JSONObject params = newSubMerchantIdApply.insertObject(clientJson); params.put("merchant_app_id", jsonObject.getString("merchant_app_id")); SubMerchantInfoInheritance subMerchantInfo = JSON.toJavaObject(params, SubMerchantInfoInheritance.class); - params.put("operator","System"); + params.put("operator", "System"); WxPayMerchantRegister register = Optional.ofNullable(merchantChannelApplicationManager.getRegister(WxPayMerchantRegister.class)) .orElseThrow(() -> new ServerErrorException("No Register found for wechat")); - JSONObject manager=new JSONObject(); - manager.put("display_name","System"); + JSONObject manager = new JSONObject(); + manager.put("display_name", "System"); register.modifyForBatch(jsonObject.getString("merchant_app_id"), clientJson, subMerchantInfo, manager); try { Thread.sleep(500); @@ -677,6 +686,7 @@ public class TestController { } + /** * 批量更新微信子商户号 */ @@ -784,12 +794,12 @@ public class TestController { // // // } - public String cutLength(String str,int maxlen){ - if(TextUtils.isEmpty(str))return ""; - if(str.length()>maxlen){ - return str.substring(0,maxlen); - }else{ - return str; + public String cutLength(String str, int maxlen) { + if (TextUtils.isEmpty(str)) return ""; + if (str.length() > maxlen) { + return str.substring(0, maxlen); + } else { + return str; } }