diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableDataNameVo.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableDataNameVo.java new file mode 100644 index 0000000..8c8d7a9 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableDataNameVo.java @@ -0,0 +1,31 @@ +package com.ruoyi.common.core.web.page; + +import java.util.Map; + +/** + * @ClassName : TableDataNameVo + * @Description : + * @Author : + * @Date: 2024-06-17 10:41 + */ +public class TableDataNameVo { + private TableDataInfo tableDataInfo; + + private Map mapName; + + public TableDataInfo getTableDataInfo() { + return tableDataInfo; + } + + public void setTableDataInfo(TableDataInfo tableDataInfo) { + this.tableDataInfo = tableDataInfo; + } + + public Map getMapName() { + return mapName; + } + + public void setMapName(Map mapName) { + this.mapName = mapName; + } +} diff --git a/ruoyi-modules/hw-business/pom.xml b/ruoyi-modules/hw-business/pom.xml index 7385159..409526e 100644 --- a/ruoyi-modules/hw-business/pom.xml +++ b/ruoyi-modules/hw-business/pom.xml @@ -16,6 +16,24 @@ + + + org.apache.httpcomponents + httpmime + 4.5.7 + + + + com.alibaba + fastjson + 1.2.41 + + + + org.apache.poi + poi-ooxml + 3.16 + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java index 78e4476..ef8a7ed 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java @@ -1,23 +1,36 @@ package com.ruoyi.business.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.VO.*; import com.ruoyi.business.service.*; +import com.ruoyi.business.utils.ExcelUtils; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.utils.poi.ExcelUtil; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; +import com.ruoyi.common.core.web.page.TableDataNameVo; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.tdengine.api.domain.TdReturnDataVo; +import io.micrometer.core.instrument.util.StringEscapeUtils; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; -import java.util.List; +import javax.servlet.http.HttpServletResponse; +import java.util.*; +import java.util.stream.Collectors; @RestController @RequestMapping("/monitorPlatform") @@ -299,4 +312,181 @@ public class HwMonitorPlatformController extends BaseController { return success(hwScenes); } + /** + * 根据场景查询场景下设备的经纬度 + * */ + @GetMapping("/selectDeviceLatitudeAndLongitude/{sceneId}") + public AjaxResult selectDeviceLatitudeAndLongitude(@PathVariable("sceneId") Long sceneId){ + List beaconDevices = hwDeviceService.selectDeviceLatitudeAndLongitude(sceneId); + return success(beaconDevices); + } + /** + * 根据设备id查询信标设备历史数据 + * */ + @GetMapping("/selectBeaconDevicesHistory") + public TableDataInfo selectBeaconDevicesHistory(@RequestParam(required = false) Map map){ +// List beaconDevices = hwDeviceService.selectBeaconDevicesHistory(map); + List> lists = hwDeviceService.selectBeaconDevicesHistory(map); + long total = Long.valueOf(lists.get(lists.size() - 1).get("total").toString()); + lists.remove(lists.size() - 1); + TableDataInfo dataTable = getDataTable(lists); + dataTable.setTotal(total); + return dataTable; + } + /** + * 根据设备id查询其对应的监控单元 + * */ + @GetMapping("/selectMonitorUnit/{deviceId}") + public AjaxResult selectMonitorUnit(@PathVariable("deviceId") Long deviceId){ + HwMonitorUnit hwMonitorUnit = hwDeviceService.selectMonitorUnit(deviceId); + return success(hwMonitorUnit); + } + /** + * 根据设备id查询其对应的电子围栏 + * */ + @GetMapping("/selectMonitorElectronic/{deviceId}") + public AjaxResult selectMonitorElectronic(@PathVariable("deviceId") Long deviceId){ + return success(hwDeviceService.selectMonitorElectronic(deviceId)); + } + /** + * 历史数据弹出框(多参数且可多选) + * */ + @GetMapping("/selectHistoryAndTrendAnalysis") + public TableDataNameVo selectHistoryDevice(@RequestParam(required = false) Map map){ + List> list = hwDeviceService.selectHistoryDevice(map); + TableDataInfo dataTable = getDataTable(list); + TableDataNameVo tableDataNameVo = new TableDataNameVo(); + if (list.size()>1){ + long total = Long.valueOf(list.get(list.size() - 1).get("total").toString()); + Map mapName = new HashMap<>(); + list.remove(list.size() - 1); + if (list.size()>0){ + mapName = list.get(list.size() - 1); + list.remove(list.size() - 1); + } + + + Map mapTotal = new HashMap(); + dataTable = getDataTable(list); + dataTable.setTotal(total); + tableDataNameVo.setTableDataInfo(dataTable); + tableDataNameVo.setMapName(mapName); + return tableDataNameVo; + } + else { + map.remove("startTime"); + map.remove("endTime"); + List> listNull = hwDeviceService.selectHistoryDevice(map); + Map map1 = new HashMap(); + if (listNull.size()>1){ + map1 = listNull.get(listNull.size() - 2); + } + dataTable.setTotal(0); + list.get(0).remove("total"); + tableDataNameVo.setMapName(map1); + tableDataNameVo.setTableDataInfo(dataTable); + return tableDataNameVo; + + } + + } + /** + * 返回一级、二级、传感器 + * */ + @GetMapping("/selectComparison") + public AjaxResult selectComparison(){ + List list = hwDeviceService.selectComparison(); + return success(list); + } + /** + * 弹出框导出数据 + * */ + @PostMapping("/export") + public void export(HttpServletResponse response,@RequestParam Map map) + { + List> list = hwDeviceService.getExportDevice(map); + List exportList = new ArrayList<>(); + for (int i = 0; i < list.size(); i++){ + DeviceExport deviceExport = new DeviceExport(); + if (list.get(i).containsKey("deviceId")){ + deviceExport.setDeviceId(Long.valueOf(list.get(i).get("deviceId").toString())); + } + if (list.get(i).containsKey("value1")){ + deviceExport.setValue1(list.get(i).get("value1").toString()); + } + if (list.get(i).containsKey("voltage")){ + deviceExport.setVoltage(list.get(i).get("voltage").toString()); + } + if (list.get(i).containsKey("longitude")){ + deviceExport.setLongitude(list.get(i).get("longitude").toString()); + } + if (list.get(i).containsKey("latitude")){ + deviceExport.setLatitude(list.get(i).get("latitude").toString()); + } + if (list.get(i).containsKey("ts")){ + deviceExport.setTs(list.get(i).get("ts").toString()); + } + exportList.add(deviceExport); + } + ExcelUtil util = new ExcelUtil(DeviceExport.class); + System.out.println(exportList.size()); + util.exportExcel(response,exportList,"历史数据导出"); + + } + + /** + * 进入实际地图后显示计量箱点位标识 + * */ + @GetMapping("/getDeviceByAreaId/{tenantId}") + public AjaxResult getDeviceByAreaId(@PathVariable("tenantId") Long tenantId){ + List deviceList = hwDeviceService.getDeviceByAreaId(tenantId); + return success(deviceList); + } + /** + * 报警信息导出 + * */ + @PostMapping("/AlarmInfosExport") + @RequiresPermissions("business:monitor:alarm") + public void AlarmInfosExport(HttpServletResponse response) { + List alarmInfoExportVos = hwAlarmInfoService.selectAlarmInfoExport(); + ExcelUtil util = new ExcelUtil(AlarmInfoExportVo.class); + util.exportExcel(response,alarmInfoExportVos,"报警数据导出"); + } + /** + * 导入excel,同一个租户重复导入时会覆盖之前的excel + * */ + @PostMapping("/import") + public JSONArray importUser(@RequestPart("file")MultipartFile file,Long tenantId) throws Exception { + JSONArray array = ExcelUtils.readMultipartFile(file); +// System.out.println("导入数据为:" + array); + hwDeviceService.insertRedis(array,tenantId); + return array; + } + /** + * 传入租户id查看导入的excel + * */ + @GetMapping("/getRedisFile/{tenantId}") + public JSONObject getRedisFile(@PathVariable("tenantId") Long tenantId) + { + JSONObject o = hwDeviceService.selectRedisFile(tenantId); + + if (!o.equals(null)&&!o.equals("")){ + + return o; + } + else{ + return null; + } + } + + /** + * 根据模糊查询返回信标设备信息 + * */ + @PostMapping("/selectDeviceByName") + public AjaxResult selectDeviceByName(@RequestBody Map map){ + List deviceList = hwDeviceService.selectMonitorUnitAndDeviceByName(map); + return success(deviceList); + } + + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/BeaconDevice.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/BeaconDevice.java new file mode 100644 index 0000000..6cb3b95 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/BeaconDevice.java @@ -0,0 +1,103 @@ +package com.ruoyi.business.domain; + +/** + * @ClassName : BeaconDevice + * @Description : + * @Author : + * @Date: 2024-06-06 15:31 + */ +public class BeaconDevice { + private Long deviceId; + + private String deviceName; + + private Double latitude; + + private Double longitude; + + private String remark; + + private String deviceLocation; + + private Long deviceModeId; + + private String deviceStatus; + + public String getDeviceStatus() { + return deviceStatus; + } + + public void setDeviceStatus(String deviceStatus) { + this.deviceStatus = deviceStatus; + } + + public Long getDeviceModeId() { + return deviceModeId; + } + + public void setDeviceModeId(Long deviceModeId) { + this.deviceModeId = deviceModeId; + } + + public String getDeviceLocation() { + return deviceLocation; + } + + public void setDeviceLocation(String deviceLocation) { + this.deviceLocation = deviceLocation; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public Double getLatitude() { + return latitude; + } + + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + public Double getLongitude() { + return longitude; + } + + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + @Override + public String toString() { + return "BeaconDevice{" + + "deviceId=" + deviceId + + ", deviceName='" + deviceName + '\'' + + ", latitude=" + latitude + + ", longitude=" + longitude + + ", remark='" + remark + '\'' + + ", deviceLocation='" + deviceLocation + '\'' + + ", deviceModeId=" + deviceModeId + + ", deviceStatus='" + deviceStatus + '\'' + + '}'; + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmInfo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmInfo.java index bf8da07..fc2ef21 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmInfo.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmInfo.java @@ -124,6 +124,18 @@ public class HwAlarmInfo extends BaseEntity { private String monitorUnitName; private String alarmLevelName; private String alarmTypeName; + /** + * 是否处理该传感器全部报警 + * */ + private String ifDisposalAll; + + public String getIfDisposalAll() { + return ifDisposalAll; + } + + public void setIfDisposalAll(String ifDisposalAll) { + this.ifDisposalAll = ifDisposalAll; + } public void setAlarmInfoId(Long alarmInfoId) { this.alarmInfoId = alarmInfoId; diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java index 3f736a1..40123d9 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwDevice.java @@ -170,6 +170,25 @@ public class HwDevice extends BaseEntity { // @Excel(name = "在线状态", readConverterExp = "1=在线,0离线") private String onlineStatus; + /** + * 经度 + * */ + private Double longitude; + /** + * 纬度 + * */ + private Double latitude; + + private String functionName; + + public String getFunctionName() { + return functionName; + } + + public void setFunctionName(String functionName) { + this.functionName = functionName; + } + private String monitorUnitName; private String sceneName; @@ -180,6 +199,43 @@ public class HwDevice extends BaseEntity { private Long offlineRuleId; + private String publicTime; + + //是否报警 + private String ifAlarm; + + public String getIfAlarm() { + return ifAlarm; + } + + public void setIfAlarm(String ifAlarm) { + this.ifAlarm = ifAlarm; + } + + public Double getLongitude() { + return longitude; + } + + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + public Double getLatitude() { + return latitude; + } + + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + public String getPublicTime() { + return publicTime; + } + + public void setPublicTime(String publicTime) { + this.publicTime = publicTime; + } + public void setDeviceId(Long deviceId) { this.deviceId = deviceId; } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwElectronicFence.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwElectronicFence.java index b1b07ef..19435a0 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwElectronicFence.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwElectronicFence.java @@ -8,7 +8,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity; /** * 电子围栏对象 hw_electronic_fence - * + * * @author xins * @date 2023-09-19 */ @@ -76,121 +76,131 @@ public class HwElectronicFence extends BaseEntity private String circleAreaListStr; private String alarmInfoFlag;//是否有报警信息关联标识 + //电子围栏区域信息 + private List hwFenceAreaList; - public void setElectronicFenceId(Long electronicFenceId) + public List getHwFenceAreaList() { + return hwFenceAreaList; + } + + public void setHwFenceAreaList(List hwFenceAreaList) { + this.hwFenceAreaList = hwFenceAreaList; + } + + public void setElectronicFenceId(Long electronicFenceId) { this.electronicFenceId = electronicFenceId; } - public Long getElectronicFenceId() + public Long getElectronicFenceId() { return electronicFenceId; } - public void setElectronicFenceName(String electronicFenceName) + public void setElectronicFenceName(String electronicFenceName) { this.electronicFenceName = electronicFenceName; } - public String getElectronicFenceName() + public String getElectronicFenceName() { return electronicFenceName; } - public void setTenantId(Long tenantId) + public void setTenantId(Long tenantId) { this.tenantId = tenantId; } - public Long getTenantId() + public Long getTenantId() { return tenantId; } - public void setSceneId(Long sceneId) + public void setSceneId(Long sceneId) { this.sceneId = sceneId; } - public Long getSceneId() + public Long getSceneId() { return sceneId; } - public void setFenceType(String fenceType) + public void setFenceType(String fenceType) { this.fenceType = fenceType; } - public String getFenceType() + public String getFenceType() { return fenceType; } - public void setEffectiveTimeFlag(String effectiveTimeFlag) + public void setEffectiveTimeFlag(String effectiveTimeFlag) { this.effectiveTimeFlag = effectiveTimeFlag; } - public String getEffectiveTimeFlag() + public String getEffectiveTimeFlag() { return effectiveTimeFlag; } - public void setTimeZone(String timeZone) + public void setTimeZone(String timeZone) { this.timeZone = timeZone; } - public String getTimeZone() + public String getTimeZone() { return timeZone; } - public void setEffectiveTime(String effectiveTime) + public void setEffectiveTime(String effectiveTime) { this.effectiveTime = effectiveTime; } - public String getEffectiveTime() + public String getEffectiveTime() { return effectiveTime; } - public void setTriggerStatus(String triggerStatus) + public void setTriggerStatus(String triggerStatus) { this.triggerStatus = triggerStatus; } - public String getTriggerStatus() + public String getTriggerStatus() { return triggerStatus; } - public void setFencePushFlag(String fencePushFlag) + public void setFencePushFlag(String fencePushFlag) { this.fencePushFlag = fencePushFlag; } - public String getFencePushFlag() + public String getFencePushFlag() { return fencePushFlag; } - public void setFencePushContent(String fencePushContent) + public void setFencePushContent(String fencePushContent) { this.fencePushContent = fencePushContent; } - public String getFencePushContent() + public String getFencePushContent() { return fencePushContent; } - public void setFenceRecoverContent(String fenceRecoverContent) + public void setFenceRecoverContent(String fenceRecoverContent) { this.fenceRecoverContent = fenceRecoverContent; } - public String getFenceRecoverContent() + public String getFenceRecoverContent() { return fenceRecoverContent; } - public void setFenceField(String fenceField) + public void setFenceField(String fenceField) { this.fenceField = fenceField; } - public String getFenceField() + public String getFenceField() { return fenceField; } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java index 68fbb69..1e7f3e7 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwMonitorUnit.java @@ -70,6 +70,16 @@ public class HwMonitorUnit extends BaseEntity private String tenantName; private boolean normalFlag;//是否正常(如果有报警未处理的则为异常) + private List devicesList; + + public List getDevicesList() { + return devicesList; + } + + public void setDevicesList(List devicesList) { + this.devicesList = devicesList; + } + private List child = new ArrayList(); /** 子部门 */ @@ -253,4 +263,4 @@ public class HwMonitorUnit extends BaseEntity .append("monitorUnitField", getMonitorUnitField()) .toString(); } -} \ No newline at end of file +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwScene.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwScene.java index e3a926c..8d265ec 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwScene.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwScene.java @@ -1,6 +1,8 @@ package com.ruoyi.business.domain; import java.math.BigDecimal; +import java.util.List; + import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; @@ -10,7 +12,7 @@ import javax.validation.constraints.NotNull; /** * 场景信息对象 hw_scene - * + * * @author xins * @date 2023-08-23 */ @@ -83,138 +85,148 @@ public class HwScene extends BaseEntity private String selectedDisable; - public void setSceneId(Long sceneId) + private List unitList; + + public List getUnitList() { + return unitList; + } + + public void setUnitList(List unitList) { + this.unitList = unitList; + } + + public void setSceneId(Long sceneId) { this.sceneId = sceneId; } - public Long getSceneId() + public Long getSceneId() { return sceneId; } - public void setSceneName(String sceneName) + public void setSceneName(String sceneName) { this.sceneName = sceneName; } - public String getSceneName() + public String getSceneName() { return sceneName; } - public void setTenantId(Long tenantId) + public void setTenantId(Long tenantId) { this.tenantId = tenantId; } - public Long getTenantId() + public Long getTenantId() { return tenantId; } - public void setSceneModeId(Long sceneModeId) + public void setSceneModeId(Long sceneModeId) { this.sceneModeId = sceneModeId; } - public Long getSceneModeId() + public Long getSceneModeId() { return sceneModeId; } - public void setScenePic(String scenePic) + public void setScenePic(String scenePic) { this.scenePic = scenePic; } - public String getScenePic() + public String getScenePic() { return scenePic; } - public void setDefaultFlag(String defaultFlag) + public void setDefaultFlag(String defaultFlag) { this.defaultFlag = defaultFlag; } - public String getDefaultFlag() + public String getDefaultFlag() { return defaultFlag; } - public void setSceneStatus(String sceneStatus) + public void setSceneStatus(String sceneStatus) { this.sceneStatus = sceneStatus; } - public String getSceneStatus() + public String getSceneStatus() { return sceneStatus; } - public void setAuthMode(String authMode) + public void setAuthMode(String authMode) { this.authMode = authMode; } - public String getAuthMode() + public String getAuthMode() { return authMode; } - public void setModeAccount(String modeAccount) + public void setModeAccount(String modeAccount) { this.modeAccount = modeAccount; } - public String getModeAccount() + public String getModeAccount() { return modeAccount; } - public void setModeKey(String modeKey) + public void setModeKey(String modeKey) { this.modeKey = modeKey; } - public String getModeKey() + public String getModeKey() { return modeKey; } - public void setModeSecret(String modeSecret) + public void setModeSecret(String modeSecret) { this.modeSecret = modeSecret; } - public String getModeSecret() + public String getModeSecret() { return modeSecret; } - public void setPreserveTime(BigDecimal preserveTime) + public void setPreserveTime(BigDecimal preserveTime) { this.preserveTime = preserveTime; } - public BigDecimal getPreserveTime() + public BigDecimal getPreserveTime() { return preserveTime; } - public void setTestPreserveTime(BigDecimal testPreserveTime) + public void setTestPreserveTime(BigDecimal testPreserveTime) { this.testPreserveTime = testPreserveTime; } - public BigDecimal getTestPreserveTime() + public BigDecimal getTestPreserveTime() { return testPreserveTime; } - public void setSceneEnvironment(String sceneEnvironment) + public void setSceneEnvironment(String sceneEnvironment) { this.sceneEnvironment = sceneEnvironment; } - public String getSceneEnvironment() + public String getSceneEnvironment() { return sceneEnvironment; } - public void setSceneField(String sceneField) + public void setSceneField(String sceneField) { this.sceneField = sceneField; } - public String getSceneField() + public String getSceneField() { return sceneField; } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTenant.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTenant.java index f5d22e3..050b4cf 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTenant.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwTenant.java @@ -104,6 +104,18 @@ public class HwTenant extends BaseEntity { // @Excel(name = "预留字段") private String tenantField; + /** + * 行政区域代码 + */ + private String tenantMapCode; + + public String getTenantMapCode() { + return tenantMapCode; + } + + public void setTenantMapCode(String tenantMapCode) { + this.tenantMapCode = tenantMapCode; + } public void setTenantId(Long tenantId) { this.tenantId = tenantId; diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java new file mode 100644 index 0000000..2452269 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AlarmInfoExportVo.java @@ -0,0 +1,90 @@ +package com.ruoyi.business.domain.VO; + +import com.ruoyi.common.core.annotation.Excel; + +import javax.validation.constraints.Email; + +/** + * @ClassName : AlarmInfoExportVo + * @Description : + * @Author : + * @Date: 2024-06-14 09:52 + */ +public class AlarmInfoExportVo { + @Excel(name = "报警id") + private Long alarmInfoId; + + @Excel(name = "报警区域") + private String areaName; + + @Excel(name = "计量箱名称") + private String monitorUnitName; + + @Excel(name = "报警级别名称") + private String alarmLevelName; + + @Excel(name = "报警类型名称") + private String alarmTypeName; + + @Excel(name = "报警时间") + private String alarmTime; + + public Long getAlarmInfoId() { + return alarmInfoId; + } + + public void setAlarmInfoId(Long alarmInfoId) { + this.alarmInfoId = alarmInfoId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public String getMonitorUnitName() { + return monitorUnitName; + } + + public void setMonitorUnitName(String monitorUnitName) { + this.monitorUnitName = monitorUnitName; + } + + public String getAlarmLevelName() { + return alarmLevelName; + } + + public void setAlarmLevelName(String alarmLevelName) { + this.alarmLevelName = alarmLevelName; + } + + public String getAlarmTypeName() { + return alarmTypeName; + } + + public void setAlarmTypeName(String alarmTypeName) { + this.alarmTypeName = alarmTypeName; + } + + public String getAlarmTime() { + return alarmTime; + } + + public void setAlarmTime(String alarmTime) { + this.alarmTime = alarmTime; + } + + @Override + public String toString() { + return "AlarmInfoExportVo{" + + "alarmInfoId=" + alarmInfoId + + ", monitorUnitName='" + monitorUnitName + '\'' + + ", alarmLevelName='" + alarmLevelName + '\'' + + ", alarmTypeName='" + alarmTypeName + '\'' + + ", alarmTime='" + alarmTime + '\'' + + '}'; + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AllNumsVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AllNumsVo.java index c053fe6..5a7a764 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AllNumsVo.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/AllNumsVo.java @@ -9,6 +9,7 @@ import java.util.List; * @Date: 2023-09-04 09:00 */ public class AllNumsVo { + private Integer beaconDeviceSum; private String sceneId; private Integer subSum; private Integer sum; @@ -37,6 +38,14 @@ public class AllNumsVo { this.sum = sum; } + public Integer getBeaconDeviceSum() { + return beaconDeviceSum; + } + + public void setBeaconDeviceSum(Integer beaconDeviceSum) { + this.beaconDeviceSum = beaconDeviceSum; + } + @Override public String toString() { return "AllNumsVo{" + diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceExport.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceExport.java new file mode 100644 index 0000000..5e308f6 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceExport.java @@ -0,0 +1,85 @@ +package com.ruoyi.business.domain.VO; + +import com.ruoyi.common.core.annotation.Excel; +import org.springframework.web.bind.annotation.ExceptionHandler; + +/** + * @ClassName : DeviceExport + * @Description : + * @Author : + * @Date: 2024-06-12 13:26 + */ +public class DeviceExport { + @Excel(name = "设备ID") + private Long deviceId; + @Excel(name = "温度") + private String value1; + @Excel(name = "电压") + private String voltage; + @Excel(name = "经度") + private String longitude; + @Excel(name = "纬度") + private String latitude; + @Excel(name = "记录时间") + private String ts; + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public String getValue1() { + return value1; + } + + public void setValue1(String value1) { + this.value1 = value1; + } + + public String getVoltage() { + return voltage; + } + + public void setVoltage(String voltage) { + this.voltage = voltage; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + @Override + public String toString() { + return "DeviceExport{" + + "deviceId=" + deviceId + + ", value1='" + value1 + '\'' + + ", voltage='" + voltage + '\'' + + ", longitude='" + longitude + '\'' + + ", latitude='" + latitude + '\'' + + ", ts='" + ts + '\'' + + '}'; + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/TreeAreaVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/TreeAreaVo.java new file mode 100644 index 0000000..d9f4701 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/TreeAreaVo.java @@ -0,0 +1,115 @@ +package com.ruoyi.business.domain.VO; + +import com.ruoyi.business.domain.HwDevice; +import com.ruoyi.business.domain.HwMonitorUnit; +import com.ruoyi.common.core.web.domain.BaseEntity; + +import java.util.List; + +/** + * @ClassName : TreeAreaVo + * @Description : + * @Author : + * @Date: 2024-06-13 10:20 + */ +public class TreeAreaVo { + + private Long areaId; + + private String areaName; + +// private String ancestors; +// +// private Long parentId; +// +// private String areaStatus; +// +// private Long orderNum; + + private List listArea; + + private List deviceList; + + private List monitorUnitList; + + public List getMonitorUnitList() { + return monitorUnitList; + } + + public void setMonitorUnitList(List monitorUnitList) { + this.monitorUnitList = monitorUnitList; + } + + public List getDeviceList() { + return deviceList; + } + + public void setDeviceList(List deviceList) { + this.deviceList = deviceList; + } + + public Long getAreaId() { + return areaId; + } + + public void setAreaId(Long areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } +// +// public String getAncestors() { +// return ancestors; +// } +// +// public void setAncestors(String ancestors) { +// this.ancestors = ancestors; +// } +// +// public Long getParentId() { +// return parentId; +// } +// +// public void setParentId(Long parentId) { +// this.parentId = parentId; +// } +// +// public String getAreaStatus() { +// return areaStatus; +// } +// +// public void setAreaStatus(String areaStatus) { +// this.areaStatus = areaStatus; +// } +// +// public Long getOrderNum() { +// return orderNum; +// } +// +// public void setOrderNum(Long orderNum) { +// this.orderNum = orderNum; +// } + + public List getListArea() { + return listArea; + } + + public void setListArea(List listArea) { + this.listArea = listArea; + } + + @Override + public String toString() { + return "TreeAreaVo{" + + "areaId=" + areaId + + ", areaName='" + areaName + '\'' + + ", listArea=" + listArea + + '}'; + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/TreeDeviceVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/TreeDeviceVo.java new file mode 100644 index 0000000..dab70dc --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/TreeDeviceVo.java @@ -0,0 +1,73 @@ +package com.ruoyi.business.domain.VO; + +import java.util.List; + +/** + * @ClassName : TreeDeviceVo + * @Description : + * @Author : + * @Date: 2024-06-11 17:47 + */ +public class TreeDeviceVo { + + private Long voId; + + private String voName; + + private Long parentId; + + private List voList; + + private String prop; + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + + public Long getVoId() { + return voId; + } + + public void setVoId(Long voId) { + this.voId = voId; + } + + public String getVoName() { + return voName; + } + + public void setVoName(String voName) { + this.voName = voName; + } + + public Long getParentId() { + return parentId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } + + public List getVoList() { + return voList; + } + + public void setVoList(List voList) { + this.voList = voList; + } + + @Override + public String toString() { + return "TreeDeviceVo{" + + "voId=" + voId + + ", voName='" + voName + '\'' + + ", parentId=" + parentId + + ", voList=" + voList + + ", prop=" + prop + + '}'; + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java index a6c834e..029ecb6 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java @@ -2,20 +2,21 @@ package com.ruoyi.business.mapper; import java.util.List; import com.ruoyi.business.domain.HwAlarmInfo; +import com.ruoyi.business.domain.VO.AlarmInfoExportVo; import com.ruoyi.business.domain.VO.AlarmInfoVo; import com.ruoyi.business.domain.VO.AlarmTypeVo; /** * 报警信息Mapper接口 - * + * * @author xins * @date 2023-09-15 */ -public interface HwAlarmInfoMapper +public interface HwAlarmInfoMapper { /** * 查询报警信息 - * + * * @param alarmInfoId 报警信息主键 * @return 报警信息 */ @@ -23,7 +24,7 @@ public interface HwAlarmInfoMapper /** * 查询报警信息列表 - * + * * @param hwAlarmInfo 报警信息 * @return 报警信息集合 */ @@ -31,7 +32,7 @@ public interface HwAlarmInfoMapper /** * 新增报警信息 - * + * * @param hwAlarmInfo 报警信息 * @return 结果 */ @@ -39,15 +40,16 @@ public interface HwAlarmInfoMapper /** * 修改报警信息 - * + * * @param hwAlarmInfo 报警信息 * @return 结果 */ public int updateHwAlarmInfo(HwAlarmInfo hwAlarmInfo); + /** * 删除报警信息 - * + * * @param alarmInfoId 报警信息主键 * @return 结果 */ @@ -55,7 +57,7 @@ public interface HwAlarmInfoMapper /** * 批量删除报警信息 - * + * * @param alarmInfoIds 需要删除的数据主键集合 * @return 结果 */ @@ -74,4 +76,14 @@ public interface HwAlarmInfoMapper * @return int */ public int selectAlarmCountByMonitorUnitId(Long monitorUnitId); + + /** + * 导出报警信息 + * */ + List selectAlarmInfoExport(); + + /** + * 批量处理报警信息 + * */ + public int updateHwAlarmInfoAllByDevice(HwAlarmInfo hwAlarmInfo); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java index ce781f0..5ade911 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java @@ -1,9 +1,15 @@ package com.ruoyi.business.mapper; +import java.util.HashMap; import java.util.List; +import java.util.Map; + import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.HwMonitorUnitVo; +import com.ruoyi.business.domain.VO.TreeAreaVo; +import com.ruoyi.business.domain.VO.TreeDeviceVo; +import org.apache.ibatis.annotations.Param; /** * 设备信息Mapper接口 @@ -108,9 +114,9 @@ public interface HwDeviceMapper * @return HwDevice */ public HwDevice selectHwDeviceByDeviceCode(String deviceCode); - + public int selectDeviceNumCount(HwDevice hwDevice); - + public int selectAbnormalDeviceNumCount(HwDevice hwDevice); @@ -134,4 +140,34 @@ public interface HwDeviceMapper * @return List */ public List selectUnallocatedList(HwDevice hwDevice); + + /** + * 查询设备列表集合 + * */ + List selectDeviceList(); + + /** + * 查询设备的字段名 + * */ + public String selectPropBydeviceIdAndFunctionName(@Param(value = "deviceModeId") Long deviceModeId,@Param(value = "functionName") String functionName); + + /** + * 根据地图显示计量箱点位标识 + * */ + List getDeviceByAreaId(@Param(value = "tenantId") Long tenantId,@Param(value = "areaId") Long areaId); + List getTreeArea(Long areaId); + + /** + * 获取监控单元下的信标设备 + * */ + List getDeviceListInMonitorUnit(Long monitorUnitId); + + /** + * 根据设备模型标识符获取设备模型名称 + * */ + String selectFunctionNameByFunctionIdentifier(String functionIdentifier); + /** + * 根据设备id查询该设备是否报警 + * */ + Integer selectDeviceIfAlarm(Long deviceId); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwElectronicFenceMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwElectronicFenceMapper.java index dcde8cf..536ef1b 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwElectronicFenceMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwElectronicFenceMapper.java @@ -114,4 +114,10 @@ public interface HwElectronicFenceMapper * @return 结果 */ public int deleteHwFenceAreaByElectronicFenceId(Long electronicFenceId); + + /** + * 查询电子围栏信息根据设备id + * */ + List selectMonitorElectronic(Long deviceId); + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java index fae663f..fbd88be 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwMonitorUnitMapper.java @@ -1,11 +1,13 @@ package com.ruoyi.business.mapper; import java.util.List; +import java.util.Map; import com.alibaba.druid.support.http.MonitorClientContextListener; import com.ruoyi.business.domain.HwMonitorUnit; import com.ruoyi.business.domain.HwScene; import com.ruoyi.business.domain.VO.*; +import org.apache.ibatis.annotations.Param; /** * 监控单元Mapper接口 @@ -155,4 +157,31 @@ public interface HwMonitorUnitMapper */ public int deleteMonitorUnitById(Long monitorUnitId); -} \ No newline at end of file + /** + * 查询信标设备数量 + * */ + Integer selectBeaconDeviceNums(Long sceneId); + + /** + * 根据场景查询信标设备 + * */ + Integer[] selectBeaconDeviceBySceneId(Long sceneId); + + /** + * 根据设备id查询其对应的电子围栏信息 + * */ + HwMonitorUnit selectMonitorUnit(Long deviceId); + + /** + * 查询监控单元信息并返回map + * */ + List selectMonitorUnitReturnMap(); + + /** + * 根据区域id查询监控单元 + * */ + List getMonitorUnitByAreaId(@Param(value = "tenantId") Long tenantId, @Param(value = "areaId") Long areaId); + + List selectMonitorUnitListHavAreaId(Long tenantId); + +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwSceneMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwSceneMapper.java index 917cc85..9066b95 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwSceneMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwSceneMapper.java @@ -1,8 +1,11 @@ package com.ruoyi.business.mapper; import java.util.List; +import java.util.Map; + import com.ruoyi.business.domain.HwScene; import com.ruoyi.business.domain.VO.HwSceneVo; +import com.ruoyi.business.domain.VO.TreeDeviceVo; /** * 场景信息Mapper接口 @@ -66,4 +69,9 @@ public interface HwSceneMapper * @return 结果 */ public int deleteHwSceneBySceneIds(Long[] sceneIds); + + /** + * 查询场景信息集合 + * */ + public List selectHwSceneListReturnMap(); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java index d5f150b..dfc742c 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmInfoService.java @@ -2,19 +2,20 @@ package com.ruoyi.business.service; import java.util.List; import com.ruoyi.business.domain.HwAlarmInfo; +import com.ruoyi.business.domain.VO.AlarmInfoExportVo; import com.ruoyi.business.domain.VO.AlarmTypeVo; /** * 报警信息Service接口 - * + * * @author xins * @date 2023-09-15 */ -public interface IHwAlarmInfoService +public interface IHwAlarmInfoService { /** * 查询报警信息 - * + * * @param alarmInfoId 报警信息主键 * @return 报警信息 */ @@ -22,7 +23,7 @@ public interface IHwAlarmInfoService /** * 查询报警信息列表 - * + * * @param hwAlarmInfo 报警信息 * @return 报警信息集合 */ @@ -30,7 +31,7 @@ public interface IHwAlarmInfoService /** * 新增报警信息 - * + * * @param hwAlarmInfo 报警信息 * @return 结果 */ @@ -38,7 +39,7 @@ public interface IHwAlarmInfoService /** * 修改报警信息 - * + * * @param hwAlarmInfo 报警信息 * @return 结果 */ @@ -46,7 +47,7 @@ public interface IHwAlarmInfoService /** * 批量删除报警信息 - * + * * @param alarmInfoIds 需要删除的报警信息主键集合 * @return 结果 */ @@ -54,7 +55,7 @@ public interface IHwAlarmInfoService /** * 删除报警信息信息 - * + * * @param alarmInfoId 报警信息主键 * @return 结果 */ @@ -68,4 +69,10 @@ public interface IHwAlarmInfoService * @return List */ public List selectAlarmsByAlarmType(Long sceneId); + + /** + * 导出报警信息 + * */ + List selectAlarmInfoExport(); + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java index 1ca2caf..4599534 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java @@ -1,10 +1,12 @@ package com.ruoyi.business.service; +import java.util.HashMap; import java.util.List; import java.util.Map; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.ruoyi.business.domain.HwDevice; +import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.VO.*; import com.ruoyi.common.datascope.annotation.DataScope; @@ -213,4 +215,53 @@ public interface IHwDeviceService { */ public List selectUnallocatedList(HwDevice device); + + /** + * 查询设备经纬度 + * */ + public List selectDeviceLatitudeAndLongitude(Long sceneId); + + /** + * 查询历史信标数据 + * */ + public List> selectBeaconDevicesHistory(Map map); + /** + * 根据设备查询其电子围栏 + * */ + public HwMonitorUnit selectMonitorUnit(Long deviceId); + + /** + * 支持多参数查询历史数据 + * */ + public List> selectHistoryDevice(Map map); + + /** + * 返回一级、二级、传感器 + * */ + public List selectComparison(); + + /** + * 导出数据接口 + * */ + List> getExportDevice(Map map); + /** + * 根据地图显示计量箱点位标识 + * */ + List getDeviceByAreaId(Long tenantId); + /** + * 查询电子围栏信息根据设备id + * */ + List selectMonitorElectronic(Long deviceId); + /** + * 将数据存入到redis中 + * */ + void insertRedis(JSONArray jsonArray,Long tenantId); + JSONObject selectRedisFile(Long tenantId); + + /** + * 根据监控单元/设备名称查询监控单元 + * */ + ListselectMonitorUnitAndDeviceByName(Map map); + + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java index 42f07bc..cb2ad69 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.stream.Collectors; import com.ruoyi.business.domain.HwAlarmType; +import com.ruoyi.business.domain.VO.AlarmInfoExportVo; import com.ruoyi.business.domain.VO.AlarmTypeVo; import com.ruoyi.business.mapper.HwAlarmTypeMapper; import com.ruoyi.common.core.constant.HwDictConstants; @@ -76,7 +77,14 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService { public int updateHwAlarmInfo(HwAlarmInfo hwAlarmInfo) { hwAlarmInfo.setUpdateTime(DateUtils.getNowDate()); hwAlarmInfo.setHandleStatus(HwDictConstants.ALARM_HANDLE_STATUS_YES); - return hwAlarmInfoMapper.updateHwAlarmInfo(hwAlarmInfo); + + if (hwAlarmInfo.getIfDisposalAll().equals("0")){ + return hwAlarmInfoMapper.updateHwAlarmInfo(hwAlarmInfo); + } + else { + return hwAlarmInfoMapper.updateHwAlarmInfoAllByDevice(hwAlarmInfo); + } + } /** @@ -142,4 +150,9 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService { } return list; } + + @Override + public List selectAlarmInfoExport() { + return hwAlarmInfoMapper.selectAlarmInfoExport(); + } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java index 7fed586..a7749c6 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.business.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.VO.*; import com.ruoyi.business.mapper.*; @@ -19,17 +20,25 @@ import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.NumberUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.datascope.annotation.DataScope; +import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.domain.*; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.data.redis.cache.RedisCache; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import sun.reflect.generics.tree.Tree; import javax.annotation.Resource; +import java.io.File; +import java.sql.Timestamp; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -56,7 +65,12 @@ public class HwDeviceServiceImpl implements IHwDeviceService { private StringRedisTemplate redisTemplate; @Autowired private HwAlarmInfoMapper hwAlarmInfoMapper; - + @Autowired + private HwElectronicFenceMapper hwElectronicFenceMapper; + @Autowired + private RedisService redisService; + @Autowired + private HwFenceAreaMapper hwFenceAreaMapper; /** * 查询设备信息 * @@ -65,7 +79,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { */ @Override public HwDevice selectHwDeviceByDeviceId(Long deviceId) { - return hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); } @@ -1123,4 +1136,410 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return hwDeviceMapper.selectUnallocatedList(device); } + + /** + * + * 查询设备经纬度 + * */ + @Override + public List selectDeviceLatitudeAndLongitude(Long sceneId) { + //根据场景查询下面的设备 + HwDevice device = new HwDevice(); + device.setSceneId(sceneId); + List hwDevices = hwDeviceMapper.selectHwDeviceList(device); + Integer[] integers = hwMonitorUnitMapper.selectBeaconDeviceBySceneId(sceneId); + //调用tde查询每个设备的经纬度 + if (integers.length!=0){ + TdSelectDto tdSelectDto = new TdSelectDto(); + tdSelectDto.setDatabaseName(TdEngineConstants.PLATFORM_DB_NAME); + TdField tdField = new TdField(); + tdField.setFieldName("longitude"); + TdField tdField1 = new TdField(); + tdField1.setFieldName("latitude"); + List fields = new ArrayList(); + fields.add(tdField); + fields.add(tdField1); + tdSelectDto.setSchemaFieldValues(fields); + List lists = new ArrayList(); + for (int i = 0;i latestData = remoteTdEngineService.getLatestData(tdSelectDto, SecurityConstants.INNER); + Object data = latestData.getData(); + String s = JSONObject.toJSONString(data); + if (latestData.getCode()!=500){ + String substring = s.substring(1, s.length() - 1); + if (!substring.isEmpty()){ + Map map = JSONObject.parseObject(substring, Map.class); + if (map.size()==2){ + BeaconDevice beaconDevice = new BeaconDevice(); + beaconDevice.setDeviceId(hwDevices.get(i).getDeviceId()); + beaconDevice.setDeviceName(hwDevices.get(i).getDeviceName()); + beaconDevice.setLatitude(Double.valueOf( map.get("latitude").toString())); + beaconDevice.setLongitude(Double.valueOf( map.get("longitude").toString())); + beaconDevice.setRemark(hwDevices.get(i).getRemark()); + beaconDevice.setDeviceLocation(hwDevices.get(i).getDeviceLocation()); + beaconDevice.setDeviceLocation("白银市"); + beaconDevice.setDeviceModeId(hwDevices.get(i).getDeviceModeId()); + lists.add(beaconDevice); + } + } + + } + + } +// System.out.println(lists); + return lists; + } + return null; + + } + + /** + * 根据设备id查询信标设备历史数据 + * */ + @Override + public List> selectBeaconDevicesHistory(Map map) { + TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto(); + tdHistorySelectDto.setDatabaseName(TdEngineConstants.PLATFORM_DB_NAME); + tdHistorySelectDto.setTableName(TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX+map.get("deviceId")); + tdHistorySelectDto.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + if (map.get("pageSize")!=null){ + tdHistorySelectDto.setLimit(Integer.valueOf(map.get("pageSize").toString())); + } + if (map.get("pageSize")!=null&&map.get("pageNum")!=null){ + tdHistorySelectDto.setOffset(Integer.valueOf(map.get("pageSize").toString())*(Integer.valueOf(map.get("pageNum").toString())-1)); + } + tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + tdHistorySelectDto.setSort(TdEngineConstants.DEFAULT_ORDER_BY_MODE); + if (map.containsKey("startTime")&&map.get("startTime")!=null){ + tdHistorySelectDto.setStartTime(Timestamp.valueOf(map.get("startTime").toString()).getTime()); + } + if (map.containsKey("endTime")&&map.get("endTime")!=null){ + tdHistorySelectDto.setEndTime(Timestamp.valueOf(map.get("endTime").toString()).getTime()); + } + R historyData = remoteTdEngineService.getHistoryData(tdHistorySelectDto, SecurityConstants.INNER); + System.out.println("查询历史数据"+map.get("deviceId")); + List> dataList = historyData.getData().dataList; + for (int i = 0; i < dataList.size(); i++){ + dataList.get(i).put("deviceId",map.get("deviceId")); + } + int count = historyData.getData().count; + Map map1 = new HashMap<>(); + map1.put("total",count); + dataList.add(map1); + return dataList; + } + + /** + * 根据设备id查询其对应的监控单元 + * */ + @Override + public HwMonitorUnit selectMonitorUnit(Long deviceId) { + HwMonitorUnit hwMonitorUnit = hwMonitorUnitMapper.selectMonitorUnit(deviceId); + return hwMonitorUnit; + } + + /** + * 历史数据弹出框(多参数且可多选) + * */ + @Override + public List> selectHistoryDevice(Map map) { + //1-趋势分析 2历史数据 + //如果是趋势分析就删除分页 + Long pageSize = 0l; + if (map.get("type")!=null){ + if (map.get("type").toString().equals("1")){ + map.remove("pageSize"); + map.remove("pageNum"); + } + else { + pageSize = Long.valueOf(map.get("pageSize").toString()); + } + } + + String deviceIds = map.get("deviceIds").toString(); + String[] str = deviceIds.split(","); + map.replace("pageSize",pageSize/str.length); + List> list = new ArrayList>(); + Long total = 0l; + for (int i = 0; i < str.length; i++) { + map.put("deviceId",str[i]); + if (i== str.length-2){ + map.replace("pageSize",pageSize%str.length); + } + if (map.get("prop")!=null){ + //查询类型的字段名 + String s = hwDeviceMapper.selectPropBydeviceIdAndFunctionName(Long.valueOf(map.get("deviceId").toString()) + , map.get("prop").toString()); + map.put("functionIdentifier",s); + } + List> list1 = this.selectBeaconDevicesHistory(map); + total = total+Long.valueOf(list1.get(list1.size()-1).get("total").toString()); + list1.remove(list1.size()-1); + List> list2 = new ArrayList>(); + //在弹出框中进行对比时,对历史数据进行过滤,根据传入的传感器类型 + + if (map.get("functionIdentifier")!=null) { + for (int x = 0; x < list1.size(); x++) { + //查看数据中是否拥有所需要的数据,没有进入下一循环 + if (list1.get(i).get(map.get("functionIdentifier").toString())==null){ + continue; + } + Map map2 = new HashMap(); + //获取出需要的数据存入返回值中 + map2.put("deviceId", list1.get(x).get("deviceId")); + map2.put("ts", list1.get(x).get("ts")); + map2.put("deviceName", list1.get(x).get("deviceName")); + map2.put("functionName", map.get("prop")); + map2.put("functionIdentifier", + list1.get(x).get(map.get("functionIdentifier").toString())); + list.add(map2); + } + } + else { + list.addAll(list1); + } + } + Map mapName = new HashMap(); + if (list.size()>0){ + Set strings = list.get(0).keySet(); + List list2 = new ArrayList(); + list2.addAll(strings); + for (int i = 0; i < list2.size(); i++) { + //查询类型的字段名 + String s = hwDeviceMapper.selectFunctionNameByFunctionIdentifier(list2.get(i)); + mapName.put(list2.get(i),s); + } + list.add(mapName); + } + if (map.get("type")!=null&&map.get("type").equals("1") ){ + for (int i = 0; i < list.size(); i++) { + if (list.get(i).containsKey("valid")){ + list.get(i).remove("valid"); + } + if (list.get(i).containsKey("acc")){ + list.get(i).remove("acc"); + } + if (list.get(i).containsKey("version")){ + list.get(i).remove("version"); + } + if (list.get(i).containsKey("speed")){ + list.get(i).remove("speed"); + } + } + } + + Map mapTotal = new HashMap(); + mapTotal.put("total", total); + list.add(mapTotal); + return list; + } + + /** + * 返回一级、二级、传感器 + * */ + @Override + public List selectComparison() { + List sceneMap = hwSceneMapper.selectHwSceneListReturnMap(); + List unitMap = hwMonitorUnitMapper.selectMonitorUnitReturnMap(); + List deviceMap = hwDeviceMapper.selectDeviceList(); + for (int i = 0; i < unitMap.size(); i++) { + List list = new ArrayList(); + for (int j = 0; j < deviceMap.size(); j++) { + if (unitMap.get(i).getVoId() == deviceMap.get(j).getParentId()) { + list.add(deviceMap.get(j)); + } + } + unitMap.get(i).setVoList(list); + } + for (int i = 0; i < sceneMap.size(); i++) { + List list = new ArrayList(); + for (int j = 0; j < unitMap.size(); j++) { + if (sceneMap.get(i).getVoId().equals(unitMap.get(j).getParentId())) { + list.add(unitMap.get(j)); + } + } + sceneMap.get(i).setVoList(list); + } + + return sceneMap; + + + } + + /** + * 导出excel + * */ + @Override + public List> getExportDevice(Map map) { + map.remove("pageSize"); + map.remove("pageNum"); + String deviceIds = map.get("deviceIds").toString(); + String[] str = deviceIds.split(","); + List> exportList = new ArrayList>(); + for (int i = 0; i < str.length; i++) { + map.put("deviceId",str[i]); + + List> list1 = this.selectBeaconDevicesHistory(map); + list1.remove(list1.size()-1); + exportList.addAll(list1); + + } + return exportList; + } + + /** + * 查询租户下的所有信标设备下挂到监控单元 + * */ + @Override + public List getDeviceByAreaId(Long tenantId) { + //如果是管理员,则不对租户进行过滤,即可以看到城市下所有租户的设备信息 + if (tenantId==1l) + { + tenantId = null; + } + + /** + * 逻辑 + *先根据租户id查询所有的监控单元 + * 再根据监控单元查出所有信标设备然后返回 + * */ + HwMonitorUnit hwMonitorUnit = new HwMonitorUnit(); + hwMonitorUnit.setTenantId(tenantId); + List unitList = hwMonitorUnitMapper.selectMonitorUnitListHavAreaId(tenantId); + for (int i = 0; i < unitList.size(); i++){ + List deviceList = this.getDeviceListInMonitorUnit(unitList.get(i).getMonitorUnitId()); + unitList.get(i).setDevicesList(deviceList); + } +// List treeArea1 = hwDeviceMapper.getTreeArea(areaId); +// for (int i=0;i selectMonitorElectronic(Long deviceId) { + List hwElectronicFences = hwElectronicFenceMapper.selectMonitorElectronic(deviceId); + for (int i = 0; i < hwElectronicFences.size();i++){ + HwFenceArea hwFenceArea = new HwFenceArea(); + hwFenceArea.setElectronicFenceId(hwElectronicFences.get(i).getElectronicFenceId()); + List hwFenceAreaList = hwFenceAreaMapper.selectHwFenceAreaList(hwFenceArea); + hwElectronicFences.get(i).setHwFenceAreaList(hwFenceAreaList); + } + return hwElectronicFences; + } + + + + //查询监控单元下的信标设备 + public List getDeviceListInMonitorUnit(Long monitorUnitId){ + List deviceListInMonitorUnit = hwDeviceMapper.getDeviceListInMonitorUnit(monitorUnitId); + Map map = new HashMap(); + map.put("pageNum","1"); + map.put("pageSize","1"); + for (int i=0;i0){ + //正常 + ifAlarm="1"; + } + else { + ifAlarm="0"; + } + List> list = this.selectBeaconDevicesHistory(map); +// list.remove(list.size()-1); + System.out.println(list); + for(int j=0;j map = JSON.parseObject(s2,LinkedHashMap.class, Feature.OrderedField); + Map linkedMap = new LinkedHashMap(); + Long along = 1l; + for (String key : map.keySet()){ + linkedMap.put(along, key); + along++; + } + array.put("Header",linkedMap); + return array; + } + + /** + * 根据名字搜索信标设备 + * */ + @Override + public List selectMonitorUnitAndDeviceByName(Map map) { + String name = map.get("name").toString(); + HwMonitorUnit hwMonitorUnit= new HwMonitorUnit(); +// System.out.println(name); + hwMonitorUnit.setMonitorUnitName(name); + List monitorUnits = hwMonitorUnitMapper.selectHwMonitorUnitList(hwMonitorUnit); + HwDevice hwDevice = new HwDevice(); + hwDevice.setDeviceName(name); + List deviceList = hwDeviceMapper.selectHwDeviceList(hwDevice); + List stringList = new ArrayList(); + for (int i = 0; i < deviceList.size(); i++){ + HwMonitorUnit hwMonitorUnit1 = hwMonitorUnitMapper.selectMonitorUnit(deviceList.get(i).getDeviceId()); + monitorUnits.add(hwMonitorUnit1); + } + List collect = monitorUnits.stream().collect(Collectors.collectingAndThen( + Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(HwMonitorUnit::getMonitorUnitId)) + ),ArrayList::new)); + List deviceListReturn = new ArrayList(); + for (int i = 0; i < collect.size(); i++){ + deviceListReturn.addAll(this.getDeviceListInMonitorUnit(collect.get(i).getMonitorUnitId())); + + } + return deviceListReturn; + } + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java index ed28dc4..fab7896 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java @@ -131,7 +131,11 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { //查询设备数量(子设备和直连设备),不包括网关 Integer integer = hwMonitorUnitMapper.selectDeviceNums(sceneId) == null ? 0 : hwMonitorUnitMapper.selectDeviceNums(sceneId); + //查询信标设备数量 + Integer beaconNums = hwMonitorUnitMapper.selectBeaconDeviceNums(sceneId) ==null ? 0 + :hwMonitorUnitMapper.selectBeaconDeviceNums(sceneId); AllNumsVo vo = new AllNumsVo(); + vo.setBeaconDeviceSum(beaconNums); vo.setSubSum(monitor); vo.setSum(integer); return vo; @@ -175,10 +179,13 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { AllNumsVo numsVo = selectAllNums(sceneId); //获取在线设备数量,获取已发布状态子设备并且关联网关为在线的数量以及在线状态发布状态的直连设备数量之和 int onlineDeviceNum = hwDeviceMapper.getOnlineDeviceNum(sceneId); - + //查询信标设备数量 + Integer beaconNums = hwMonitorUnitMapper.selectBeaconDeviceNums(sceneId) ==null ? 0 + :hwMonitorUnitMapper.selectBeaconDeviceNums(sceneId); SubDeviceSumVo subDeviceSumVo = new SubDeviceSumVo(); subDeviceSumVo.setSubSum(numsVo.getSubSum());//监控单元数量 - subDeviceSumVo.setDeviceNum(numsVo.getSum());//设备数量 + subDeviceSumVo.setDeviceNum(beaconNums);//信标设备数量 +// subDeviceSumVo.setDeviceNum(numsVo.getSum());//设备数量 subDeviceSumVo.setOnlineDeviceNum(onlineDeviceNum);//在线设备数量 return subDeviceSumVo; diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelClassField.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelClassField.java new file mode 100644 index 0000000..276386b --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelClassField.java @@ -0,0 +1,77 @@ +package com.ruoyi.business.utils; + +import java.util.LinkedHashMap; + +/** + * @author sunnyzyq + * @date 2021/12/17 + */ +public class ExcelClassField { + + /** 字段名称 */ + private String fieldName; + + /** 表头名称 */ + private String name; + + /** 映射关系 */ + private LinkedHashMap kvMap; + + /** 示例值 */ + private Object example; + + /** 排序 */ + private int sort; + + /** 是否为注解字段:0-否,1-是 */ + private int hasAnnotation; + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public LinkedHashMap getKvMap() { + return kvMap; + } + + public void setKvMap(LinkedHashMap kvMap) { + this.kvMap = kvMap; + } + + public Object getExample() { + return example; + } + + public void setExample(Object example) { + this.example = example; + } + + public int getSort() { + return sort; + } + + public void setSort(int sort) { + this.sort = sort; + } + + public int getHasAnnotation() { + return hasAnnotation; + } + + public void setHasAnnotation(int hasAnnotation) { + this.hasAnnotation = hasAnnotation; + } + +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelExport.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelExport.java new file mode 100644 index 0000000..47d689d --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelExport.java @@ -0,0 +1,28 @@ +package com.ruoyi.business.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author sunnyzyq + * @date 2021/12/17 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExcelExport { + + /** 字段名称 */ + String value(); + + /** 导出排序先后: 数字越小越靠前(默认按Java类字段顺序导出) */ + int sort() default 0; + + /** 导出映射,格式如:0-未知;1-男;2-女 */ + String kv() default ""; + + /** 导出模板示例值(有值的话,直接取该值,不做映射) */ + String example() default ""; + +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelImport.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelImport.java new file mode 100644 index 0000000..96f270d --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelImport.java @@ -0,0 +1,31 @@ +package com.ruoyi.business.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author sunnyzyq + * @date 2021/12/17 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExcelImport { + + /** 字段名称 */ + String value(); + + /** 导出映射,格式如:0-未知;1-男;2-女 */ + String kv() default ""; + + /** 是否为必填字段(默认为非必填) */ + boolean required() default false; + + /** 最大长度(默认255) */ + int maxLength() default 255; + + /** 导入唯一性验证(多个字段则取联合验证) */ + boolean unique() default false; + +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelUtils.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelUtils.java new file mode 100644 index 0000000..abc880b --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/utils/ExcelUtils.java @@ -0,0 +1,1139 @@ +package com.ruoyi.business.utils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.poi.hssf.usermodel.HSSFDataValidation; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFClientAnchor; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.URL; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.Map.Entry; +import java.util.regex.Pattern; + +/** + * Excel导入导出工具类 + * 原文链接(不定时增加新功能): https://zyqok.blog.csdn.net/article/details/121994504 + * + * @author sunnyzyq + * @date 2021/12/17 + */ +@SuppressWarnings("unused") +public class ExcelUtils { + + private static final String XLSX = ".xlsx"; + private static final String XLS = ".xls"; + public static final String ROW_MERGE = "row_merge"; + public static final String COLUMN_MERGE = "column_merge"; + private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + private static final String ROW_NUM = "rowNum"; + private static final String ROW_DATA = "rowData"; + private static final String ROW_TIPS = "rowTips"; + private static final int CELL_OTHER = 0; + private static final int CELL_ROW_MERGE = 1; + private static final int CELL_COLUMN_MERGE = 2; + private static final int IMG_HEIGHT = 30; + private static final int IMG_WIDTH = 30; + private static final char LEAN_LINE = '/'; + private static final int BYTES_DEFAULT_LENGTH = 10240; + private static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance(); + + + public static List readFile(File file, Class clazz) throws Exception { + JSONArray array = readFile(file); + return getBeanList(array, clazz); + } + + public static List readMultipartFile(MultipartFile mFile, Class clazz) throws Exception { + JSONArray array = readMultipartFile(mFile); + return getBeanList(array, clazz); + } + + public static JSONArray readFile(File file) throws Exception { + return readExcel(null, file); + } + + public static JSONArray readMultipartFile(MultipartFile mFile) throws Exception { + return readExcel(mFile, null); + } + + public static Map readFileManySheet(File file) throws Exception { + return readExcelManySheet(null, file); + } + + public static Map readFileManySheet(MultipartFile file) throws Exception { + return readExcelManySheet(file, null); + } + + private static List getBeanList(JSONArray array, Class clazz) throws Exception { + List list = new ArrayList<>(); + Map uniqueMap = new HashMap<>(16); + for (int i = 0; i < array.size(); i++) { + list.add(getBean(clazz, array.getJSONObject(i), uniqueMap)); + } + return list; + } + + /** + * 获取每个对象的数据 + */ + private static T getBean(Class c, JSONObject obj, Map uniqueMap) throws Exception { + T t = c.newInstance(); + Field[] fields = c.getDeclaredFields(); + List errMsgList = new ArrayList<>(); + boolean hasRowTipsField = false; + StringBuilder uniqueBuilder = new StringBuilder(); + int rowNum = 0; + for (Field field : fields) { + // 行号 + if (field.getName().equals(ROW_NUM)) { + rowNum = obj.getInteger(ROW_NUM); + field.setAccessible(true); + field.set(t, rowNum); + continue; + } + // 是否需要设置异常信息 + if (field.getName().equals(ROW_TIPS)) { + hasRowTipsField = true; + continue; + } + // 原始数据 + if (field.getName().equals(ROW_DATA)) { + field.setAccessible(true); + field.set(t, obj.toString()); + continue; + } + // 设置对应属性值 + setFieldValue(t, field, obj, uniqueBuilder, errMsgList); + } + // 数据唯一性校验 + if (uniqueBuilder.length() > 0) { + if (uniqueMap.containsValue(uniqueBuilder.toString())) { + Set rowNumKeys = uniqueMap.keySet(); + for (Integer num : rowNumKeys) { + if (uniqueMap.get(num).equals(uniqueBuilder.toString())) { + errMsgList.add(String.format("数据唯一性校验失败,(%s)与第%s行重复)", uniqueBuilder, num)); + } + } + } else { + uniqueMap.put(rowNum, uniqueBuilder.toString()); + } + } + // 失败处理 + if (errMsgList.isEmpty() && !hasRowTipsField) { + return t; + } + StringBuilder sb = new StringBuilder(); + int size = errMsgList.size(); + for (int i = 0; i < size; i++) { + if (i == size - 1) { + sb.append(errMsgList.get(i)); + } else { + sb.append(errMsgList.get(i)).append(";"); + } + } + // 设置错误信息 + for (Field field : fields) { + if (field.getName().equals(ROW_TIPS)) { + field.setAccessible(true); + field.set(t, sb.toString()); + } + } + return t; + } + + private static void setFieldValue(T t, Field field, JSONObject obj, StringBuilder uniqueBuilder, List errMsgList) { + // 获取 ExcelImport 注解属性 + ExcelImport annotation = field.getAnnotation(ExcelImport.class); + if (annotation == null) { + return; + } + String cname = annotation.value(); + if (cname.trim().length() == 0) { + return; + } + // 获取具体值 + String val = null; + if (obj.containsKey(cname)) { + val = getString(obj.getString(cname)); + } + if (val == null) { + return; + } + field.setAccessible(true); + // 判断是否必填 + boolean require = annotation.required(); + if (require && val.isEmpty()) { + errMsgList.add(String.format("[%s]不能为空", cname)); + return; + } + // 数据唯一性获取 + boolean unique = annotation.unique(); + if (unique) { + if (uniqueBuilder.length() > 0) { + uniqueBuilder.append("--").append(val); + } else { + uniqueBuilder.append(val); + } + } + // 判断是否超过最大长度 + int maxLength = annotation.maxLength(); + if (maxLength > 0 && val.length() > maxLength) { + errMsgList.add(String.format("[%s]长度不能超过%s个字符(当前%s个字符)", cname, maxLength, val.length())); + } + // 判断当前属性是否有映射关系 + LinkedHashMap kvMap = getKvMap(annotation.kv()); + if (!kvMap.isEmpty()) { + boolean isMatch = false; + for (String key : kvMap.keySet()) { + if (kvMap.get(key).equals(val)) { + val = key; + isMatch = true; + break; + } + } + if (!isMatch) { + errMsgList.add(String.format("[%s]的值不正确(当前值为%s)", cname, val)); + return; + } + } + // 其余情况根据类型赋值 + String fieldClassName = field.getType().getSimpleName(); + try { + if ("String".equalsIgnoreCase(fieldClassName)) { + field.set(t, val); + } else if ("boolean".equalsIgnoreCase(fieldClassName)) { + field.set(t, Boolean.valueOf(val)); + } else if ("int".equalsIgnoreCase(fieldClassName) || "Integer".equals(fieldClassName)) { + try { + field.set(t, Integer.valueOf(val)); + } catch (NumberFormatException e) { + errMsgList.add(String.format("[%s]的值格式不正确(当前值为%s)", cname, val)); + } + } else if ("double".equalsIgnoreCase(fieldClassName)) { + field.set(t, Double.valueOf(val)); + } else if ("long".equalsIgnoreCase(fieldClassName)) { + field.set(t, Long.valueOf(val)); + } else if ("BigDecimal".equalsIgnoreCase(fieldClassName)) { + field.set(t, new BigDecimal(val)); + } else if ("Date".equalsIgnoreCase(fieldClassName)) { + try { + field.set(t, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(val)); + } catch (Exception e) { + field.set(t, new SimpleDateFormat("yyyy-MM-dd").parse(val)); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static Map readExcelManySheet(MultipartFile mFile, File file) throws IOException { + Workbook book = getWorkbook(mFile, file); + if (book == null) { + return Collections.emptyMap(); + } + Map map = new LinkedHashMap<>(); + for (int i = 0; i < book.getNumberOfSheets(); i++) { + Sheet sheet = book.getSheetAt(i); + JSONArray arr = readSheet(sheet); + map.put(sheet.getSheetName(), arr); + } + book.close(); + return map; + } + + private static JSONArray readExcel(MultipartFile mFile, File file) throws IOException { + Workbook book = getWorkbook(mFile, file); + if (book == null) { + return new JSONArray(); + } + JSONArray array = readSheet(book.getSheetAt(0)); + book.close(); + return array; + } + + private static Workbook getWorkbook(MultipartFile mFile, File file) throws IOException { + boolean fileNotExist = (file == null || !file.exists()); + if (mFile == null && fileNotExist) { + return null; + } + // 解析表格数据 + InputStream in; + String fileName; + if (mFile != null) { + // 上传文件解析 + in = mFile.getInputStream(); + fileName = getString(mFile.getOriginalFilename()).toLowerCase(); + } else { + // 本地文件解析 + in = new FileInputStream(file); + fileName = file.getName().toLowerCase(); + } + Workbook book; + if (fileName.endsWith(XLSX)) { + book = new XSSFWorkbook(in); + } else if (fileName.endsWith(XLS)) { + POIFSFileSystem poifsFileSystem = new POIFSFileSystem(in); + book = new HSSFWorkbook(poifsFileSystem); + } else { + return null; + } + in.close(); + return book; + } + + private static JSONArray readSheet(Sheet sheet) { + // 首行下标 + int rowStart = sheet.getFirstRowNum(); + // 尾行下标 + int rowEnd = sheet.getLastRowNum(); + // 获取表头行 + Row headRow = sheet.getRow(rowStart); + if (headRow == null) { + return new JSONArray(); + } + int cellStart = headRow.getFirstCellNum(); + int cellEnd = headRow.getLastCellNum(); + LinkedHashMap keyMap = new LinkedHashMap<>(); + for (int j = cellStart; j < cellEnd; j++) { + // 获取表头数据 + String val = getCellValue(headRow.getCell(j)); + if (val != null && val.trim().length() != 0) { + keyMap.put(j, val); + } + } + // 如果表头没有数据则不进行解析 + if (keyMap.isEmpty()) { + return (JSONArray) Collections.emptyList(); + } + // 获取每行JSON对象的值 + JSONArray array = new JSONArray(); + // 如果首行与尾行相同,表明只有一行,返回表头数据 + if (rowStart == rowEnd) { + JSONObject obj = new JSONObject(); + // 添加行号 +// obj.put(ROW_NUM, 1); + for (int i : keyMap.keySet()) { + obj.put(keyMap.get(i), ""); + } + array.add(obj); + return array; + } + for (int i = rowStart + 1; i <= rowEnd; i++) { + Row eachRow = sheet.getRow(i); + JSONObject obj = new JSONObject(true); + // 添加行号 +// obj.put(ROW_NUM, i + 1); + StringBuilder sb = new StringBuilder(); + for (int k = cellStart; k < cellEnd; k++) { + if (eachRow != null) { + String val = getCellValue(eachRow.getCell(k)); + // 所有数据添加到里面,用于判断该行是否为空 + sb.append(val); + obj.put(keyMap.get(k), val); + } + } + if (sb.length() > 0) { + array.add(obj); + } + } + return array; + } + + private static String getCellValue(Cell cell) { + // 空白或空 + if (cell == null || cell.getCellTypeEnum() == CellType.BLANK) { + return ""; + } + // String类型 + if (cell.getCellTypeEnum() == CellType.STRING) { + String val = cell.getStringCellValue(); + if (val == null || val.trim().length() == 0) { + return ""; + } + return val.trim(); + } + // 数字类型 + if (cell.getCellTypeEnum() == CellType.NUMERIC) { + String s = cell.getNumericCellValue() + ""; + // 去掉尾巴上的小数点0 + if (Pattern.matches(".*\\.0*", s)) { + return s.split("\\.")[0]; + } else { + return s; + } + } + // 布尔值类型 + if (cell.getCellTypeEnum() == CellType.BOOLEAN) { + return cell.getBooleanCellValue() + ""; + } + // 错误类型 + return cell.getCellFormula(); + } + + public static void exportTemplate(HttpServletResponse response, String fileName, Class clazz) { + exportTemplate(response, fileName, fileName, clazz, false); + } + + public static void exportTemplate(HttpServletResponse response, String fileName, String sheetName, + Class clazz) { + exportTemplate(response, fileName, sheetName, clazz, false); + } + + public static void exportTemplate(HttpServletResponse response, String fileName, Class clazz, + boolean isContainExample) { + exportTemplate(response, fileName, fileName, clazz, isContainExample); + } + + public static void exportTemplate(HttpServletResponse response, String fileName, String sheetName, + Class clazz, boolean isContainExample) { + // 获取表头字段 + List headFieldList = getExcelClassFieldList(clazz); + // 获取表头数据和示例数据 + List> sheetDataList = new ArrayList<>(); + List headList = new ArrayList<>(); + List exampleList = new ArrayList<>(); + Map> selectMap = new LinkedHashMap<>(); + for (int i = 0; i < headFieldList.size(); i++) { + ExcelClassField each = headFieldList.get(i); + headList.add(each.getName()); + exampleList.add(each.getExample()); + LinkedHashMap kvMap = each.getKvMap(); + if (kvMap != null && kvMap.size() > 0) { + selectMap.put(i, new ArrayList<>(kvMap.values())); + } + } + sheetDataList.add(headList); + if (isContainExample) { + sheetDataList.add(exampleList); + } + // 导出数据 + export(response, fileName, sheetName, sheetDataList, selectMap); + } + + private static List getExcelClassFieldList(Class clazz) { + // 解析所有字段 + Field[] fields = clazz.getDeclaredFields(); + boolean hasExportAnnotation = false; + Map> map = new LinkedHashMap<>(); + List sortList = new ArrayList<>(); + for (Field field : fields) { + ExcelClassField cf = getExcelClassField(field); + if (cf.getHasAnnotation() == 1) { + hasExportAnnotation = true; + } + int sort = cf.getSort(); + if (map.containsKey(sort)) { + map.get(sort).add(cf); + } else { + List list = new ArrayList<>(); + list.add(cf); + sortList.add(sort); + map.put(sort, list); + } + } + Collections.sort(sortList); + // 获取表头 + List headFieldList = new ArrayList<>(); + if (hasExportAnnotation) { + for (Integer sort : sortList) { + for (ExcelClassField cf : map.get(sort)) { + if (cf.getHasAnnotation() == 1) { + headFieldList.add(cf); + } + } + } + } else { + headFieldList.addAll(map.get(0)); + } + return headFieldList; + } + + private static ExcelClassField getExcelClassField(Field field) { + ExcelClassField cf = new ExcelClassField(); + String fieldName = field.getName(); + cf.setFieldName(fieldName); + ExcelExport annotation = field.getAnnotation(ExcelExport.class); + // 无 ExcelExport 注解情况 + if (annotation == null) { + cf.setHasAnnotation(0); + cf.setName(fieldName); + cf.setSort(0); + return cf; + } + // 有 ExcelExport 注解情况 + cf.setHasAnnotation(1); + cf.setName(annotation.value()); + String example = getString(annotation.example()); + if (!example.isEmpty()) { + if (isNumeric(example) && example.length() < 8) { + cf.setExample(Double.valueOf(example)); + } else { + cf.setExample(example); + } + } else { + cf.setExample(""); + } + cf.setSort(annotation.sort()); + // 解析映射 + String kv = getString(annotation.kv()); + cf.setKvMap(getKvMap(kv)); + return cf; + } + + private static LinkedHashMap getKvMap(String kv) { + LinkedHashMap kvMap = new LinkedHashMap<>(); + if (kv.isEmpty()) { + return kvMap; + } + String[] kvs = kv.split(";"); + if (kvs.length == 0) { + return kvMap; + } + for (String each : kvs) { + String[] eachKv = getString(each).split("-"); + if (eachKv.length != 2) { + continue; + } + String k = eachKv[0]; + String v = eachKv[1]; + if (k.isEmpty() || v.isEmpty()) { + continue; + } + kvMap.put(k, v); + } + return kvMap; + } + + /** + * 导出表格到本地 + * + * @param file 本地文件对象 + * @param sheetData 导出数据 + */ + public static void exportFile(File file, List> sheetData) { + if (file == null) { + System.out.println("文件创建失败"); + return; + } + if (sheetData == null) { + sheetData = new ArrayList<>(); + } + Map>> map = new HashMap<>(); + map.put(file.getName(), sheetData); + export(null, file, file.getName(), map, null); + } + + /** + * 导出表格到本地 + * + * @param 导出数据类似,和K类型保持一致 + * @param filePath 文件父路径(如:D:/doc/excel/) + * @param fileName 文件名称(不带尾缀,如:学生表) + * @param list 导出数据 + * @throws IOException IO异常 + */ + public static File exportFile(String filePath, String fileName, List list) throws IOException { + File file = getFile(filePath, fileName); + List> sheetData = getSheetData(list); + exportFile(file, sheetData); + return file; + } + + /** + * 获取文件 + * + * @param filePath filePath 文件父路径(如:D:/doc/excel/) + * @param fileName 文件名称(不带尾缀,如:用户表) + * @return 本地File文件对象 + */ + private static File getFile(String filePath, String fileName) throws IOException { + String dirPath = getString(filePath); + String fileFullPath; + if (dirPath.isEmpty()) { + fileFullPath = fileName; + } else { + // 判定文件夹是否存在,如果不存在,则级联创建 + File dirFile = new File(dirPath); + if (!dirFile.exists()) { + boolean mkdirs = dirFile.mkdirs(); + if (!mkdirs) { + return null; + } + } + // 获取文件夹全名 + if (dirPath.endsWith(String.valueOf(LEAN_LINE))) { + fileFullPath = dirPath + fileName + XLSX; + } else { + fileFullPath = dirPath + LEAN_LINE + fileName + XLSX; + } + } + System.out.println(fileFullPath); + File file = new File(fileFullPath); + if (!file.exists()) { + boolean result = file.createNewFile(); + if (!result) { + return null; + } + } + return file; + } + + private static List> getSheetData(List list) { + // 获取表头字段 + List excelClassFieldList = getExcelClassFieldList(list.get(0).getClass()); + List headFieldList = new ArrayList<>(); + List headList = new ArrayList<>(); + Map headFieldMap = new HashMap<>(); + for (ExcelClassField each : excelClassFieldList) { + String fieldName = each.getFieldName(); + headFieldList.add(fieldName); + headFieldMap.put(fieldName, each); + headList.add(each.getName()); + } + // 添加表头名称 + List> sheetDataList = new ArrayList<>(); + sheetDataList.add(headList); + // 获取表数据 + for (T t : list) { + Map fieldDataMap = getFieldDataMap(t); + Set fieldDataKeys = fieldDataMap.keySet(); + List rowList = new ArrayList<>(); + for (String headField : headFieldList) { + if (!fieldDataKeys.contains(headField)) { + continue; + } + Object data = fieldDataMap.get(headField); + if (data == null) { + rowList.add(""); + continue; + } + ExcelClassField cf = headFieldMap.get(headField); + // 判断是否有映射关系 + LinkedHashMap kvMap = cf.getKvMap(); + if (kvMap == null || kvMap.isEmpty()) { + rowList.add(data); + continue; + } + String val = kvMap.get(data.toString()); + if (isNumeric(val)) { + rowList.add(Double.valueOf(val)); + } else { + rowList.add(val); + } + } + sheetDataList.add(rowList); + } + return sheetDataList; + } + + private static Map getFieldDataMap(T t) { + Map map = new HashMap<>(); + Field[] fields = t.getClass().getDeclaredFields(); + try { + for (Field field : fields) { + String fieldName = field.getName(); + field.setAccessible(true); + Object object = field.get(t); + map.put(fieldName, object); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + return map; + } + + public static void exportEmpty(HttpServletResponse response, String fileName) { + List> sheetDataList = new ArrayList<>(); + List headList = new ArrayList<>(); + headList.add("导出无数据"); + sheetDataList.add(headList); + export(response, fileName, sheetDataList); + } + + public static void export(HttpServletResponse response, String fileName, List> sheetDataList) { + export(response, fileName, fileName, sheetDataList, null); + } + + public static void exportManySheet(HttpServletResponse response, String fileName, Map>> sheetMap) { + export(response, null, fileName, sheetMap, null); + } + + + public static void export(HttpServletResponse response, String fileName, String sheetName, + List> sheetDataList) { + export(response, fileName, sheetName, sheetDataList, null); + } + + public static void export(HttpServletResponse response, String fileName, String sheetName, + List> sheetDataList, Map> selectMap) { + + Map>> map = new HashMap<>(); + map.put(sheetName, sheetDataList); + export(response, null, fileName, map, selectMap); + } + + public static void export(HttpServletResponse response, String fileName, List list, Class template) { + // list 是否为空 + boolean lisIsEmpty = list == null || list.isEmpty(); + // 如果模板数据为空,且导入的数据为空,则导出空文件 + if (template == null && lisIsEmpty) { + exportEmpty(response, fileName); + return; + } + // 如果 list 数据,则导出模板数据 + if (lisIsEmpty) { + exportTemplate(response, fileName, template); + return; + } + // 导出数据 + List> sheetDataList = getSheetData(list); + export(response, fileName, sheetDataList); + } + + public static void export(HttpServletResponse response, String fileName, List> sheetDataList, Map> selectMap) { + export(response, fileName, fileName, sheetDataList, selectMap); + } + + private static void export(HttpServletResponse response, File file, String fileName, + Map>> sheetMap, Map> selectMap) { + // 整个 Excel 表格 book 对象 + SXSSFWorkbook book = new SXSSFWorkbook(); + // 每个 Sheet 页 + Set>>> entries = sheetMap.entrySet(); + for (Entry>> entry : entries) { + List> sheetDataList = entry.getValue(); + Sheet sheet = book.createSheet(entry.getKey()); + Drawing patriarch = sheet.createDrawingPatriarch(); + // 设置表头背景色(灰色) + CellStyle headStyle = book.createCellStyle(); + headStyle.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.index); + headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + headStyle.setAlignment(HorizontalAlignment.CENTER); + headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index); + // 设置表身背景色(默认色) + CellStyle rowStyle = book.createCellStyle(); + rowStyle.setAlignment(HorizontalAlignment.CENTER); + rowStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 设置表格列宽度(默认为15个字节) + sheet.setDefaultColumnWidth(15); + // 创建合并算法数组 + int rowLength = sheetDataList.size(); + int columnLength = sheetDataList.get(0).size(); + int[][] mergeArray = new int[rowLength][columnLength]; + for (int i = 0; i < sheetDataList.size(); i++) { + // 每个 Sheet 页中的行数据 + Row row = sheet.createRow(i); + List rowList = sheetDataList.get(i); + for (int j = 0; j < rowList.size(); j++) { + // 每个行数据中的单元格数据 + Object o = rowList.get(j); + int v = 0; + if (o instanceof URL) { + // 如果要导出图片的话, 链接需要传递 URL 对象 + setCellPicture(book, row, patriarch, i, j, (URL) o); + } else { + Cell cell = row.createCell(j); + if (i == 0) { + // 第一行为表头行,采用灰色底背景 + v = setCellValue(cell, o, headStyle); + } else { + // 其他行为数据行,默认白底色 + v = setCellValue(cell, o, rowStyle); + } + } + mergeArray[i][j] = v; + } + } + // 合并单元格 + mergeCells(sheet, mergeArray); + // 设置下拉列表 + setSelect(sheet, selectMap); + } + // 写数据 + if (response != null) { + // 前端导出 + try { + write(response, book, fileName); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + // 本地导出 + FileOutputStream fos; + try { + fos = new FileOutputStream(file); + ByteArrayOutputStream ops = new ByteArrayOutputStream(); + book.write(ops); + fos.write(ops.toByteArray()); + fos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * 合并当前Sheet页的单元格 + * + * @param sheet 当前 sheet 页 + * @param mergeArray 合并单元格算法 + */ + private static void mergeCells(Sheet sheet, int[][] mergeArray) { + // 横向合并 + for (int x = 0; x < mergeArray.length; x++) { + int[] arr = mergeArray[x]; + boolean merge = false; + int y1 = 0; + int y2 = 0; + for (int y = 0; y < arr.length; y++) { + int value = arr[y]; + if (value == CELL_COLUMN_MERGE) { + if (!merge) { + y1 = y; + } + y2 = y; + merge = true; + } else { + merge = false; + if (y1 > 0) { + sheet.addMergedRegion(new CellRangeAddress(x, x, (y1 - 1), y2)); + } + y1 = 0; + y2 = 0; + } + } + if (y1 > 0) { + sheet.addMergedRegion(new CellRangeAddress(x, x, (y1 - 1), y2)); + } + } + // 纵向合并 + int xLen = mergeArray.length; + int yLen = mergeArray[0].length; + for (int y = 0; y < yLen; y++) { + boolean merge = false; + int x1 = 0; + int x2 = 0; + for (int x = 0; x < xLen; x++) { + int value = mergeArray[x][y]; + if (value == CELL_ROW_MERGE) { + if (!merge) { + x1 = x; + } + x2 = x; + merge = true; + } else { + merge = false; + if (x1 > 0) { + sheet.addMergedRegion(new CellRangeAddress((x1 - 1), x2, y, y)); + } + x1 = 0; + x2 = 0; + } + } + if (x1 > 0) { + sheet.addMergedRegion(new CellRangeAddress((x1 - 1), x2, y, y)); + } + } + } + + private static void write(HttpServletResponse response, SXSSFWorkbook book, String fileName) throws IOException { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String name = new String(fileName.getBytes("GBK"), "ISO8859_1") + XLSX; + response.addHeader("Content-Disposition", "attachment;filename=" + name); + ServletOutputStream out = response.getOutputStream(); + book.write(out); + out.flush(); + out.close(); + } + + private static int setCellValue(Cell cell, Object o, CellStyle style) { + // 设置样式 + cell.setCellStyle(style); + // 数据为空时 + if (o == null) { + cell.setCellType(CellType.STRING); + cell.setCellValue(""); + return CELL_OTHER; + } + // 是否为字符串 + if (o instanceof String) { + String s = o.toString(); + // 当数字类型长度超过8位时,改为字符串类型显示(Excel数字超过一定长度会显示为科学计数法) + if (isNumeric(s) && s.length() < 8) { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(Double.parseDouble(s)); + return CELL_OTHER; + } else { + cell.setCellType(CellType.STRING); + cell.setCellValue(s); + } + if (s.equals(ROW_MERGE)) { + return CELL_ROW_MERGE; + } else if (s.equals(COLUMN_MERGE)) { + return CELL_COLUMN_MERGE; + } else { + return CELL_OTHER; + } + } + // 是否为字符串 + if (o instanceof Integer || o instanceof Long || o instanceof Double || o instanceof Float) { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(Double.parseDouble(o.toString())); + return CELL_OTHER; + } + // 是否为Boolean + if (o instanceof Boolean) { + cell.setCellType(CellType.BOOLEAN); + cell.setCellValue((Boolean) o); + return CELL_OTHER; + } + // 如果是BigDecimal,则默认3位小数 + if (o instanceof BigDecimal) { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(((BigDecimal) o).setScale(3, RoundingMode.HALF_UP).doubleValue()); + return CELL_OTHER; + } + // 如果是Date数据,则显示格式化数据 + if (o instanceof Date) { + cell.setCellType(CellType.STRING); + cell.setCellValue(formatDate((Date) o)); + return CELL_OTHER; + } + // 如果是其他,则默认字符串类型 + cell.setCellType(CellType.STRING); + cell.setCellValue(o.toString()); + return CELL_OTHER; + } + + private static void setCellPicture(SXSSFWorkbook wb, Row sr, Drawing patriarch, int x, int y, URL url) { + // 设置图片宽高 + sr.setHeight((short) (IMG_WIDTH * IMG_HEIGHT)); + // (jdk1.7版本try中定义流可自动关闭) + try (InputStream is = url.openStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + byte[] buff = new byte[BYTES_DEFAULT_LENGTH]; + int rc; + while ((rc = is.read(buff, 0, BYTES_DEFAULT_LENGTH)) > 0) { + outputStream.write(buff, 0, rc); + } + // 设置图片位置 + XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, y, x, y + 1, x + 1); + // 设置这个,图片会自动填满单元格的长宽 + anchor.setAnchorType(AnchorType.MOVE_AND_RESIZE); + patriarch.createPicture(anchor, wb.addPicture(outputStream.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static String formatDate(Date date) { + if (date == null) { + return ""; + } + SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); + return format.format(date); + } + + private static void setSelect(Sheet sheet, Map> selectMap) { + if (selectMap == null || selectMap.isEmpty()) { + return; + } + Set>> entrySet = selectMap.entrySet(); + for (Entry> entry : entrySet) { + int y = entry.getKey(); + List list = entry.getValue(); + if (list == null || list.isEmpty()) { + continue; + } + String[] arr = new String[list.size()]; + for (int i = 0; i < list.size(); i++) { + arr[i] = list.get(i); + } + DataValidationHelper helper = sheet.getDataValidationHelper(); + CellRangeAddressList addressList = new CellRangeAddressList(1, 65000, y, y); + DataValidationConstraint dvc = helper.createExplicitListConstraint(arr); + DataValidation dv = helper.createValidation(dvc, addressList); + if (dv instanceof HSSFDataValidation) { + dv.setSuppressDropDownArrow(false); + } else { + dv.setSuppressDropDownArrow(true); + dv.setShowErrorBox(true); + } + sheet.addValidationData(dv); + } + } + + private static boolean isNumeric(String str) { + if (Objects.nonNull(str) && "0.0".equals(str)) { + return true; + } + for (int i = str.length(); --i >= 0; ) { + if (!Character.isDigit(str.charAt(i))) { + return false; + } + } + return true; + } + + private static String getString(String s) { + if (s == null) { + return ""; + } + if (s.isEmpty()) { + return s; + } + return s.trim(); + } + + /** + * 获取 Excel 文件表头信息 + * + * @param fileUrl + * @return + * @throws Exception + */ + public static List getExcelHeaders(MultipartFile fileUrl) throws Exception { + File file = multipartFile2File(fileUrl); + InputStream is = new FileInputStream(file); + Workbook workbook = new XSSFWorkbook(is); + Sheet sheet = workbook.getSheetAt(0); + System.out.println(sheet.getLastRowNum()); + //获取 excel 第一行数据(表头) + Row row = sheet.getRow(0); + //存放表头信息 + List headers = new ArrayList(); + Set set = new HashSet<>(); + //算下有多少列 + int colCount = sheet.getRow(0).getLastCellNum(); + System.out.println(colCount); + for (int j = 0; j < colCount; j++) { + Cell cell = row.getCell(j); + String cellValue = cell.getStringCellValue().trim(); + headers.add(cellValue); + } + return headers; + } + + /** + * 获取 Excel 文件信息(除去表头) + * + * @param fileUrl + * @return + * @throws Exception + */ + public static List> getExcelData(String fileUrl) throws Exception { + File file = new File(fileUrl); + InputStream is = new FileInputStream(file); + Workbook workbook = new XSSFWorkbook(is); + Sheet sheet = workbook.getSheetAt(0); + //获取 Excel 中 sheet 的行数 + int rowNum = sheet.getLastRowNum(); + List> resList = new ArrayList<>(); + //负责标记检测到空行时,跳过 + boolean flag = false; + for (int i = 1; i <= rowNum; i++) { + //默认认为此行为空行 + flag = true; + Row row = sheet.getRow(i); + //过滤空行 + if (row == null) { + continue; + } + //创建列表,负责装纳一行数据 + List list = new ArrayList<>(); + //获取列数 + int colCount = sheet.getRow(i).getLastCellNum(); + for (int j = 0; j < colCount; j++) { + //获得制定空格 + Cell cell = row.getCell(j); + String cellValue = ""; + //如果存在空格内有内容,就将标志位设置为 false,表示这一行不是空行 + if (!(cell == null)) { + cellValue = getStringCellValue(cell); + if (!"".equals(cellValue)) { + flag = false; + } + } + list.add(cellValue); + } + if (!flag) { + resList.add(list); + } else { + continue; + } + } + return resList; + } + + + public static File multipartFile2File(MultipartFile multipartFile) { + String path = "../demo.xlsx"; + File file = new File(path); + try { + if (!file.exists()) { + file.createNewFile(); + } + // 底层也是通过io流写入文件file + FileCopyUtils.copy(multipartFile.getBytes(), file); + } catch (Exception e) { + throw new RuntimeException(e); + } + return file; + } + + /** + * 获取单元格数据内容为字符串类型的数据 + * + * @param cell Excel单元格 + * @return String 单元格数据内容 + */ + public static String getStringCellValue(Cell cell) { + String strCell = ""; + if (cell == null) { + return ""; + } + switch (cell.getCellType()) { + case Cell.CELL_TYPE_STRING: + strCell = cell.getStringCellValue().trim(); + break; + case Cell.CELL_TYPE_NUMERIC: + strCell = String.valueOf(cell.getNumericCellValue()).trim(); + break; + case Cell.CELL_TYPE_BOOLEAN: + strCell = String.valueOf(cell.getBooleanCellValue()).trim(); + break; + case Cell.CELL_TYPE_BLANK: + strCell = ""; + break; + default: + strCell = ""; + break; + } + if (strCell.equals("") || strCell == null) { + return ""; + } + return strCell; + } + + + +} diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml index 0d5c386..5b14138 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -41,6 +41,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + select hai.alarm_info_id, hai.alarm_info_type, hai.alarm_releated_id, hai.device_id, @@ -56,7 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + - + insert into hw_alarm_info @@ -161,7 +170,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from hw_alarm_info where alarm_info_id in + delete from hw_alarm_info where alarm_info_id in #{alarmInfoId} @@ -183,5 +192,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" exists (select 1 from hw_device hd where hai.device_id=hd.device_id and hd.device_status='1' and hd.monitor_unit_id=#{monitorUnitId}) + + + update hw_alarm_info + + handle_status = #{handleStatus}, + update_by = #{updateBy}, + update_time = #{updateTime}, + alarm_info_field = #{alarmInfoField}, + + where device_id = (select t.device_id from (select device_id from hw_alarm_info hai where alarm_info_id = #{alarmInfoId})t) and handle_status = 0 + - \ No newline at end of file + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml index c981a02..e50f1d8 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml @@ -39,6 +39,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + @@ -359,4 +374,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ${params.tenantDataScope} + + + + + + + + + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml index c1b064c..40bdada 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and fence_field = #{fenceField} - + - + insert into hw_electronic_fence @@ -152,7 +152,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from hw_fence_target where electronic_fence_id in + delete from hw_fence_target where electronic_fence_id in #{electronicFenceId} @@ -224,4 +224,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from hw_fence_area where electronic_fence_id = #{electronicFenceId} - \ No newline at end of file + + + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml index e3aef8b..ef81f04 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml @@ -60,6 +60,11 @@ + + + + + select monitor_unit_id, monitor_unit_name, scene_id, parent_id, monitor_unit_type_id, area_id, monitor_address, monitor_pic, preserve_time, remark, monitor_unit_status, create_by, create_time, update_by, update_time, monitor_unit_field from hw_monitor_unit hmu @@ -312,4 +317,39 @@ update hw_monitor_unit set monitor_unit_status = '9' where monitor_unit_id = #{monitorUnitId} - \ No newline at end of file + + + + + + + + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml index bb40a02..100241a 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwSceneMapper.xml @@ -52,6 +52,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + select scene_id, scene_name, tenant_id, scene_mode_id, scene_pic, default_flag, scene_status, auth_mode, mode_account, mode_key, mode_secret, preserve_time, test_preserve_time, remark, create_by, create_time, update_by, update_time, scene_environment, scene_field from hw_scene hs @@ -198,4 +203,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{sceneId} + diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml index 32d8e76..ffc6949 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwTenantMapper.xml @@ -25,10 +25,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select tenant_id, tenant_type, tenant_name, tenant_industry, contact_name, contact_phone, email, area_id, contact_address, remark, tenant_status, is_register, create_by, create_time, update_by, update_time,tenant_board_topic, tenant_board_pic,tenant_grade, tenant_field from hw_tenant ht + select tenant_id, tenant_type, tenant_name, tenant_industry, contact_name, contact_phone, email, area_id, contact_address, remark, tenant_status, is_register, create_by, create_time, update_by, update_time,tenant_board_topic, tenant_board_pic,tenant_grade, tenant_field ,tenant_map_code from hw_tenant ht