From 2f8e173048d22c5b40612c3538b9c1aa5a5397f6 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期五, 27 三月 2026 13:38:05 +0800
Subject: [PATCH] #乐观锁
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 267 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..2204a2f 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,277 @@
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.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.vincent.rsf.framework.common.Cools;
+import com.vincent.rsf.framework.common.R;
+import com.vincent.rsf.framework.exception.CoolException;
+import com.vincent.rsf.server.manager.controller.dto.LocStockDto;
+import com.vincent.rsf.server.manager.controller.dto.LocUsageDto;
+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.enums.CommonStatus;
+import com.vincent.rsf.server.manager.enums.LocStsType;
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 com.vincent.rsf.server.manager.utils.Shelves;
+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.Arrays;
+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(), ",");
+ }
+ List<Loc> existsLocs = this.list(new LambdaQueryWrapper<Loc>()
+ .in(Loc::getId, locs.getId())
+ .eq(Loc::getStatus, 1));
+ if (existsLocs.isEmpty()) {
+ throw new CoolException("搴撲綅淇℃伅淇敼澶辫触锛侊紒");
+ }
+ for (Loc currentLoc : existsLocs) {
+ if (!Objects.isNull(loc.getAreaId())) {
+ currentLoc.setAreaId(loc.getAreaId());
+ }
+ if (!Objects.isNull(loc.getWarehouseId())) {
+ currentLoc.setWarehouseId(loc.getWarehouseId());
+ }
+ if (!Objects.isNull(loc.getUseStatus())) {
+ currentLoc.setUseStatus(loc.getUseStatus());
+ }
+ if (!Objects.isNull(loc.getTypeIds()) && !loc.getTypeIds().isEmpty()) {
+ currentLoc.setType(join);
+ }
+ if (!Objects.isNull(loc.getLength())) {
+ currentLoc.setLength(loc.getLength());
+ }
+ if (!Objects.isNull(loc.getWidth())) {
+ currentLoc.setWidth(loc.getWidth());
+ }
+ if (!Objects.isNull(loc.getHeight())) {
+ currentLoc.setHeight(loc.getHeight());
+ }
+ if (!Objects.isNull(loc.getChannel())) {
+ currentLoc.setChannel(loc.getChannel());
+ }
+ if (!Objects.isNull(loc.getFlagLabelMange())) {
+ currentLoc.setFlagLabelMange(loc.getFlagLabelMange());
+ }
+ if (!Objects.isNull(loc.getStatus()) && loc.getStatus().equals(CommonStatus.COMMONSTATUS_NO.val)) {
+ currentLoc.setUseStatus(LocStsType.LOC_STS_TYPE_X.type);
+ }
+ if (!Objects.isNull(loc.getStatus())) {
+ currentLoc.setStatus(loc.getStatus());
+ }
+ if (!this.updateById(currentLoc)) {
+ throw new CoolException("搴撲綅淇℃伅淇敼澶辫触锛侊紒");
+ }
+ }
+
+ return R.ok(loc);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public R initLocs(LocMastInitParam param, Long loginUserId) {
+
+ WarehouseAreas warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
+ .eq(!Objects.isNull(param.getWarehouseId()), WarehouseAreas::getWarehouseId, param.getWarehouseId())
+ .eq(!Objects.isNull(param.getAreaId()), WarehouseAreas::getId, param.getAreaId()));
+ if (Objects.isNull(warehouseAreas)) {
+ throw new CoolException("搴撳尯涓嶅瓨鍦紒锛�");
+ }
+ // 娓呯┖琛�
+ // this.baseMapper.deleteAll();
+ // 娓呯┖褰撳墠搴撳尯搴撲綅
+ List<Loc> locs = this.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, warehouseAreas.getWarehouseId())
+ .eq(Loc::getAreaId, warehouseAreas.getId()));
+ if (!locs.isEmpty()) {
+ if (!this.remove(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, warehouseAreas.getWarehouseId())
+ .eq(Loc::getAreaId, warehouseAreas.getId()))) {
+ throw new CoolException("鍒濆鍖栧け璐ワ細鏁版嵁鍒犻櫎澶辫触锛侊紒");
+ }
+ }
+
+ String join = StringUtils.join(param.getTypeIds(), ",");
+
+ String[] split = warehouseAreas.getCode().split("\\.");
+ if (split.length == 0) {
+ throw new CoolException("搴撳尯缂栫爜閿欒锛侊紒");
+ }
+ StringBuilder locStar = new StringBuilder();
+ for (int i = 0; i < split.length; i++) {
+ locStar.append(split[i]).append("-");
+ }
+
+ List<Loc> list = new ArrayList<>();
+ Integer chanl = 0; // 榛樿绗竴宸烽亾
+ for (int r = param.getStartRow(); r <= param.getEndRow(); r++) {
+ try {
+ Shelves shelves = new Shelves(param.getEndRow() - param.getStartRow() + 1, param.getChannel(),
+ param.getStartRow());
+ for (List<Integer> node : shelves.nodes) {
+ if (node.contains(r)) {
+ if (!Cools.isEmpty(param.getStartChannel()) && param.getStartChannel() > 0) {
+ chanl = shelves.nodes.indexOf(node) + param.getStartChannel();
+ } else {
+ chanl = shelves.nodes.indexOf(node) + 1;
+ }
+ break;
+ }
+ }
+ } catch (Exception e) {
+ throw new CoolException("瑙f瀽宸烽亾鍙峰け璐�");
+ }
+ for (int b = param.getStartBay(); b <= param.getEndBay(); b++) {
+ for (int l = param.getStartLev(); l <= param.getEndLev(); l++) {
+ // 鑾峰彇搴撲綅鍙�
+ String locNo = locStar + String.format("%d", r) + String.format("-%d", b) + String.format("-%d", l);
+ Loc loc = new Loc();
+ loc.setCode(locNo)
+ .setUseStatus("O")
+ .setRow(r)
+ .setCol(b)
+ .setLev(l)
+ .setChannel(chanl)
+ .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();
+ }
+
+ /**
+ * 鑾峰彇搴撲綅浣跨敤鎯呭喌
+ *
+ * @return
+ */
+ @Override
+ public R getLocPies() {
+ List<LocUsageDto> locPies = this.baseMapper.getLocPies();
+ return R.ok().add(locPies);
+ }
+
+ /**
+ * @author Ryan
+ * @date 2025/8/16
+ * @description: 鑾峰彇搴撲綅鏄庣粏
+ * @version 1.0
+ */
+ @Override
+ public IPage<LocStockDto> getLocDetls(Page<Object> page) {
+ return this.baseMapper.getLocDetls(page);
+ }
}
--
Gitblit v1.9.1