jiangping
2023-12-14 4ce54dd2d91ccdd45d6a33c5fc75b546780626be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.doumee.service.business.impl.hksync;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.AcsDeviceListRequest;
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.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 org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 设备信息表Service实现
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Service
public class HkSyncImgServiceImpl extends HkSyncBaseServiceImpl {
 
    @Autowired
    private CarEventMapper carEventMapper;
    @Autowired
    private DeviceEventMapper deviceEventMapper;
    @Autowired
    private VisitEventMapper visitEventMapper;
    @Override
    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 visitEventImg) {
        //
 
        return  null;
    }
}