|
@@ -1,10 +1,18 @@
|
|
|
package com.lote.wms.outstock.boxed.service.impl;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import com.lote.wms.common.config.SystemConfig;
|
|
|
+import com.lote.wms.common.utils.FileServerClient;
|
|
|
+import com.lote.wms.common.utils.POIExcelUtil;
|
|
|
+import com.lote.wms.inventory.check.entity.InventoryCheckDetail;
|
|
|
+import com.lote.wms.inventory.inventory.entity.Inventory;
|
|
|
+import com.lote.wms.outstock.order.entity.OutOrderItem;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.mybatis.plugin.model.Pager;
|
|
|
import org.mybatis.plugin.util.PagerUtil;
|
|
|
import org.slf4j.Logger;
|
|
@@ -62,6 +70,10 @@ public class OutBoxedItemServiceImpl implements OutBoxedItemService {
|
|
|
@Resource
|
|
|
private OutOrderItemService outOrderItemService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SystemConfig systemConfig;
|
|
|
+
|
|
|
+
|
|
|
private static final Logger logger = LoggerFactory.getLogger(OutBoxedItemServiceImpl.class);
|
|
|
|
|
|
public OutBoxedItem add(OutBoxedItem record) {
|
|
@@ -110,8 +122,8 @@ public class OutBoxedItemServiceImpl implements OutBoxedItemService {
|
|
|
message.setSuccess(false);
|
|
|
String orderId = vo.getOutOrderId();
|
|
|
String orderNo = vo.getOutOrderNo();// 也可能是跟踪单号
|
|
|
- String boxId = vo.getBoxId();
|
|
|
- String boxNo = vo.getBoxNo();
|
|
|
+// String boxId = vo.getBoxId();
|
|
|
+// String boxNo = vo.getBoxNo();
|
|
|
vo.setBarcode((vo.getBarcode()));
|
|
|
String barcode = vo.getBarcode();
|
|
|
|
|
@@ -177,14 +189,15 @@ public class OutBoxedItemServiceImpl implements OutBoxedItemService {
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
- OutBoxed outBoxed = outBoxedService.get(boxId);
|
|
|
- if (outBoxed == null) {
|
|
|
- message.setMsg("箱子不存在,id:" + boxId + ",请重新进入装箱");
|
|
|
- return message;
|
|
|
- }
|
|
|
+ // 箱子后面称重打单的时候再添加
|
|
|
+// OutBoxed outBoxed = outBoxedService.get(boxId);
|
|
|
+// if (outBoxed == null) {
|
|
|
+// message.setMsg("箱子不存在,id:" + boxId + ",请重新进入装箱");
|
|
|
+// return message;
|
|
|
+// }
|
|
|
// 更新商品数量
|
|
|
- outBoxed.setQuantity(outBoxed.getQuantity() + productQty);
|
|
|
- outBoxedService.update(outBoxed);
|
|
|
+// outBoxed.setQuantity(outBoxed.getQuantity() + productQty);
|
|
|
+// outBoxedService.update(outBoxed);
|
|
|
|
|
|
// 从下架记录表
|
|
|
OutBoxedItem boxedItem = new OutBoxedItem();
|
|
@@ -193,8 +206,15 @@ public class OutBoxedItemServiceImpl implements OutBoxedItemService {
|
|
|
boxedItem.setOutOrderNo(order.getOrderNo1());
|
|
|
boxedItem.setOutOrderId(orderId);
|
|
|
|
|
|
- boxedItem.setBoxId(boxId);
|
|
|
- boxedItem.setBoxNo(boxNo);
|
|
|
+
|
|
|
+ List<OutBoxed> boxedList = outBoxedService.listByOrderId(orderId);
|
|
|
+ // 如果称重后再取消装箱记录,就有可能没装箱就有箱子,就得提前录入
|
|
|
+ if (boxedList != null && boxedList.size()==1){
|
|
|
+ OutBoxed box = boxedList.get(0);
|
|
|
+ boxedItem.setBoxId(box.getId());
|
|
|
+ boxedItem.setBoxNo(box.getBoxNo());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
boxedItem.setBarcode(barcode);
|
|
|
boxedItem.setSku(outShelfVo.getSku());
|
|
@@ -217,6 +237,8 @@ public class OutBoxedItemServiceImpl implements OutBoxedItemService {
|
|
|
if (isFinished) {
|
|
|
message.setMsg("出库单号:" + orderNo + ",完成装箱,请操作下一单");
|
|
|
message.setExtend(isFinished);
|
|
|
+ // 普通复核装箱,如果完成 创建出一个没箱号的箱子
|
|
|
+ initOutBoxedAndItem(order,user);
|
|
|
}
|
|
|
message.setSuccess(true);
|
|
|
return message;
|
|
@@ -292,4 +314,254 @@ public class OutBoxedItemServiceImpl implements OutBoxedItemService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void initOutBoxedAndItem(OutOrder order, User user){
|
|
|
+ List<OutBoxed> boxedList = outBoxedService.listByOrderId(order.getId());
|
|
|
+ if (boxedList == null || boxedList.size()==0){
|
|
|
+ OutBoxed box = new OutBoxed();
|
|
|
+ box.setId(IdWorkerAide.nextId());
|
|
|
+ box.setBoxNo("");
|
|
|
+
|
|
|
+ box.setCustomerId(order.getCustomerId());
|
|
|
+ box.setCustomerCode(order.getCustomerCode());
|
|
|
+
|
|
|
+ box.setWarehouseCode(order.getWarehouseCode());
|
|
|
+ box.setWarehouseId(order.getWarehouseId());
|
|
|
+
|
|
|
+ box.setOutOrderId(order.getId());
|
|
|
+ box.setOutOrderNo(order.getOrderNo1());
|
|
|
+
|
|
|
+ box.setShipwayCode(order.getShipwayCode());
|
|
|
+ box.setShipwayName(order.getShipwayName());
|
|
|
+
|
|
|
+ box.setCreatedByUserCode(user.getCode());
|
|
|
+ box.setCreatedByUserId(user.getId());
|
|
|
+ box.setCreatedTime(new Date());
|
|
|
+ int productQty = 0;
|
|
|
+ List<OutOrderItem> itemList = outOrderItemService.listByOrderId(order.getId());
|
|
|
+ for (OutOrderItem item : itemList) {
|
|
|
+ productQty += item.getQuantity();
|
|
|
+ }
|
|
|
+ box.setQuantity(productQty);
|
|
|
+ outBoxedService.add(box);
|
|
|
+
|
|
|
+ OutBoxedItemCriteria criteria = new OutBoxedItemCriteria();
|
|
|
+ criteria.setLimit(-1);
|
|
|
+ criteria.setOrderByClause("created_time desc");
|
|
|
+ Criteria cri = criteria.createCriteria();
|
|
|
+ cri.andOutOrderIdEqualTo(order.getId());
|
|
|
+ List<OutBoxedItem> list = outBoxedItemMapper.selectByConditionList(criteria);
|
|
|
+ for (OutBoxedItem outBoxedItem : list) {
|
|
|
+ outBoxedItem.setBoxId(box.getId());
|
|
|
+ update(outBoxedItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Message submitBarcodeByShow(OutBoxedItemQueryVo vo, User user) {
|
|
|
+ Message message = new Message();
|
|
|
+ message.setSuccess(false);
|
|
|
+ String orderId = vo.getOutOrderId();
|
|
|
+ String orderNo = vo.getOutOrderNo();// 也可能是跟踪单号
|
|
|
+ String boxId = vo.getBoxId();
|
|
|
+ String boxNo = vo.getBoxNo();
|
|
|
+ vo.setBarcode((vo.getBarcode()));
|
|
|
+ String barcode = vo.getBarcode();
|
|
|
+
|
|
|
+ Integer productQty = vo.getProductQty();
|
|
|
+
|
|
|
+ if (productQty < 1) {
|
|
|
+ message.setMsg("装箱数量必须大于等于1");
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(orderNo)) {
|
|
|
+ message.setMsg("出库单号不能为空");
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+ OutOrder order = outOrderService.get(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ message.setMsg("订单id不存在,请重新扫描提交出库单号");
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isEqual(order.getIsHoldUp(), BaseConstant.Y)) {
|
|
|
+ message.setMsg("出库单已拦截,不可装箱");
|
|
|
+
|
|
|
+ outOrderLogService.addLog(order, user, OutOrderOpTypeEnum.OUT_BOXED, null, message.getMsg(), false);
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+ if (StringUtil.isEqual(order.getStatusCode(), OutOrderStatusEnum.CANCELED.getCode())
|
|
|
+ || StringUtil.isEqual(order.getIsCancel(), BaseConstant.Y)) {
|
|
|
+ message.setMsg("出库单已取消,不可装箱");
|
|
|
+
|
|
|
+ outOrderLogService.addLog(order, user, OutOrderOpTypeEnum.OUT_BOXED, null, message.getMsg(), false);
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer sumOrderItemQty = outOrderItemService.sumQtyByOrderId(orderId);
|
|
|
+ Integer sumOutShelfQty = outShelfService.sumQtyByOrderId(orderId);
|
|
|
+ if (sumOutShelfQty > sumOrderItemQty) {
|
|
|
+ message.setMsg("该订单下架商品总数量超过订单预报商品总数量,请联系技术并提供订单号");
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证条码
|
|
|
+ OutShelfResultVo outShelfVo = outShelfService.getForOutBox(orderId, barcode);
|
|
|
+ if (outShelfVo == null) {
|
|
|
+ message.setMsg("出库单号:" + orderNo + ",条码:" + barcode + "无下架记录");
|
|
|
+
|
|
|
+ outOrderLogService.addLog(order, user, OutOrderOpTypeEnum.OUT_BOXED, null, message.getMsg(), false);
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 待装箱数量
|
|
|
+ int waitBoxQty = outShelfVo.getTotalQty() - outShelfVo.getBoxedQty();
|
|
|
+ if (waitBoxQty <= 0) {
|
|
|
+ // 如果已装箱 已经大于待装箱...
|
|
|
+ message.setMsg("出库单号:" + orderNo + ",条码:" + barcode + "待装箱数量为:" + waitBoxQty + ",请删除装箱记录,重新装箱");
|
|
|
+ outOrderLogService.addLog(order, user, OutOrderOpTypeEnum.OUT_BOXED, null, message.getMsg(), false);
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (productQty > waitBoxQty) {// 提交下架数量大于已装箱数量
|
|
|
+ message.setMsg("出库单号:" + orderNo + ",条码:" + barcode + "待装箱数量为:" + waitBoxQty);
|
|
|
+
|
|
|
+ outOrderLogService.addLog(order, user, OutOrderOpTypeEnum.OUT_BOXED, null, message.getMsg(), false);
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ OutBoxed outBoxed = outBoxedService.get(boxId);
|
|
|
+ if (outBoxed == null) {
|
|
|
+ message.setMsg("箱子不存在,id:" + boxId + ",请重新进入装箱");
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+ // 更新商品数量
|
|
|
+ outBoxed.setQuantity(outBoxed.getQuantity() + productQty);
|
|
|
+ outBoxedService.update(outBoxed);
|
|
|
+
|
|
|
+ // 从下架记录表
|
|
|
+ OutBoxedItem boxedItem = new OutBoxedItem();
|
|
|
+ boxedItem.setId(IdWorkerAide.nextId());
|
|
|
+
|
|
|
+ boxedItem.setOutOrderNo(order.getOrderNo1());
|
|
|
+ boxedItem.setOutOrderId(orderId);
|
|
|
+
|
|
|
+ boxedItem.setBoxId(boxId);
|
|
|
+ boxedItem.setBoxNo(boxNo);
|
|
|
+
|
|
|
+ boxedItem.setBarcode(barcode);
|
|
|
+ boxedItem.setSku(outShelfVo.getSku());
|
|
|
+ boxedItem.setQuantity(productQty);
|
|
|
+
|
|
|
+ boxedItem.setQualityName(outShelfVo.getQualityName());
|
|
|
+ boxedItem.setQualityCode(outShelfVo.getQualityCode());
|
|
|
+ boxedItem.setBatchNo(outShelfVo.getBatchNo());
|
|
|
+
|
|
|
+ boxedItem.setCreatedByUserCode(user.getCode());
|
|
|
+ boxedItem.setCreatedByUserId(user.getId());
|
|
|
+ boxedItem.setCreatedTime(new Date());
|
|
|
+ add(boxedItem);
|
|
|
+
|
|
|
+ message.setMsg("装箱成功,条码:" + barcode + ",数量:" + productQty);
|
|
|
+ outOrderLogService.addLog(order, user, OutOrderOpTypeEnum.OUT_BOXED, null, message.getMsg(), true);
|
|
|
+
|
|
|
+ // 处理订单状态更新
|
|
|
+ boolean isFinished = handleStatus(order, user);
|
|
|
+ if (isFinished) {
|
|
|
+ message.setMsg("出库单号:" + orderNo + ",完成装箱,请点击重置按钮操作下一单或导出复核装箱明细");
|
|
|
+ message.setExtend(isFinished);
|
|
|
+ }
|
|
|
+ message.setSuccess(true);
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Message export(Map<String, Object> map) {
|
|
|
+ String orderNo = (String) map.get("outOrderNo");
|
|
|
+ Message selectOrder = outOrderService.selectByNo(orderNo);
|
|
|
+ if (!selectOrder.isSuccess()) {
|
|
|
+ return selectOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ OutOrder order = (OutOrder) selectOrder.getExtend();
|
|
|
+ // 只有装箱完成的才可以导出
|
|
|
+ if (!StringUtil.isEquals(order.getStatusCode(), OutOrderStatusEnum.BOXCOMPLETE.getCode())) {
|
|
|
+ return Message.fail("只有已装箱的订单可以操作导出!");
|
|
|
+ }
|
|
|
+ String headCnStrList[] = new String[] { "序号", "出库单号", "货主代码", "仓库代码", "出库类型", "运输方式", "跟踪单号", "箱号", "sku",
|
|
|
+ "商品条码","批次号","品质等级名称","商品数量","创建时间" };
|
|
|
+ Sheet sheet = null;
|
|
|
+ List<String> headCnList = Arrays.asList(headCnStrList);
|
|
|
+ try {
|
|
|
+ sheet = POIExcelUtil.createSheet("复核装箱明细", headCnList);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<OutBoxedItem> outBoxedItemList = outBoxedItemMapper.selectByOutOrderNo(order.getOrderNo1());
|
|
|
+ if (Objects.isNull(outBoxedItemList) || outBoxedItemList.size()==0){
|
|
|
+ return Message.fail("该出库单无明细");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换成行
|
|
|
+ List<String[]> row = parseRow(outBoxedItemList,order, headCnList);
|
|
|
+ // 保存到excel中
|
|
|
+ POIExcelUtil.addRows(sheet, row);
|
|
|
+
|
|
|
+
|
|
|
+ // 保存到临时文件返回路径 TODO
|
|
|
+ try {
|
|
|
+ // 随机生成文件
|
|
|
+ String fileName = UUID.randomUUID().toString() + ".xlsx";
|
|
|
+ File tempFile = new File(systemConfig.getRuntimeFileDir() + "/outstock/");
|
|
|
+ if (!tempFile.exists()) {
|
|
|
+ tempFile.mkdirs();
|
|
|
+ }
|
|
|
+ String fileNameAndPath = systemConfig.getRuntimeFileDir() + "/outstock/" + fileName;
|
|
|
+ POIExcelUtil.saveToFile(sheet, fileNameAndPath);
|
|
|
+
|
|
|
+ // 上传文件服务器
|
|
|
+ String downUrl = FileServerClient.fileUpload(systemConfig.getFileServerUrl(), fileNameAndPath);
|
|
|
+ return Message.success(downUrl);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return Message.fail("系统异常,请稍后重试!");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String[]> parseRow(List<OutBoxedItem> outBoxedItemList, OutOrder order, List<String> headCnList) {
|
|
|
+ List<String[]> rows = new ArrayList<>();
|
|
|
+ int number=1;
|
|
|
+ //String headCnStrList[] = new String[] { "序号", "出库单号", "货主代码", "仓库代码", "出库类型", "运输方式", "跟踪单号", "箱号", "sku",
|
|
|
+ // "商品条码","批次号","品质等级名称","商品数量","创建时间" };
|
|
|
+ for (OutBoxedItem outBoxedItem : outBoxedItemList) {
|
|
|
+ String[] row = new String[headCnList.size()];
|
|
|
+ row[0] = String.valueOf(number++);
|
|
|
+ row[1] = order.getOrderNo1();
|
|
|
+ row[2] = order.getCustomerCode();
|
|
|
+ row[3] = order.getWarehouseCode();
|
|
|
+ row[4] = order.getTypeName();
|
|
|
+ row[5] = order.getShipwayName();
|
|
|
+ row[6] = order.getTrackingNo1();
|
|
|
+ row[7] = outBoxedItem.getBoxNo();
|
|
|
+ row[8] = outBoxedItem.getSku();
|
|
|
+ row[9] = outBoxedItem.getBarcode();
|
|
|
+ row[10] = outBoxedItem.getBatchNo();
|
|
|
+ row[11] = outBoxedItem.getQualityName();
|
|
|
+ row[12] = outBoxedItem.getQuantity().toString();
|
|
|
+ row[13] = outBoxedItem.getCreatedTime().toString();
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|