Bladeren bron

修改AI识别进出记录

konghl 4 jaren geleden
bovenliggende
commit
a8eea157cb

+ 23 - 10
security-protection-service/src/main/java/com/ai/bss/security/protection/service/impl/AiIdenLogManageServiceImpl.java

@ -27,6 +27,7 @@ import com.ai.bss.work.safety.service.api.AiTaskCommand;
27 27
import com.ai.bss.work.safety.service.api.AiTaskQuery;
28 28
import com.alibaba.fastjson.JSON;
29 29
import com.alibaba.fastjson.JSONArray;
30
import com.alibaba.fastjson.JSONObject;
30 31
import com.alibaba.fastjson.TypeReference;
31 32
32 33
@Service
@ -70,12 +71,18 @@ public class AiIdenLogManageServiceImpl implements AiIdenLogManageService {
70 71
			dataMap.put("idenPictureSnapDate", DateUtil.formatObjectToDate(dataMap.get("idenPictureSnapDate")));
71 72
			
72 73
			// 结果详情
73
			String idenResultArr = dataMap.get("idenResult") == null ? "" : String.valueOf(dataMap.get("idenResult"));
74
			if (StringUtils.isNotEmpty(idenResultArr)) {
75
				List<Map<String, String>> idenResultList = JSONArray.parseObject(idenResultArr, List.class);
76
				if (!CollectionUtils.isEmpty(idenResultList)) {
77
					dataMap.putAll(idenResultList.get(0));
78
				}
74
			String idenResultString = dataMap.get("idenResult") == null ? "" : String.valueOf(dataMap.get("idenResult"));
75
			if (StringUtils.isNotEmpty(idenResultString)) {
76
				Object idenResultObject = JSON.parse(idenResultString);
77
				 if (idenResultObject instanceof JSONObject) {
78
					 Map<String, String> idenResultMap=JSON.parseObject(idenResultString, Map.class);
79
					 dataMap.putAll(idenResultMap);
80
				 }else if (idenResultObject instanceof JSONArray) {
81
					 List<Map<String, String>> idenResultList = JSONArray.parseObject(idenResultString, List.class);
82
						if (!CollectionUtils.isEmpty(idenResultList)) {
83
							dataMap.putAll(idenResultList.get(0));
84
						}
85
				 }
79 86
			}
80 87
81 88
			// 员工信息
@ -166,10 +173,16 @@ public class AiIdenLogManageServiceImpl implements AiIdenLogManageService {
166 173
167 174
		// 结果详情
168 175
		if (StringUtils.isNotEmpty(aiIdenLog.getIdenResult())) {
169
			List<Map<String, String>> idenResultList = JSONArray.parseObject(aiIdenLog.getIdenResult(), List.class);
170
			if (!CollectionUtils.isEmpty(idenResultList)) {
171
				aiIdenLogInfoMap.putAll(idenResultList.get(0));
172
			}
176
			Object idenResultObject = JSON.parse(aiIdenLog.getIdenResult());
177
			 if (idenResultObject instanceof JSONObject) {
178
				 Map<String, String> idenResultMap=JSON.parseObject(aiIdenLog.getIdenResult(), Map.class);
179
				 aiIdenLogInfoMap.putAll(idenResultMap);
180
			 }else if (idenResultObject instanceof JSONArray) {
181
				 List<Map<String, String>> idenResultList = JSONArray.parseObject(aiIdenLog.getIdenResult(), List.class);
182
					if (!CollectionUtils.isEmpty(idenResultList)) {
183
						aiIdenLogInfoMap.putAll(idenResultList.get(0));
184
					}
185
			 }
173 186
		}
174 187
175 188
		// 员工信息

+ 30 - 11
security-protection-service/src/main/java/com/ai/bss/security/protection/service/task/AiResultRecordKafkaTask.java

@ -14,8 +14,9 @@ import com.ai.abc.api.model.CommonRequest;
14 14
import com.ai.abc.api.model.CommonResponse;
15 15
import com.ai.abc.util.JsonUtils;
16 16
import com.ai.bss.security.protection.service.interfaces.AiIdenLogManageService;
17
import com.ai.bss.security.protection.service.interfaces.ResourceToolManageService;
18 17
import com.ai.bss.security.protection.utils.EbcConstant;
18
import com.ai.bss.user.dto.EmployeeDto;
19
import com.ai.bss.user.service.api.EmployeeService;
19 20
import com.ai.bss.work.safety.model.AiIdenLog;
20 21
import com.ai.bss.work.safety.service.api.AiTaskCommand;
21 22
import com.ai.bss.work.safety.service.api.MonitorSceneQuery;
@ -38,14 +39,14 @@ public class AiResultRecordKafkaTask {
38 39
	private AiTaskCommand aiTaskCommand;
39 40
40 41
	@Autowired
41
	private ResourceToolManageService resourceToolManageService;
42
43
	@Autowired
44 42
	private MonitorSceneQuery monitorSceneQuery;
45 43
46 44
	@Autowired
47 45
	private AiIdenLogManageService aiIdenLogManageService;
48 46
47
	@Autowired
48
	private EmployeeService employeeService;
49
49 50
	@KafkaListener(containerFactory = "kafkaBatchListener6", topics = "${kafka.topic.aitask:topic_ai_task}", groupId = "ai_group")
50 51
	public void AiResultRecordListener(ConsumerRecord<String, String> records, Acknowledgment ack) throws Throwable {
51 52
		try {
@ -54,11 +55,15 @@ public class AiResultRecordKafkaTask {
54 55
			String message = records.value();
55 56
			log.info("已接AI任务执行结果消息,消息为:" + message);
56 57
58
			AiIdenLog aiIdenLog = JSON.parseObject(message, new TypeReference<AiIdenLog>() {
59
			});
60
57 61
			JSONObject messageJson = JSONObject.parseObject(message);
58 62
			String resourceToolId = messageJson.getString("resourceToolId");
59 63
			String idenResultType = messageJson.getString("idenResultType");
64
			Long relateEmployeeRoleId = messageJson.getLong("relateEmployeeRoleId");
60 65
61
			// 查询相关数据
66
			// 关联场景信息
62 67
			CommonResponse<List<Map<String, Object>>> sceneTerminalRelResponse = monitorSceneQuery
63 68
					.selectSceneTerminalRel(new CommonRequest<Long>(Long.valueOf(resourceToolId)));
64 69
			if (sceneTerminalRelResponse == null || CollectionUtils.isEmpty(sceneTerminalRelResponse.getData())) {
@ -68,9 +73,6 @@ public class AiResultRecordKafkaTask {
68 73
69 74
			Map<String, Object> sceneTerminalRelMap = sceneTerminalRelResponse.getData().get(0);
70 75
71
			// 封装数据
72
			AiIdenLog aiIdenLog = JSON.parseObject(message, new TypeReference<AiIdenLog>() {
73
			});
74 76
			aiIdenLog.setMonitorSceneId(sceneTerminalRelMap.get("monitorSceneId") == null ? ""
75 77
					: String.valueOf(sceneTerminalRelMap.get("monitorSceneId")));
76 78
			aiIdenLog.setMonitorSceneName(sceneTerminalRelMap.get("monitorSceneName") == null ? ""
@ -82,9 +84,26 @@ public class AiResultRecordKafkaTask {
82 84
			aiIdenLog.setOrganizationId(
83 85
					sceneTerminalRelMap.get("orgId") == null ? "" : String.valueOf(sceneTerminalRelMap.get("orgId")));
84 86
85
			// TODO 人员信息暂时默认
86
			aiIdenLog.setRelateEmployeeRoleId("201613310867");
87
			aiIdenLog.setRelateEmployeeRoleName("王浩");
87
			// 关联员工信息
88
			EmployeeDto employeeDto = null;
89
			if (relateEmployeeRoleId != null) {
90
				employeeDto = new EmployeeDto();
91
				employeeDto.setId(relateEmployeeRoleId);
92
				CommonRequest<EmployeeDto> employeeDtoRequest = new CommonRequest<EmployeeDto>(employeeDto);
93
				CommonResponse<EmployeeDto> employeeDtoResponse = employeeService.queryEmployee(employeeDtoRequest);
94
				if (employeeDtoResponse == null || employeeDtoResponse.getData() == null) {
95
					employeeDto = null;
96
				} else {
97
					employeeDto = employeeDtoResponse.getData();
98
				}
99
			}
100
			if (employeeDto != null) {
101
				aiIdenLog.setRelateEmployeeRoleName(employeeDto.getName());
102
				aiIdenLog.setOrganizationId(String.valueOf(employeeDto.getOrganizeId()));
103
			} else {
104
				aiIdenLog.setRelateEmployeeRoleId("-1");
105
				aiIdenLog.setRelateEmployeeRoleName(null);
106
			}
88 107
89 108
			// 执行操作
90 109
			CommonResponse<AiIdenLog> aiIdenLogRunningResult = aiIdenLogManageService.createAiIdenLog(aiIdenLog);