|
|
@@ -1,15 +1,19 @@
|
|
|
package com.uas.platform.b2c.fa.settlement.service.impl;
|
|
|
|
|
|
+import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.constant.SplitChar;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
+import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
import com.uas.platform.b2c.fa.settlement.dao.BillDao;
|
|
|
import com.uas.platform.b2c.fa.settlement.dao.BillSubmitDao;
|
|
|
import com.uas.platform.b2c.fa.settlement.model.Bill;
|
|
|
import com.uas.platform.b2c.fa.settlement.model.BillSubmit;
|
|
|
import com.uas.platform.b2c.fa.settlement.service.BillSubmitService;
|
|
|
import com.uas.platform.b2c.trade.order.dao.OrderDao;
|
|
|
+import com.uas.platform.b2c.trade.order.dao.PurchaseDao;
|
|
|
import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
+import com.uas.platform.b2c.trade.order.model.Purchase;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.Status;
|
|
|
@@ -19,6 +23,7 @@ import com.uas.platform.core.persistence.criteria.LogicalExpression;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
@@ -45,11 +50,17 @@ public class BillSubmitServiceImpl implements BillSubmitService {
|
|
|
|
|
|
private final BillSubmitDao billSubmitDao;
|
|
|
|
|
|
+ private final PurchaseDao purchaseDao;
|
|
|
+
|
|
|
+ private final SysConf sysConf;
|
|
|
+
|
|
|
@Autowired
|
|
|
- public BillSubmitServiceImpl (OrderDao orderDao, BillDao billDao, BillSubmitDao billSubmitDao) {
|
|
|
+ public BillSubmitServiceImpl(OrderDao orderDao, BillDao billDao, BillSubmitDao billSubmitDao, PurchaseDao purchaseDao, SysConf sysConf) {
|
|
|
this.orderDao = orderDao;
|
|
|
this.billDao = billDao;
|
|
|
this.billSubmitDao = billSubmitDao;
|
|
|
+ this.purchaseDao = purchaseDao;
|
|
|
+ this.sysConf = sysConf;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -97,12 +108,17 @@ public class BillSubmitServiceImpl implements BillSubmitService {
|
|
|
} else {
|
|
|
map.get(order.getSellerenuu()).add(order);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
List<BillSubmit> billSubmits = new ArrayList<BillSubmit>();
|
|
|
for (Long sellerenuu : map.keySet()) {
|
|
|
- BillSubmit billSubmit = createBillSubmit(bill, map.get(sellerenuu), buyerEnuu);
|
|
|
- billSubmits.add(billSubmit);
|
|
|
+ List<BillSubmit> billSubmitList = new ArrayList<>();
|
|
|
+ billSubmitList.add(createBillSubmit(bill, map.get(sellerenuu), buyerEnuu));
|
|
|
+ if (sellerenuu.longValue() == sysConf.getEnUU().longValue()) {
|
|
|
+ billSubmitList.addAll(createBillSubmitByPurchase(map.get(sellerenuu)));
|
|
|
+ }
|
|
|
+ if (billSubmitList != null) {
|
|
|
+ billSubmits.addAll(billSubmitList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return billSubmitDao.save(billSubmits);
|
|
|
@@ -113,52 +129,133 @@ public class BillSubmitServiceImpl implements BillSubmitService {
|
|
|
Long buyeruu = SystemSession.getUser().getUserUU();
|
|
|
// 发票基本信息
|
|
|
BillSubmit billSubmit = new BillSubmit();
|
|
|
- billSubmit.setInvoicetitle(bill.getHead());
|
|
|
- billSubmit.setInvoiceid(bill.getId());
|
|
|
- billSubmit.setInvoiceAddress(bill.getArea() + "," + bill.getDetailAddress());
|
|
|
- billSubmit.setInvoicetype(bill.getKind());
|
|
|
- billSubmit.setCreateTime(new Date());
|
|
|
- billSubmit.setReceiverName(bill.getName());
|
|
|
- billSubmit.setRecTel(bill.getTelephone());
|
|
|
- billSubmit.setStatus(Status.SUBMITTED.value());
|
|
|
- billSubmit.setSubmituu(SystemSession.getUser().getUserUU());
|
|
|
- billSubmit.setBillInfo(FastjsonUtils.toJson(bill));
|
|
|
- if (SystemSession.getUser().getEnterprise() != null)
|
|
|
- billSubmit.setSubmitEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ billSubmit.setBillInfo(bill);
|
|
|
|
|
|
String orderIds = "";
|
|
|
+ String purchaseIds = "";
|
|
|
Double price = 0d;
|
|
|
for (int i = 0; i < orders.size(); i++) {
|
|
|
- if (buyerEnuu != null) {
|
|
|
Order order = orders.get(i);
|
|
|
- if (buyerEnuu.equals(order.getBuyerenuu()) && buyeruu.equals(order.getBuyeruu())) {
|
|
|
- billSubmit.setSellername(order.getSellername());
|
|
|
- billSubmit.setSellerenuu(order.getSellerenuu());
|
|
|
- billSubmit.setStoreid(order.getStoreid());
|
|
|
+ if ((buyerEnuu == null && order.getBuyerenuu() == null)|| (buyerEnuu != null && buyerEnuu.equals(order.getBuyerenuu())) && buyeruu.equals(order.getBuyeruu())) {
|
|
|
order.setInvoicetype(bill.getKind());
|
|
|
- order.setInvoiceAddress(bill.getArea() + "," + bill.getDetailAddress());
|
|
|
+ order.setInvoiceAddress(FastjsonUtils.toJson(bill));
|
|
|
order.setInvoiceid(bill.getId());
|
|
|
order.setInvoicetitle(bill.getHead());
|
|
|
order.setVatBillStatus(Status.TOBEMAKE_BILL.value());
|
|
|
orderDao.save(order);
|
|
|
- price += order.getPrice();
|
|
|
+
|
|
|
+ price = NumberUtil.add(order.getPrice(), price);
|
|
|
+
|
|
|
+ List<Purchase> purchases = purchaseDao.findByOrderid(order.getOrderid());
|
|
|
+ for (Purchase purchase : purchases) {
|
|
|
+ if (order.getSellerenuu().longValue() != sysConf.getEnUU().longValue()) {
|
|
|
+ //自营店订单
|
|
|
+ purchase.setInvoicetitle(bill.getHead());
|
|
|
+ purchase.setInvoicetype(bill.getKind());
|
|
|
+ purchase.setInvoiceAddress(FastjsonUtils.toJson(bill));
|
|
|
+ purchase.setInvoicetitle(bill.getHead());
|
|
|
+ purchase.setVatBillStatus(Status.TOBEMAKE_BILL.value());
|
|
|
+ purchaseDao.save(purchase);
|
|
|
+ }
|
|
|
+ purchaseIds += ("," + purchase.getPurchaseid());
|
|
|
+ }
|
|
|
orderIds += order.getOrderid();
|
|
|
if (i < orders.size() - 1)
|
|
|
orderIds += SplitChar.COMMA;
|
|
|
} else {
|
|
|
throw new IllegalOperatorException("订单号: " + order.getOrderid() + " ,不属于您的订单,请重新确认订单号");
|
|
|
}
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
+ billSubmit.setCurrency(orders.get(0).getCurrency());
|
|
|
+ billSubmit.setSellername(orders.get(0).getSellername());
|
|
|
+ billSubmit.setSellerenuu(orders.get(0).getSellerenuu());
|
|
|
+ billSubmit.setStoreid(orders.get(0).getStoreid());
|
|
|
+ billSubmit.setDissociative(orders.get(0).getDissociative());
|
|
|
billSubmit.setPrice(price);
|
|
|
billSubmit.setOrderids(orderIds);
|
|
|
+ if (StringUtils.isEmpty(purchaseIds)){
|
|
|
+ billSubmit.setPurchaseids(purchaseIds);
|
|
|
+ } else {
|
|
|
+ billSubmit.setPurchaseids(purchaseIds.substring(1));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
return billSubmit;
|
|
|
}
|
|
|
|
|
|
+ // 初始化发票申请(用户发起用)
|
|
|
+ public List<BillSubmit> createBillSubmitByPurchase(List<Order> orders) {
|
|
|
+ if (CollectionUtils.isEmpty(orders)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<Bill> billOne = billDao.getBillByUseruuAndEnuuAndKind(sysConf.getAdminUU(), sysConf.getEnUU(),Type.Bill_Deduct.value());
|
|
|
+ if (CollectionUtils.isEmpty(billOne)) {
|
|
|
+ throw new IllegalOperatorException("商城专票信息被删除,请联系商城管理员添加");
|
|
|
+ }
|
|
|
+ // 发票基本信息
|
|
|
+ List<Purchase> purchaseList = new ArrayList<>();
|
|
|
+ for (Order order : orders) {
|
|
|
+ List<Purchase> purchases = purchaseDao.findByOrderid(order.getOrderid());
|
|
|
+ purchaseList.addAll(purchases);
|
|
|
+ }
|
|
|
+ Map<Long, List<Purchase>> map = new HashedMap();
|
|
|
+ for (Purchase purchase : purchaseList) {
|
|
|
+ //同一个卖家的汇总
|
|
|
+ List<Purchase> purchaseList1 = map.get(purchase.getSellerenuu());
|
|
|
+ if (purchaseList1 == null) {
|
|
|
+ purchaseList1 = new ArrayList<>();
|
|
|
+ }
|
|
|
+ purchaseList1.add(purchase);
|
|
|
+ map.put(purchase.getSellerenuu(), purchaseList1);
|
|
|
+ }
|
|
|
+ List<BillSubmit> list = new ArrayList<>();
|
|
|
+ Set<Long> longSet = map.keySet();
|
|
|
+ Double price = 0d;
|
|
|
+ String orderIds = "";
|
|
|
+ String purchaseIds = "";
|
|
|
+ for (Long enuu : longSet) {
|
|
|
+ List<Purchase> purchases = map.get(enuu);
|
|
|
+ BillSubmit billSubmit = new BillSubmit();
|
|
|
+ Bill bill = billOne.get(0);
|
|
|
+ billSubmit.setBillInfo(bill);
|
|
|
+ price = 0d;
|
|
|
+ orderIds = "";
|
|
|
+ purchaseIds = "";
|
|
|
+ for (Purchase purchase : purchases) {
|
|
|
+ purchase.setInvoicetitle(bill.getHead());
|
|
|
+ purchase.setInvoicetype(bill.getKind());
|
|
|
+ purchase.setInvoiceAddress(FastjsonUtils.toJson(bill));
|
|
|
+ purchase.setInvoicetitle(bill.getHead());
|
|
|
+ purchase.setVatBillStatus(Status.TOBEMAKE_BILL.value());
|
|
|
+ orderIds += ("," + purchase.getOrderid());
|
|
|
+ purchaseIds += ("," + purchase.getPurchaseid());
|
|
|
+ NumberUtil.add(purchase.getPrice(), price);
|
|
|
+ }
|
|
|
+ billSubmit.setCurrency(purchases.get(0).getCurrency());
|
|
|
+ billSubmit.setSubmituu(sysConf.getAdminUU());
|
|
|
+ billSubmit.setSubmitEnuu(sysConf.getEnUU());
|
|
|
+ billSubmit.setSellername(purchases.get(0).getSellername());
|
|
|
+ billSubmit.setSellerenuu(purchases.get(0).getSellerenuu());
|
|
|
+ billSubmit.setStoreid(purchases.get(0).getStoreid());
|
|
|
+ billSubmit.setDissociative(Type.ENTERPRISING.value());
|
|
|
+ billSubmit.setPrice(price);
|
|
|
+ if (StringUtils.isEmpty(orderIds)) {
|
|
|
+ billSubmit.setOrderids(orderIds);
|
|
|
+ } else {
|
|
|
+ billSubmit.setOrderids(orderIds.substring(1));
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(purchaseIds)) {
|
|
|
+ billSubmit.setPurchaseids(purchaseIds);
|
|
|
+ } else {
|
|
|
+ billSubmit.setPurchaseids(purchaseIds.substring(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ list.add(billSubmit);
|
|
|
+
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public BillSubmit saveByAdmin(Order order) {
|
|
|
Bill bill = billDao.findOne(order.getInvoiceid());
|
|
|
@@ -167,20 +264,13 @@ public class BillSubmitServiceImpl implements BillSubmitService {
|
|
|
}
|
|
|
|
|
|
// 发票基本信息
|
|
|
+ List<BillSubmit> list = new ArrayList<>();
|
|
|
BillSubmit billSubmit = new BillSubmit();
|
|
|
- billSubmit.setBillInfo(FastjsonUtils.toJson(bill));
|
|
|
- billSubmit.setInvoicetitle(bill.getHead());
|
|
|
- billSubmit.setInvoiceid(bill.getId());
|
|
|
- billSubmit.setInvoiceAddress(bill.getArea() + "," + bill.getDetailAddress());
|
|
|
- billSubmit.setInvoicetype(bill.getKind());
|
|
|
- billSubmit.setCreateTime(new Date());
|
|
|
- billSubmit.setReceiverName(bill.getName());
|
|
|
- billSubmit.setRecTel(bill.getTelephone());
|
|
|
- billSubmit.setStatus(Status.SUBMITTED.value());
|
|
|
+ billSubmit.setBillInfo(bill);
|
|
|
billSubmit.setSubmituu(order.getBuyeruu());
|
|
|
if (order.getBuyerenuu() != null)
|
|
|
billSubmit.setSubmitEnuu(order.getBuyerenuu());
|
|
|
-
|
|
|
+ billSubmit.setCurrency(order.getCurrency());
|
|
|
billSubmit.setSellername(order.getSellername());
|
|
|
billSubmit.setSellerenuu(order.getSellerenuu());
|
|
|
billSubmit.setStoreid(order.getStoreid());
|
|
|
@@ -191,19 +281,42 @@ public class BillSubmitServiceImpl implements BillSubmitService {
|
|
|
order.setInvoicetitle(bill.getHead());
|
|
|
order.setVatBillStatus(Status.TOBEMAKE_BILL.value());
|
|
|
orderDao.save(order);
|
|
|
-
|
|
|
+ String purchaseIds = "";
|
|
|
+ List<Purchase> purchases = purchaseDao.findByOrderid(order.getOrderid());
|
|
|
+ for (Purchase purchase : purchases) {
|
|
|
+ purchaseIds += purchase.getPurchaseid();
|
|
|
+ purchase.setInvoicetitle(bill.getHead());
|
|
|
+ purchase.setInvoicetype(bill.getKind());
|
|
|
+ purchase.setInvoiceAddress(FastjsonUtils.toJson(bill));
|
|
|
+ purchase.setInvoicetitle(bill.getHead());
|
|
|
+ purchase.setVatBillStatus(Status.TOBEMAKE_BILL.value());
|
|
|
+ }
|
|
|
+ purchaseDao.save(purchases);
|
|
|
+ if (order.getSellerenuu().longValue() == sysConf.getEnUU().longValue()) {
|
|
|
+ List<Order> orderList = new ArrayList<>();
|
|
|
+ orderList.add(order);
|
|
|
+ list.addAll(createBillSubmitByPurchase(orderList));
|
|
|
+ }
|
|
|
+ billSubmit.setPurchaseids(purchaseIds);
|
|
|
billSubmit.setPrice(order.getPrice());
|
|
|
billSubmit.setOrderids(order.getOrderid());
|
|
|
+ billSubmit.setDissociative(order.getDissociative());
|
|
|
+ BillSubmit submit = billSubmitDao.save(billSubmit);
|
|
|
+ billSubmitDao.save(list);
|
|
|
|
|
|
- return billSubmitDao.save(billSubmit);
|
|
|
+ return submit;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Page<BillSubmit> getAll(final PageInfo pageInfo, String keyword, String invoicetype , String status, String role) {
|
|
|
if (Type.BUYER.name().equals(role)) {
|
|
|
pageInfo.expression(PredicateUtils.eq("submituu", SystemSession.getUser().getUserUU(), false));
|
|
|
- if (SystemSession.getUser().getEnterprise() != null)
|
|
|
+ if (SystemSession.getUser().getEnterprise() != null) {
|
|
|
pageInfo.expression(PredicateUtils.eq("submitEnuu", SystemSession.getUser().getEnterprise().getUu(), false));
|
|
|
+ } else {
|
|
|
+ pageInfo.expression(PredicateUtils.eq("dissociative", Type.PERSONAL.value(), false));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (Type.SELLER.name().equals(role)) {
|