czt
2025-12-25 9e8d09ec8c825872f732f98cad402cbc6a85959a
fzzy-igdss-web/src/main/java/com/fzzy/group/manager/GroupManager.java
@@ -1,17 +1,18 @@
package com.fzzy.group.manager;
import com.fzzy.common.manager.CommonManager;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.data.ChartPie;
import com.fzzy.igds.data.GisData;
import com.fzzy.igds.domain.Depot;
import com.fzzy.igds.domain.Dept;
import com.fzzy.igds.domain.DicArea;
import com.fzzy.igds.service.CoreDeptService;
import com.fzzy.igds.service.DepotService;
import com.fzzy.igds.service.DicAreaService;
import com.fzzy.igds.constant.FoodVariety;
import com.fzzy.igds.constant.RespCodeEnum;
import com.fzzy.igds.data.*;
import com.fzzy.igds.domain.*;
import com.fzzy.igds.service.*;
import com.fzzy.igds.utils.ContextUtil;
import com.fzzy.igds.utils.DateUtil;
import com.fzzy.igds.utils.NumberUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -28,11 +29,21 @@
public class GroupManager {
    @Resource
    private CommonManager commonManager;
    @Resource
    private DicAreaService dicAreaService;
    @Resource
    private CoreDeptService deptService;
    @Resource
    private DepotService depotService;
    @Resource
    private CoreCompanyService coreCompanyService;
    @Resource
    private InoutRecordService inoutRecordService;
    @Resource
    private EventInfoService eventInfoService;
    @Resource
    private SnapRecordService snapRecordService;
    /**
     * 获取省及下属市州集合
@@ -115,12 +126,225 @@
    }
    /**
     * 统计gis数据,只统计登录人下属的数据统计
     * 获取库区封装信息
     * @param companyId
     * @return
     */
    public GisData getGisData() {
    public List<GroupDeptData> getDeptData(String companyId) {
        GisData gisData = new GisData();
        List<GroupDeptData> list = new ArrayList<>();
        GroupDeptData deptData;
        List<Dept> deptList = deptService.getDeptData();
        if (null != deptList && !deptList.isEmpty()) {
            List<Depot> depotList;
            for (Dept dept : deptList) {
                deptData = new GroupDeptData();
                deptData.setDeptId(dept.getId());
                deptData.setDeptName(dept.getKqmc());
                deptData.setCode(dept.getXzqhdm());
                deptData.setCounty(dept.getXzqhmc());
                deptData.setJd(dept.getJd());
                deptData.setWd(dept.getWd());
                //统计仓库数
                depotList = depotService.getCacheDepotList(dept.getCompanyId(), dept.getId());
                if (null != depotList && !depotList.isEmpty()) {
                    for (Depot depot : depotList) {
                        deptData.setDepotNumber(deptData.getDepotNumber() + 1);
                        if(StringUtils.isNotBlank(depot.getPledgeBank())){
                            deptData.setDepotBankNumber(deptData.getDepotBankNumber() + 1);
                        }
                        if(null == depot.getStorageReal()){
                            depot.setStorageReal(0.0);
                        }
                        deptData.setStorageNum(deptData.getStorageNum() + depot.getStorageReal()/1000);
                    }
                }
                //统计出入库数量
                InoutParam inoutParam = new InoutParam();
                inoutParam.setDeptId(dept.getId());
                inoutParam.setCompanyId(companyId);
                inoutParam.setStart(DateUtil.getCurZero(new Date()));
                inoutParam.setEnd(DateUtil.getNextZero(new Date()));
                List<InoutRecord> inoutRecords = inoutRecordService.listInout(inoutParam);
                if (null != inoutRecords && !inoutRecords.isEmpty()) {
                    for (InoutRecord inoutRecord : inoutRecords) {
                        if (Constant.TYPE_IN.equals(inoutRecord.getType())) {
                            deptData.setInNum(deptData.getInNum() + 1);
                        }
                        if (Constant.TYPE_OUT.equals(inoutRecord.getType())){
                            deptData.setOutNum(deptData.getOutNum() + 1);
                        }
                    }
                }
                list.add(deptData);
            }
        }
        return list;
    }
    /**
     * 大屏首页统计信息:企业数、库区数、仓库数、质押仓数、散粮及成品粮数、分品种库存数
     *
     * @param param
     * @return
     */
    public PageResponse<GroupIndexData> getGroupIndexData(IgdsBaseParam param) {
        GroupIndexData indexData = new GroupIndexData();
        //企业数
        Integer companyNum = coreCompanyService.getCompanyNum(param.getCompanyId());
        indexData.setCompanyNum(companyNum);
        //库区数
        List<Dept> deptList = deptService.listDept(null, param.getCompanyId(), null);
        if (null != deptList) {
            indexData.setDeptNum(deptList.size());
        }
        ///仓库数及质押仓库数
        List<Depot> depotList = depotService.getCacheDepotList(param.getCompanyId());
        if (null != depotList) {
            Double foodSum = 0.0;
            Double packFoodSum = 0.0;
            indexData.setDepotNum(depotList.size());
            //用于统计分品种库存
            LinkedHashMap<String, Double> varietyMap = new LinkedHashMap<>();
            for (Depot depot : depotList) {
                if(StringUtils.isNotBlank(depot.getPledgeBank())){
                    indexData.setDepotBankNum(indexData.getDepotBankNum() + 1);
                }
                if(null == depot.getStorageReal()){
                    depot.setStorageReal(0.0);
                }
                if(StringUtils.isNotBlank(depot.getStoreType()) && "2".equals(depot.getStoreType())){
                    packFoodSum += depot.getStorageReal()/1000;
                }else {
                    foodSum += depot.getStorageReal()/1000;
                }
                if(depot.getStorageReal() > 0){
                    if(StringUtils.isBlank(depot.getFoodVariety())){
                        //设置为其他品类
                        depot.setFoodVariety("9999000");
                    }
                    varietyMap.putIfAbsent(depot.getFoodVariety(), 0.000);
                    varietyMap.put(depot.getFoodVariety(), varietyMap.get(depot.getFoodVariety()) + NumberUtil.keepPrecision(depot.getStorageReal()/1000, 3));
                }
            }
            for (String mapKey : varietyMap.keySet()) {
                if (varietyMap.get(mapKey) <= 0) {
                    continue;
                }
                indexData.getXaxis().add(FoodVariety.getMsg(mapKey));
                indexData.getSeriesData().add(new DecimalFormat("0.000").format(varietyMap.get(mapKey)));
            }
            indexData.setFoodSum(new DecimalFormat("0.000").format(foodSum));
            indexData.setPackFoodSum(new DecimalFormat("0.000").format(packFoodSum));
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, indexData);
    }
    /**
     * 大屏首页-库区信息统计
     * @param param
     * @return
     */
    public PageResponse<List<GroupDeptData>> indexDeptList(IgdsBaseParam param) {
        List<GroupDeptData> list = new ArrayList<>();
        GroupDeptData deptData;
        List<Dept> deptList = deptService.getDeptData();
        if (null != deptList && !deptList.isEmpty()) {
            List<Depot> depotList;
            for (Dept dept : deptList) {
                deptData = new GroupDeptData();
                deptData.setDeptId(dept.getId());
                deptData.setDeptName(dept.getKqmc());
                deptData.setCode(dept.getXzqhdm());
                deptData.setCounty(dept.getXzqhmc());
                deptData.setJd(dept.getJd());
                deptData.setWd(dept.getWd());
                //统计仓库数
                depotList = depotService.getCacheDepotList(dept.getCompanyId(), dept.getId());
                if (null != depotList && !depotList.isEmpty()) {
                    for (Depot depot : depotList) {
                        deptData.setDepotNumber(deptData.getDepotNumber() + 1);
                        if(StringUtils.isNotBlank(depot.getPledgeBank())){
                            deptData.setDepotBankNumber(deptData.getDepotBankNumber() + 1);
                        }
                        if(null == depot.getStorageReal()){
                            depot.setStorageReal(0.0);
                        }
                        deptData.setStorageNum(deptData.getStorageNum() + depot.getStorageReal()/1000);
                    }
                }
                //统计出入库数量
                InoutParam inoutParam = new InoutParam();
                inoutParam.setDeptId(dept.getId());
                inoutParam.setCompanyId(param.getCompanyId());
                inoutParam.setStart(DateUtil.getCurZero(new Date()));
                inoutParam.setEnd(DateUtil.getNextZero(new Date()));
                List<InoutRecord> inoutRecords = inoutRecordService.listInout(inoutParam);
                if (null != inoutRecords && !inoutRecords.isEmpty()) {
                    for (InoutRecord inoutRecord : inoutRecords) {
                        if (Constant.TYPE_IN.equals(inoutRecord.getType())) {
                            deptData.setInNum(deptData.getInNum() + 1);
                        }
                        if (Constant.TYPE_OUT.equals(inoutRecord.getType())){
                            deptData.setOutNum(deptData.getOutNum() + 1);
                        }
                    }
                }
                //统计AI事件数量
                IgdsBaseParam igdsParam = new IgdsBaseParam();
                igdsParam.setDeptId(dept.getId());
                igdsParam.setCompanyId(param.getCompanyId());
                igdsParam.setStart(DateUtil.getNewByDay(new Date(), -6));
                igdsParam.setEnd(DateUtil.getNextZero(new Date()));
                List<EventInfo> enevtList = eventInfoService.getListByParam(igdsParam);
                if (null != enevtList && !enevtList.isEmpty()) {
                    deptData.setWarnNum7(enevtList.size());
                    for (EventInfo eventInfo : enevtList) {
                        if(DateFormatUtils.format(new Date(), "yyyyMMdd").equals(DateFormatUtils.format(eventInfo.getTime(), "yyyyMMdd"))){
                            deptData.setDailyTotal(deptData.getDailyTotal() + 1);
                        }
                    }
                }
                list.add(deptData);
            }
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, list);
    }
    /**
     * 统计gis数据,只统计登录人下属的数据统计
     *
     * @return
     */
    public GroupGisData getGisData() {
        GroupGisData groupGisData = new GroupGisData();
        //查询伊犁下属区县
        //区县
@@ -138,7 +362,7 @@
        List<Dept> deptList = deptService.getDeptData();
        if (null != deptList && !deptList.isEmpty()) {
            //库区总数
            gisData.setDeptNum(deptList.size());
            groupGisData.setDeptNum(deptList.size());
            for (Dept dept : deptList) {
                if (StringUtils.isBlank(dept.getXzqhdm()) || null == valuePieChart.get(dept.getXzqhdm())) {
                    if(null == valuePieChart.get("999999")){
@@ -151,33 +375,54 @@
            }
        }
        if(gisData.getDeptNum() > 0){
        if(groupGisData.getDeptNum() > 0){
            for (String mapKey : valuePieChart.keySet()) {
                gisData.getDeptList().add(new ChartPie(valuePieChart.get(mapKey) + "", namePieChart.get(mapKey), new DecimalFormat("0.0").format((double)valuePieChart.get(mapKey) / gisData.getDeptNum() * 100)));
                groupGisData.getDeptList().add(new ChartPie(valuePieChart.get(mapKey) + "", namePieChart.get(mapKey), new DecimalFormat("0.0").format((double)valuePieChart.get(mapKey) / groupGisData.getDeptNum() * 100)));
            }
        }
        //统计重量
        List<Depot> depotLisst = depotService.getData(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), false);
        if (null != depotLisst && !depotLisst.isEmpty()) {
            for (Depot depot : depotLisst) {
        List<Depot> depotList = depotService.getData(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), false);
        if (null != depotList && !depotList.isEmpty()) {
            for (Depot depot : depotList) {
                if(null == depot.getStorageReal()){
                    depot.setStorageReal(0.0);
                }
                gisData.setSum(gisData.getSum() + depot.getStorageReal());
                groupGisData.setSum(groupGisData.getSum() + depot.getStorageReal());
                if(StringUtils.isNotBlank(depot.getPledgeBank())){
                    gisData.setBankSum(gisData.getBankSum() + depot.getStorageReal());
                    groupGisData.setBankSum(groupGisData.getBankSum() + depot.getStorageReal());
                }else{
                    gisData.setNormalSum(gisData.getNormalSum() + depot.getStorageReal());
                    groupGisData.setNormalSum(groupGisData.getNormalSum() + depot.getStorageReal());
                }
            }
        }
        if(gisData.getSum() > 0){
            gisData.setSumPer(new DecimalFormat("0.00").format(gisData.getSum() / gisData.getSum() * 100L));
            gisData.setBankSumPer(new DecimalFormat("0.00").format(gisData.getBankSum() / gisData.getSum() * 100L));
            gisData.setNormalSumPer(new DecimalFormat("0.00").format(gisData.getNormalSum() / gisData.getSum() * 100L));
        if(groupGisData.getSum() > 0){
            groupGisData.setSumPer(new DecimalFormat("0.00").format(groupGisData.getSum() / groupGisData.getSum() * 100L));
            groupGisData.setBankSumPer(new DecimalFormat("0.00").format(groupGisData.getBankSum() / groupGisData.getSum() * 100L));
            groupGisData.setNormalSumPer(new DecimalFormat("0.00").format(groupGisData.getNormalSum() / groupGisData.getSum() * 100L));
        }
        return gisData;
        return groupGisData;
    }
    /**
     * 大屏首页-抓拍跟踪信息
     * @param param
     * @return
     */
    public PageResponse<List<SnapRecord>> indexSnapList(IgdsBaseParam param) {
        param.setStart(DateUtil.getNewByDay(new Date(), -10));
        param.setEnd(new Date());
        List<SnapRecord> listSnap = snapRecordService.getListByParam(param);
        if (null != listSnap && !listSnap.isEmpty()) {
            //判断文件是否存在
            for (SnapRecord record : listSnap) {
                record.setImgName(commonManager.isImgExit( record.getImgName(), null));
            }
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, listSnap);
    }
}