| | |
| | | import cn.exrick.xboot.file.service.FileService; |
| | | import cn.exrick.xboot.your.entity.Alarm; |
| | | import cn.exrick.xboot.your.entity.Car; |
| | | import cn.exrick.xboot.your.entity.EventLog; |
| | | import cn.exrick.xboot.your.service.IAlarmService; |
| | | import cn.exrick.xboot.your.service.ICarService; |
| | | import cn.exrick.xboot.your.service.IEventLogService; |
| | | import cn.exrick.xboot.your.util.FaceSystem; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.google.gson.Gson; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Collection; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | //人脸比对检测车厢异常开启 |
| | | @RestController |
| | | @Api(tags = "人脸比对检测车厢异常开启") |
| | | @RequestMapping("/hk") |
| | | public class FaceImgController { |
| | | |
| | |
| | | private IAlarmService iAlarmService; |
| | | @Autowired |
| | | private RedisTemplateHelper redisTemplate; |
| | | @Autowired |
| | | private IEventLogService iEventLogService; |
| | | |
| | | |
| | | @ApiOperation(value = "人脸对比图片") |
| | | @RequestMapping(value = "/faceImg", method = RequestMethod.POST) |
| | | public void saveOrUpdate(HttpServletRequest request) throws IOException, ServletException { |
| | | OssSetting os = new Gson().fromJson(settingService.get(SettingConstant.LOCAL_OSS).getValue(), OssSetting.class); |
| | |
| | | String targetAttrs = jsonObject1.get("targetAttrs").toString(); |
| | | JSONObject jsonObject2 = JSONUtil.parseObj(targetAttrs); |
| | | String deviceName = jsonObject2.get("deviceName").toString(); |
| | | System.out.println(deviceName); |
| | | //System.out.println(deviceName); |
| | | |
| | | QueryWrapper<Car> wrapper = new QueryWrapper<Car>(); |
| | | wrapper.eq("car_no",deviceName.substring(0,deviceName.length()-1)); |
| | | Car one = iCarService.getOne(wrapper); |
| | | if(one==null){ |
| | | return; |
| | | } |
| | | |
| | | Date date1 = new Date(); |
| | | long time = date1.getTime()-2*60*1000; |
| | | Date date = new Date(time); |
| | | String format1 = DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"); |
| | | String format2 = DateUtil.format(date1,"yyyy-MM-dd HH:mm:ss"); |
| | | QueryWrapper<Alarm> awrapper = new QueryWrapper<>(); |
| | | awrapper.between("create_time",format1,format2); |
| | | awrapper.eq("car_no",one.getCarNo()); |
| | | awrapper.eq("type",5); |
| | | List<Alarm> list = iAlarmService.list(awrapper); |
| | | if(list.size()>0){ |
| | | return; |
| | | } |
| | | |
| | | User user = userService.get(one.getUserId()); |
| | | User user1 = userService.get(one.getFollowUserId()); |
| | |
| | | String avatar2 = os.getHttp() + os.getEndpoint() + "/" + f.getId(); |
| | | if(user!=null){ |
| | | String avatar = user.getAvatar(); |
| | | int result1 = FaceSystem.getResult(avatar, avatar2); |
| | | if(result1<70){ |
| | | flag++; |
| | | }else{ |
| | | deleteFile(f.getId()); |
| | | if(StrUtil.isNotEmpty(avatar)){ |
| | | int result1 = FaceSystem.getResult(avatar, avatar2); |
| | | if(result1<50){ |
| | | flag++; |
| | | }else{ |
| | | deleteFile(f.getId());//是一个人删除图片 flag=0 |
| | | //如果抓拍图片跟司机照片对比是一个人,则下面的都不执行了。 |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(user1!=null){ |
| | | //如果抓拍图片跟司机照片对比不是一个人,则再对比下配送员。 |
| | | if(user1!=null&&flag>0){ |
| | | String avatar = user1.getAvatar(); |
| | | int result1 = FaceSystem.getResult(avatar, avatar2); |
| | | if(result1<70){ |
| | | flag++; |
| | | }else{ |
| | | deleteFile(f.getId()); |
| | | if(StrUtil.isNotEmpty(avatar)){ |
| | | int result1 = FaceSystem.getResult(avatar, avatar2); |
| | | if(result1<50){ |
| | | flag++; |
| | | }else{ |
| | | deleteFile(f.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(flag>0){ |
| | | if(flag>1){ |
| | | Alarm alarm = new Alarm(); |
| | | alarm.setCarNo(one.getCarNo()); |
| | | alarm.setCarId(one.getId()); |
| | |
| | | alarm.setValue("车厢异常开启"); |
| | | alarm.setAlarmImg(avatar2); |
| | | iAlarmService.saveOrUpdate(alarm); |
| | | |
| | | EventLog eventLog = new EventLog(); |
| | | eventLog.setCarNo(one.getCarNo()); |
| | | eventLog.setType(5); |
| | | eventLog.setRefId(avatar2); |
| | | iEventLogService.saveOrUpdate(eventLog); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | System.out.println(e.toString()); |
| | | //System.out.println(e.toString()); |
| | | } |
| | | } |
| | | } |