4.18 后端处理更新
This commit is contained in:
		
							parent
							
								
									fc09a4efc3
								
							
						
					
					
						commit
						d976d8824b
					
				| @ -0,0 +1,40 @@ | |||||||
|  | package com.dkha.common.modules.vo; | ||||||
|  | import com.dkha.common.modules.vo.position.PositionVO; | ||||||
|  | import com.fasterxml.jackson.annotation.JsonInclude; | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.AllArgsConstructor; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.NoArgsConstructor; | ||||||
|  | 
 | ||||||
|  | @AllArgsConstructor | ||||||
|  | @NoArgsConstructor | ||||||
|  | @Data | ||||||
|  | //@JsonInclude(JsonInclude.Include.NON_NULL) | ||||||
|  | @ApiModel(value="视频页面比对展示的vo", description="前端页面比对人脸库展示数据") | ||||||
|  | public class CompareFaceList { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "时间") | ||||||
|  |     private String time; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "原始人脸地址") | ||||||
|  |     private String cphoto; | ||||||
|  |     @ApiModelProperty(value = "比对最相似的人脸地址") | ||||||
|  |     private String rphoto; | ||||||
|  |     @ApiModelProperty(value = "比对相似度") | ||||||
|  |     private double xsd; | ||||||
|  |     @ApiModelProperty(value = "姓名") | ||||||
|  |     private String name; | ||||||
|  | //    @ApiModelProperty(value = "性别") | ||||||
|  | //    private String sex; | ||||||
|  | //    @ApiModelProperty(value = "身份证号码") | ||||||
|  | //    private String idCard; | ||||||
|  | //    @ApiModelProperty(value = "年龄") | ||||||
|  | //    private Integer age; | ||||||
|  |     @ApiModelProperty(value = "库名称") | ||||||
|  |     private String libName; | ||||||
|  | //    @ApiModelProperty(value = "库id") | ||||||
|  | //    private String libId; | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,17 @@ | |||||||
|  | package com.dkha.common.modules.vo.face; | ||||||
|  | import com.fasterxml.jackson.annotation.JsonInclude; | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import lombok.AllArgsConstructor; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.NoArgsConstructor; | ||||||
|  | 
 | ||||||
|  | @Data | ||||||
|  | @AllArgsConstructor | ||||||
|  | @NoArgsConstructor | ||||||
|  | @JsonInclude(JsonInclude.Include.NON_NULL) | ||||||
|  | @ApiModel(value = "人脸库1:1比对返回", description = "人脸检索") | ||||||
|  | public class FaceResEntity { | ||||||
|  |     private String cphoto; | ||||||
|  |     //private String rphoto; | ||||||
|  |     private String time; | ||||||
|  | } | ||||||
| @ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||||
| import org.springframework.context.ConfigurableApplicationContext; | import org.springframework.context.ConfigurableApplicationContext; | ||||||
| import org.springframework.context.annotation.Bean; | import org.springframework.context.annotation.Bean; | ||||||
| import org.springframework.scheduling.annotation.EnableScheduling; | import org.springframework.scheduling.annotation.EnableScheduling; | ||||||
|  | import com.dkha.server.controllers.WebSocketContral; | ||||||
| 
 | 
 | ||||||
| import java.net.InetSocketAddress; | import java.net.InetSocketAddress; | ||||||
| 
 | 
 | ||||||
| @ -23,6 +24,7 @@ public class FaceServerApplication { | |||||||
|         SpringApplication springApplication = new SpringApplication(FaceServerApplication.class); |         SpringApplication springApplication = new SpringApplication(FaceServerApplication.class); | ||||||
|         ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args); |         ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args); | ||||||
|         //解决WebSocket不能注入的问题 |         //解决WebSocket不能注入的问题 | ||||||
|  |         WebSocketContral.setApplicationContext(configurableApplicationContext); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -1,45 +1,21 @@ | |||||||
| package com.dkha.server.controllers; | package com.dkha.server.controllers; | ||||||
| 
 | 
 | ||||||
| import com.alibaba.fastjson.JSONObject; |  | ||||||
| import com.dkha.common.exception.DkException; |  | ||||||
| import com.dkha.common.fileupload.MinioUtil; | import com.dkha.common.fileupload.MinioUtil; | ||||||
| import com.dkha.common.page.PageParam; | import com.dkha.common.http.HttpUtil; | ||||||
|  | import com.dkha.common.modules.vo.face.FaceResEntity; | ||||||
|  | import com.dkha.common.modules.vo.CompareFaceList; | ||||||
| import com.dkha.common.result.CommonResult; | import com.dkha.common.result.CommonResult; | ||||||
| import com.dkha.common.util.ExcelUtils; | import com.google.gson.Gson; | ||||||
| import com.dkha.common.util.UtilValidate; |  | ||||||
| import com.dkha.server.annotation.NoRepeatSubmitAnnotation; |  | ||||||
| import com.dkha.server.modules.entities.FaceCameraEntity; |  | ||||||
| import com.dkha.server.modules.entities.faceCamera.FaceCameraExcel; |  | ||||||
| import com.dkha.server.modules.entities.faceCamera.FaceCameraInfo; |  | ||||||
| import com.dkha.server.modules.entities.faceCamera.InsertFaceCamera; |  | ||||||
| import com.dkha.server.services.FaceCameraService; |  | ||||||
| import com.dkha.server.system.modules.sys.entity.SysRegionEntity; |  | ||||||
| import com.dkha.server.system.modules.sys.enums.RegionLevelEnum; |  | ||||||
| import com.dkha.server.system.modules.sys.service.SysRegionService; |  | ||||||
| import com.dkha.server.util.RequestUtil; |  | ||||||
| import io.swagger.annotations.Api; |  | ||||||
| import io.swagger.annotations.ApiOperation; |  | ||||||
| import io.swagger.annotations.ApiParam; |  | ||||||
| import lombok.Data; |  | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.apache.shiro.authz.annotation.RequiresPermissions; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.beans.factory.annotation.Value; | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
| import org.springframework.web.multipart.MultipartFile; |  | ||||||
| import sun.misc.BASE64Decoder; |  | ||||||
| 
 | 
 | ||||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||||
| import javax.servlet.http.HttpServletRequest; |  | ||||||
| import javax.servlet.http.HttpServletResponse; |  | ||||||
| import javax.validation.Valid; |  | ||||||
| import java.io.ByteArrayInputStream; |  | ||||||
| import java.io.IOException; |  | ||||||
| import java.io.InputStream; |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.*; | import java.util.*; | ||||||
| 
 | 
 | ||||||
| import static com.dkha.common.systemcode.SystemCode.EXCEL_ERROR_DATA; |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| @RestController | @RestController | ||||||
| @RequestMapping("faces") | @RequestMapping("faces") | ||||||
| @ -47,18 +23,27 @@ import static com.dkha.common.systemcode.SystemCode.EXCEL_ERROR_DATA; | |||||||
| public class FaceController extends CommonResult { | public class FaceController extends CommonResult { | ||||||
|     @Resource |     @Resource | ||||||
|     private MinioUtil minioUtil; |     private MinioUtil minioUtil; | ||||||
|  |     @Value("${api.server.prefix}") | ||||||
|  |     private String apiServerPrefix; | ||||||
|  |     @Autowired | ||||||
|  |     private HttpUtil httpUtil; | ||||||
|  |     @Autowired | ||||||
|  |     private Gson gson; | ||||||
|  |     private  int count ; | ||||||
| 
 | 
 | ||||||
|     private  Map<String,FaceResEntity> faceRes = new HashMap<>(); |     private  Map<String,FaceResEntity> faceRes = new HashMap<>(); | ||||||
| 
 | 
 | ||||||
|     private List<FaceResEntity> list = new ArrayList<>(); |     private List<FaceResEntity> facelist = new ArrayList<>(); | ||||||
|  | 
 | ||||||
|  |     private List<CompareFaceList> compareFaceLists = new ArrayList<>(); | ||||||
|     public  FaceController(){ |     public  FaceController(){ | ||||||
|         FaceResEntity  resEntity = new FaceResEntity(); |         //FaceResEntity  resEntity = new FaceResEntity(); | ||||||
|         resEntity.setName("jhx"); |         //resEntity.setTime("jhx"); | ||||||
|         resEntity.setRphoto("http://192.168.60.52:9000/school/face/jhx.jpg"); |         // resEntity.setRphoto("http://192.168.60.52:9000/school/face/jhx.jpg"); | ||||||
|         faceRes.put("eYJST7eY2mbnjGZvywPfxg==",resEntity); |         //faceRes.put("eYJST7eY2mbnjGZvywPfxg==",resEntity); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @RequestMapping("callback") |     /*@RequestMapping("callback") | ||||||
|     public String callback(HttpServletRequest request) throws IOException { |     public String callback(HttpServletRequest request) throws IOException { | ||||||
|         try { |         try { | ||||||
|         String streamText = RequestUtil.getStreamText(request); |         String streamText = RequestUtil.getStreamText(request); | ||||||
| @ -69,13 +54,14 @@ public class FaceController extends CommonResult { | |||||||
|         byte[] _byte =  new BASE64Decoder().decodeBuffer(str); |         byte[] _byte =  new BASE64Decoder().decodeBuffer(str); | ||||||
|         InputStream inputStream = new ByteArrayInputStream(_byte); |         InputStream inputStream = new ByteArrayInputStream(_byte); | ||||||
| 
 | 
 | ||||||
|         String  object1 =   "http://192.168.60.52:9000/test/"+minioUtil.uploadImage(inputStream,"").getString("path"); |         String  object1 =   "http://192.168.1.133:9000/middleware/"+minioUtil.uploadImage(inputStream,"").getString("path"); | ||||||
|         System.out.println(object1); |         System.out.println(object1); | ||||||
|             if( faceRes.get(object.getString("ImageID"))!=null){ |             if( faceRes.get(object.getString("ImageID"))!=null){ | ||||||
|                 FaceResEntity resEntity =  faceRes.get(object.getString("ImageID")); |                 FaceResEntity resEntity =  faceRes.get(object.getString("ImageID")); | ||||||
|                 resEntity.setCphoto(object1); |                 resEntity.setCphoto(object1); | ||||||
|                 resEntity.setXsd(xsd.substring(0,5)); |                 //resEntity.setXsd(xsd.substring(0,5)); | ||||||
|                 list.add(resEntity); |                 list.add(resEntity); | ||||||
|  | 
 | ||||||
|             } |             } | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
| @ -85,10 +71,88 @@ public class FaceController extends CommonResult { | |||||||
| 
 | 
 | ||||||
|     @GetMapping("list") |     @GetMapping("list") | ||||||
|     public List<FaceResEntity> getList(){ |     public List<FaceResEntity> getList(){ | ||||||
|  |         list.clear(); | ||||||
|  |         //System.out.println("返回list测试:" + list); | ||||||
|  |         //String testUrl = apiServerPrefix + ApiUrlEnum.FACE_SEARCH.getUrl(); | ||||||
|  |         String testUrl = "http://192.168.1.196:5000/cutimage"; | ||||||
|  |         System.out.println("testurl:"+ testUrl); | ||||||
|  |         ReturnVO returnVO = (ReturnVO) httpUtil.post(testUrl, null, ReturnVO.class); | ||||||
|  |         List<FaceResEntity> resEntity = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<FaceResEntity>>() {}); | ||||||
|  |         //FaceResEntity  resEntity = new FaceResEntity(); | ||||||
|  |         //resEntity.setName("ceshi"); | ||||||
|  |         //resEntity.setCphoto("http://192.168.1.133:9000/middleware/103/1028345463.jpg"); | ||||||
|  |         for(FaceResEntity res :resEntity) { | ||||||
|  |             System.out.println("resEntity cphoto:"+ res.getCphoto()); | ||||||
|  |             list.add(res); | ||||||
|  |         } | ||||||
|  |         System.out.println("返回list测试:" + list); | ||||||
|         return list; |         return list; | ||||||
|  |         //return (List<FaceResEntity>) successResult(list); | ||||||
|  |     } | ||||||
|  | */ | ||||||
|  |     @GetMapping( "returnList") | ||||||
|  |     public List<FaceResEntity> returnList(){ | ||||||
|  |         System.out.println("开始returnlist"); | ||||||
|  |         System.out.println(facelist.size()); | ||||||
|  |         return facelist; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| /*    @GetMapping("one") | 
 | ||||||
|  |     //从算法端获取图片列表接口 | ||||||
|  |     @PostMapping("/getList") | ||||||
|  |     public void getList( | ||||||
|  |             @RequestBody List<FaceResEntity> resEntities) { | ||||||
|  |         System.out.println("getlist被请求"); | ||||||
|  |         facelist.clear(); | ||||||
|  |         //System.out.println(resEntities); | ||||||
|  |         for (FaceResEntity res :resEntities){ | ||||||
|  |             count++; | ||||||
|  |             facelist.add(res); | ||||||
|  |         } | ||||||
|  |         System.out.println(facelist); | ||||||
|  |         WebSocketContral webSocketContral =new WebSocketContral(); | ||||||
|  |         webSocketContral.sendMessage(gson.toJson(facelist)); | ||||||
|  |         //webSocketContral.sendMessage("发送websocket信息中"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public  void sendWebsocket1(List<FaceResEntity> onfacelist){ | ||||||
|  |         facelist.clear(); | ||||||
|  |         facelist = onfacelist; | ||||||
|  |         WebSocketContral webSocketContral =new WebSocketContral(); | ||||||
|  |         System.out.println("facelist"+ facelist); | ||||||
|  |         System.out.println("GSON" + gson.toJson(facelist)); | ||||||
|  |         webSocketContral.sendMessage(gson.toJson(facelist)); | ||||||
|  |         //webSocketContral.sendMessage("发送websocket信息中"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public  void sendWebsocket2(List<CompareFaceList> oncompareFacelist){ | ||||||
|  |         compareFaceLists.clear(); | ||||||
|  |         compareFaceLists = oncompareFacelist; | ||||||
|  |         WebSocketContral webSocketContral =new WebSocketContral(); | ||||||
|  |         webSocketContral.sendMessage(gson.toJson(oncompareFacelist)); | ||||||
|  |         //webSocketContral.sendMessage("发送websocket信息中"); | ||||||
|  |         System.out.println("list:"+ oncompareFacelist); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @PostMapping("/compareList") | ||||||
|  |     public void compareList( | ||||||
|  |             @RequestBody List<CompareFaceList> compareFaceLists ){ | ||||||
|  | //        String compareURL = apiServerPrefix + ApiUrlEnum.ALARMS_POSTURL.getUrl(); | ||||||
|  | //        ReturnVO returnVO = (ReturnVO) httpUtil.post(compareURL, list, ApiVO.class); | ||||||
|  | //        CompareFaceList compareFaceList = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<CompareFaceList>() {}); | ||||||
|  | //        compareFaceLists.add(compareFaceList); | ||||||
|  | //        return successResult(compareFaceLists); | ||||||
|  |         compareFaceLists.clear(); | ||||||
|  |         for(CompareFaceList com: compareFaceLists ){ | ||||||
|  |             compareFaceLists.add(com); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public List<FaceResEntity> getFacelist() { | ||||||
|  |         return this.facelist; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /*    @GetMapping("one") | ||||||
|     public List<String getOne(){ |     public List<String getOne(){ | ||||||
|         if(list.isEmpty()){ |         if(list.isEmpty()){ | ||||||
|             return  ""; |             return  ""; | ||||||
| @ -97,17 +161,4 @@ public class FaceController extends CommonResult { | |||||||
|     }*/ |     }*/ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     @Data |  | ||||||
|     public class FaceResEntity |  | ||||||
|     { |  | ||||||
|         private String cphoto; |  | ||||||
|         private String rphoto; |  | ||||||
|         private String name; |  | ||||||
|         private String xsd; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -138,6 +138,7 @@ public class IndexContral extends  CommonResult{ | |||||||
|         myMap.put("faceNumber",faceNumber); |         myMap.put("faceNumber",faceNumber); | ||||||
|         myMap.put("taskNumber",taskNumber); |         myMap.put("taskNumber",taskNumber); | ||||||
|         myMap.put("warnNumber",warnNumber); |         myMap.put("warnNumber",warnNumber); | ||||||
|  |         //myMap.put("warnNumber",4); | ||||||
|         myMap.put("daysOfOperation",daysOfOperation); |         myMap.put("daysOfOperation",daysOfOperation); | ||||||
|         return successResult(myMap); |         return successResult(myMap); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -0,0 +1,19 @@ | |||||||
|  | package com.dkha.server.controllers; | ||||||
|  | 
 | ||||||
|  | import org.springframework.context.annotation.Bean; | ||||||
|  | import org.springframework.context.annotation.Configuration; | ||||||
|  | import org.springframework.web.socket.server.standard.ServerEndpointExporter; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @Author Spring | ||||||
|  |  * @Since 2019/9/12 20:10 | ||||||
|  |  * @Description | ||||||
|  |  */ | ||||||
|  | @Configuration | ||||||
|  | public class WebSocketConfig { | ||||||
|  | 
 | ||||||
|  |     @Bean | ||||||
|  |     public ServerEndpointExporter serverEndpointExporter() { | ||||||
|  |         return new ServerEndpointExporter(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,197 @@ | |||||||
|  | package com.dkha.server.controllers; | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.concurrent.ConcurrentHashMap; | ||||||
|  | import java.util.concurrent.CopyOnWriteArraySet; | ||||||
|  | import com.alibaba.fastjson.JSONObject; | ||||||
|  | import com.dkha.common.enums.ApiUrlEnum; | ||||||
|  | import com.dkha.common.exception.DkException; | ||||||
|  | import com.dkha.common.fileupload.MinioUtil; | ||||||
|  | import com.dkha.common.http.HttpUtil; | ||||||
|  | import com.dkha.common.modules.vo.ReturnVO; | ||||||
|  | import com.dkha.common.util.JsonUtil; | ||||||
|  | import com.dkha.common.util.UtilValidate; | ||||||
|  | import com.dkha.server.services.ICompareService; | ||||||
|  | import com.dkha.server.services.IFileService; | ||||||
|  | import com.fasterxml.jackson.core.type.TypeReference; | ||||||
|  | import org.apache.poi.ss.formula.functions.T; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.beans.factory.annotation.Value; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | import javax.websocket.OnClose; | ||||||
|  | import javax.websocket.OnMessage; | ||||||
|  | import javax.websocket.OnOpen; | ||||||
|  | import javax.websocket.Session; | ||||||
|  | import javax.websocket.server.ServerEndpoint; | ||||||
|  | 
 | ||||||
|  | import com.dkha.common.enums.ErrEnum; | ||||||
|  | import com.dkha.common.enums.SocketEnum; | ||||||
|  | import com.dkha.common.modules.vo.face.FaceResEntity; | ||||||
|  | import com.dkha.common.redis.RedisUtils; | ||||||
|  | import com.dkha.common.util.UtilValidate; | ||||||
|  | //import com.dkha.task.comm.TimerData; | ||||||
|  | //import com.dkha.task.modual.mapper.SysUserTokenDao; | ||||||
|  | //import com.dkha.task.modual.vo.BayonetVO; | ||||||
|  | import com.dkha.common.modules.vo.ReturnVO; | ||||||
|  | import com.dkha.common.util.JsonUtil; | ||||||
|  | import com.dkha.common.modules.vo.CompareFaceList; | ||||||
|  | import com.google.gson.Gson; | ||||||
|  | import org.springframework.context.ApplicationContext; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | 
 | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | @ServerEndpoint("/webSocketServer") | ||||||
|  | @Slf4j | ||||||
|  | public class WebSocketContral { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     private Session session; | ||||||
|  |     private Gson gson=new Gson(); | ||||||
|  | 
 | ||||||
|  |     private static CopyOnWriteArraySet<WebSocketContral> webSocketSet=new CopyOnWriteArraySet<WebSocketContral>(); | ||||||
|  |     public static Map<String, WebSocketContral> myMap=new ConcurrentHashMap(); | ||||||
|  | 
 | ||||||
|  |     private RedisUtils redisUtils; | ||||||
|  |     //此处是解决无法注入的关键 | ||||||
|  |     private static ApplicationContext applicationContext; | ||||||
|  |     //要注入的service或者dao | ||||||
|  | //    private SysUserTokenDao sysUserTokenDao; | ||||||
|  | 
 | ||||||
|  |     public static void setApplicationContext(ApplicationContext applicationContext) { | ||||||
|  |         WebSocketContral.applicationContext = applicationContext; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @OnOpen | ||||||
|  |     public void opOpen(Session session) | ||||||
|  |     { | ||||||
|  |         redisUtils =applicationContext.getBean(RedisUtils.class); | ||||||
|  |         this.session=session; | ||||||
|  |         if(myMap.containsKey(session.getId())) | ||||||
|  |         { | ||||||
|  |             try { | ||||||
|  |                 this.session.close(); | ||||||
|  |             } catch (IOException e) { | ||||||
|  |             } | ||||||
|  | //            log.error("已经存在"); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | //        sysUserTokenDao=applicationContext.getBean(SysUserTokenDao.class); | ||||||
|  | //		String time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()); | ||||||
|  | //		SysUserTokenEntity sysUserTokenEntity= null;//sysUserTokenDao.getByToken(token,time); | ||||||
|  | //		if(UtilValidate.isEmpty(sysUserTokenEntity)) | ||||||
|  | //		{ | ||||||
|  | //		    log.error("token过期"); | ||||||
|  | //            sessionSendMsg(session,gson.toJson(new ReturnVO(ErrEnum.UNAUTHORIZED))); | ||||||
|  | //            try { | ||||||
|  | //                this.session.close(); | ||||||
|  | //            } catch (Exception e) { | ||||||
|  | //            } | ||||||
|  | //            return; | ||||||
|  | //        } | ||||||
|  | //		//广播使用 | ||||||
|  | //        redisUtils.set("token",token); | ||||||
|  | //        //对应使用 | ||||||
|  | //        redisUtils.set(RedisKeys.getSessionIdKey(session.getId()),token); | ||||||
|  | //        TimerData.tokens.put(session.getId(),token); | ||||||
|  |         webSocketSet.add(this); | ||||||
|  |         myMap.put(session.getId(), this); | ||||||
|  | //		log.info(session.getId()+"【websocket消息】有新的连接,总数:{},{},{}",webSocketSet.size(),myMap.size(),token); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  |     @OnClose | ||||||
|  |     public void onClose() | ||||||
|  |     { | ||||||
|  | //		log.info(this.session.getId()+"【websocket消息】连接断开,总数:{},{}",webSocketSet.size(),myMap.size()); | ||||||
|  | //        if(TimerData.bayonetMap.containsKey(this.session.getId())) { | ||||||
|  | //            TimerData.bayonetMap.remove(this.session.getId()); | ||||||
|  | //        } | ||||||
|  |         myMap.remove(this.session.getId()); | ||||||
|  |         webSocketSet.remove(this); | ||||||
|  | //        log.info("关闭成功{},{},{}",webSocketSet.size(),myMap.size(),TimerData.bayonetMap.size()); | ||||||
|  |     } | ||||||
|  |     @OnMessage | ||||||
|  |     public void onMessage(String message) | ||||||
|  |     { | ||||||
|  | //        log.error("接收数据:{}",message); | ||||||
|  | //        if(UtilValidate.isEmpty(this.session) || this.session.isOpen()==false){return;} | ||||||
|  |         //System.out.println(message); | ||||||
|  |         if(UtilValidate.isNotEmpty(message)) | ||||||
|  |         { | ||||||
|  |             ReturnVO returnVO=gson.fromJson(message,ReturnVO.class); | ||||||
|  |             System.out.println(message); | ||||||
|  |             System.out.println(returnVO.getMessage()); | ||||||
|  |             System.out.println(returnVO.getMessage().getClass()); | ||||||
|  |             if(returnVO.getMessage().equals("okpro")) { | ||||||
|  |                 System.out.println("进入第一个方法"); | ||||||
|  |                 if (UtilValidate.isNotEmpty(returnVO.getData())) { | ||||||
|  |                     // List<FaceResEntity> facelist =gson.fromJson(gson.toJson(returnVO.getData()),List<FaceResEntity>.class); | ||||||
|  |                     List<FaceResEntity> onfacelist = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<FaceResEntity>>() {}); | ||||||
|  |                     FaceController faceController = new FaceController(); | ||||||
|  |                     faceController.sendWebsocket1(onfacelist); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             else if(returnVO.getMessage().equals("okplus")){ | ||||||
|  |                 if (UtilValidate.isNotEmpty(returnVO.getData())) { | ||||||
|  |                     // List<FaceResEntity> facelist =gson.fromJson(gson.toJson(returnVO.getData()),List<FaceResEntity>.class); | ||||||
|  |                     List<CompareFaceList> oncompareFaceLists = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<CompareFaceList>>() {}); | ||||||
|  |                     FaceController faceController = new FaceController(); | ||||||
|  |                     faceController.sendWebsocket2(oncompareFaceLists); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } | ||||||
|  | 	    log.info("【websocket消息】收到客户端消息:{}",message); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 给指定id用户推送信息 | ||||||
|  |      * @param message | ||||||
|  |      */ | ||||||
|  |     public void sendMessage(String id,String message) | ||||||
|  |     { | ||||||
|  |         for(WebSocketContral websocket:webSocketSet) | ||||||
|  |         { | ||||||
|  |             if(websocket.session.getId().equals(id)) | ||||||
|  |             { | ||||||
|  | //                log.info("【websocket消息】给ID={}发送消息,message={}",id,message); | ||||||
|  |                 sessionSendMsg(websocket.session,message); | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * 群发消息调用 | ||||||
|  |      * @param message | ||||||
|  |      */ | ||||||
|  |     public void sendMessage(String message) | ||||||
|  |     { | ||||||
|  |         for(WebSocketContral websocket:webSocketSet) | ||||||
|  |         { | ||||||
|  | //			log.info("【websocket消息】广播消息,message={}",message); | ||||||
|  |             sessionSendMsg(websocket.session,message); | ||||||
|  |             System.out.println("后台在发送websocket信息"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 发送消息 | ||||||
|  |      * @param session | ||||||
|  |      * @param message | ||||||
|  |      */ | ||||||
|  |     private void sessionSendMsg(Session session,String message) | ||||||
|  |     { | ||||||
|  |         try { | ||||||
|  |             session.getBasicRemote().sendText(message); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             log.error("socket发送消息错误:"+e.getMessage()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -169,7 +169,7 @@ public class CompareServiceImpl implements ICompareService { | |||||||
|     private void validateSingleFaceImage(String image) { |     private void validateSingleFaceImage(String image) { | ||||||
|         //人脸检测url |         //人脸检测url | ||||||
|         String faceSearchUrl = apiRequestPrefix + ApiUrlEnum.FACE_SEARCH.getUrl(); |         String faceSearchUrl = apiRequestPrefix + ApiUrlEnum.FACE_SEARCH.getUrl(); | ||||||
|         //String faceSearchUrltest ="http://192.168.3.135:5000/message/mask"; |         //String faceSearchUrltest ="http://192.168.3.123:5001/message/mask"; | ||||||
|         //组装api请求数据 |         //组装api请求数据 | ||||||
|         ReturnVO returnVO = (ReturnVO) httpUtil.post(faceSearchUrl + "?url=" + image, null, ReturnVO.class); |         ReturnVO returnVO = (ReturnVO) httpUtil.post(faceSearchUrl + "?url=" + image, null, ReturnVO.class); | ||||||
|         System.out.println(returnVO.getCode()+returnVO.getMessage()); |         System.out.println(returnVO.getCode()+returnVO.getMessage()); | ||||||
|  | |||||||
| @ -71,6 +71,7 @@ public class ShiroConfig { | |||||||
|         filterMap.put("/webjars/**", "anon"); |         filterMap.put("/webjars/**", "anon"); | ||||||
|         filterMap.put("/druid/**", "anon"); |         filterMap.put("/druid/**", "anon"); | ||||||
|         filterMap.put("/login", "anon"); |         filterMap.put("/login", "anon"); | ||||||
|  |         filterMap.put("/webSocketServer", "anon"); | ||||||
|         filterMap.put("/swagger/**", "anon"); |         filterMap.put("/swagger/**", "anon"); | ||||||
|         filterMap.put("/v2/api-docs", "anon"); |         filterMap.put("/v2/api-docs", "anon"); | ||||||
|         filterMap.put("/swagger-ui.html", "anon"); |         filterMap.put("/swagger-ui.html", "anon"); | ||||||
|  | |||||||
| @ -70,6 +70,8 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl<SysUserTokenDao, Sy | |||||||
|             tokenEntity.setUpdateDate(now); |             tokenEntity.setUpdateDate(now); | ||||||
|             tokenEntity.setExpireDate(expireTime); |             tokenEntity.setExpireDate(expireTime); | ||||||
| 
 | 
 | ||||||
|  |             System.out.println(token); | ||||||
|  | 
 | ||||||
|             //更新token |             //更新token | ||||||
|             this.updateById(tokenEntity); |             this.updateById(tokenEntity); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -49,7 +49,6 @@ public class SysMenuController { | |||||||
| 	public Result<List<SysMenuDTO>> nav(){ | 	public Result<List<SysMenuDTO>> nav(){ | ||||||
| 		UserDetail user = SecurityUser.getUser(); | 		UserDetail user = SecurityUser.getUser(); | ||||||
| 		List<SysMenuDTO> list = sysMenuService.getUserMenuList(user, MenuTypeEnum.MENU.value()); | 		List<SysMenuDTO> list = sysMenuService.getUserMenuList(user, MenuTypeEnum.MENU.value()); | ||||||
| 
 |  | ||||||
| 		return new Result<List<SysMenuDTO>>().ok(list); | 		return new Result<List<SysMenuDTO>>().ok(list); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -99,6 +99,7 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuDao, SysMenuEntit | |||||||
| 		//系统管理员,拥有最高权限 | 		//系统管理员,拥有最高权限 | ||||||
| 		if(user.getSuperAdmin() == SuperAdminEnum.YES.value()){ | 		if(user.getSuperAdmin() == SuperAdminEnum.YES.value()){ | ||||||
| 			menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage()); | 			menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage()); | ||||||
|  | 			System.out.println("menuListsize:"+ menuList.size()); | ||||||
| 		}else { | 		}else { | ||||||
| 			menuList = baseDao.getUserMenuList(user.getId(), type, HttpContextUtils.getLanguage()); | 			menuList = baseDao.getUserMenuList(user.getId(), type, HttpContextUtils.getLanguage()); | ||||||
| 		} | 		} | ||||||
|  | |||||||
							
								
								
									
										44
									
								
								face-task/src/main/java/com/dkha/task/service/Datatest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								face-task/src/main/java/com/dkha/task/service/Datatest.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | |||||||
|  | package com.dkha.task.service; | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.concurrent.ConcurrentHashMap; | ||||||
|  | import java.util.concurrent.CopyOnWriteArraySet; | ||||||
|  | 
 | ||||||
|  | import javax.websocket.OnClose; | ||||||
|  | import javax.websocket.OnMessage; | ||||||
|  | import javax.websocket.OnOpen; | ||||||
|  | import javax.websocket.Session; | ||||||
|  | import javax.websocket.server.PathParam; | ||||||
|  | import javax.websocket.server.ServerEndpoint; | ||||||
|  | 
 | ||||||
|  | import com.dkha.common.enums.ErrEnum; | ||||||
|  | import com.dkha.common.enums.SocketEnum; | ||||||
|  | import com.dkha.common.modules.vo.face.FaceResEntity; | ||||||
|  | import com.dkha.common.redis.RedisKeys; | ||||||
|  | import com.dkha.common.redis.RedisUtils; | ||||||
|  | import com.dkha.common.util.UtilValidate; | ||||||
|  | import com.dkha.server.controllers.FaceController; | ||||||
|  | import com.dkha.task.comm.TimerData; | ||||||
|  | import com.dkha.task.modual.SysUserTokenEntity; | ||||||
|  | import com.dkha.task.modual.mapper.SysUserTokenDao; | ||||||
|  | import com.dkha.task.modual.vo.BayonetVO; | ||||||
|  | import com.dkha.task.modual.vo.ReturnVO; | ||||||
|  | import com.google.gson.Gson; | ||||||
|  | import lombok.Data; | ||||||
|  | import org.springframework.context.ApplicationContext; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | 
 | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.springframework.web.bind.annotation.GetMapping; | ||||||
|  | 
 | ||||||
|  | public class Datatest { | ||||||
|  |     public List<FaceResEntity> getFaceList() { | ||||||
|  |             FaceController faceController = new FaceController(); | ||||||
|  |             System.out.println(faceController.getFacelist()); | ||||||
|  |             return faceController.getFacelist(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -68,18 +68,18 @@ public class WebSocketContral { | |||||||
|             return; |             return; | ||||||
| 		} | 		} | ||||||
| 		sysUserTokenDao=applicationContext.getBean(SysUserTokenDao.class); | 		sysUserTokenDao=applicationContext.getBean(SysUserTokenDao.class); | ||||||
| 		String time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()); | //		String time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()); | ||||||
| 		SysUserTokenEntity sysUserTokenEntity= null;//sysUserTokenDao.getByToken(token,time); | //		SysUserTokenEntity sysUserTokenEntity= null;//sysUserTokenDao.getByToken(token,time); | ||||||
| 		if(UtilValidate.isEmpty(sysUserTokenEntity)) | //		if(UtilValidate.isEmpty(sysUserTokenEntity)) | ||||||
| 		{ | //		{ | ||||||
| 		    log.error("token过期"); | //		    log.error("token过期"); | ||||||
|             sessionSendMsg(session,gson.toJson(new ReturnVO(ErrEnum.UNAUTHORIZED))); | //            sessionSendMsg(session,gson.toJson(new ReturnVO(ErrEnum.UNAUTHORIZED))); | ||||||
|             try { | //            try { | ||||||
|                 this.session.close(); | //                this.session.close(); | ||||||
|             } catch (Exception e) { | //            } catch (Exception e) { | ||||||
|             } | //            } | ||||||
|             return; | //            return; | ||||||
|         } | //        } | ||||||
| //		//广播使用 | //		//广播使用 | ||||||
| //        redisUtils.set("token",token); | //        redisUtils.set("token",token); | ||||||
| //        //对应使用 | //        //对应使用 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user