an>
69
			String resourceToolId = resourceToolMap.get("resourceToolId") == null ? ""
70
					: String.valueOf(resourceToolMap.get("resourceToolId"));
71
72 62
			CommonResponse<List<Map<String, Object>>> sceneTerminalRelResponse = monitorSceneQuery
73 63
					.selectSceneTerminalRel(new CommonRequest<Long>(Long.valueOf(resourceToolId)));
74 64
			if (sceneTerminalRelResponse == null || CollectionUtils.isEmpty(sceneTerminalRelResponse.getData())) {
75 65
				log.error("AI任务执行结果的关联场景不存在:  resourceToolId=" + resourceToolId);
76 66
				throw new NullPointerException("sceneTerminalRel not exist");
77 67
			}
78
			Map<String, Object> sceneTerminalRelMap = sceneTerminalRelResponse.getData().get(0);
79 68
80
			CommonResponse<List<Map<String, Object>>> aiTaskResponse = aiAlarmManageService
81
					.queryAiTaskByDevice(resourceToolId, aiIdenModel);
82
			if (aiTaskResponse == null || CollectionUtils.isEmpty(aiTaskResponse.getData())) {
83
				log.error("AI任务执行结果的任务不存在:  resourceToolId=" + resourceToolId + ", aiIdenModel=" + aiIdenModel);
84
				throw new NullPointerException("aiTask not exist");
85
			}
86
			Map<String, Object> aiTaskMap = aiTaskResponse.getData().get(0);
69
			Map<String, Object> sceneTerminalRelMap = sceneTerminalRelResponse.getData().get(0);
87 70
88 71
			// 封装数据
89 72
			AiIdenLog aiIdenLog = JSON.parseObject(message, new TypeReference<AiIdenLog>() {
90 73
			});
91
			aiIdenLog.setResourceToolId(resourceToolId);
92
			aiIdenLog.setResourceToolName(resourceToolMap.get("resourceToolName") == null ? ""
93
					: String.valueOf(resourceToolMap.get("resourceToolName")));
94 74
			aiIdenLog.setMonitorSceneId(sceneTerminalRelMap.get("monitorSceneId") == null ? ""
95 75
					: String.valueOf(sceneTerminalRelMap.get("monitorSceneId")));
96 76
			aiIdenLog.setMonitorSceneName(sceneTerminalRelMap.get("monitorSceneName") == null ? ""
@ -101,30 +81,27 @@ public class AiResultRecordKafkaTask {
101 81
					sceneTerminalRelMap.get("place") == null ? "" : String.valueOf(sceneTerminalRelMap.get("place")));
102 82
			aiIdenLog.setOrganizationId(
103 83
					sceneTerminalRelMap.get("orgId") == null ? "" : String.valueOf(sceneTerminalRelMap.get("orgId")));
104
			aiIdenLog.setAiTaskId(
105
					aiTaskMap.get("aiTaskId") == null ? 0L : Long.valueOf(String.valueOf(aiTaskMap.get("aiTaskId"))));
106 84
107 85
			// TODO 人员信息暂时默认
108 86
			aiIdenLog.setRelateEmployeeRoleId("201613310867");
109 87
			aiIdenLog.setRelateEmployeeRoleName("王浩");
110 88
111 89
			// 执行操作
112
			CommonRequest<AiIdenLog> aiIdenLogRequest = new CommonRequest<AiIdenLog>(aiIdenLog);
113
114
			CommonResponse<AiIdenLog> runningResult = aiTaskCommand.createAiIdenLog(aiIdenLogRequest);
115
			log.debug("AI任务执行结果: \n{}", JsonUtils.toJSONStringByDateFormat(runningResult, true));
90
			CommonResponse<AiIdenLog> aiIdenLogRunningResult = aiIdenLogManageService.createAiIdenLog(aiIdenLog);
91
			log.debug("AI任务执行结果: \n{}", JsonUtils.toJSONStringByDateFormat(aiIdenLogRunningResult, true));
116 92
117
			if (!runningResult.isSuccess()) {
118
				log.error("AI任务执行结果异常: " + runningResult.getFail().getMessage());
93
			if (!aiIdenLogRunningResult.isSuccess()) {
94
				log.error("AI任务执行结果异常: " + aiIdenLogRunningResult.getFail().getMessage());
119 95
				return;
120 96
			}
121 97
122 98
			if (!EbcConstant.AI_IDENTIFY_RESULT_NORMAL.equals(idenResultType)) {
123
				CommonResponse runningResult1 = aiTaskCommand.aiIdenLogTriggerEvent(aiIdenLogRequest);
99
				CommonRequest<AiIdenLog> aiIdenLogRequest = new CommonRequest<AiIdenLog>(aiIdenLog);
100
				CommonResponse triggerEventRunningResult = aiTaskCommand.aiIdenLogTriggerEvent(aiIdenLogRequest);
124 101
125
				log.debug("AI任务非正常情况的执行结果: \n{}", JsonUtils.toJSONStringByDateFormat(runningResult1, true));
126
				if (!runningResult.isSuccess()) {
127
					log.error("AI任务非正常情况的执行结果异常: " + runningResult.getFail().getMessage());
102
				log.debug("AI任务触发事件的执行结果: \n{}", JsonUtils.toJSONStringByDateFormat(triggerEventRunningResult, true));
103
				if (!triggerEventRunningResult.isSuccess()) {
104
					log.error("AI任务触发事件的执行结果异常: " + triggerEventRunningResult.getFail().getMessage());
128 105
					return;
129 106
				}
130 107
			}

+ 20 - 0
security-protection-service/src/main/java/com/ai/bss/security/protection/utils/EbcConstant.java

@ -57,6 +57,9 @@ public class EbcConstant {
57 57
	// 静态常量: AI任务状态
58 58
	public static final String BUSINESS_SPEC_AI_TASK_STATUS = "AI_TASK_STATUS";
59 59
	
60
	//静态常量: 职务类型
61
	public static final String BUSINESS_SPEC_EMPLOYEE_POSITION="mainJobPosition";
62
	
60 63
	// 视频监控保存视频文件固定前缀
61 64
	public static final String AI_MONITOR_FILE_PREFIX_VIDEO= "-video";
62 65
		
@ -81,6 +84,23 @@ public class EbcConstant {
81 84
	//场景关联设备的作用类别:其他
82 85
	public static final String TERMINAL_EFFECT_TYPE_OTH="OTH";
83 86
	
87
	//审核状态:待审核
88
	public static final String AUDIT_STATUS_INI="INI";
89
	
90
	//审核状态:已生效(审核通过)
91
	public static final String AUDIT_STATUS_ACC="ACC";
92
	
93
	//审核状态:未生效(未审核通过)
94
	public static final String AUDIT_STATUS_DIS="DIS";
95
	
96
	//AI匹配模型:着装违规识别
97
	public static final String AI_MODEL_CLOTHING_CODE="CLOTHING_CODE";
98
	
99
	//AI匹配模型:人脸识别
100
	public static final String AI_MODEL_FACE="FACE";
101
	
102
	//AI匹配模型:陌生人识别
103
	public static final String AI_MODEL_STRANGER="STRANGER";
84 104
	
85 105
	
86 106
	// 当前登录者的STAFF_ID

[FE]合并 · b30890588a - Nuosi Git Service
Browse Source

[FE]合并

xiayu3 4 years ago
parent
commit
b30890588a

+ 29 - 11
monitor-manage-service/src/main/java/com/ai/bss/monitorManage/service/impl/ListeningFileDirectoryServiceImpl.java

@ -16,6 +16,7 @@ import java.util.HashMap;
16 16
import java.util.Iterator;
17 17
import java.util.List;
18 18
import java.util.Map;
19
import java.util.Map.Entry;
19 20
import java.util.Timer;
20 21
import java.util.TimerTask;
21 22
@ -48,9 +49,10 @@ public class ListeningFileDirectoryServiceImpl  implements ListeningFileDirector
48 49
    @Autowired
49 50
    private KafkaProcess kafkaProcess;
50 51
    
51
    private static Map<String,Timer> timerMap=new HashMap<String,Timer>();
52
    
52
    //防止重启后重复监控文件
53 53
    private String taskName="pictureTask";
54
    private static Map<String,Timer> timerMap=new HashMap<String,Timer>();
55
    private static Map<String,WatchKey> keyMap=new HashMap<String,WatchKey>();
54 56
55 57
    @Override
56 58
    public void getFile(String filePath,int index)  {
@ -65,7 +67,7 @@ public class ListeningFileDirectoryServiceImpl  implements ListeningFileDirector
65 67
    	timerMap.get(timerMapKey).schedule(new TimerTask() {
66 68
            @Override
67 69
            public void run() {
68
                WatchKey key;
70
                WatchKey watchKey;
69 71
                //System.out.println("filePath:   " + filePath);
70 72
                log.info("filePath:   " + filePath);
71 73
                String mapKey = "";
@ -78,10 +80,12 @@ public class ListeningFileDirectoryServiceImpl  implements ListeningFileDirector
78 80
                            File file = new File(filePath);//path为监听文件夹
79 81
                            //System.out.println("等待图片加载!");
80 82
                            log.info("等待图片加载!");
81
                            key = watchService.take();//没有文件增加时,阻塞在这里
83
                            watchKey = watchService.take();//没有文件增加时,阻塞在这里
84
                            keyMap.put(timerMapKey, watchKey);
85
                            
82 86
                            int i = 0;
83 87
                            String[] fileContent = new String[3600];
84
                            for (WatchEvent<?> event : key.pollEvents()) {
88
                            for (WatchEvent<?> event : watchKey.pollEvents()) {
85 89
                                String fileName = filePath+MonitorManageConsts.getSystemSeparator()+event.context();
86 90
                                //System.out.println("增加文件的文件夹路径== :"+fileName);
87 91
                                //System.out.println("增加文件的名称== :"+event.context());
@ -124,7 +128,7 @@ public class ListeningFileDirectoryServiceImpl  implements ListeningFileDirector
124 128
//                                Map<String, String> fileMap = fileManageService.uploadFile(mfile,null);
125 129
//                                System.out.println("pictureUrl=== " + fileMap.get("pictureUrl"));
126 130
127
                            }if (!key.reset()) {
131
                            }if (!watchKey.reset()) {
128 132
                                break; //中断循环
129 133
                            }
130 134
                        }
@ -171,12 +175,26 @@ public class ListeningFileDirectoryServiceImpl  implements ListeningFileDirector
171 175
		}
172 176
    	
173 177
        try{
174
        	Iterator<Map.Entry<String, Timer>> it = timerMap.entrySet().iterator();
175
    	    while(it.hasNext()){
176
    	        Map.Entry<String, Timer> entry = it.next();
177
    	        entry.getValue().cancel();
178
        		it.remove(); 
178
        	Iterator<Map.Entry<String, Timer>> timerIt = timerMap.entrySet().iterator();
179
    	    while(timerIt.hasNext()){
180
    	        Map.Entry<String, Timer> entry = timerIt.next();
181
    	        Timer timer=entry.getValue();
182
    	        timer.cancel();
183
    	        timer=null;
184
        		timerIt.remove(); 
185
			}
186
    	    
187
			if (!CollectionUtils.isEmpty(keyMap)) {
188
				Iterator<Entry<String, WatchKey>> keyIt = keyMap.entrySet().iterator();
189
			    while(keyIt.hasNext()){
190
			        Map.Entry<String, WatchKey> entry = keyIt.next();
191
			        WatchKey watchKey=entry.getValue();
192
			        watchKey.cancel();
193
			        watchKey=null;
194
					keyIt.remove();
195
				}
179 196
			}
197
			
180 198
        }catch(Exception e){
181 199
           log.error("removeTimer is error :"+e.getMessage());  
182 200
           return "关闭失败";

+ 8 - 6
monitor-manage-service/src/main/java/com/ai/bss/monitorManage/service/impl/MonitorManageServiceImpl.java

@ -42,14 +42,15 @@ public class MonitorManageServiceImpl implements MonitorManageService {
42 42
	//@Autowired
43 43
	//private SecurityProtectionMinioConfig minioConfig;
44 44
45
	private static boolean isBeginFlag=false;
46
45
	//监听状态
46
	private boolean isListenFlag=false;
47
	
47 48
	@Override
48 49
	public String loadPictureFromDirectory() throws InterruptedException {
49
		if (!isBeginFlag) {
50
		if (!isListenFlag) {
50 51
			//监听文件目录,加载文件
51 52
			loadFileList();
52
			isBeginFlag=true;
53
			isListenFlag=true;
53 54
			log.info("图片监听开启成功");
54 55
			return "开启成功";
55 56
		}
@ -62,7 +63,7 @@ public class MonitorManageServiceImpl implements MonitorManageService {
62 63
		File file = new File(baseFilePath);//path为监听文件夹
63 64
64 65
		File[] files = file.listFiles();
65
		int n=1;
66
		int n=0;
66 67
		//摄像头列表
67 68
		for(File file1:files){
68 69
			file1.getName();
@ -84,6 +85,7 @@ public class MonitorManageServiceImpl implements MonitorManageService {
84 85
				n++;
85 86
			}
86 87
		}
88
		log.info("此次开启监听"+n+"个文件夹");
87 89
	}
88 90
	
89 91
	/**
@ -93,7 +95,7 @@ public class MonitorManageServiceImpl implements MonitorManageService {
93 95
		log.debug("关闭图片监听");
94 96
		String result=listeningFileDirectoryService.removeTimer();
95 97
		
96
		isBeginFlag=false;
98
		isListenFlag=false;
97 99
		log.info("关闭图片监听:"+result);
98 100
		return result;
99 101
	}

+ 2 - 0
monitor-manage-service/src/main/java/com/ai/bss/monitorManage/utils/AiIdenUtils.java

@ -98,6 +98,8 @@ public class AiIdenUtils {
98 98
		} finally {
99 99
			try {
100 100
				is.close();
101
			} catch (NullPointerException e) {
102
				log.error("getBufferedImage is NullPointerException1: " + e.getMessage() + ", filePath=" + filePath);
101 103
			} catch (IOException e) {
102 104
				log.error("getBufferedImage is IOException1: " + e.getMessage() + ", filePath=" + filePath);
103 105
			}