Prechádzať zdrojové kódy

Merge branch 'master' of http://121.40.253.172:3000/pengyue/jsh_erp into master_liaozeyong

# Conflicts:
#	src/main/java/com/jsh/erp/service/DepotHeadService.java
#	src/main/java/com/jsh/erp/service/MaterialService.java
#	src/main/java/com/jsh/erp/service/impl/DepotHeadServiceImpl.java
#	src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java
#	src/main/resources/mapper_xml/MaterialMapperEx.xml
廖泽勇 1 mesiac pred
rodič
commit
16be4ef8db

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

@@ -446,6 +446,9 @@ public class ExceptionConstants {
     public static final int DEPOT_ITEM_EXIST_NEW_STATUS_FAILED_CODE = 8500030;
     public static final String DEPOT_ITEM_EXIST_NEW_STATUS_FAILED_MSG = "抱歉,单据:%s最新状态不能进行批量操作";
 
+    public static final int DEPOT_HEAD_NOT_EXIST_CODE = 8500031;
+    public static final String DEPOT_HEAD_NOT_EXIST_MSG = "抱歉,单据不存在";
+
     /**
      *  单据明细信息
      * type = 90

+ 35 - 0
src/main/java/com/jsh/erp/controller/OpenController.java

@@ -1,9 +1,22 @@
 package com.jsh.erp.controller;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jsh.erp.datasource.entities.MaterialVo4Unit;
+import com.jsh.erp.service.MaterialService;
+import com.jsh.erp.service.SyncTescoSystemService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @Description 外部接口
  * @Author MS.BLUE
@@ -14,6 +27,28 @@ import org.springframework.web.bind.annotation.RestController;
 @Api(tags = {"外部接口"})
 public class OpenController {
 
+    private Logger logger = LoggerFactory.getLogger(OpenController.class);
+
+    @Resource
+    private SyncTescoSystemService syncTescoSystemService;
+
+    /**
+     * 获取商品系统sku,返回结果为json格式
+     * @param param 商品条码 ,[{"barCode":"1"},{"barCode":"2"}]
+     * @return 返回结果,JSON格式,{"code":0,"data":[{"barCode":"1","systemSku":"20230412100000000001"}]}
+     */
+    @ApiOperation(value = "获取商品系统sku,返回信息集采系统")
+    @PostMapping(value = "/sync-system-sku")
+    public String syncSystemSku(String param) {
+        return syncTescoSystemService.syncSystemSku(param);
+    }
+
+
+    @ApiOperation(value = "同步集采订单-》销售订单")
+    @PostMapping(value = "/sync-order")
+    public String syncOrder(String param){
+        return null;
+    }
 
 
 

+ 1 - 0
src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java

@@ -160,4 +160,5 @@ public interface MaterialMapperEx {
 
     List<MaterialVo4Unit> getMaterialByBatchNumber(@Param("batchNumberArray") String [] batchNumberArray);
 
+    List<MaterialVo4Unit> getMaterialBySystemSku(@Param("systemSkuArray") String [] systemSkuArray);
 }

+ 15 - 0
src/main/java/com/jsh/erp/datasource/vo/DepotHeadXsddRequestVO.java

@@ -0,0 +1,15 @@
+package com.jsh.erp.datasource.vo;
+
+import com.jsh.erp.datasource.entities.DepotHead;
+import lombok.Data;
+
+/**
+ * @Description 销售订单主表
+ * @Author MS.BLUE
+ * @Date 2025-04-12
+ */
+@Data
+public class DepotHeadXsddRequestVO extends DepotHead {
+
+
+}

+ 15 - 0
src/main/java/com/jsh/erp/datasource/vo/DepotItemXsddRequestVO.java

@@ -0,0 +1,15 @@
+package com.jsh.erp.datasource.vo;
+
+import com.jsh.erp.datasource.entities.DepotItem;
+import lombok.Data;
+
+/**
+ * @Description 销售订单子表
+ * @Author MS.BLUE
+ * @Date 2025-04-12
+ */
+@Data
+public class DepotItemXsddRequestVO extends DepotItem {
+
+
+}

+ 5 - 0
src/main/java/com/jsh/erp/service/DepotHeadService.java

@@ -9,6 +9,8 @@ import com.jsh.erp.datasource.vo.DepotHeadVo4InDetail;
 import com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount;
 import com.jsh.erp.datasource.vo.DepotHeadVo4List;
 import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount;
+import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
+import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
@@ -184,4 +186,7 @@ public interface DepotHeadService extends IService<DepotHead> {
      * @return
      */
     DepotHead getDepotLastByMaterialId(long mid);
+
+    String syncOrderToXsdd(DepotHeadXsddRequestVO depotHead, List<DepotItemXsddRequestVO> depotItemList) throws Exception;
+
 }

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

@@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
+import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
 import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
 import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList;
+import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
 import com.jsh.erp.datasource.vo.InOutPriceVo;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -93,6 +95,9 @@ public interface DepotItemService extends IService<DepotItem> {
     void saveDetials(String rows, Long headerId, String actionType, HttpServletRequest request) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    void saveOrderItem(DepotHeadXsddRequestVO order, List<DepotItemXsddRequestVO> itemList) throws Exception;
+
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     String getBillStatusByParam(DepotHead depotHead, String linkStr, String linkType);
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)

+ 5 - 0
src/main/java/com/jsh/erp/service/MaterialService.java

@@ -139,6 +139,8 @@ public interface MaterialService extends IService<Material> {
 
     List<MaterialVo4Unit> getMaterialByBarCode(String barCode);
 
+    List<MaterialVo4Unit> getMaterialByBarCode(List<String> barCodeList);
+
     List<MaterialVo4Unit> getMaterialByBarCodeAndWithOutMId(String barCode, Long mId);
 
     List<MaterialInitialStockWithMaterial> getInitialStockWithMaterial(List<Long> depotList);
@@ -177,4 +179,7 @@ public interface MaterialService extends IService<Material> {
 
     //导入表格
     BaseResponseInfo importExcelTwo(MultipartFile file, HttpServletRequest request) throws Exception;
+
+    List<MaterialVo4Unit> getMaterialBySystemSku(List<String> systemSkuList);
+
 }

+ 269 - 0
src/main/java/com/jsh/erp/service/SyncTescoSystemService.java

@@ -0,0 +1,269 @@
+package com.jsh.erp.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jsh.erp.datasource.entities.DepotHeadVo4Body;
+import com.jsh.erp.datasource.entities.MaterialVo4Unit;
+import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
+import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * @Description TODO
+ * @Author MS.BLUE
+ * @Date 2025-04-12
+ */
+@Service
+public class SyncTescoSystemService {
+
+    private Logger logger = LoggerFactory.getLogger(SyncTescoSystemService.class);
+
+    @Resource
+    private MaterialService materialService;
+
+    @Resource
+    private DepotHeadService depotHeadService;
+
+    @Resource
+    private SequenceService sequenceService;
+
+    public String syncSystemSku(String param) {
+        logger.info("获取商品系统sku,返回信息集采系统 param:{}", param);
+        JSONObject result = new JSONObject();
+        JSONArray dataArray = new JSONArray();
+
+        try {
+            // 参数校验
+            if (param == null || param.isEmpty()) {
+                result.put("code", 1);
+                result.put("msg", "参数不能为空");
+                return result.toJSONString();
+            }
+
+            // 解析传入的JSON参数
+            JSONArray barCodeArray = JSONArray.parseArray(param);
+            if (barCodeArray == null || barCodeArray.isEmpty()) {
+                result.put("code", 1);
+                result.put("msg", "参数格式错误");
+                return result.toJSONString();
+            }
+
+            // 提取 barCode 到字符串数组
+            List<String> barCodeList = new ArrayList<>();
+            for (int i = 0; i < barCodeArray.size(); i++) {
+                JSONObject barCodeObj = barCodeArray.getJSONObject(i);
+                String barCode = barCodeObj.getString("barCode");
+                barCodeList.add(barCode);
+            }
+
+            // 查询商品信息
+            List<MaterialVo4Unit> materialList = materialService.getMaterialByBarCode(barCodeList);
+            if (materialList != null && !materialList.isEmpty()) {
+                result.put("code", 0);
+                for (MaterialVo4Unit material : materialList) {
+                    JSONObject item = new JSONObject();
+                    item.put("barCode", material.getmBarCode());
+                    item.put("systemSku", material.getSystemSku());
+                    dataArray.add(item);
+                }
+            } else {
+                result.put("code", 1);
+                result.put("msg", "未找到对应商品信息");
+            }
+        } catch (Exception e) {
+            result.put("code", 1);
+            result.put("msg", "系统异常,请稍后重试");
+        }
+
+        // 将数据数组放入返回结果
+        result.put("data", dataArray);
+        logger.info("  result:{}", param);
+        return result.toJSONString();
+    }
+
+    /**
+     *
+     集采下单成功->封装同步erp销售订单请求体
+
+     {
+     orderSn:"订单编号",
+     customer:{//客户信息
+     name:"客户名称",
+     contact:"客户联系方式",
+     address:"客户地址"
+     },
+     item:[{//订单商品信息
+     erp_sku:"erp_sku编号",
+     unitPrice:"商品单价",
+     quantity:"商品下单数量",
+     price:"商品实付价格"
+     }]
+     }
+
+     * @param param
+     * @return
+     */
+    public String syncOrder(String param) {
+        logger.info("同步集采订单-》销售订单 param:{}", param);
+        JSONObject result = new JSONObject();
+        try {
+            // 解析传入的JSON参数
+            JSONObject paramJson = JSONObject.parseObject(param);
+            if (paramJson == null || paramJson.isEmpty()) {
+                result.put("code", 1);
+                result.put("msg", "参数不能为空");
+                return result.toJSONString();
+            }
+
+            // 校验订单编号
+            String orderSn = paramJson.getString("orderSn");
+            if (orderSn == null || orderSn.isEmpty()) {
+                result.put("code", 1);
+                result.put("msg", "订单编号不能为空");
+                return result.toJSONString();
+            }
+
+            // 校验客户信息
+            JSONObject customer = paramJson.getJSONObject("customer");
+            if (customer == null || customer.isEmpty()) {
+                result.put("code", 1);
+                result.put("msg", "客户信息不能为空");
+                return result.toJSONString();
+            }
+
+            // 校验订单商品信息
+            JSONArray itemArray = paramJson.getJSONArray("item");
+            if (itemArray == null || itemArray.isEmpty()) {
+                result.put("code", 1);
+                result.put("msg", "订单商品信息不能为空");
+                return result.toJSONString();
+            }
+
+            buildOrderAndItem(paramJson, itemArray);
+
+            // 返回成功结果
+            result.put("code", 0);
+            result.put("msg", "订单同步成功");
+        } catch (Exception e) {
+            logger.error("同步订单发生异常", e);
+            result.put("code", 1);
+            result.put("msg", "系统异常,请稍后重试");
+        }
+        return result.toJSONString();
+    }
+
+    private void buildOrderAndItem(JSONObject orderJson, JSONArray itemJsonArray) throws Exception {
+        DepotHeadXsddRequestVO order = new DepotHeadXsddRequestVO();
+        order.setType("其他");
+        order.setSubType("销售订单");
+        String orderSn = orderJson.getString("orderSn");
+
+        String number = sequenceService.buildOnlyNumber();
+        String defaultNumber = "XSDD" + number;
+        order.setDefaultNumber(defaultNumber);
+        order.setNumber(defaultNumber);
+        order.setCreateTime(new Date());
+        order.setOperTime(new Date());
+        order.setOrganId(1L);// 供应商
+        order.setCreator(1L);// 创建人
+        order.setAccountId(1L);// 账户
+        order.setChangeAmount(BigDecimal.ZERO);
+        order.setBackAmount(BigDecimal.ZERO);
+        order.setTotalPrice(orderJson.getBigDecimal("totalPrice"));
+        order.setPayType("现付");
+        order.setDiscount(BigDecimal.ZERO);
+        order.setDiscountMoney(BigDecimal.ZERO);
+        order.setDiscountLastMoney(orderJson.getBigDecimal("totalPrice"));
+        order.setStatus("0");
+        order.setPurchaseStatus("0");
+        order.setSource("2");// 来源集采商城
+        order.setTenantId(null);
+        order.setDeleteFlag("0");
+
+        List<DepotItemXsddRequestVO> itemList = new ArrayList<>();
+
+        List<String> systemSkuList = itemJsonArray.stream().map(JSONObject.class::cast).map(json -> json.getString("erp_sku")).collect(Collectors.toList());
+
+        Map<String, JSONObject> skuToJsonMap = itemJsonArray.stream().map(JSONObject.class::cast).collect(Collectors.toMap(json -> json.getString("erp_sku"), json -> json));
+
+        List<MaterialVo4Unit> materialList = materialService.getMaterialBySystemSku(systemSkuList);
+
+        Map<String, List<MaterialVo4Unit>> skuToMaterialMap = materialList.stream().collect(Collectors.groupingBy(MaterialVo4Unit::getSystemSku));
+
+        for (Map.Entry<String, JSONObject> entry : skuToJsonMap.entrySet()) {
+            String erpSku = entry.getKey(); // 获取 erp_sku
+            JSONObject itemJson = entry.getValue(); // 获取对应的 JSONObject
+
+            Integer quantity = itemJson.getInteger("quantity");
+            BigDecimal unitPrice = itemJson.getBigDecimal("unitPrice");
+            BigDecimal price = itemJson.getBigDecimal("price");
+
+            if (quantity == null || unitPrice == null || price == null) {
+                logger.warn("商品信息不完整,erp_sku: {}", erpSku);
+                continue;
+            }
+
+            List<MaterialVo4Unit> materials = skuToMaterialMap.get(erpSku);
+
+            if (materials != null && !materials.isEmpty()) {
+                BigDecimal remainingQuantity = itemJson.getBigDecimal("quantity"); // 剩余数量
+                for (MaterialVo4Unit material : materials) {
+                    BigDecimal inventory = material.getInventory(); // 当前商品库存
+                    if (inventory.compareTo(BigDecimal.ZERO) <= 0) {
+                        continue; // 如果库存为0,跳过
+                    }
+
+                    DepotItemXsddRequestVO item = new DepotItemXsddRequestVO();
+                    item.setHeaderId(order.getId());
+                    item.setMaterialId(material.getId());
+                    item.setMaterialExtendId(material.getMeId());
+                    item.setMaterialUnit(material.getUnit());
+                    item.setSku(material.getSku());
+                    item.setDepotId(material.getDepotId());
+                    item.setTaxRate(BigDecimal.ONE);
+                    item.setTaxMoney(BigDecimal.ZERO);
+                    item.setBatchNumber("");
+                    item.setUnitPrice(unitPrice); // 设置单价
+                    if (inventory.compareTo(remainingQuantity) >= 0) {
+                        // 如果当前商品库存大于等于剩余数量,直接使用剩余数量
+                        item.setOperNumber(remainingQuantity);
+                        // 计算实付价格:单价 × 剩余数量
+                        BigDecimal taxLastMoney = itemJson.getBigDecimal("unitPrice").multiply(remainingQuantity);
+                        item.setTaxLastMoney(taxLastMoney);
+                        item.setAllPrice(taxLastMoney);
+                        itemList.add(item);
+                        break; // 结束循环
+                    } else {
+                        // 如果当前商品库存小于剩余数量,使用当前商品库存
+                        item.setOperNumber(inventory);
+                        // 计算实付价格:单价 × 剩余数量
+                        BigDecimal taxLastMoney = itemJson.getBigDecimal("unitPrice").multiply(remainingQuantity);
+                        item.setTaxLastMoney(taxLastMoney);
+                        item.setAllPrice(taxLastMoney);
+                        itemList.add(item);
+                        remainingQuantity = remainingQuantity.subtract(inventory); // 减少剩余数量
+                    }
+                }
+            } else {
+                // 如果未找到对应的 MaterialVo4Unit,可以记录日志或处理异常
+                logger.warn("未找到 erp_sku: {} 对应的商品信息", erpSku);
+            }
+        }
+        depotHeadService.syncOrderToXsdd(order, itemList);
+    }
+
+
+
+
+}

+ 23 - 0
src/main/java/com/jsh/erp/service/impl/DepotHeadServiceImpl.java

@@ -1811,6 +1811,7 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
                 ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
     }
 
+<<<<<<< HEAD
     /**
      * 根据商品id获取最后一条销售订单
      * @param mid 商品id
@@ -1821,4 +1822,26 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
         return depotHeadMapper.getDepotLastByMaterialId(mid);
     }
 
+    @Override
+    public String syncOrderToXsdd(DepotHeadXsddRequestVO depotHead, List<DepotItemXsddRequestVO> depotItemList) throws Exception {
+        // 校验单号是否重复
+        if (checkIsBillNumberExist(0L, depotHead.getNumber()) > 0) {
+            throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE, String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
+        }
+        // 添加主表
+        depotHeadMapper.insertSelective(depotHead);
+
+        // 根据单据编号查询单据id
+        DepotHeadExample dhExample = new DepotHeadExample();
+        dhExample.createCriteria().andNumberEqualTo(depotHead.getNumber()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<DepotHead> list = depotHeadMapper.selectByExample(dhExample);
+        if (list != null) {
+            Long headId = list.get(0).getId();
+            /** 销售订单 单据子表信息 */
+            depotItemService.saveOrderItem(depotHead, depotItemList);
+        }
+        logService.insertLog("销售订单", new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(depotHead.getNumber()).toString(), ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest());
+        return "";
+    }
+
 }

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

@@ -8,9 +8,11 @@ import com.jsh.erp.constants.ExceptionConstants;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.*;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
+import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
 import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
 import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
 import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList;
+import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
 import com.jsh.erp.datasource.vo.InOutPriceVo;
 import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
@@ -19,6 +21,7 @@ import com.jsh.erp.utils.StringUtil;
 import com.jsh.erp.utils.Tools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -761,6 +764,52 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
                     String.format(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_MSG));
         }
     }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public void saveOrderItem(DepotHeadXsddRequestVO order, List<DepotItemXsddRequestVO> itemList) throws Exception {
+        // 查询单据主表信息
+        DepotHead depotHead = depotHeadMapper.selectByPrimaryKey(order.getId());
+        if (depotHead == null) {
+            throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_NOT_EXIST_CODE, String.format(ExceptionConstants.DEPOT_HEAD_NOT_EXIST_MSG));
+        }
+        if (null != itemList && itemList.size() > 0) {
+            for (DepotItemXsddRequestVO item : itemList) {
+                DepotItem depotItem = new DepotItem();
+                BeanUtils.copyProperties(item, depotItem);
+
+                // 以下进行单位换算
+                Unit unitInfo = materialService.findUnit(depotItem.getMaterialId()); // 查询多单位信息
+                if (depotItem.getOperNumber() != null) {
+                    // 获取子表单商品单位
+                    String unit = depotItem.getMaterialUnit() == null ? "" : depotItem.getMaterialUnit();
+                    BigDecimal oNumber = depotItem.getOperNumber();
+                    if (StringUtil.isNotEmpty(unitInfo.getName())) {
+                        String basicUnit = unitInfo.getBasicUnit(); // 基本单位
+                        if (unit.equals(basicUnit)) { // 如果等于基本单位
+                            depotItem.setBasicNumber(oNumber); // 数量一致
+                        } else if (unit.equals(unitInfo.getOtherUnit())) { // 如果等于副单位
+                            depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatio())); // 数量乘以比例
+                        } else if (unit.equals(unitInfo.getOtherUnitTwo())) { // 如果等于副单位2
+                            depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioTwo())); // 数量乘以比例
+                        } else if (unit.equals(unitInfo.getOtherUnitThree())) { // 如果等于副单位3
+                            depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioThree())); // 数量乘以比例
+                        } else {
+                            depotItem.setBasicNumber(oNumber); // 数量一致
+                        }
+                    } else {
+                        depotItem.setBasicNumber(oNumber); // 其他情况
+                    }
+                }
+                this.insertDepotItemWithObj(depotItem);
+                // 更新当前库存
+                updateCurrentStock(depotItem);
+            }
+        } else {
+            throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_CODE, String.format(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_MSG));
+        }
+    }
+
     /**
      * 判断单据的状态
      * 通过数组对比:原单据的商品和商品数量(汇总) 与 分批操作后单据的商品和商品数量(汇总)

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

@@ -136,7 +136,7 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
             }
         }
         //删除行数据处理
-        if (null != deletedJson) {
+        if (null != deletedJson && deletedJson.size()>0) {
             StringBuffer bf=new StringBuffer();
             for (int i = 0; i < deletedJson.size(); i++) {
                 bf.append(deletedJson.getString(i));

+ 76 - 58
src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java

@@ -1,5 +1,6 @@
 package com.jsh.erp.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -1457,6 +1458,13 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
     }
 
     @Override
+    public List<MaterialVo4Unit> getMaterialByBarCode(List<String> barCodeList) {
+        // 将 List<String> 转换为 String[]
+        String[] barCodeArray = barCodeList.toArray(new String[0]);
+        return materialMapperEx.getMaterialByBarCode(barCodeArray);
+    }
+
+    @Override
     public List<MaterialVo4Unit> getMaterialByBarCodeAndWithOutMId(String barCode, Long mId) {
         String [] barCodeArray=barCode.split(",");
         return materialMapperEx.getMaterialByBarCodeAndWithOutMId(barCodeArray, mId);
@@ -1701,9 +1709,9 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
             Long beginTime = System.currentTimeMillis();
             //文件扩展名只能为xls
             String fileName = file.getOriginalFilename();
-            if(StringUtil.isNotEmpty(fileName)) {
-                String fileExt = fileName.substring(fileName.indexOf(".")+1);
-                if(!"xls".equals(fileExt)) {
+            if (StringUtil.isNotEmpty(fileName)) {
+                String fileExt = fileName.substring(fileName.indexOf(".") + 1);
+                if (!"xls".equals(fileExt)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXTENSION_ERROR_CODE,
                             ExceptionConstants.MATERIAL_EXTENSION_ERROR_MSG);
                 }
@@ -1712,13 +1720,13 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
             Sheet src = workbook.getSheet(0);
             //获取真实的行数,剔除掉空白行
             int rightRows = ExcelUtils.getRightRows(src);
-            List<Depot> depotList= depotService.getDepot();
+            List<Depot> depotList = depotService.getDepot();
             int depotCount = depotList.size();
             Map<String, Long> depotMap = parseDepotToMap(depotList);
             User user = userService.getCurrentUser();
             List<MaterialWithInitStock> mList = new ArrayList<>();
             //单次导入超出1000条
-            if(rightRows > 1002) {
+            if (rightRows > 1002) {
                 throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_IMPORT_OVER_LIMIT_CODE,
                         String.format(ExceptionConstants.MATERIAL_IMPORT_OVER_LIMIT_MSG));
             }
@@ -1732,34 +1740,34 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 String weight = ExcelUtils.getContent(src, i, 6); //基础重量(kg)
                 String unit = ExcelUtils.getContent(src, i, 7); //基本单位
                 //名称为空
-                if(StringUtil.isEmpty(name)) {
+                if (StringUtil.isEmpty(name)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NAME_EMPTY_CODE,
-                            String.format(ExceptionConstants.MATERIAL_NAME_EMPTY_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_NAME_EMPTY_MSG, i + 1));
                 }
                 //名称长度超出
-                if(name.length()>100) {
+                if (name.length() > 100) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NAME_OVER_CODE,
-                            String.format(ExceptionConstants.MATERIAL_NAME_OVER_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_NAME_OVER_MSG, i + 1));
                 }
                 //规格长度超出
-                if(StringUtil.isNotEmpty(standard) && standard.length()>100) {
+                if (StringUtil.isNotEmpty(standard) && standard.length() > 100) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STANDARD_OVER_CODE,
-                            String.format(ExceptionConstants.MATERIAL_STANDARD_OVER_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_STANDARD_OVER_MSG, i + 1));
                 }
                 //型号长度超出
-                if(StringUtil.isNotEmpty(model) && model.length()>100) {
+                if (StringUtil.isNotEmpty(model) && model.length() > 100) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_MODEL_OVER_CODE,
-                            String.format(ExceptionConstants.MATERIAL_MODEL_OVER_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_MODEL_OVER_MSG, i + 1));
                 }
                 //基本单位为空
-                if(StringUtil.isEmpty(unit)) {
+                if (StringUtil.isEmpty(unit)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_EMPTY_CODE,
-                            String.format(ExceptionConstants.MATERIAL_UNIT_EMPTY_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_UNIT_EMPTY_MSG, i + 1));
                 }
                 //类别为空
-                if(StringUtil.isEmpty(categoryName)) {
+                if (StringUtil.isEmpty(categoryName)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_Category_Name_EMPTY_CODE,
-                            String.format(ExceptionConstants.MATERIAL_Category_Name_EMPTY_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_Category_Name_EMPTY_MSG, i + 1));
                 }
                 MaterialWithInitStock m = new MaterialWithInitStock();
                 //设置商品名字、规格、型号、颜色、品牌
@@ -1776,14 +1784,14 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 Long serial_no = categoryId == null ? null : materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
                 //设置系统sku
                 m.setSystemSku(serial_no + DateUtils.dateTimeNow());
-                if(null!=categoryId){
+                if (null != categoryId) {
                     m.setCategoryId(categoryId);
                 }
-                if(StringUtil.isNotEmpty(weight)) {
+                if (StringUtil.isNotEmpty(weight)) {
                     //校验基础重量是否是数字(含小数)
-                    if(!StringUtil.isPositiveBigDecimal(weight)) {
+                    if (!StringUtil.isPositiveBigDecimal(weight)) {
                         throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_CODE,
-                                String.format(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_MSG, i+1));
+                                String.format(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_MSG, i + 1));
                     }
                     m.setWeight(new BigDecimal(weight));
                 }
@@ -1800,11 +1808,11 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 String systemSku = ExcelUtils.getContent(src, i, 18); //系统sku
                 String productionDate = ExcelUtils.getContent(src, i, 19); //生产日期
                 String expiryNum = ExcelUtils.getContent(src, i, 20); //保质期天数
-                if(StringUtil.isNotEmpty(expiryNum)) {
+                if (StringUtil.isNotEmpty(expiryNum)) {
                     //校验保质期是否是正整数
-                    if(!StringUtil.isPositiveLong(expiryNum)) {
+                    if (!StringUtil.isPositiveLong(expiryNum)) {
                         throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE,
-                                String.format(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG, i+1));
+                                String.format(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG, i + 1));
                     }
                     //m.setExpiryNum(Integer.parseInt(expiryNum));
                 }
@@ -1819,22 +1827,22 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 String remark = ExcelUtils.getContent(src, i, 29); //备注
                 // m.setPosition(StringUtil.isNotEmpty(position)?position:null);
                 //m.setMfrs(StringUtil.isNotEmpty(mfrs)?mfrs:null);
-                m.setOtherField1(StringUtil.isNotEmpty(otherField1)?otherField1:null);
-                m.setOtherField2(StringUtil.isNotEmpty(otherField2)?otherField2:null);
-                m.setOtherField3(StringUtil.isNotEmpty(otherField3)?otherField3:null);
+                m.setOtherField1(StringUtil.isNotEmpty(otherField1) ? otherField1 : null);
+                m.setOtherField2(StringUtil.isNotEmpty(otherField2) ? otherField2 : null);
+                m.setOtherField3(StringUtil.isNotEmpty(otherField3) ? otherField3 : null);
                 m.setRemark(remark);
                 //状态格式错误
-                if(!"1".equals(enabled) && !"0".equals(enabled)) {
+                if (!"1".equals(enabled) && !"0".equals(enabled)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLED_ERROR_CODE,
-                            String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i + 1));
                 }
                 //基本条码为空
-                if(StringUtil.isEmpty(barCode)) {
+                if (StringUtil.isEmpty(barCode)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EMPTY_CODE,
-                            String.format(ExceptionConstants.MATERIAL_BARCODE_EMPTY_MSG, i+1));
+                            String.format(ExceptionConstants.MATERIAL_BARCODE_EMPTY_MSG, i + 1));
                 }
                 //校验基本条码长度为4到40位
-                if(!StringUtil.checkBarCodeLength(barCode)) {
+                if (!StringUtil.checkBarCodeLength(barCode)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_CODE,
                             String.format(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_MSG, barCode));
                 }
@@ -1853,14 +1861,14 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 basicObj.put("wholesaleDecimal", wholesaleDecimal);
                 basicObj.put("lowDecimal", lowDecimal);
                 materialExObj.put("basic", basicObj);
-                if(StringUtil.isNotEmpty(manyUnit) && StringUtil.isNotEmpty(ratio)){ //多单位
+                if (StringUtil.isNotEmpty(manyUnit) && StringUtil.isNotEmpty(ratio)) { //多单位
                     //校验比例是否是数字(含小数)
-                    if(!StringUtil.isPositiveBigDecimal(ratio.trim())) {
+                    if (!StringUtil.isPositiveBigDecimal(ratio.trim())) {
                         throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_RATIO_NOT_INTEGER_CODE,
-                                String.format(ExceptionConstants.MATERIAL_RATIO_NOT_INTEGER_MSG, i+1));
+                                String.format(ExceptionConstants.MATERIAL_RATIO_NOT_INTEGER_MSG, i + 1));
                     }
                     Long unitId = unitService.getUnitIdByParam(unit, manyUnit, new BigDecimal(ratio.trim()));
-                    if(unitId != null) {
+                    if (unitId != null) {
                         m.setUnitId(unitId);
                         m.setUnit("");
                     }
@@ -1871,10 +1879,10 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                     JSONObject otherObj = new JSONObject();
                     //otherObj.put("barCode", manyBarCode);
                     otherObj.put("commodityUnit", manyUnit);
-                    otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio));
-                    otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio));
-                    otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal,ratio));
-                    otherObj.put("lowDecimal", parsePrice(lowDecimal,ratio));
+                    otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal, ratio));
+                    otherObj.put("commodityDecimal", parsePrice(commodityDecimal, ratio));
+                    otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal, ratio));
+                    otherObj.put("lowDecimal", parsePrice(lowDecimal, ratio));
                     materialExObj.put("other", otherObj);
                 } else {
                     m.setUnit(unit);
@@ -1882,17 +1890,17 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 }
                 m.setMaterialExObj(materialExObj);
                 m.setEnabled("1".equals(enabled));
-                if(StringUtil.isNotEmpty(enableSerialNumber) && "1".equals(enableSerialNumber)) {
+                if (StringUtil.isNotEmpty(enableSerialNumber) && "1".equals(enableSerialNumber)) {
                     m.setEnableSerialNumber("1");
                 } else {
                     m.setEnableSerialNumber("0");
                 }
-                if(StringUtil.isNotEmpty(enableBatchNumber) && "1".equals(enableBatchNumber)) {
+                if (StringUtil.isNotEmpty(enableBatchNumber) && "1".equals(enableBatchNumber)) {
                     m.setEnableBatchNumber("1");
                 } else {
                     m.setEnableBatchNumber("0");
                 }
-                if("1".equals(enableSerialNumber) && "1".equals(enableBatchNumber)) {
+                if ("1".equals(enableSerialNumber) && "1".equals(enableBatchNumber)) {
                     throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_CODE,
                             String.format(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_MSG, barCode));
                 }
@@ -1906,13 +1914,13 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
             //防止初始库存和当前库存出现重复
             Map<String, String> materialDepotInitialMap = new HashMap<>();
             Map<String, String> materialDepotCurrentMap = new HashMap<>();
-            for(MaterialWithInitStock m: mList) {
+            for (MaterialWithInitStock m : mList) {
                 Long mId = 0L;
                 //判断该商品是否存在,如果不存在就新增,如果存在就更新
                 String basicBarCode = getBasicBarCode(m);
                 //根据条件返回产品列表
-                List<Material> materials = getMaterialListByParam(m.getName(),m.getStandard(),m.getModel(),m.getColor(),m.getUnit(),m.getUnitId(), basicBarCode);
-                if(materials.size() == 0) { //产品列表为0,新增商品
+                List<Material> materials = getMaterialListByParam(m.getName(), m.getStandard(), m.getModel(), m.getColor(), m.getUnit(), m.getUnitId(), basicBarCode);
+                if (materials.size() == 0) { //产品列表为0,新增商品
                     materialMapperEx.insertSelectiveEx(m);
                     mId = m.getId();
                 } else { //产品列表不为0,商品存在,修改商品属性
@@ -1922,7 +1930,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                     material.setId(mId);
                     materialMapper.updateByPrimaryKeySelective(material);
                     //更新多单位
-                    if(material.getUnitId() == null) {
+                    if (material.getUnitId() == null) {
                         materialMapperEx.setUnitIdToNull(material.getId());
                     }
                     //如果之前有保质期,则更新保质期
@@ -1936,7 +1944,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 insertOrUpdateMaterialExtend(materialExObj, "other", "0", mId, user);
                 //给商品更新库存
                 Map<Long, BigDecimal> stockMap = m.getStockMap();
-                for(Depot depot: depotList){
+                for (Depot depot : depotList) {
                     Long depotId = depot.getId();
                     String materialDepotKey = mId + "_" + depotId;
                     //获取初始库存
@@ -1944,33 +1952,33 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                     //excel里面的当前库存
                     BigDecimal stock = stockMap.get(depot.getId());
                     //新增或更新初始库存
-                    if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
+                    if (stock != null && stock.compareTo(BigDecimal.ZERO) != 0) {
                         String basicStr = materialExObj.getString("basic");
                         MaterialExtend materialExtend = JSONObject.parseObject(basicStr, MaterialExtend.class);
-                        if(StringUtil.isNotEmpty(materialExtend.getSku())) {
+                        if (StringUtil.isNotEmpty(materialExtend.getSku())) {
                             throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SKU_BEGIN_STOCK_FAILED_CODE,
                                     String.format(ExceptionConstants.MATERIAL_SKU_BEGIN_STOCK_FAILED_MSG, materialExtend.getBarCode()));
                         }
                         buildChangeInitialStock(deleteInitialStockMaterialIdList, insertInitialStockMaterialList, materialDepotInitialMap, mId, depotId, materialDepotKey, stock);
                     } else {
-                        if(initStock.compareTo(BigDecimal.ZERO)!=0) {
+                        if (initStock.compareTo(BigDecimal.ZERO) != 0) {
                             buildChangeInitialStock(deleteInitialStockMaterialIdList, insertInitialStockMaterialList, materialDepotInitialMap, mId, depotId, materialDepotKey, stock);
                         }
                     }
                     //新增或更新当前库存
                     Long billCount = depotItemService.getCountByMaterialAndDepot(mId, depotId);
-                    if(billCount == 0) {
-                        if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
+                    if (billCount == 0) {
+                        if (stock != null && stock.compareTo(BigDecimal.ZERO) != 0) {
                             buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, stock);
                         } else {
-                            if(initStock.compareTo(BigDecimal.ZERO)!=0) {
+                            if (initStock.compareTo(BigDecimal.ZERO) != 0) {
                                 buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, stock);
                             }
                         }
                     } else {
                         BigDecimal currentNumber = getCurrentStockByMaterialIdAndDepotId(mId, depotId);
                         //当前库存的更新:减去初始库存,再加上导入的新初始库存
-                        if(currentNumber!=null && initStock!=null && stock!=null) {
+                        if (currentNumber != null && initStock != null && stock != null) {
                             currentNumber = currentNumber.subtract(initStock).add(stock);
                         }
                         buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, currentNumber);
@@ -1978,11 +1986,11 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 }
             }
             //批量更新库存,先删除后新增
-            if(insertInitialStockMaterialList.size()>0) {
+            if (insertInitialStockMaterialList.size() > 0) {
                 batchDeleteInitialStockByMaterialList(deleteInitialStockMaterialIdList);
                 materialInitialStockMapperEx.batchInsert(insertInitialStockMaterialList);
             }
-            if(insertCurrentStockMaterialList.size()>0) {
+            if (insertCurrentStockMaterialList.size() > 0) {
                 batchDeleteCurrentStockByMaterialList(deleteCurrentStockMaterialIdList);
                 materialCurrentStockMapperEx.batchInsert(insertCurrentStockMaterialList);
             }
@@ -1991,7 +1999,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                     new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
                     ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
             Long endTime = System.currentTimeMillis();
-            logger.info("导入耗时:{}", endTime-beginTime);
+            logger.info("导入耗时:{}", endTime - beginTime);
             info.code = 200;
             info.data = "导入成功";
         } catch (BusinessRunTimeException e) {
@@ -2005,4 +2013,14 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
         return info;
     }
 
+    @Override
+    public List<MaterialVo4Unit> getMaterialBySystemSku(List<String> systemSkuList) {
+        if (CollectionUtil.isEmpty(systemSkuList)){
+            return null;
+        }
+        String[] systemSkuArray = systemSkuList.toArray(new String[0]);
+        List<MaterialVo4Unit> list =  materialMapperEx.getMaterialBySystemSku(systemSkuArray);
+        return list;
+    }
+
 }

+ 15 - 0
src/main/resources/mapper_xml/MaterialMapperEx.xml

@@ -809,5 +809,20 @@
     </select>
 
 
+    <select id="getMaterialBySystemSku" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultType="com.jsh.erp.datasource.entities.MaterialVo4Unit">
+        select m.*,u.name unit_name, me.id meId,me.bar_code m_bar_code, me.commodity_unit, me.purchase_decimal, me.commodity_decimal,me.inventory
+        me.wholesale_decimal, me.low_decimal, me.sku, me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.depot_id, me.position
+        from jsh_material m
+        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
+        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
+        where
+        me.system_sku in (
+        <foreach collection="systemSkuArray" item="systemSku" separator=",">
+            #{systemSku}
+        </foreach>
+        )
+        and ifnull(m.delete_flag,'0') !='1'
+        order by m.id desc, me.default_flag desc,me.production_date asc, me.batch_number asc
+    </select>
 
 </mapper>