Changes提交修改

This commit is contained in:
15666619788
2025-07-27 22:23:59 +08:00
parent a9895296f0
commit 34d3a965d7
35 changed files with 894 additions and 26 deletions

View File

@@ -58,4 +58,6 @@ public interface DocMapper
* @return 结果
*/
public int deleteDocByIds(Long[] ids);
List<Doc> selectDocAllList(Doc doc);
}

View File

@@ -8,6 +8,7 @@ import com.xinda.iot.model.ThingsModelLogCountVO;
import com.xinda.iot.model.param.DataCenterParam;
import com.xinda.iot.model.scenemodel.SceneHistoryParam;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@@ -55,4 +56,6 @@ public interface DataCenterService {
* @return com.xinda.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
void deviceHistoryExport(DeviceHistoryParam deviceHistoryParam, HttpServletResponse response);
}

View File

@@ -62,4 +62,5 @@ public interface IDocService
*/
public int deleteDocById(Long id);
List<Doc> selectDocAllList(Doc doc);
}

View File

@@ -191,6 +191,9 @@ public class AlertLogServiceImpl implements IAlertLogService {
}
if (alertLog.getEnable()==1) {
RepairOrder order = alertLog.getOrder();
SysUser user = getLoginUser().getUser();
order.setTenantId(user.getDeptId());
order.setCreateTime(DateUtils.getNowDate());
repairOrderMapper.insertRepairOrder(order);
alertLog.setOrderId(order.getId());
}

View File

@@ -1,6 +1,9 @@
package com.xinda.iot.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.scenemodel.SceneModelVariableTypeEnum;
import com.xinda.common.utils.DateUtils;
import com.xinda.common.utils.StringUtils;
@@ -15,9 +18,16 @@ import com.xinda.iot.model.param.DataCenterParam;
import com.xinda.iot.model.scenemodel.SceneHistoryParam;
import com.xinda.iot.service.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -182,4 +192,79 @@ public class DataCenterServiceImpl implements DataCenterService {
resultList.addAll(functionLogService.countThingsModelInvoke(dataCenterParam));
return resultList;
}
@Override
public void deviceHistoryExport(DeviceHistoryParam deviceHistoryParam, HttpServletResponse response) {
// 1. 获取历史数据
List<JSONObject> dataList = this.deviceHistory(deviceHistoryParam);
// 2. 提取所有标识符(去重)
Set<String> allIdentifiers = new HashSet<>();
for (JSONObject obj : dataList) {
for (String timeKey : obj.keySet()) {
JSONArray items = obj.getJSONArray(timeKey);
for (int i = 0; i < items.size(); i++) {
JSONObject item = items.getJSONObject(i);
allIdentifiers.addAll(item.keySet());
}
}
}
// 3. 创建Excel工作簿
try (Workbook workbook = new XSSFWorkbook()) {
Sheet sheet = workbook.createSheet("设备历史数据");
// 4. 创建表头
Row headerRow = sheet.createRow(0);
int colIndex = 0;
headerRow.createCell(colIndex++).setCellValue("时间");
for (String identifier : allIdentifiers) {
headerRow.createCell(colIndex++).setCellValue(identifier);
}
// 5. 填充数据
int rowIndex = 1;
for (JSONObject obj : dataList) {
for (String timeKey : obj.keySet()) {
Row dataRow = sheet.createRow(rowIndex++);
int cellIndex = 0;
dataRow.createCell(cellIndex++).setCellValue(timeKey); // 时间列
JSONArray items = obj.getJSONArray(timeKey);
Map<String, String> valueMap = new HashMap<>();
for (int i = 0; i < items.size(); i++) {
JSONObject item = items.getJSONObject(i);
item.forEach((key, value) -> valueMap.put(key, value.toString()));
}
// 按表头顺序填充数据
for (String identifier : allIdentifiers) {
String value = valueMap.getOrDefault(identifier, "");
dataRow.createCell(cellIndex++).setCellValue(value);
}
}
}
// 6. 自动调整列宽
for (int i = 0; i < allIdentifiers.size() + 1; i++) {
sheet.autoSizeColumn(i);
}
// 7. 设置响应头
String fileName = URLEncoder.encode("设备历史数据_" + System.currentTimeMillis(), "UTF-8") + ".xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
// 8. 写入响应流
workbook.write(response.getOutputStream());
} catch (IOException e) {
log.error("导出Excel失败", e);
try {
response.setContentType("application/json");
response.getWriter().print(JSON.toJSONString(AjaxResult.error("导出失败")));
} catch (IOException ex) {
log.error("错误处理失败", ex);
}
}
}
}

View File

@@ -52,6 +52,15 @@ public class DocServiceImpl implements IDocService
return docMapper.selectDocList(doc);
}
@Override
public List<Doc> selectDocAllList(Doc doc)
{
SysUser sysUser = getLoginUser().getUser();
//添加设备
doc.setDeptId(sysUser.getDept().getDeptId());
return docMapper.selectDocAllList(doc);
}
/**
* 新增档案管理
*

View File

@@ -39,6 +39,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="tenantName != null and tenantName != ''"> and d.tenant_name like concat('%', #{tenantName}, '%')</if>
</where>
</select>
<select id="selectDocAllList" parameterType="Doc" resultMap="DocResult">
<include refid="selectDocVo"/>
<where>
<!-- <if test="deptId != null "> and dept_id = #{deptId}</if>-->
<if test="deptId != null and deptId != 0 ">
and d.dept_id in (
SELECT #{deptId} AS dept_id
UNION ALL
SELECT DISTINCT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(ancestors, ',', n.n), ',', -1) AS SIGNED) AS dept_id
FROM sys_dept de
JOIN (
SELECT 1 AS n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
) n ON CHAR_LENGTH(ancestors) - CHAR_LENGTH(REPLACE(ancestors, ',', '')) >= n.n - 1
WHERE de.dept_id = #{deptId}
AND SUBSTRING_INDEX(SUBSTRING_INDEX(ancestors, ',', n.n), ',', -1) != ''
)
</if>
<if test="fileName != null and fileName != ''"> and d.file_name like concat('%', #{fileName}, '%')</if>
</where>
</select>
<select id="selectDocById" parameterType="Long" resultMap="DocResult">
<include refid="selectDocVo"/>