Browse Source

处理分批发货的问题

yuj 7 years ago
parent
commit
cc84222ac2

+ 22 - 0
src/main/java/com/uas/platform/b2c/core/utils/NumberUtil.java

@@ -230,6 +230,28 @@ public class NumberUtil {
 		return b1.subtract(b2).doubleValue();
 	}
 
+
+	/**
+	 * Double型减法运算
+	 *
+	 * @param d1
+	 *            被减数
+	 * @param ds
+	 *            减数
+	 * @return 运算结果
+	 * @author suntg
+	 */
+	public static double sub(Double d1, Double... ds) {
+		d1 = d1 == null ? 0d : d1;
+		BigDecimal b1 = new BigDecimal(Double.toString(d1));
+		BigDecimal b2 = null;
+		for (Double d : ds) {
+			b2 = new BigDecimal(Double.toString(d));
+			b1 = b1.subtract(b2);
+		}
+		return b1.doubleValue();
+	}
+
 	/**
 	 * Double 乘法运算
 	 * 

+ 2 - 3
src/main/java/com/uas/platform/b2c/logistics/controller/InvoiceFPurchaseController.java

@@ -249,16 +249,15 @@ public class InvoiceFPurchaseController {
 	 * 保存出货单信息
 	 *
 	 * @param json the json 对象json字符串
-	 * @param id   the id 单号
+	 * @param id   the id 采购单号
 	 * @return ResultMap 返回结果集
 	 * @throws OperationsException the operations exception
 	 */
 	@RequestMapping(value = "/inFpu/save", method = RequestMethod.POST)
 	@ApiOperation(value = "保存出货单信息", httpMethod = "POST")
 	public ResultMap saveInvoiceFP(@ApiParam(required = true, value = "对象json字符串") @RequestBody String json, @ApiParam(required = true, value = "单号") Long id) throws OperationsException {
-		JSONObject sendInfo = FastjsonUtils.fromJson(json, JSONObject.class);
 		logger.log("平台出货单管理", "保存出货单信息", "保存出货单信息 流水号:" + id + ", 操作人:" + SystemSession.getUser().getUserUU() + "-" + SystemSession.getUser().getUserName());
-		return inFpuService.saveInvoiceFPurchaseList(sendInfo, id);
+		return inFpuService.ship(json, id);
 	}
 
 	/**

+ 39 - 2
src/main/java/com/uas/platform/b2c/logistics/model/InvoiceFPurchaseDetail.java

@@ -1,6 +1,8 @@
 package com.uas.platform.b2c.logistics.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2c.core.utils.NumberUtil;
+import com.uas.platform.b2c.prod.store.model.QualificationType;
 import com.uas.platform.b2c.trade.order.model.PurchaseDetail;
 import com.uas.platform.core.exception.IllegalStatusException;
 import com.uas.platform.core.persistence.StatusColumn;
@@ -266,8 +268,43 @@ public class InvoiceFPurchaseDetail {
 		this.currencyName = puDetail.getCurrencyName();
 		this.tax = puDetail.getTax();
 		this.returnInWeek = puDetail.getReturnInWeek();
-		this.returnQty = puDetail.getReturnQty();
-		this.changeQty = puDetail.getChangeQty();
+		this.b2cMinDelivery = puDetail.getB2cMinDelivery();
+		this.b2cMaxDelivery = puDetail.getB2cMaxDelivery();
+		this.remark = puDetail.getRemark();
+		this.goodsnumber = puDetail.getGoodsnumber();
+	}
+
+	/**
+	 * 根据采购单明细生成发货单明细
+	 *
+	 * @param puDetail 采购单明细
+	 */
+	public InvoiceFPurchaseDetail(PurchaseDetail puDetail, Double qty) {
+		if (puDetail == null) {
+			throw new IllegalStatusException("采购单明细已失效");
+		}
+		this.pudetailid = puDetail.getId();
+		this.batchCode = puDetail.getBatchCode();
+		this.uuid = puDetail.getUuid();
+		this.original = puDetail.getOriginal();
+		this.cmpCode = puDetail.getCmpCode();
+		this.kiName = puDetail.getKiName();
+		this.kindUuid = puDetail.getKindUuid();
+		this.brName = puDetail.getBrName();
+		this.brandNameCn = puDetail.getBrandNameCn();
+		this.branduuid = puDetail.getBranduuid();
+		this.brandid = puDetail.getBrandid();
+		this.img = puDetail.getImg();
+		this.unitprice = puDetail.getUnitprice();
+		this.taxUnitPrice = puDetail.getTaxUnitPrice();
+		this.number = qty;
+		this.taxes = puDetail.getTaxes();
+		this.price = NumberUtil.mul(qty, this.taxUnitPrice);
+		this.ensurePrice = this.price;
+		this.transationPrice = this.price;
+		this.currencyName = puDetail.getCurrencyName();
+		this.tax = puDetail.getTax();
+		this.returnInWeek = puDetail.getReturnInWeek();
 		this.b2cMinDelivery = puDetail.getB2cMinDelivery();
 		this.b2cMaxDelivery = puDetail.getB2cMaxDelivery();
 		this.remark = puDetail.getRemark();

+ 21 - 1
src/main/java/com/uas/platform/b2c/logistics/service/InvoiceFPurchaseService.java

@@ -1,9 +1,11 @@
 package com.uas.platform.b2c.logistics.service;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.management.OperationsException;
 
+import com.uas.platform.b2c.trade.order.model.Purchase;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import org.springframework.data.domain.Page;
 
@@ -42,7 +44,16 @@ public interface InvoiceFPurchaseService {
 	 * @param puid the puid 采购单号
 	 * @return InvoiceFPurchase 返回InvoiceFPurchase对象
 	 */
-	public InvoiceFPurchase createInvoiceFPurchase(Long puid);
+	InvoiceFPurchase createInvoiceFPurchase(Long puid);
+
+	/**
+	 * 采购转出货
+	 *
+	 * @param purchase the puid 采购单号\
+	 * @param shipList 发货信息
+	 * @return InvoiceFPurchase 返回InvoiceFPurchase对象
+	 */
+	InvoiceFPurchase createInvoiceFPurchase(Purchase purchase, List<Map<Long, Double>> shipList);
 
 	/**
 	 * 查找待出货
@@ -157,4 +168,13 @@ public interface InvoiceFPurchaseService {
 	 * @throws OperationsException the operations exception
 	 */
 	public void sendFErp(Invoice invoice) throws OperationsException;
+
+
+	/**
+	 * 卖家发货
+	 * @param shiInfo 发货信息,
+	 * @param id 采购单信息
+	 * @return 返回发货单
+	 */
+	ResultMap ship(String shiInfo, Long id);
 }

+ 1 - 1
src/main/java/com/uas/platform/b2c/logistics/service/impl/InvoiceFOrderServiceImpl.java

@@ -228,7 +228,7 @@ public class InvoiceFOrderServiceImpl implements InvoiceFOrderService {
 		inFor = inForDao.save(inFor);
 		/**
 		 * 改写订单单关联属性及状态
-		 * 
+		 *
 		 * @TODO 这里是用OneToOne还是什么有待考究
 		 */
 		// 判断关联的出货单是否为待收货状态

+ 240 - 55
src/main/java/com/uas/platform/b2c/logistics/service/impl/InvoiceFPurchaseServiceImpl.java

@@ -18,7 +18,13 @@ import com.uas.platform.b2c.logistics.model.InvoiceFPurchaseDetail;
 import com.uas.platform.b2c.logistics.model.Logistics;
 import com.uas.platform.b2c.logistics.service.InvoiceFPurchaseService;
 import com.uas.platform.b2c.logistics.service.LogisticsOldService;
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
+import com.uas.platform.b2c.prod.commodity.model.CommodityInOutbound;
+import com.uas.platform.b2c.prod.commodity.model.InOutboundDetail;
+import com.uas.platform.b2c.prod.commodity.model.Product;
+import com.uas.platform.b2c.prod.commodity.service.CommodityInOutboundService;
 import com.uas.platform.b2c.prod.commodity.service.ProductService;
+import com.uas.platform.b2c.prod.commodity.type.InOutBoundType;
 import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
 import com.uas.platform.b2c.trade.aftersale.model.AfterSaleStatus;
 import com.uas.platform.b2c.trade.order.dao.OrderDao;
@@ -37,6 +43,9 @@ import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.Status;
 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 com.uas.sso.util.FlexJsonUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
@@ -49,6 +58,7 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
+import java.beans.beancontext.BeanContextMembershipListener;
 import java.util.*;
 
 @Service
@@ -72,6 +82,8 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 
 	private final ProductService productService;
 
+	private final CommodityInOutboundService commodityInOutboundService;
+
 	private static final TradeBufferedLogger logger = BufferedLoggerManager
 			.getLogger(TradeBufferedLogger.class);
 
@@ -80,7 +92,7 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 	@Autowired
 	public InvoiceFPurchaseServiceImpl(InvoiceFPurchaseDao inFpuDao, CreateNumberService createNumberService,
 									   EnterpriseDao enterpriseDao, PurchaseDao purchaseDao, LogisticsDao logisticsDao,
-									   LogisticsCompanyCodeDao logisticsCompanyCodeDao, OrderDao orderDao, SysConf sysConf, LogisticsOldService logisticsService, ProductService productService) {
+									   LogisticsCompanyCodeDao logisticsCompanyCodeDao, OrderDao orderDao, SysConf sysConf, LogisticsOldService logisticsService, ProductService productService, CommodityInOutboundService commodityInOutboundService) {
 		this.inFpuDao = inFpuDao;
 		this.createNumberService = createNumberService;
 		this.enterpriseDao = enterpriseDao;
@@ -91,6 +103,7 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 		this.sysConf = sysConf;
 		this.logisticsService = logisticsService;
 		this.productService = productService;
+		this.commodityInOutboundService = commodityInOutboundService;
 	}
 
 	@Override
@@ -193,6 +206,132 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 		return inFpu;
 	}
 
+	/**
+	 * 采购转出货
+	 *
+	 * @param purchase     the puid 采购单号\
+	 * @param shipList
+	 * @return InvoiceFPurchase 返回InvoiceFPurchase对象
+	 */
+	@Override
+	public InvoiceFPurchase createInvoiceFPurchase(Purchase purchase, List<Map<Long, Double>> shipList) {
+		if (purchase == null) {
+			throw new IllegalOperatorException("传入信息为空");
+		}
+		if (purchase.getStatus() != Status.TOBESHIPPED.value() && purchase.getStatus() != Status.CONFIRMED.value()) {
+			throw new IllegalAccessError(
+					"采购单" + purchase.getPurchaseid() + "的状态是" + Status.valueOf(purchase.getStatus()).getPhrase() + ",不能转出货");
+		}
+		Long uu = SystemSession.getUser().getUserUU();
+		Date date = new Date();
+		InvoiceFPurchase inFpu = new InvoiceFPurchase(purchase);
+
+		//保存适用配送规则和自提点信息
+		if (purchase.getJsonRule() != null){
+			inFpu.setJsonRule(purchase.getJsonRule());
+		}
+		if (purchase.getJsonTakeSelf() != null){
+			inFpu.setJsonTakeSelf(purchase.getJsonTakeSelf());
+		}
+		// 生成出货单号
+		String invoiceid = createNumberService.generateVoucherId(EncodingRulesConstant.INVOICE_FROMPURCHASE,
+				"trade$invoice_fmpu", 8);
+		inFpu.setInvoiceid(invoiceid);
+		Double taxes = 0d;//税金
+		Double price = 0d;//价税合计
+		Double ensurePrice = 0D; //实际价格
+		Double number = 0d;//数量
+		Short detno = 1;
+
+		// 保存所有出货单明细编号ID
+		List<String> detailIds = new LinkedList<>();
+		Set<InvoiceFPurchaseDetail> IpDetails = new HashSet<>();
+
+		// 给明细赋值
+		Double qty = 0.0d;
+		Set<InOutboundDetail> inOutSet = new HashSet<>();
+		Product product = null;
+		InOutboundDetail inOutboundDetail = null;
+		for (PurchaseDetail puDetail : purchase.getPurchaseDetails()) {
+			// 如果当前采购单明细的状态不是待出货状态,则处理下一条明细是否转出货
+			qty = 0.0d;
+			for (Map<Long, Double> map : shipList) {
+				qty = map.get(puDetail.getId());
+			}
+			if (Status.TOBESHIPPED.value() != puDetail.getStatus() || NumberUtil.compare(qty, DoubleConstant.zero) < 1) {
+				continue;
+			}
+			product = productService.findProductByProdNum(puDetail.getGoodsnumber());
+			if (product == null) {
+				throw new IllegalOperatorException("找不到物料信息");
+			}
+			if (NumberUtil.compare(product.getErpReserve(), qty) < 0) {
+				throw new IllegalOperatorException("型号为" + product.getPcmpcode() + "的物料库存信息不足");
+			}
+			List<Double> qties = new ArrayList<>();
+			qties.add(puDetail.getShipQty());
+			qties.add(qty);
+			double remainder = NumberUtil.sub(puDetail.getNumber(), qty);
+			if (NumberUtil.compare(remainder, DoubleConstant.zero) < 0) {
+				throw new IllegalOperatorException("出货明细" + puDetail.getCmpCode() + "的出货数超过待出货数");
+			}
+			product.setErpReserve(NumberUtil.sub(product.getErpReserve(), qty));
+			productService.save(product);
+
+			inOutboundDetail = new InOutboundDetail(product, puDetail, qty);
+			inOutSet.add(inOutboundDetail);
+
+			InvoiceFPurchaseDetail inFpuD = new InvoiceFPurchaseDetail(puDetail, qty);
+			String detailId = createNumberService.generateVoucherId(EncodingRulesConstant.INVOICE_DETAIL_FROMPURCHASE,
+					"trade$invoice_fmpu_dt", 9);
+			inFpuD.setDetailid(detailId);
+			inFpuD.setDetno(detno++);
+			inFpuD.setInvoiceFPurchase(inFpu);
+			inFpuD.setStatus(Status.TOBESHIPPED.value());
+			inFpuD.setStoreid(puDetail.getStoreid());
+			puDetail.setInpdetailid(detailId);
+			puDetail.setShipQty(NumberUtil.add(puDetail.getShipQty(), qty));
+			purchase.setShipQty(NumberUtil.add(purchase.getShipQty(), qty));
+			detailIds.add(inFpuD.getDetailid());
+			IpDetails.add(inFpuD);
+			// 计算总金额、数量和税金
+			price = NumberUtil.add(price, NumberUtil.mul(qty, puDetail.getTaxUnitPrice()));
+			number = NumberUtil.add(number, qty);
+			ensurePrice = NumberUtil.add(ensurePrice, price);
+			taxes = NumberUtil.add(taxes, NumberUtil.sub(NumberUtil.mul(qty, puDetail.getTaxUnitPrice()), NumberUtil.mul(qty, puDetail.getUnitprice())));
+		}
+		Enterprise enterprise = enterpriseDao.findByUu(purchase.getSellerenuu());
+		if (enterprise == null) {
+			throw new IllegalOperatorException("该供应商不存在");
+		}
+		// 给属性赋值
+		inFpu.setCreattime(date);
+		inFpu.setSellername(enterprise.getEnName());
+		taxes = NumberUtil.pricesScaleTwo(taxes);
+		inFpu.setTaxes(taxes);
+		price = NumberUtil.pricesScaleTwo(price);
+		inFpu.setPrice(price);
+		//添加运费
+		ensurePrice = NumberUtil.add(ensurePrice, inFpu.getFare());
+		ensurePrice = NumberUtil.pricesScaleTwo(ensurePrice);
+		inFpu.setEnsurePrice(ensurePrice);
+		inFpu.setNumber(number);
+		inFpu.setStatusToBeShipped(uu);
+		inFpu.setInfpuRemark(purchase.getPurchaseRemark());
+		inFpu.setSendType(purchase.getSendType());
+		inFpu.setInvoiceFPurchaseDetails(IpDetails);
+
+		if (CollectionUtils.isNotEmpty(inOutSet)){
+			CommodityInOutbound commodityInOutbound = commodityInOutboundService.produceCommodityInOutbound(inOutSet, InOutBoundType.SELL_OUTBOUND);
+			if (commodityInOutbound != null) {
+				commodityInOutboundService.save(commodityInOutbound);
+			}
+		}
+		// 设置采购单关联属性
+		purchase.addInid(inFpu.getInvoiceid());
+		return inFpu;
+	}
+
 	@Override
 	public List<InvoiceFPurchase> findToBeShipped() {
 		return inFpuDao.findByStatus(Status.TOBESHIPPED.value());
@@ -254,12 +393,8 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 		Long userUU = SystemSession.getUser().getUserUU();
 		InvoiceFPurchase invoiceFPurchase = inFpuDao.getOne(id);
 		Purchase purchase = purchaseDao.findOne(invoiceFPurchase.getPuid());
-//		String deliveryType = sendInfo.getString("deliveryType");
 		Integer sendType = Integer.parseInt(sendInfo.getString("sendType"));
 
-//		if(StringUtils.isEmpty(deliveryType)) {
-//			return new ResultMap(CodeType.NO_INFO, "配送方式的信息为空,请重新操作");
-//		}
 		if (sendType == null){
 			return new ResultMap(CodeType.NO_INFO, "配送方式的信息为空,请重新操作");
 		}
@@ -278,31 +413,12 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 			Logistics logistics = logisticsService.bornLogisticsByCompanyNameAndNum(logisticsJson.getString("companyName"), logisticsJson.getString("number"));
 			invoiceFPurchase.setLogistics(logistics);
 		}
-//		if("logistics".equals(deliveryType)) {
-//			JSONObject  logisjson= sendInfo.getJSONObject("logisticsInfo");
-//			Logistics logistics = logisticsService.bornLogisticsByCompanyNameAndNum(logisjson.getString("companyName"), logisjson.getString("number"));
-//			invoiceFPurchase.setLogistics(logistics);
-//
-//		}else if("selfDelivery".equals(deliveryType)){
-//			JSONObject  logisticsJson= sendInfo.getJSONObject("selfDeliveryPerson");
-//			String name = logisticsJson.getString("name");
-//			if(StringUtils.isEmpty(name)) {
-//				return new ResultMap(CodeType.NO_INFO, "送货人信息为空,请重新操作");
-//			}
-//			String phone = logisticsJson.getString("phone");
-//			if(StringUtils.isEmpty(phone)) {
-//				return new ResultMap(CodeType.NO_INFO, "送货人电话信息为空,请重新操作");
-//			}
-//			invoiceFPurchase.setSelfDeliveryName(name);
-//			invoiceFPurchase.setSelfDeliveryPhone(phone);
-//		}
 
 		String jsonSdAddress = sendInfo.getString("jsonSdAddress");
 		if(StringUtils.isEmpty(jsonSdAddress)) {
 			return new ResultMap(CodeType.NO_INFO, "发货人的地址信息为空,请重新操作");
 		}
 		invoiceFPurchase.setJsonSdAddress(jsonSdAddress);
-//		invoiceFPurchase.setDeliveryType(deliveryType);
 		invoiceFPurchase.setSendType(sendType);
 		
 		invoiceFPurchase.setStatusInBound(userUU);
@@ -326,13 +442,6 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 		if (inFpu.getLogistics() != null){
 			purchase.setLgtId(inFpu.getLogistics().getId());
 		}
-//		if("logistics".equals(inFpu.getDeliveryType())) {
-//			purchase.setLgtId(inFpu.getLogistics().getId());
-//		}else {
-//			purchase.setSelfDeliveryName(inFpu.getSelfDeliveryName());
-//			purchase.setSelfDeliveryPhone(inFpu.getSelfDeliveryPhone());
-//		}
-//		purchase.setDeliveryType(inFpu.getDeliveryType());
 
 		purchase.setJsonSdAddress(inFpu.getJsonSdAddress());
 		purchase.setSendName(SystemSession.getUser().getUserName());
@@ -349,12 +458,6 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 			if (inFpu.getLogistics() != null){
 				order.setLgtId(inFpu.getLogistics().getId());
 			}
-//			if("logistics".equals(inFpu.getDeliveryType())) {
-//				order.setLgtId(inFpu.getLogistics().getId());
-//			}else {
-//				order.setSelfDeliveryName(inFpu.getSelfDeliveryName());
-//				order.setSelfDeliveryPhone(inFpu.getSelfDeliveryPhone());
-//			}
 			order.setJsonSdAddress(inFpu.getJsonSdAddress());
 			order.setStatusInBound(userUU);
             order.setSendstatus(Status.NOT_UPLOAD.value());// 将订单设置为未下载状态,以便erp下载
@@ -363,13 +466,6 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 			}
 			orderDao.save(order);
 		}
-
-		//从标准品中做出库动作
-//		ResultMap resultMap = productService.deductRepositoryQty(purchase);
-//		if(resultMap.getCode() != CodeType.OK.code()) {
-//			return resultMap;
-//		}
-
 		return ResultMap.success(inFpu);
 	}
 
@@ -478,18 +574,107 @@ public class InvoiceFPurchaseServiceImpl implements InvoiceFPurchaseService {
 		jsonObject.put("logisticsInfo", logisticsInfo);
 		jsonObject.put("sendType", purchase.getSendType());
 		saveInvoiceFPurchaseList(jsonObject, invoiceFpurc.getId());
+	}
 
-//		Logistics logist = new Logistics();
-//		logist.setCompanyName(invoice.getCompanyName());
-//		logist.setNumber(invoice.getCompanyNumber());
-//		logisticsDao.save(logist);
-//		invoiceFpurc.setLogistics(logist);
-//		invoiceFpurc.setStatusInBound(SystemSession.getUser().getUserUU());
-//		inFpuDao.save(invoiceFpurc);
-//		purchase.setStatusInBound(SystemSession.getUser().getUserUU());
-//		purchase.setLgtId(invoiceFpurc.getLogistics().getId());
-//		purchaseDao.save(purchase);
-		
+	/**
+	 * 卖家发货
+	 *
+	 * @param shiInfo 发货信息,
+	 * @param id      采购单信息
+	 * @return 返回发货单
+	 */
+	@Override
+	public ResultMap ship(String shiInfo, Long id) {
+		if (StringUtilB2C.isEmpty(shiInfo)) {
+			return new ResultMap(CodeType.NO_INFO, "发货信息为空");
+		}
+		if (id == null) {
+			return new ResultMap(CodeType.NO_INFO, "采购单信息为空");
+		}
+		Purchase purchase = purchaseDao.findOne(id);
+		if (purchase == null) {
+			return new ResultMap(CodeType.NO_INFO, "找不到对应的采购单");
+		}
+		JSONObject jObj = FlexJsonUtil.fromJson(shiInfo, JSONObject.class);
+
+		Long userUU = SystemSession.getUser().getUserUU();
+		String shipStr = jObj.getString("shipList");
+		if (org.apache.commons.lang.StringUtils.isEmpty(shipStr)) {
+			return new ResultMap(CodeType.NO_INFO, "发货明细缺失");
+		}
+		List<Map<Long, Double>> shipList = FlexJsonUtils.fromJsonArray(shipStr, Map.class);
+		InvoiceFPurchase invoiceFPurchase = createInvoiceFPurchase(purchase, shipList);
+		Integer sendType = Integer.parseInt(jObj.getString("sendType"));
+
+		if (sendType == null){
+			return new ResultMap(CodeType.NO_INFO, "配送方式的信息为空,请重新操作");
+		}
+
+		JSONObject  logisticsJson = jObj.getJSONObject("logisticsInfo");
+		if (logisticsJson != null){
+			Logistics logistics = logisticsService.bornLogisticsByCompanyNameAndNum(logisticsJson.getString("companyName"), logisticsJson.getString("number"));
+			invoiceFPurchase.setLogistics(logistics);
+		}
+
+		String jsonSdAddress = jObj.getString("jsonSdAddress");
+		if(StringUtils.isEmpty(jsonSdAddress)) {
+			return new ResultMap(CodeType.NO_INFO, "发货人的地址信息为空,请重新操作");
+		}
+		invoiceFPurchase.setJsonSdAddress(jsonSdAddress);
+		invoiceFPurchase.setSendType(sendType);
+
+		invoiceFPurchase.setStatusInBound(userUU);
+		Set<InvoiceFPurchaseDetail> invoiceFPurchaseDetails = invoiceFPurchase.getInvoiceFPurchaseDetails();
+		for (InvoiceFPurchaseDetail detail : invoiceFPurchaseDetails) {
+			if(Status.UNAVAILABLE_PERSONAL.value() == detail.getStatus()
+					|| Status.UNAVAILABLE_DISAGREE.value() == detail.getStatus()) {
+				continue;
+			}
+			detail.setStatus(Status.INBOUND.value());
+		}
+		InvoiceFPurchase inFpu = inFpuDao.save(invoiceFPurchase);
+
+
+		if (inFpu.getLogistics() != null) {
+			purchase.setLgtId(inFpu.getLogistics().getId());
+		}
+
+		purchase.setJsonSdAddress(inFpu.getJsonSdAddress());
+		purchase.setSendName(SystemSession.getUser().getUserName());
+		purchase.setSenduu(SystemSession.getUser().getUserUU());
+		purchase.setSendTime(new Date());
+		purchase.addInid(inFpu.getInvoiceid());
+
+		if(NumberUtil.compare(purchase.getQty(), purchase.getShipQty()) < 1) {
+			//如果不是优软商城店铺,则代表店铺直售
+			if(!purchase.getStoreid().equals(sysConf.getStoreid())) {
+				Order order = orderDao.findByOrderid(purchase.getOrderid());
+				if(order == null) {
+					return new ResultMap(CodeType.NOT_PERMIT, "您订单的信息有误,请重新提交");
+				}
+				if (inFpu.getLogistics() != null){
+					order.setLgtId(inFpu.getLogistics().getId());
+				}
+				order.setJsonSdAddress(inFpu.getJsonSdAddress());
+				order.setStatusInBound(userUU);
+				order.setSendstatus(Status.NOT_UPLOAD.value());// 将订单设置为未下载状态,以便erp下载
+				for (OrderDetail detail : order.getOrderDetails()) {
+					detail.setStatusInBound(userUU);
+				}
+				orderDao.save(order);
+			}
+			Set<PurchaseDetail> purchaseDetails = purchase.getPurchaseDetails();
+			for (PurchaseDetail purchaseDetail : purchaseDetails) {
+				if (Status.TOBESHIPPED.value() == purchaseDetail.getStatus()) {
+					purchaseDetail.setStatusInBound(userUU);
+				}
+			}
+			purchase.setStatusInBound(userUU);
+		}
+
+		purchaseDao.save(purchase);
+		return null;
 	}
 
+
 }

+ 9 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductDao.java

@@ -38,6 +38,15 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
     @Query(value = "select p from Product p where p.prodNum in :prodNums")
     List<Product> findByProdNums(@Param("prodNums") List<String> prodNums);
 
+
+    /**
+     * 根据编号获取物料信息。
+     * @param prodNum  物料编号list
+     * @return 返回物料信息。
+     */
+    @Query(value = "select p from Product p where p.prodNum = prodNum")
+    List<Product> findByProdNum(@Param("prodNum") String prodNum);
+
     /**
      * 通过uu查询非标准器件进行存储
      *

+ 17 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/InOutboundDetail.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.prod.commodity.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.uas.platform.b2c.trade.order.model.PurchaseDetail;
 
 import javax.persistence.*;
 import java.io.Serializable;
@@ -238,5 +239,21 @@ public class InOutboundDetail implements Serializable {
         this.spec = product.getSpec();
         this.qty = product.getErpReserve();
         this.price = product.getPrice();
+        this.productId = product.getId();
+    }
+
+    public InOutboundDetail(Product product, PurchaseDetail detail, Double qty) {
+        this.brandCn = product.getPbrand();
+        this.brandEn = product.getPbranden();
+        this.brandId = product.getPbrandid();
+        this.branduuid = product.getPbranduuid();
+        this.kindId = product.getKindid();
+        this.kindName = product.getKind();
+        this.cmpCode = product.getPcmpcode();
+        this.cmpuuid = product.getCmpUuId();
+        this.spec = product.getSpec();
+        this.qty = qty;
+        this.price = detail.getTaxUnitPrice();
+        this.productId = product.getId();
     }
 }

+ 7 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java

@@ -346,6 +346,13 @@ public interface ProductService {
      */
     List<Product> findProductIdAndProdnumsByProdNums(List<String> prodNums);
 
+    /**
+     * 根据物料编号找物料
+     * @param prodNum
+     * @return
+     */
+    Product findProductByProdNum(String prodNum);
+
 
     /**
      * 批量保存

+ 8 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -1600,7 +1600,10 @@ public class GoodsServiceImpl implements GoodsService {
                 isChangeSaleType = true;
             }
             nowGoods.setStoreid(sysConf.getStoreid());
-            nowGoods.setStoreName(sysConf.getEnName());
+            StoreIn storeIn = storeInService.findByUuid(sysConf.getStoreid());
+            if (storeIn != null){
+                nowGoods.setStoreName(storeIn.getStoreName());
+            }
         } else if (Integer.valueOf(oldGoods.getSelfSale()).equals(IntegerConstant.SELF_SALE)) {
             StoreIn storeIn = storeInService.findByEnUU(nowGoods.getEnUU());
             if (storeIn != null && storeIn.getStatus() == StoreStatus.OPENED) {
@@ -1722,7 +1725,10 @@ public class GoodsServiceImpl implements GoodsService {
                 isChangeSaleType = true;
             }
             nowGoods.setStoreid(sysConf.getStoreid());
-            nowGoods.setStoreName(sysConf.getEnName());
+            StoreIn storeIn = storeInService.findByUuid(sysConf.getStoreid());
+            if (storeIn != null) {
+                nowGoods.setStoreName(storeIn.getStoreName());
+            }
         } else if (Integer.valueOf(oldGoods.getSelfSale()).equals(IntegerConstant.SELF_SALE)) {
             StoreIn storeIn = storeInService.findByEnUU(nowGoods.getEnUU());
             if (storeIn != null && storeIn.getStatus() == StoreStatus.OPENED) {

+ 20 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -2268,6 +2268,26 @@ public class ProductServiceImpl implements ProductService {
         }
     }
 
+
+    /**
+     * 根据物料编号找物料
+     *
+     * @param prodNum
+     * @return
+     */
+    @Override
+    public Product findProductByProdNum(String prodNum) {
+        if (StringUtils.isEmpty(prodNum)) {
+            return null;
+        } else {
+            List<Product> products = productDao.findByProdNum(prodNum);
+            if (CollectionUtils.isEmpty(products)) {
+                return null;
+            }
+            return products.get(0);
+        }
+    }
+
     /**
      * 批量保存,通过jdbctemplate
      *

+ 14 - 0
src/main/java/com/uas/platform/b2c/trade/order/model/Order.java

@@ -648,6 +648,12 @@ public class Order extends Document implements Serializable {
 	@Column(name = "or_spId")
 	private Long spId;
 
+	/**
+	 * 出货量
+	 */
+	@Column(name = "or_shipqty")
+	private Double shipQty = 0.0d;
+
 	/**
 	 * 分期信息(不做关联)
 	 */
@@ -2912,4 +2918,12 @@ public class Order extends Document implements Serializable {
 	public void setReceiveName(String receiveName) {
 		this.receiveName = receiveName;
 	}
+
+	public Double getShipQty() {
+		return shipQty;
+	}
+
+	public void setShipQty(Double shipQty) {
+		this.shipQty = shipQty;
+	}
 }

+ 14 - 0
src/main/java/com/uas/platform/b2c/trade/order/model/OrderDetail.java

@@ -468,6 +468,12 @@ public class OrderDetail extends Document implements Serializable{
 	@Column(name = "go_b2cmindelivery")
 	private Short b2cMinDelivery;
 
+	/**
+	 * 出货量
+	 */
+	@Column(name = "detail_shipqty")
+	private Double shipQty = 0.0d;
+
 
 
 	/**
@@ -2036,4 +2042,12 @@ public class OrderDetail extends Document implements Serializable{
         this.branduuid = branduuid;
         return this;
     }
+
+	public Double getShipQty() {
+		return shipQty;
+	}
+
+	public void setShipQty(Double shipQty) {
+		this.shipQty = shipQty;
+	}
 }

+ 23 - 1
src/main/java/com/uas/platform/b2c/trade/order/model/Purchase.java

@@ -9,6 +9,7 @@ import com.uas.platform.core.model.Status;
 import com.uas.platform.core.persistence.StatusColumn;
 import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.springframework.util.StringUtils;
 
 import javax.persistence.*;
 import java.io.Serializable;
@@ -194,7 +195,7 @@ public class Purchase extends Document implements Serializable {
 	/**
 	 * 转的发货单id
 	 */
-	@Column(name = "in_id")
+	@Column(name = "in_id", columnDefinition = "1000")
 	private String inid;
 
 	/**
@@ -515,6 +516,12 @@ public class Purchase extends Document implements Serializable {
 	@Column(name = "pu_installmentid")
 	private Long installmentId;
 
+	/**
+	 * 出货量
+	 */
+	@Column(name = "pu_shipqty")
+	private Double shipQty = 0.0d;
+
 	/**
 	 * 分期信息(不做关联)
 	 */
@@ -1454,6 +1461,13 @@ public class Purchase extends Document implements Serializable {
 		this.inid = inid;
 	}
 
+	public void addInid(String inid) {
+		if (!StringUtils.isEmpty(this.inid)) {
+			this.inid += ",";
+		}
+		this.inid += inid;
+	}
+
 	/**
 	 * Gets currency.
 	 *
@@ -1790,6 +1804,14 @@ public class Purchase extends Document implements Serializable {
 		this.used = 1;
 	}
 
+	public Double getShipQty() {
+		return shipQty;
+	}
+
+	public void setShipQty(Double shipQty) {
+		this.shipQty = shipQty;
+	}
+
 	@Override
 	public String toString() {
 		return "Purchase [id=" + id + ", purchaseid=" + purchaseid + ", sellerenuu=" + sellerenuu + ", sellername=" + sellername

+ 14 - 0
src/main/java/com/uas/platform/b2c/trade/order/model/PurchaseDetail.java

@@ -336,6 +336,12 @@ public class PurchaseDetail extends Document {
 	@Column(name = "go_spec", length = 4000)
 	private String spec;
 
+	/**
+	 * 出货量
+	 */
+	@Column(name = "detail_shipqty")
+	private Double shipQty = 0.0d;
+
 
 	/********************************* 非持久化字段 *********************************/
 
@@ -1544,6 +1550,14 @@ public class PurchaseDetail extends Document {
 		return null;
 	}
 
+	public Double getShipQty() {
+		return shipQty;
+	}
+
+	public void setShipQty(Double shipQty) {
+		this.shipQty = shipQty;
+	}
+
 	public String getSpec() {
 		return spec;
 	}

+ 0 - 11
src/main/java/com/uas/platform/b2c/trade/order/service/impl/OrderServiceImpl.java

@@ -1555,17 +1555,6 @@ public class OrderServiceImpl implements OrderService {
             throw new IllegalOperatorException(
                     "订单" + order.getOrderid() + "的状态是:" + Status.valueOf(order.getStatus()).getPhrase() + ",不能转出货单");
         }
-        // 检查有效时间
-        // Date now = new Date();
-        // 平台不需这个逻辑了
-        // if (now.getTime() > order.getAvailabletime().getTime()) {
-        // // 失效订单
-        // /**
-        // * @TODO 用官方账号写入被作废的记录,并置为未及时付款失效订单
-        // */
-        // // 抛异常
-        // throw new IllegalOperatorException("已经超过订单有效期");
-        // }
 
         // 现货自动转采购的统一用管理员身份
         order.setStatusToBeShipped(sysConf.getAdminUU());