sgj
2026-03-27 1eddf64a7104dcd06065e8ac309eebc42c24fb05
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotConfService.java
@@ -1,14 +1,18 @@
package com.fzzy.igds.service;
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.DepotConf;
import com.fzzy.igds.repository.DepotConfRepository;
import com.fzzy.igds.mapper.DepotConfMapper;
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;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
@@ -26,14 +30,12 @@
public class DepotConfService {
    @Resource
    private DepotConfRepository depotConfRepository;
    @Resource
    private DepotService depotService;
    private DepotConfMapper depotConfMapper;
    @Resource
    private RedisCache redisCache;
    /**
     * jpa查询配置信息
     * 查询配置信息
     *
     * @param companyId
     * @param deptId
@@ -44,14 +46,58 @@
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        if (StringUtils.isEmpty(deptId)) {
            deptId = ContextUtil.subDeptId(null);
        QueryWrapper<DepotConf> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", companyId);
        if (StringUtils.isNotBlank(deptId)) {
            queryWrapper.eq("dept_id", deptId);
        }
        return depotConfRepository.getDepotConf(companyId, deptId);
        return depotConfMapper.selectList(queryWrapper);
    }
    /**
     * jpa更新保存配置信息
     * 根据用户类型查询配置信息
     * @return
     */
    public List<DepotConf> getConfListByUserType() {
        //获取当前登录人
        SysUser user = ContextUtil.getLoginUser();
        QueryWrapper<DepotConf> queryWrapper = new QueryWrapper<>();
        //监管用户-默认查看所有信息不增加条件
        if (Constant.USER_TYPE_10.equals(user.getUserType())) {
            queryWrapper.eq("company_id", user.getCompanyId());
            //不增加条件
        }
        //库区用户,如果是公司用户可以查看公司下属所有库区,如果为当前库区只查询当前库区
        if (Constant.USER_TYPE_30.equals(user.getUserType())) {
           queryWrapper.eq("company_id", user.getCompanyId());
            if (ContextUtil.isDepotUser(user.getDeptId() + "")) {
                queryWrapper.eq("dept_id", user.getDeptId() + "");
            } else {
                queryWrapper.likeRight("dept_id", user.getDeptId() + "");
            }
        }
        //银行用户,根据合同查询银行下所有库区
        if (Constant.USER_TYPE_20.equals(user.getUserType())) {
            if(StringUtils.isBlank(user.getUserData())) return null;
            queryWrapper.eq("d.company_id", user.getCompanyId());
            queryWrapper.eq("c.pledge_bank", user.getUserData());
            return depotConfMapper.selectByBank(queryWrapper);
        }
        return depotConfMapper.selectList(queryWrapper);
    }
    /**
     * 更新保存配置信息
     *
     * @param conf
     */
@@ -61,23 +107,31 @@
        }
        if (StringUtils.isEmpty(conf.getDeptId())) {
            conf.setDeptId(ContextUtil.subDeptId(null));
        }
        if (null == conf.getUpdateBy()) {
            conf.setCreateBy(ContextUtil.getLoginUserName());
            conf.setCreateTime(new Date());
            conf.setUpdateBy(ContextUtil.getLoginUserName());
            conf.setUpdateTime(new Date());
            depotConfMapper.insert(conf);
        } else {
            conf.setUpdateBy(ContextUtil.getLoginUserName());
            conf.setUpdateTime(new Date());
            depotConfMapper.update(conf, new UpdateWrapper<DepotConf>().eq("depot_id", conf.getDepotId()));
        }
        conf.setUpdateBy(ContextUtil.getLoginUserName());
        conf.setUpdateTime(new Date());
        depotConfRepository.save(conf);
        flushConfCache(conf.getCompanyId());
    }
    /**
     * jpa删除配置信息
     * 删除配置信息
     *
     * @param conf
     * @return
     */
    public void deleteDepotConf(DepotConf conf) {
        depotConfRepository.delete(conf);
        depotConfMapper.deleteById(conf);
        //删除配置缓存
        this.delCacheDepotConf(conf, conf.getCompanyId());
@@ -91,14 +145,8 @@
     */
    public void setCacheDepotConf(List<DepotConf> list, String companyId) {
        if (null != list) {
            Depot depot;
            String key;
            for (DepotConf depotConf : list) {
                depot = depotService.getCacheDepot(companyId, depotConf.getDepotId());
                if (null != depot) {
                    depotConf.setDepotName(depot.getName());
                    depotConf.setDepotType(depot.getDepotType());
                }
                key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotConf.getDepotId());
                redisCache.setCacheObject(key, depotConf);
            }
@@ -199,30 +247,11 @@
        String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotId);
        DepotConf depotConf = redisCache.getCacheObject(key);
        if (null == depotConf) {
            depotConf = depotConfRepository.getDepotConfByDepotId(companyId, depotId);
            depotConf = depotConfMapper.selectById(depotId);
            redisCache.setCacheObject(key, depotConf);
        }
        return depotConf;
    }
    /**
     * 根据仓库列表,自动生成仓库配置信息
     * @param companyId
     */
    private void addConfByDepot(String companyId) {
        List<Depot> list = depotService.getCacheDepotList(companyId);
        if (null == list || list.isEmpty()) {
            return;
        }
        DepotConf conf;
        for (Depot depot : list) {
            conf = new DepotConf();
            conf.setDepotId(depot.getId());
            conf.setCompanyId(depot.getCompanyId());
            conf.setDeptId(depot.getDeptId());
            this.saveConf(conf);
        }
    }
    /**
@@ -234,7 +263,7 @@
            companyId = ContextUtil.getCompanyId();
        }
        List<DepotConf> list = depotConfRepository.getDepotConfByCompanyId(companyId);
        List<DepotConf> list = this.getConfList(companyId, null);
        this.setCacheDepotConf(list, companyId);
    }
@@ -244,6 +273,10 @@
     * @param freq
     */
    public void updateFreq(String freq) {
        depotConfRepository.updateGrainFreq(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), freq);
        UpdateWrapper<DepotConf> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("dept_id", ContextUtil.subDeptId(null)).set("grain_freq", freq);
        depotConfMapper.update(null, updateWrapper);
    }
}