|
@@ -2,15 +2,26 @@ 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.order.ProductColor;
|
|
|
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.service.product.mapper.ProductColorMapper;
|
|
|
import com.iamberry.rst.util.PageUtil;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
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 +29,17 @@ 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;
|
|
|
+ @Autowired
|
|
|
+ private ProductColorMapper productColorMapper;
|
|
|
|
|
|
@Override
|
|
|
public InventoryInfo getByInventoryId(Integer inventoryId) {
|
|
@@ -48,4 +68,216 @@ 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.getWarehouseId() == null){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,出库仓库ID。");
|
|
|
+ }
|
|
|
+ if(invent.getInventoryProductBar() == null && invent.getInventoryProductColorId() == null){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,出库需要产品SKU或颜色ID。");
|
|
|
+ }else{
|
|
|
+ ProductColor productColor = null;
|
|
|
+ if(!StringUtils.isEmpty(invent.getInventoryProductBar())){
|
|
|
+ productColor = productColorMapper.getProductColorByBar(invent.getInventoryProductBar());
|
|
|
+ }else{
|
|
|
+ productColor = productColorMapper.getProductColorById(invent.getInventoryProductColorId());
|
|
|
+ }
|
|
|
+ if(productColor != null){
|
|
|
+ invent.setInventoryProductBar(productColor.getColorBar());
|
|
|
+ }else{
|
|
|
+ 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());
|
|
|
+
|
|
|
+ String record = "";
|
|
|
+ if(!StringUtils.isEmpty(invent.getInventoryRecentRecord())){
|
|
|
+ record = invent.getInventoryRecentRecord();
|
|
|
+ }
|
|
|
+ //日志记录与 库存最后记录保持一致
|
|
|
+ String logRecord = "";
|
|
|
+
|
|
|
+ //inventoryGoodProductNum;//良品数量
|
|
|
+ if(invent.getInventoryGoodProductNum() != null && invent.getInventoryGoodProductNum() != 0 ){
|
|
|
+ logRecord = sdf.format(new Date())+"[良品]入库"+invent.getInventoryGoodProductNum()+"件,"+record;
|
|
|
+ newInent.setInventoryGoodProductNum(info.getInventoryGoodProductNum() + invent.getInventoryGoodProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(logRecord);
|
|
|
+ isNumUpadate = true;
|
|
|
+ num = invent.getInventoryGoodProductNum();
|
|
|
+ logQualityType = 1;
|
|
|
+ }else if(invent.getInventoryDefectiveProductNum() != null && invent.getInventoryDefectiveProductNum() != 0 ){
|
|
|
+ //inventoryDefectiveProductNum;//不良品数量
|
|
|
+ logRecord = sdf.format(new Date())+"[不良品]入库"+invent.getInventoryDefectiveProductNum()+"件,"+record;
|
|
|
+ newInent.setInventoryDefectiveProductNum(info.getInventoryDefectiveProductNum() + invent.getInventoryDefectiveProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(logRecord);
|
|
|
+ isNumUpadate = true;
|
|
|
+ num = invent.getInventoryDefectiveProductNum();
|
|
|
+ logQualityType = 2;
|
|
|
+ }
|
|
|
+// else if(invent.getInventoryRemainingNum() != null && invent.getInventoryRemainingNum() != 0 ){
|
|
|
+// // inventoryRemainingNum;//库存剩余数量
|
|
|
+// newInent.setInventoryRemainingNum(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(logRecord);
|
|
|
+ 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.getWarehouseId() == null){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,出库仓库ID。");
|
|
|
+ }
|
|
|
+ if(invent.getInventoryProductBar() == null && invent.getInventoryProductColorId() == null){
|
|
|
+ throw new RuntimeException("【出库】更新库存失败,出库需要产品SKU或颜色ID。");
|
|
|
+ }else{
|
|
|
+ ProductColor productColor = null;
|
|
|
+ if(!StringUtils.isEmpty(invent.getInventoryProductBar())){
|
|
|
+ productColor = productColorMapper.getProductColorByBar(invent.getInventoryProductBar());
|
|
|
+ }else{
|
|
|
+ productColor = productColorMapper.getProductColorById(invent.getInventoryProductColorId());
|
|
|
+ }
|
|
|
+ if(productColor != null){
|
|
|
+ invent.setInventoryProductBar(productColor.getColorBar());
|
|
|
+ }else{
|
|
|
+ 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());
|
|
|
+
|
|
|
+ String record = "";
|
|
|
+ if(!StringUtils.isEmpty(invent.getInventoryRecentRecord())){
|
|
|
+ record = invent.getInventoryRecentRecord();
|
|
|
+ }
|
|
|
+
|
|
|
+ //日志记录与 库存最后记录保持一致
|
|
|
+ String logRecord = "";
|
|
|
+
|
|
|
+ //inventoryGoodProductNum;//良品数量
|
|
|
+ if(invent.getInventoryGoodProductNum() != null && invent.getInventoryGoodProductNum() != 0 ){
|
|
|
+ if(info.getInventoryGoodProductNum() > invent.getInventoryGoodProductNum()){
|
|
|
+ logRecord = sdf.format(new Date())+"[良品]出库"+invent.getInventoryGoodProductNum()+"件,"+record;
|
|
|
+ newInent.setInventoryGoodProductNum(info.getInventoryGoodProductNum() - invent.getInventoryGoodProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(logRecord);
|
|
|
+ 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()){
|
|
|
+ logRecord = sdf.format(new Date())+"[不良品]出库"+invent.getInventoryDefectiveProductNum()+"件,"+record;
|
|
|
+ newInent.setInventoryDefectiveProductNum(info.getInventoryDefectiveProductNum() - invent.getInventoryDefectiveProductNum());
|
|
|
+ newInent.setInventoryRecentRecord(logRecord);
|
|
|
+ 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.setInventoryRemainingNum(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);
|
|
|
+ if(invent.getLogType() != null && invent.getLogType()!=0){
|
|
|
+ inventoryLog.setLogType(invent.getLogType()); //类型1.采购 2.发货 3.次品
|
|
|
+ }else{
|
|
|
+ inventoryLog.setLogType(1); //类型1.采购 2.发货 3.次品
|
|
|
+ }
|
|
|
+ inventoryLog.setLogOperationType(2); //减去
|
|
|
+ inventoryLog.setLogDesc(logRecord);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|