add app 获取源合同文件、合成签名后文件url接口

master
luoyang 5 years ago
parent 4dc79f41dd
commit 5822cbc520

@ -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;
}

@ -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");

@ -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);
}
}

@ -632,7 +632,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
List<String> 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<String> 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]);

Loading…
Cancel
Save