|
|
@ -1,14 +1,24 @@ |
|
|
|
package com.zc.business.service.impl; |
|
|
|
|
|
|
|
import com.google.gson.JsonArray; |
|
|
|
import com.google.gson.JsonElement; |
|
|
|
import com.google.gson.JsonObject; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
import com.ruoyi.common.utils.DateUtils; |
|
|
|
import com.zc.business.domain.DcPublishManage; |
|
|
|
import com.zc.business.mapper.DcPublishManageMapper; |
|
|
|
import com.zc.business.service.IDcPublishManageService; |
|
|
|
import com.zc.business.utils.StakeMarkUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.json.JSONArray; |
|
|
|
import org.json.JSONObject; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
@ -145,4 +155,89 @@ public class DcPublishManageServiceImpl implements IDcPublishManageService |
|
|
|
public List<DcPublishManage> selectDcPublishManageStatistics(DcPublishManage dcPublishManage) { |
|
|
|
return dcPublishManageMapper.selectDcPublishManageStatistics(dcPublishManage); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<DcPublishManage> selectDcPublishManageExport(DcPublishManage dcPublishManage) { |
|
|
|
List<DcPublishManage> dcPublishManagesValue = dcPublishManageMapper.selectDcPublishManageStatistics(dcPublishManage); |
|
|
|
ArrayList<DcPublishManage> objects = new ArrayList<>(); |
|
|
|
for (DcPublishManage dcPublishManages : dcPublishManagesValue) { |
|
|
|
Integer publishChannels = dcPublishManages.getPublishChannels();//取出发布渠道判断使用
|
|
|
|
if (publishChannels == 7 && StringUtils.isNotBlank(dcPublishManages.getContentDetails())) {//语音广播
|
|
|
|
String contentDetails = dcPublishManages.getContentDetails(); |
|
|
|
JsonParser parser = new JsonParser(); |
|
|
|
JsonArray jsonArray = parser.parse(contentDetails).getAsJsonArray(); |
|
|
|
// 假设我们只关心第一个对象(因为语音广播一个设备一次只会发一条语音)
|
|
|
|
JsonObject jsonObject = jsonArray.get(0).getAsJsonObject(); |
|
|
|
JsonArray functionsArray = jsonObject.get("functions").getAsJsonArray(); |
|
|
|
// 遍历 functions 数组以找到 text
|
|
|
|
for (JsonElement functionElement : functionsArray) { |
|
|
|
JsonObject functionObject = functionElement.getAsJsonObject(); |
|
|
|
JsonObject paramsObject = functionObject.get("params").getAsJsonObject(); |
|
|
|
// 提取 text
|
|
|
|
String text = paramsObject.get("text").getAsString(); |
|
|
|
dcPublishManages.setContentDetails(text); |
|
|
|
break; //退出循环
|
|
|
|
} |
|
|
|
} |
|
|
|
if (publishChannels == 4 && StringUtils.isNotBlank(dcPublishManages.getContentDetails())) { |
|
|
|
String contentDetails = dcPublishManages.getContentDetails(); |
|
|
|
try { |
|
|
|
JSONArray jsonArray = new JSONArray(contentDetails); |
|
|
|
StringBuilder contentStringBuilder = new StringBuilder(); |
|
|
|
for (int i = 0; i < jsonArray.length(); i++) { |
|
|
|
// 确保当前元素是JSONObject
|
|
|
|
Object element = jsonArray.get(i); |
|
|
|
if (element instanceof JSONObject) { |
|
|
|
JSONObject jsonObject = (JSONObject) element; |
|
|
|
JSONArray functionsArray = jsonObject.getJSONArray("functions"); |
|
|
|
for (int j = 0; j < functionsArray.length(); j++) { |
|
|
|
JSONObject functionObject = functionsArray.getJSONObject(j); |
|
|
|
if ("13".equals(functionObject.getString("functionId"))) { |
|
|
|
JSONObject paramsObject = functionObject.getJSONObject("params"); |
|
|
|
JSONArray parametersArray = paramsObject.getJSONArray("parameters"); |
|
|
|
for (int k = 0; k < parametersArray.length(); k++) { |
|
|
|
JSONObject parameterObject = parametersArray.getJSONObject(k); |
|
|
|
String content = parameterObject.getString("CONTENT"); |
|
|
|
if (contentStringBuilder.length() > 0) { |
|
|
|
contentStringBuilder.append(","); |
|
|
|
} |
|
|
|
contentStringBuilder.append(content); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dcPublishManages.setContentDetails(contentStringBuilder.toString()); |
|
|
|
} else { |
|
|
|
dcPublishManages.setContentDetails(""); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); // 处理JSON解析中的异常
|
|
|
|
} |
|
|
|
} |
|
|
|
objects.add(dcPublishManages); |
|
|
|
} |
|
|
|
return objects; |
|
|
|
} |
|
|
|
|
|
|
|
//数据处理
|
|
|
|
@Override |
|
|
|
public List<HashMap> selectOperLog() throws ParseException { |
|
|
|
List<HashMap> maps = dcPublishManageMapper.selectOperLog(); |
|
|
|
for (HashMap map:maps){ |
|
|
|
DcPublishManage dcPublishManage = new DcPublishManage(); |
|
|
|
dcPublishManage.setLogId((Long) map.get("id")); |
|
|
|
dcPublishManage.setContentDetails(map.get("operParam").toString()); |
|
|
|
dcPublishManage.setRemark(map.get("remark").toString()); |
|
|
|
dcPublishManage.setPublishStatus(1); |
|
|
|
String operTime = map.get("operTime").toString(); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
Date date = sdf.parse(operTime); |
|
|
|
dcPublishManage.setCreateTime(date); |
|
|
|
dcPublishManage.setPublishTime(date); |
|
|
|
dcPublishManage.setPublisher("admin"); |
|
|
|
dcPublishManage.setPublishChannels(4); |
|
|
|
dcPublishManageMapper.insertDcPublishManage(dcPublishManage); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|