From c8fde8647b48e7c7d9b3beb6e8c39459f07c9eb2 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 08 五月 2025 14:55:46 +0800
Subject: [PATCH] Merge branch 'devlop' of http://47.97.1.152:5880/r/wms-master into devlop

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java |  183 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 181 insertions(+), 2 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
index dea1d43..259612b 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
@@ -1,12 +1,191 @@
 package com.vincent.rsf.server.manager.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.vincent.rsf.framework.common.R;
+import com.vincent.rsf.framework.exception.CoolException;
+import com.vincent.rsf.server.manager.controller.params.LocMastInitParam;
+import com.vincent.rsf.server.manager.controller.params.LocModifyParams;
+import com.vincent.rsf.server.manager.entity.*;
 import com.vincent.rsf.server.manager.mapper.LocMapper;
-import com.vincent.rsf.server.manager.entity.Loc;
-import com.vincent.rsf.server.manager.service.LocService;
+import com.vincent.rsf.server.manager.mapper.LocTypeRelaMapper;
+import com.vincent.rsf.server.manager.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
+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.util.Objects;
 
 @Service("locService")
 public class LocServiceImpl extends ServiceImpl<LocMapper, Loc> implements LocService {
 
+    @Autowired
+    private WarehouseAreasService warehouseAreasService;
+
+    @Autowired
+    private LocTypeRelaService locTypeRelaService;
+
+    @Autowired
+    private LocAreaRelaService locAreaRelaService;
+
+    @Autowired
+    private LocAreaService locAreaService;
+
+    @Autowired
+    private LocTypeRelaMapper locTypeRelaMapper;
+
+    @Override
+    public R modifyLocs(LocModifyParams locs) {
+        if (locs.getId().isEmpty()) {
+            throw new CoolException("搴撲綅ID涓嶈兘涓虹┖锛侊紒");
+        }
+        Loc loc = locs.getLoc();
+
+        if (Objects.isNull(loc)) {
+            throw new CoolException("淇敼搴撲綅淇℃伅涓嶈兘涓虹┖锛侊紒");
+        }
+
+        String join = loc.getType();
+        if (!Objects.isNull(loc.getTypeIds()) && !loc.getTypeIds().isEmpty()) {
+             join = StringUtils.join(loc.getTypeIds(), ",");
+        }
+        boolean update = this.update(new LambdaUpdateWrapper<Loc>()
+                .in(Loc::getId, locs.getId())
+                .eq(Loc::getStatus, 1)
+                .set(!Objects.isNull(loc.getAreaId()), Loc::getAreaId, loc.getAreaId())
+                .set(!Objects.isNull(loc.getWarehouseId()), Loc::getWarehouseId, loc.getWarehouseId())
+                .set(!Objects.isNull(loc.getUseStatus()), Loc::getUseStatus, loc.getUseStatus())
+                .set(!Objects.isNull(loc.getTypeIds()) && !loc.getTypeIds().isEmpty(), Loc::getType, join)
+                .set(!Objects.isNull(loc.getLength()), Loc::getLength, loc.getLength())
+                .set(!Objects.isNull(loc.getWidth()), Loc::getWidth, loc.getWidth())
+                .set(!Objects.isNull(loc.getHeight()), Loc::getHeight, loc.getHeight())
+                .set(!Objects.isNull(loc.getChannel()), Loc::getChannel, loc.getChannel())
+                .set(!Objects.isNull(loc.getFlagLabelMange()), Loc::getFlagLabelMange, loc.getFlagLabelMange())
+                .set(!Objects.isNull(loc.getStatus()), Loc::getStatus, loc.getStatus()));
+        if (!update) {
+            throw new CoolException("搴撲綅淇℃伅淇敼澶辫触锛侊紒");
+        }
+
+        return R.ok(loc);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R initLocs(LocMastInitParam param, Long loginUserId) {
+        //娓呯┖琛�
+//        this.baseMapper.deleteAll();
+        //娓呯┖褰撳墠搴撳尯搴撲綅
+        List<Loc> locs = this.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, param.getWarehouseId()).eq(Loc::getAreaId, param.getAreaId()));
+        if (!locs.isEmpty()) {
+            if (!this.remove(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, param.getWarehouseId()).eq(Loc::getAreaId, param.getAreaId()))) {
+                throw new CoolException("鍒濆鍖栧け璐ワ細鏁版嵁鍒犻櫎澶辫触锛侊紒");
+            }
+        }
+        WarehouseAreas warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
+                .eq(WarehouseAreas::getWarehouseId, param.getWarehouseId())
+                .eq(WarehouseAreas::getId, param.getAreaId()));
+        if (Objects.isNull(warehouseAreas)) {
+            throw new CoolException("搴撳尯涓嶅瓨鍦紒锛�");
+        }
+        String join = StringUtils.join(param.getTypeIds(), ",");
+
+        List<Loc> list = new ArrayList<>();
+        for (int r = param.getStartRow(); r <= param.getEndRow(); r++) {
+            for (int b = param.getStartBay(); b <= param.getEndBay(); b++) {
+                for (int l = param.getStartLev(); l <= param.getEndLev(); l++) {
+                    // 鑾峰彇搴撲綅鍙�
+                    String locNo = String.format("%02d", r) + String.format("%03d", b) + String.format("%02d", l);
+                    Loc loc = new Loc();
+                    loc.setCode(locNo)
+                            .setUseStatus("O")
+                            .setRow(r)
+                            .setCol(b)
+                            .setLev(l)
+                            .setType(join)
+                            .setAreaId(param.getAreaId())
+                            .setUpdateBy(loginUserId)
+                            .setCreateBy(loginUserId)
+                            .setWarehouseId(warehouseAreas.getWarehouseId());
+                    list.add(loc);
+                }
+            }
+        }
+
+        if (!this.saveBatch(list)) {
+            throw new CoolException("搴撲綅鍒濆鍖栧け璐ワ紒锛�");
+        }
+        List<LocTypeRela> locTypeRelas = new ArrayList<>();
+        for (Long typeId : param.getTypeIds()) {
+            for (Loc loc : list) {
+                LocTypeRela typeRela = new LocTypeRela();
+                typeRela.setLocId(loc.getId()).setTypeId(typeId);
+                locTypeRelas.add(typeRela);
+            }
+        }
+        if (!locTypeRelaService.saveBatch(locTypeRelas)) {
+            throw new CoolException("搴撲綅绫诲瀷鍏宠仈澶辫触锛侊紒");
+        }
+        return R.ok("鍒濆鍖栨垚鍔燂紒锛�");
+    }
+
+    @Override
+    public boolean saveType(Loc loc) {
+        List<LocTypeRela> relas =  new ArrayList<>();
+        loc.getTypeIds().forEach(id -> {
+            LocTypeRela typeRela = new LocTypeRela();
+            typeRela.setTypeId(id)
+                    .setLocId(loc.getId());
+            relas.add(typeRela);
+        });
+        if (!locTypeRelaService.saveOrUpdateBatch(relas)) {
+            throw new CoolException("搴撲綅鍏宠仈鍏崇郴淇濆瓨澶辫触锛侊紒");
+        }
+        return true;
+    }
+
+    @Override
+    public boolean updateLoc(Loc loc) {
+        locTypeRelaMapper.delete(new LambdaQueryWrapper<LocTypeRela>().eq(LocTypeRela::getLocId, loc.getId()));
+        List<LocTypeRela> relas =  new ArrayList<>();
+        loc.getTypeIds().forEach(id -> {
+            LocTypeRela typeRela = new LocTypeRela();
+            typeRela.setTypeId(id)
+                    .setLocId(loc.getId());
+            relas.add(typeRela);
+        });
+        if (!locTypeRelaService.saveOrUpdateBatch(relas)) {
+            throw new CoolException("搴撲綅鍏宠仈鍏崇郴淇濆瓨澶辫触锛侊紒");
+        }
+        return true;
+    }
+
+    @Override
+    public R batchBindLocs(LocModifyParams locs) {
+        if (locs.getId().isEmpty()) {
+            throw new CoolException("搴撲綅ID涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(locs.getLocAreaId())) {
+            throw new CoolException("淇敼搴撲綅淇℃伅涓嶈兘涓虹┖锛侊紒");
+        }
+        List<LocArea> locAreas = locAreaService.list(new LambdaQueryWrapper<LocArea>().eq(LocArea::getId, locs.getLocAreaId()));
+        if (locAreas.isEmpty()) {
+            throw new CoolException("搴撲綅鍒嗗尯涓嶅瓨鍦紒锛�");
+        }
+        List<LocAreaRela> relas = new ArrayList<>();
+        locs.getId().forEach(id -> {
+            LocAreaRela locAreaRela = new LocAreaRela();
+            locAreaRela.setLocId(id)
+                    .setLocAreaId(locs.getLocAreaId());
+            relas.add(locAreaRela);
+        });
+        if (!locAreaRelaService.saveBatch(relas)) {
+            throw new CoolException("搴撲綅鍒嗗尯澶辫触锛侊紒");
+        }
+
+        return R.ok();
+    }
 }

--
Gitblit v1.9.1