#
Junjie
2024-08-30 48278d6051b6e58d648178964585d35ae000ec91
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//package com.zy.asrs.wms.common.interceptor;
//
//import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
//import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
//import org.apache.ibatis.executor.Executor;
//import org.apache.ibatis.mapping.BoundSql;
//import org.apache.ibatis.mapping.MappedStatement;
//import org.apache.ibatis.session.ResultHandler;
//import org.apache.ibatis.session.RowBounds;
//
//import java.sql.SQLException;
//
//
//public class StockSortInterceptor implements InnerInterceptor {
//
//    @Override
//    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
//        // 获取原始SQL语句
//        String originalSql = boundSql.getSql();
//        // 判断方法是否为特定的查询方法
//        if (isSpecificQueryMethod(ms)) {
//            // 添加排序逻辑
//            String sql = addSort(originalSql);
//            // 修改完成的sql 再设置回去
//            PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
//            mpBoundSql.sql(sql);
//        }
//    }
//
//    private boolean isSpecificQueryMethod(MappedStatement ms) {
//        // 检查MappedStatement的ID以判断是否为特定的查询方法
//        String statementId = ms.getId();
//        return statementId.equals("com.zy.asrs.wms.asrs.mapper.LocDetlMapper.getStock");
//    }
//
//    private String addSort(String originalSql) {
//        // 根据需要添加排序逻辑
//        return originalSql + " ORDER BY" + isQueue();
//    }
//
//    private String isQueue() {
//        //先进先出:在查询库存记录时,排序字段按照man_loc_detl表的createTime升序排序
//        return " create_time ASC";
//    }
//
//    private String isFree() {
//        //设备空闲情况:优先查询空闲的设备,在有空闲的设备时,从空闲的设备对应的货架上查询
//        //TODO
//        return " create_time ASC";
//    }
//
//    private String isBarcodeDesc() {
//        //托盘最大值降序:就是按照托盘号降序
//        return " barcode DESC";
//    }
//
//    private String isBarcodeAsc() {
//        //托盘最大值升序:就是按照托盘号升序
//        return " barcode ASC";
//    }
//
//    private String isEven() {
//        // 楼层均匀分布:
//        //TODO
//        return " barcode ASC";
//    }
//
//}