|
|
|
@ -0,0 +1,66 @@ |
|
|
|
package com.inspect.simulator.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.inspect.simulator.mapper.ResultAnalysisMapper; |
|
|
|
import com.inspect.simulator.service.ResultAnalysisService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
public class ResultAnnalysisServiceImpl implements ResultAnalysisService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ResultAnalysisMapper resultAnalysisMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public String selectChannelImgByPatrolPointId(String patrolPointId) { |
|
|
|
String resImageUrl=null; |
|
|
|
String jsonStr = resultAnalysisMapper.selectChannelImgByPatrolPointId(patrolPointId); |
|
|
|
resImageUrl = extractResImageUrl(jsonStr, patrolPointId); |
|
|
|
if (resImageUrl==null){ |
|
|
|
try { |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonStr); |
|
|
|
resImageUrl = jsonObject.getString("resImageUrl"); |
|
|
|
} catch (Exception e) { |
|
|
|
e.getMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
return resImageUrl != null ? resImageUrl : "Image URL not found"; |
|
|
|
} |
|
|
|
|
|
|
|
public String extractResImageUrl(String jsonStr, String objectId) { |
|
|
|
if (jsonStr == null || jsonStr.isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
try { |
|
|
|
JSONObject json = JSONObject.parseObject(jsonStr); |
|
|
|
String[] listKeys = {"resultList"}; |
|
|
|
for (String key : listKeys) { |
|
|
|
if (json.containsKey(key)) { |
|
|
|
JSONArray items = json.getJSONArray(key); |
|
|
|
for (int i = 0; i < items.size(); i++) { |
|
|
|
JSONObject item = items.getJSONObject(i); |
|
|
|
if (objectId.equals(item.getString("objectId"))) { |
|
|
|
JSONArray results = item.getJSONArray("results"); |
|
|
|
if (results != null && !results.isEmpty()) { |
|
|
|
JSONObject firstResult = results.getJSONObject(0); |
|
|
|
if (firstResult.containsKey("resImageUrl")) { |
|
|
|
return firstResult.getString("resImageUrl"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |