CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.ld.igds.databoard.manager;
 
import com.bstek.bdf2.core.model.DefaultDept;
import com.ld.igds.constant.DepotType;
import com.ld.igds.constant.FoodVariety;
import com.ld.igds.data.ChartPie;
import com.ld.igds.databoard.data.DeptInfo;
import com.ld.igds.grain.service.CoreGrainService;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DicArea;
import com.ld.igds.screen.data.ChartFood5303;
import com.ld.igds.screen.data.DepotGrainData;
import com.ld.igds.sys.service.SysDeptService;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.view.service.HDepotService;
import com.ld.igds.view.service.HDicAreaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 大屏逻辑控制层
 * @author chen
 */
@Component
public class DataboardManager {
 
    @Autowired
    private CoreGrainService grainService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private HDepotService depotService;
    @Autowired
    private HDicAreaService areaService;
    /**
     * 获取仓库列表,及仓库最新的一条粮情信息
     *
     * @return
     */
    public List<DepotGrainData> listDepotAndGrain(String companyId, String deptId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getDefaultCompanyId();
        }
 
        return grainService.getDepotAndGrain(companyId, deptId);
    }
 
 
    public ChartFood5303 getFoodNumber(String companyId, String deptId) {
 
        ChartFood5303 dto = new ChartFood5303();
        List<DepotGrainData> depotList = grainService.getDepotAndGrain(companyId, deptId);
 
        if(depotList == null || depotList.isEmpty()){
            return dto;
        }
        Map<String, Double> varietyPieChar = new HashMap<>();
        Map<String, Double> yearPieChart = new HashMap<>();
        Map<String, Double> locationPieChart = new HashMap<>();
 
        Double realStorage = 0.0;
        Integer depotNum = 0;
        for (DepotGrainData depot : depotList) {
            if(DepotType.TYPE_99.getCode().equals(depot.getDepotType())){
                continue;
            }
            //仓库个数
            depotNum += 1;
            if (null == depot.getStorageReal()) {
                continue;
            }
            dto.setDepotType(depot.getDepotTypeName());
            //总储量
            realStorage += depot.getStorageReal();
 
            //品种
            if (StringUtils.isEmpty(depot.getFoodVariety())) {
                varietyPieChar.putIfAbsent("其他", 0.0);
                varietyPieChar.put("其他", varietyPieChar.get("其他") + depot.getStorageReal());
            }else {
                varietyPieChar.putIfAbsent(depot.getFoodVariety(), 0.0);
                varietyPieChar.put(depot.getFoodVariety(), varietyPieChar.get(depot.getFoodVariety()) + depot.getStorageReal());
            }
 
            //年份
            if (StringUtils.isEmpty(depot.getFoodYear())) {
                if (StringUtils.isEmpty(depot.getFoodVariety())) {
                    yearPieChart.putIfAbsent("其他年份", 0.0);
                    yearPieChart.put("其他年份", yearPieChart.get("其他年份") + depot.getStorageReal());
                }else {
                    yearPieChart.putIfAbsent("其他年份," + depot.getFoodVariety(), 0.0);
                    yearPieChart.put("其他年份," + depot.getFoodVariety(), yearPieChart.get("其他年份," + depot.getFoodVariety()) + depot.getStorageReal());
                }
            }else {
                if (StringUtils.isEmpty(depot.getFoodVariety())) {
                    yearPieChart.putIfAbsent(depot.getFoodYear() + ",其他粮", 0.0);
                    yearPieChart.put(depot.getFoodYear() + ",其他粮", yearPieChart.get(depot.getFoodYear() + ",其他粮") + depot.getStorageReal());
                }else {
                    yearPieChart.putIfAbsent(depot.getFoodYear() + "," +depot.getFoodVariety(), 0.0);
                    yearPieChart.put(depot.getFoodYear() + "," +depot.getFoodVariety(), yearPieChart.get(depot.getFoodYear() + "," +depot.getFoodVariety()) + depot.getStorageReal());
                }
            }
 
            //产地
            if (StringUtils.isEmpty(depot.getFoodLocation())) {
                locationPieChart.putIfAbsent("其他", 0.0);
                locationPieChart.put("其他", locationPieChart.get("其他") + depot.getStorageReal());
            }else {
                locationPieChart.putIfAbsent(depot.getFoodLocation(), 0.0);
                locationPieChart.put(depot.getFoodLocation(), locationPieChart.get(depot.getFoodLocation()) + depot.getStorageReal());
            }
        }
        dto.setDepotNum(depotNum);
        dto.setRealStorage(realStorage);
 
        ChartPie chartPie;
        //品种数量转化
        for (String key : varietyPieChar.keySet()) {
            chartPie = new ChartPie();
            chartPie.setName(FoodVariety.getMsg(key));
            chartPie.setValue(new DecimalFormat("0").format(varietyPieChar.get(key)));
            dto.getListFoodVariety().add(chartPie);
        }
        //年份
        for (String key : yearPieChart.keySet()) {
            chartPie = new ChartPie();
            String[] split = key.split(",");
            if(split.length > 1){
                chartPie.setName(split[0] + "年" + FoodVariety.getMsg(split[1]));
                chartPie.setValue(new DecimalFormat("0").format(yearPieChart.get(key)));
            }else {
                chartPie.setName(key);
                chartPie.setValue(new DecimalFormat("0").format(yearPieChart.get(key)));
            }
            dto.getListFoodYear().add(chartPie);
        }
        //产地
        for (String key : locationPieChart.keySet()) {
            chartPie = new ChartPie();
            chartPie.setName(key);
            chartPie.setValue(new DecimalFormat("0").format(locationPieChart.get(key)));
            dto.getListFoodLocation().add(chartPie);
        }
 
        return dto;
    }
 
    /**
     * 获取库区基础信息
     * @param deptId
     * @return
     */
    public DeptInfo getDeptInfo(String deptId) {
 
        DeptInfo dto = new DeptInfo();
        DefaultDept dept = sysDeptService.getDeptById(deptId);
        if (null == dept) {
            return dto;
        }
 
        //库区名称
        dto.setDeptName(dept.getName());
 
        //所在省市县
        String addr = "";
        DicArea dicArea = areaService.listDicAreaByCode(dept.getProvince());
        if(null != dicArea){
            addr += "-" + dicArea.getName();
        }
        dicArea = areaService.listDicAreaByCode(dept.getCity());
        if(null != dicArea){
            addr += "-" + dicArea.getName();
        }
        dicArea = areaService.listDicAreaByCode(dept.getCountry());
        if(null != dicArea){
            addr += "-" + dicArea.getName();
            dto.setAddr(addr.substring(1));
        }else{
            dto.setAddr("未配置");
        }
 
        //设计储量
        Double storage = 0.0;
        if (null != dept.getStorage()) {
            storage += dept.getStorage();
        }
        if (null != dept.getOilStorage()) {
            storage += dept.getOilStorage();
        }
        dto.setStorage(Double.toString(storage));
 
        //获取仓库列表
        List<Depot> depotList = depotService.getData(null);
        if (depotList == null || depotList.isEmpty()) {
            return dto;
        }
 
        //统计数量及储量
        Double foodStorage = 0.0, oilStorage = 0.0;
        int depotNum = 0, oilNum = 0;
        for (Depot depot : depotList) {
            if (DepotType.TYPE_99.getCode().equals(depot.getDepotType())) {
                continue;
            }
            if (DepotType.TYPE_03.getCode().equals(depot.getDepotType())) {
                oilNum += 1;
                if (null == depot.getStorageReal()) {
                    continue;
                }
                oilStorage += depot.getStorageReal()/1000;
            } else {
                depotNum += 1;
                if (null == depot.getStorageReal()) {
                    continue;
                }
                foodStorage += depot.getStorageReal()/1000;
            }
        }
        dto.setDepotNum(depotNum);
        dto.setOilNum(oilNum);
        dto.setFoodStorage(new DecimalFormat("0.0").format(foodStorage));
        dto.setOilStorage(new DecimalFormat("0.0").format(oilStorage));
 
        return dto;
    }
}