czt
2025-12-25 a1cc1dca3ad00d2ac1b81c54b0f98b3684c31da1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.fzzy.group.manager;
 
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.utils.ContextUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.*;
 
/**
 * @Description
 * @Author CZT
 * @Date 2025/12/11 15:48
 */
@Slf4j
@Component
public class GroupManager {
 
    @Resource
    private DicAreaService dicAreaService;
    @Resource
    private CoreDeptService deptService;
    @Resource
    private DepotService depotService;
 
    /**
     * 获取省及下属市州集合
     *
     * @param areaCode
     * @return
     */
    public List<DicArea> getArea(String areaCode) {
 
        DicArea area = dicAreaService.listDicAreaByCode(areaCode);
        if (null == area) {
            return null;
        }
 
        List<DicArea> list = new ArrayList<>();
        list.add(area);
        if (Constant.AREA_TYPE_1.equals(area.getType())) {
            //市州级别,只查询伊犁
            List<DicArea> children = dicAreaService.listData(null, null, "654000");
            if (null != children && !children.isEmpty()) {
                for (DicArea child : children) {
                    if (Constant.AREA_TYPE_2.equals(child.getType())) {
                        //区县
                        List<DicArea> childrenItem = dicAreaService.listData(child.getCode(), null, null);
                        if (null != childrenItem && !childrenItem.isEmpty()) {
                            list.addAll(childrenItem);
                        }
                    }
                }
                list.addAll(children);
            }
        }
 
        return list;
    }
 
    /**
     * 获取对应省份及下属市州children
     *
     * @param areaCode
     * @return
     */
    public List<DicArea> getAreaAndChild(String areaCode) {
 
        DicArea area = dicAreaService.listDicAreaByCode(areaCode);
        if (null == area) {
            return null;
        }
 
        List<DicArea> list = new ArrayList<>();
        if (Constant.AREA_TYPE_1.equals(area.getType())) {
            //市州级别,只查询伊犁
            List<DicArea> children = dicAreaService.listData(null, null, "654000");
            if (null != children && !children.isEmpty()) {
                for (DicArea child : children) {
                    if (Constant.AREA_TYPE_2.equals(child.getType())) {
                        //区县
                        List<DicArea> childrenItem = dicAreaService.listData(child.getCode(), null, null);
                        if (null != childrenItem && !childrenItem.isEmpty()) {
                            child.setChildren(childrenItem);
                        }
                    }
                }
                area.setChildren(children);
            }
 
        }
        list.add(area);
        return list;
    }
 
    /**
     * 获取组织下所有库区信息
     *
     * @param companyId
     * @return
     */
    public List<Dept> getAllDept(String companyId) {
        return deptService.listDept(null, companyId, null);
    }
 
    /**
     * 统计gis数据,只统计登录人下属的数据统计
     * @return
     */
    public GisData getGisData() {
 
        GisData gisData = new GisData();
 
        //查询伊犁下属区县
        //区县
        List<DicArea> dicAreaList = dicAreaService.listData("654000", null, null);
 
        //统计区县下库区数
        LinkedHashMap<String, Integer> valuePieChart = new LinkedHashMap<>();
        LinkedHashMap<String, String> namePieChart = new LinkedHashMap<>();
        if (null != dicAreaList && !dicAreaList.isEmpty()) {
            for (DicArea dicArea : dicAreaList) {
                valuePieChart.put(dicArea.getCode(), 0);
                namePieChart.put(dicArea.getCode(), dicArea.getName());
            }
        }
        List<Dept> deptList = deptService.getDeptData();
        if (null != deptList && !deptList.isEmpty()) {
            //库区总数
            gisData.setDeptNum(deptList.size());
            for (Dept dept : deptList) {
                if (StringUtils.isBlank(dept.getXzqhdm()) || null == valuePieChart.get(dept.getXzqhdm())) {
                    if(null == valuePieChart.get("999999")){
                        valuePieChart.put("999999", 0);
                        namePieChart.put("999999", "其他区县");
                    }
                    dept.setXzqhdm("999999");
                }
                valuePieChart.put(dept.getXzqhdm(), valuePieChart.get(dept.getXzqhdm()) + 1);
            }
        }
 
        if(gisData.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)));
            }
        }
 
        //统计重量
        List<Depot> depotLisst = depotService.getData(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), false);
        if (null != depotLisst && !depotLisst.isEmpty()) {
            for (Depot depot : depotLisst) {
                if(null == depot.getStorageReal()){
                    depot.setStorageReal(0.0);
                }
                gisData.setSum(gisData.getSum() + depot.getStorageReal());
                if(StringUtils.isNotBlank(depot.getPledgeBank())){
                    gisData.setBankSum(gisData.getBankSum() + depot.getStorageReal());
                }else{
                    gisData.setNormalSum(gisData.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));
        }
 
        return gisData;
    }
}