| | |
| | | import com.arcsoft.face.FaceEngine; |
| | | import com.arcsoft.face.toolkit.ImageFactory; |
| | | import com.arcsoft.face.toolkit.ImageInfo; |
| | | import com.whyc.constant.UserOperation; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.factory.FaceEngineFactory; |
| | | import com.whyc.pojo.PermitGroup; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.service.FaceService; |
| | | import com.whyc.service.PermitGroupUserService; |
| | | import com.whyc.service.UserService; |
| | | import com.whyc.service.*; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.FaceIdentifyUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import sun.misc.BASE64Decoder; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @Resource |
| | | private MapOutlineService mapOutlineService; |
| | | |
| | | @Autowired |
| | | private BaoJiGroupUserService baoJiGroupUserService; |
| | | |
| | | @GetMapping("activeOnline") |
| | | @ApiOperation(value = "在线激活人脸识别引擎",notes = "只需要刚开始时调用一次,会导致appId与硬件设备绑定,必须有外部网络,否则激活会失败!" + |
| | |
| | | |
| | | //文件全路径 |
| | | String fileName = fileDirName + File.separator + uName + ".jpg"; |
| | | |
| | | FileOutputStream fot=null; |
| | | try { |
| | | FileOutputStream fot = new FileOutputStream(fileName); |
| | | |
| | | fot = new FileOutputStream(fileName); |
| | | fot.write(dataBytes); |
| | | fot.flush(); |
| | | fot.close(); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if(fot!=null){ |
| | | try { |
| | | fot.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /*=========数据库表更新===========*/ |
| | |
| | | * 人脸库管理: 更新 |
| | | * @return |
| | | */ |
| | | @PutMapping |
| | | @PostMapping("update") |
| | | @ApiOperation(value = "更新") |
| | | public Response update(@RequestBody String fileData,@RequestParam String uName){ |
| | | //传参,uName,fileData--文件流 |
| | |
| | | |
| | | //文件全路径 |
| | | String fileName = fileDirName + File.separator + uName + ".jpg"; |
| | | |
| | | FileOutputStream fot =null; |
| | | try { |
| | | FileOutputStream fot = new FileOutputStream(fileName); |
| | | |
| | | fot = new FileOutputStream(fileName); |
| | | fot.write(dataBytes); |
| | | fot.flush(); |
| | | fot.close(); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if(fot!=null){ |
| | | try { |
| | | fot.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return new Response().setII(1,"更新成功"); |
| | | } |
| | |
| | | * 人脸库管理: 删除 |
| | | * @return |
| | | */ |
| | | @DeleteMapping |
| | | @PostMapping("delete") |
| | | @ApiOperation(value = "删除") |
| | | @Transactional |
| | | public Response delete(@RequestParam Integer uId,@RequestParam Integer faceId, |
| | |
| | | */ |
| | | @PostMapping("faceCompare2N") |
| | | @ApiOperation(value = "人脸识别对比") |
| | | public Response faceCompare2N(@RequestBody String fileData,@RequestParam String uKeyId){ |
| | | public Response faceCompare2N(@RequestBody String fileData,@RequestParam String uKeyId,HttpServletRequest request){ |
| | | Response res = new Response(); |
| | | //先验证uKeyId对应的用户 |
| | | UserInf userByUKeyId = userService.getUserByUKeyId(uKeyId); |
| | |
| | | if (res.getCode() == 1) { |
| | | res = FaceIdentifyUtil.orientAndPxDetect(faceEngine, imageInfo); |
| | | //人像角度,大小校验通过 |
| | | if(res.getCode()==1) { |
| | | if((boolean) res.getData()) { |
| | | //重置标识 |
| | | res.setData(null); |
| | | res.setMsg(null); |
| | | //获取数据库中所有的人脸图片 |
| | | List<UserInf> userInfList = service.findAllFaceUrl(); |
| | | if(userInfList.size()==0){ |
| | | res.setCode(0); |
| | | res.setMsg("人脸库暂无任何数据"); |
| | | }else{ |
| | | boolean urlExist = false; |
| | | for (UserInf temp:userInfList){ |
| | | String filePath = temp.getFace().getUrl(); |
| | | File file = new File(filePath); |
| | | //不存在则不继续执行 |
| | | if(!file.exists()){ |
| | | continue; |
| | | }else{ |
| | | urlExist = true; |
| | | } |
| | | ImageInfo imageInfo2 = ImageFactory.getRGBData(file); |
| | | res = FaceIdentifyUtil.faceCompare(faceEngine, imageInfo, imageInfo2); |
| | | //对比成功,记录用户登录信息 |
| | | if(res.getCode()==1){ |
| | | if((boolean) res.getData()){ |
| | | //Ukey对应用户和人脸对应用户验证 |
| | | if(!temp.getUId().equals(userByUKeyId.getUId())){ |
| | | return res.set(1,false,"UKey对应用户和当前人脸对应用户不匹配"); |
| | | } |
| | | res.setData2(temp); |
| | | List<Object> dataList = new ArrayList<>(); |
| | | dataList.add(temp); |
| | | |
| | | // 将登陆成功的用户存入session |
| | | ServletContext servletContext = request.getServletContext(); |
| | | servletContext.setAttribute(temp.getUName(), request.getSession().getId()); |
| | | ActionUtil.getSession().setAttribute("user", temp); |
| | | |
| | | //设置session不活动时间为30分 |
| | |
| | | ActionUtil.getSession().setAttribute("ip", ActionUtil.getRequest().getRemoteAddr()); |
| | | List<PermitGroup> permitList = permitGroupUserService.getPermitByUser(temp.getUId()); |
| | | if (permitList!=null && permitList.size()!=0) { |
| | | dataList.add(permitList.get(0).getPermitGroupId()); |
| | | ActionUtil.getSession().setAttribute("permits", permitList); |
| | | } else { |
| | | res.setCode(1); |
| | | res.setData(false); |
| | | res.setMsg("还未分配权限"); |
| | | } |
| | | |
| | | //查询用户对应的班组标识 |
| | | dataList.add(baoJiGroupUserService.getGroupFlag(temp.getUId().intValue())); |
| | | //查询激活的地图 |
| | | String mapName = mapOutlineService.selectMapName(); |
| | | dataList.add(mapName); |
| | | CommonUtil.record(temp.getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | res.setData2(dataList); |
| | | |
| | | //将新登录的用户存入application |
| | | userService.setApplication(temp); |
| | | } |
| | | } |
| | | if(!urlExist){ |
| | | res.set(1,false,"ukey对应的人脸库路径不存在"); |
| | | } |
| | | } |
| | | } |
| | | } |