|
@@ -1,11 +1,15 @@
|
|
|
package com.lote.wms.inventory.check.service.impl;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-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.base.product.entity.ProductBarcode;
|
|
|
+import com.lote.wms.common.config.SystemConfig;
|
|
|
+import com.lote.wms.common.utils.*;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.mybatis.plugin.model.Pager;
|
|
|
import org.mybatis.plugin.util.PagerUtil;
|
|
|
import org.slf4j.Logger;
|
|
@@ -21,10 +25,6 @@ import com.lote.wms.common.core.db.DataAccessHolder;
|
|
|
import com.lote.wms.common.core.db.IdWorkerAide;
|
|
|
import com.lote.wms.common.exception.ServiceException;
|
|
|
import com.lote.wms.common.model.Message;
|
|
|
-import com.lote.wms.common.utils.BeanUtil;
|
|
|
-import com.lote.wms.common.utils.DateUtil;
|
|
|
-import com.lote.wms.common.utils.NumberUtil;
|
|
|
-import com.lote.wms.common.utils.StringUtil;
|
|
|
import com.lote.wms.inventory.check.dao.InventoryCheckMapper;
|
|
|
import com.lote.wms.inventory.check.entity.InventoryCheck;
|
|
|
import com.lote.wms.inventory.check.entity.InventoryCheckCriteria;
|
|
@@ -70,6 +70,9 @@ public class InventoryCheckServiceImpl implements InventoryCheckService {
|
|
|
@Resource
|
|
|
private InventoryCheckDetailService inventoryCheckDetailService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SystemConfig systemConfig;
|
|
|
+
|
|
|
private static final Logger logger = LoggerFactory.getLogger(InventoryCheckServiceImpl.class);
|
|
|
|
|
|
public InventoryCheck add(InventoryCheck record) {
|
|
@@ -559,11 +562,11 @@ public class InventoryCheckServiceImpl implements InventoryCheckService {
|
|
|
return message;
|
|
|
}
|
|
|
if (!StringUtil.isEquals(check.getStatusCode(), InventoryCheckStatusEnum.CONFIRM.getCode())) {
|
|
|
- message.setMsg("只有确认差异状态的盘点单可以操作生效");
|
|
|
+ message.setMsg("只有确认差异状态的盘点单可以操作完结");
|
|
|
return message;
|
|
|
}
|
|
|
if (StringUtil.isEquals(check.getStatusCode(), InventoryCheckStatusEnum.EFFECT.getCode())) {
|
|
|
- message.setMsg("该盘点单状态已确认生效");
|
|
|
+ message.setMsg("该盘点单状态已确认完结");
|
|
|
return message;
|
|
|
}
|
|
|
|
|
@@ -599,33 +602,33 @@ public class InventoryCheckServiceImpl implements InventoryCheckService {
|
|
|
}
|
|
|
|
|
|
// -----------------------------------开始更新库存
|
|
|
- InventoryVo inventoryVo = new InventoryVo();
|
|
|
- inventoryVo.setId(inventory.getId());
|
|
|
- BeanUtil.copy(inventory, inventoryVo);
|
|
|
- inventoryVo.setRefNo(check.getCode());
|
|
|
- inventoryVo.setUserCode(user.getCode());
|
|
|
- inventoryVo.setUserId(user.getId());
|
|
|
- if (diffQty > 0) {
|
|
|
- // 盘盈生效
|
|
|
- inventoryVo.setChangeQty(diffQty);
|
|
|
- inventoryVo.setOpType(InventoryOpTypeEnum.INVENTORY_CHECK_GAINS_EFFECT);
|
|
|
- Message addQtyMessage = inventoryService.addQty(inventoryVo);
|
|
|
- // 如添加库存失败,抛异常将上面的操作回滚
|
|
|
- if (!addQtyMessage.isSuccess()) {
|
|
|
- throw new ServiceException(addQtyMessage.getMsg());
|
|
|
- }
|
|
|
- gains++;
|
|
|
-
|
|
|
- } else {
|
|
|
- // 盘亏
|
|
|
- inventoryVo.setChangeQty(-diffQty);
|
|
|
- inventoryVo.setOpType(InventoryOpTypeEnum.INVENTORY_CHECK_LOSS_EFFECT);
|
|
|
- Message cutInventoryMessage = inventoryService.cutQty(inventoryVo);
|
|
|
- if (!cutInventoryMessage.isSuccess()) {
|
|
|
- throw new ServiceException(cutInventoryMessage.getMsg());
|
|
|
- }
|
|
|
- loss++;
|
|
|
- }
|
|
|
+// InventoryVo inventoryVo = new InventoryVo();
|
|
|
+// inventoryVo.setId(inventory.getId());
|
|
|
+// BeanUtil.copy(inventory, inventoryVo);
|
|
|
+// inventoryVo.setRefNo(check.getCode());
|
|
|
+// inventoryVo.setUserCode(user.getCode());
|
|
|
+// inventoryVo.setUserId(user.getId());
|
|
|
+// if (diffQty > 0) {
|
|
|
+// // 盘盈生效
|
|
|
+// inventoryVo.setChangeQty(diffQty);
|
|
|
+// inventoryVo.setOpType(InventoryOpTypeEnum.INVENTORY_CHECK_GAINS_EFFECT);
|
|
|
+// Message addQtyMessage = inventoryService.addQty(inventoryVo);
|
|
|
+// // 如添加库存失败,抛异常将上面的操作回滚
|
|
|
+// if (!addQtyMessage.isSuccess()) {
|
|
|
+// throw new ServiceException(addQtyMessage.getMsg());
|
|
|
+// }
|
|
|
+// gains++;
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// // 盘亏
|
|
|
+// inventoryVo.setChangeQty(-diffQty);
|
|
|
+// inventoryVo.setOpType(InventoryOpTypeEnum.INVENTORY_CHECK_LOSS_EFFECT);
|
|
|
+// Message cutInventoryMessage = inventoryService.cutQty(inventoryVo);
|
|
|
+// if (!cutInventoryMessage.isSuccess()) {
|
|
|
+// throw new ServiceException(cutInventoryMessage.getMsg());
|
|
|
+// }
|
|
|
+// loss++;
|
|
|
+// }
|
|
|
// -----------------------------------结束更新库存
|
|
|
|
|
|
detail.setIsEffect(BaseConstant.Y);
|
|
@@ -643,9 +646,87 @@ public class InventoryCheckServiceImpl implements InventoryCheckService {
|
|
|
|
|
|
update(check);
|
|
|
|
|
|
- message.setMsg("确认生效成功,盘盈记录数:" + gains + ",盘亏记录数:" + loss);
|
|
|
+// message.setMsg("确认生效成功,盘盈记录数:" + gains + ",盘亏记录数:" + loss);
|
|
|
+ message.setMsg("确认完结成功。" );
|
|
|
message.setSuccess(true);
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Message export(Map<String, Object> map) {
|
|
|
+ String id = (String) map.get("id");
|
|
|
+ if (Objects.isNull(id) || "".equals(id)){
|
|
|
+ return Message.fail("请选择一条数据!");
|
|
|
+ }
|
|
|
+ InventoryCheck check = get(id);
|
|
|
+ if (check == null) {
|
|
|
+ return Message.fail("盘点单id不存在!");
|
|
|
+ }
|
|
|
+ if (!StringUtil.isEquals(check.getStatusCode(), InventoryCheckStatusEnum.EFFECT.getCode())) {
|
|
|
+ return Message.fail("盘点单状态已确认完结才可以导出");
|
|
|
+ }
|
|
|
+
|
|
|
+ String headCnStrList[] = new String[] { "序号", "货位", "货品编码", "UPC", "货品描述", "货主名称", "在库数量", "盘点数", "备注",
|
|
|
+ "库存状态" };
|
|
|
+ Sheet sheet = null;
|
|
|
+ List<String> headCnList = Arrays.asList(headCnStrList);
|
|
|
+ try {
|
|
|
+ sheet = POIExcelUtil.createSheet("盘点单明细", headCnList);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<InventoryCheckDetail> inventoryCheckDetailList = inventoryCheckDetailService.listByCheckId(check.getId());
|
|
|
+ if (Objects.isNull(inventoryCheckDetailList) || inventoryCheckDetailList.size()==0){
|
|
|
+ return Message.fail("该盘点单无明细");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换成行
|
|
|
+ List<String[]> row = parseRow(inventoryCheckDetailList, headCnList);
|
|
|
+ // 保存到excel中
|
|
|
+ POIExcelUtil.addRows(sheet, row);
|
|
|
+
|
|
|
+
|
|
|
+ // 保存到临时文件返回路径 TODO
|
|
|
+ try {
|
|
|
+ // 随机生成文件
|
|
|
+ String fileName = UUID.randomUUID().toString() + ".xlsx";
|
|
|
+ File tempFile = new File(systemConfig.getRuntimeFileDir() + "/inventory/");
|
|
|
+ if (!tempFile.exists()) {
|
|
|
+ tempFile.mkdirs();
|
|
|
+ }
|
|
|
+ String fileNameAndPath = systemConfig.getRuntimeFileDir() + "/inventory/" + 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<InventoryCheckDetail> inventoryCheckDetailList, List<String> headCnList) {
|
|
|
+ List<String[]> rows = new ArrayList<>();
|
|
|
+ int number=1;
|
|
|
+ for (InventoryCheckDetail inventoryCheckDetail : inventoryCheckDetailList) {
|
|
|
+ String[] row = new String[headCnList.size()];
|
|
|
+ row[0] = String.valueOf(number++);
|
|
|
+ row[1] = inventoryCheckDetail.getLocationCode();
|
|
|
+ row[2] = inventoryCheckDetail.getSku();
|
|
|
+ row[3] = inventoryCheckDetail.getBarcode();
|
|
|
+ row[4] = inventoryCheckDetail.getProductName();
|
|
|
+ row[5] = inventoryCheckDetail.getCustomerCode();
|
|
|
+ row[6] = String.valueOf(inventoryCheckDetail.getSysQty());
|
|
|
+ row[7] = String.valueOf(inventoryCheckDetail.getCheckQty());
|
|
|
+ row[8] = inventoryCheckDetail.getRemark();
|
|
|
+ Inventory inventory = inventoryService.get(inventoryCheckDetail.getInventoryId());
|
|
|
+ row[9] = inventory.getStatusName();
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
}
|