package com.huaheng.api.SSP.service; import com.huaheng.api.SSP.domain.*; import com.huaheng.common.exception.service.ServiceException; import com.huaheng.pc.SSP.domain.SSPdetail; import com.huaheng.pc.SSP.domain.SSPheader; import com.huaheng.pc.SSP.mapper.SSPdetailMapperAuto; import com.huaheng.pc.SSP.mapper.SSPheaderMapperAuto; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.general.company.domain.WarehouseCompany; import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto; import com.huaheng.pc.receipt.receiptDetail.service.IReceiptDetailService; import com.huaheng.pc.receipt.receiptHeader.service.IReceiptHeaderService; import net.bytebuddy.implementation.bytecode.Throw; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @Service @Transactional public class OrderConfirmService { @Resource private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto; @Autowired IReceiptDetailService detailService; @Autowired IReceiptHeaderService headerService; @Resource private SSPheaderMapperAuto ssPheaderMapperAuto; @Resource private SSPdetailMapperAuto ssPdetailMapperAuto; //订单回传 public AjaxResult ocfm(ConfirmModel cfm) { ConfirmHeaderModel headerModel = cfm.getConfirmHeaderModel(); List<ConfirmTypeModel> typeModels = cfm.getOrderItems(); if (headerModel == null||typeModels == null){ return AjaxResult.error("订单头表为空或订单明细表为空!"); }if (headerModel.getCubeCode()==null||headerModel.getCubeCode()==""){ return AjaxResult.error("钱柜编码不能为空!"); }if (headerModel.getId()==null||headerModel.getId()==""){ return AjaxResult.error("钱柜系统主表标识不能为空!"); }if (headerModel.getOrderHeaderId()<1){ return AjaxResult.error("订单头表标识不能为空!"); }if (headerModel.getOrderCode()==null||headerModel.getOrderCode()==""){ return AjaxResult.error("订单编码不能为空!"); }if (!headerModel.getOrderType().equals("receipt")&&!headerModel.getOrderType().equals("shipment")){ return AjaxResult.error("订单类型错误!"); }if (headerModel.getfDatetime()==null||headerModel.getcDatetime()==""){ return AjaxResult.error("完成的时间不能为空!"); }if (headerModel.getcDatetime()==null||headerModel.getcDatetime()==""){ return AjaxResult.error("交互的当前时间不能为空!"); } String wc = headerModel.getWarehouseCode(); if (wc==null||wc==""){ return AjaxResult.error("warehouseCode不能为空!!"); } WarehouseCompany warehouseCompany = new WarehouseCompany(); warehouseCompany.setWarehouseCode(wc); List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany); if (list == null || list.size() == 0) { return AjaxResult.error("系统中没有该仓库:" + warehouseCompany.toString() + " 信息,请先录入仓库信息!"); } SSPheader ssPheader = new SSPheader(); ssPheader.setWarehouseCode(headerModel.getWarehouseCode()); ssPheader.setCubeCode(headerModel.getCubeCode()); ssPheader.sethID(headerModel.getId()); ssPheader.setOrderHeaderId(headerModel.getOrderHeaderId()); ssPheader.setOrderCode(headerModel.getOrderCode()); ssPheader.setOrderType(headerModel.getOrderType()); ssPheader.setfDatetime(headerModel.getfDatetime()); ssPheader.setcDatetime(headerModel.getcDatetime()); if (ssPheader.getOrderType().equals("receipt")){ return receipt(ssPheader,typeModels); }else { return shipment(ssPheader,typeModels); } } private AjaxResult receipt(SSPheader chm,List<ConfirmTypeModel> ctmlist){ for (ConfirmTypeModel ctm : ctmlist){ if (ctm.getItemId()==null||ctm.getItemId()==""){ return AjaxResult.error("钱柜系统明细标识不能为空!"); }if (ctm.getOrderDetailId()<1){ return AjaxResult.error("订单明细表标识不能为空!"); }if (ctm.getCompanyCode()==null||ctm.getCompanyCode()==""){ return AjaxResult.error("货主编码不能为空!"); }if (ctm.getContainerCode()==null||ctm.getContainerCode()==""){ return AjaxResult.error("容器编码不能为空!"); }if (ctm.getItemCode()==null||ctm.getItemCode()==""){ return AjaxResult.error("商品编码不能为空!"); }if (ctm.getItemBarcode()==null||ctm.getItemBarcode()=="") { return AjaxResult.error("商品条码不能为空!"); } SSPheader sh = new SSPheader(); sh.sethID(chm.gethID()); sh.setOrderHeaderId(chm.getOrderHeaderId()); sh.setOrderType(chm.getOrderType()); //组合入库子单 SSPdetail sd = new SSPdetail(); sd.setItemId(ctm.getItemId()); sd.setOrderDetailId(ctm.getOrderDetailId()); sd.setOrderHeaderId(chm.getOrderHeaderId()); sd.setCompanyCode(ctm.getCompanyCode()); sd.setContainerCode(ctm.getContainerCode()); sd.setItemCode(ctm.getItemCode()); sd.setItemName(ctm.getItemName()); sd.setItemBarcode(ctm.getItemBarcode()); sd.setItemState(ctm.getItemState()); sd.setQty(ctm.getQty()); sd.setItemUnit(ctm.getItemUnit()); sd.setOrderType("receipt"); //判断系统中是否已有该主单 try { if (ssPheaderMapperAuto.selectListEntityByEqual(sh).size()<1){ ssPheaderMapperAuto.insert(chm); ssPdetailMapperAuto.insert(sd); }else { SSPdetail sd1 = new SSPdetail(); sd1.setOrderDetailId(ctm.getOrderDetailId()); sd1.setOrderHeaderId(chm.getOrderHeaderId()); //判断系统中是否已有该子单 if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size() < 1) { ssPdetailMapperAuto.insert(sd); } else { sd1.setItemId(ctm.getItemId()); sd1.setOrderType("receipt"); //如果有,再判断该子单是否是多次回传,以及是否是入库子单 if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size() < 1) { ssPdetailMapperAuto.insert(sd); } } } }catch (Exception e){ throw new ServiceException("入库主单或子单新增失败!"); } } return AjaxResult.setResultCS(0,"入库单回传成功"); } private AjaxResult shipment(SSPheader chm,List<ConfirmTypeModel> ctmlist){ for (ConfirmTypeModel ctm : ctmlist){ if (ctm.getItemId()==null||ctm.getItemId()==""){ return AjaxResult.error("钱柜系统明细标识不能为空!"); }if (ctm.getOrderDetailId()<1){ return AjaxResult.error("订单明细表标识不能为空!"); }if (ctm.getCompanyCode()==null||ctm.getCompanyCode()==""){ return AjaxResult.error("货主编码不能为空!"); }if (ctm.getContainerCode()==null||ctm.getContainerCode()==""){ return AjaxResult.error("容器编码不能为空!"); }if (ctm.getItemCode()==null||ctm.getItemCode()==""){ return AjaxResult.error("商品编码不能为空!"); }if (ctm.getItemBarcode()==null||ctm.getItemBarcode()=="") { return AjaxResult.error("商品条码不能为空!"); } SSPheader sh = new SSPheader(); sh.sethID(chm.gethID()); sh.setOrderHeaderId(chm.getOrderHeaderId()); sh.setOrderType(chm.getOrderType()); //组合入库子单 SSPdetail sd = new SSPdetail(); sd.setItemId(ctm.getItemId()); sd.setOrderDetailId(ctm.getOrderDetailId()); sd.setOrderHeaderId(chm.getOrderHeaderId()); sd.setCompanyCode(ctm.getCompanyCode()); sd.setContainerCode(ctm.getContainerCode()); sd.setItemCode(ctm.getItemCode()); sd.setItemName(ctm.getItemName()); sd.setItemBarcode(ctm.getItemBarcode()); sd.setItemState(ctm.getItemState()); sd.setQty(ctm.getQty()); sd.setItemUnit(ctm.getItemUnit()); sd.setOrderType("shipment"); //判断系统中是否已有该主单 try { if (ssPheaderMapperAuto.selectListEntityByEqual(sh).size()<1){ ssPheaderMapperAuto.insert(chm); ssPdetailMapperAuto.insert(sd); }else { SSPdetail sd1 = new SSPdetail(); sd1.setOrderDetailId(ctm.getOrderDetailId()); sd1.setOrderHeaderId(chm.getOrderHeaderId()); //判断系统中是否已有该子单 if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size()<1){ ssPdetailMapperAuto.insert(sd); }else { sd1.setItemId(ctm.getItemId()); sd1.setOrderType("shipment"); //如果有,再判断该子单是否是多次回传,以及是否是出库子单 if (ssPdetailMapperAuto.selectListEntityByEqual(sd1).size()<1) { ssPdetailMapperAuto.insert(sd); } } } }catch (Exception e){ throw new ServiceException("出库主单或出库子单新增失败!"); } } return AjaxResult.setResultCS(0,"出库单回传成功"); } }