jiazx0107
2026-02-08 e7ab049344b954b044fc474992c378fcbbeeba33
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/QuantityService.java
@@ -1,13 +1,20 @@
package com.fzzy.igds.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.igds.constant.RedisConst;
import com.fzzy.igds.data.QuantityParam;
import com.fzzy.igds.domain.Quantity;
import com.fzzy.igds.domain.QuantityConf;
import com.fzzy.igds.repository.QuantityConfRepository;
import com.fzzy.igds.mapper.QuantityConfMapper;
import com.fzzy.igds.mapper.QuantityMapper;
import com.fzzy.igds.utils.ContextUtil;
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;
@@ -24,12 +31,82 @@
public class QuantityService {
    @Resource
    private QuantityConfRepository quantityConfRepository;
    private QuantityConfMapper quantityConfMapper;
    @Resource
    private RedisCache redisCache;
    @Resource
    private QuantityMapper  quantityMapper;
    /**
     * JPA - 查询配置信息,根据库区编码获取
     * 分页查询质量检测数据
     *
     * @author sgj
     * @date 2025/12/18
     */
    public void listPageQuantity(Page<Quantity> page, QuantityParam param) {
        QueryWrapper<Quantity> queryWrapper = new QueryWrapper<>();
        param.setCompanyId(ContextUtil.getCompanyId());
        queryWrapper.eq("company_id", param.getCompanyId());
        //库区检索
        if (StringUtils.isNotBlank(param.getDeptId())) {
            queryWrapper.like("dept_id", param.getDeptId());
        }
        //仓库检索
        if (StringUtils.isNotBlank(param.getDepotId())) {
            queryWrapper.eq("depot_id", param.getDepotId());
        }
        //时间检索
        if(param.getStart() != null){
            queryWrapper.ge("receive_date", param.getStart());
        }
        if(param.getEnd() != null){
            queryWrapper.le("receive_date", param.getEnd());
        }
        queryWrapper.orderByAsc("receive_date");
        quantityMapper.selectPage(page, queryWrapper);
    }
    /**
     * 查询数据列表
     * @param depotId
     * @param limit    查询条数
     * @return
     */
    public List<Quantity> getQuantityList(String depotId, Integer limit) {
        if (StringUtils.isEmpty(depotId)) {
            return null;
        }
        QueryWrapper<Quantity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("depot_id", depotId);
        queryWrapper.orderByDesc("receive_date");
        queryWrapper.last("LIMIT " + limit);
        return quantityMapper.selectList(queryWrapper);
    }
    /**
     * 保存数据
     *
     * @param data
     */
    public void saveData(Quantity data) {
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
        if(StringUtils.isBlank(data.getCreateBy())){
            data.setCreateBy(ContextUtil.getLoginUserName());
            data.setCreateTime(new Date());
        }
        quantityMapper.insert(data);
    }
    /**
     * 查询配置信息,根据库区编码获取
     *
     * @param companyId
     * @param deptId
@@ -39,15 +116,22 @@
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        if (StringUtils.isEmpty(deptId)) {
            deptId = ContextUtil.subDeptId(null);
        }
        return quantityConfRepository.listQuantityConf(companyId, deptId);
        QueryWrapper<QuantityConf> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", companyId);
        if (StringUtils.isNotBlank(deptId)) {
            queryWrapper.eq("dept_id", deptId);
        }
        queryWrapper.orderByAsc("order_num");
        return quantityConfMapper.selectList(queryWrapper);
    }
    /**
     * JPA - 查询配置信息,根据组织编码获取
     * - 查询配置信息,根据组织编码获取
     *
     * @param companyId
     * @return
@@ -57,11 +141,11 @@
            companyId = ContextUtil.getCompanyId();
        }
        return quantityConfRepository.listQuantityConf(companyId);
        return this.getConfList(companyId, null);
    }
    /**
     * JPA - 更新保存数据
     * - 更新保存数据
     *
     * @param conf
     */
@@ -69,41 +153,50 @@
        if (StringUtils.isEmpty(conf.getDepotId())) {
            return;
        }
        if (StringUtils.isEmpty(conf.getCompanyId())) {
        if (StringUtils.isBlank(conf.getCompanyId())) {
            conf.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(conf.getDeptId())) {
        if (StringUtils.isBlank(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());
            quantityConfMapper.insert(conf);
        } else {
            conf.setUpdateBy(ContextUtil.getLoginUserName());
            conf.setUpdateTime(new Date());
            quantityConfMapper.update(conf, new UpdateWrapper<QuantityConf>().eq("depot_id", conf.getDepotId()));
        }
        conf.setUpdateBy(ContextUtil.getLoginUserName());
        conf.setUpdateTime(new Date());
        quantityConfRepository.save(conf);
        //刷新缓存
        setCacheQuantityConf(conf);
        this.setCacheQuantityConf(conf);
    }
    /**
     * JPA- 更新配置咋混个太
     * 更新信息
     *
     * @param conf
     */
    public void updateQuantityConfBySn(QuantityConf conf) {
        //更新状态
        quantityConfRepository.updateConfStatus(conf.getIp(), conf.getPort(), conf.getStatus(), conf.getSn());
        setCacheQuantityConf(conf);
        UpdateWrapper<QuantityConf> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("sn", conf.getSn()).set("ip", conf.getIp()).set("port", conf.getPort()).set("status", conf.getStatus());
        quantityConfMapper.update(null, updateWrapper);
        this.setCacheQuantityConf(conf);
    }
    /**
     * JPA - 删除数据
     * - 删除数据
     *
     * @param conf
     * @return
     */
    public String delQuantityConf(QuantityConf conf) {
        quantityConfRepository.delete(conf);
        quantityConfMapper.deleteById(conf);
        //删除配置信息
        flushConfCache(conf.getCompanyId(), conf.getDeptId());