@ -3,14 +3,19 @@ package au.com.royalpay.payment.manage.analysis.core.impls;
import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean ;
import au.com.royalpay.payment.manage.analysis.beans.AnalysisBean ;
import au.com.royalpay.payment.manage.analysis.core.BDAnalysisService ;
import au.com.royalpay.payment.manage.analysis.core.BDAnalysisService ;
import au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper ;
import au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper ;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper ;
import au.com.royalpay.payment.manage.mappers.log.StatisticsBDSalesReportMapper ;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole ;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.JSONObject ;
import org.apache.commons.io.IOUtils ;
import org.apache.commons.io.IOUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
import org.apache.commons.lang3.time.DateUtils ;
import org.apache.poi.hssf.usermodel.* ;
import org.apache.poi.hssf.usermodel.* ;
import org.apache.poi.hssf.util.HSSFColor ;
import org.apache.poi.hssf.util.HSSFColor ;
import org.apache.poi.ss.usermodel.* ;
import org.apache.poi.ss.usermodel.* ;
import org.apache.poi.ss.util.CellRangeAddress ;
import org.apache.poi.ss.util.CellRangeAddress ;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import javax.annotation.Resource ;
import javax.annotation.Resource ;
@ -18,8 +23,12 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException ;
import java.io.IOException ;
import java.io.OutputStream ;
import java.io.OutputStream ;
import java.math.BigDecimal ;
import java.math.BigDecimal ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import java.util.List ;
import java.util.UUID ;
/ * *
/ * *
* Created by yishuqian on 30 / 0 9 / 2016.
* Created by yishuqian on 30 / 0 9 / 2016.
@ -30,6 +39,12 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Resource
@Resource
private BDAnalysisMapper bdAnalysisMapper ;
private BDAnalysisMapper bdAnalysisMapper ;
@Resource
private StatisticsBDSalesReportMapper bdSalesReportMapper ;
@Resource
private TransactionAnalysisMapper transactionAnalysisMapper ;
@Override
@Override
public List < JSONObject > getSalesAnalysis ( JSONObject jsonObject ) {
public List < JSONObject > getSalesAnalysis ( JSONObject jsonObject ) {
@ -38,7 +53,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
private List < JSONObject > listSalesAnalysis ( JSONObject jsonObject ) {
private List < JSONObject > listSalesAnalysis ( JSONObject jsonObject ) {
List < JSONObject > listCountApproved = bdAnalysisMapper . countApproved ( jsonObject ) ;
List < JSONObject > listCountApproved = bdAnalysisMapper . countApproved ( jsonObject ) ;
List < JSONObject > bdSaleList = bdAnalysis Mapper. getBDSaleList ( jsonObject ) ;
List < JSONObject > bdSaleList = bdSalesReport Mapper. getBDSaleList ( jsonObject ) ;
for ( JSONObject countApproved : listCountApproved ) {
for ( JSONObject countApproved : listCountApproved ) {
for ( JSONObject saleList : bdSaleList ) {
for ( JSONObject saleList : bdSaleList ) {
if ( countApproved . getString ( "bd_id" ) . equals ( saleList . getString ( "bd_id" ) ) ) {
if ( countApproved . getString ( "bd_id" ) . equals ( saleList . getString ( "bd_id" ) ) ) {
@ -46,8 +61,30 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
}
}
}
}
}
}
SimpleDateFormat sd = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
if ( sd . format ( jsonObject . getDate ( "end" ) ) . equals ( sd . format ( DateUtils . addDays ( new Date ( ) , 1 ) ) ) ) {
jsonObject . put ( "begin" , DateUtils . addDays ( jsonObject . getDate ( "end" ) , - 1 ) ) ;
jsonObject . put ( "end" , jsonObject . getDate ( "end" ) ) ;
List < JSONObject > todaySaleList = bdAnalysisMapper . getBDSaleList ( jsonObject ) ;
for ( JSONObject todayBDSaleItem : todaySaleList ) {
boolean flag = false ;
for ( JSONObject baSaleItem : bdSaleList ) {
if ( baSaleItem . getString ( "bd_id" ) . equals ( todayBDSaleItem . getString ( "bd_id" ) ) ) {
BigDecimal newAmount = baSaleItem . getBigDecimal ( "total" ) . add ( todayBDSaleItem . getBigDecimal ( "total" ) ) ;
baSaleItem . put ( "total" , newAmount ) ;
flag = true ;
}
}
if ( ! flag ) {
bdSaleList . add ( todayBDSaleItem ) ;
}
}
}
return bdSaleList ;
return bdSaleList ;
}
}
//单独计算当日数据
@Override
@Override
public List < JSONObject > getSalesPartnersByBD ( JSONObject jsonObject ) {
public List < JSONObject > getSalesPartnersByBD ( JSONObject jsonObject ) {
@ -144,6 +181,62 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
return bdAnalysisMapper . countApproved ( params ) ;
return bdAnalysisMapper . countApproved ( params ) ;
}
}
/ * *
* BD 销 售 每 日 数 据 统 计
* @param date
* /
@Override
public void generateReport ( String date ) {
try {
Date beginTime = DateUtils . parseDate ( date , new String [ ] { "yyyy-MM-dd" } ) ;
Date yesterdayEndTime = DateUtils . addDays ( beginTime , 1 ) ;
String endDate = DateFormatUtils . format ( yesterdayEndTime , "yyyy-MM-dd" ) ;
Date endTime = DateUtils . parseDate ( endDate , new String [ ] { "yyyy-MM-dd" } ) ;
JSONObject params = new JSONObject ( ) ;
params . put ( "begin" , beginTime ) ;
params . put ( "end" , endTime ) ;
List < JSONObject > bdSaleList = bdAnalysisMapper . getOneDayBDSaleList ( params ) ;
if ( bdSaleList . size ( ) ! = 0 ) {
for ( JSONObject item : bdSaleList ) {
JSONObject existBDSalesReport = bdSalesReportMapper . findByBDIdAndLogDate ( item . getString ( "bd_id" ) , beginTime , 0 ) ;
if ( existBDSalesReport = = null ) {
JSONObject object = new JSONObject ( item ) ;
object . put ( "log_id" , UUID . randomUUID ( ) . toString ( ) ) ;
object . put ( "log_date" , beginTime ) ;
object . put ( "create_time" , new Date ( ) ) ;
bdSalesReportMapper . save ( object ) ;
} else {
existBDSalesReport . put ( "pay_amount" , item . getString ( "pay_amount" ) ) ;
existBDSalesReport . put ( "refund_amount" , item . getString ( "refund_amount" ) ) ;
existBDSalesReport . put ( "net_amount" , item . getString ( "net_amount" ) ) ;
bdSalesReportMapper . update ( existBDSalesReport ) ;
}
}
}
List < JSONObject > orgSaleList = transactionAnalysisMapper . getOneDayOrgMerchantSaleList ( params ) ;
if ( orgSaleList . size ( ) ! = 0 ) {
for ( JSONObject item : orgSaleList ) {
JSONObject existOrgSalesReport = bdSalesReportMapper . findByBDIdAndLogDate ( item . getString ( "bd_id" ) , beginTime , 1 ) ;
if ( existOrgSalesReport = = null ) {
JSONObject object = new JSONObject ( item ) ;
object . put ( "log_id" , UUID . randomUUID ( ) . toString ( ) ) ;
object . put ( "log_date" , beginTime ) ;
object . put ( "create_time" , new Date ( ) ) ;
bdSalesReportMapper . save ( object ) ;
} else {
existOrgSalesReport . put ( "pay_amount" , item . getString ( "pay_amount" ) ) ;
existOrgSalesReport . put ( "refund_amount" , item . getString ( "refund_amount" ) ) ;
existOrgSalesReport . put ( "net_amount" , item . getString ( "net_amount" ) ) ;
bdSalesReportMapper . update ( existOrgSalesReport ) ;
}
}
}
} catch ( ParseException e ) {
e . printStackTrace ( ) ;
}
}
@Override
@Override
public void exportPartnerExcelByBd ( AnalysisBean analysisBean , HttpServletResponse httpResponse , JSONObject manager ) throws IOException {
public void exportPartnerExcelByBd ( AnalysisBean analysisBean , HttpServletResponse httpResponse , JSONObject manager ) throws IOException {
OutputStream ous = null ;
OutputStream ous = null ;
@ -294,8 +387,6 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
cell20 . setCellValue ( text20 ) ;
cell20 . setCellValue ( text20 ) ;
for ( int i = 0 ; i < monthTotalSale . size ( ) ; i + + ) {
for ( int i = 0 ; i < monthTotalSale . size ( ) ; i + + ) {
sheet . addMergedRegion ( new CellRangeAddress ( 0 , 0 , 2 * i + 2 , 2 * i + 3 ) ) ;
sheet . addMergedRegion ( new CellRangeAddress ( 0 , 0 , 2 * i + 2 , 2 * i + 3 ) ) ;
HSSFCell cell02 = row0 . createCell ( i * 2 + 2 ) ;
HSSFCell cell02 = row0 . createCell ( i * 2 + 2 ) ;
@ -319,8 +410,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
BigDecimal total = monthTotalSale . get ( i ) . getBigDecimal ( "total" ) ;
BigDecimal total = monthTotalSale . get ( i ) . getBigDecimal ( "total" ) ;
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
rate = 100 ;
rate = 100 ;
}
} else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
rate = 0 ;
rate = 0 ;
} else {
} else {
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
@ -359,8 +449,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
BigDecimal total = clients . get ( m ) . getBigDecimal ( "month_total" ) ;
BigDecimal total = clients . get ( m ) . getBigDecimal ( "month_total" ) ;
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
rate = 100 ;
rate = 100 ;
}
} else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
rate = 0 ;
rate = 0 ;
} else {
} else {
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;