|
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
@ -13,12 +14,15 @@ import com.yxt.supervise.monitor.api.entity.DeviceImage; |
|
|
|
import com.yxt.supervise.monitor.api.vo.PageVo; |
|
|
|
import com.yxt.supervise.monitor.biz.scheduled.SyncService; |
|
|
|
import com.yxt.supervise.monitor.biz.util.HttpUtils; |
|
|
|
import com.yxt.supervise.monitor.biz.util.ImageCompareUtil; |
|
|
|
import com.yxt.supervise.monitor.biz.util.ImageDownloadUtil; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Service |
|
|
@ -39,6 +43,8 @@ public class YDeviceImageService extends ServiceImpl<YDeviceImageMapper, DeviceI |
|
|
|
queryWrapper.eq("type", searchVo.get("type")); |
|
|
|
} |
|
|
|
queryWrapper.eq("isDelete", 0); |
|
|
|
queryWrapper.eq("isShow", 1); |
|
|
|
queryWrapper.orderByAsc("channelNo"); |
|
|
|
|
|
|
|
IPage<DeviceImage> athleteBOIPage = null; |
|
|
|
try { |
|
|
@ -51,9 +57,9 @@ public class YDeviceImageService extends ServiceImpl<YDeviceImageMapper, DeviceI |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void getDeviceImageBefore() { |
|
|
|
public void getImage(String channelNo) { |
|
|
|
// 访问接口 把图片保存到本地
|
|
|
|
String url = "https://api2.hik-cloud.com/api/v1/open/basic/channels/actions/capture"; |
|
|
|
String channelNo = "4"; |
|
|
|
String picName = ""; |
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("deviceSerial", "L20560109"); // 设备序列号 string
|
|
|
@ -67,10 +73,57 @@ public class YDeviceImageService extends ServiceImpl<YDeviceImageMapper, DeviceI |
|
|
|
String day = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"); |
|
|
|
picName = day + channelNo + ".png"; |
|
|
|
try { |
|
|
|
ImageDownloadUtil.download(picUrl,SyncService.imagePath,picName); |
|
|
|
ImageDownloadUtil.download(picUrl, SyncService.imagePath + channelNo, picName); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 入库操作
|
|
|
|
QueryWrapper<DeviceImage> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq("isShow", "1"); |
|
|
|
wrapper.eq("channelNo", channelNo); |
|
|
|
wrapper.orderByDesc("createTime"); |
|
|
|
List<DeviceImage> deviceImageList = this.list(wrapper); |
|
|
|
|
|
|
|
DeviceImage deviceImage = new DeviceImage(); |
|
|
|
deviceImage.setDeviceSerial("L20560109"); |
|
|
|
deviceImage.setCreateTime(new Date()); |
|
|
|
deviceImage.setChannelNo(channelNo); |
|
|
|
deviceImage.setIsShow("1"); |
|
|
|
|
|
|
|
if (deviceImageList.size() > 0) { |
|
|
|
DeviceImage deviceImageExit = deviceImageList.get(0); |
|
|
|
String convertImage = deviceImageExit.getImgAfter(); |
|
|
|
deviceImage.setImgBefore(convertImage); |
|
|
|
deviceImage.setImgAfter(SyncService.imagePath + channelNo + "/" + picName); |
|
|
|
String similar = String.valueOf(ImageCompareUtil.compareImage(convertImage, SyncService.imagePath + channelNo + "/" + picName)); |
|
|
|
String[] similarSplit = similar.split("\\."); |
|
|
|
if (similarSplit.length > 0) { |
|
|
|
deviceImage.setSimilarity(similarSplit[0] + "%"); |
|
|
|
}else{ |
|
|
|
deviceImage.setSimilarity(similar + "%"); |
|
|
|
} |
|
|
|
deviceImage.setModifyTime(new Date()); |
|
|
|
|
|
|
|
// 添加之前先把历史数据isShow改成不展示
|
|
|
|
this.flushDeviceImageIsShow(channelNo); |
|
|
|
this.save(deviceImage); |
|
|
|
} else { |
|
|
|
deviceImage.setImgBefore(SyncService.imagePath + channelNo + "/" + picName); |
|
|
|
deviceImage.setImgAfter(SyncService.imagePath + channelNo + "/" + picName); |
|
|
|
deviceImage.setSimilarity("100%"); |
|
|
|
this.save(deviceImage); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void flushDeviceImageIsShow(String channelNo) { |
|
|
|
UpdateWrapper<DeviceImage> wrapper = new UpdateWrapper<>(); |
|
|
|
wrapper.eq("channelNo", channelNo); |
|
|
|
wrapper.set("isShow", 0); |
|
|
|
this.update(wrapper); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|