From 5822cbc52001f38f419ee8fc21b20ae34a4387b3 Mon Sep 17 00:00:00 2001 From: luoyang Date: Mon, 19 Aug 2019 09:43:45 +0800 Subject: [PATCH] =?UTF-8?q?add=20app=20=E8=8E=B7=E5=8F=96=E6=BA=90?= =?UTF-8?q?=E5=90=88=E5=90=8C=E6=96=87=E4=BB=B6=E3=80=81=E5=90=88=E6=88=90?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E5=90=8E=E6=96=87=E4=BB=B6url=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appclient/core/RetailAppService.java | 6 + .../core/impls/RetailAppServiceImp.java | 103 +++++++++++++++++- .../appclient/web/RetailAppController.java | 25 ++++- .../core/impls/SignInAccountServiceImpl.java | 4 +- 4 files changed, 132 insertions(+), 6 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java index 69cedabf3..e2034364d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java @@ -10,7 +10,9 @@ import au.com.royalpay.payment.tools.merchants.beans.QRCodeConfig; import au.com.royalpay.payment.tools.merchants.beans.UpdateSurchargeDTO; import com.alibaba.fastjson.JSONObject; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -193,4 +195,8 @@ public interface RetailAppService { JSONObject toggleCBBankCustomerSurcharge(JSONObject device, boolean customerSurcharge); void getCBBankAggregateFile(JSONObject device, HttpServletResponse httpResponse); + + void getSourceAggregateFile(JSONObject device, HttpServletResponse httpResponse); + + JSONObject getClientAggregateFile(JSONObject device, MultipartFile file) throws IOException; } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java index af8b694ee..f7ce405a2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java @@ -42,6 +42,7 @@ import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery; import au.com.royalpay.payment.manage.tradelog.core.TradeLogService; import au.com.royalpay.payment.manage.tradelog.refund.RefundService; import au.com.royalpay.payment.tools.cms.RoyalPayCMSSupport; +import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; import au.com.royalpay.payment.tools.device.DeviceSupport; import au.com.royalpay.payment.tools.device.message.AppMessage; import au.com.royalpay.payment.tools.device.message.AppMsgSender; @@ -67,6 +68,7 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageList; import com.github.qcloudsms.httpclient.HTTPException; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; @@ -82,12 +84,12 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import org.springframework.web.multipart.MultipartFile; import org.thymeleaf.context.Context; import org.thymeleaf.spring4.SpringTemplateEngine; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; +import java.awt.image.BufferedImage; +import java.io.*; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DateFormat; @@ -107,6 +109,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; +import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; @@ -201,8 +204,11 @@ public class RetailAppServiceImp implements RetailAppService { @Resource private SpringTemplateEngine thymeleaf; @Resource + private AttachmentClient attachmentClient; + @Resource private StringRedisTemplate stringRedisTemplate; private final String CBBANK_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2019/08/05/1564972204689_uwZvpTBjtLUMcN8c540xcZvux1Rd3O.pdf"; + private final String IMG_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2019/08/16/1565936989217_WDSAGRKhBHTD6s6HGcZPeirOXCyzbn.pdf"; @Resource private SmsSender smsSender; @@ -2201,6 +2207,97 @@ public class RetailAppServiceImp implements RetailAppService { exportAggregateFile(client, httpResponse); } + @Override + public void getSourceAggregateFile(JSONObject device, HttpServletResponse httpResponse) { + String clientType = device.getString("client_type"); + deviceSupport.findRegister(clientType); + JSONObject client = clientManager.getClientInfo(device.getIntValue("client_id")); + client.put("now", DateFormatUtils.format(new Date(), "yyyy-MM-dd")); + String clientName = ""; + clientName = client.getString("business_name"); + if (StringUtils.isNotBlank(client.getString("acn"))) { + clientName += "(" + client.getString("acn") + ")"; + client.put("client_acn", client.getString("acn")); + } + client.put("client_name", clientName); + client.put("bd_name", client.getString("bd_user_name")); + client.put("client_phone", client.getString("contact_phone")); + client.put("client_email", client.getString("contact_email")); + client.put("client_address", (client.getString("address") + "\n" + client.getString("suburb") + ' ' + client.getString("state") + ' ' + client.getString("postcode"))); + JSONObject rate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "CB_BankPay"); + if (rate != null) { + client.put("client_rate", (rate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN).toPlainString() + "%")); + int cleanDays = rate.getIntValue("clean_days"); + client.put("clean_days", ("T+" + cleanDays)); + client.put("days", cleanDays); + } + JSONObject bankAccount = clientManager.getBankAccountByClientId(client.getIntValue("client_id")); + if (bankAccount != null) { + client.put("bank_name", bankAccount.getString("bank")); + client.put("bank_country", bankAccount.getString("city")); + client.put("bank_account_number", bankAccount.getString("account_no")); + client.put("bank_account_name", bankAccount.getString("account_name")); + } + exportAggregateFile(client, httpResponse); + } + + @Override + public JSONObject getClientAggregateFile(JSONObject device, MultipartFile file) throws IOException{ + String clientType = device.getString("client_type"); + deviceSupport.findRegister(clientType); + JSONObject client = clientManager.getClientInfo(device.getIntValue("client_id")); + client.put("now", DateFormatUtils.format(new Date(), "yyyy-MM-dd")); + String clientName = ""; + clientName = client.getString("business_name"); + if (StringUtils.isNotBlank(client.getString("acn"))) { + clientName += "(" + client.getString("acn") + ")"; + client.put("client_acn", client.getString("acn")); + } + client.put("client_name", clientName); + client.put("bd_name", client.getString("bd_user_name")); + client.put("client_phone", client.getString("contact_phone")); + client.put("client_email", client.getString("contact_email")); + client.put("client_address", (client.getString("address") + "\n" + client.getString("suburb") + ' ' + client.getString("state") + ' ' + client.getString("postcode"))); + JSONObject rate = merchantInfoProvider.clientCurrentRate(client.getIntValue("client_id"), new Date(), "CB_BankPay"); + if (rate != null) { + client.put("client_rate", (rate.getBigDecimal("rate_value").setScale(2, RoundingMode.DOWN).toPlainString() + "%")); + int cleanDays = rate.getIntValue("clean_days"); + client.put("clean_days", ("T+" + cleanDays)); + client.put("days", cleanDays); + } + JSONObject bankAccount = clientManager.getBankAccountByClientId(client.getIntValue("client_id")); + if (bankAccount != null) { + client.put("bank_name", bankAccount.getString("bank")); + client.put("bank_country", bankAccount.getString("city")); + client.put("bank_account_number", bankAccount.getString("account_no")); + client.put("bank_account_name", bankAccount.getString("account_name")); + } + BufferedImage img = ImageIO.read(file.getInputStream()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImageIO.write(img, "png", out); + client.put("img","data:image/png;base64," + Base64.encodeBase64String(out.toByteArray())); + return exportImgAggregateFile(client); + } + + private JSONObject exportImgAggregateFile(JSONObject client) throws IOException{ + JSONObject result = new JSONObject(); + InputStream stream = null; + try { + PdfUtils pdu = new PdfUtils(); + pdu.setTemplatePdfPath(IMG_AGGREGATE_FILE); + pdu.setPdfTemplate(client); + File file = new File(client.getString("client_moniker") + "_agreement.pdf"); + ByteArrayOutputStream bos = pdu.templetPdfBos(file); + stream = new ByteArrayInputStream(bos.toByteArray()); + result = attachmentClient.uploadFile(stream, client.getString("client_moniker") + "_agreement.pdf", false); + } catch (Exception e) { + logger.error("合同制作出现问题:", e); + } finally { + stream.close(); + } + return result; + } + private void exportAggregateFile(JSONObject client, HttpServletResponse httpResponse) { httpResponse.setContentType("application/pdf"); httpResponse.setHeader("content-disposition", "attachment;filename=" + client.getString("client_moniker") + "_AGREEMENT_" + new Date() + ".pdf"); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index 011bad9b0..6f12e7ad5 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; +import java.io.IOException; import java.math.BigDecimal; import java.text.ParseException; import java.util.Arrays; @@ -719,8 +720,30 @@ public class RetailAppController { } @RequestMapping(value = "/cbbank_pay/aggregate_file", method = RequestMethod.GET) - public void getCBBankAggragateFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,HttpServletResponse httpResponse) { + public void getCBBankAggregateFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,HttpServletResponse httpResponse) { retailAppService.getCBBankAggregateFile(device, httpResponse); } + /** + * 原合同文件 + * @param device + * @param httpResponse + */ + @RequestMapping(value = "/client/aggregate_file", method = RequestMethod.GET) + public void getSourceAggregateFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,HttpServletResponse httpResponse) { + //todo 后面需替换成正式合同 + retailAppService.getSourceAggregateFile(device, httpResponse); + } + + /** + * 合成后的合同文件 + * @param device + * @param file 签名的url图片 + */ + @RequestMapping(value = "/client/aggregate_file", method = RequestMethod.POST) + public JSONObject getClientAggregateFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestParam MultipartFile file) throws IOException { + //todo 后面需替换成正式合同 + return retailAppService.getClientAggregateFile(device, file); + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java index 94df28bfd..128f45763 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java @@ -632,7 +632,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati List clientFileUrl = clientFiles.stream() .filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status")==1 || fileJson.getIntValue("status")==2))) .sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date"))) - .map(groupBd -> groupBd.getString("file_value")) + .map(json -> json.getString("file_value")) .collect(Collectors.toList()); if (clientFileUrl!=null && clientFileUrl.size()>0) { JSONObject fileJson = new JSONObject(); @@ -644,7 +644,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati List clientBackToFileUrl = clientFiles.stream() .filter(fileJson -> (fileKey.equals(fileJson.getString("file_name")) && (fileJson.getIntValue("status")==0 || fileJson.getIntValue("status")==2))) .sorted((log1, log2) -> log2.getDate("last_update_date").compareTo(log1.getDate("last_update_date"))) - .map(groupBd -> groupBd.getString("file_value")) + .map(json -> json.getString("file_value")) .collect(Collectors.toList()); JSONObject fileJson = new JSONObject(); fileJson.put("key", putKeys[i]);