sgj
2026-03-24 b8e8195a9cae963e6f59fcd5208698098e03aba8
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package com.fzzy.common.manager;
 
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.constant.DepotType;
import com.fzzy.igds.data.IgdsBaseParam;
import com.fzzy.igds.data.InoutParam;
import com.fzzy.igds.data.MainData;
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.work.service.WorkOrderService;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
 
/**
 * @Description
 * @Author CZT
 * @Date 2025/11/29 15:19
 */
@Slf4j
@Component
public class CommonManager {
 
    @Resource
    private DepotService depotService;
    @Resource
    private DicService dicService;
    @Resource
    private CoreDeptService coreDeptService;
    @Resource
    private SecCameraService secCameraService;
    @Resource
    private ISysDeptService iSysDeptService;
    @Resource
    private FileService fileService;
    @Resource
    private CoreCompanyService coreCompanyService;
    @Resource
    private SloganService sloganService;
    @Resource
    private WorkOrderService workOrderService;
    @Resource
    private InoutRecordService inoutRecordService;
    @Resource
    private EventInfoService eventInfoService;
    @Resource
    private SnapRecordService snapRecordService;
    @Resource
    private GatewaySerService gatewaySerService;
 
    /**
     * 根据库区编码获取库区网关信息
     *
     * @param deptId
     * @return
     */
    public GatewaySer getGatewaySerByDeptId(String deptId) {
        if (StringUtils.isBlank(deptId)) {
            deptId = ContextUtil.subDeptId(null);
        }
 
        return gatewaySerService.getCacheSerByDeptId(deptId);
    }
 
    /**
     * 根据库区编码获取库区下所有仓库列表
     *
     * @param id
     * @return
     */
    public SysDept getDeptById(String id) {
 
        return iSysDeptService.selectDeptById(Long.valueOf(id));
    }
 
    /**
     * 获取库区鸟瞰图
     *
     * @param deptId
     * @return
     */
    public String isDeptImgExit(String deptId) {
 
        Dept dept = coreDeptService.getDeptById(deptId);
 
        String imgPath = (dept == null ? null : dept.getImgPath());
        return isImgExit(imgPath, "dept");
    }
 
    /**
     * 判断路径下文件是否存在,不存在则给默认
     *
     * @param imgPath
     * @param tag
     * @return
     */
    public String isImgExit(String imgPath, String tag) {
        return fileService.isImgExit(imgPath, tag);
    }
 
    /**
     * 根据字典类型获取字典列表
     *
     * @param parentCode
     * @param companyId
     * @return
     */
    public List<SysDictData> getDicTrigger(String parentCode, String companyId) {
        return dicService.getDictDataByType(parentCode, companyId);
    }
 
    /**
     * 根据库区编码获取库区下所有仓库列表
     *
     * @param deptId
     * @return
     */
    public List<Depot> listDepotByDeptId(String deptId) {
        try {
            if (StringUtils.isEmpty(deptId)) {
                deptId = ContextUtil.subDeptId(null);
            }
 
            return depotService.getCacheDepotList(ContextUtil.getCompanyId(), deptId);
 
        } catch (Exception e) {
            return null;
        }
    }
 
    /**
     * 根据仓库类型获取库区下仓库列表
     *
     * @param deptId
     * @param depotTypes 类型多个,用逗号隔开
     * @return
     */
    public List<Depot> listAllDepot(String deptId, String depotTypes) {
 
        List<Depot> depots = this.listDepotByDeptId(deptId);
        if (null == depots || depots.isEmpty()) {
            return null;
        }
 
        List<Depot> result = new ArrayList<>();
        for (Depot depot : depots) {
            if (depotTypes.contains(depot.getDepotType())) {
                result.add(depot);
            }
        }
        return result;
    }
 
    /**
     * @return
     */
    public List<SysDictData> getInoutType() {
        return dicService.getInoutType();
    }
 
 
    /**
     * 根据公司ID获取公司下的分库列表
     *
     * @author sgj
     * @date 2025/12/12
     */
    public List<Dept> listDeptData(String parentId) {
        return coreDeptService.getDeptByUserType(parentId);
    }
 
    /**
     * 根据仓库编码获取仓库类型
     *
     * @param depotId
     * @return
     */
    public String getDepotTypeById(String depotId) {
        String depotType = DepotType.TYPE_01.getCode();
 
        Depot depot = depotService.getCacheDepot(ContextUtil.getCompanyId(), depotId);
        if (null != depot && StringUtils.isNotEmpty(depot.getDepotType())) {
            depotType = depot.getDepotType();
        }
 
        return depotType;
    }
 
    /**
     * 获取设备列表
     *
     * @author sgj
     * @date 2025/12/12
     */
    public List<Camera> listCameraData() {
        return secCameraService.listCamera(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null));
    }
 
    /**
     * 获取收储公司列表
     *
     * @author sgj
     * @date 2025/12/17
     */
    public List<Company> listCompanyData() {
        return coreCompanyService.getCompanyByUserType();
    }
 
 
    /**
     * 获取启用的大屏标语
     *
     * @return
     */
    public Slogan getDicSlogan() {
        List<Slogan> slogans = sloganService.listData(Constant.YN_Y);
        if (null == slogans || slogans.isEmpty()) {
            return null;
        }
        return slogans.get(0);
    }
 
 
    /**
     * 获取启用的大屏标语
     *
     * @return
     */
    public MainData getIndexData(SysUser user) {
 
        MainData mainData = new MainData();
 
        //待办工单数
        Integer orderNum = workOrderService.getTodoNumByUser(user);
        mainData.setOrderNum(orderNum);
 
        //统计出入库信息
        Double inSum = 0.0;
        Double outSum = 0.0;
        LinkedHashMap<String, Integer> mapWeekInNum = new LinkedHashMap<>();
        LinkedHashMap<String, Integer> mapWeekOutNum = new LinkedHashMap<>();
        LinkedHashMap<String, Integer> mapMonthInNum = new LinkedHashMap<>();
        LinkedHashMap<String, Integer> mapMonthOutNum = new LinkedHashMap<>();
        LinkedHashMap<String, Integer> mapWeekAiNum = new LinkedHashMap<>();
        LinkedHashMap<String, Integer> mapWeekSnapNum = new LinkedHashMap<>();
        LinkedHashMap<String, Double> mapWeekMaizeNum = new LinkedHashMap<>();
        String key;
        for (int i = -29; i <= 0; i++) {
            mapMonthInNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0);
            mapMonthOutNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0);
            if (i >= -6) {
                mapWeekInNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0);
                mapWeekOutNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0);
                mapWeekAiNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0);
                mapWeekSnapNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0);
                mapWeekMaizeNum.put(DateFormatUtils.format(DateUtil.getNewByDay(new Date(), i), "MM-dd"), 0.0);
            }
        }
 
        //近7天AI事件数
        IgdsBaseParam param = new IgdsBaseParam();
        param.setDeptId(user.getDeptId() + "");
        param.setStart(DateUtil.getNewByDay(new Date(), -6));
        param.setEnd(new Date());
        List<EventInfo> listEvent = eventInfoService.getListByParam(param);
        if (null != listEvent && !listEvent.isEmpty()) {
            mainData.setAiNum(listEvent.size());
            for (EventInfo event : listEvent) {
                key = DateFormatUtils.format(event.getTime(), "MM-dd");
                if (null != mapWeekAiNum.get(key)) {
                    mapWeekAiNum.put(key, mapWeekAiNum.get(key) + 1);
                }
            }
        }
        for (String mapKey : mapWeekAiNum.keySet()) {
            mainData.getWeekAiDateList().add(mapKey);
            mainData.getWeekAiNumList().add(mapWeekAiNum.get(mapKey));
        }
 
        //近7天抓拍信息统计
        List<SnapRecord> listSnap = snapRecordService.getListByParam(param);
        if (null != listSnap && !listSnap.isEmpty()) {
            for (SnapRecord snap : listSnap) {
                key = DateFormatUtils.format(snap.getSnapTime(), "MM-dd");
                if (null != mapWeekSnapNum.get(key)) {
                    mapWeekSnapNum.put(key, mapWeekSnapNum.get(key) + 1);
                }
            }
        }
        for (String mapKey : mapWeekSnapNum.keySet()) {
            mainData.getWeekSnapDateList().add(mapKey);
            mainData.getWeekSnapNumList().add(mapWeekSnapNum.get(mapKey));
        }
        //近七天玉米出库价格统计
 
        InoutParam inoutParamOfMaize = new InoutParam();
        inoutParamOfMaize.setDeptId(user.getDeptId() + "");
        //粮食品种玉米
        inoutParamOfMaize.setFoodVariety("1120000");
        inoutParamOfMaize.setType(Constant.TYPE_OUT);
        inoutParamOfMaize.setStart(DateUtil.getNewByDay(new Date(), -6));
        inoutParamOfMaize.setEnd(new Date());
        List<InoutRecord> inoutRecordsOfMaize = inoutRecordService.listInout(inoutParamOfMaize);
        if (null != inoutRecordsOfMaize && !inoutRecordsOfMaize.isEmpty()) {
            for (InoutRecord record : inoutRecordsOfMaize) {
                key = DateFormatUtils.format(record.getRegisterTime(), "MM-dd");
                if (null != mapWeekMaizeNum.get(key)) {
                    Double nowPrice = mapWeekMaizeNum.get(key);
                    Double newPrice = record.getPrice();
                    if (nowPrice > newPrice || nowPrice == 0) {
                        nowPrice = newPrice;
                    }
                    mapWeekMaizeNum.put(key, nowPrice);
 
                }
            }
        }
        for (String mapKey : mapWeekMaizeNum.keySet()) {
            mainData.getWeekMaizeDateList().add(mapKey);
            mainData.getWeekMaizeNumList().add(mapWeekMaizeNum.get(mapKey));
        }
 
        //查询近30天所有出入库信息
        InoutParam inoutParam = new InoutParam();
        inoutParam.setDeptId(user.getDeptId() + "");
        inoutParam.setStart(DateUtil.getNewByDay(new Date(), -29));
        inoutParam.setEnd(new Date());
        List<InoutRecord> inoutRecords = inoutRecordService.listInout(inoutParam);
        if (null != inoutRecords && !inoutRecords.isEmpty()) {
            for (InoutRecord record : inoutRecords) {
                key = DateFormatUtils.format(record.getRegisterTime(), "MM-dd");
                if (Constant.TYPE_IN.equals(record.getType())) {
                    if (null != mapWeekInNum.get(key)) {
                        mapWeekInNum.put(key, mapWeekInNum.get(key) + 1);
                    }
                    if (null != mapMonthInNum.get(key)) {
                        mapMonthInNum.put(key, mapMonthInNum.get(key) + 1);
                    }
                    if (key.equals(DateFormatUtils.format(new Date(), "MM-dd"))) {
                        mainData.setInNumDay(mainData.getInNumDay() + 1);
                        inSum += record.getRecordWeight();
                    }
                }
                if (Constant.TYPE_OUT.equals(record.getType())) {
                    if (null != mapWeekOutNum.get(key)) {
                        mapWeekOutNum.put(key, mapWeekOutNum.get(key) + 1);
                    }
                    if (null != mapMonthOutNum.get(key)) {
                        mapMonthOutNum.put(key, mapMonthOutNum.get(key) + 1);
                    }
                    if (key.equals(DateFormatUtils.format(new Date(), "MM-dd"))) {
                        mainData.setOutNumDay(mainData.getOutNumDay() + 1);
                        outSum += record.getRecordWeight();
                    }
                }
            }
        }
 
        for (String mapKey : mapWeekInNum.keySet()) {
            mainData.getWeekDateList().add(mapKey);
            mainData.getWeekInNumList().add(mapWeekInNum.get(mapKey));
        }
 
        for (String mapKey : mapWeekOutNum.keySet()) {
            mainData.getWeekOutNumList().add(mapWeekOutNum.get(mapKey));
        }
 
        for (String mapKey : mapMonthInNum.keySet()) {
            mainData.getMonthDateList().add(mapKey);
            mainData.getMonthInNumList().add(mapMonthInNum.get(mapKey));
        }
 
        for (String mapKey : mapMonthOutNum.keySet()) {
            mainData.getMonthOutNumList().add(mapMonthOutNum.get(mapKey));
        }
        mainData.setInSum(inSum / 1000);
        mainData.setOutSum(outSum / 1000);
        return mainData;
    }
 
}