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);
|
}
|
}
|