Procházet zdrojové kódy

27. 新增上移,下移,置顶,置底接口,实现业务逻辑检索,依次排序,交换层号等功能

26.	修改批量入库接口,新加功能,查询库中当前垛位下最大层号,依次排序,添加到入库表,库存表
25.	垛位管理页面新增单击查询该垛位下库存信息
20.	库房管理系统,新增批量新增垛位功能,根据起始数量,其实编号,新增垛位前缀来进行编排的批量操作
19.	库房管理系统,调试保存或修改垛位接口,修复bug
dw před 4 měsíci
rodič
revize
e47cf0fad5

+ 18
- 0
sto/src/main/java/com/shinsoft/sto/controller/main/WareController.java Zobrazit soubor

@@ -102,5 +102,23 @@ public class WareController {
102 102
             return resultJSON;
103 103
         }
104 104
     }
105
+
106
+    /**
107
+     * 根据仓库id与垛位id查询垛位下库存信息
108
+     */
109
+    @RequestMapping("/getWares")
110
+    public ResultJSON getWares(@RequestParam("wareId") String wareId,@RequestParam("stackId") String stackId, HttpServletRequest request) {
111
+        try {
112
+            String belongId = request.getHeader("belongId");
113
+            resultJSON = wareService.getWares(wareId, stackId,belongId);
114
+        } catch (Exception ex) {
115
+            ex.printStackTrace();
116
+            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ex);
117
+        } finally {
118
+            return resultJSON;
119
+        }
120
+    }
121
+
122
+
105 123
 }
106 124
 

+ 56
- 0
sto/src/main/java/com/shinsoft/sto/controller/ware/StoreChangeController.java Zobrazit soubor

@@ -3,6 +3,8 @@ package com.shinsoft.sto.controller.ware;
3 3
 import com.alibaba.fastjson.JSON;
4 4
 import com.shinsoft.sto.model.system.ResultJSON;
5 5
 import com.shinsoft.sto.service.ware.StoreChangeService;
6
+import com.shinsoft.tools.JSONTools;
7
+import com.shinsoft.tools.model.common.ResponseCodeMsg;
6 8
 import org.springframework.beans.factory.annotation.Autowired;
7 9
 import org.springframework.web.bind.annotation.RequestMapping;
8 10
 import org.springframework.web.bind.annotation.RequestParam;
@@ -41,5 +43,59 @@ public class StoreChangeController {
41 43
         }
42 44
         return map;
43 45
     }
46
+
47
+    /**
48
+     * 层号上移
49
+     */
50
+    @RequestMapping("/moveUp")
51
+    public ResultJSON moveUp(@RequestParam("wareId") String wareId, @RequestParam("stackId") String stackId, @RequestParam("prodId") String prodId, @RequestParam("layerNo") String layerNo, HttpServletRequest request) {
52
+        try {
53
+            String belongId = request.getHeader("belongId");
54
+            return storeChangeService.moveUp(wareId, stackId, prodId, layerNo, belongId);
55
+        } catch (Exception ex) {
56
+            return ResultJSON.error("上移失败"+ex.getMessage());
57
+        }
58
+    }
59
+
60
+    /**
61
+     * 层号下移
62
+     */
63
+    @RequestMapping("/moveDown")
64
+    public ResultJSON moveDown(@RequestParam("wareId") String wareId, @RequestParam("stackId") String stackId, @RequestParam("prodId") String prodId, @RequestParam("layerNo") String layerNo, HttpServletRequest request) {
65
+        try {
66
+            String belongId = request.getHeader("belongId");
67
+            return storeChangeService.moveDown(wareId, stackId, prodId, layerNo, belongId);
68
+        } catch (Exception ex) {
69
+            return ResultJSON.error("下移失败"+ex.getMessage());
70
+        }
71
+    }
72
+
73
+    /**
74
+     * 层号置顶
75
+     */
76
+    @RequestMapping("/moveTop")
77
+    public ResultJSON moveTop(@RequestParam("wareId") String wareId, @RequestParam("stackId") String stackId, @RequestParam("prodId") String prodId, @RequestParam("layerNo") String layerNo, HttpServletRequest request) {
78
+        try {
79
+            String belongId = request.getHeader("belongId");
80
+            return storeChangeService.moveTop(wareId, stackId, prodId, layerNo, belongId);
81
+        } catch (Exception ex) {
82
+            ex.printStackTrace();
83
+            return ResultJSON.error("置顶失败"+ex.getMessage());
84
+        }
85
+    }
86
+
87
+    /**
88
+     * 层号置底
89
+     */
90
+    @RequestMapping("/moveBottom")
91
+    public ResultJSON moveBottom(@RequestParam("wareId") String wareId, @RequestParam("stackId") String stackId, @RequestParam("prodId") String prodId, @RequestParam("layerNo") String layerNo, HttpServletRequest request) {
92
+        try {
93
+            String belongId = request.getHeader("belongId");
94
+           return storeChangeService.moveBottom(wareId, stackId, prodId, layerNo, belongId);
95
+        } catch (Exception ex) {
96
+            ex.printStackTrace();
97
+            return ResultJSON.error("置底失败"+ex.getMessage());
98
+        }
99
+    }
44 100
 }
45 101
 

+ 4
- 0
sto/src/main/java/com/shinsoft/sto/mapper/main/WareMapper.java Zobrazit soubor

@@ -3,6 +3,8 @@ package com.shinsoft.sto.mapper.main;
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.shinsoft.sto.model.common.selectModel;
5 5
 import com.shinsoft.sto.model.main.Ware;
6
+import com.shinsoft.sto.model.record.ImportModel;
7
+import org.apache.ibatis.annotations.Param;
6 8
 import org.apache.ibatis.annotations.Select;
7 9
 
8 10
 import java.util.List;
@@ -13,4 +15,6 @@ public interface WareMapper extends BaseMapper<Ware> {
13 15
     List<selectModel> selectWareOptions();
14 16
     Ware selectByWareId(String wareId, String userId, String belongId);
15 17
 
18
+    List<ImportModel> selectImportModel(@Param("wareId") String wareId, @Param("stackId") String stackId,@Param("belongId") String belongId);
19
+
16 20
 }

+ 44
- 0
sto/src/main/java/com/shinsoft/sto/mapper/main/WareMapper.xml Zobrazit soubor

@@ -78,4 +78,48 @@ and t.id =   #{param1,jdbcType=VARCHAR}
78 78
 and  t.belong_id = #{param3,jdbcType=VARCHAR}
79 79
     and ifnull(t.cancel_flag,'0') = '0'
80 80
   </select>
81
+
82
+    <select id="selectImportModel">
83
+        select
84
+            t2.PROD_NO prodNo,
85
+            t2.ST_GRADE stGrade,
86
+            T2.WEIGHT weight,
87
+            T2.QUANTITY quantity,
88
+            T2.DELIVERY_ADDRESS,
89
+            T2.IN_TRUCK_NO inTruckNo,
90
+            T2.IN_DTM inDtm,
91
+            T2.IN_USER_NAME inUser,
92
+            T2.LOCK_FLAG lockFlag,
93
+            T2.ATTRIB_01 attrib01,
94
+            T2.ATTRIB_02 attrib02,
95
+            T2.ATTRIB_03 attrib03,
96
+            T2.ATTRIB_04 attrib04,
97
+            T2.ATTRIB_05 attrib05,
98
+            T3.CUSTOMER_NM AS ownerCompany,
99
+            T4.CUSTOMER_NM AS receivingCompany,
100
+            T5.CUSTOMER_NM AS customerCompanyName,
101
+            T6.WARE_NM wareName,
102
+            t7.NAME stackName,
103
+            T1.LAYER_NO layerNo,
104
+            T1.STACK_ID,
105
+            T1.WARE_ID,
106
+            T8.MATERIAL_NAME materialName,
107
+            T2.ID prodId
108
+        from T_WARE_STORE t1
109
+                 LEFT JOIN T_PROD_MASTER T2 ON T2.ID = T1.STORE_ID
110
+                 LEFT JOIN T_MAIN_CUSTOMER T3 ON T3.ID = T2.OWNER_COMPANY
111
+                 LEFT JOIN T_MAIN_CUSTOMER T4 ON T4.ID = T2.RECEIVING_COMPANY
112
+                 LEFT JOIN T_MAIN_CUSTOMER T5 ON T5.ID = T2.CUSTOMER_COMPANY
113
+                 LEFT JOIN T_MAIN_WARE T6 ON T6.ID = T1.WARE_ID
114
+                 LEFT JOIN T_MAIN_STACK T7 ON T7.ID = T1.STACK_ID
115
+                 LEFT JOIN T_MAIN_MATERIAL T8 ON T8.ID = T2.MATERIAL_ID
116
+        WHERE
117
+            t1.STACK_ID = #{stackId}
118
+          and t1.WARE_ID = #{wareId}
119
+          and t1.BELONG_ID = #{belongId}
120
+          AND T2.IN_FLAG = '0'
121
+          AND T2.OUT_FLAG = '0'
122
+          AND T2.CANCEL_FLAG = '0'
123
+        order by t1.LAYER_NO desc
124
+    </select>
81 125
 </mapper>

+ 2
- 0
sto/src/main/java/com/shinsoft/sto/mapper/ware/StoreChangeMapper.java Zobrazit soubor

@@ -12,5 +12,7 @@ public interface StoreChangeMapper extends BaseMapper<StoreChange> {
12 12
 
13 13
     IPage<StoreChange> selectStoreChangePage(Page<StoreChange> page,
14 14
                                              @Param("parms") Map<String, Object> map);
15
+
16
+    Integer selectMaxLayerNoByWareAndStack(@Param("wareId") String wareId,@Param("stackId") String stackId,@Param("belongId") String belongId);
15 17
 }
16 18
 

+ 13
- 0
sto/src/main/java/com/shinsoft/sto/mapper/ware/StoreChangeMapper.xml Zobrazit soubor

@@ -39,5 +39,18 @@
39 39
         <include refid="QueryWhere"/>
40 40
         order by ws.id desc
41 41
     </select>
42
+    <select id="selectMaxLayerNoByWareAndStack">
43
+        SELECT MAX(TO_NUMBER(layer_no))
44
+        FROM (
45
+                 SELECT layer_no
46
+                 FROM T_WARE_STORE
47
+                 WHERE ware_id = #{wareId}
48
+                   AND stack_id = #{stackId}
49
+                   AND belong_id = #{belongId}
50
+                   AND CANCEL_FLAG = '0'
51
+                 ORDER BY TO_NUMBER(layer_no) DESC
52
+             )
53
+        WHERE ROWNUM = 1
54
+    </select>
42 55
 </mapper>
43 56
 

+ 24
- 4
sto/src/main/java/com/shinsoft/sto/model/record/ImportModel.java Zobrazit soubor

@@ -1,11 +1,13 @@
1 1
 package com.shinsoft.sto.model.record;
2 2
 
3
+import com.alibaba.excel.annotation.ExcelIgnore;
3 4
 import com.alibaba.excel.annotation.ExcelProperty;
4 5
 import com.alibaba.excel.annotation.format.DateTimeFormat;
5 6
 import com.alibaba.excel.annotation.write.style.ColumnWidth;
6 7
 import lombok.AllArgsConstructor;
7 8
 import lombok.Data;
8 9
 import lombok.NoArgsConstructor;
10
+import net.sf.jsqlparser.util.validation.Validation;
9 11
 
10 12
 import java.math.BigDecimal;
11 13
 
@@ -83,12 +85,30 @@ public class ImportModel {
83 85
     @ColumnWidth(15)
84 86
     private String remark1;
85 87
 
86
-//    @ExcelProperty(value = "垛位备注", index = 18)
87
-//    @ColumnWidth(15)
88
-//    private String remark2;
89
-
90 88
     @ExcelProperty(value = "入库/理货人员", index = 18)
91 89
     @ColumnWidth(20)
92 90
     private String inUser;
91
+
92
+
93
+
94
+    @ExcelIgnore
95
+    private String inDtm;
96
+
97
+    @ExcelIgnore
98
+    private String lockFlag;
99
+
100
+    @ExcelIgnore
101
+    private String customerCompanyName;
102
+
103
+    @ExcelIgnore
104
+    private String wareId;
105
+
106
+    @ExcelIgnore
107
+    private String stackId;
108
+
109
+    @ExcelIgnore
110
+    private String prodId;
111
+
112
+
93 113
 //
94 114
 }

+ 8
- 0
sto/src/main/java/com/shinsoft/sto/service/impl/main/WareServiceImp.java Zobrazit soubor

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9 9
 import com.shinsoft.sto.mapper.main.WareMapper;
10 10
 import com.shinsoft.sto.model.common.selectModel;
11 11
 import com.shinsoft.sto.model.main.Ware;
12
+import com.shinsoft.sto.model.record.ImportModel;
12 13
 import com.shinsoft.sto.service.main.WareService;
13 14
 import com.shinsoft.tools.JSONTools;
14 15
 import com.shinsoft.tools.model.common.ResultJSON;
@@ -121,5 +122,12 @@ public class WareServiceImp extends ServiceImpl<WareMapper, Ware> implements War
121 122
         resultJSON = JSONTools.toResultJSON(options);
122 123
         return resultJSON;
123 124
     }
125
+
126
+    @Override
127
+    public ResultJSON getWares(String wareId, String stackId, String belongId) {
128
+        List<ImportModel> importModels = wareMapper.selectImportModel(wareId, stackId, belongId);
129
+        return JSONTools.toResultJSON(importModels);
130
+    }
131
+
124 132
 }
125 133
 

+ 40
- 4
sto/src/main/java/com/shinsoft/sto/service/impl/record/InrecordServiceImpl.java Zobrazit soubor

@@ -95,6 +95,20 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
95 95
             if(ObjectUtils.isEmpty(dataList)){
96 96
                 return ResultJSON.error(ResponseCodeMsg.CODE_EX, "数据为空");
97 97
             }
98
+//            根据层号正排序
99
+            // 根据层号正排序(数值排序)
100
+            dataList.sort((o1, o2) -> {
101
+                try {
102
+                    Integer num1 = Integer.parseInt(o1.getLayerNo());
103
+                    Integer num2 = Integer.parseInt(o2.getLayerNo());
104
+                    return num1.compareTo(num2);
105
+                } catch (NumberFormatException e) {
106
+                    // 如果解析失败,回退到字符串比较
107
+                    String layerNo1 = o1.getLayerNo();
108
+                    String layerNo2 = o2.getLayerNo();
109
+                    return layerNo1 != null ? layerNo1.compareTo(layerNo2) : 0;
110
+                }
111
+            });
98 112
             for (ImportModel model : dataList){
99 113
                 /**
100 114
                  * 数据校验
@@ -171,7 +185,7 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
171 185
                     return ResultJSON.error(ResponseCodeMsg.CODE_EX, "入库失败");
172 186
                 }
173 187
 //                拼接入库记录
174
-                Inrecord inrecord = inRecordSplice(model, userId, belongId,material,customer,customer1,userName);
188
+                Inrecord inrecord = inRecordSplice(model, userId, belongId,material,customer,customer1,userName,ware,stack);
175 189
                 int insert1 = inrecordMapper.insert(inrecord);
176 190
                 if (insert1 <= 0) {
177 191
                     return ResultJSON.error(ResponseCodeMsg.CODE_EX, "入库失败");
@@ -200,6 +214,7 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
200 214
     /**
201 215
      * 拼接材料信息
202 216
      */
217
+    @Transactional(rollbackFor = Exception.class)
203 218
     public ProdMaster prodSplice(ImportModel importModel,String userId,String belongId,Material material,Customer customer,Customer customer1,String userName){
204 219
         ProdMaster prodMaster = new ProdMaster();
205 220
         prodMaster.setId(UUID.randomUUID().toString().replace("-", ""));
@@ -242,7 +257,8 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
242 257
     /**
243 258
      * 拼接入库记录
244 259
      */
245
-    public Inrecord inRecordSplice(ImportModel importModel,String userId,String belongId,Material material,Customer customer,Customer customer1,String userName){
260
+    @Transactional(rollbackFor = Exception.class)
261
+    public Inrecord inRecordSplice(ImportModel importModel,String userId,String belongId,Material material,Customer customer,Customer customer1,String userName,Ware ware,Stack stack){
246 262
         Inrecord inrecord = new Inrecord();
247 263
         inrecord.setAddId(userId);
248 264
         inrecord.setId(UUID.randomUUID().toString().replace("-", ""));
@@ -250,7 +266,7 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
250 266
         inrecord.setBelongId(belongId);
251 267
         inrecord.setInWareName(importModel.getWareName());
252 268
         inrecord.setInStackName(importModel.getStackName());
253
-        inrecord.setInLayerNo(importModel.getLayerNo());
269
+
254 270
         inrecord.setProdNo(importModel.getProdNo());
255 271
         inrecord.setOwnerCompany(customer.getId());
256 272
         inrecord.setReceivingCompany(customer1.getId());
@@ -270,12 +286,22 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
270 286
         }else{
271 287
             inrecord.setTallyPeople(userName);
272 288
         }
289
+        // 根据仓库id和垛位id查询最大层号
290
+        Integer maxLayerNo = storeChangeMapper.selectMaxLayerNoByWareAndStack(ware.getId(), stack.getId(),belongId);
291
+        Integer newLayerNo = null;
292
+        if (maxLayerNo == null) {
293
+            newLayerNo = 1; // 如果没有现有层号,则从第1层开始
294
+        } else {
295
+            newLayerNo = maxLayerNo + 1; // 否则在最大层号基础上加1
296
+        }
297
+        inrecord.setInLayerNo(String.valueOf(newLayerNo));
273 298
         return inrecord;
274 299
     }
275 300
 
276 301
     /**
277 302
      * 拼接库存信息
278 303
      */
304
+    @Transactional(rollbackFor = Exception.class)
279 305
     public StoreChange storeChangeSplice(ImportModel importModel,String userId,String belongId,ProdMaster prodMaster,String userName,Ware ware,Stack stack){
280 306
         StoreChange storeChange = new StoreChange();
281 307
         storeChange.setId(UUID.randomUUID().toString().replace("-", ""));
@@ -289,18 +315,28 @@ public class InrecordServiceImpl extends ServiceImpl<InrecordMapper, Inrecord> i
289 315
         storeChange.setAddTime(new Date());
290 316
         storeChange.setBelongId(belongId);
291 317
         storeChange.setCancelFlag("0");
292
-        storeChange.setLayerNo(importModel.getLayerNo());
293 318
         if(importModel.getInUser()!=null){
294 319
             storeChange.setAddName(importModel.getInUser());
295 320
         }else{
296 321
             storeChange.setAddName(userName);
297 322
         }
323
+// 根据仓库id和垛位id查询最大层号
324
+        Integer maxLayerNo = storeChangeMapper.selectMaxLayerNoByWareAndStack(ware.getId(), stack.getId(),belongId);
325
+        Integer newLayerNo = null;
326
+        if (maxLayerNo == null) {
327
+            newLayerNo = 1; // 如果没有现有层号,则从第1层开始
328
+        } else {
329
+            newLayerNo = maxLayerNo + 1; // 否则在最大层号基础上加1
330
+        }
331
+        storeChange.setLayerNo(newLayerNo.toString()); // 设置新的层号
332
+
298 333
         return storeChange;
299 334
     }
300 335
 
301 336
     /**
302 337
      * 拼接操作记录
303 338
      */
339
+    @Transactional(rollbackFor = Exception.class)
304 340
     public ChangeRecord changeRecordSplice(ImportModel importModel,String userId,String belongId,Customer customer,Customer customer1,String userName,Material material,ProdMaster prodMaster){
305 341
         ChangeRecord changeRecord = new ChangeRecord();
306 342
         changeRecord.setId(UUID.randomUUID().toString().replace("-", ""));

+ 292
- 0
sto/src/main/java/com/shinsoft/sto/service/impl/ware/StoreChangeServiceImpl.java Zobrazit soubor

@@ -1,5 +1,7 @@
1 1
 package com.shinsoft.sto.service.impl.ware;
2 2
 
3
+import com.alibaba.cloud.commons.lang.StringUtils;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 5
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 6
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5 7
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -9,12 +11,15 @@ import com.shinsoft.sto.model.system.ResponseCodeMsg;
9 11
 import com.shinsoft.sto.model.system.ResultJSON;
10 12
 import com.shinsoft.sto.service.ware.StoreChangeService;
11 13
 import org.springframework.stereotype.Service;
14
+import org.springframework.transaction.annotation.Transactional;
12 15
 
16
+import java.util.List;
13 17
 import java.util.Map;
14 18
 
15 19
 @Service
16 20
 public class StoreChangeServiceImpl extends ServiceImpl<StoreChangeMapper, StoreChange> implements StoreChangeService {
17 21
 
22
+
18 23
     @Override
19 24
     public ResultJSON query(int page, int rows, Map<String, Object> map) {
20 25
         try {
@@ -26,5 +31,292 @@ public class StoreChangeServiceImpl extends ServiceImpl<StoreChangeMapper, Store
26 31
             return ResultJSON.error(ResponseCodeMsg.CODE_EX, ex.getMessage());
27 32
         }
28 33
     }
34
+
35
+    @Override
36
+    @Transactional(rollbackFor = Exception.class)
37
+    public ResultJSON moveUp(String wareId, String stackId, String prodId, String layerNo, String belongId) {
38
+        try {
39
+            // 参数验证
40
+            if (StringUtils.isEmpty(wareId) || StringUtils.isEmpty(stackId) ||
41
+                    StringUtils.isEmpty(layerNo) || StringUtils.isEmpty(belongId)) {
42
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "必要参数不能为空");
43
+            }
44
+
45
+            // 查询目标层数据
46
+            StoreChange targetLayer = baseMapper.selectOne(new QueryWrapper<StoreChange>()
47
+                    .eq("ware_id", wareId)
48
+                    .eq("stack_id", stackId)
49
+                    .eq("layer_no", layerNo)
50
+                    .eq("cancel_flag", "0")
51
+                    .eq("belong_id", belongId));
52
+
53
+            if (targetLayer == null) {
54
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "目标层数据不存在");
55
+            }
56
+
57
+            // 查询上一层数据
58
+            StoreChange upperLayer = baseMapper.selectOne(new QueryWrapper<StoreChange>()
59
+                    .eq("ware_id", wareId)
60
+                    .eq("stack_id", stackId)
61
+                    .eq("layer_no", String.valueOf(Integer.parseInt(layerNo) + 1))
62
+                    .eq("cancel_flag", "0")
63
+                    .eq("belong_id", belongId));
64
+
65
+            if (upperLayer == null) {
66
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "上层数据不存在,无法上移");
67
+            }
68
+
69
+            // 交换层号
70
+            String originalTargetLayerNo = targetLayer.getLayerNo();
71
+            String originalUpperLayerNo = upperLayer.getLayerNo();
72
+
73
+            // 更新目标层为上一层的层号
74
+            StoreChange updateTarget = new StoreChange();
75
+            updateTarget.setId(targetLayer.getId());
76
+            updateTarget.setLayerNo(originalUpperLayerNo);
77
+            int updateResult1 = baseMapper.updateById(updateTarget);
78
+
79
+            // 更新上一层为目标层的层号
80
+            StoreChange updateUpper = new StoreChange();
81
+            updateUpper.setId(upperLayer.getId());
82
+            updateUpper.setLayerNo(originalTargetLayerNo);
83
+            int updateResult2 = baseMapper.updateById(updateUpper);
84
+
85
+            if (updateResult1 <= 0 || updateResult2 <= 0) {
86
+                throw new RuntimeException("上移失败");
87
+            }
88
+
89
+            return ResultJSON.success("上移成功");
90
+
91
+        } catch (NumberFormatException e) {
92
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, "层号格式错误");
93
+        } catch (Exception e) {
94
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, "层号交换失败: " + e.getMessage());
95
+        }
96
+    }
97
+
98
+
99
+    @Override
100
+    @Transactional(rollbackFor = Exception.class)
101
+    public ResultJSON moveDown(String wareId, String stackId, String prodId, String layerNo, String belongId) {
102
+        try {
103
+            // 参数验证
104
+            if (StringUtils.isEmpty(wareId) || StringUtils.isEmpty(stackId) ||
105
+                    StringUtils.isEmpty(layerNo) || StringUtils.isEmpty(belongId)) {
106
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "必要参数不能为空");
107
+            }
108
+
109
+            // 查询目标层数据
110
+            StoreChange targetLayer = baseMapper.selectOne(new QueryWrapper<StoreChange>()
111
+                    .eq("ware_id", wareId)
112
+                    .eq("stack_id", stackId)
113
+                    .eq("layer_no", layerNo)
114
+                    .eq("cancel_flag", "0")
115
+                    .eq("belong_id", belongId));
116
+
117
+            if (targetLayer == null) {
118
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "目标层数据不存在");
119
+            }
120
+
121
+            // 查询上一层数据
122
+            StoreChange upperLayer = baseMapper.selectOne(new QueryWrapper<StoreChange>()
123
+                    .eq("ware_id", wareId)
124
+                    .eq("stack_id", stackId)
125
+                    .eq("layer_no", String.valueOf(Integer.parseInt(layerNo) - 1))
126
+                    .eq("cancel_flag", "0")
127
+                    .eq("belong_id", belongId));
128
+
129
+            if (upperLayer == null) {
130
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "下层数据不存在,无法下移");
131
+            }
132
+
133
+            // 交换层号
134
+            String originalTargetLayerNo = targetLayer.getLayerNo();
135
+            String originalUpperLayerNo = upperLayer.getLayerNo();
136
+
137
+            // 更新目标层为上一层的层号
138
+            StoreChange updateTarget = new StoreChange();
139
+            updateTarget.setId(targetLayer.getId());
140
+            updateTarget.setLayerNo(originalUpperLayerNo);
141
+            int updateResult1 = baseMapper.updateById(updateTarget);
142
+
143
+            // 更新上一层为目标层的层号
144
+            StoreChange updateUpper = new StoreChange();
145
+            updateUpper.setId(upperLayer.getId());
146
+            updateUpper.setLayerNo(originalTargetLayerNo);
147
+            int updateResult2 = baseMapper.updateById(updateUpper);
148
+
149
+            if (updateResult1 <= 0 || updateResult2 <= 0) {
150
+                throw new RuntimeException("下移失败");
151
+            }
152
+
153
+            return ResultJSON.success("下移成功");
154
+
155
+        } catch (NumberFormatException e) {
156
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, "层号格式错误");
157
+        } catch (Exception e) {
158
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, "层号交换失败: " + e.getMessage());
159
+        }
160
+    }
161
+
162
+    @Override
163
+    @Transactional(rollbackFor = Exception.class)
164
+    public ResultJSON moveTop(String wareId, String stackId, String prodId, String layerNo, String belongId) {
165
+        try {
166
+            // 参数验证
167
+            if (StringUtils.isEmpty(wareId) || StringUtils.isEmpty(stackId) ||
168
+                    StringUtils.isEmpty(layerNo) || StringUtils.isEmpty(belongId)) {
169
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "必要参数不能为空");
170
+            }
171
+
172
+            // 验证层号是否为有效数字
173
+            int currentLayerNo;
174
+            try {
175
+                currentLayerNo = Integer.parseInt(layerNo);
176
+            } catch (NumberFormatException e) {
177
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "层号格式错误");
178
+            }
179
+
180
+            // 查询当前垛位的所有有效层数据,按层号升序排列
181
+            List<StoreChange> allLayers = baseMapper.selectList(
182
+                    new QueryWrapper<StoreChange>()
183
+                            .eq("ware_id", wareId)
184
+                            .eq("stack_id", stackId)
185
+                            .eq("cancel_flag", "0")
186
+                            .eq("belong_id", belongId)
187
+                            .orderByAsc("layer_no"));
188
+
189
+            if (allLayers.isEmpty()) {
190
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "该垛位无有效数据");
191
+            }
192
+
193
+            // 查找当前层的记录
194
+            StoreChange currentLayer = null;
195
+            int currentIndex = -1;
196
+            for (int i = 0; i < allLayers.size(); i++) {
197
+                if (currentLayerNo == Integer.parseInt(allLayers.get(i).getLayerNo())) {
198
+                    currentLayer = allLayers.get(i);
199
+                    currentIndex = i;
200
+                    break;
201
+                }
202
+            }
203
+
204
+            if (currentLayer == null) {
205
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "当前层数据不存在");
206
+            }
207
+
208
+            // 如果已经在顶层(最大层号),则无需移动
209
+            int maxLayerIndex = allLayers.size() - 1;
210
+            if (currentIndex == maxLayerIndex) {
211
+                return ResultJSON.success("已在顶层,无需移动");
212
+            }
213
+
214
+            // 开始批量更新层号:将目标层移到顶层,其他层号依次调整
215
+            for (int i = currentIndex; i < maxLayerIndex; i++) {
216
+                StoreChange layerToMove = allLayers.get(i + 1);
217
+                StoreChange update = new StoreChange();
218
+                update.setId(layerToMove.getId());
219
+                update.setLayerNo(String.valueOf(Integer.parseInt(layerToMove.getLayerNo()) - 1)); // 层号减1
220
+                int result = baseMapper.updateById(update);
221
+                if (result <= 0) {
222
+                    throw new RuntimeException("更新层号失败");
223
+                }
224
+            }
225
+
226
+            // 将目标层设置为新的最大层号
227
+            StoreChange updateCurrent = new StoreChange();
228
+            updateCurrent.setId(currentLayer.getId());
229
+            updateCurrent.setLayerNo(String.valueOf(Integer.parseInt(allLayers.get(maxLayerIndex).getLayerNo())));
230
+            int result = baseMapper.updateById(updateCurrent);
231
+            if (result <= 0) {
232
+                throw new RuntimeException("更新目标层号失败");
233
+            }
234
+
235
+            return ResultJSON.success("移动到顶层成功");
236
+
237
+        } catch (Exception e) {
238
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, "移动到顶层失败: " + e.getMessage());
239
+        }
240
+    }
241
+
242
+    @Override
243
+    @Transactional(rollbackFor = Exception.class)
244
+    public ResultJSON moveBottom(String wareId, String stackId, String prodId, String layerNo, String belongId) {
245
+        try {
246
+            // 参数验证
247
+            if (StringUtils.isEmpty(wareId) || StringUtils.isEmpty(stackId) ||
248
+                    StringUtils.isEmpty(layerNo) || StringUtils.isEmpty(belongId)) {
249
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "必要参数不能为空");
250
+            }
251
+
252
+            // 验证层号是否为有效数字
253
+            int currentLayerNo;
254
+            try {
255
+                currentLayerNo = Integer.parseInt(layerNo);
256
+            } catch (NumberFormatException e) {
257
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "层号格式错误");
258
+            }
259
+
260
+            // 查询当前垛位的所有有效层数据,按层号升序排列
261
+            List<StoreChange> allLayers = baseMapper.selectList(
262
+                    new QueryWrapper<StoreChange>()
263
+                            .eq("ware_id", wareId)
264
+                            .eq("stack_id", stackId)
265
+                            .eq("cancel_flag", "0")
266
+                            .eq("belong_id", belongId)
267
+                            .orderByAsc("layer_no"));
268
+
269
+            if (allLayers.isEmpty()) {
270
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "该垛位无有效数据");
271
+            }
272
+
273
+            // 查找当前层的记录
274
+            StoreChange currentLayer = null;
275
+            int currentIndex = -1;
276
+            for (int i = 0; i < allLayers.size(); i++) {
277
+                if (currentLayerNo == Integer.parseInt(allLayers.get(i).getLayerNo())) {
278
+                    currentLayer = allLayers.get(i);
279
+                    currentIndex = i;
280
+                    break;
281
+                }
282
+            }
283
+
284
+            if (currentLayer == null) {
285
+                return ResultJSON.error(ResponseCodeMsg.CODE_EX, "当前层数据不存在");
286
+            }
287
+
288
+            // 如果已经在底层(最小层号),则无需移动
289
+            if (currentIndex == 0) {
290
+                return ResultJSON.success("已在底层,无需移动");
291
+            }
292
+
293
+            // 开始批量更新层号:将目标层移到底层,其他层号依次调整
294
+            for (int i = currentIndex; i > 0; i--) {
295
+                StoreChange layerToMove = allLayers.get(i - 1);
296
+                StoreChange update = new StoreChange();
297
+                update.setId(layerToMove.getId());
298
+                update.setLayerNo(String.valueOf(Integer.parseInt(layerToMove.getLayerNo()) + 1)); // 层号加1
299
+                int result = baseMapper.updateById(update);
300
+                if (result <= 0) {
301
+                    throw new RuntimeException("更新层号失败");
302
+                }
303
+            }
304
+
305
+            // 将目标层设置为新的最小层号(1)
306
+            StoreChange updateCurrent = new StoreChange();
307
+            updateCurrent.setId(currentLayer.getId());
308
+            updateCurrent.setLayerNo("1"); // 设置为最小层号
309
+            int result = baseMapper.updateById(updateCurrent);
310
+            if (result <= 0) {
311
+                throw new RuntimeException("更新目标层号失败");
312
+            }
313
+
314
+            return ResultJSON.success("移动到底层成功");
315
+
316
+        } catch (Exception e) {
317
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, "移动到底层失败: " + e.getMessage());
318
+        }
319
+    }
320
+
29 321
 }
30 322
 

+ 4
- 0
sto/src/main/java/com/shinsoft/sto/service/main/WareService.java Zobrazit soubor

@@ -27,5 +27,9 @@ public interface WareService extends IService<Ware> {
27 27
     ResultJSON removeBatch(String userId, String ids);
28 28
 
29 29
     ResultJSON getWareOptions();
30
+
31
+    ResultJSON getWares(String wareId,String stackId,String belongId);
32
+
33
+
30 34
 }
31 35
 

+ 8
- 0
sto/src/main/java/com/shinsoft/sto/service/ware/StoreChangeService.java Zobrazit soubor

@@ -8,5 +8,13 @@ public interface StoreChangeService {
8 8
     ResultJSON query(int page,
9 9
                      int rows,
10 10
                      Map<String, Object> map);
11
+
12
+    ResultJSON moveUp(String wareId, String stackId, String prodId, String layerNo, String belongId);
13
+
14
+    ResultJSON moveDown(String wareId, String stackId, String prodId, String layerNo, String belongId);
15
+
16
+    ResultJSON moveTop(String wareId, String stackId, String prodId, String layerNo, String belongId);
17
+
18
+    ResultJSON moveBottom(String wareId, String stackId, String prodId, String layerNo, String belongId);
11 19
 }
12 20
 

Loading…
Zrušit
Uložit