@ -15,7 +15,11 @@ import au.com.royalpay.payment.manage.bill.bean.NewBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillBean ;
import au.com.royalpay.payment.manage.bill.core.BillService ;
import au.com.royalpay.payment.manage.mappers.bill.BillMapper ;
import au.com.royalpay.payment.manage.merchants.core.ClientManager ;
import au.com.royalpay.payment.tools.env.PlatformEnvironment ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.exceptions.NotFoundException ;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException ;
import au.com.royalpay.payment.tools.utils.PageListUtils ;
/ * *
@ -25,24 +29,39 @@ import au.com.royalpay.payment.tools.utils.PageListUtils;
public class BillServiceImpl implements BillService {
@Resource
private BillMapper billMapper ;
@Resource
private ClientManager clientManager ;
@Override
public void save ( int client_id , NewBillBean newBillBean ) {
public JSONObject save ( int client_id , NewBillBean newBillBean ) {
JSONObject client = clientManager . getClientInfo ( client_id ) ;
// if(client==null){
// throw new NotFoundException("client info not found");
// }
Date now = new Date ( ) ;
JSONObject record = new JSONObject ( ) ;
record . put ( "client_id" , client_id ) ;
record . put ( "price" , newBillBean . getPrice ( ) ) ;
record . put ( "currency" , newBillBean . getCurrency ( ) ) ;
record . put ( "remark" , newBillBean . getRemark ( ) ) ;
record . put ( "client_id" , client_id ) ;
record . put ( "price" , newBillBean . getAmount ( ) ) ;
record . put ( "currency" , newBillBean . getCurrency ( ) ) ;
record . put ( "remark" , newBillBean . getRemark ( ) ) ;
record . put ( "create_time" , now ) ;
record . put ( "cancle_time" , DateUtils . addHours ( now , newBillBean . getIneffective_hour ( ) ) ) ;
record . put ( "cancle_time" , addExpire ( now , newBillBean . getExpire ( ) ) ) ;
record . put ( "status" , 1 ) ;
billMapper . save ( record ) ;
JSONObject result = new JSONObject ( ) ;
result . put ( "partner_name" , client . getString ( "short_name" ) ) ;
result . put ( "partner_code" , client . getString ( "client_moniker" ) ) ;
result . put ( "full_name" , client . getString ( "company_name" ) ) ;
result . put ( "code_url" , PlatformEnvironment . getEnv ( ) . concatUrl ( "/bills/payment/orders/" + record . getString ( "blll_id" ) ) ) ;
result . put ( "bill" , record ) ;
return result ;
}
@Override
public JSONObject queryBills ( int client_id , QueryBillBean queryBillBean ) {
PageList < JSONObject > list = billMapper . listWithOrderAnalysis ( queryBillBean . toParams ( ) , new PageBounds ( queryBillBean . getPage ( ) , queryBillBean . getLimit ( ) ) ) ;
JSONObject params = queryBillBean . toParams ( ) ;
params . put ( "client_id" , client_id ) ;
PageList < JSONObject > list = billMapper . listWithOrderAnalysis ( params , new PageBounds ( queryBillBean . getPage ( ) , queryBillBean . getLimit ( ) ) ) ;
return PageListUtils . buildPageListResult ( list ) ;
}
@ -56,7 +75,7 @@ public class BillServiceImpl implements BillService {
}
@Override
public void updateBillStatus ( String billId , String status , int client_id ) {
public void updateBillStatus ( String billId , String status , int client_id ) {
JSONObject bill = billMapper . findOne ( billId ) ;
if ( bill . getIntValue ( "client_id" ) ! = client_id ) {
throw new BadRequestException ( "You have no right to check this bill" ) ;
@ -71,4 +90,20 @@ public class BillServiceImpl implements BillService {
public void removeBill ( String billId ) {
billMapper . delete ( billId ) ;
}
private Date addExpire ( Date now , String expire ) {
if ( Integer . valueOf ( expire . substring ( 0 , expire . length ( ) - 1 ) ) = = 0 ) {
return null ;
}
String unit = expire . substring ( expire . length ( ) - 1 , expire . length ( ) ) ;
switch ( unit ) {
case "s" :
return DateUtils . addSeconds ( now , Integer . valueOf ( expire . substring ( 0 , expire . length ( ) - 1 ) ) ) ;
case "h" :
return DateUtils . addHours ( now , Integer . valueOf ( expire . substring ( 0 , expire . length ( ) - 1 ) ) ) ;
case "d" :
return DateUtils . addDays ( now , Integer . valueOf ( expire . substring ( 0 , expire . length ( ) - 1 ) ) ) ;
}
throw new ServerErrorException ( "日期单位不正确" ) ;
}
}