From e046dba174365eb8934ee1e4206f09821145e876 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 21 八月 2025 13:23:22 +0800
Subject: [PATCH] no message

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/MobileServiceImpl.java |  746 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 726 insertions(+), 20 deletions(-)

diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/MobileServiceImpl.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/MobileServiceImpl.java
index 2b4fb39..5b25040 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/MobileServiceImpl.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/service/impl/MobileServiceImpl.java
@@ -1,57 +1,148 @@
 package com.zy.asrs.wms.asrs.service.impl;
 
-import com.zy.asrs.wms.asrs.entity.WaitPakin;
-import com.zy.asrs.wms.asrs.entity.enums.LocTypeHeightType;
-import com.zy.asrs.wms.asrs.entity.enums.TaskStsType;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zy.asrs.framework.common.R;
+import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wms.apis.wcs.entity.request.SlapLightControlParam;
+import com.zy.asrs.wms.apis.wcs.entity.response.CommonReponse;
+import com.zy.asrs.wms.apis.wcs.utils.HttpEssUtils;
+import com.zy.asrs.wms.asrs.entity.*;
+import com.zy.asrs.wms.asrs.entity.dto.MatnrDetlDto;
+import com.zy.asrs.wms.asrs.entity.dto.PickSheetDetlDto;
+import com.zy.asrs.wms.asrs.entity.dto.ShippingOrderDetlDto;
+import com.zy.asrs.wms.asrs.entity.enums.*;
+import com.zy.asrs.wms.asrs.entity.enums.OrderType;
 import com.zy.asrs.wms.asrs.entity.param.BatchMergeOrdersParam;
 import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam;
-import com.zy.asrs.wms.asrs.service.MobileService;
-import com.zy.asrs.wms.asrs.service.WaitPakinService;
-import com.zy.asrs.wms.asrs.service.WorkService;
+import com.zy.asrs.wms.asrs.entity.param.PakinOnShelvesParams;
+import com.zy.asrs.wms.asrs.mapper.*;
+import com.zy.asrs.wms.asrs.service.*;
 import com.zy.asrs.wms.system.entity.Host;
 import com.zy.asrs.wms.system.service.HostService;
+import io.netty.util.internal.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
+@Slf4j
 public class MobileServiceImpl implements MobileService {
 
     @Autowired
     private WaitPakinService waitPakinService;
     @Autowired
+    private WaitPakinLogService waitPakinLogService;
+    @Autowired
     private WorkService workService;
     @Autowired
     private HostService hostService;
+    @Autowired
+    private OrderService orderService;
+    @Autowired
+    private OrderDetlService orderDetlService;
+    @Autowired
+    private OrderLogService orderLogService;
+    @Autowired
+    private LocService locService;
+    @Autowired
+    private LocDetlService locDetlService;
+    @Autowired
+    private LocAreaService locAreaService;
+    @Autowired
+    private LocAreaTypeService locAreaTypeService;
+    @Autowired
+    private PickSheetService pickSheetService;
+    @Autowired
+    private PickSheetDetlService pickSheetDetlService;
+    @Autowired
+    private MatService matService;
+    @Autowired
+    private WaveService waveService;
+    @Autowired
+    private WaveLogService waveLogService;
+    @Autowired
+    private CacheSiteService cacheSiteService;
+    @Autowired
+    WaveDetlLogService waveDetlLogService;
+    @Autowired
+    private WaveDetlService waveDetlService;
+    @Autowired
+    private CacheSiteMapper cacheSiteMapper;
+
+    @Autowired
+    private SeedSitesMapper seedSitesMapper;
+    @Autowired
+    private OrderDetlMapper orderDetlMapper;
+    @Autowired
+    private WaveSeedService waveSeedMapper;
+    @Autowired
+    private WaveSeedLogService waveSeedLogService;
+    @Autowired
+    private OrderDetlLogService orderDetlLogService;
+    @Autowired
+    private PlatformDetlService platformDetlService;
+    @Autowired
+    private PlatformDetlLogService platformDetlLogService;
+
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public boolean batchMergeOrders(BatchMergeOrdersParam ordersParam) {
+        Loc locServiceOne = locService.getOne(new LambdaQueryWrapper<Loc>()
+                .eq(Loc::getLocStsId, 1)
+                .eq(Loc::getBarcode, ordersParam.getMergeNo()), false);
+        if (!Objects.isNull(locServiceOne)) {
+            throw new CoolException("鎵樼洏宸插叆搴擄紝涓嶈兘鍐嶇粍鎵橈紒锛�");
+        }
+
+        Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, ordersParam.getOrderNo()));
+        if (Objects.isNull(order)) {
+            throw new CoolException("璁㈠崟涓嶅瓨鍦紒锛�");
+        }
 
         ArrayList<WaitPakin> waitPakins = new ArrayList<>();
         ordersParam.getOrderDetls().forEach(orderdetl -> {
             WaitPakin waitPakin = new WaitPakin();
-            waitPakin.setBatch(orderdetl.getBatch()).setAnfme(orderdetl.getMergeNum()).setBarcode(ordersParam.getMergeNo()).setMatnr(orderdetl.getMatnr()).setDetlId(orderdetl.getDetlId()).setIoStatus(0).setOrderNo(orderdetl.getOrderNo()).setOrderId(orderdetl.getOrderId()).setStatus(1);
+            waitPakin.setBatch(orderdetl.getBatch())
+                    .setAnfme(orderdetl.getMergeNum())
+                    .setBarcode(ordersParam.getMergeNo())
+                    .setMatnr(orderdetl.getMatnr())
+                    .setDetlId(orderdetl.getDetlId())
+                    .setIoStatus(0)
+                    .setOrderNo(orderdetl.getOrderNo())
+                    .setOrderId(orderdetl.getOrderId())
+                    .setStatus(1);
             waitPakins.add(waitPakin);
         });
 
-        /*** 椤圭洰涓嬪彂娴佺▼ * 1. PDA缁勬嫋閫氱煡妗�* 2. 鐢熸垚浠诲姟妗�* 3. 閫氳繃瀹氭椂浠诲姟涓嬪彂鑷矱SS** */
         //缁勬嫋閫氱煡妗�
         waitPakins.forEach(pakin -> {
-            waitPakinService.comb(pakin);
+            waitPakinService.comb(pakin, ordersParam.getInType());
         });
 
-        //鐢熸垚浠诲姟妗�
-        GeneratePakInParam generatePakInParam = new GeneratePakInParam();
-        //褰撳墠娌℃湁璧峰绔欑偣锛岄粯璁�101锛� 楂樹綆浣嶉粯璁や紶浣庡簱浣�
-        generatePakInParam.setBarcode(ordersParam.getMergeNo())
-                .setOriginSite("101")
-                .setTaskType(TaskStsType.GENERATE_IN.id).setLocTypeHeight(LocTypeHeightType.LOW.id);
-        if (workService.generatePakIn(generatePakInParam)) {
-            return true;
+
+        // UTC鍏ュ簱鍗曟嵁(闈炲钩搴撳叆搴撳崟鎹�)
+        if (!ordersParam.getInType().equals(OrderType.PK_IN_ORDER.id)) {
+            /*** 椤圭洰涓嬪彂娴佺▼ * 1. PDA缁勬嫋閫氱煡妗�* 2. 鐢熸垚浠诲姟妗�* 3. 閫氳繃瀹氭椂浠诲姟涓嬪彂鑷矱SS** */
+            //鐢熸垚浠诲姟妗�
+            GeneratePakInParam generatePakInParam = new GeneratePakInParam();
+            //褰撳墠娌℃湁璧峰绔欑偣锛岄粯璁�101锛� 楂樹綆浣嶉粯璁や紶浣庡簱浣�
+            generatePakInParam.setBarcode(ordersParam.getMergeNo())
+                    .setOriginSite("101")
+                    .setTaskType(TaskStsType.GENERATE_IN.id).setLocTypeHeight(LocTypeHeightType.LOW.id);
+            if (workService.generatePakIn(generatePakInParam)) {
+                return true;
+            }
         }
         return false;
     }
@@ -60,4 +151,619 @@
     public List<Host> getHosts() {
         return hostService.list();
     }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean pakinToStock(PakinOnShelvesParams shelvesParams) {
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, shelvesParams.getLoc()));
+        if (Objects.isNull(loc)) {
+            throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
+        }
+        if (loc.getLocStsId() != LocStsType.O.val()) {
+            throw new CoolException("褰撳墠搴撲綅鐘舵�佷笉鏄┖搴撶姸鎬�." + LocStsType.O.val());
+        }
+
+        //鍒ゆ柇褰撳墠浠撳簱鏄惁涓哄钩搴撲綅
+        List<LocArea> locAreas = locAreaService.list(new LambdaQueryWrapper<LocArea>().eq(LocArea::getLocId, loc.getId()));
+        if (locAreas.isEmpty()) {
+            throw new CoolException("搴撲綅娌℃湁鍒嗛厤鎵�灞炰粨搴撳尯鍩燂紒锛�");
+        }
+        locAreas.forEach(locArea -> {
+            LocAreaType typeServiceOne = locAreaTypeService.getOne(new LambdaQueryWrapper<LocAreaType>().eq(LocAreaType::getId, locArea.getTypeId()));
+            if (typeServiceOne.getParentId() != LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id && typeServiceOne.getId() != LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id) {
+                throw new CoolException("璇烽�夋嫨骞冲簱鍖哄簱浣嶏紝鍐嶆搷浣滐紒锛�");
+            }
+        });
+
+        loc.setBarcode(shelvesParams.getBarcode());
+        loc.setUpdateTime(new Date());
+        //搴撳瓨鐘舵�佷慨鏀逛负鍦ㄥ簱鐘舵��
+        loc.setLocStsId(LocStsType.F.val());
+        if (!locService.updateById(loc)) {
+            throw new CoolException("搴撲綅鏇存柊澶辫触锛侊紒");
+        }
+        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, shelvesParams.getBarcode()));
+        if (waitPakins.isEmpty()) {
+            throw new CoolException("褰撳墠鎷栫洏娌℃湁缁勬嫋妗�!!");
+        }
+
+        waitPakins.forEach(pakin -> {
+            LocDetl locDetl = new LocDetl();
+            locDetl.setAnfme(pakin.getAnfme());
+            locDetl.setBatch(pakin.getBatch());
+            locDetl.setMatId(pakin.getMatnrId$());
+            locDetl.setCreateTime(new Date());
+            locDetl.setOrderNo(pakin.getOrderNo());
+            locDetl.setLocNo(loc.getLocNo());
+            locDetl.setLocId(loc.getId());
+            locDetl.setMatnr(pakin.getMatnr());
+            Mat one = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, pakin.getMatnr()));
+            if (Objects.isNull(one)) {
+                throw new CoolException("褰撳墠鐗╂枡涓嶅瓨鍦紒锛�");
+            }
+            locDetl.setMatId(one.getId());
+            locDetl.setMemo(pakin.getMemo());
+            locDetl.setUpdateTime(new Date());
+            if (!locDetlService.saveOrUpdate(locDetl)) {
+                throw new CoolException("搴撳瓨鏄庣粏鏇存柊澶辫触锛侊紒");
+            }
+            //淇敼鐘舵�佷负鍏ュ簱涓�
+            pakin.setIoStatus(1);
+
+            OrderDetl detl = orderDetlService.getById(pakin.getDetlId());
+            if (Objects.isNull(detl)) {
+                throw new CoolException("鏁版嵁閿欒锛氬崟鎹槑缁嗕笉瀛樺湪锛侊紒");
+            }
+            Double qty = Math.round((detl.getQty() + pakin.getAnfme()) * 1000) / 1000.0;
+            detl.setQty(qty);
+            if (!orderDetlService.updateById(detl)) {
+                throw new CoolException("鍗曟嵁鏄庣粏淇敼澶辫触锛侊紒");
+            }
+        });
+
+        //鍒犻櫎缁勬嫋妗o紝鍔犲叆鍘嗗彶缁勬嫋妗�
+        waitPakins.forEach(waitPakin -> {
+            WaitPakinLog pakinLog = new WaitPakinLog();
+            BeanUtils.copyProperties(waitPakin, pakinLog);
+            pakinLog.setIoStatus(1);
+            pakinLog.setId(null);
+            if (!waitPakinLogService.saveOrUpdate(pakinLog)) {
+                throw new CoolException("缁勬嫋鍘嗗彶妗f洿鏂板け璐�");
+            }
+        });
+
+        //閫氳繃缁勬嫋璁㈠崟ID鑾峰彇璁㈠崟锛屽苟鍒犻櫎鍘熷崟鎹紝鍔犲叆鍗曟嵁鍘嗗彶妗�
+        Set<Long> list = waitPakins.stream().map(WaitPakin::getOrderId).collect(Collectors.toSet());
+        List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getId, list));
+        orders.forEach(order -> {
+            List<OrderDetl> detls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderId, order.getId()));
+            Double sum = detls.stream().mapToDouble(OrderDetl::getQty).sum();
+//            Double summed = detls.stream().mapToDouble(OrderDetl::getWorkQty).sum();
+//            Double v = Math.round((sum ) * 1000) / 1000.0;
+            Double anfme = detls.stream().mapToDouble(OrderDetl::getAnfme).sum();
+            if (sum.compareTo(anfme) == 0.0) {
+                order.setOrderSettle(OrderSettleType.COMPLETE.val());
+                if (!orderService.updateById(order)) {
+                    throw new CoolException("鍗曟嵁鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+                }
+            }
+        });
+
+//        //璁㈠崟鍏ュ巻鍙叉。
+//        orders.forEach(order -> {
+////            if (order.getOrderType() != OrderType.PK_IN_ORDER.id) {
+////                throw new CoolException("褰撳墠璁㈠崟绫诲瀷:" + order.getOrderType() + ",涓嶅彲鍋氬钩搴撲笂鏋舵搷浣滐紒锛�");
+////            }
+//            //淇敼璁㈠崟鐘舵�佷负宸插畬鎴�
+//            order.setOrderSettle(OrderSettleType.COMPLETE.val());
+//            OrderLog orderLog = new OrderLog();
+//            BeanUtils.copyProperties(order, orderLog);
+//            orderLog.setId(null);
+//            if (!orderLogService.save(orderLog)) {
+//                throw new CoolException("鍘嗗彶鍗曟嵁鏇存柊澶辫触锛侊紒");
+//            }
+//        });
+//        //鍒犻櫎璁㈠崟鏁版嵁
+//        if (!orderService.removeBatchByIds(orders)) {
+//            throw new CoolException("璁㈠崟鍒犻櫎澶辫触锛侊紒");
+//        }
+//        List<OrderDetl> detls = orderDetlMapper.selectList(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, list));
+//        List<OrderDetlLog> detlLogs = new ArrayList<>();
+//        detls.forEach(delt ->{
+//            OrderDetlLog detlLog = new OrderDetlLog();
+//            BeanUtils.copyProperties(delt, detlLog);
+//            detlLog.setQty(delt.getWorkQty());
+//            detlLog.setWorkQty(0.0);
+//            detlLog.setId(null);
+//            detlLogs.add(detlLog);
+//        });
+//        //璁㈠崟鏄庣粏杞巻鍙叉。
+//        if (!orderDetlLogService.saveBatch(detlLogs)) {
+//            throw new CoolException("璁㈠崟鏄庣粏杞巻鍙插け璐ワ紒锛�");
+//        }
+//
+//        //鍒犻櫎璁㈠崟鏄庣粏鏁版嵁
+//        if (!orderDetlService.remove(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, list))) {
+//            throw new CoolException("璁㈠崟鏄庣粏鍒犻櫎澶辫触锛侊紒");
+//        }
+        if (!waitPakinService.removeBatchByIds(waitPakins)) {
+            throw new CoolException("缁勬嫋妗e垹闄ゅけ璐ワ紒锛�");
+        }
+        return true;
+    }
+
+    @Override
+    public PickSheetDetlDto outFlatSheet(String code) {
+        PickSheetDetlDto pickDetlDto = new PickSheetDetlDto();
+        PickSheet pickSheet = pickSheetService.getOne(new LambdaQueryWrapper<PickSheet>()
+                .eq(PickSheet::getPickNo, code)
+                .eq(PickSheet::getDeleted, 0)
+                .eq(PickSheet::getStatus, 1)
+        );
+        if (Objects.isNull(pickSheet)) {
+            throw new CoolException("鎷h揣鍗曚笉瀛樺湪锛侊紒");
+        }
+        BeanUtils.copyProperties(pickSheet, pickDetlDto);
+
+        List<PickSheetDetl> sheetDetls = pickSheetDetlService.list(new LambdaQueryWrapper<PickSheetDetl>()
+                .eq(PickSheetDetl::getPickId, pickSheet.getId())
+                .eq(PickSheetDetl::getStatus, 1)
+                .eq(PickSheetDetl::getDeleted, 0));
+        pickDetlDto.setPickSheetDetlList(sheetDetls);
+        return pickDetlDto;
+    }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean confirmFlatSheet(String code) {
+        PickSheet pickSheet = pickSheetService.getOne(new LambdaQueryWrapper<PickSheet>().eq(PickSheet::getPickNo, code));
+        if (Objects.isNull(pickSheet)) {
+            throw new CoolException("鎷h揣鍗曚笉瀛樺湪锛侊紒");
+        }
+        if (pickSheet.getStatus() == 1) {
+            //鐘舵�佷慨鏀逛负锛� 宸茶浆鍘嗗彶妗�
+            pickSheet.setStatus(3);
+            if (!pickSheetService.updateById(pickSheet)) {
+                throw new CoolException("杞巻鍙叉。澶辫触锛侊紒");
+            } else {
+                if (!pickSheetDetlService.update(new LambdaUpdateWrapper<PickSheetDetl>().eq(PickSheetDetl::getPickId, pickSheet.getId()).set(PickSheetDetl::getStatus, 3))) {
+                    throw new CoolException("鎷h揣鍗曟槑缁嗚浆鍘嗗彶妗eけ璐ワ紒锛�");
+                }
+            }
+        } else {
+            throw new CoolException("璇峰嬁鎿嶄綔鍘嗗彶妗f暟鎹紒锛�");
+        }
+        List<PickSheetDetl> sheetDetls = pickSheetDetlService.list(new LambdaQueryWrapper<PickSheetDetl>().eq(PickSheetDetl::getPickId, pickSheet.getId()));
+        Map<Long, List<PickSheetDetl>> listMap = sheetDetls.stream().collect(Collectors.groupingBy(PickSheetDetl::getLocId));
+        listMap.keySet().forEach(key -> {
+            Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getId, key));
+            listMap.get(key).forEach(pickDetl -> {
+                LocDetl detl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getId, pickDetl.getLocDetlId()));
+                if (Objects.isNull(detl)) {
+                    throw new CoolException("鏁版嵁閿欒锛侊紒");
+                }
+                //鏇存柊閿佸畾搴撳瓨
+//                BigDecimal workQty = BigDecimal.valueOf(detl.getAnfme()).subtract(pickDetl.getAnfme());
+                detl.setWorkQty(0.0);
+                //璁$畻缁撴灉灏忎簬绛変簬闆讹紝绉诲嚭搴撳瓨鏄庣粏
+                BigDecimal qty = BigDecimal.valueOf(detl.getAnfme()).subtract(pickDetl.getAnfme());
+                detl.setAnfme(qty.doubleValue());
+                if (qty.compareTo(new BigDecimal("0.00")) <= 0) {
+                    detl.setDeleted(1);
+                    if (!locDetlService.removeById(detl)) {
+                        throw new CoolException("搴撳瓨鏄庣粏鍒犻櫎澶辫触锛侊紒");
+                    }
+                } else { //缁撴灉澶т簬闆讹紝鏇存柊搴撳瓨鏄庣粏
+                    if (!locDetlService.updateById(detl)) {
+                        throw new CoolException("搴撳瓨鏄庣粏鏇存柊澶辫触锛侊紒");
+                    }
+                }
+            });
+            /**鏄庣粏鏇存柊瀹屾垚鍚庯紝鍒ゆ柇鏄惁涓虹┖锛屼负绌烘洿鏂颁富鍗曠姸鎬佷负绌哄簱锛屾嫋鐩樼爜娓呯┖锛屼笉涓虹┖涓嶅仛鏇存柊**/
+            List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, loc.getId()).eq(LocDetl::getDeleted, 0));
+            if (list.isEmpty()) {
+                boolean update = locService.update(new LambdaUpdateWrapper<Loc>()
+                        .eq(Loc::getId, loc.getId())
+                        .set(Loc::getBarcode, null)
+                        .set(Loc::getUpdateTime, new Date())
+                        .set(Loc::getLocStsId, LocStsType.O.val()));
+                if (!update) {
+                    throw new CoolException("搴撳瓨鏇存柊澶辫触锛侊紒 ");
+                }
+            }
+        });
+        
+        //鍒ゆ柇鏄惁涓烘尝娆″崟鎹�
+        if (pickSheet.getType().equals(1)) {
+            //鍒犻櫎娉㈡鍙婂搴旀槑缁嗕俊鎭�
+            if (!waveService.remove(new LambdaQueryWrapper<Wave>().eq(Wave::getId, pickSheet.getWaveId()))) {
+                throw new CoolException("娉㈡鍒楄〃鍗曟嵁鍒犻櫎澶辫触锛侊紒");
+            }
+
+            if (!waveDetlService.remove(new LambdaQueryWrapper<WaveDetl>().eq(WaveDetl::getWaveId, pickSheet.getWaveId()))) {
+                throw new CoolException("娉㈡鏄庣粏鍒楄〃鍒犻櫎澶辫触锛侊紒");
+            }
+
+            List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getWaveId, pickSheet.getWaveId()));
+            if (orders.isEmpty()) {
+                throw new CoolException("娉㈡璁㈠崟涓嶅瓨鍦紒锛�");
+            }
+            List<Long> list = orders.stream().map(Order::getId).collect(Collectors.toList());
+            boolean remove = orderDetlService.remove(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderId, list));
+            if (!remove) {
+                throw new CoolException("鍘熷璁㈠崟鏄庣粏鍒犻櫎澶辫触锛侊紒");
+            }
+            if (!orderService.remove(new LambdaQueryWrapper<Order>().in(Order::getId, list))) {
+                throw new CoolException("鍘熷璁㈠崟鍒犻櫎澶辫触锛侊紒");
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * 鑾峰彇鎾澧欑珯鐐�
+     *
+     * @return
+     */
+    @Override
+    public List<CacheSite> getSeedLocs() {
+        return cacheSiteMapper.selectList(new LambdaQueryWrapper<>());
+    }
+
+    /**
+     * 璁㈠崟缁戝畾鎾澧欑珯鐐�+
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean bindOrderBySite(Map<String, Object> param) {
+        CacheSite siteNo = cacheSiteMapper.selectOne(new LambdaQueryWrapper<CacheSite>()
+                .eq(CacheSite::getSiteNo, param.get("siteNo")), false);
+        if (Objects.isNull(siteNo)) {
+            throw new CoolException("绔欑偣寮傚父锛侊紒");
+        }
+        if (param.get("type").equals("bind")) {
+            if (!StringUtil.isNullOrEmpty(siteNo.getOrderNo())) {
+                throw new CoolException("褰撳墠鎾绔欑偣宸茬粦瀹氳鍗曪紒锛�");
+            }
+            Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
+                    .eq(Order::getOrderNo, param.get("orderNo").toString()));
+            if (Objects.isNull(order)) {
+                throw new CoolException("缁戝畾璁㈠崟涓嶅瓨鍦紒锛�");
+            }
+            siteNo.setOrderNo(order.getOrderNo())
+                    .setOrderId(order.getId())
+                    .setSiteStatus(CacheSiteStatusType.R.id)
+                    .setBarcode(param.get("barcode").toString());
+            if (!cacheSiteService.saveOrUpdate(siteNo)) {
+                throw new CoolException("璁㈠崟鎾浣嶇粦瀹氬け璐ワ紒锛�");
+            }
+
+//            if (!waveSeedMapper.update(new LambdaUpdateWrapper<WaveSeed>()
+//                    .eq(WaveSeed::getOrderNo, order.getOrderNo())
+//                    .set(WaveSeed::getSiteId, siteNo.getId())
+//                    .set(WaveSeed::getSiteNo, siteNo.getSiteNo()))) {
+//                throw new CoolException("鎾绔欑偣鏇存柊澶辫触锛侊紒");
+//            }
+            //缁戝畾鎴愬姛锛屾挱绉嶅浜伅
+            sowLightMange(siteNo.getSiteNo(), order, "LIGHT");
+        } else {
+            if (StringUtil.isNullOrEmpty(siteNo.getOrderNo())) {
+                throw new CoolException("褰撳墠鎾绔欑偣鏈粦瀹氳鍗曪紒锛�");
+            }
+            siteNo.setOrderId(null).setOrderNo(null).setBarcode(null).setSiteNo("0");
+            if (cacheSiteMapper.updateById(siteNo) < 1) {
+                throw new CoolException("璁㈠崟涓庢挱绉嶄綅瑙g粦澶辫触锛侊紒");
+            }
+        }
+        return true;
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/7/11
+     * @description: 缁戝畾鎾澧欎寒鐏�
+     * @version 1.0
+     */
+    public void sowLightMange(String siteNo, Order order, String light) {
+        // 鍒拌揪鎷i�変綅锛屾帶鍒舵挱绉嶅浜伅
+        CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>()
+                .eq(CacheSite::getSiteNo, siteNo));
+        if (Objects.isNull(cacheSite)) {
+            log.error("鏉$爜锛歿}锛屾湭鎵惧埌鎾澧欎寒鐏�", siteNo);
+            throw new CoolException("鏈壘鍒版挱绉嶅");
+        }
+        List<OrderDetl> detls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().eq(OrderDetl::getOrderId, order.getId()));
+        if (Objects.isNull(detls)) {
+            throw new CoolException("鏁版嵁閿欒锛岃鍗曟槑缁嗕笉瀛樺湪锛侊紒");
+        }
+        int anfme = (int) detls.stream().mapToDouble(OrderDetl::getAnfme).sum();
+        SlapLightControlParam slapLightControlParam = new SlapLightControlParam();
+        slapLightControlParam
+                .setControllerCode(cacheSite.getMemo())
+                .setTagCode(cacheSite.getSiteNo())
+                .setColor("GREEN")
+                .setIndex(cacheSite.getIndex())
+//                .setMode("LIGHT")
+                .setMode(light)
+                .setDisplay(anfme + "");
+        // 鍙戣捣浜伅璇锋眰
+        log.info("鎾澧欎寒鐏笅鍙�", JSONObject.toJSONString(slapLightControlParam));
+        CommonReponse response = HttpEssUtils.post("鍒拌揪鎷i�変綅锛屾挱绉嶅浜伅", HttpEssUtils.PLT_SEND_COMMAND, slapLightControlParam);
+        if (response.getCode().equals(0)) {
+            log.info("鎾澧檣}浜伅鎴愬姛", cacheSite.getSiteNo());
+        } else {
+            log.info("鎾澧檣}浜伅澶辫触", cacheSite.getSiteNo());
+        }
+    }
+
+
+    @Override
+    public R selectShippingDetl(Map<String, Object> params) {
+        //鍒ゆ柇璁㈠崟鏄惁涓虹┖
+        if (StringUtil.isNullOrEmpty((String) params.get("orderNo"))) {
+            throw new CoolException("璁㈠崟缂栫爜鍙蜂笉鑳戒负绌猴紒锛�");
+        }
+        String orderNo = params.get("orderNo").toString();
+        Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, orderNo));
+        if (Objects.isNull(order)) {
+            throw new CoolException("璁㈠崟涓嶅瓨鍦紒锛�");
+        }
+        if (!order.getOrderType().equals(OrderType.UTC_OUT_ORDER.id)) {
+            throw new CoolException("璁㈠崟涓哄叆搴撳崟鎹紝涓嶈兘鍙戣揣锛侊紒");
+        }
+
+        List<ShippingOrderDetlDto> waveSeeds = waveSeedMapper.selectShippingOrderDtel(orderNo);
+
+        return R.ok(waveSeeds);
+    }
+
+    /**
+     * 鍙戣揣鍗曟槑缁嗙‘璁�
+     * 1. 鍑哄簱淇敼璁㈠崟瀹屾垚鐘舵�侊紝鍒ゆ柇璁㈠崟鏄惁瀹屾垚锛屽畬鎴愬姞鍏ュ巻鍙叉。锛屾湭瀹屾垚淇敼璁㈠崟宸插畬鎴愭暟閲�
+     * 2. 鍒犻櫎璁㈠崟宸插畬鎴愭挱绉嶆槑缁嗕俊鎭�
+     * 3. 娓呴櫎闆嗚揣鍖虹粦瀹氭暟鎹�
+     *
+     * @param params
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R confirmShippingDetl(List<ShippingOrderDetlDto> params) {
+        if (params.isEmpty()) {
+            throw new CoolException("鍙戣揣鍗曟嵁鏄庣粏涓虹┖锛屼笉鍙墽琛屽彂璐ф搷浣滐紒锛�");
+        }
+
+        //鑾峰彇褰撳墠涓婁紶鎵�鏈夎鍗曞彿
+        Set<String> orderNoSet = params.stream().map(ShippingOrderDetlDto::getOrderNo).collect(Collectors.toSet());
+        if (orderNoSet.isEmpty()) {
+            throw new CoolException("涓诲崟淇℃伅涓嶅瓨鍦紝璇锋牳瀵瑰嚭搴撹鍗曪紒锛�");
+        }
+
+        List<Order> orderList = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNo, orderNoSet));
+        if (orderList.isEmpty()) {
+            throw new CoolException("璁㈠崟涓嶅瓨鍦紒锛�");
+        }
+
+        params.forEach(order -> {
+            OrderDetl byId = orderDetlService.getById(order.getId());
+            if (Objects.isNull(byId)) {
+                throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦紒锛�");
+            }
+            OrderDetlLog orderDetlLog = new OrderDetlLog();
+            BeanUtils.copyProperties(byId, orderDetlLog);
+            orderDetlLog.setId(null);
+            orderDetlLog.setQty(order.getWorkQty());
+            orderDetlLog.setWorkQty(0.0);
+            if (!orderDetlLogService.save(orderDetlLog)) {
+                throw new CoolException("璁㈠崟鏄庣粏杞巻鍙叉。澶辫触锛侊紒");
+            }
+
+            //瀹屽叏鎷h揣锛岃鍗曞畬鎴愬垹闄ゅ師濮嬭鍗曟槑缁�
+            //new BigDecimal(order.getAnfme()).compareTo(new BigDecimal(order.getWorkQty())) == 0
+            if (new BigDecimal(order.getAnfme()).compareTo(new BigDecimal(order.getWorkQty())) == 0) {
+                if (!orderDetlService.removeById(byId)) {
+                    throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦紒锛�");
+                }
+            } else { //閮ㄥ垎鎷h揣
+                byId.setQty(Math.round((order.getWorkQty() + byId.getQty()) * 1000) / 1000.0);
+                byId.setWorkQty(0.0);
+                if (!orderDetlService.updateById(byId)) {
+                    throw new CoolException("閮ㄥ垎鎷f枡鏄庣粏鏇存柊澶辫触锛侊紒");
+                }
+            }
+
+            List<WaveSeed> waveSeeds = waveSeedMapper.list(new LambdaQueryWrapper<WaveSeed>().eq(WaveSeed::getOrderDetlId, order.getId()));
+            //fixme 璁㈠崟鏄庣粏鏈挱绉嶏紝榛樿鍙彂璐�
+            if (!waveSeeds.isEmpty()) {
+                ArrayList<WaveSeedLog> waveSeedLogs = new ArrayList<>();
+                waveSeeds.forEach(seed -> {
+                    WaveSeedLog waveSeedLog = new WaveSeedLog();
+                    BeanUtils.copyProperties(seed, waveSeedLog);
+                    waveSeedLog.setId(null);
+                    waveSeedLogs.add(waveSeedLog);
+                });
+                if (!waveSeedLogService.saveBatch(waveSeedLogs)) {
+                    throw new CoolException("娉㈡槑鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
+                }
+
+                List<Long> list = waveSeeds.stream().map(WaveSeed::getId).collect(Collectors.toList());
+                //鍒犻櫎鎾鏄庣粏淇℃伅
+                if (!waveSeedMapper.removeByIds(list)) {
+                    throw new CoolException("鎾鏄庣粏鍒犻櫎鎼虹▼锛侊紒");
+                }
+
+            }
+
+        });
+
+        orderList.forEach(one -> {
+            OrderLog orderLog = new OrderLog();
+            BeanUtils.copyProperties(one, orderLog);
+            orderLog.setId(null);
+            orderLog.setOrderSettle(OrderSettleType.COMPLETE.val());
+
+            if (!orderLogService.save(orderLog)) {
+                throw new CoolException("鍘熷璁㈠崟杞巻鍙叉。澶辫触锛侊紒");
+            }
+            //鏌ヨ褰撳墠璁㈠崟涓嬪惁杩樻湁鏄庣粏瀛樺湪
+            List<OrderDetl> orders = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>().in(OrderDetl::getOrderNo, one.getOrderNo()));
+            //璁㈠崟鏄庣粏涓虹┖锛屽垯鍒犻櫎涓诲崟
+            if (orders.isEmpty()) {
+                if (!orderService.remove(new LambdaQueryWrapper<Order>().eq(Order::getOrderNo, one.getOrderNo()))) {
+                    throw new CoolException("鍘熷璁㈠崟鍒犻櫎澶辫触锛侊紒");
+                }
+            } else { //涓嶄负绌猴紝淇敼璁㈠崟鐘舵�侊紝鍙噸鏂扮粍鎷�
+                one.setOrderSettle(OrderSettleType.INIT.val());
+                if (orderService.updateById(one)) ;
+            }
+        });
+
+        Set<Long> ordersSet = orderList.stream().map(Order::getId).collect(Collectors.toSet());
+        List<PlatformDetl> platDetls = platformDetlService.list(new LambdaQueryWrapper<PlatformDetl>().in(PlatformDetl::getOrderId, ordersSet));
+        if (platDetls.isEmpty()) {
+            throw new CoolException("璁㈠崟淇℃伅鏈繘闆嗚揣鍖猴紒锛�");
+        }
+        ArrayList<PlatformDetlLog> platformDetls = new ArrayList<>();
+        platDetls.forEach(plat -> {
+            PlatformDetlLog detl = new PlatformDetlLog();
+            BeanUtils.copyProperties(plat, detl);
+            detl.setId(null);
+            platformDetls.add(detl);
+        });
+        //闆嗚揣鍖鸿浆鍘嗗彶妗�
+        if (!platformDetlLogService.saveBatch(platformDetls)) {
+            throw new CoolException("闆嗚揣鍖鸿鍗曡浆鍘嗗彶妗eけ璐ワ紒锛�");
+        }
+
+        return R.ok("鍙戣揣瀹屾垚锛侊紒");
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/6/28
+     * @description: 鑾峰彇骞冲簱鎺ㄨ崘搴撲綅
+     * @version 1.0
+     */
+    @Override
+    public R getRecommendLocs() {
+        return locService.getRecommengLocs();
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/6/28
+     * @description: 鏌ヨ鐗╂枡淇℃伅
+     * @version 1.0
+     */
+    @Override
+    public R getMatsByCode(String matnr) {
+        QueryWrapper<LocDetl> wrapper = new QueryWrapper<>();
+        wrapper.eq("matnr", matnr).select("matnr, SUM(anfme) anfme");
+        LocDetl detl = locDetlService.getOne(wrapper);
+
+        Mat one = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detl.getMatnr()), false);
+        if (Objects.isNull(one)) {
+            throw new CoolException("鐗╂枡涓嶅瓨鍦紒锛�");
+        }
+        one.setAnfme(detl.getAnfme());
+        return R.ok().add(Arrays.asList(one));
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/7/10
+     * @description: 鑾峰彇搴撲綅鏄庣粏
+     * @version 1.0
+     */
+    @Override
+    public List<LocDetl> getDetlsByCode(String barcode) {
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getLocNo, barcode));
+        if (Objects.isNull(loc)) {
+            throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
+        }
+        LocArea locArea = locAreaService.getOne(new LambdaQueryWrapper<LocArea>()
+                .eq(LocArea::getLocId, loc.getId())
+                .eq(LocArea::getTypeId, LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id));
+        if (Objects.isNull(locArea)) {
+            throw new CoolException("闈炲钩搴撳簱浣嶄笉鍙墽琛屾鎿嶄綔锛侊紒");
+        }
+        List<LocDetl> detls = locDetlService.list(new LambdaQueryWrapper<LocDetl>()
+                .eq(LocDetl::getLocNo, barcode));
+        for (int i = 0; i < detls.size(); i++) {
+            Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getId, detls.get(i).getMatId()));
+            MatnrDetlDto detlDto = new MatnrDetlDto();
+            detlDto.setTspec(mat.getSpecs())
+                    .setType(mat.getModel())
+                    .setMatnrName(mat.getMaktx())
+                    .setMatnrNo(mat.getMatnr());
+            detls.get(i).setMats(detlDto);
+        }
+        return detls;
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/7/11
+     * @description: 骞冲簱搴撲綅杞Щ
+     * @version 1.0
+     */
+    @Override
+    public R transferLocs(Map<String, String> param) {
+        Loc barcode = locService.getOne(new LambdaQueryWrapper<Loc>()
+                .eq(Loc::getLocStsId, LocStsType.F.val())
+                .eq(Loc::getLocNo, param.get("barcode")));
+        if (Objects.isNull(barcode)) {
+            throw new CoolException(param.get("barcode") +  "搴撲綅鐘舵�佷笉鍙墽琛屾鎿嶄綔锛侊紒");
+        }
+        Loc tarCode = locService.getOne(new LambdaQueryWrapper<Loc>()
+                .eq(Loc::getLocStsId, LocStsType.O.val())
+                .eq(Loc::getLocNo, param.get("tarCode")));
+        if (Objects.isNull(tarCode)) {
+            throw new CoolException("璇锋鏌ョ洰鏍囦负鍞綅鏄惁瀛樺湪鎴栨槸鍚︿负绌哄簱锛侊紒");
+        }
+
+        List<Long> ids = Arrays.asList(barcode.getId(), tarCode.getId());
+
+        List<LocArea> locAreas = locAreaService.list(new LambdaQueryWrapper<LocArea>()
+                .in(LocArea::getLocId, ids)
+                .eq(LocArea::getTypeId, LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id));
+        if (!locAreas.isEmpty() && locAreas.size() != ids.size()) {
+            throw new CoolException("闈炲钩搴撲笉鍙墽琛屾鎿嶄綔锛侊紒");
+        }
+
+        List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, barcode.getLocNo()));
+        if (locDetls.isEmpty()) {
+            return R.error("搴撲綅鏄庣粏涓嶅瓨鍦紒锛�");
+        }
+
+        if (!locService.update(new LambdaUpdateWrapper<Loc>()
+                .eq(Loc::getLocNo, barcode.getLocNo())
+                .set(Loc::getBarcode, null)
+                .set(Loc::getLocStsId, LocStsType.O.val()))) {
+            throw new CoolException("婧愬簱浣嶇姸鎬佷慨鏀瑰け璐ワ紒锛�");
+        }
+
+        if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getLocNo, tarCode.getLocNo())
+                .set(Loc::getBarcode, barcode.getBarcode())
+                .set(Loc::getLocStsId, LocStsType.F.val()))) {
+            throw new CoolException("鐩爣搴撲綅淇敼澶辫触锛侊紒");
+        }
+
+        if (!locDetlService.update(new LambdaUpdateWrapper<LocDetl>()
+                .eq(LocDetl::getLocId, barcode.getId())
+                .set(LocDetl::getLocId, tarCode.getId())
+                .set(LocDetl::getLocNo, tarCode.getLocNo()))) {
+            throw new CoolException("搴撲綅鏄庣粏淇敼澶辫触锛侊紒");
+        }
+
+        return R.ok();
+    }
+
+
 }

--
Gitblit v1.9.1