浏览代码

Merge remote-tracking branch 'origin/dev_huangjunjie'

yz 19 小时之前
父节点
当前提交
f044e67a87

+ 4 - 0
src/main/java/com/jsh/erp/constants/ExceptionConstants.java

@@ -387,6 +387,10 @@ public class ExceptionConstants {
     public static final int MATERIAL_DEFAULT_WHOLESALE_DECIMAL_NOT_DECIMAL_CODE = 8000037;
     public static final int MATERIAL_DEFAULT_WHOLESALE_DECIMAL_NOT_DECIMAL_CODE = 8000037;
     public static final String MATERIAL_DEFAULT_WHOLESALE_DECIMAL_NOT_DECIMAL_MSG = "第%s行默认销售价格式错误";
     public static final String MATERIAL_DEFAULT_WHOLESALE_DECIMAL_NOT_DECIMAL_MSG = "第%s行默认销售价格式错误";
 
 
+    //基础重量格式错误
+    public static final int MATERIAL_STOCK_NOT_DECIMAL_CODE = 8000038;
+    public static final String MATERIAL_STOCK_NOT_DECIMAL_MSG = "第%s行期初库存格式错误";
+
     /**
     /**
      *  单据信息
      *  单据信息
      * type = 85
      * type = 85

+ 1 - 1
src/main/java/com/jsh/erp/controller/pda/PdaController.java

@@ -136,7 +136,7 @@ public class PdaController extends BaseController {
     @ApiOperation("商品详情")
     @ApiOperation("商品详情")
     @GetMapping("/materialDetail/{id}/{depotId}")
     @GetMapping("/materialDetail/{id}/{depotId}")
     public AjaxResult materialDetail(@PathVariable("id") Long id, @PathVariable("depotId") Long depotId) throws Exception {
     public AjaxResult materialDetail(@PathVariable("id") Long id, @PathVariable("depotId") Long depotId) throws Exception {
-        return AjaxResult.success(depotItemService.pdaDetail(id));
+        return AjaxResult.success(depotItemService.pdaDetail(id,depotId));
     }
     }
 
 
     @ApiOperation("商品库存详情")
     @ApiOperation("商品库存详情")

+ 3 - 0
src/main/java/com/jsh/erp/datasource/entities/MaterialBatch.java

@@ -90,4 +90,7 @@ public class MaterialBatch {
     @ApiModelProperty("单据id")
     @ApiModelProperty("单据id")
     private Long depotItemId;
     private Long depotItemId;
 
 
+    @ApiModelProperty("商品扩展id")
+    private Long materialExtendId;
+
 }
 }

+ 1 - 1
src/main/java/com/jsh/erp/service/DepotItemService.java

@@ -31,7 +31,7 @@ public interface DepotItemService extends IService<DepotItem> {
      * @param id 商品订单ID
      * @param id 商品订单ID
      * @return
      * @return
      */
      */
-    PDADepotItemVO pdaDetail(Long id) throws Exception;
+    PDADepotItemVO pdaDetail(Long id, Long depotId) throws Exception;
 
 
     /**
     /**
      * 商品库存详情列表
      * 商品库存详情列表

+ 3 - 3
src/main/java/com/jsh/erp/service/impl/DepotItemServiceImpl.java

@@ -114,14 +114,14 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
      * @return
      * @return
      */
      */
     @Override
     @Override
-    public PDADepotItemVO pdaDetail(Long id) throws Exception {
+    public PDADepotItemVO pdaDetail(Long id, Long depotId) throws Exception {
         PDADepotItemVO itemVO = depotItemMapper.pdaDetail(id);
         PDADepotItemVO itemVO = depotItemMapper.pdaDetail(id);
         Unit unitInfo = materialService.findUnit(itemVO.getMaterialId()); //查询多单位信息
         Unit unitInfo = materialService.findUnit(itemVO.getMaterialId()); //查询多单位信息
         BigDecimal stock;
         BigDecimal stock;
         if (unitInfo != null && unitInfo.getId() != null){
         if (unitInfo != null && unitInfo.getId() != null){
-            stock = unitService.parseStockByUnit(materialService.getMaterialStockByMid(itemVO.getMaterialId()),unitInfo,itemVO.getCommodityUnit());
+            stock = unitService.parseStockByUnit(materialService.getCurrentStockByMaterialIdAndDepotId(itemVO.getMaterialId(),depotId),unitInfo,itemVO.getMaterialUnit());
         }else {
         }else {
-            stock = materialService.getMaterialStockByMid(itemVO.getMaterialId());
+            stock = materialService.getCurrentStockByMaterialIdAndDepotId(itemVO.getMaterialId(),depotId);
         }
         }
         itemVO.setInventory(stock.toString());
         itemVO.setInventory(stock.toString());
         return itemVO;
         return itemVO;

+ 49 - 28
src/main/java/com/jsh/erp/service/impl/MaterialBatchServiceImpl.java

@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.MaterialBatchMapper;
 import com.jsh.erp.datasource.mappers.MaterialBatchMapper;
+import com.jsh.erp.datasource.mappers.MaterialInitialStockMapper;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
 import com.jsh.erp.exception.JshException;
 import com.jsh.erp.exception.JshException;
 import com.jsh.erp.query.LambdaQueryWrapperX;
 import com.jsh.erp.query.LambdaQueryWrapperX;
+import com.jsh.erp.query.QueryWrapperX;
 import com.jsh.erp.service.*;
 import com.jsh.erp.service.*;
 import com.jsh.erp.utils.DateUtils;
 import com.jsh.erp.utils.DateUtils;
 import com.jsh.erp.utils.RandomHelper;
 import com.jsh.erp.utils.RandomHelper;
@@ -40,6 +42,9 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
     @Resource
     @Resource
     private InventoryLogService inventoryLogService;
     private InventoryLogService inventoryLogService;
 
 
+    @Resource
+    private MaterialInitialStockMapper materialInitialStockMapper;
+
 
 
     /**
     /**
      * 根据单据子表id生成商品批次数据
      * 根据单据子表id生成商品批次数据
@@ -82,28 +87,45 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
         materialBatch.setPosition(depotItem.getPosition());
         materialBatch.setPosition(depotItem.getPosition());
         //条码
         //条码
         materialBatch.setBarCode(materialExtend.getBarCode());
         materialBatch.setBarCode(materialExtend.getBarCode());
+        materialBatch.setMaterialExtendId(materialExtend.getId());
         materialBatchMapper.insert(materialBatch);
         materialBatchMapper.insert(materialBatch);
     }
     }
 
 
     @Override
     @Override
     public void handleMaterialBatchByDepotItemId(Long diId) throws Exception {
     public void handleMaterialBatchByDepotItemId(Long diId) throws Exception {
         DepotItem depotItem = depotItemService.getDepotItem(diId);
         DepotItem depotItem = depotItemService.getDepotItem(diId);
+        //获取商品期初库存
+        MaterialInitialStock mis = materialInitialStockMapper.selectOne(new LambdaQueryWrapperX<MaterialInitialStock>()
+                .eq(MaterialInitialStock::getMaterialId,depotItem.getMaterialId())
+                .eq(MaterialInitialStock::getDepotId,depotItem.getDepotId())
+                .eq(MaterialInitialStock::getDeleteFlag,"0"));
         //根据单据商品id查询商品批次数据
         //根据单据商品id查询商品批次数据
         List<MaterialBatch> list = materialBatchMapper.getMaterialBatchByMaterialId(depotItem.getMaterialId(),depotItem.getDepotId());
         List<MaterialBatch> list = materialBatchMapper.getMaterialBatchByMaterialId(depotItem.getMaterialId(),depotItem.getDepotId());
         //根据单据子表基础单位数量减去批次库存
         //根据单据子表基础单位数量减去批次库存
         BigDecimal basicNumber = depotItem.getBasicNumber();
         BigDecimal basicNumber = depotItem.getBasicNumber();
-        for (MaterialBatch materialBatch : list) {
-            if (materialBatch.getInventory().compareTo(basicNumber) >= 0){
-                //批次库存足够,扣除库存,结束循环
-                BigDecimal inventory = materialBatch.getInventory().subtract(basicNumber);
-                materialBatch.setInventory(inventory);
-                updateInventory("出库",diId,materialBatch);
-                break;
-            }else {
-                //库存不足,扣除当前批次库存,继续循环
-                basicNumber = basicNumber.subtract(materialBatch.getInventory());
-                materialBatch.setInventory(BigDecimal.ZERO);
-                updateInventory("出库",diId,materialBatch);
+        if (mis.getNumber() != null && mis.getNumber().compareTo(basicNumber) >= 0){
+            //初期库存足够,扣除期初库存
+            BigDecimal inventory = mis.getNumber().subtract(basicNumber);
+            mis.setNumber(inventory);
+            materialInitialStockMapper.updateByPrimaryKeySelective(mis);
+        }else {
+            //初期库存不足,先扣除期初,再从批次扣除
+            basicNumber = basicNumber.subtract(mis.getNumber());
+            mis.setNumber(BigDecimal.ZERO);
+            materialInitialStockMapper.updateByPrimaryKeySelective(mis);
+            for (MaterialBatch materialBatch : list) {
+                if (materialBatch.getInventory().compareTo(basicNumber) >= 0){
+                    //批次库存足够,扣除库存,结束循环
+                    BigDecimal inventory = materialBatch.getInventory().subtract(basicNumber);
+                    materialBatch.setInventory(inventory);
+                    updateInventory("出库",diId,materialBatch);
+                    break;
+                }else {
+                    //库存不足,扣除当前批次库存,继续循环
+                    basicNumber = basicNumber.subtract(materialBatch.getInventory());
+                    materialBatch.setInventory(BigDecimal.ZERO);
+                    updateInventory("出库",diId,materialBatch);
+                }
             }
             }
         }
         }
     }
     }
@@ -113,19 +135,19 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
         if (materialBatch.getInventory() != null){
         if (materialBatch.getInventory() != null){
             //获取修改前库存
             //获取修改前库存
             int originalStock = materialBatchMapper.selectOne("id",materialBatch.getId()).getInventory().intValue();
             int originalStock = materialBatchMapper.selectOne("id",materialBatch.getId()).getInventory().intValue();
-                User user = userService.getCurrentUser();
-                InventoryLog log = new InventoryLog();
-                log.setUpdateUser(user.getId());
-                log.setUpdateTime(new Date());
-                log.setMaterialId(materialBatch.getMaterialId());
-                log.setMaterialExtendId(materialBatch.getId());
-                log.setOriginalStock(originalStock);
-                log.setCurrentStock(materialBatch.getInventory().intValue());
-                log.setItemId(id);
-                log.setType(type);
-                inventoryLogService.save(log);
-                update(new UpdateWrapper<MaterialBatch>().set("inventory",materialBatch.getInventory()).eq("id",materialBatch.getId()));
-                depotItemService.updateCurrentStockFun(materialBatch.getMaterialId(),materialBatch.getDepotId());
+            User user = userService.getCurrentUser();
+            InventoryLog log = new InventoryLog();
+            log.setUpdateUser(user.getId());
+            log.setUpdateTime(new Date());
+            log.setMaterialId(materialBatch.getMaterialId());
+            log.setMaterialExtendId(materialBatch.getId());
+            log.setOriginalStock(originalStock);
+            log.setCurrentStock(materialBatch.getInventory().intValue());
+            log.setItemId(id);
+            log.setType(type);
+            inventoryLogService.save(log);
+            update(new UpdateWrapper<MaterialBatch>().set("inventory",materialBatch.getInventory()).eq("id",materialBatch.getId()));
+            depotItemService.updateCurrentStockFun(materialBatch.getMaterialId(),materialBatch.getDepotId());
         }
         }
     }
     }
 
 
@@ -146,7 +168,6 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
     public List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, String standardOrModel, String color, String brand, String mfrs, String enableSerialNumber, String enableBatchNumber, Integer offset, Integer rows, Long depotId) throws Exception {
     public List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, String standardOrModel, String color, String brand, String mfrs, String enableSerialNumber, String enableBatchNumber, Integer offset, Integer rows, Long depotId) throws Exception {
         List<MaterialVo4Unit> list =null;
         List<MaterialVo4Unit> list =null;
         try{
         try{
-
             if(StringUtil.isNotEmpty(q)) {
             if(StringUtil.isNotEmpty(q)) {
                 q = q.replace("'", "");
                 q = q.replace("'", "");
                 q = q.trim();
                 q = q.trim();
@@ -169,8 +190,8 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
         if (barCodes != null && !barCodes.isEmpty()){
         if (barCodes != null && !barCodes.isEmpty()){
             barCodeList = Arrays.asList(barCodes.split(","));
             barCodeList = Arrays.asList(barCodes.split(","));
         }
         }
-        List<Long> ids = materialExtendService.selectIdsByBarCode(barCodeList);
-        List<MaterialBatch> list = materialBatchMapper.selectList(new LambdaQueryWrapperX<MaterialBatch>().eq(MaterialBatch::getDepotId,depotId).inIfPresent(MaterialBatch::getMaterialId,ids).gt(MaterialBatch::getInventory,BigDecimal.ZERO));
+        //List<Long> ids = materialExtendService.selectIdsByBarCode(barCodeList);
+        List<MaterialBatch> list = materialBatchMapper.selectList(new LambdaQueryWrapperX<MaterialBatch>().eq(MaterialBatch::getDepotId,depotId).inIfPresent(MaterialBatch::getBarCode,barCodeList).gt(MaterialBatch::getInventory,BigDecimal.ZERO));
         return list;
         return list;
     }
     }
 
 

+ 14 - 4
src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java

@@ -213,6 +213,8 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                         jsonObj.setId(null);
                         jsonObj.setId(null);
                         //设置初始库
                         //设置初始库
                         materialInitialStockMapper.insertSelective(jsonObj);
                         materialInitialStockMapper.insertSelective(jsonObj);
+                        //更新当前库存
+                        depotItemService.updateCurrentStockFun(mId,jsonObj.getDepotId());
                     }
                     }
                 }
                 }
             }
             }
@@ -249,7 +251,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 List<MaterialInitialStock> stockArr = obj.getStock();
                 List<MaterialInitialStock> stockArr = obj.getStock();
                 for (int i = 0; i < stockArr.size(); i++) {
                 for (int i = 0; i < stockArr.size(); i++) {
                     MaterialInitialStock jsonObj = stockArr.get(i);
                     MaterialInitialStock jsonObj = stockArr.get(i);
-                    if(jsonObj.getId() != null && jsonObj.getLowSafeStock() != null || jsonObj.getPosition() != null) {
+                    if(jsonObj.getId() != null && jsonObj.getLowSafeStock() != null || jsonObj.getPosition() != null || jsonObj.getNumber() != null) {
                         BigDecimal lowSafeStock = jsonObj.getLowSafeStock();
                         BigDecimal lowSafeStock = jsonObj.getLowSafeStock();
                         BigDecimal highSafeStock = null;
                         BigDecimal highSafeStock = null;
                         if(jsonObj.getHighSafeStock() != null) {
                         if(jsonObj.getHighSafeStock() != null) {
@@ -263,12 +265,12 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                         MaterialInitialStockExample example = new MaterialInitialStockExample();
                         MaterialInitialStockExample example = new MaterialInitialStockExample();
                         example.createCriteria().andMaterialIdEqualTo(material.getId()).andDepotIdEqualTo(depotId);
                         example.createCriteria().andMaterialIdEqualTo(material.getId()).andDepotIdEqualTo(depotId);
                         materialInitialStockMapper.deleteByExample(example);
                         materialInitialStockMapper.deleteByExample(example);
-                        if (lowSafeStock!=null || highSafeStock!=null || jsonObj.getPosition() != null) {
+                        if (lowSafeStock!=null || highSafeStock!=null || jsonObj.getPosition() != null || jsonObj.getNumber() != null) {
                             //insertInitialStockByMaterialAndDepot(depotId, material.getId(), parseBigDecimalEx("0"), lowSafeStock, highSafeStock);
                             //insertInitialStockByMaterialAndDepot(depotId, material.getId(), parseBigDecimalEx("0"), lowSafeStock, highSafeStock);
                             materialInitialStockMapper.insertSelective(jsonObj);
                             materialInitialStockMapper.insertSelective(jsonObj);
                         }
                         }
                         //更新当前库存
                         //更新当前库存
-                        //depotItemService.updateCurrentStockFun(material.getId(), depotId);
+                        depotItemService.updateCurrentStockFun(material.getId(), depotId);
                     }
                     }
                 }
                 }
             }
             }
@@ -1024,6 +1026,12 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                     if(depotId!=null && depotId!=0L){
                     if(depotId!=null && depotId!=0L){
                         String stockStr = ExcelUtils.getContent(src, i, col);
                         String stockStr = ExcelUtils.getContent(src, i, col);
                         if(StringUtil.isNotEmpty(stockStr)) {
                         if(StringUtil.isNotEmpty(stockStr)) {
+                            String [] depots = stockStr.split(",");
+                            //校验库存是否是数字(含小数)
+                            if(!StringUtil.isPositiveBigDecimal(depots[0])) {
+                                throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_DECIMAL_CODE,
+                                        String.format(ExceptionConstants.MATERIAL_STOCK_NOT_DECIMAL_MSG, i+1));
+                            }
                             stockMap.put(depotId, stockStr);
                             stockMap.put(depotId, stockStr);
                         }
                         }
                     }
                     }
@@ -1944,10 +1952,12 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                     String position = stockMap.get(depot.getId());
                     String position = stockMap.get(depot.getId());
                     //新增或更新初始库存
                     //新增或更新初始库存
                     if(StringUtil.isNotEmpty(position)) {
                     if(StringUtil.isNotEmpty(position)) {
+                        String [] depots = position.split(",");
                         MaterialInitialStock materialInitialStock = new MaterialInitialStock();
                         MaterialInitialStock materialInitialStock = new MaterialInitialStock();
+                        materialInitialStock.setNumber(new BigDecimal(depots[0]));
                         materialInitialStock.setDepotId(depotId);
                         materialInitialStock.setDepotId(depotId);
                         materialInitialStock.setMaterialId(material.getId());
                         materialInitialStock.setMaterialId(material.getId());
-                        materialInitialStock.setPosition(position);
+                        materialInitialStock.setPosition(depots.length > 1 ? depots[1] : "");
                         materialInitialStockMapper.insertSelective(materialInitialStock);
                         materialInitialStockMapper.insertSelective(materialInitialStock);
                     }
                     }
                 }
                 }