|
|
@@ -2,6 +2,11 @@ package com.uas.platform.b2c.logistics.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.platform.b2c.common.account.model.TradeLog;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.core.support.log.TradeBufferedLogger;
|
|
|
+import com.uas.platform.b2c.core.utils.DoubleArith;
|
|
|
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
+import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
import com.uas.platform.b2c.logistics.dao.InvoiceFOrderDao;
|
|
|
import com.uas.platform.b2c.logistics.model.InvoiceFOrder;
|
|
|
import com.uas.platform.b2c.logistics.model.InvoiceFOrderDetail;
|
|
|
@@ -9,25 +14,24 @@ import com.uas.platform.b2c.logistics.model.Logistics;
|
|
|
import com.uas.platform.b2c.logistics.service.InvoiceFOrderDetailService;
|
|
|
import com.uas.platform.b2c.logistics.service.InvoiceFOrderService;
|
|
|
import com.uas.platform.b2c.logistics.service.LogisticsPortService;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
|
|
|
+import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
import com.uas.platform.b2c.trade.order.dao.OrderDao;
|
|
|
import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
import com.uas.platform.b2c.trade.order.model.OrderDetail;
|
|
|
import com.uas.platform.b2c.trade.order.service.OrderService;
|
|
|
-import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
-import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
-import com.uas.platform.b2c.core.support.log.TradeBufferedLogger;
|
|
|
-import com.uas.platform.b2c.core.utils.DoubleArith;
|
|
|
-import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
-import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
+import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
+import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
import com.uas.platform.b2c.trade.util.TradeLogUtil;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
import com.uas.platform.core.model.EncodingRulesConstant;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.Status;
|
|
|
-import com.uas.platform.core.model.Type;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
@@ -41,11 +45,7 @@ import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class InvoiceFOrderServiceImpl implements InvoiceFOrderService {
|
|
|
@@ -301,6 +301,174 @@ public class InvoiceFOrderServiceImpl implements InvoiceFOrderService {
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2016年3月7日 下午2:05:34
|
|
|
+ * 存放订单号,快递信息,发货地址信息 批量转出货单
|
|
|
+ *
|
|
|
+ * @param json 批量转出的map
|
|
|
+ * @param id 订单id
|
|
|
+ * @return string 返回结果描述
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap orderShip(String json, Long id) {
|
|
|
+ if (StringUtils.isEmpty(json)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "发货信息为空");
|
|
|
+ }
|
|
|
+ if (id == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "订单信息为空");
|
|
|
+ }
|
|
|
+ Order order = orderDao.findOne(id);
|
|
|
+ if (order == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "找不到对应订单信息");
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = FastjsonUtils.parseObject(json);
|
|
|
+ String shipList = jsonObject.getString("map");
|
|
|
+ if (org.apache.commons.lang.StringUtils.isEmpty(shipList)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "发货明细缺失");
|
|
|
+ }
|
|
|
+ Map<Long, Double> map = FlexJsonUtils.fromJson(shipList, Map.class);
|
|
|
+ if (MapUtils.isEmpty(map)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "发货明细缺失");
|
|
|
+ }
|
|
|
+ InvoiceFOrder thisFor = null;
|
|
|
+ ResultMap resultMap = createInvoiceFromOrder(order, map);
|
|
|
+ if (resultMap.getCode() == CodeType.OK.code()) {
|
|
|
+ thisFor = (InvoiceFOrder) resultMap.getData();
|
|
|
+ } else {
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ String addr = String.valueOf(jsonObject.get("jsonSdAddress"));
|
|
|
+ String logistic = String.valueOf(jsonObject.get("logistics"));
|
|
|
+ String logisticsCompany = String.valueOf(jsonObject.get("companyName"));
|
|
|
+ if (StringUtils.isEmpty(addr)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "操作不当,发货地址信息为空,请添加相应的信息");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(logistic)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "操作不当,快递信息为空,请添加相应的信息");
|
|
|
+ }
|
|
|
+ Logistics loList = FastjsonUtils.fromJson(logistic, Logistics.class);
|
|
|
+ thisFor.setLogistics(loList);
|
|
|
+ Long uu = SystemSession.getUser().getUserUU();
|
|
|
+ thisFor.setStatusInBound(uu);
|
|
|
+ thisFor.setJsonSdAddress(addr);
|
|
|
+ Set<InvoiceFOrderDetail> invoiceFOrderDetails = thisFor.getInvoiceFOrderDetails();
|
|
|
+ for (InvoiceFOrderDetail invoiceFOrderDetail : invoiceFOrderDetails) {
|
|
|
+ if (invoiceFOrderDetail.getStatus().intValue() == Status.TOBESHIPPED.value()) {
|
|
|
+ invoiceFOrderDetail.setStatus(Status.INBOUND.value());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ InvoiceFOrder inF = inForDao.save(thisFor);
|
|
|
+
|
|
|
+ // 提交订单到邮政物流接口
|
|
|
+ if ("邮政国内".equals(logisticsCompany)) {
|
|
|
+ String EMS = LogisticsPortservice.newOrderMailNo(json);
|
|
|
+ if (EMS != "success") {
|
|
|
+ throw new IllegalAccessError("邮政接口调用出错");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setLgtId(inF.getLogistics().getId());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ order.setDeliverTime(sdf.format(new Date()));
|
|
|
+ order.setJsonSdAddress(addr);
|
|
|
+ Set<OrderDetail> orderDetails = order.getOrderDetails();
|
|
|
+ if (NumberUtil.compare(order.getQty(), order.getShipQty()) < 1) {
|
|
|
+ for (OrderDetail orderDetail : orderDetails) {
|
|
|
+ if (orderDetail.getStatus().intValue() == Status.SENDING.value()) {
|
|
|
+ orderDetail.setStatusInBound(uu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setStatusInBound(uu);
|
|
|
+ }
|
|
|
+ orderDao.save(order);
|
|
|
+ return ResultMap.success(inF);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据Order生成平台出货单,并进行发货动作
|
|
|
+ * @param order 订单
|
|
|
+ * @param order 需要发货的订单
|
|
|
+ */
|
|
|
+ private ResultMap createInvoiceFromOrder(Order order, Map<Long, Double> map) {
|
|
|
+ if (order == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "找不到对应订单");
|
|
|
+ }
|
|
|
+ if (MapUtils.isEmpty(map)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "发货明细为空");
|
|
|
+ }
|
|
|
+ Long userUU = SystemSession.getUser().getUserUU();
|
|
|
+ String invoiceId = EncodingRulesConstant.INVOICE_FROMORDER.replace("_TIMESTAP_NUMBER",
|
|
|
+ createNumberService.getTimeNumber("trade$invoice_fmor", 8));
|
|
|
+ InvoiceFOrder invoice = new InvoiceFOrder(order, invoiceId);
|
|
|
+ Short detno = 1;
|
|
|
+ Double taxes = 0d;
|
|
|
+ Double prices = 0d;
|
|
|
+ Double number = 0d;
|
|
|
+ Double ensurePrice = 0.0d;
|
|
|
+ // 生成平台发货单明细
|
|
|
+ Set<InvoiceFOrderDetail> iDetails = new HashSet<>();
|
|
|
+ Set<String> iDetailIds = new HashSet<>();
|
|
|
+ Double qty = 0.0d;
|
|
|
+ for (OrderDetail orDetail : order.getOrderDetails()) {
|
|
|
+ qty = 0.0d;
|
|
|
+ qty = map.get(orDetail.getId());
|
|
|
+ if ((Status.SHIPPED.value() != orDetail.getStatus()) || (NumberUtil.compare(qty, DoubleConstant.zero) < 1)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Double[] arr = new Double[]{orDetail.getShipQty(), qty};
|
|
|
+ double remaider = NumberUtil.sub(orDetail.getNumber(), arr);
|
|
|
+ if (NumberUtil.compare(remaider, DoubleConstant.zero) < 1) {
|
|
|
+ throw new IllegalOperatorException("型号为" + orDetail.getCmpCode() + "的明细发货数大于待发货数");
|
|
|
+ }
|
|
|
+ String detailId = EncodingRulesConstant.INVOICE_DETAIL_FROMORDER.replace("_TIMESTAP_NUMBER",
|
|
|
+ createNumberService.getTimeNumber("trade$invoice_fmor_dt", 9));
|
|
|
+ InvoiceFOrderDetail invoiceDetail = new InvoiceFOrderDetail(orDetail, detailId, qty);
|
|
|
+ invoiceDetail.setDetno(detno++);
|
|
|
+ taxes = DoubleArith.add(taxes, invoiceDetail.getTaxes());
|
|
|
+ prices = DoubleArith.add(prices, invoiceDetail.getPrice());
|
|
|
+ number = DoubleArith.add(number, invoiceDetail.getNumber());
|
|
|
+ ensurePrice = DoubleArith.add(ensurePrice, invoiceDetail.getEnsurePrice());
|
|
|
+ invoiceDetail.setInvoiceFOrder(invoice);
|
|
|
+ iDetails.add(invoiceDetail);
|
|
|
+ orDetail.setInfdetailid(detailId);
|
|
|
+ iDetailIds.add(detailId);
|
|
|
+
|
|
|
+ orDetail.setShipQty(NumberUtil.add(orDetail.getShipQty(), qty));
|
|
|
+ if (NumberUtil.compare(orDetail.getNumber(), orDetail.getShipQty()) < 1) {
|
|
|
+ orDetail.setStatusSending(userUU);
|
|
|
+ }
|
|
|
+ order.setShipQty(NumberUtil.add(order.getShipQty(), qty));
|
|
|
+ }
|
|
|
+ //设置配送规则和自提点信息
|
|
|
+ if (order.getJsonRule() != null){
|
|
|
+ invoice.setJsonRule(order.getJsonRule());
|
|
|
+ }
|
|
|
+ if (order.getJsonTakeSelf() != null){
|
|
|
+ invoice.setJsonTakeSelf(order.getJsonTakeSelf());
|
|
|
+ }
|
|
|
+ invoice.setTaxes(taxes);
|
|
|
+ invoice.setPrice(prices);
|
|
|
+ invoice.setNumber(number);
|
|
|
+ invoice.setEnsurePrice(ensurePrice);
|
|
|
+ invoice.setTobeshipped(userUU);
|
|
|
+ invoice.setInvoiceFOrderDetails(iDetails);
|
|
|
+ invoice.setInforRemark(order.getOrderRemark());
|
|
|
+ invoice.setDeliveryType(order.getDeliverytype());
|
|
|
+
|
|
|
+ if (invoice.getUasPurcid() != null) {
|
|
|
+ // 手动将平台状态改成202(要考虑一点,UAS和平台做的单据是否都可以这样做)
|
|
|
+ invoice.setSendstatus(Status.NOT_UPLOAD.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新订单及明细的状态信息
|
|
|
+ if (NumberUtil.compare(order.getQty(), order.getShipQty()) < 1) {
|
|
|
+ order.setStatusSending(userUU);
|
|
|
+ }
|
|
|
+ order.setInid(invoice.getInvoiceid());
|
|
|
+ return ResultMap.success(invoice);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据订单生成平台出货单及其明细信息,并保存出货单和修改订单状态信息
|
|
|
* Created by huxz 2017-1-13 15:39:40
|