diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index 0cc1def19..8ae5307d8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -301,7 +301,6 @@ public class RetailAppController { } @RequestMapping(value = "/bills",method = RequestMethod.PUT) public JSONObject addBill(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody NewBillBean newBillBean){ - device.put("client_id",9); JSONObject result = billService.save(device.getIntValue("client_id"),newBillBean); result.remove("bill"); return result; @@ -311,7 +310,9 @@ public class RetailAppController { billService.updateBillStatus(bill_id,"2",device.getIntValue("client_id")); } @RequestMapping(value = "/bills/orders/{bill_id}",method = RequestMethod.GET) - public List getBillOrders(@PathVariable("bill_id")String bill_id, QueryBillOrderBean queryBillOrderBean,@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){ - return billOrderService.query(bill_id,device.getIntValue("client_id"),queryBillOrderBean); + public JSONObject getBillOrders(@PathVariable("bill_id")String bill_id, QueryBillOrderBean queryBillOrderBean,@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){ + JSONObject result =billOrderService.query(bill_id,device.getIntValue("client_id"),queryBillOrderBean); + result.put("analysis",billOrderService.analysis(bill_id,device.getIntValue("client_id"),queryBillOrderBean)); + return result; } } diff --git a/src/main/java/au/com/royalpay/payment/manage/bill/core/BillOrderService.java b/src/main/java/au/com/royalpay/payment/manage/bill/core/BillOrderService.java index d60b76de1..9492f5516 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bill/core/BillOrderService.java +++ b/src/main/java/au/com/royalpay/payment/manage/bill/core/BillOrderService.java @@ -13,5 +13,7 @@ public interface BillOrderService { List getByBillId(String bill_id, int client_id); - List query(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean); + JSONObject query(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean); + + JSONObject analysis(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean); } diff --git a/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillOrderServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillOrderServiceImpl.java index 91da8fa62..53e8b3b8e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillOrderServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillOrderServiceImpl.java @@ -4,10 +4,11 @@ import java.util.List; import javax.annotation.Resource; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean; import au.com.royalpay.payment.manage.bill.core.BillOrderService; @@ -15,6 +16,7 @@ import au.com.royalpay.payment.manage.mappers.bill.BillMapper; import au.com.royalpay.payment.manage.mappers.bill.BillOrderMapper; import au.com.royalpay.payment.manage.mappers.system.CustomerRelationAlipayMapper; import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import au.com.royalpay.payment.tools.utils.PageListUtils; /** * Created by wangning on 11/02/2018. @@ -27,30 +29,53 @@ public class BillOrderServiceImpl implements BillOrderService { private BillMapper billMapper; @Resource private CustomerRelationAlipayMapper customerRelationAlipayMapper; + @Override public List getByBillId(String bill_id, int client_id) { JSONObject bill = billMapper.findOne(bill_id); - if(bill.getIntValue("client_id")!= client_id){ + if (bill.getIntValue("client_id") != client_id) { throw new BadRequestException("You have no right to check this bill"); } List wechatBillOrders = billOrderMapper.findByBillIdWithWechatInfo(bill_id); for (JSONObject order : wechatBillOrders) { - if("Alipay".equals(order.getString("channel"))){ + if ("Alipay".equals(order.getString("channel"))) { JSONObject alipayInfo = customerRelationAlipayMapper.findCustomerByUserId(order.getString("customer_id")); - order.put("nickname",alipayInfo.getString("nickname")); - order.put("headimg",alipayInfo.getString("headimg")); + if (alipayInfo != null) { + order.put("nickname", alipayInfo.getString("nickname")); + order.put("headimg", alipayInfo.getString("headimg")); + } } } return wechatBillOrders; } @Override - public List query(String bill_id,int client_id, QueryBillOrderBean queryBillOrderBean) { + public JSONObject query(String bill_id, int client_id, QueryBillOrderBean queryBillOrderBean) { + JSONObject bill = billMapper.findOne(bill_id); + if (bill.getIntValue("client_id") != client_id) { + throw new BadRequestException("You have no right to check this bill"); + } + PageList list = billOrderMapper.queryWithWechatInfo(bill_id, queryBillOrderBean.toParams(), + new PageBounds(queryBillOrderBean.getPage(), queryBillOrderBean.getLimit())); + for (JSONObject jsonObject : list) { + if ("Alipay".equals(jsonObject.getString("channel"))) { + JSONObject alipayInfo = customerRelationAlipayMapper.findCustomerByUserId(jsonObject.getString("customer_id")); + if (alipayInfo != null) { + jsonObject.put("nickname", alipayInfo.getString("nickname")); + jsonObject.put("headimg", alipayInfo.getString("headimg")); + } + } + } + return PageListUtils.buildPageListResult(list); + } + + @Override + public JSONObject analysis(String bill_id, int client_id, QueryBillOrderBean queryBillOrderBean) { JSONObject bill = billMapper.findOne(bill_id); - if(bill.getIntValue("client_id")!= client_id){ + if (bill.getIntValue("client_id") != client_id) { throw new BadRequestException("You have no right to check this bill"); } - return billOrderMapper.query(bill_id,queryBillOrderBean.toParams()); + return billOrderMapper.analysis(bill_id, queryBillOrderBean.toParams()); } } diff --git a/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillServiceImpl.java index 528eea653..974815bc8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/bill/core/impl/BillServiceImpl.java @@ -1,5 +1,6 @@ package au.com.royalpay.payment.manage.bill.core.impl; +import java.math.BigDecimal; import java.util.Date; import javax.annotation.Resource; @@ -16,9 +17,9 @@ 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.CommonConsts; 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; @@ -41,7 +42,7 @@ public class BillServiceImpl implements BillService { Date now = new Date(); JSONObject record = new JSONObject(); record.put("client_id", client_id); - record.put("price", newBillBean.getAmount()); + record.put("price", newBillBean.getAmount().divide(CommonConsts.HUNDRED,2, BigDecimal.ROUND_DOWN)); record.put("currency", newBillBean.getCurrency()); record.put("remark", newBillBean.getRemark()); record.put("create_time", now); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/bill/BillOrderMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/bill/BillOrderMapper.java index 7bd13b780..f0a040470 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/bill/BillOrderMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/bill/BillOrderMapper.java @@ -5,6 +5,8 @@ import java.util.List; import org.apache.ibatis.annotations.Param; import com.alibaba.fastjson.JSONObject; +import com.github.miemiedev.mybatis.paginator.domain.PageBounds; +import com.github.miemiedev.mybatis.paginator.domain.PageList; import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper; import cn.yixblog.support.mybatis.autosql.annotations.AutoSql; @@ -31,5 +33,9 @@ public interface BillOrderMapper { @AutoSql(type = SqlType.SELECT) List findByBillId(@Param("bill_id") String bill_id); - List query(@Param("bill_id") String bill_id, @Param("param") JSONObject jsonObject); + PageList query(@Param("bill_id") String bill_id, @Param("param") JSONObject jsonObject, PageBounds pageBounds); + + PageList queryWithWechatInfo(@Param("bill_id") String bill_id, @Param("param") JSONObject jsonObject, PageBounds pageBounds); + + JSONObject analysis(@Param("bill_id")String bill_id,@Param("param")JSONObject jsonObject); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml index efa7dd02d..0911155ef 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml @@ -3,9 +3,10 @@ + + + \ No newline at end of file