package com.ld.igds.three.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ld.igds.common.CoreThreeService;
|
import com.ld.igds.models.ThreeConf;
|
import com.ld.igds.pest.dto.PestData;
|
import com.ld.igds.three.ThreeCodeEnum;
|
import com.ld.igds.three.ThreeConstant;
|
import com.ld.igds.three.data.Data2004;
|
import com.ld.igds.three.data.ThreeResponse;
|
import com.ld.igds.three.mapper.ThreeMapper;
|
import com.ld.igds.three.param.ThreeCommonParam;
|
import com.ld.igds.three.param.ThreeRequest;
|
import com.ld.igds.three.service.ThreeService;
|
import com.ld.igds.three.util.ThreeRespUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 2004-虫害采集接口实现
|
*
|
* @author chen
|
*/
|
@Service
|
public class ThreeServiceImpl2004 implements ThreeService {
|
|
@Autowired
|
private CoreThreeService commonService;
|
@Autowired
|
private ThreeMapper threeMapper;
|
|
@Override
|
public String getInterfaceId() {
|
return ThreeConstant.API_THREE_2004;
|
}
|
|
@SuppressWarnings("unchecked")
|
@Override
|
public ThreeResponse<Object> execute(ThreeRequest<JSONObject> req) {
|
//转化请求参数
|
ThreeCommonParam param = JSONObject.parseObject(req.getData().toString(), ThreeCommonParam.class);
|
|
//判断uid
|
if (StringUtils.isEmpty(param.getUid())) {
|
return ThreeRespUtil.error(ThreeCodeEnum.CODE_1005, req);
|
}
|
|
//返回数据定义
|
List<Data2004> list = new ArrayList<>();
|
Data2004 data2004;
|
|
//获取所有仓库虫害信息(每个仓库取最新的一条)
|
Map<String, PestData> pestMap = getGasAll(req.getCompanyId());
|
if (pestMap.isEmpty()) {
|
return ThreeRespUtil.success(list, req);
|
}
|
|
//根据uid判断查询所有仓库虫害还是单个仓库虫害
|
if (ThreeConstant.REQUEST_UID.equals(param.getUid())) {
|
//获取全部三维配置信息
|
List<ThreeConf> threeList = commonService.getCacheThreeAll(req.getCompanyId());
|
if (threeList == null || threeList.isEmpty()) {
|
return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "未查询相关三维配置信息,请联系管理员!", req);
|
}
|
|
//返回数据处理
|
for (ThreeConf threeConf : threeList) {
|
if (StringUtils.isEmpty(threeConf.getDeviceId()) &&
|
StringUtils.isNotEmpty(threeConf.getDepotId())) {
|
|
PestData pestData = pestMap.get(threeConf.getDepotId());
|
if (pestData != null) {
|
data2004 = getData(pestData, threeConf.getUid());
|
list.add(data2004);
|
}
|
}
|
}
|
|
|
} else {
|
//根据uid获取三维配置信息
|
ThreeConf threeConf = commonService.getCacheThreeConfById(req.getCompanyId(), param.getUid());
|
if (threeConf == null) {
|
return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "未查询到此uid的配置信息,请联系管理员!", req);
|
}
|
|
PestData pestData = pestMap.get(threeConf.getDepotId());
|
if (pestData != null) {
|
data2004 = getData(pestData, threeConf.getUid());
|
list.add(data2004);
|
}
|
}
|
|
return ThreeRespUtil.success(list, req);
|
}
|
|
/**
|
* 数据封装
|
*
|
* @param pestData
|
* @param uid
|
* @return
|
*/
|
private Data2004 getData(PestData pestData, String uid) {
|
|
Data2004 data = new Data2004();
|
|
data.setUid(uid);
|
data.setTime(pestData.getReceiveDate());
|
data.setResult(pestData.getRemark());
|
|
return data;
|
}
|
|
|
/**
|
* 从数据库查询气体,并转为map集合
|
*
|
* @param companyId
|
* @return
|
*/
|
private Map<String, PestData> getGasAll(String companyId) {
|
|
List<PestData> pestAll = threeMapper.getPestAll(companyId);
|
|
Map<String, PestData> map = new HashMap<>();
|
|
if (pestAll != null && pestAll.size() > 0) {
|
for (PestData pestData : pestAll) {
|
map.put(pestData.getDepotId(), pestData);
|
}
|
}
|
return map;
|
}
|
}
|