Просмотр исходного кода

Merge remote-tracking branch 'origin/featurt-liwei' into xuankuang

# Conflicts:
#	warewms-ams/pom.xml
zhangxin 1 год назад
Родитель
Сommit
b41bb315eb

+ 34 - 0
ruoyi-admin/src/main/java/com/ruoyi/xuankuang/controller/ProcessLocationController.java

@@ -0,0 +1,34 @@
+package com.ruoyi.xuankuang.controller;
+
+import com.ruoyi.ams.xuankuang.service.ProcessLocationService;
+import com.ruoyi.common.core.domain.AjaxResult;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+
+
+@RestController
+@RequestMapping("/beneficiation")
+@Slf4j
+public class ProcessLocationController {
+
+    @Autowired
+    private ProcessLocationService processLocationService;
+
+    @GetMapping("/adjustAll")
+    public AjaxResult handleLoacationInventory(@RequestHeader("path") String path) throws Exception {
+        processLocationService.handleLoacationInventory(path);
+        return AjaxResult.success();
+    }
+
+    @GetMapping("/oneInventory")
+    private AjaxResult oneInventory(@RequestHeader("locationNo") String locationNo,
+                                  @RequestHeader("bindSku") String bindSku,
+                                  @RequestHeader("palletNo") String palletNo,
+                                  @RequestHeader("quantity") String quantity) {
+
+        processLocationService.oneInventory(locationNo,bindSku,palletNo,quantity);
+        return AjaxResult.success();
+    }
+}

+ 2 - 2
ruoyi-admin/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://47.100.220.92:3306/warewms_xuankuang_cy?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+                url: jdbc:mysql://47.100.220.92:3306/warewms_xuankuang_liwei?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
                 username: warewms
                 password: warewms123
                 driverClassName: com.mysql.cj.jdbc.Driver
@@ -58,7 +58,7 @@ spring:
                         multi-statement-allow: true
     redis:
         # 地址
-        host: 154.12.20.200
+        host: 192.168.157.130
         # 端口,默认为6379
         port: 6379
         # 数据库索引

Разница между файлами не показана из-за своего большого размера
+ 12 - 18
ruoyi-admin/src/test/java/com/ruoyi/admin/test/base/ProcessLocationTest.java


+ 1 - 0
ruoyi-ui/package.json

@@ -66,6 +66,7 @@
     "@vue/cli-service": "4.4.6",
     "babel-eslint": "10.1.0",
     "babel-plugin-dynamic-import-node": "2.3.3",
+    "babel-plugin-import": "^1.13.8",
     "chalk": "4.1.0",
     "compression-webpack-plugin": "5.0.2",
     "connect": "3.6.6",

+ 0 - 2
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/impl/AmsHexdefineDetailServiceImpl.java

@@ -1,7 +1,5 @@
 package com.ruoyi.ams.agv.ndc.service.impl;
 
-import java.lang.reflect.Field;
-import java.util.ArrayList;
 import java.util.List;
 
 import com.ruoyi.ams.agv.ndc.common.ValType;

+ 35 - 0
warewms-ams/src/main/java/com/ruoyi/ams/order/service/impl/WmsDocOrderHeaderServiceImpl.java

@@ -26,6 +26,7 @@ import com.ruoyi.ams.order.domain.WmsDocOrderDetails;
 import com.ruoyi.ams.order.form.*;
 import com.ruoyi.ams.order.mapper.WmsDocOrderDetailsMapper;
 import com.ruoyi.ams.order.service.IActAllocationDetailsService;
+import com.ruoyi.ams.order.service.IWmsDocOrderDetailsService;
 import com.ruoyi.ams.order.vo.CheckOutVO;
 import com.ruoyi.ams.order.vo.PickingListVO;
 import com.ruoyi.ams.order.vo.StockOrderVO;
@@ -70,6 +71,8 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
     @Autowired
     private IWmsDocOrderHeaderService wmsDocOrderHeaderService;
     @Autowired
+    private IWmsDocOrderDetailsService wmsDocOrderDetailsService;
+    @Autowired
     private IWmsBoxInfoService wmsBoxInfoService;
     @Autowired
     private WmsBoxInfoMapper wmsBoxInfoMapper;
@@ -148,6 +151,36 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
     @Transactional
     @Override
     public AjaxResult insertWmsDocOrderHeader(WmsDocOrderHeader wmsDocOrderHeader) {
+        List<WmsDocOrderDetails> wmsDocOrderDetails = wmsDocOrderDetailsService.selectWmsDocOrderDetailsByOrderNo(wmsDocOrderHeader.getOrderNo());
+        String soReference3 = wmsDocOrderHeader.getSoReference3();
+        String sku = "";
+        switch(soReference3) {
+            case "1":
+                sku = "Na2CO3";
+                break;
+            case "2":
+                sku = "C5H10OS2";
+                break;
+            case "3":
+                sku = "(NaPO3)6";
+                break;
+            case "4":
+                sku = "(NH4)2SO4";
+                break;
+            case "5":
+                sku = "CH3CH2OCS2Na";
+                break;
+            default:
+                sku = "未知物质";
+                break;
+        }
+        String finalSku = sku;
+        wmsDocOrderDetails.forEach(item ->{
+            if(!finalSku.equals(item.getSku())){
+                throw new RuntimeException("物料不符!");
+            }
+        });
+
         String orderNo = idSequenceUtils.generateId("ORDERNO");
         wmsDocOrderHeader.setOrderNo(orderNo);
         wmsDocOrderHeader.setEdiSendFlag("N");
@@ -495,11 +528,13 @@ public class WmsDocOrderHeaderServiceImpl implements IWmsDocOrderHeaderService {
 
     @Override
     public int insertWmsDocOrderDetails(WmsDocOrderDetails wmsDocOrderDetails) {
+
         if (wmsDocOrderDetails.getOrderLineNo() == null) {
             long lineNo = wmsDocOrderHeaderMapper.selectLineNo(wmsDocOrderDetails.getOrderNo());
             wmsDocOrderDetails.setOrderLineNo(BigDecimal.valueOf(lineNo + 1));
             wmsDocOrderDetails.setQtyOrderedEach(wmsDocOrderDetails.getQtyOrdered());
         }
+
         return wmsDocOrderDetailsMapper.insertWmsDocOrderDetails(wmsDocOrderDetails);
     }
 

+ 24 - 0
warewms-ams/src/main/java/com/ruoyi/ams/xuankuang/service/ExcelLocLotModel.java

@@ -0,0 +1,24 @@
+package com.ruoyi.ams.xuankuang.service;
+
+
+import com.ruoyi.common.annotation.Excel;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ExcelLocLotModel implements Serializable {
+
+    @Excel(name = "库位号(例:A-01-02)")
+    private String locationNo;
+
+    @Excel(name = "绑定的物料号(例:C4H9O2PSSNH4)")
+    private String bindSku;
+
+    @Excel(name = "数量(例:50.00)")
+    private String quantity;
+
+    @Excel(name = "托盘号")
+    private String palletNo;
+
+}

+ 6 - 0
warewms-ams/src/main/java/com/ruoyi/ams/xuankuang/service/ProcessLocationService.java

@@ -0,0 +1,6 @@
+package com.ruoyi.ams.xuankuang.service;
+
+public interface ProcessLocationService {
+    void handleLoacationInventory(String page) throws Exception;
+    void oneInventory(String locationNo, String bindSku, String palletNo, String quantity);
+}

+ 207 - 0
warewms-ams/src/main/java/com/ruoyi/ams/xuankuang/service/impl/ProcessLocationServiceImpl.java

@@ -0,0 +1,207 @@
+package com.ruoyi.ams.xuankuang.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.comparator.CompareUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.ams.inv.domain.InvLotLocId;
+import com.ruoyi.ams.inv.service.IInvLotAttService;
+import com.ruoyi.ams.inv.service.IInvLotLocIdService;
+import com.ruoyi.ams.xuankuang.service.ExcelLocLotModel;
+import com.ruoyi.ams.xuankuang.service.ProcessLocationService;
+import com.ruoyi.base.domain.BaseLocationInfo;
+import com.ruoyi.base.domain.BaseSku;
+import com.ruoyi.base.service.IBaseLocationInfoService;
+import com.ruoyi.base.service.IBaseSkuService;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import io.netty.util.internal.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.compress.utils.Lists;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class ProcessLocationServiceImpl implements ProcessLocationService {
+
+    private static final String FREE = "00";
+    @Autowired
+    private IBaseLocationInfoService baseLocationInfoService;
+
+    @Autowired
+    private IInvLotAttService invLotAttService;
+
+    @Autowired
+    private IInvLotLocIdService invLotLocIdService;
+
+    @Autowired
+    private IBaseSkuService baseSkuService;
+
+
+    //仓库ID的默认值
+    private static final Long WAREHOUSE_ID = 1L;
+
+
+    /**
+     * 选矿项目调整库存专用脚本
+     *
+     * @author ChenYang
+     */
+    @Override
+    public void handleLoacationInventory(String path) throws Exception {
+        Assert.isTrue(StringUtils.isNotBlank(path),"路径不能为空");
+        Map<String, String> skuTypeMapping = getSkuTypeMapping();
+        Assert.isTrue(CollectionUtil.isNotEmpty(skuTypeMapping), "skuTypeMapping is empty");
+
+        //2.到Excel中查询数据
+        //TODO 从路径获取文件
+        File excelFile = FileUtil.file(path);
+        ExcelUtil<ExcelLocLotModel> locLotModelExcelUtil = new ExcelUtil<ExcelLocLotModel>(ExcelLocLotModel.class);
+        List<ExcelLocLotModel> ExcelLocLotList = locLotModelExcelUtil.importExcel(FileUtil.getInputStream(excelFile));
+
+        //2.转json
+        /*String LocLotJsonInfo = "[{\"locationNo\":\"A-01-02\",\"bindSku\":\"C4H9O2PSSNH4\",\"quantity\":50,\"palletNo\":\"TP0023\"},{\"locationNo\":\"A-01-02\",\"bindSku\":\"C4H9O2PSSNH4\",\"quantity\":50,\"palletNo\":\"TP0023\"}]";
+        List<ExcelLocLotModel> ExcelLocLotList = JSONObject.parseArray(LocLotJsonInfo, ExcelLocLotModel.class);*/
+        List<ExcelLocLotModel> errorLocLotList = Lists.newArrayList();
+        for(ExcelLocLotModel locLotModel : ExcelLocLotList){
+            try {
+                String count = locLotModel.getQuantity();
+                BigDecimal quantity = StringUtils.isNotBlank(count) ? new BigDecimal(count) : null;
+                //所需的sku,库位号locationNo以及数量即可操作
+                String locationNo = handleLocationNo(locLotModel.getLocationNo());
+                redressInventory(locationNo, locLotModel.getBindSku(), locLotModel.getPalletNo(), quantity, skuTypeMapping);
+            }catch (RuntimeException ex){
+                log.warn("ex is {}", ex);
+                errorLocLotList.add(locLotModel);
+                continue;
+            }
+        }
+        System.err.println(JSONObject.toJSONString(errorLocLotList));
+    }
+
+
+    public Map<String, String> getSkuTypeMapping(){
+        //1.获取物料号(sku)和物料类型(type)的映射
+        List<BaseSku> skuList = baseSkuService.querySkuList();
+        Map<String, String> skuTypeMapping = skuList.stream().filter(item -> StringUtils.isNotBlank(item.getSku())).collect(Collectors.toMap(BaseSku::getSku, BaseSku::getSkuType));
+        return skuTypeMapping;
+    }
+
+
+    @Override
+    public void oneInventory(String locationNo, String bindSku, String palletNo, String quantity){
+        Map<String, String> skuTypeMapping = getSkuTypeMapping();
+        Assert.isTrue(CollectionUtil.isNotEmpty(skuTypeMapping), "skuTypeMapping is empty");
+        BigDecimal quantity2 = StringUtils.isNotBlank(quantity) ? new BigDecimal(quantity) : null;
+        locationNo = handleLocationNo(locationNo);
+        redressInventory(locationNo, bindSku, palletNo, quantity2, skuTypeMapping);
+    }
+    /**
+     * 重置一个库的库位库存信息
+     * @param locationNo 库位号
+     * @param bindSku
+     * @param palletNo
+     * @param quantity
+     * @param skuTypeMapping
+     */
+    public void redressInventory(String locationNo, String bindSku, String palletNo, BigDecimal quantity, Map<String, String> skuTypeMapping) {
+        //1.通过库位号获得库位的ID
+        BaseLocationInfo baseLocationInfo = baseLocationInfoService.selectBaseLocationInfoByIdOrNo(locationNo, WAREHOUSE_ID);
+        if (ObjectUtil.isNull(baseLocationInfo)) return;
+        if (StringUtils.isBlank(bindSku) && ObjectUtil.isNotNull(quantity)) return;
+
+
+        //2.1 如果当前库位是空的,或者库位数量是空的,则删除inv_lot_loc_id中的库存数据并重置库位数据
+        if((ObjectUtil.isNull(quantity) || CompareUtil.compare(quantity, BigDecimal.ZERO)<=0)){
+            //生成新的批次记录
+            invLotAttService.insertInvLotAtt(bindSku, palletNo);
+            invLotLocIdService.deleteInvLotLocList(baseLocationInfo.getId());
+            reSetLocationInfo(baseLocationInfo, bindSku, Constants.YES, skuTypeMapping);
+            return;
+        }
+
+        if(StringUtils.isNotBlank(bindSku)
+                && ObjectUtil.isNotNull(quantity)
+                && CompareUtil.compare(quantity, BigDecimal.ZERO) > 0){
+            //查出原先的库存情况,如果当前库存SKU不符合,则生成新的批次记录
+            List<InvLotLocId> invLotLocList = invLotLocIdService.getInvLotLocList(baseLocationInfo.getId());
+            if(CollectionUtil.isNotEmpty(invLotLocList)){
+                //此时数据是错的都要重新生成库存
+                List<String> skuList = invLotLocList.stream().map(item -> item.getSku()).collect(Collectors.toList());
+                if(CollectionUtil.isEmpty(skuList) || skuList.size() > 1 || !StringUtils.equals(skuList.get(0), bindSku)){
+                    //生成新的批次记录
+                    String lotnum = invLotAttService.insertInvLotAtt(bindSku, palletNo);
+                    //删除原先的库存记录`,生成新的库存记录
+                    invLotLocIdService.deleteInvLotLocList(baseLocationInfo.getId());
+                    invLotLocIdService.insertInvLotLocId(baseLocationInfo.getId(), lotnum, bindSku, quantity);
+                    //重置库位数据
+                    reSetLocationInfo(baseLocationInfo, bindSku, Constants.NO, skuTypeMapping);
+                    return;
+                } else {
+                    //此时只有数量是错的,那么update一下数量就好
+                    InvLotLocId invLotLocId = invLotLocList.get(0);
+                    invLotLocId.setQty(quantity);
+                    //TODO  其他关于数量的字段要改嘛
+                    invLotLocId.setQtyEach(quantity);
+                    invLotLocIdService.updateInvLotLocId(invLotLocId);
+                    //重置库存数据
+                    reSetLocationInfo(baseLocationInfo, bindSku, Constants.NO, skuTypeMapping);
+                    return;
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 重置库位表字段
+     * @param baseLocationInfo
+     * @param bindSku 物料号
+     * @param isEmpty
+     * @param skuTypeMapping
+     */
+    private Boolean reSetLocationInfo(BaseLocationInfo baseLocationInfo, String bindSku, String isEmpty, Map<String, String> skuTypeMapping) {
+        //重置当前的库位信息
+        baseLocationInfo.setIsEmpty(isEmpty);
+        baseLocationInfo.setStockStatus(FREE);
+        baseLocationInfo.setUserdefine10(StringUtils.isNotBlank(bindSku) ? bindSku : null);
+        baseLocationInfo.setBindSku(StringUtils.isNotBlank(bindSku) ? skuTypeMapping.get(bindSku) : null );
+        return baseLocationInfoService.reSetLocationInfo(baseLocationInfo);
+    }
+
+
+
+    public static void main(String[] args) {
+//        System.out.println(handleLocationNo("A\t-02\t-08"));
+//        System.out.println(handleLocationNo("  A-02-08"));
+//        System.out.println(handleLocationNo("  -02-08"));
+//        System.out.println(handleLocationNo("Out-02-cache"));
+//        System.out.w's'x'z's'x'x'z(handleLocationNo("STAGE01"));
+    }
+
+
+    private static String handleLocationNo(String locationNo) {
+        if (StringUtils.isBlank(locationNo)) return StringUtil.EMPTY_STRING;
+        Pattern pattern = Pattern.compile("\\s*|\t|\r|\n");
+        Matcher matcher = pattern.matcher(locationNo);
+        String lotNo = matcher.replaceAll(StringUtil.EMPTY_STRING);
+        String start = StringUtils.split(lotNo, "-")[0];
+        if(start.length() == 1 && StringUtils.isAllUpperCase(start)){
+            lotNo = StringUtils.replace(lotNo, "-", "\t-");
+        }
+        return lotNo;
+    }
+
+}