czt
2026-02-26 181252cf8ba494441b1fdb3873da7afa90ff0813
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutConfService.java
@@ -1,9 +1,12 @@
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.repository.InoutConfRepository;
import com.fzzy.igds.repository.InoutSysConfRepository;
import com.fzzy.igds.domain.Dept;
import com.fzzy.igds.mapper.InoutConfMapper;
import com.fzzy.igds.mapper.InoutSysConfMapper;
import com.fzzy.igds.domain.InoutConf;
import com.fzzy.igds.domain.InoutSysConf;
import com.fzzy.igds.utils.ContextUtil;
@@ -14,6 +17,7 @@
import com.ruoyi.system.service.ISysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@@ -29,15 +33,56 @@
    @Resource
    private ISysDeptService iSysDeptService;
    @Resource
    private InoutSysConfRepository inoutSysConfRepository;
    private CoreDeptService deptService;
    @Resource
    private InoutConfRepository inoutConfRepository;
    private InoutConfMapper inoutConfMapper;
    @Resource
    private InoutSysConfMapper inoutSysConfMapper;
    @Resource
    private RedisCache redisCache;
    /*--------------- 出入库流程 ---------------*/
    /**
     * JPA-查询流程配置
     * 根据条件查询流程信息
     *
     * @param deptId
     * @param parentId
     * @return
     */
    public List<InoutSysConf> listInoutSysConf(String deptId, String parentId) {
        QueryWrapper<InoutSysConf> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(deptId)) {
            queryWrapper.eq("dept_id", deptId);
        }
        if (StringUtils.isNotBlank(parentId)) {
            queryWrapper.likeRight("dept_id", parentId);
        }
        return inoutSysConfMapper.selectList(queryWrapper);
    }
    /**
     * 根据条件查询流程信息
     *
     * @param deptId
     * @return
     */
    public InoutSysConf getInoutSysConf(String deptId) {
        List<InoutSysConf> list = listInoutSysConf(deptId, null);
        if (null == list || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
    /**
     * 查询流程配置
     *
     * @return
     */
@@ -46,15 +91,13 @@
        SysUser user = ContextUtil.getLoginUser();
        SysDept userDept = iSysDeptService.selectDeptById(user.getDeptId());
        if (Constant.DEPT_TYPE_20.equals(userDept.getType())) {
            return inoutSysConfRepository.getDataById(ContextUtil.subDeptId(user));
        }else {
            return inoutSysConfRepository.getDataByParentId(user.getDeptId() + "%");
            return this.listInoutSysConf(ContextUtil.subDeptId(user), null);
        } else {
            return this.listInoutSysConf(null, user.getDeptId() + "%");
        }
    }
    /**
     *
     *
     * @param companyId
     * @param deptId
     */
@@ -66,19 +109,18 @@
        inoutSysConf.setProgressOut("REGISTER-WEIGHT_EMPTY-HANDLE-WEIGHT_FULL-RECORD");
        this.saveSysConfData(inoutSysConf);
        this.flushInoutSysConfCache(inoutSysConf);
        this.flushInoutSysConfCache();
    }
    /**
     *
     * @param deptId
     */
    public void delSysConfData(String deptId) {
        inoutSysConfRepository.deleteById(deptId);
        inoutSysConfMapper.deleteById(deptId);
    }
    /**
     * JPA-保存流程配置
     * 保存流程配置
     *
     * @param data
     * @return
@@ -87,20 +129,34 @@
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
        inoutSysConfRepository.save(data);
        this.flushInoutSysConfCache(data);
        if (StringUtils.isEmpty(data.getUpdateBy())) {
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
            data.setUpdateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            inoutSysConfMapper.insert(data);
        } else {
            data.setUpdateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            inoutSysConfMapper.update(data, new UpdateWrapper<InoutSysConf>().eq("dept_id", data.getDeptId()));
        }
        this.flushInoutSysConfCache();
    }
    /**
     * 设置缓存
     *
     * @param data
     */
    public void flushInoutSysConfCache(InoutSysConf data) {
        String key = RedisConst.buildKey(data.getDeptId(), Constant.CACHE_INOUT_SYS_CONF);
        redisCache.setCacheObject(key, data);
    public void flushInoutSysConfCache() {
        List<InoutSysConf> list = listInoutSysConf(null,null);
        if(null == list || list.isEmpty()){
            return;
        }
        for (InoutSysConf conf : list) {
            String key = RedisConst.buildKey(conf.getDeptId(), Constant.CACHE_INOUT_SYS_CONF);
            redisCache.setCacheObject(key, conf);
        }
    }
    /**
@@ -112,77 +168,105 @@
     */
    public InoutSysConf getCacheInoutSysConf(String companyId, String deptId) {
        String key = RedisConst.buildKey(deptId, Constant.CACHE_INOUT_SYS_CONF);
        return (InoutSysConf) redisCache.getCacheObject(key);
        InoutSysConf conf = (InoutSysConf) redisCache.getCacheObject(key);
        if (null == conf) {
            conf = getInoutSysConf(deptId);
            flushInoutSysConfCache();
        }
        return conf;
    }
    /*--------------- 出入库设备 ---------------*/
    /**
     * JPA-查询设备配置
     * 查询设备配置
     *
     * @return
     */
    public List<InoutConf> getInoutConfList(String companyId, String deptId) {
        QueryWrapper<InoutConf> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        if (StringUtils.isEmpty(deptId)) {
            deptId = ContextUtil.subDeptId(null);
        queryWrapper.eq("company_id", companyId);
        if (StringUtils.isNotEmpty(deptId)) {
            queryWrapper.eq("dept_id", deptId);
        }
        return inoutConfRepository.getInoutConfList(companyId, deptId);
        return inoutConfMapper.selectList(queryWrapper);
    }
    /**
     * JPA-保存设备配置
     * 保存设备配置
     *
     * @param data
     * @return
     */
    public String saveData(InoutConf data) {
        if (0 == data.getInOrder()) {
            data.setInOrder(1);
        }
        if (StringUtils.isEmpty(data.getSort())) {
            data.setSort("1");
        }
        if (StringUtils.isEmpty(data.getId())) {
            data.setId(ContextUtil.generateId());
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
        }
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(null));
        }
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
        inoutConfRepository.save(data);
        if (0 == data.getInOrder()) {
            data.setInOrder(1);
        }
        if (StringUtils.isEmpty(data.getSort())) {
            data.setSort("1");
        }
        if (StringUtils.isBlank(data.getId())) {
            data.setId(ContextUtil.generateId());
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
            data.setUpdateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            inoutConfMapper.insert(data);
        } else {
            data.setUpdateBy(ContextUtil.getLoginUserName());
            data.setUpdateTime(new Date());
            inoutConfMapper.updateById(data);
        }
        return null;
    }
    /**
     * JPA-删除设备配置
     * 删除设备配置
     *
     * @param data
     * @return
     */
    public String delData(InoutConf data) {
        inoutConfRepository.delete(data);
        inoutConfMapper.deleteById(data);
        return null;
    }
    /**
     * 设置缓存
     *
     * @param companyId
     * @param deptId
     */
    public void flushInoutConfCache(String companyId, String deptId) {
        List<InoutConf> list = this.getInoutConfList(companyId, deptId);
        String key = RedisConst.buildKey(companyId, Constant.CACHE_INOUT_CONF_LIST, deptId);
        redisCache.setCacheObject(key, list);
    public void flushInoutConfCache(String companyId) {
        List<Dept> depts = deptService.listDept(null, companyId, null);
        if(null == depts || depts.isEmpty()){
            return;
        }
        List<InoutConf> inoutConfList;
        for (Dept dept : depts) {
            inoutConfList = this.getInoutConfList(companyId, dept.getId());
            if(null == inoutConfList || inoutConfList.isEmpty()){
                continue;
            }
            String key = RedisConst.buildKey(companyId, Constant.CACHE_INOUT_CONF_LIST, dept.getId());
            redisCache.setCacheObject(key, inoutConfList);
        }
    }
    /**
     * 获取缓存
     *
     * @param companyId
     * @param deptId
     * @return
@@ -190,7 +274,7 @@
    public List<InoutConf> getCacheInoutConf(String companyId, String deptId) {
        String key = RedisConst.buildKey(companyId, Constant.CACHE_INOUT_CONF_LIST, deptId);
        List<InoutConf> list = redisCache.getCacheObject(key);
        if(null == list){
        if (null == list) {
            list = this.getInoutConfList(companyId, deptId);
            redisCache.setCacheObject(key, list);
        }
@@ -199,6 +283,7 @@
    /**
     * 获取缓存
     *
     * @param companyId
     * @param deptId
     * @param confId
@@ -210,7 +295,7 @@
        }
        List<InoutConf> list = getCacheInoutConf(companyId, deptId);
        if (null == list  || list.isEmpty()) {
        if (null == list || list.isEmpty()) {
            return null;
        }
        for (InoutConf inoutConf : list) {
@@ -223,11 +308,15 @@
    /**
     * 更新出入库设备状态
     *
     * @param ip
     * @param port
     * @param status
     */
    public void updateInoutConfStatus(String ip, Integer port, String status) {
        inoutConfRepository.updateInoutConfStatus(status, ip, port);
        UpdateWrapper<InoutConf> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("ip", ip).eq("port", port).set("status", status);
        inoutConfMapper.update(null, updateWrapper);
    }
}