package com.doumee.service.business.impl.hksync;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.haikang.model.HKConstants;
|
import com.doumee.core.haikang.model.param.BaseResponse;
|
import com.doumee.core.haikang.model.param.request.*;
|
import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse;
|
import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse;
|
import com.doumee.core.haikang.service.HKService;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.DateUtil;
|
import com.doumee.core.utils.FtpUtil;
|
import com.doumee.dao.business.*;
|
import com.doumee.dao.business.model.CarEvent;
|
import com.doumee.dao.business.model.Device;
|
import com.doumee.dao.business.model.DeviceEvent;
|
import com.doumee.dao.business.model.VisitEvent;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.UUID;
|
|
/**
|
* 设备信息表Service实现
|
* @author 江蹄蹄
|
* @date 2023/11/30 15:33
|
*/
|
@Service
|
@Slf4j
|
public class HkSyncImgServiceImpl extends HkSyncBaseServiceImpl {
|
|
@Autowired
|
private CarEventMapper carEventMapper;
|
@Autowired
|
private DeviceEventMapper deviceEventMapper;
|
@Autowired
|
private VisitEventMapper visitEventMapper;
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
@Override
|
@Async
|
public String downHKImgs(int type){
|
if(Constants.DEALING_HK_IMG){
|
return null ;
|
}
|
Constants.DEALING_HK_IMG =true;
|
try {
|
//查询所有访客事件记录中所有下载的海康端 抓拍照片 和 照片
|
startDealVisitImg();
|
|
//查询所有停车场事件记录中所有下载的海康端 车牌图片 和 车辆图片
|
startDealCarImg();
|
//查询所有门禁事件记录中所有下载的海康端 抓拍照片 和 身份证图片URL
|
startDealDeviceImg();
|
}catch (Exception e){
|
|
}finally {
|
Constants.DEALING_HK_IMG =false;
|
}
|
return null;
|
}
|
|
private void startDealDeviceImg() {
|
List<DeviceEvent> deviceEventList = deviceEventMapper.selectList(new QueryWrapper<DeviceEvent>().lambda()
|
.eq(DeviceEvent::getIsdeleted,Constants.ZERO)
|
.and(wrapper ->{wrapper.likeLeft(DeviceEvent::getExtEventPictureURL,HKConstants.IMG_INDEX)
|
.or()
|
.likeLeft(DeviceEvent::getExtEventIDCardPictureURL,HKConstants.IMG_INDEX) ;}));
|
Date date= new Date();
|
if(deviceEventList !=null && deviceEventList.size()>0){
|
for(DeviceEvent model:deviceEventList){
|
String img1 = model.getExtEventPictureURL();
|
String img2 = model.getExtEventIDCardPictureURL();
|
String serverIndex = model.getSvrIndexCode();//服务器编码
|
String rs1 = downHkImgToFtp(img1,serverIndex,Constants.DEVICE_EVENT_IMG);
|
String rs2 = downHkImgToFtp(img2,serverIndex,Constants.DEVICE_EVENT_IMG);
|
DeviceEvent event = new DeviceEvent();
|
event.setId(model.getId());
|
event.setEditDate(date);
|
if(StringUtils.isNotBlank(rs1)){
|
event.setExtEventPictureURL(rs1);
|
}else{
|
event.setExtEventPictureURL(img1.replace(HKConstants.IMG_INDEX, HKConstants.IMG_INDEX_ERROR));
|
}
|
if(StringUtils.isNotBlank(rs2)){
|
event.setExtEventIDCardPictureURL(rs2);
|
}else{
|
event.setExtEventIDCardPictureURL(img2.replace(HKConstants.IMG_INDEX, HKConstants.IMG_INDEX_ERROR));
|
}
|
deviceEventMapper.updateById(event);
|
}
|
}
|
|
}
|
|
private void startDealCarImg() {
|
List<CarEvent> carEventList = carEventMapper.selectList(new QueryWrapper<CarEvent>().lambda()
|
.eq(CarEvent::getIsdeleted,Constants.ZERO)
|
.and(wrapper ->{wrapper.likeLeft(CarEvent::getPlatePicUrl,HKConstants.IMG_INDEX)
|
.or()
|
.likeLeft(CarEvent::getVehiclePicUrl,HKConstants.IMG_INDEX) ;}));
|
Date date= new Date();
|
if(carEventList !=null && carEventList.size()>0){
|
for(CarEvent model:carEventList){
|
String img1 = model.getPlatePicUrl();
|
String img2 = model.getVehiclePicUrl();
|
String serverIndex = model.getSvrIndex();//服务器编码
|
String rs1 = downHkImgToFtp(img1,serverIndex,Constants.CAR_EVENT_IMG);
|
String rs2 = downHkImgToFtp(img2,serverIndex,Constants.CAR_EVENT_IMG);
|
CarEvent event = new CarEvent();
|
event.setId(model.getId());
|
event.setEditDate(date);
|
if(StringUtils.isNotBlank(rs1)){
|
event.setPlatePicUrl(rs1);
|
}else{
|
event.setPlatePicUrl(img1.replace(HKConstants.IMG_INDEX, HKConstants.IMG_INDEX_ERROR));
|
}
|
if(StringUtils.isNotBlank(rs2)){
|
event.setVehiclePicUrl(rs2);
|
}else{
|
event.setVehiclePicUrl(img2.replace(HKConstants.IMG_INDEX, HKConstants.IMG_INDEX_ERROR));
|
}
|
carEventMapper.updateById(event);
|
}
|
}
|
|
}
|
|
private void startDealVisitImg() {
|
List<VisitEvent> visitEventList = visitEventMapper.selectList(new QueryWrapper<VisitEvent>().lambda()
|
.eq(VisitEvent::getIsdeleted,Constants.ZERO)
|
.and(wrapper ->{wrapper.likeLeft(VisitEvent::getCaptureUrl,HKConstants.IMG_INDEX)
|
.or()
|
.likeLeft(VisitEvent::getPhotoUrl,HKConstants.IMG_INDEX) ;}));
|
|
Date date= new Date();
|
if(visitEventList !=null && visitEventList.size()>0){
|
for(VisitEvent model:visitEventList){
|
String img1 = model.getCaptureUrl();
|
String img2 = model.getPhotoUrl();
|
String serverIndex = model.getSvrIndexCode();//服务器编码
|
String rs1 = downHkImgToFtp(img1,serverIndex,Constants.VISIT_EVENT_IMG);
|
String rs2 = downHkImgToFtp(img2,serverIndex,Constants.VISIT_EVENT_IMG);
|
VisitEvent event = new VisitEvent();
|
event.setId(model.getId());
|
event.setEditDate(date);
|
if(StringUtils.isNotBlank(rs1)){
|
event.setCaptureUrl(rs1);
|
}else{
|
event.setCaptureUrl(img1.replace(HKConstants.IMG_INDEX, HKConstants.IMG_INDEX_ERROR));
|
}
|
if(StringUtils.isNotBlank(rs2)){
|
event.setPhotoUrl(rs2);
|
}else{
|
event.setPhotoUrl(img2.replace(HKConstants.IMG_INDEX, HKConstants.IMG_INDEX_ERROR));
|
}
|
visitEventMapper.updateById(event);
|
}
|
}
|
|
}
|
|
private String downHkImgToFtp(String img1, String serverIndex, String folder) {
|
InputStream is = null;
|
if(StringUtils.equals(folder,Constants.CAR_EVENT_IMG)){
|
//停车场抓拍图
|
CarPictureRequest param = new CarPictureRequest();
|
param.setPicUri(img1);
|
param.setAswSyscode(serverIndex);
|
is = HKService.getCarPicture(param);
|
}else if(StringUtils.equals(folder,Constants.DEVICE_EVENT_IMG)){
|
//门禁事件图片
|
DevicePictureRequest param = new DevicePictureRequest();
|
param.setPicUri(img1);
|
param.setSvrIndexCode(serverIndex);
|
is = HKService.getDevicePicture(param);
|
}else if(StringUtils.equals(folder,Constants.VISIT_EVENT_IMG)){
|
//访客事件图片
|
VisitPictureRequest param = new VisitPictureRequest();
|
param.setPicUri(img1);
|
param.setSvrIndexCode(serverIndex);
|
is = HKService.getVisitPicture(param);
|
}
|
//TODO------jiangping---------
|
try {
|
FtpUtil ftp = new FtpUtil(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_HOST).getCode(),
|
Integer.parseInt(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_PORT).getCode()),
|
systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_USERNAME).getCode(),
|
systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_PWD).getCode());
|
String date = DateUtil.getNowShortDate();
|
String fName = File.separator+date+File.separator+ UUID.randomUUID().toString()+".jpg";
|
String fileName = folder+fName;
|
boolean r = ftp.uploadInputstream(is,fileName);//上传
|
if(r){
|
log.info("【海康图片下载上传FTP失败】======================" );
|
return fName;
|
}else{
|
log.error("【海康图片下载上传FTP失败】======================" );
|
}
|
} catch (Exception e) {
|
log.error("【海康图片下载上传FTP失败】======================"+e.getMessage());
|
}
|
return null;
|
}
|
}
|