@ -64,7 +64,6 @@ import org.springframework.format.number.CurrencyStyleFormatter;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.Assert ;
import org.springframework.util.Assert ;
import org.springframework.util.CollectionUtils ;
import org.thymeleaf.context.Context ;
import org.thymeleaf.context.Context ;
import org.thymeleaf.spring5.SpringTemplateEngine ;
import org.thymeleaf.spring5.SpringTemplateEngine ;
@ -256,6 +255,12 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
return data ;
return data ;
} ) . collect ( Collectors . toList ( ) ) ;
} ) . collect ( Collectors . toList ( ) ) ;
log . put ( "bank_statistics" , bankStatistics ) ;
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 ( "editable" , DateUtils . isSameDay ( log . getDate ( "settle_date" ) , new Date ( ) ) & & log . getBooleanValue ( "editable" ) ) ;
log . put ( "channel_analysis" , clearingDetailAnalysisMapper . analysisChannelReport ( clearingId ) ) ;
log . put ( "channel_analysis" , clearingDetailAnalysisMapper . analysisChannelReport ( clearingId ) ) ;
}
}
@ -390,9 +395,11 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
@Override
@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 ) ;
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 ( ) ) {
if ( logs . isEmpty ( ) ) {
throw new NotFoundException ( ) ;
throw new NotFoundException ( ) ;
}
}
@ -486,9 +493,11 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
@Override
@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 ) ;
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 ( ) ) {
if ( logs . isEmpty ( ) ) {
throw new NotFoundException ( ) ;
throw new NotFoundException ( ) ;
}
}
@ -496,11 +505,19 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
for ( JSONObject log : logs ) {
for ( JSONObject log : logs ) {
List < JSONObject > details = clearingDetailMapper . listReportsOfSettlement ( log . getIntValue ( "clearing_id" ) ) ;
List < JSONObject > details = clearingDetailMapper . listReportsOfSettlement ( log . getIntValue ( "clearing_id" ) ) ;
details = mergeBatchSettleClients ( details ) ;
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 ( ) ) ;
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 {
private byte [ ] generateSettleXlsxFile ( Date dt , List < JSONObject > settlements , String bank ) throws IOException {
try ( Workbook wb = new XSSFWorkbook ( ) ) {
try ( Workbook wb = new XSSFWorkbook ( ) ) {
Sheet sheet = wb . createSheet ( "Merchant_Settlement_Info_" + DateFormatUtils . format ( dt , "yyyyMMdd" ) ) ;
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 ) {
for ( JSONObject log : logs ) {
List < JSONObject > details = clearingDetailMapper . listReportsOfSettlement ( log . getIntValue ( "clearing_id" ) ) ;
List < JSONObject > details = clearingDetailMapper . listReportsOfSettlement ( log . getIntValue ( "clearing_id" ) ) ;
details = mergeBatchSettleClients ( details ) ;
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 ( ) ;
OutputStream ous = resp . getOutputStream ( ) ;
if ( files . size ( ) = = 1 ) {
if ( files . size ( ) = = 1 ) {
@ -580,7 +597,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
resp . addHeader ( "Content-Disposition" , "attachment; filename=" + zipName ) ;
resp . addHeader ( "Content-Disposition" , "attachment; filename=" + zipName ) ;
OutputStream ous = resp . getOutputStream ( ) ;
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 ) ) {
try ( ZipOutputStream zos = new ZipOutputStream ( ous ) ) {
for ( ABAFile aba : abaFiles ) {
for ( ABAFile aba : abaFiles ) {
zos . putNextEntry ( new ZipEntry ( aba . filename ( ) ) ) ;
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 ( ) ) ;
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 ) {
private ABAFile generateSettleAbaFile ( String bank , Date dt , List < JSONObject > settlements ) {
@ -1092,28 +1112,8 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
@Override
@Override
public JSONObject sendSettlementMail ( Date date , String checkCode ) {
public JSONObject sendSettlementMail ( Date date , List< String > clearIds ) {
JSONObject result = new JSONObject ( ) ;
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 {
try {
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 ( ) ;
@ -1121,7 +1121,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
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 ( ) ;
List < JSONObject > xlsxFileList = getXlsx ( date , "CBA" );
List < JSONObject > xlsxFileList = getXlsx ( date , "CBA" , clearIds );
if ( xlsxFileList . size ( ) > 1 ) {
if ( xlsxFileList . size ( ) > 1 ) {
fileName1 + = ".zip" ;
fileName1 + = ".zip" ;
attach1 . put ( "content" , Base64 . encodeBase64String ( getZipByteArr ( xlsxFileList ) ) ) ;
attach1 . put ( "content" , Base64 . encodeBase64String ( getZipByteArr ( xlsxFileList ) ) ) ;
@ -1133,7 +1133,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
attachList . add ( attach1 ) ;
attachList . add ( attach1 ) ;
JSONObject attach2 = new JSONObject ( ) ;
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" ) ;
String fileName2 = "Merchant_Settlement_Info_aba_" + DateFormatUtils . format ( date , "yyyyMMdd" ) ;
if ( abaFileList . size ( ) > 1 ) {
if ( abaFileList . size ( ) > 1 ) {
fileName2 + = ".zip" ;
fileName2 + = ".zip" ;
@ -1157,6 +1157,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
Context ctx = new Context ( ) ;
Context ctx = new Context ( ) ;
ctx . setVariable ( "date" , DateFormatUtils . format ( date , "dd-MM-yyyy" ) ) ;
ctx . setVariable ( "date" , DateFormatUtils . format ( date , "dd-MM-yyyy" ) ) ;
ctx . setVariable ( "abaFiles" , abaFileList ) ;
ctx . setVariable ( "abaFiles" , abaFileList ) ;
ctx . setVariable ( "totalAmount" , abaFileList . stream ( ) . map ( ABAFile : : getTotalSettleAmount ) . reduce ( BigDecimal : : add ) ) ;
final String content = thymeleaf . process ( "mail/settlement_mail" , ctx ) ;
final String content = thymeleaf . process ( "mail/settlement_mail" , ctx ) ;
// 测试用地址
// 测试用地址
// String mailId = mailService.sendEmail(title, "164851225@qq.com", "1029811920@qq.com", content,
// 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 ( ) ;
JSONObject config = sysConfigManager . getSysConfig ( ) ;
String mailId = mailService . sendEmail ( title , config . getString ( "settle_mail_to" ) , config . getString ( "settle_mail_cc" ) , content , attachList ) ;
String mailId = mailService . sendEmail ( title , config . getString ( "settle_mail_to" ) , config . getString ( "settle_mail_cc" ) , content , attachList ) ;
if ( settleMail = = null ) {
JSONObject settleMailRecord = new JSONObject ( ) ;
JSONObject settleMailRecord = new JSONObject ( ) ;
settleMailRecord . put ( "send_date" , new Date ( ) ) ;
settleMailRecord . put ( "send_date" , new Date ( ) ) ;
settleMailRecord . put ( "clearing_date" , date ) ;
settleMailRecord . put ( "clearing_date" , date ) ;
settleMailRecord . put ( "email_id" , mailId ) ;
settleMailRecord . put ( "email_id" , mailId ) ;
if ( StringUtils . isEmpty ( mailId ) ) {
if ( StringUtils . isEmpty ( mailId ) ) {
result . put ( "result" , 1 ) ;
result . put ( "result" , 1 ) ;
result . put ( "msg" , "System error" ) ;
result . put ( "msg" , "System error" ) ;
settleMailRecord . put ( "mail_status" , 0 ) ;
settleMailRecord . put ( "mail_status" , 0 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
return result ;
return result ;
} else {
settleMailRecord . put ( "mail_status" , 1 ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
}
} else {
} else {
if ( ! StringUtils . isEmpty ( mailId ) ) {
settleMailRecord . put ( "mail_status" , 1 ) ;
JSONObject updateRecord = new JSONObject ( ) ;
settleMailRecord . put ( "notice_status" , 0 ) ;
updateRecord . put ( "id" , settleMail . getString ( "id" ) ) ;
logSettleMailMapper . save ( settleMailRecord ) ;
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 ;
}
}
}
sendTaskFinishMessages ( ManagerRole . FINANCIAL_STAFF , "清算文件已发送清算方" , "发送清算通知" ) ;
sendTaskFinishMessages ( ManagerRole . FINANCIAL_STAFF , "清算文件已发送清算方" , "发送清算通知" ) ;
clearingLogMapper . lockSettlements ( date ) ;
clearingLogMapper . lockSettlements ( date ) ;
@ -1246,7 +1233,7 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
}
}
@Override
@Override
public JSONObject findLogSettleByDate ( Date date ) {
public List< JSONObject> findLogSettleByDate ( Date date ) {
return logSettleMailMapper . findByDate ( date ) ;
return logSettleMailMapper . findByDate ( date ) ;
}
}