sgj
2026-03-24 deb8a2c32ba0cb7a88819b54d720418cdc2f7ebb
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotService.java
@@ -2,11 +2,14 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.constant.RedisConst;
import com.fzzy.igds.domain.Depot;
import com.fzzy.igds.domain.DepotStore;
import com.fzzy.igds.domain.Dept;
import com.fzzy.igds.mapper.DepotMapper;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
@@ -32,6 +35,9 @@
    private RedisCache redisCache;
    @Resource
    private DepotStoreService depotStoreService;
    @Resource
    private CoreDeptService coreDeptService;
    /**
     * 查询库区下仓库列表
@@ -61,6 +67,51 @@
        }
        return depotMapper.selectList(queryWrapper);
    }
    /**
     * 根据用户类型查询所有仓库,作为dorado的map回显使用
     *
     * @param deptId
     * @author sgj
     * @since 2026/03/24
     */
    public List<Depot> getDepotByUserType(String deptId) {
        List<Depot> result = new ArrayList<>();
        if (StringUtils.isNotBlank(deptId)) {
            //查公司下所有库区
            result = this.getData(null, deptId, false);
            return result;
        }
        //获取当前登录人
        SysUser user = ContextUtil.getLoginUser();
        if (Constant.USER_TYPE_10.equals(user.getUserType())) {
            //监管用户,直接查询组织下所有库区
            result = this.getData(user.getCompanyId(), null, false);
            return result;
        }
        if (Constant.USER_TYPE_20.equals(user.getUserType())) {
            //银行用户,根据合同查询银行下所有库区
            List<Dept> deptByBank = coreDeptService.getDeptByBank(user.getUserData());
            for (Dept dept : deptByBank) {
                result.addAll(this.getData(null, dept.getId(), false));
            }
            return result;
        }
        if (Constant.USER_TYPE_30.equals(user.getUserType())) {
            //库区用户
            if (ContextUtil.isDepotUser(user.getDeptId() + "")) {
                //查询用户所属库区
                result = this.getData(null, user.getDeptId() + "", false);
            } else {
                //查询用户所属公司下所有库区
                result = this.getData(user.getCompanyId(), null, false);
            }
            return result;
        }
        return result;
    }
    /**
@@ -130,7 +181,6 @@
        lastData.setUpdateTime(new Date());
        lastData.setUpdateBy("系统定时统计");
        lastData.setDepotStatus(depot.getDepotStatus());
        lastData.setFoodVariety(depot.getFoodVariety());
        lastData.setFoodLevel(depot.getFoodLevel());
@@ -138,7 +188,6 @@
        lastData.setFoodLocationId(depot.getFoodLocationId());
        lastData.setFoodType(depot.getFoodType());
        lastData.setFoodYear(depot.getFoodYear());
        lastData.setStorageReal(depot.getStorageReal());
        lastData.setCreateTime(new Date()); //设置为最新时间,其他系统可以通过此时间查询数据是否有更新修改,同步到省平台接口。
@@ -250,13 +299,15 @@
            companyId = ContextUtil.getCompanyId();
        }
        List<Depot> list = new ArrayList<>();
        List<Depot> resultList = new ArrayList<>();
        String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT) + "*";
        Collection<String> keys = redisCache.keys(patten);
        if (null != keys) {
            for (String key : keys) {
                if (null == redisCache.getCacheObject(key)) {
                    list = new ArrayList<>();
                    break;
                }
                list.add((Depot) redisCache.getCacheObject(key));
            }
        }
@@ -267,27 +318,16 @@
            setCacheDepotList(list, companyId);
        }
        if (!list.isEmpty()) {
            //重新排序
            //检查数据是否为空
            for (Depot depot : list) {
                if( null!=depot){
                    resultList.add(depot);
                }
            }
            boolean hasNullOrderNum = true;
            // 检查是否有仓库的排序号为空
            for (Depot depot : resultList) {
                if ( null== depot.getOrderNum()) {
                    hasNullOrderNum = true;
                    break;
            for (Depot depot : list) {
                if (null == depot.getOrderNum()) {
                    //排序号为空,则默认给1
                    depot.setOrderNum(1);
                }
            }
            // 如果存在排序号为空的仓库,则不进行排序
            if (!hasNullOrderNum) {
                Collections.sort(resultList, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
            }
            Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
        }
        return resultList;
        return list;
    }
    /**
@@ -302,8 +342,6 @@
            return null;
        }
        List<Depot> list = getCacheDepotList(companyId);
        List<Depot> resultList = new ArrayList<>();
        if (null == list || list.isEmpty()) {
            return null;
        }
@@ -313,28 +351,11 @@
                result.add(depot);
            }
        }
        if (!list.isEmpty()) {
        if (!result.isEmpty()) {
            //重新排序
            //检查数据是否为空
            for (Depot depot : list) {
                if( null!=depot){
                    resultList.add(depot);
                }
            }
            boolean hasNullOrderNum = true;
            // 检查是否有仓库的排序号为空
            for (Depot depot : resultList) {
                if ( null== depot.getOrderNum()) {
                    hasNullOrderNum = true;
                    break;
                }
            }
            // 如果存在排序号为空的仓库,则不进行排序
            if (!hasNullOrderNum) {
                Collections.sort(resultList, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
            }
            Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
        }
        return resultList;
        return result;
    }
    /**