jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
package com.ld.igds.pest.impl;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
import lombok.extern.slf4j.Slf4j;
 
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.data.ChartLine;
import com.ld.igds.data.ChartSeries;
import com.ld.igds.models.DicSysConf;
import com.ld.igds.models.Pest;
import com.ld.igds.models.PestInfo;
import com.ld.igds.pest.CorePestService;
import com.ld.igds.pest.PestDataBuilder;
import com.ld.igds.pest.dto.PestData;
import com.ld.igds.pest.dto.PestParam;
import com.ld.igds.pest.mapper.PestServiceMapper;
 
/**
 * 
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2019年12月25日
 *
 */
@Slf4j
@Component
public class CorePestServiceImpl implements CorePestService {
 
    @Autowired
    private PestServiceMapper pestMapper;
    @Autowired
    private CoreCommonService commonService;
 
    @Override
    public List<PestData> pageQueryList(PestParam param) {
 
        Page<PestData> page = new Page<PestData>(param.getPage(),
                param.getLimit());
        page.setSearchCount(false);
        List<PestData> result;
        if (null == param.getStart()) {// 表明没有设置时间参数,为了保证正常获取数据
            result = pestMapper.pageListPest(page, param);
        } else {// 如果有参数,将pageSize设置为100
            page.setSize(100);
            result = pestMapper.pageListPest(page, param);
        }
        if (null == result || result.isEmpty()) {
            return result;
        }
        // 粮情数据调整
        if (param.isTagUpdate()) {
            // 获取配置信息
            DicSysConf conf = commonService.getCacheSysConf(result.get(0)
                    .getCompanyId());
            for (PestData data : result) {
                PestDataBuilder.updatePestData(data, conf);
            }
        }
        return result;
    }
 
    @Override
    public void saveOrUpdateData(Pest pest) {
        try {
            log.debug("虫害信息:{}", pest.toString());
            pestMapper.savePest(pest);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
 
    @Override
    public void saveInfoPest(List<PestInfo> listPest) {
        try {
            for (PestInfo pestInfo : listPest) {
                pestMapper.saveInfo(pestInfo);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
 
    @Override
    public ChartLine queryLineData(PestParam param) {
        List<PestData> list = pestMapper.listChartPest(param);
        if (null == list || list.isEmpty())
            return null;
        // 折线图配置
        String[] arrtLegendData = new String[] { "检测最多虫数" };
 
        List<String> xaxisData = new ArrayList<String>();
        List<ChartSeries> listSeries = new ArrayList<ChartSeries>();
        for (String name : arrtLegendData) {
            listSeries.add(new ChartSeries(name));
        }
        for (PestData grain : list) {
            // X轴数据添加
            xaxisData.add(DateFormatUtils.format(grain.getReceiveDate(),
                    "yyyy-MM-dd HH:mm"));
            listSeries.get(0).getData().add(String.valueOf(grain.getPestMax()));
        }
 
        return new ChartLine(Arrays.asList(arrtLegendData), xaxisData,
                listSeries);
    }
}