|
@@ -2,15 +2,23 @@ package com.iamberry.rst.service.cm;
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
+import com.iamberry.rst.core.cm.SalesOrderItem;
|
|
|
import com.iamberry.rst.core.fm.InventoryInfo;
|
|
|
+import com.iamberry.rst.core.fm.InventoryLog;
|
|
|
+import com.iamberry.rst.core.order.OrderWarehouse;
|
|
|
import com.iamberry.rst.core.page.PageRequest;
|
|
|
import com.iamberry.rst.core.page.PagedResult;
|
|
|
import com.iamberry.rst.faces.cm.InventoryService;
|
|
|
+import com.iamberry.rst.service.fm.mapper.InventoryLogMapper;
|
|
|
import com.iamberry.rst.service.fm.mapper.InventoryMapper;
|
|
|
+import com.iamberry.rst.service.order.mapper.OrderWarehouseMapper;
|
|
|
import com.iamberry.rst.util.PageUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -18,8 +26,15 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class InventoryServiceImpl implements InventoryService {
|
|
|
+
|
|
|
+ private static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
@Autowired
|
|
|
private InventoryMapper inventoryMapper;
|
|
|
+ @Autowired
|
|
|
+ private InventoryLogMapper inventoryLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private OrderWarehouseMapper orderWarehouseMapper;
|
|
|
|
|
|
@Override
|
|
|
public InventoryInfo getByInventoryId(Integer inventoryId) {
|
|
@@ -48,4 +63,172 @@ public class InventoryServiceImpl implements InventoryService {
|
|
|
public Integer insert(InventoryInfo inventoryInfo) {
|
|
|
return inventoryMapper.insert(inventoryInfo);
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Integer addInventory(InventoryInfo invent) {
|
|
|
+ Integer flag = 0;
|
|
|
+ if(invent.getInventoryProductBar() == null || invent.getWarehouseId() == null){
|
|
|
+ throw new RuntimeException("【入库】更新库存失败,入库需要产品SKU与仓库ID。");
|
|
|
+ }
|
|
|
+ OrderWarehouse orderWarehouse = orderWarehouseMapper.getOrderWarehouseById(invent.getWarehouseId());
|
|
|
+ if(orderWarehouse == null){
|
|
|
+ throw new RuntimeException("【入库】更新库存失败,查询仓库信息失败。");
|
|
|
+ }
|
|
|
+ String warehouseName = orderWarehouse.getWarehouseName();
|
|
|
+ InventoryInfo info = inventoryMapper.getByInventoryByBar(invent.getInventoryProductBar(),invent.getWarehouseId());
|
|
|
+ if(info != null){
|
|
|
+ boolean isNumUpadate = false;
|
|
|
+ Integer logType = 0;
|
|
|
+ Integer num = 0; //数量
|
|
|
+ Integer logQualityType=0;//1.良品 2不良品
|
|
|
+ InventoryInfo newInent = new InventoryInfo();
|
|
|
+ newInent.setInventoryId(info.getInventoryId());
|
|
|
+
|
|
|
+ //inventoryGoodProductNum;//良品数量
|
|
|
+ if(invent.getInventoryGoodProductNum() != null && invent.getInventoryGoodProductNum() != 0 ){
|
|
|
+ newInent.setOperationNum(info.getInventoryGoodProductNum() + invent.getInventoryGoodProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(sdf.format(new Date())+"[良品]入库:"+invent.getInventoryGoodProductNum()+"件");
|
|
|
+ isNumUpadate = true;
|
|
|
+ num = invent.getInventoryGoodProductNum();
|
|
|
+ logQualityType = 1;
|
|
|
+ }else if(invent.getInventoryDefectiveProductNum() != null && invent.getInventoryDefectiveProductNum() != 0 ){
|
|
|
+ //inventoryDefectiveProductNum;//不良品数量
|
|
|
+ newInent.setOperationNum(info.getInventoryDefectiveProductNum() + invent.getInventoryDefectiveProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(sdf.format(new Date())+"[不良品]入库:"+invent.getInventoryDefectiveProductNum()+"件");
|
|
|
+ isNumUpadate = true;
|
|
|
+ num = invent.getInventoryDefectiveProductNum();
|
|
|
+ logQualityType = 2;
|
|
|
+ }
|
|
|
+// else if(invent.getInventoryRemainingNum() != null && invent.getInventoryRemainingNum() != 0 ){
|
|
|
+// // inventoryRemainingNum;//库存剩余数量
|
|
|
+// newInent.setOperationNum(info.getInventoryRemainingNum() - invent.getInventoryRemainingNum());
|
|
|
+// info.setInventoryRecentRecord(sdf.format(new Date())+"[剩余库存]出库:"+invent.getInventoryRemainingNum()+"件");
|
|
|
+// isNumUpadate = true;
|
|
|
+// num = invent.getInventoryRemainingNum();
|
|
|
+// }
|
|
|
+ if(isNumUpadate && logQualityType != 0 && num != 0){
|
|
|
+ flag = inventoryMapper.updateById(newInent);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("【入库】更新库存失败,库存修改失败。");
|
|
|
+ }
|
|
|
+ InventoryLog inventoryLog = new InventoryLog();
|
|
|
+ inventoryLog.setLogProductName(info.getInventoryProductName());
|
|
|
+ inventoryLog.setLogProductBar(info.getInventoryProductBar());
|
|
|
+ inventoryLog.setLogRemainingNum(num);
|
|
|
+ if(invent.getLogType() != null && invent.getLogType()!=0){
|
|
|
+ inventoryLog.setLogType(invent.getLogType()); //类型1.采购 2.发货 3.次品
|
|
|
+ }else{
|
|
|
+ inventoryLog.setLogType(1); //类型1.采购 2.发货 3.次品
|
|
|
+ }
|
|
|
+ inventoryLog.setLogOperationType(1); //增加
|
|
|
+ inventoryLog.setLogDesc(sdf.format(new Date())+"入库:"+num+"件");
|
|
|
+ inventoryLog.setLogQualityType(logQualityType);
|
|
|
+ inventoryLog.setLogWarehouseId(invent.getWarehouseId());
|
|
|
+ flag = inventoryLogMapper.insert(inventoryLog);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("【入库】更新库存失败,增加库存记录失败。");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("【入库】更新库存失败,数量未变动或数据出错。");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("【入库】更新库存失败,未查询到库存信息,请确认“"+ warehouseName +"”是否有该产品["+ invent.getInventoryProductBar()+ "]的库存信息。");
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Integer minusInventory(InventoryInfo invent) {
|
|
|
+ Integer flag = 0;
|
|
|
+ if(invent.getInventoryProductBar() == null || invent.getWarehouseId() == null){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,出库需要产品SKU与仓库ID。");
|
|
|
+ }
|
|
|
+ OrderWarehouse orderWarehouse = orderWarehouseMapper.getOrderWarehouseById(invent.getWarehouseId());
|
|
|
+ if(orderWarehouse == null){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,查询仓库信息失败。");
|
|
|
+ }
|
|
|
+ String warehouseName = orderWarehouse.getWarehouseName();
|
|
|
+ InventoryInfo info = inventoryMapper.getByInventoryByBar(invent.getInventoryProductBar(),invent.getWarehouseId());
|
|
|
+ if(info != null){
|
|
|
+ boolean isNumUpadate = false;
|
|
|
+ Integer logType = 0;
|
|
|
+ Integer num = 0; //数量
|
|
|
+ Integer logQualityType=0;//1.良品 2不良品
|
|
|
+ InventoryInfo newInent = new InventoryInfo();
|
|
|
+ newInent.setInventoryId(info.getInventoryId());
|
|
|
+
|
|
|
+ //inventoryGoodProductNum;//良品数量
|
|
|
+ if(invent.getInventoryGoodProductNum() != null && invent.getInventoryGoodProductNum() != 0 ){
|
|
|
+ if(info.getInventoryGoodProductNum() > invent.getInventoryGoodProductNum()){
|
|
|
+ newInent.setOperationNum(info.getInventoryGoodProductNum() - invent.getInventoryGoodProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(sdf.format(new Date())+"[良品]出库:"+invent.getInventoryGoodProductNum()+"件");
|
|
|
+ isNumUpadate = true;
|
|
|
+ num = invent.getInventoryGoodProductNum();
|
|
|
+ logQualityType = 1;
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,"+ warehouseName +"["+ info.getInventoryProductName()+ "("+ info.getProductColorName() +")" +"][良品数量]库存不足。");
|
|
|
+ }
|
|
|
+ }else if(invent.getInventoryDefectiveProductNum() != null && invent.getInventoryDefectiveProductNum() != 0 ){
|
|
|
+ //inventoryDefectiveProductNum;//不良品数量
|
|
|
+ if(info.getInventoryDefectiveProductNum() > invent.getInventoryDefectiveProductNum()){
|
|
|
+ newInent.setOperationNum(info.getInventoryDefectiveProductNum() - invent.getInventoryDefectiveProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(sdf.format(new Date())+"[不良品]出库:"+invent.getInventoryDefectiveProductNum()+"件");
|
|
|
+ isNumUpadate = true;
|
|
|
+ num = invent.getInventoryDefectiveProductNum();
|
|
|
+ logQualityType = 2;
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,"+ warehouseName +"["+ info.getInventoryProductName()+ "("+ info.getProductColorName() +")" +"][不良品]库存不足。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+// else if(invent.getInventoryRemainingNum() != null && invent.getInventoryRemainingNum() != 0 ){
|
|
|
+// // inventoryRemainingNum;//库存剩余数量
|
|
|
+// if(info.getInventoryRemainingNum() > invent.getInventoryRemainingNum()){
|
|
|
+// newInent.setOperationNum(info.getInventoryRemainingNum() - invent.getInventoryRemainingNum());
|
|
|
+// info.setInventoryRecentRecord(sdf.format(new Date())+"[剩余库存]出库:"+invent.getInventoryRemainingNum()+"件");
|
|
|
+// isNumUpadate = true;
|
|
|
+// num = invent.getInventoryRemainingNum();
|
|
|
+// }else{
|
|
|
+// throw new RuntimeException("【出库】更新库存失败,"+ warehouseName +"["+ info.getInventoryProductName()+ "("+ info.getProductColorName() +")" +"][剩余数量]库存不足。");
|
|
|
+// }
|
|
|
+// }
|
|
|
+ if(isNumUpadate && logQualityType != 0){
|
|
|
+ flag = inventoryMapper.updateById(newInent);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,库存修改失败。");
|
|
|
+ }
|
|
|
+ InventoryLog inventoryLog = new InventoryLog();
|
|
|
+ inventoryLog.setLogProductName(info.getInventoryProductName());
|
|
|
+ inventoryLog.setLogProductBar(info.getInventoryProductBar());
|
|
|
+ inventoryLog.setLogRemainingNum(num);
|
|
|
+ inventoryLog.setLogType(2); //类型1.采购 2.发货 3.次品
|
|
|
+ inventoryLog.setLogOperationType(2); //减去
|
|
|
+ inventoryLog.setLogDesc(sdf.format(new Date())+"待发货标记出库:"+num+"件");
|
|
|
+ inventoryLog.setLogQualityType(logQualityType);
|
|
|
+ inventoryLog.setLogWarehouseId(invent.getWarehouseId());
|
|
|
+ flag = inventoryLogMapper.insert(inventoryLog);
|
|
|
+ if(flag < 1){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,增加库存记录失败。");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,数量未变动或数据出错。");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,未查询到库存信息,请确认“"+ warehouseName +"”是否有该产品["+ invent.getInventoryProductBar()+ "]的库存信息。");
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String addInventoryList(List<InventoryInfo> inventoryInfoList) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String minusInventoryList(List<InventoryInfo> inventoryInfoList) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|