package com.ycl.service.caseHandler.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.entity.caseHandler.BaseCase;
import com.ycl.entity.caseHandler.EventSource;
import com.ycl.entity.caseHandler.QuestionCategory;
import com.ycl.entity.caseHandler.Violations;
import com.ycl.entity.video.VideoAlarmReport;
import com.ycl.entity.video.VideoPoint;
import com.ycl.mapper.caseHandler.ViolationsMapper;
import com.ycl.service.caseHandler.IBaseCaseService;
import com.ycl.service.caseHandler.IViolationsService;
import com.ycl.service.video.impl.IVideoPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
/**
*
* 违规事件 服务实现类
*
*
* @author wl
* @since 2022-09-24
*/
@Service
public class ViolationsServiceImpl extends ServiceImpl implements IViolationsService {
private IVideoPointService videoPointService;
private IBaseCaseService baseCaseService;
@Autowired
public void setVideoPointService(IVideoPointService videoPointService) {
this.videoPointService = videoPointService;
}
@Autowired
public void setBaseCaseService(IBaseCaseService baseCaseService) {
this.baseCaseService = baseCaseService;
}
@Override
public void saveFromVideo(List videoAlarmReports) {
for (VideoAlarmReport videoAlarmReport : videoAlarmReports) {
VideoPoint videoPoint = null;
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(VideoPoint::getPlatResourceId, videoAlarmReport.getPlatResourceId());
List pointList = videoPointService.list(queryWrapper);
if (pointList.size() > 0) {
videoPoint = pointList.get(0);
}
BaseCase baseCase = BaseCase.builder().eventSource(EventSource.VIDEO.getCode()).category(QuestionCategory.VIOLATION.getCode())
.createTime(LocalDateTime.now()).createUser(0L).state(1).alarmTime(videoAlarmReport.getAlarmTime()).build();
Violations violations = new Violations();
if (videoPoint != null) {
baseCase.setLatitude(videoPoint.getLatitude());
baseCase.setLongitude(videoPoint.getLongitude());
baseCase.setStreetId(videoPoint.getStreetId());
baseCase.setCommunityId(videoPoint.getCommunityId());
}
baseCaseService.save(baseCase);
violations.setId(baseCase.getId());
violations.setVideoAlarmReportId(videoAlarmReport.getId());
baseMapper.insert(violations);
}
}
}