diff --git a/zc-business/src/main/java/com/zc/business/controller/DcPublishManageController.java b/zc-business/src/main/java/com/zc/business/controller/DcPublishManageController.java index ad006952..e02d512d 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcPublishManageController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcPublishManageController.java @@ -1,5 +1,6 @@ package com.zc.business.controller; +import java.text.ParseException; import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -164,7 +165,7 @@ public class DcPublishManageController extends BaseController @PostMapping("/export") public void export(HttpServletResponse response, DcPublishManage dcPublishManage) { - List list = dcPublishManageService.selectDcPublishManageStatistics(dcPublishManage); + List list = dcPublishManageService.selectDcPublishManageExport(dcPublishManage); ExcelUtil util = new ExcelUtil<>(DcPublishManage.class); util.exportExcel(response, list, "信息发布管理记录数据"); } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcPublishManage.java b/zc-business/src/main/java/com/zc/business/domain/DcPublishManage.java index 56cc54a2..bd6f2074 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcPublishManage.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcPublishManage.java @@ -38,7 +38,7 @@ public class DcPublishManage extends BaseEntity private String title; /** 发布渠道:多选用逗号隔开1-手机短信2-微信公众号3-微博4-情报板5-服务网站6-微信小程序 */ - @Excel(name = "发布渠道",readConverterExp="1=手机短信,2=微信公众号,3=微博,4=情报板,5=服务网站,6=微信小程序,7=语音广播") + @Excel(name = "发布渠道",readConverterExp="1=手机短信,2=微信公众号,3=微博,4=情报板,5=服务网站,6=微信小程序,7=语音广播,8=企业微信") private Integer publishChannels; /** 审核状态:0-待审核1-已审核2-未通过 */ diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcPublishManageMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcPublishManageMapper.java index d30f429d..d8c0e384 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcPublishManageMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcPublishManageMapper.java @@ -87,4 +87,6 @@ public interface DcPublishManageMapper public List> eventTypePublishManageMonth(DcPublishManage dcPublishManage); //公众服务统计查询 public List selectDcPublishManageStatistics(DcPublishManage dcPublishManage); + //数据处理 + public List selectOperLog(); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcPublishManageService.java b/zc-business/src/main/java/com/zc/business/service/IDcPublishManageService.java index 71f5f2eb..e42583d8 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcPublishManageService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcPublishManageService.java @@ -1,20 +1,21 @@ package com.zc.business.service; +import java.text.ParseException; import java.util.HashMap; import java.util.List; import com.zc.business.domain.DcPublishManage; /** * 信息发布管理记录Service接口 - * + * * @author ruoyi * @date 2024-04-19 */ -public interface IDcPublishManageService +public interface IDcPublishManageService { /** * 查询信息发布管理记录 - * + * * @param id 信息发布管理记录主键 * @return 信息发布管理记录 */ @@ -22,7 +23,7 @@ public interface IDcPublishManageService /** * 查询信息发布管理记录列表 - * + * * @param dcPublishManage 信息发布管理记录 * @return 信息发布管理记录集合 */ @@ -31,7 +32,7 @@ public interface IDcPublishManageService List selectEventDcPublishManageList(DcPublishManage dcPublishManage); /** * 新增信息发布管理记录 - * + * * @param dcPublishManage 信息发布管理记录 * @return 结果 */ @@ -39,7 +40,7 @@ public interface IDcPublishManageService /** * 修改信息发布管理记录 - * + * * @param dcPublishManage 信息发布管理记录 * @return 结果 */ @@ -47,7 +48,7 @@ public interface IDcPublishManageService /** * 批量删除信息发布管理记录 - * + * * @param ids 需要删除的信息发布管理记录主键集合 * @return 结果 */ @@ -55,7 +56,7 @@ public interface IDcPublishManageService /** * 删除信息发布管理记录信息 - * + * * @param id 信息发布管理记录主键 * @return 结果 */ @@ -74,4 +75,8 @@ public interface IDcPublishManageService public List> eventTypePublishManageMonth(DcPublishManage dcPublishManage); //公众服务统计查询 public List selectDcPublishManageStatistics(DcPublishManage dcPublishManage); + //公众服务统计导出 + public List selectDcPublishManageExport(DcPublishManage dcPublishManage); + //数据处理 + public List selectOperLog() throws ParseException; } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcPublishManageServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcPublishManageServiceImpl.java index dd9e9c1c..8028edde 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcPublishManageServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcPublishManageServiceImpl.java @@ -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 selectDcPublishManageStatistics(DcPublishManage dcPublishManage) { return dcPublishManageMapper.selectDcPublishManageStatistics(dcPublishManage); } + + @Override + public List selectDcPublishManageExport(DcPublishManage dcPublishManage) { + List dcPublishManagesValue = dcPublishManageMapper.selectDcPublishManageStatistics(dcPublishManage); + ArrayList 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 selectOperLog() throws ParseException { + List 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; + } } diff --git a/zc-business/src/main/resources/mapper/business/DcPublishManageMapper.xml b/zc-business/src/main/resources/mapper/business/DcPublishManageMapper.xml index 1624000e..fd487350 100644 --- a/zc-business/src/main/resources/mapper/business/DcPublishManageMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcPublishManageMapper.xml @@ -51,11 +51,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" manage.id, manage.event_id, manage.publish_channels_id, manage.title, manage.publish_channels , manage.publisher, manage.publish_status, manage.content_details, manage.remark, + CASE + WHEN manage.publish_channels = 8 THEN event.stake_mark + WHEN manage.publish_channels IN (4, 7) THEN log.dc_device_name + ELSE'未知' + END AS position, event.create_time eventTime from dc_publish_manage as manage LEFT JOIN dc_event as event on event.id=manage.event_id LEFT JOIN dc_event_traffic_control as traffic on event.id=traffic.id LEFT JOIN dc_facility as facility ON traffic.facility_id=facility.id + left join dc_oper_log as log on log.id=manage.log_id where manage.event_id=#{eventId} +