|
|
@@ -7,18 +7,17 @@ import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
import com.yunfeiyun.agmp.common.constant.ResConstants;
|
|
|
import com.yunfeiyun.agmp.common.framework.oss.cloud.OSSFactory;
|
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
-import com.yunfeiyun.agmp.common.utils.JSONUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.mq.IotActionEnums;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotCbdrecogAgainReqVo;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotCbdrecogReqVo;
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.EnumCbdMarkType;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumCbdRecogType;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.IotWeatherService;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
-import com.yunfeiyun.agmp.iot.common.util.tmn.CustomerIdUtil;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdrecogInfoResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdrecogResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotCbdrecogService;
|
|
|
@@ -41,7 +40,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -75,217 +73,103 @@ public class IotCbdrecogServiceImpl implements IIotCbdrecogService {
|
|
|
@Override
|
|
|
public int artificialUpdate(IotCbdrecogReqVo reqVo) {
|
|
|
String cbdrecogType = reqVo.getCbdrecogType();
|
|
|
- String cbdrecogMarktype = "0";
|
|
|
String cbdimgBid = reqVo.getCbdimgBid();
|
|
|
String cbdrecogManualmark = reqVo.getCbdrecogManualmark();
|
|
|
String cbdrecogManualBase64 = reqVo.getCbdrecogManualBase64();
|
|
|
String devBid = reqVo.getDevBid();
|
|
|
|
|
|
-
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("cbdimgBid", cbdimgBid);
|
|
|
IotCbdimg iotCbdimg = (IotCbdimg) mongoService.findOne(IotCbdimg.class, map, null, null);
|
|
|
+ String nowDate = DateUtils.dateTimeNow();
|
|
|
+ iotCbdimg.setCbdimgModifieddate(nowDate);
|
|
|
|
|
|
- Criteria cri = Criteria.where("cbdimgBid").is(cbdimgBid)
|
|
|
- .and("cbdrecogType").is(cbdrecogType)
|
|
|
- .and("cbdrecogMarktype").is(cbdrecogMarktype);
|
|
|
- IotCbdrecog iotCbdrecog = mongoTemplate.findOne(new Query(cri),
|
|
|
- IotCbdrecog.class, "IotCbdrecog");
|
|
|
- boolean isUpdate = true;
|
|
|
+ Map<String, IotCbdrecog> cbdrecog = iotCbdimg.getCbdrecog();
|
|
|
+ IotCbdrecog iotCbdrecog = cbdrecog.get(cbdrecogType);
|
|
|
if (iotCbdrecog == null) {
|
|
|
- Criteria cri2 = Criteria.where("cbdimgBid").is(cbdimgBid)
|
|
|
- .and("cbdrecogType").is(cbdrecogType);
|
|
|
- iotCbdrecog = mongoTemplate.findOne(new Query(cri2),
|
|
|
- IotCbdrecog.class, "IotCbdrecog");
|
|
|
- if (iotCbdrecog == null) {
|
|
|
- iotCbdrecog = new IotCbdrecog();
|
|
|
- iotCbdrecog.setCbdimgBid(cbdimgBid);
|
|
|
- iotCbdrecog.setCbdrecogType(cbdrecogType);
|
|
|
- iotCbdrecog.setCbdrecogDelstatus("0");
|
|
|
- iotCbdrecog.setCbdrecogCreatedDate(iotCbdimg.getCbdimgCreatedDate());
|
|
|
- iotCbdrecog.setCbdrecogModifieddate(iotCbdimg.getCbdimgCreatedDate());
|
|
|
- iotCbdrecog.setCbdrecogCreator(SecurityUtils.getUserId());
|
|
|
-
|
|
|
- }
|
|
|
+ iotCbdrecog = new IotCbdrecog();
|
|
|
+ BeanUtils.copyProperties(iotCbdimg, iotCbdrecog);
|
|
|
iotCbdrecog.setCbdrecogBid(iotCbdrecog.getUUId());
|
|
|
- iotCbdrecog.setCbdrecogMarktype(cbdrecogMarktype);
|
|
|
- isUpdate = false;
|
|
|
+ iotCbdrecog.setCbdrecogType(cbdrecogType);
|
|
|
+ // 字段不使用,统一标记成机器
|
|
|
+ iotCbdrecog.setCbdrecogMarktype(EnumCbdMarkType.AUTO.getCode());
|
|
|
+ iotCbdrecog.setCbdrecogDelstatus("0");
|
|
|
+ iotCbdrecog.setCbdrecogCreator(SecurityUtils.getUserId());
|
|
|
+ iotCbdrecog.setCbdrecogCreatedDate(nowDate);
|
|
|
}
|
|
|
|
|
|
+ iotCbdrecog.setCbdrecogModifier(SecurityUtils.getUserId());
|
|
|
+ iotCbdrecog.setCbdrecogModifieddate(nowDate);
|
|
|
if (StringUtils.isNotEmpty(cbdrecogManualBase64)) {
|
|
|
String imgUrl = getPestRecogImgOssUrl(cbdrecogManualBase64, iotCbdrecog.getCbdrecogBid());
|
|
|
iotCbdrecog.setCbdrecogManualaddr(imgUrl);
|
|
|
}
|
|
|
- iotCbdrecog.setCbdrecogManualmark(cbdrecogManualmark);
|
|
|
|
|
|
- JSONArray recogArray = JSONArray.parseArray(cbdrecogManualmark);
|
|
|
-
|
|
|
- List<JSONObject> points = new ArrayList<>();//包含了所有识别(标记),其中(已收录过的害虫的),提交上来的是pestid:标记信息,人工识别(?未收录过的害虫?前端是否判断后提交?),提交上来的是 ”害虫名称“:"标记信息"
|
|
|
- List<JSONObject> points2 = new ArrayList<>();
|
|
|
- if (recogArray != null) {
|
|
|
- for (Object o : JSONArray.parseArray(cbdrecogManualmark)) {
|
|
|
- points.add((JSONObject) o);
|
|
|
- }
|
|
|
+ if (StringUtils.isNotEmpty(cbdrecogManualmark)) {
|
|
|
+ iotCbdrecog.setCbdrecogManualmark(cbdrecogManualmark);
|
|
|
}
|
|
|
|
|
|
- //害虫信息
|
|
|
- List<IotPest> iotPests = iotPestService.selectIotPestList(null);
|
|
|
- //Map<String, String> pestMap = iotPests.stream().collect(Collectors.toMap(IotPest::getPestId, IotPest::getPestBid));
|
|
|
- Map<String, String> pestMap = iotPests.stream().collect(Collectors.toMap(IotPest::getPestId, IotPest::getPestName));
|
|
|
- Map<String, String> pestMap2 = iotPests.stream().collect(Collectors.toMap(IotPest::getPestId, IotPest::getPestBid));
|
|
|
- //设备信息
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
- //统计害虫数量(pestid->数量)
|
|
|
- Map<String, Integer> pest = new HashMap<>();
|
|
|
-
|
|
|
- //IotPestrecog存储
|
|
|
- for (JSONObject point : points) {
|
|
|
- points2.add(point);
|
|
|
- //判断人工修正的是否有新的害虫名字,有的新的新增,并存储
|
|
|
- for (String s : point.keySet()) {
|
|
|
- if (pestMap.get(s) == null) {//未收录的
|
|
|
- if (!pestMap.containsValue(s)) {//名字确实不存在的
|
|
|
- IotPest iotPest = new IotPest();
|
|
|
- iotPest.setPestBid(iotPest.getUUId());
|
|
|
- iotPest.setPestName(s);
|
|
|
- iotPest.setPestId(iotPest.getPestBid());//新产生的iotpest, pest id和pest bid一样
|
|
|
- iotPest.setPestCreator(SecurityUtils.getUserId());
|
|
|
- iotPest.setPestCreatedDate(DateUtils.dateTimeNow());
|
|
|
- iotPest.setPestDelstatus("0");
|
|
|
- iotPest.setPestInsertType("2");
|
|
|
- iotPest.setTid(CustomerIdUtil.getCustomerId());
|
|
|
- iotPestService.insertIotPest(iotPest);//新害虫名称入库
|
|
|
-
|
|
|
- //pestMap.put(iotPest.getPestId(), iotPest.getPestBid());
|
|
|
- pestMap.put(iotPest.getPestId(), iotPest.getPestName());
|
|
|
- pestMap2.put(iotPest.getPestBid(), iotPest.getPestName());
|
|
|
-
|
|
|
- JSONObject point2 = new JSONObject();
|
|
|
- point2.put(iotPest.getPestId(), point.get(s));
|
|
|
- points2.add(point2);
|
|
|
- points2.remove(point);
|
|
|
-
|
|
|
- //pest.put(iotPest.getPestId(), pest.get(s) == null ? 1 : pest.get(s) + 1);
|
|
|
- pest.put(iotPest.getPestId(), pest.get(iotPest.getPestId()) == null ? 1 : pest.get(iotPest.getPestId()) + 1);
|
|
|
- } else {
|
|
|
- //名字-》pestid
|
|
|
- String findPestId = "";
|
|
|
- for (Map.Entry<String, String> entry : pestMap.entrySet()) {
|
|
|
- if (s.equals(entry.getValue())) {
|
|
|
- findPestId = entry.getKey();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- pest.put(findPestId, pest.get(findPestId) == null ? 1 : pest.get(findPestId) + 1);
|
|
|
- }
|
|
|
- } else {
|
|
|
- pest.put(s, pest.get(s) == null ? 1 : pest.get(s) + 1);
|
|
|
+ JSONArray recogArray = JSONArray.parseArray(cbdrecogManualmark);
|
|
|
+ Map<String, IotCbdPestrecog> cbdPestrecogMap = new LinkedHashMap<>();
|
|
|
+ Long cbdrecogTotalnumManual = 0L;
|
|
|
+ for(Object o : recogArray) {
|
|
|
+ JSONObject point = (JSONObject) o;
|
|
|
+ for(String pestName : point.keySet()) {
|
|
|
+ String province = iotDevice.getDevProvince();
|
|
|
+ String city = iotDevice.getDevCity();
|
|
|
+ String district = iotDevice.getDevDistrict();
|
|
|
+ BigDecimal lat = iotDevice.getDevLatalign() == null ? iotDevice.getDevLat() : iotDevice.getDevLatalign();
|
|
|
+ BigDecimal lng = iotDevice.getDevLngalign() == null ? iotDevice.getDevLng() : iotDevice.getDevLngalign();
|
|
|
+ IotCbdPestrecog cbdPestrecog = cbdPestrecogMap.get(pestName);
|
|
|
+ if(!cbdPestrecogMap.containsKey(pestName)) {
|
|
|
+ cbdPestrecog = new IotCbdPestrecog();
|
|
|
+ cbdPestrecog.setPestrecogBid(iotCbdrecog.getCbdrecogBid());
|
|
|
+ cbdPestrecog.setTid(iotDevice.getTid());
|
|
|
+ cbdPestrecog.setDevBid(iotDevice.getDevBid());
|
|
|
+ cbdPestrecog.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
+ cbdPestrecog.setRecogBid(iotCbdrecog.getCbdrecogBid());
|
|
|
+ cbdPestrecog.setImgBid(iotCbdimg.getCbdimgBid());
|
|
|
+ cbdPestrecog.setPestrecogMarktype(EnumCbdMarkType.HAND.getCode());
|
|
|
+ cbdPestrecog.setCbdrecogType(cbdrecogType);
|
|
|
+ cbdPestrecog.setPestrecogLng(lng);
|
|
|
+ cbdPestrecog.setPestrecogLat(lat);
|
|
|
+ cbdPestrecog.setPestrecogProvince(province);
|
|
|
+ cbdPestrecog.setPestrecogCity(city);
|
|
|
+ cbdPestrecog.setPestrecogDistrict(district);
|
|
|
+
|
|
|
+ cbdPestrecog.setPestBusid(pestName);
|
|
|
+ cbdPestrecog.setPestName(pestName);
|
|
|
+ cbdPestrecog.setPestrecogNum(1L);
|
|
|
+ cbdPestrecog.setPestrecogCreatedDate(nowDate);
|
|
|
+
|
|
|
+ cbdPestrecogMap.put(pestName, cbdPestrecog);
|
|
|
+ }else{
|
|
|
+ cbdPestrecog.setPestrecogNum(cbdPestrecog.getPestrecogNum() + 1);
|
|
|
}
|
|
|
-
|
|
|
+ cbdrecogTotalnumManual += 1;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //IotPestrecog进行存储
|
|
|
- String province = iotDevice.getDevProvince();
|
|
|
- String city = iotDevice.getDevCity();
|
|
|
- String district = iotDevice.getDevDistrict();
|
|
|
- BigDecimal lat = iotDevice.getDevLatalign() == null ? iotDevice.getDevLat() : iotDevice.getDevLatalign();
|
|
|
- BigDecimal lng = iotDevice.getDevLngalign() == null ? iotDevice.getDevLng() : iotDevice.getDevLngalign();
|
|
|
-
|
|
|
- JSONObject weatherInfo = iotWeatherService.getWeatherByAddress(province, city, district);
|
|
|
- BigDecimal at = BigDecimal.valueOf(Long.parseLong("0"));
|
|
|
- BigDecimal ah = BigDecimal.valueOf(Long.parseLong("0"));
|
|
|
- if (weatherInfo != null) {
|
|
|
- at = BigDecimal.valueOf(Double.parseDouble((String) weatherInfo.getOrDefault("tem", "0")));
|
|
|
- ah = BigDecimal.valueOf(Double.parseDouble(((String) weatherInfo.getOrDefault("humidity", "0")).replace("%", "")));
|
|
|
- }
|
|
|
-
|
|
|
- List<IotPestrecog> iotPestrecogList = new ArrayList<>();
|
|
|
- long recogNum = 0L;
|
|
|
- for (String s : pest.keySet()) {
|
|
|
- long pestNum = pest.get(s).longValue();
|
|
|
- recogNum += pestNum;
|
|
|
-
|
|
|
- IotPestrecog iotPestrecog = new IotPestrecog();
|
|
|
- iotPestrecog.setCId(iotDevice.getTid());
|
|
|
- iotPestrecog.setPestrecogBid(iotPestrecog.getUUId());
|
|
|
- iotPestrecog.setDevBid(iotDevice.getDevBid());
|
|
|
- iotPestrecog.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
- iotPestrecog.setPestrecogAt(at);
|
|
|
- iotPestrecog.setPestrecogAh(ah);
|
|
|
- iotPestrecog.setPestrecogLng(lng);
|
|
|
- iotPestrecog.setPestrecogLat(lat);
|
|
|
- iotPestrecog.setPestrecogProvince(province);
|
|
|
- iotPestrecog.setPestrecogCity(city);
|
|
|
- iotPestrecog.setPestrecogDistrict(district);
|
|
|
- //iotPestrecog.setPestBusid(pestMap.get(s));
|
|
|
- iotPestrecog.setPestBusid(pestMap2.get(s));//这里按设计要存放pest bid
|
|
|
- iotPestrecog.setPestrecogNum(pest.get(s).longValue());
|
|
|
- iotPestrecog.setPestrecogMarktype(cbdrecogMarktype);
|
|
|
- iotPestrecog.setPestrecogCreatedDate(iotCbdrecog.getCbdrecogCreatedDate());
|
|
|
-
|
|
|
- iotPestrecogList.add(iotPestrecog);
|
|
|
- }
|
|
|
-
|
|
|
-// iotCbdrecog.setCbdimgRecognum(recogNum);
|
|
|
-
|
|
|
- Map<String, String> cbdpestMap = new HashMap<>();
|
|
|
- cbdpestMap.put("cbdrecogBid", iotCbdrecog.getCbdrecogBid());
|
|
|
- List<IotCbdpest> cbdpestList = mongoService.findAll(IotCbdpest.class, cbdpestMap);
|
|
|
- Set<String> pestrecogBidSet = new HashSet<>();
|
|
|
- Set<String> cbdpestBidSet = new HashSet<>();
|
|
|
- for (IotCbdpest cbdpest : cbdpestList) {
|
|
|
- pestrecogBidSet.add(cbdpest.getPestrecogBid());
|
|
|
- cbdpestBidSet.add(cbdpest.getCbdpestBid());
|
|
|
- }
|
|
|
- List<String> pestrecogBidList = new ArrayList<>(pestrecogBidSet);
|
|
|
- List<String> cbdpestBidList = new ArrayList<>(cbdpestBidSet);
|
|
|
-
|
|
|
- if (pestrecogBidList.size() > 0) {
|
|
|
- mongoService.removeAllByBatch("pestrecogBid", pestrecogBidList, "IotCbdpest");
|
|
|
+ Long cbdrecogTypenumManual = (long) cbdPestrecogMap.size();
|
|
|
+ iotCbdrecog.setCbdrecogTypenumManual(cbdrecogTypenumManual);
|
|
|
+ iotCbdrecog.setCbdrecogTotalnumManual(cbdrecogTotalnumManual);
|
|
|
+ iotCbdrecog.setCbdrecogPestnumManual(cbdrecogTotalnumManual);
|
|
|
+
|
|
|
+ List<IotCbdPestrecog> pestrecogList = new ArrayList<>(cbdPestrecogMap.values());
|
|
|
+ Map<String, List<IotCbdPestrecog>> pestrecog = iotCbdrecog.getPestrecog();
|
|
|
+ if(pestrecog == null){
|
|
|
+ pestrecog = new HashMap<>();
|
|
|
+ pestrecog.put(EnumCbdMarkType.HAND.getCode(), pestrecogList);
|
|
|
+ }else{
|
|
|
+ pestrecog.put(EnumCbdMarkType.HAND.getCode(), pestrecogList);
|
|
|
}
|
|
|
- if (cbdpestBidList.size() > 0) {
|
|
|
- mongoService.removeAllByBatch("cbdpestBid", cbdpestBidList, "IotCbdpest");
|
|
|
- }
|
|
|
-
|
|
|
- //针对人工识别,设置cbdrecogResultManual和cbdrecogManualmark
|
|
|
- String cbdrecogResultManual = "";
|
|
|
- //遍历pest,拼接成字符串
|
|
|
- for (String s : pest.keySet()) {
|
|
|
- cbdrecogResultManual += s + "," + pest.get(s).longValue() + "#";
|
|
|
- }
|
|
|
- if (cbdrecogResultManual.endsWith("#")) {
|
|
|
- cbdrecogResultManual = cbdrecogResultManual.substring(0, cbdrecogResultManual.length() - 1);
|
|
|
- }
|
|
|
-
|
|
|
- iotCbdrecog.setCbdrecogResultManual(cbdrecogResultManual);
|
|
|
+ iotCbdrecog.setPestrecog(pestrecog);
|
|
|
+ cbdrecog.put(cbdrecogType, iotCbdrecog);
|
|
|
+ iotCbdimg.setCbdrecog(cbdrecog);
|
|
|
|
|
|
- iotCbdrecog.setCbdrecogManualmark(JSONUtils.toJSONString(points2));
|
|
|
+ mongoService.removeAllByParam("cbdimgBid", cbdimgBid, "IotCbdimg");
|
|
|
|
|
|
- if (isUpdate) {
|
|
|
- Map<String, Object> updateField = JSONUtils.toMap(JSONUtils.toJSONString(iotCbdrecog));
|
|
|
- updateField.remove("id");
|
|
|
- updateField.remove("uuid");
|
|
|
-
|
|
|
- Criteria criteria = new Criteria();
|
|
|
- criteria.and("cbdrecogBid").is(iotCbdrecog.getCbdrecogBid());
|
|
|
- Query updateQuery = new Query(criteria);
|
|
|
- mongoService.updateOrCreate(IotCbdrecog.class, updateQuery, updateField);
|
|
|
- } else {
|
|
|
- mongoService.saveOne(iotCbdrecog);
|
|
|
- }
|
|
|
-
|
|
|
- for (IotPestrecog iotPestrecog : iotPestrecogList) {
|
|
|
- mongoService.saveOne(iotPestrecog);
|
|
|
-
|
|
|
- // 保存 测报灯图片识别和虫情信息关联信息
|
|
|
- IotCbdpest iotCbdpest = new IotCbdpest();
|
|
|
- iotCbdpest.setTid(iotDevice.getTid());
|
|
|
- iotCbdpest.setCbdpestBid(iotCbdpest.getUUId());
|
|
|
- iotCbdpest.setPestrecogBid(iotPestrecog.getPestrecogBid());
|
|
|
- iotCbdpest.setCbdrecogBid(iotCbdrecog.getCbdrecogBid());
|
|
|
- mongoService.saveOne(iotCbdpest);
|
|
|
- }
|
|
|
+ mongoService.saveOne(iotCbdimg);
|
|
|
return 1;
|
|
|
}
|
|
|
|