@ -64,7 +64,6 @@ import org.springframework.format.number.CurrencyStyleFormatter;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.Assert ;
import org.springframework.util.CollectionUtils ;
import org.thymeleaf.context.Context ;
import org.thymeleaf.spring5.SpringTemplateEngine ;
@ -256,6 +255,12 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
return data ;
} ) . collect ( Collectors . toList ( ) ) ;
log . put ( "bank_statistics" , bankStatistics ) ;
if ( StringUtils . isNotEmpty ( log . getString ( "plan_detail" ) ) ) {
try {
log . put ( "plan_detail" , JSON . parseObject ( log . getString ( "plan_detail" ) ) ) ;
} catch ( JSONException ignore ) {
}
}
log . put ( "editable" , DateUtils . isSameDay ( log . getDate ( "settle_date" ) , new Date ( ) ) & & log . getBooleanValue ( "editable" ) ) ;
log . put ( "channel_analysis" , clearingDetailAnalysisMapper . analysisChannelReport ( clearingId ) ) ;
}
@ -390,9 +395,11 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public List < JSONObject > getXlsx ( Date dt , String bank ) throws IOException {
public List < JSONObject > getXlsx ( Date dt , String bank , List < String > clearIds ) throws IOException {
List < JSONObject > logs = clearingLogMapper . findByDate ( dt ) ;
logs = logs . stream ( ) . filter ( log - > log . getBooleanValue ( "editable" ) ) . collect ( Collectors . toList ( ) ) ;
logs = logs . stream ( ) . filter ( log - > log . getBooleanValue ( "editable" ) )
. filter ( log - > clearIds . isEmpty ( ) | | clearIds . contains ( log . getString ( "clearing_id" ) ) )
. collect ( Collectors . toList ( ) ) ;
if ( logs . isEmpty ( ) ) {
throw new NotFoundException ( ) ;
}
@ -486,9 +493,11 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public List < ABAFile > getAba ( Date dt , String bank ) {
public List < ABAFile > getAba ( Date dt , String bank , List < String > clearIds ) {
List < JSONObject > logs = clearingLogMapper . findByDate ( dt ) ;
logs = logs . stream ( ) . filter ( log - > log . getBooleanValue ( "editable" ) ) . collect ( Collectors . toList ( ) ) ;
logs = logs . stream ( ) . filter ( log - > log . getBooleanValue ( "editable" ) )
. filter ( log - > clearIds . isEmpty ( ) | | clearIds . contains ( log . getString ( "clearing_id" ) ) )
. collect ( Collectors . toList ( ) ) ;
if ( logs . isEmpty ( ) ) {
throw new NotFoundException ( ) ;
}
@ -496,11 +505,19 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
for ( JSONObject log : logs ) {
List < JSONObject > details = clearingDetailMapper . listReportsOfSettlement ( log . getIntValue ( "clearing_id" ) ) ;
details = mergeBatchSettleClients ( details ) ;
files . addAll ( generateSettleAbaFiles ( dt , details , log . getDate ( "operate_time" ) ) ) ;
String remark = extractSettleRemark ( log ) ;
files . addAll ( generateSettleAbaFiles ( dt , details , log . getDate ( "operate_time" ) , remark ) ) ;
}
return files . stream ( ) . filter ( file - > bank . equals ( file . bank ( ) ) ) . collect ( Collectors . toList ( ) ) ;
}
public String extractSettleRemark ( JSONObject log ) {
return Optional . ofNullable ( StringUtils . defaultIfEmpty ( log . getString ( "plan_detail" ) , null ) )
. map ( JSON : : parseObject )
. map ( plan - > StringUtils . defaultIfEmpty ( plan . getString ( "remark" ) , plan . getString ( "plan_id" ) ) )
. orElse ( "" ) ;
}
private byte [ ] generateSettleXlsxFile ( Date dt , List < JSONObject > settlements , String bank ) throws IOException {
try ( Workbook wb = new XSSFWorkbook ( ) ) {
Sheet sheet = wb . createSheet ( "Merchant_Settlement_Info_" + DateFormatUtils . format ( dt , "yyyyMMdd" ) ) ;
@ -536,7 +553,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
for ( JSONObject log : logs ) {
List < JSONObject > details = clearingDetailMapper . listReportsOfSettlement ( log . getIntValue ( "clearing_id" ) ) ;
details = mergeBatchSettleClients ( details ) ;
files . addAll ( generateSettleAbaFiles ( dt , details , log . getDate ( "operate_time" ) )) ;
files . addAll ( generateSettleAbaFiles ( dt , details , log . getDate ( "operate_time" ) , extractSettleRemark ( log ) )) ;
}
OutputStream ous = resp . getOutputStream ( ) ;
if ( files . size ( ) = = 1 ) {
@ -580,7 +597,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
resp . addHeader ( "Content-Disposition" , "attachment; filename=" + zipName ) ;
OutputStream ous = resp . getOutputStream ( ) ;
List < ABAFile > abaFiles = generateSettleAbaFiles ( settleDate , details , opTime );
List < ABAFile > abaFiles = generateSettleAbaFiles ( settleDate , details , opTime , extractSettleRemark ( clearing ) );
try ( ZipOutputStream zos = new ZipOutputStream ( ous ) ) {
for ( ABAFile aba : abaFiles ) {
zos . putNextEntry ( new ZipEntry ( aba . filename ( ) ) ) ;
@ -591,9 +608,12 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
private List < ABAFile > generateSettleAbaFiles ( Date dt , List < JSONObject > settlements , Date operateTime ) {
private List < ABAFile > generateSettleAbaFiles ( Date dt , List < JSONObject > settlements , Date operateTime , String remark ) {
List < String > banks = settlements . stream ( ) . map ( detail - > detail . getString ( "settle_bank" ) ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
return banks . stream ( ) . map ( bank - > generateSettleAbaFile ( bank , dt , settlements ) ) . peek ( file - > file . setOperateTime ( operateTime ) ) . collect ( Collectors . toList ( ) ) ;
return banks . stream ( ) . map ( bank - > generateSettleAbaFile ( bank , dt , settlements ) )
. peek ( file - > file . setOperateTime ( operateTime ) )
. peek ( file - > file . setRemark ( remark ) )
. collect ( Collectors . toList ( ) ) ;
}
private ABAFile generateSettleAbaFile ( String bank , Date dt , List < JSONObject > settlements ) {
@ -1092,28 +1112,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public JSONObject sendSettlementMail ( Date date , String checkCode ) {
public JSONObject sendSettlementMail ( Date date , List< String > clearIds ) {
JSONObject result = new JSONObject ( ) ;
String redisCode = stringRedisTemplate . boundValueOps ( reidsCheckCodeKey ) . get ( ) ;
if ( StringUtils . isEmpty ( redisCode ) ) {
result . put ( "result" , 1 ) ;
result . put ( "msg" , "The verification code has expired , Please send the verification code again" ) ;
return result ;
}
if ( ! redisCode . equals ( checkCode ) ) {
result . put ( "result" , 1 ) ;
result . put ( "msg" , "The verification code is incorrect" ) ;
return result ;
}
JSONObject settleMail = logSettleMailMapper . findByDate ( date ) ;
if ( settleMail ! = null ) {
List < JSONObject > emailStatus = mailService . checkEmailStatus ( settleMail . getString ( "email_id" ) ) ;
if ( ! CollectionUtils . isEmpty ( emailStatus ) & & emailStatus . get ( 0 ) . getIntValue ( "status" ) = = 1 & & settleMail . getIntValue ( "mail_status" ) = = 1 ) {
result . put ( "result" , 0 ) ;
result . put ( "msg" , "Excel has been sent" ) ;
return result ;
}
}
try {
String title = "Royalpay Settlement File " + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
JSONObject model = new JSONObject ( ) ;
@ -1121,7 +1121,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
String fileName1 = "Merchant_Settlement_Info_xlsx_" + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
List < JSONObject > attachList = new ArrayList < > ( ) ;
JSONObject attach1 = new JSONObject ( ) ;
List < JSONObject > xlsxFileList = getXlsx ( date , "CBA" );
List < JSONObject > xlsxFileList = getXlsx ( date , "CBA" , clearIds );
if ( xlsxFileList . size ( ) > 1 ) {
fileName1 + = ".zip" ;
attach1 . put ( "content" , Base64 . encodeBase64String ( getZipByteArr ( xlsxFileList ) ) ) ;
@ -1133,7 +1133,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
attachList . add ( attach1 ) ;
JSONObject attach2 = new JSONObject ( ) ;
List < ABAFile > abaFileList = getAba ( date , "CBA" );
List < ABAFile > abaFileList = getAba ( date , "CBA" , clearIds );
String fileName2 = "Merchant_Settlement_Info_aba_" + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
if ( abaFileList . size ( ) > 1 ) {
fileName2 + = ".zip" ;
@ -1157,6 +1157,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
Context ctx = new Context ( ) ;
ctx . setVariable ( "date" , DateFormatUtils . format ( date , "dd-MM-yyyy" ) ) ;
ctx . setVariable ( "abaFiles" , abaFileList ) ;
ctx . setVariable ( "totalAmount" , abaFileList . stream ( ) . map ( ABAFile : : getTotalSettleAmount ) . reduce ( BigDecimal : : add ) ) ;
final String content = thymeleaf . process ( "mail/settlement_mail" , ctx ) ;
// 测试用地址
// String mailId = mailService.sendEmail(title, "164851225@qq.com", "1029811920@qq.com", content,
@ -1164,35 +1165,21 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
JSONObject config = sysConfigManager . getSysConfig ( ) ;
String mailId = mailService . sendEmail ( title , config . getString ( "settle_mail_to" ) , config . getString ( "settle_mail_cc" ) , content , attachList ) ;
if ( settleMail = = null ) {
JSONObject settleMailRecord = new JSONObject ( ) ;
settleMailRecord . put ( "send_date" , new Date ( ) ) ;
settleMailRecord . put ( "clearing_date" , date ) ;
settleMailRecord . put ( "email_id" , mailId ) ;
if ( StringUtils . isEmpty ( mailId ) ) {
result . put ( "result" , 1 ) ;
result . put ( "msg" , "System error" ) ;
settleMailRecord . put ( "mail_status" , 0 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
return result ;
} else {
settleMailRecord . put ( "mail_status" , 1 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
}
JSONObject settleMailRecord = new JSONObject ( ) ;
settleMailRecord . put ( "send_date" , new Date ( ) ) ;
settleMailRecord . put ( "clearing_date" , date ) ;
settleMailRecord . put ( "email_id" , mailId ) ;
if ( StringUtils . isEmpty ( mailId ) ) {
result . put ( "result" , 1 ) ;
result . put ( "msg" , "System error" ) ;
settleMailRecord . put ( "mail_status" , 0 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
return result ;
} else {
if ( ! StringUtils . isEmpty ( mailId ) ) {
JSONObject updateRecord = new JSONObject ( ) ;
updateRecord . put ( "id" , settleMail . getString ( "id" ) ) ;
updateRecord . put ( "mail_status" , 1 ) ;
updateRecord . put ( "email_id" , mailId ) ;
logSettleMailMapper . update ( updateRecord ) ;
} else {
result . put ( "result" , 0 ) ;
result . put ( "msg" , "System error" ) ;
return result ;
}
settleMailRecord . put ( "mail_status" , 1 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
}
sendTaskFinishMessages ( ManagerRole . FINANCIAL_STAFF , "清算文件已发送清算方" , "发送清算通知" ) ;
clearingLogMapper . lockSettlements ( date ) ;
@ -1246,7 +1233,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
@Override
public JSONObject findLogSettleByDate ( Date date ) {
public List< JSONObject> findLogSettleByDate ( Date date ) {
return logSettleMailMapper . findByDate ( date ) ;
}