@ -3,10 +3,13 @@ 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.core.BDAnalysisService ;
import au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper ;
import au.com.royalpay.payment.manage.mappers.log.StatisticsBDSalesReportMapper ;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
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.util.HSSFColor ;
import org.apache.poi.ss.usermodel.* ;
@ -18,8 +21,12 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException ;
import java.io.OutputStream ;
import java.math.BigDecimal ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import java.util.UUID ;
/ * *
* Created by yishuqian on 30 / 0 9 / 2016.
@ -30,24 +37,50 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Resource
private BDAnalysisMapper bdAnalysisMapper ;
@Resource
private StatisticsBDSalesReportMapper bdSalesReportMapper ;
@Override
public List < JSONObject > getSalesAnalysis ( JSONObject jsonObject ) {
return listSalesAnalysis ( jsonObject ) ;
}
private List < JSONObject > listSalesAnalysis ( JSONObject jsonObject ) {
private List < JSONObject > listSalesAnalysis ( JSONObject jsonObject ) {
List < JSONObject > listCountApproved = bdAnalysisMapper . countApproved ( jsonObject ) ;
List < JSONObject > bdSaleList = bdAnalysisMapper . getBDSaleList ( jsonObject ) ;
for ( JSONObject countApproved : listCountApproved ) {
for ( JSONObject saleList : bdSaleList ) {
if ( countApproved . getString ( "bd_id" ) . equals ( saleList . getString ( "bd_id" ) ) ) {
saleList . put ( "num" , countApproved . getString ( "num" ) ) ;
List < JSONObject > bdSaleList = bdSalesReportMapper . getBDSaleList ( jsonObject ) ;
for ( JSONObject countApproved : listCountApproved ) {
for ( JSONObject saleList : bdSaleList ) {
if ( countApproved . getString ( "bd_id" ) . equals ( saleList . getString ( "bd_id" ) ) ) {
saleList . put ( "num" , countApproved . getString ( "num" ) ) ;
}
}
}
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", DateUtils.addDays(jsonObject.getDate("end"), -2));
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 ;
}
//单独计算当日数据
@Override
public List < JSONObject > getSalesPartnersByBD ( JSONObject jsonObject ) {
@ -58,32 +91,32 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
public List < JSONObject > getSalesPartnersReportByBD ( JSONObject jsonObject ) {
List < JSONObject > bdAnalysis = bdAnalysisMapper . getBDSalePartnerReport ( jsonObject ) ;
List < JSONObject > result = new ArrayList < > ( ) ;
String keys_1 [ ] = { "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" } ;
String key_2 [ ] = { "10" , "11" , "12" } ;
result = getPartnerTypes ( keys_1 , result , 1 , 5 , bdAnalysis ) ;
return getPartnerTypes ( key_2 , result , 2 , 6 , bdAnalysis ) ;
String keys_1 [ ] = { "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" } ;
String key_2 [ ] = { "10" , "11" , "12" } ;
result = getPartnerTypes ( keys_1 , result , 1 , 5 , bdAnalysis ) ;
return getPartnerTypes ( key_2 , result , 2 , 6 , bdAnalysis ) ;
}
private List < JSONObject > getPartnerTypes ( String keys [ ] , List < JSONObject > result , int short_length , int long_length , List < JSONObject > bdAnalysis ) {
for ( String key : keys ) {
private List < JSONObject > getPartnerTypes ( String keys [ ] , List < JSONObject > result , int short_length , int long_length , List < JSONObject > bdAnalysis ) {
for ( String key : keys ) {
int countValue = 0 ;
int countTotal = 0 ;
JSONObject object = new JSONObject ( ) ;
JSONArray list = new JSONArray ( ) ;
for ( JSONObject type : bdAnalysis ) {
if ( type . getString ( "royalpayindustry" ) ! = null & & type . getString ( "royalpayindustry" ) . startsWith ( key ) & & ( type . getString ( "royalpayindustry" ) . length ( ) = = short_length | | type . getString ( "royalpayindustry" ) . length ( ) = = long_length ) ) {
for ( JSONObject type : bdAnalysis ) {
if ( type . getString ( "royalpayindustry" ) ! = null & & type . getString ( "royalpayindustry" ) . startsWith ( key ) & & ( type . getString ( "royalpayindustry" ) . length ( ) = = short_length | | type . getString ( "royalpayindustry" ) . length ( ) = = long_length ) ) {
countValue + = type . getIntValue ( "partner_counts" ) ;
countTotal + = type . getIntValue ( "total" ) ;
list . add ( type ) ;
}
}
if ( countValue = = 0 ) {
if ( countValue = = 0 ) {
continue ;
}
object . put ( "count_value" , countValue ) ;
object . put ( "count_total" , countTotal ) ;
object . put ( "mccCode" , key ) ;
object . put ( "children" , list ) ;
object . put ( "count_value" , countValue ) ;
object . put ( "count_total" , countTotal ) ;
object . put ( "mccCode" , key ) ;
object . put ( "children" , list ) ;
result . add ( object ) ;
}
return result ;
@ -92,7 +125,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Override
public void exportSalesExcel ( AnalysisBean analysisBean , HttpServletResponse httpResponse , JSONObject manager ) throws IOException {
httpResponse . setContentType ( "application/vnd.ms-excel" ) ;
String fileName = analysisBean . getBegin_month ( ) + "~" + analysisBean . getEnd_month ( ) ;
String fileName = analysisBean . getBegin_month ( ) + "~" + analysisBean . getEnd_month ( ) ;
// String fileName = new String(URLEncoder.encode(defaultname,"utf8"));
httpResponse . setHeader ( "Content-Disposition" , "attachment;filename="
+ fileName + ".xls" ) ;
@ -113,20 +146,20 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
List < JSONObject > bds = bdAnalysisMapper . getBDSaleList ( params ) ;
HSSFWorkbook workbook = new HSSFWorkbook ( ) ;
for ( JSONObject bd : bds ) {
for ( JSONObject bd : bds ) {
String bd_id = bd . getString ( "bd_id" ) ;
String bd_name = bd . getString ( "bd_name" ) ;
JSONObject monthParams = new JSONObject ( ) ;
monthParams . put ( "bd_id" , bd_id ) ;
monthParams . put ( "begin_month" , analysisBean . getBegin_month ( ) ) ;
monthParams . put ( "end_month" , analysisBean . getEnd_month ( ) ) ;
monthParams . put ( "bd_id" , bd_id ) ;
monthParams . put ( "begin_month" , analysisBean . getBegin_month ( ) ) ;
monthParams . put ( "end_month" , analysisBean . getEnd_month ( ) ) ;
List < JSONObject > monthTotalSale = bdAnalysisMapper . getMonthSalesList ( monthParams ) ;
for ( JSONObject month : monthTotalSale ) {
monthParams . put ( "month" , month . getString ( "y_m" ) ) ;
List < JSONObject > clientsMonthSale = bdAnalysisMapper . getClientsMonthSale ( bd_id , analysisBean . getBegin_month ( ) , analysisBean . getEnd_month ( ) , month . getString ( "y_m" ) ) ;
month . put ( "clients" , clientsMonthSale ) ;
for ( JSONObject month : monthTotalSale ) {
monthParams . put ( "month" , month . getString ( "y_m" ) ) ;
List < JSONObject > clientsMonthSale = bdAnalysisMapper . getClientsMonthSale ( bd_id , analysisBean . getBegin_month ( ) , analysisBean . getEnd_month ( ) , month . getString ( "y_m" ) ) ;
month . put ( "clients" , clientsMonthSale ) ;
}
exportExcel ( workbook , bd_name , monthTotalSale ) ;
exportExcel ( workbook , bd_name , monthTotalSale ) ;
}
OutputStream outputStream = httpResponse . getOutputStream ( ) ;
try {
@ -144,14 +177,52 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
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 ) ;
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 ) ;
}
}
}
} catch ( ParseException e ) {
e . printStackTrace ( ) ;
}
}
@Override
public void exportPartnerExcelByBd ( AnalysisBean analysisBean , HttpServletResponse httpResponse , JSONObject manager ) throws IOException {
OutputStream ous = null ;
try {
try {
JSONObject parmerters = analysisBean . toParams ( null ) ;
List < JSONObject > listPartnerByBd = bdAnalysisMapper . getBDSalePartnerList ( parmerters ) ;
httpResponse . setContentType ( "application/octet-stream;" ) ;
httpResponse . addHeader ( "Content-Disposition" , "attachment; filename=" + "Merchant_list--" + parmerters . getString ( "bd_name" ) + analysisBean . getBegin ( ) + "~" + analysisBean . getEnd ( ) + ".xls" ) ;
httpResponse . addHeader ( "Content-Disposition" , "attachment; filename=" + "Merchant_list--" + parmerters . getString ( "bd_name" ) + analysisBean . getBegin ( ) + "~" + analysisBean . getEnd ( ) + ".xls" ) ;
ous = httpResponse . getOutputStream ( ) ;
HSSFWorkbook wb = new HSSFWorkbook ( ) ;
HSSFFont font = wb . createFont ( ) ;
@ -159,7 +230,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
font . setFontHeightInPoints ( ( short ) 15 ) ;
CellStyle analysisStyle = wb . createCellStyle ( ) ;
analysisStyle . setFont ( font ) ;
Sheet sheet = wb . createSheet ( "Merchant list" ) ;
Sheet sheet = wb . createSheet ( "Merchant list" ) ;
sheet . createFreezePane ( 1 , 2 ) ;
sheet . setDefaultColumnWidth ( ( short ) 25 ) ;
int rowNum = 0 ;
@ -168,7 +239,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
for ( int i = 0 ; i < title . length ; i + + ) {
row . createCell ( i , Cell . CELL_TYPE_STRING ) . setCellValue ( title [ i ] ) ;
}
for ( JSONObject partner : listPartnerByBd ) {
for ( JSONObject partner : listPartnerByBd ) {
row = sheet . createRow ( + + rowNum ) ;
row . createCell ( 0 , Cell . CELL_TYPE_STRING ) . setCellValue ( partner . getString ( "short_name" ) ) ;
row . createCell ( 1 , Cell . CELL_TYPE_STRING ) . setCellValue ( partner . getString ( "client_moniker" ) ) ;
@ -176,7 +247,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
}
wb . write ( ous ) ;
ous . flush ( ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
} finally {
IOUtils . closeQuietly ( ous ) ;
}
@ -186,7 +257,7 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
@Override
public void exportPartnerExcelByData ( AnalysisBean analysisBean , HttpServletResponse httpResponse , JSONObject manager ) throws IOException {
OutputStream ous = null ;
try {
try {
JSONObject parmerters = analysisBean . toParams ( null ) ;
List < JSONObject > listPartnerByData = listSalesAnalysis ( parmerters ) ;
httpResponse . setContentType ( "application/octet-stream;" ) ;
@ -198,31 +269,31 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
font . setFontHeightInPoints ( ( short ) 15 ) ;
CellStyle analysisStyle = wb . createCellStyle ( ) ;
analysisStyle . setFont ( font ) ;
Sheet sheet = wb . createSheet ( "Merchant Sale List" ) ;
Sheet sheet = wb . createSheet ( "Merchant Sale List" ) ;
sheet . createFreezePane ( 1 , 2 ) ;
sheet . setDefaultColumnWidth ( ( short ) 25 ) ;
int rowNum = 0 ;
Row row = sheet . createRow ( rowNum ) ;
String [ ] title = { "BD Name" , "AUD Amount" , "Refund Fee" , "New Merchants" } ;
String [ ] title = { "BD Name" , "AUD Amount" , "Refund Fee" , "New Merchants" } ;
for ( int i = 0 ; i < title . length ; i + + ) {
row . createCell ( i , Cell . CELL_TYPE_STRING ) . setCellValue ( title [ i ] ) ;
}
for ( JSONObject dataSale : listPartnerByData ) {
for ( JSONObject dataSale : listPartnerByData ) {
row = sheet . createRow ( + + rowNum ) ;
row . createCell ( 0 , Cell . CELL_TYPE_STRING ) . setCellValue ( dataSale . getString ( "bd_name" ) ) ;
row . createCell ( 1 , Cell . CELL_TYPE_STRING ) . setCellValue ( dataSale . getString ( "total" ) ) ;
row . createCell ( 2 , Cell . CELL_TYPE_STRING ) . setCellValue ( dataSale . getString ( "refund_fee" ) ) ;
row . createCell ( 3 , Cell . CELL_TYPE_STRING ) . setCellValue ( dataSale . getString ( "num" ) = = null ? "0" : dataSale . getString ( "num" ) ) ;
row . createCell ( 3 , Cell . CELL_TYPE_STRING ) . setCellValue ( dataSale . getString ( "num" ) = = null ? "0" : dataSale . getString ( "num" ) ) ;
}
wb . write ( ous ) ;
ous . flush ( ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
} finally {
IOUtils . closeQuietly ( ous ) ;
}
}
private void exportExcel ( HSSFWorkbook workbook , String title , List < JSONObject > monthTotalSale ) {
private void exportExcel ( HSSFWorkbook workbook , String title , List < JSONObject > monthTotalSale ) {
// 声明一个工作薄
// 生成一个表格
HSSFSheet sheet = workbook . createSheet ( title ) ;
@ -271,9 +342,9 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
// comment.setAuthor("leno");
//产生表格标题行
HSSFRow row0 = sheet . createRow ( 0 ) ;
HSSFRow row1 = sheet . createRow ( 1 ) ;
HSSFRow row2 = sheet . createRow ( 2 ) ;
HSSFRow row0 = sheet . createRow ( 0 ) ;
HSSFRow row1 = sheet . createRow ( 1 ) ;
HSSFRow row2 = sheet . createRow ( 2 ) ;
HSSFCell cell00 = row0 . createCell ( 0 ) ;
HSSFCell cell01 = row0 . createCell ( 1 ) ;
HSSFCell cell20 = row2 . createCell ( 0 ) ;
@ -294,15 +365,13 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
cell20 . setCellValue ( text20 ) ;
for ( int i = 0 ; i < monthTotalSale . size ( ) ; i + + ) {
sheet . addMergedRegion ( new CellRangeAddress ( 0 , 0 , 2 * i + 2 , 2 * i + 3 ) ) ;
HSSFCell cell02 = row0 . createCell ( i * 2 + 2 ) ;
HSSFCell cell12 = row1 . createCell ( i * 2 + 2 ) ;
HSSFCell cell13 = row1 . createCell ( i * 2 + 3 ) ;
HSSFCell cell22 = row2 . createCell ( i * 2 + 2 ) ;
HSSFCell cell23 = row2 . createCell ( i * 2 + 3 ) ;
sheet . addMergedRegion ( new CellRangeAddress ( 0 , 0 , 2 * i + 2 , 2 * i + 3 ) ) ;
HSSFCell cell02 = row0 . createCell ( i * 2 + 2 ) ;
HSSFCell cell12 = row1 . createCell ( i * 2 + 2 ) ;
HSSFCell cell13 = row1 . createCell ( i * 2 + 3 ) ;
HSSFCell cell22 = row2 . createCell ( i * 2 + 2 ) ;
HSSFCell cell23 = row2 . createCell ( i * 2 + 3 ) ;
cell02 . setCellStyle ( style ) ;
cell12 . setCellStyle ( style ) ;
@ -314,19 +383,18 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
HSSFRichTextString text13 = new HSSFRichTextString ( "增长百分比" ) ;
HSSFRichTextString text22 = new HSSFRichTextString ( monthTotalSale . get ( i ) . getString ( "total" ) ) ;
double rate = 0 ;
if ( i > 0 ) {
BigDecimal lastTotal = monthTotalSale . get ( i - 1 ) . getBigDecimal ( "total" ) ;
BigDecimal total = monthTotalSale . get ( i ) . getBigDecimal ( "total" ) ;
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
rate = 100 ;
}
else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
rate = 0 ;
} else {
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
}
if ( i > 0 ) {
BigDecimal lastTotal = monthTotalSale . get ( i - 1 ) . getBigDecimal ( "total" ) ;
BigDecimal total = monthTotalSale . get ( i ) . getBigDecimal ( "total" ) ;
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
rate = 100 ;
} else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
rate = 0 ;
} else {
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
}
}
HSSFRichTextString text23 = i = = 0 ? new HSSFRichTextString ( "-" ) : new HSSFRichTextString ( String . valueOf ( rate ) ) ;
HSSFRichTextString text23 = i = = 0 ? new HSSFRichTextString ( "-" ) : new HSSFRichTextString ( String . valueOf ( rate ) ) ;
cell02 . setCellValue ( text0 ) ;
cell12 . setCellValue ( text12 ) ;
cell13 . setCellValue ( text13 ) ;
@ -335,35 +403,34 @@ public class BDAnalysisServiceImpl implements BDAnalysisService {
}
List < JSONObject > partnersSale = ( List < JSONObject > ) monthTotalSale . get ( 0 ) . get ( "clients" ) ;
for ( int m = 0 ; m < partnersSale . size ( ) ; m + + ) {
HSSFRow row = sheet . createRow ( m + 3 ) ;
for ( int m = 0 ; m < partnersSale . size ( ) ; m + + ) {
HSSFRow row = sheet . createRow ( m + 3 ) ;
HSSFCell cell_client_name = row . createCell ( 0 ) ;
HSSFCell cell_approve_time = row . createCell ( 1 ) ;
cell_client_name . setCellStyle ( style ) ;
cell_approve_time . setCellStyle ( style ) ;
HSSFRichTextString text_client_name = new HSSFRichTextString ( partnersSale . get ( m ) . getString ( "short_name" ) ) ;
HSSFRichTextString text_approve_time = new HSSFRichTextString ( partnersSale . get ( m ) . getString ( "approve_time" ) ) ;
HSSFRichTextString text_approve_time = new HSSFRichTextString ( partnersSale . get ( m ) . getString ( "approve_time" ) ) ;
cell_client_name . setCellValue ( text_client_name ) ;
cell_approve_time . setCellValue ( text_approve_time ) ;
for ( int n = 0 ; n < monthTotalSale . size ( ) ; n + + ) {
List < JSONObject > clients = ( List < JSONObject > ) monthTotalSale . get ( n ) . get ( "clients" ) ;
HSSFCell celli2 = row . createCell ( n * 2 + 2 ) ;
HSSFCell celli3 = row . createCell ( n * 2 + 3 ) ;
HSSFCell celli2 = row . createCell ( n * 2 + 2 ) ;
HSSFCell celli3 = row . createCell ( n * 2 + 3 ) ;
celli2 . setCellStyle ( style2 ) ;
celli3 . setCellStyle ( style2 ) ;
HSSFRichTextString texti2 = new HSSFRichTextString ( clients . get ( m ) . getString ( "month_total" ) ) ;
double rate = 0 ;
if ( n > 0 ) {
List < JSONObject > lastClients = ( List < JSONObject > ) monthTotalSale . get ( n - 1 ) . get ( "clients" ) ;
if ( n > 0 ) {
List < JSONObject > lastClients = ( List < JSONObject > ) monthTotalSale . get ( n - 1 ) . get ( "clients" ) ;
BigDecimal lastTotal = lastClients . 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 ) {
rate = 100 ;
}
else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
rate = 0 ;
} else {
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) ! = 0 ) {
rate = 100 ;
} else if ( lastTotal . compareTo ( new BigDecimal ( 0 ) ) = = 0 & & total . compareTo ( new BigDecimal ( 0 ) ) = = 0 ) {
rate = 0 ;
} else {
rate = total . subtract ( lastTotal ) . multiply ( new BigDecimal ( 100 ) ) . divide ( lastTotal , 2 , BigDecimal . ROUND_DOWN ) . doubleValue ( ) ;
}
}
HSSFRichTextString texti3 = new HSSFRichTextString ( String . valueOf ( rate ) ) ;