@ -4,7 +4,11 @@ import au.com.royalpay.payment.core.PaymentApi;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException ;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException ;
import au.com.royalpay.payment.core.tasksupport.SettlementSupport ;
import au.com.royalpay.payment.core.tasksupport.SettlementSupport ;
import au.com.royalpay.payment.manage.management.clearing.core.CleanService ;
import au.com.royalpay.payment.manage.management.clearing.core.CleanService ;
import au.com.royalpay.payment.manage.mappers.log.* ;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailAnalysisMapper ;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper ;
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper ;
import au.com.royalpay.payment.manage.mappers.log.LogSettleMailMapper ;
import au.com.royalpay.payment.manage.mappers.log.ValidationLogMapper ;
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper ;
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper ;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper ;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper ;
import au.com.royalpay.payment.manage.mappers.system.CalendarMapper ;
import au.com.royalpay.payment.manage.mappers.system.CalendarMapper ;
@ -25,6 +29,7 @@ import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage ;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage ;
import au.com.royalpay.payment.tools.defines.TradeType ;
import au.com.royalpay.payment.tools.defines.TradeType ;
import au.com.royalpay.payment.tools.env.PlatformEnvironment ;
import au.com.royalpay.payment.tools.env.PlatformEnvironment ;
import au.com.royalpay.payment.tools.env.SysConfigManager ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException ;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException ;
import au.com.royalpay.payment.tools.exceptions.NotFoundException ;
import au.com.royalpay.payment.tools.exceptions.NotFoundException ;
@ -33,12 +38,14 @@ import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.tasksupport.TaskFinishNotifyEvent ;
import au.com.royalpay.payment.tools.tasksupport.TaskFinishNotifyEvent ;
import au.com.royalpay.payment.tools.utils.PageListUtils ;
import au.com.royalpay.payment.tools.utils.PageListUtils ;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils ;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.JSONObject ;
import com.github.miemiedev.mybatis.paginator.domain.Order ;
import com.github.miemiedev.mybatis.paginator.domain.Order ;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds ;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds ;
import com.github.miemiedev.mybatis.paginator.domain.PageList ;
import com.github.miemiedev.mybatis.paginator.domain.PageList ;
import org.apache.commons.codec.binary.Base64 ;
import org.apache.commons.codec.binary.Base64 ;
import org.apache.commons.csv.CSVFormat ;
import org.apache.commons.csv.CSVFormat ;
import org.apache.commons.csv.CSVPrinter ;
import org.apache.commons.csv.CSVPrinter ;
@ -47,7 +54,12 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
import org.apache.commons.lang3.time.DateUtils ;
import org.apache.commons.lang3.time.DateUtils ;
import org.apache.poi.ss.usermodel.* ;
import org.apache.poi.ss.usermodel.Cell ;
import org.apache.poi.ss.usermodel.CellStyle ;
import org.apache.poi.ss.usermodel.Font ;
import org.apache.poi.ss.usermodel.Row ;
import org.apache.poi.ss.usermodel.Sheet ;
import org.apache.poi.ss.usermodel.Workbook ;
import org.apache.poi.xssf.usermodel.XSSFWorkbook ;
import org.apache.poi.xssf.usermodel.XSSFWorkbook ;
import org.joda.time.DateTime ;
import org.joda.time.DateTime ;
import org.joda.time.Days ;
import org.joda.time.Days ;
@ -65,20 +77,37 @@ import org.springframework.util.CollectionUtils;
import org.thymeleaf.context.Context ;
import org.thymeleaf.context.Context ;
import org.thymeleaf.spring4.SpringTemplateEngine ;
import org.thymeleaf.spring4.SpringTemplateEngine ;
import javax.annotation.Resource ;
import java.io.BufferedWriter ;
import javax.servlet.http.HttpServletResponse ;
import java.io.ByteArrayOutputStream ;
import java.io.* ;
import java.io.IOException ;
import java.io.OutputStream ;
import java.io.OutputStreamWriter ;
import java.io.PrintWriter ;
import java.io.Writer ;
import java.math.BigDecimal ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.math.RoundingMode ;
import java.net.URISyntaxException ;
import java.net.URISyntaxException ;
import java.text.DecimalFormat ;
import java.text.DecimalFormat ;
import java.text.NumberFormat ;
import java.text.NumberFormat ;
import java.util.* ;
import java.util.ArrayList ;
import java.util.Calendar ;
import java.util.Currency ;
import java.util.Date ;
import java.util.GregorianCalendar ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Locale ;
import java.util.Map ;
import java.util.Objects ;
import java.util.TreeMap ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.TimeUnit ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import java.util.zip.ZipEntry ;
import java.util.zip.ZipEntry ;
import java.util.zip.ZipOutputStream ;
import java.util.zip.ZipOutputStream ;
import javax.annotation.Resource ;
import javax.servlet.http.HttpServletResponse ;
import static au.com.royalpay.payment.manage.permission.utils.OrgCheckUtils.checkOrgPermission ;
import static au.com.royalpay.payment.manage.permission.utils.OrgCheckUtils.checkOrgPermission ;
/ * *
/ * *
@ -125,6 +154,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
private SpringTemplateEngine thymeleaf ;
private SpringTemplateEngine thymeleaf ;
@Resource
@Resource
private ClientConfigService clientConfigService ;
private ClientConfigService clientConfigService ;
@Resource
private SysConfigManager sysConfigManager ;
@Value ( "${app.settlement.email-to}" )
@Value ( "${app.settlement.email-to}" )
private String settlementEmailTo ;
private String settlementEmailTo ;
@ -248,69 +279,6 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
return total ;
return total ;
}
}
@Override
public JSONObject getClearDetailsLimit20 ( Date settleDate , String managerId ) {
List < JSONObject > logs = clearingLogMapper . findByDate ( settleDate ) ;
if ( logs . isEmpty ( ) ) {
throw new NotFoundException ( ) ;
}
JSONObject total = new JSONObject ( ) ;
total . put ( "settle_date" , settleDate ) ;
total . put ( "total_credit" , 0 ) ;
total . put ( "total_debit" , 0 ) ;
total . put ( "gross_amount" , 0 ) ;
total . put ( "wechat_charge" , 0 ) ;
total . put ( "royalpay_charge" , 0 ) ;
total . put ( "net_amount" , 0 ) ;
total . put ( "total_charge" , 0 ) ;
total . put ( "tax_amount" , 0 ) ;
total . put ( "charge_cashback" , 0 ) ;
List < JSONObject > details = new ArrayList < > ( ) ;
List < JSONObject > totalList = new ArrayList < > ( ) ;
int clearingId = 0 ;
for ( JSONObject log : logs ) {
addBigDecimal ( total , log , "total_credit" ) ;
addBigDecimal ( total , log , "total_debit" ) ;
addBigDecimal ( total , log , "gross_amount" ) ;
addBigDecimal ( total , log , "wechat_charge" ) ;
addBigDecimal ( total , log , "royalpay_charge" ) ;
addBigDecimal ( total , log , "net_amount" ) ;
addBigDecimal ( total , log , "total_charge" ) ;
addBigDecimal ( total , log , "charge_cashback" ) ;
addBigDecimal ( total , log , "tax_amount" ) ;
clearingId = log . getIntValue ( "clearing_id" ) ;
List < JSONObject > logDetails = clearingDetailMapper . listReportsOfSettlementLimit20 ( clearingId ) ;
details . addAll ( logDetails ) ;
List < String > banks = logDetails . stream ( ) . map ( detail - > detail . getString ( "settle_bank" ) ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
List < JSONObject > bankStatistics = banks . stream ( ) . map ( bank - > {
JSONObject data = new JSONObject ( ) ;
data . put ( "bank" , bank ) ;
data . put ( "total_settle" , logDetails . stream ( )
. filter ( detail - > bank . equals ( detail . getString ( "settle_bank" ) ) )
. map ( detail - > detail . getBigDecimal ( "clearing_amount" ) )
. reduce ( BigDecimal : : add )
) ;
data . put ( "clients" , logDetails . stream ( )
. filter ( detail - > bank . equals ( detail . getString ( "settle_bank" ) ) )
. count ( ) ) ;
return data ;
} ) . collect ( Collectors . toList ( ) ) ;
//bankStatistics.put()
log . put ( "bank_statistics" , bankStatistics ) ;
log . put ( "editable" , DateUtils . isSameDay ( log . getDate ( "settle_date" ) , new Date ( ) ) & & log . getBooleanValue ( "editable" ) ) ;
log . put ( "channel_analysis" , clearingDetailAnalysisMapper . analysisChannelReport ( clearingId ) ) ;
}
totalList = clearingDetailMapper . listRepostTotal ( clearingId ) ;
total . put ( "totalList" , totalList ) ;
total . put ( "logs" , logs ) ;
total . put ( "details" , details ) ;
List < JSONObject > channels = clearingDetailAnalysisMapper . analysisChannelReportDaily ( settleDate ) ;
total . put ( "channel_analysis" , channels ) ;
return total ;
}
private void addBigDecimal ( JSONObject total , JSONObject log , String key ) {
private void addBigDecimal ( JSONObject total , JSONObject log , String key ) {
total . put ( key , total . getBigDecimal ( key ) . add ( log . getBigDecimal ( key ) ) ) ;
total . put ( key , total . getBigDecimal ( key ) . add ( log . getBigDecimal ( key ) ) ) ;
}
}
@ -1004,11 +972,6 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
String title = "Royalpay Settlement File " + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
String title = "Royalpay Settlement File " + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
JSONObject model = new JSONObject ( ) ;
JSONObject model = new JSONObject ( ) ;
model . put ( "date" , DateFormatUtils . format ( date , "dd-MM-yyyy" ) ) ;
model . put ( "date" , DateFormatUtils . format ( date , "dd-MM-yyyy" ) ) ;
// todo themeleaf
// final String content = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
// "mail/settlement_mail.vm", "utf-8", model);
String fileName1 = "Merchant_Settlement_Info_xlsx_" + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
String fileName1 = "Merchant_Settlement_Info_xlsx_" + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
List < JSONObject > attachList = new ArrayList < > ( ) ;
List < JSONObject > attachList = new ArrayList < > ( ) ;
JSONObject attach1 = new JSONObject ( ) ;
JSONObject attach1 = new JSONObject ( ) ;
@ -1052,9 +1015,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
// 测试用地址
// 测试用地址
// String mailId = mailService.sendEmail(title, "164851225@qq.com", "1029811920@qq.com", content,
// String mailId = mailService.sendEmail(title, "164851225@qq.com", "1029811920@qq.com", content,
// attachList);
// attachList);
String mailId = mailService . sendEmail ( title , "diana.baldi@flexewallet.com,steven.stamboultgis@novatti.com,fazal.cader@flexewallet.com" ,
JSONObject config = sysConfigManager . getSysConfig ( ) ;
"locky@royalpay.com.au,leo.huang@royalpay.com.au,eason.qian@royalpay.com.au,astro.dai@royalpay.com.au,settlement@royalpay.com.au,settlements@flexewallet.com" ,
String mailId = mailService . sendEmail ( title , config . getString ( "settle_mail_to" ) , config . getString ( "settle_mail_cc" ) , content , attachList ) ;
content , attachList ) ;
if ( settleMail = = null ) {
if ( settleMail = = null ) {
JSONObject settleMailRecord = new JSONObject ( ) ;
JSONObject settleMailRecord = new JSONObject ( ) ;