Selaa lähdekoodia

修改AI识别进出记录

konghl 4 vuotta sitten
vanhempi
commit
a8eea157cb

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

27
import com.ai.bss.work.safety.service.api.AiTaskQuery;
27
import com.ai.bss.work.safety.service.api.AiTaskQuery;
28
import com.alibaba.fastjson.JSON;
28
import com.alibaba.fastjson.JSON;
29
import com.alibaba.fastjson.JSONArray;
29
import com.alibaba.fastjson.JSONArray;
30
import com.alibaba.fastjson.JSONObject;
30
import com.alibaba.fastjson.TypeReference;
31
import com.alibaba.fastjson.TypeReference;
31
32
32
@Service
33
@Service
70
			dataMap.put("idenPictureSnapDate", DateUtil.formatObjectToDate(dataMap.get("idenPictureSnapDate")));
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
173
167
		// 结果详情
174
		// 结果详情
168
		if (StringUtils.isNotEmpty(aiIdenLog.getIdenResult())) {
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
import com.ai.abc.api.model.CommonResponse;
14
import com.ai.abc.api.model.CommonResponse;
15
import com.ai.abc.util.JsonUtils;
15
import com.ai.abc.util.JsonUtils;
16
import com.ai.bss.security.protection.service.interfaces.AiIdenLogManageService;
16
import com.ai.bss.security.protection.service.interfaces.AiIdenLogManageService;
17
import com.ai.bss.security.protection.service.interfaces.ResourceToolManageService;
18
import com.ai.bss.security.protection.utils.EbcConstant;
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
import com.ai.bss.work.safety.model.AiIdenLog;
20
import com.ai.bss.work.safety.model.AiIdenLog;
20
import com.ai.bss.work.safety.service.api.AiTaskCommand;
21
import com.ai.bss.work.safety.service.api.AiTaskCommand;
21
import com.ai.bss.work.safety.service.api.MonitorSceneQuery;
22
import com.ai.bss.work.safety.service.api.MonitorSceneQuery;
38
	private AiTaskCommand aiTaskCommand;
39
	private AiTaskCommand aiTaskCommand;
39
40
40
	@Autowired
41
	@Autowired
41
	private ResourceToolManageService resourceToolManageService;
42
43
	@Autowired
44
	private MonitorSceneQuery monitorSceneQuery;
42
	private MonitorSceneQuery monitorSceneQuery;
45
43
46
	@Autowired
44
	@Autowired
47
	private AiIdenLogManageService aiIdenLogManageService;
45
	private AiIdenLogManageService aiIdenLogManageService;
48
46
47
	@Autowired
48
	private EmployeeService employeeService;
49
49
	@KafkaListener(containerFactory = "kafkaBatchListener6", topics = "${kafka.topic.aitask:topic_ai_task}", groupId = "ai_group")
50
	@KafkaListener(containerFactory = "kafkaBatchListener6", topics = "${kafka.topic.aitask:topic_ai_task}", groupId = "ai_group")
50
	public void AiResultRecordListener(ConsumerRecord<String, String> records, Acknowledgment ack) throws Throwable {
51
	public void AiResultRecordListener(ConsumerRecord<String, String> records, Acknowledgment ack) throws Throwable {
51
		try {
52
		try {
54
			String message = records.value();
55
			String message = records.value();
55
			log.info("已接AI任务执行结果消息,消息为:" + message);
56
			log.info("已接AI任务执行结果消息,消息为:" + message);
56
57
58
			AiIdenLog aiIdenLog = JSON.parseObject(message, new TypeReference<AiIdenLog>() {
59
			});
60
57
			JSONObject messageJson = JSONObject.parseObject(message);
61
			JSONObject messageJson = JSONObject.parseObject(message);
58
			String resourceToolId = messageJson.getString("resourceToolId");
62
			String resourceToolId = messageJson.getString("resourceToolId");
59
			String idenResultType = messageJson.getString("idenResultType");
63
			String idenResultType = messageJson.getString("idenResultType");
64
			Long relateEmployeeRoleId = messageJson.getLong("relateEmployeeRoleId");
60
65
61
			// 查询相关数据
66
			// 关联场景信息
62
			CommonResponse<List<Map<String, Object>>> sceneTerminalRelResponse = monitorSceneQuery
67
			CommonResponse<List<Map<String, Object>>> sceneTerminalRelResponse = monitorSceneQuery
63
					.selectSceneTerminalRel(new CommonRequest<Long>(Long.valueOf(resourceToolId)));
68
					.selectSceneTerminalRel(new CommonRequest<Long>(Long.valueOf(resourceToolId)));
64
			if (sceneTerminalRelResponse == null || CollectionUtils.isEmpty(sceneTerminalRelResponse.getData())) {
69
			if (sceneTerminalRelResponse == null || CollectionUtils.isEmpty(sceneTerminalRelResponse.getData())) {
68
73
69
			Map<String, Object> sceneTerminalRelMap = sceneTerminalRelResponse.getData().get(0);
74
			Map<String, Object> sceneTerminalRelMap = sceneTerminalRelResponse.getData().get(0);
70
75
71
			// 封装数据
72
			AiIdenLog aiIdenLog = JSON.parseObject(message, new TypeReference<AiIdenLog>() {
73
			});
74
			aiIdenLog.setMonitorSceneId(sceneTerminalRelMap.get("monitorSceneId") == null ? ""
76
			aiIdenLog.setMonitorSceneId(sceneTerminalRelMap.get("monitorSceneId") == null ? ""
75
					: String.valueOf(sceneTerminalRelMap.get("monitorSceneId")));
77
					: String.valueOf(sceneTerminalRelMap.get("monitorSceneId")));
76
			aiIdenLog.setMonitorSceneName(sceneTerminalRelMap.get("monitorSceneName") == null ? ""
78
			aiIdenLog.setMonitorSceneName(sceneTerminalRelMap.get("monitorSceneName") == null ? ""
82
			aiIdenLog.setOrganizationId(
84
			aiIdenLog.setOrganizationId(
83
					sceneTerminalRelMap.get("orgId") == null ? "" : String.valueOf(sceneTerminalRelMap.get("orgId")));
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
			CommonResponse<AiIdenLog> aiIdenLogRunningResult = aiIdenLogManageService.createAiIdenLog(aiIdenLog);
109
			CommonResponse<AiIdenLog> aiIdenLogRunningResult = aiIdenLogManageService.createAiIdenLog(aiIdenLog);