diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientApply.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientApply.java index 68569df3b..76be422f8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientApply.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/ClientApply.java @@ -4,6 +4,7 @@ import au.com.royalpay.payment.manage.merchants.beans.ClientApplyInfo; import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery; import com.alibaba.fastjson.JSONObject; +import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -40,4 +41,6 @@ public interface ClientApply { JSONObject findOrgByBDId(String bd_id); void notifyBD(String client_apply_id); + + void exportApplyPartnerList(JSONObject manager, HttpServletResponse response) throws Exception; } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientApplyImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientApplyImpl.java index 99b8288a4..2d9c07f5d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientApplyImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientApplyImpl.java @@ -27,6 +27,12 @@ import com.github.miemiedev.mybatis.paginator.domain.PageList; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFFont; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; @@ -36,11 +42,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import java.io.OutputStream; +import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; /** * Created by yishuqian on 18/10/2016. @@ -158,44 +167,44 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw JSONObject partner = info.insertObject(); - if (info.getClientMoniker()== null || info.getClientMoniker().isEmpty()){ + if (info.getClientMoniker() == null || info.getClientMoniker().isEmpty()) { throw new NotFoundException("clientMoniker can not be null"); } - if (info.getShortName() == null || info.getShortName().isEmpty()){ - partner.put("short_name","0"); + if (info.getShortName() == null || info.getShortName().isEmpty()) { + partner.put("short_name", "0"); } - if (!partner.containsKey("sector")){ - partner.put("sector","0"); + if (!partner.containsKey("sector")) { + partner.put("sector", "0"); } - if (!partner.containsKey("industry")){ - partner.put("industry","0"); + if (!partner.containsKey("industry")) { + partner.put("industry", "0"); } - if (info.getAddress() == null || info.getAddress().isEmpty()){ - partner.put("address","0"); + if (info.getAddress() == null || info.getAddress().isEmpty()) { + partner.put("address", "0"); } - if (info.getSuburb() == null || info.getSuburb().isEmpty()){ - partner.put("suburb","0"); + if (info.getSuburb() == null || info.getSuburb().isEmpty()) { + partner.put("suburb", "0"); } - if (info.getPostcode() == null || info.getPostcode().isEmpty()){ - partner.put("postcode","0"); + if (info.getPostcode() == null || info.getPostcode().isEmpty()) { + partner.put("postcode", "0"); } - if (info.getState() == null || info.getState().isEmpty()){ - partner.put("state","0"); + if (info.getState() == null || info.getState().isEmpty()) { + partner.put("state", "0"); } - if (info.getCountry() == null || info.getCountry().isEmpty()){ - partner.put("county","AUS"); + if (info.getCountry() == null || info.getCountry().isEmpty()) { + partner.put("county", "AUS"); } - if (info.getCompanyPhone()== null || info.getCompanyPhone().isEmpty()){ - partner.put("company_phone","0"); + if (info.getCompanyPhone() == null || info.getCompanyPhone().isEmpty()) { + partner.put("company_phone", "0"); } - if (info.getContactPerson() == null || info.getContactPerson().isEmpty()){ - partner.put("contact_person","0"); + if (info.getContactPerson() == null || info.getContactPerson().isEmpty()) { + partner.put("contact_person", "0"); } - if (info.getContactEmail() == null || info.getContactEmail().isEmpty()){ - partner.put("contact_email","0"); + if (info.getContactEmail() == null || info.getContactEmail().isEmpty()) { + partner.put("contact_email", "0"); } - if (partner.containsKey("remark")){ + if (partner.containsKey("remark")) { partner.remove("remark"); } @@ -212,9 +221,9 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw if (clientMapper.findClientByMoniker(info.getClientMoniker()) != null) { throw new BadRequestException("error.partner.valid.dumplicate_client_moniker"); } - partner.put("source",2);//自主申请 - partner.put("country","AUS");//自主申请 - partner.put("ali_sub_merchant_id",info.getClientMoniker()); + partner.put("source", 2);//自主申请 + partner.put("country", "AUS");//自主申请 + partner.put("ali_sub_merchant_id", info.getClientMoniker()); clientMapper.save(partner); JSONObject clientConfig = new JSONObject(); @@ -222,8 +231,8 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw clientConfig.put("client_pay_type", apply.getString("client_pay_type")); clientConfig.put("client_pay_desc", apply.getString("client_pay_desc")); } - clientConfig.put("client_id",partner.getIntValue("client_id")); - clientConfig.put("client_moniker",info.getClientMoniker()); + clientConfig.put("client_id", partner.getIntValue("client_id")); + clientConfig.put("client_moniker", info.getClientMoniker()); clientConfigService.save(clientConfig); JSONObject client_bd = new JSONObject(); @@ -251,12 +260,12 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw Assert.notNull(apply); - if (info.getClientMoniker()== null || info.getClientMoniker().isEmpty()){ + if (info.getClientMoniker() == null || info.getClientMoniker().isEmpty()) { throw new NotFoundException("clientMoniker can not be null"); } JSONObject client = clientMapper.findClientByMoniker(info.getClientMoniker()); Assert.notNull(client); - clientModifySupport.processClientModify(new SourceModify(manager,client.getString("client_moniker"),2)); + clientModifySupport.processClientModify(new SourceModify(manager, client.getString("client_moniker"), 2)); apply.put("client_id", client.getIntValue("client_id")); apply.put("client_moniker", info.getClientMoniker()); apply.put("apply_approve_result", 2); @@ -269,8 +278,8 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw JSONObject account = clientAccountMapper.findById(accountId); Assert.notNull(account); JSONObject updateObj = new JSONObject(); - updateObj.put("account_id",accountId); - updateObj.put("remark",remark); + updateObj.put("account_id", accountId); + updateObj.put("remark", remark); clientAccountMapper.update(updateObj); } @@ -292,7 +301,7 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw @Override public void notifyBD(String client_apply_id) { JSONObject client = clientApplyMapper.findClientApplicationById(client_apply_id); - publisher.publishEvent(new ClientApplyNotifyBDEvent(this,client)); + publisher.publishEvent(new ClientApplyNotifyBDEvent(this, client)); } @@ -300,4 +309,109 @@ public class ClientApplyImpl implements ClientApply, ApplicationEventPublisherAw public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { this.publisher = applicationEventPublisher; } + + @Override + public void exportApplyPartnerList(JSONObject manager, HttpServletResponse resp) throws Exception{ + PartnerQuery partnerQuery = new PartnerQuery(); + JSONObject params = partnerQuery.toJsonParam(); + if (ManagerRole.BD_USER.hasRole(manager.getIntValue("role"))) { + params.put("bd_user", manager.getString("manager_id")); + } + OutputStream ous = null; + resp.setContentType("application/octet-stream;"); + resp.addHeader("Content-Disposition", "attachment; filename=" + "apply_partner_list.xls"); + ous = resp.getOutputStream(); + HSSFWorkbook wb = new HSSFWorkbook(); + Cell cell = null; + HSSFFont font = wb.createFont(); + font.setBoldweight(Font.BOLDWEIGHT_BOLD); + font.setFontHeightInPoints((short) 10); + CellStyle titleStyle = wb.createCellStyle(); + titleStyle.setFont(font); + HSSFCellStyle style = wb.createCellStyle(); + style.setFillForegroundColor(HSSFColor.RED.index); + style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + PageList partners = clientApplyMapper.listPartnerApplications(params, new PageBounds(Order.formString("apply_approve_result.asc,create_time.desc"))); + Sheet sheet = wb.createSheet("apply_partner_list"); + sheet.setDefaultColumnWidth(20); + int rowNum = 0; + Row row = sheet.createRow(rowNum); + String[] CommissionTitle = {"Application Time", "Client Moniker", "Company Name", "Short Name", "Contact Person" , "Contact Phone", "Contact Email", "Country","State", "Suburb", "Address", "Company Phone", "Company Website", "Progress", "BD", "Apply Approve Result", "Source"}; + for (int i = 0; i < CommissionTitle.length; i++) { + cell = row.createCell(i, Cell.CELL_TYPE_STRING); + cell.setCellStyle(titleStyle); + cell.setCellValue(CommissionTitle[i]); + } + for (JSONObject partner : partners) { + row = sheet.createRow(++rowNum); + String type = ""; + row.createCell(0, Cell.CELL_TYPE_STRING).setCellValue(DateFormatUtils.format(partner.getDate("create_time"),"yyyy-MM-dd HH:mm:ss")); + row.createCell(1, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("client_moniker")); + row.createCell(2, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("company_name")); + row.createCell(3, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("short_name")); + row.createCell(4, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("contact_person")); + row.createCell(5, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("contact_phone")); + row.createCell(6, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("contact_email")); + row.createCell(7, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("country")); + row.createCell(8, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("state")); + row.createCell(9, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("suburb")); + row.createCell(10, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("address")); + row.createCell(11, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("company_phone")); + row.createCell(12, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("company_website")); + row.createCell(13, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("remark")); + row.createCell(14, Cell.CELL_TYPE_STRING).setCellValue(partner.getString("bd_user_name")); + row.createCell(15, Cell.CELL_TYPE_STRING).setCellValue(getApplyResultStatus(partner.getIntValue("apply_approve_result"))); + row.createCell(16, Cell.CELL_TYPE_STRING).setCellValue(getSource(partner.getIntValue("apply_approve_result"))); + } + wb.write(ous); + ous.flush(); + } + + public String getApplyResultStatus(int result) { + String status = ""; + switch (result) { + case 0: + status = "待审核"; + break; + case 1: + status = "已提交BD"; + break; + case 2: + status = "BD已通过"; + break; + case 3: + status = "初审拒绝"; + break; + case 4: + status = "BD提交后不通过"; + break; + default: + status = "待审核"; + break; + } + return status; + } + + public String getSource(int result) { + String status = ""; + switch (result) { + case 0: + status = "PC"; + break; + case 1: + status = "公众号菜单"; + break; + case 2: + status = "公众号推送"; + break; + case 3: + status = "小程序申请"; + break; + default: + status = "PC"; + break; + } + return status; + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerApplyController.java b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerApplyController.java index ea9f41539..bf1f153e8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerApplyController.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerApplyController.java @@ -164,5 +164,9 @@ public class PartnerApplyController { return clientApply.listBDByOrg(org_id); } - + @RequestMapping(value = "/export_xls", method = RequestMethod.GET) + public void exportApplyPartnerList(HttpServletResponse httpResponse, + @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) throws Exception{ + clientApply.exportApplyPartnerList(manager, httpResponse); + } } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml index 32ef0c8cf..96ee0b611 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.xml @@ -689,8 +689,8 @@ COUNT(DISTINCT o.customer_id) AS customers, o.channel AS channel, ifnull(SUM(if(t.transaction_type = 'Credit', t.clearing_amount, 0)), 0) AS total, - ifnull(SUM(if(t.refund_id>0, t.clearing_amount, 0)), 0) AS refund_amount, - SUM(if(t.refund_id>0, 1, 0)) AS refund_orders, + ifnull(SUM(if(t.transaction_type = 'Debit', t.clearing_amount, 0)), 0) AS refund_amount, + SUM(if(t.transaction_type = 'Debit', 1, 0)) AS refund_orders, round(SUM(if(t.transaction_type='Credit',t.clearing_amount,0))/COUNT(DISTINCT o.customer_id),2) single_amount FROM pmt_transactions t INNER JOIN pmt_orders o ON o.order_id = t.order_id diff --git a/src/main/ui/static/payment/partner/templates/partner_application.html b/src/main/ui/static/payment/partner/templates/partner_application.html index 5541bd35e..63ac128bd 100644 --- a/src/main/ui/static/payment/partner/templates/partner_application.html +++ b/src/main/ui/static/payment/partner/templates/partner_application.html @@ -14,6 +14,11 @@ +
+ 自助申请商户导出 +