Compare commits
3 Commits
0787e4b205
...
d97928b38a
Author | SHA1 | Date | |
---|---|---|---|
d97928b38a | |||
1d37bfb719 | |||
98ef841f18 |
@ -1,17 +1,16 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.equipment.domain.vo.AlarmInformationVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DataOverviewVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.EquipmentClassificationVo;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 首页数据
|
||||
@ -39,29 +38,36 @@ public class HomePageController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 获取设备使用数据
|
||||
@GetMapping("/{deviceId}")
|
||||
public Map<String, Object> getUsageData(
|
||||
@PathVariable String deviceId,
|
||||
@RequestParam String range) {
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
if ("halfYear".equals(range)) {
|
||||
response.put("months", Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月"));
|
||||
response.put("data", Arrays.asList(45, 52, 38, 60, 56, 48));
|
||||
} else if ("oneYear".equals(range)) {
|
||||
response.put("months", Arrays.asList("7月", "8月", "9月", "10月", "11月", "12月",
|
||||
"1月", "2月", "3月", "4月", "5月", "6月"));
|
||||
response.put("data", Arrays.asList(42, 38, 45, 48, 52, 55, 45, 52, 38, 60, 56, 48));
|
||||
}
|
||||
|
||||
response.put("deviceId", deviceId);
|
||||
response.put("range", range);
|
||||
response.put("lastUpdate", new Date());
|
||||
|
||||
return response;
|
||||
/**
|
||||
* 获取 设备分类
|
||||
* DataOverview
|
||||
*/
|
||||
@GetMapping("/getEquipmentClassification")
|
||||
public R<EquipmentClassificationVo> getEquipmentClassification() {
|
||||
return R.ok(deviceService.getEquipmentClassification());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 报警信息
|
||||
* DataOverview
|
||||
*/
|
||||
@GetMapping("/getAlarmInformation")
|
||||
public R<AlarmInformationVo> getAlarmInformation() {
|
||||
return R.ok(deviceService.getAlarmInformation());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param range 时间范围 1:半年 2:一年
|
||||
* @return 每月使用数据列表
|
||||
*/
|
||||
@GetMapping("/getEquipmentUsageData/{deviceId}/{range}")
|
||||
public R<List<Map<String, Object>>> getEquipmentUsageData(@PathVariable Long deviceId, @PathVariable Integer range) {
|
||||
return R.ok(deviceService.getEquipmentUsageData(deviceId, range));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ public class EncryptUtilsTest {
|
||||
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
|
||||
loginBody.setGrantType("password");
|
||||
loginBody.setTenantId("894078");
|
||||
loginBody.setCode("9");
|
||||
loginBody.setUuid("d5be31eac1244cee851a9903f358bc6a");
|
||||
loginBody.setCode("0");
|
||||
loginBody.setUuid("1d6615668c7f410da77c4e002c601073");
|
||||
// loginBody.setUsername("admin");
|
||||
// loginBody.setPassword("admin123");
|
||||
loginBody.setUsername("dyf");
|
||||
|
@ -126,26 +126,26 @@ public class DeviceController extends BaseController {
|
||||
|
||||
|
||||
// @Log("分配客户")
|
||||
@Operation(summary = "分配客户")
|
||||
@PutMapping(value = "/assignCustomer")
|
||||
public R<Void> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
deviceService.assignCustomer(customerVo);
|
||||
return R.ok();
|
||||
}
|
||||
// @Operation(summary = "分配客户")
|
||||
// @PutMapping(value = "/assignCustomer")
|
||||
// public R<Void> assignCustomer(@Validated @RequestBody CustomerVo customerVo) {
|
||||
// deviceService.assignCustomer(customerVo);
|
||||
// return R.ok();
|
||||
// }
|
||||
|
||||
|
||||
// @Log("撤回设备")
|
||||
@Operation(summary = "撤回分配设备")
|
||||
@PostMapping(value = "/withdraw")
|
||||
public R<Void> withdrawDevice(@RequestBody List<Long> ids) {
|
||||
try {
|
||||
deviceService.withdrawDevice(ids);
|
||||
} catch (Exception e) {
|
||||
log.error("updateDevice error: " + e.getMessage());
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
// @Operation(summary = "撤回分配设备")
|
||||
// @PostMapping(value = "/withdraw")
|
||||
// public R<Void> withdrawDevice(@RequestBody List<Long> ids) {
|
||||
// try {
|
||||
// deviceService.withdrawDevice(ids);
|
||||
// } catch (Exception e) {
|
||||
// log.error("updateDevice error: " + e.getMessage());
|
||||
// return R.fail(e.getMessage());
|
||||
// }
|
||||
// return R.ok();
|
||||
// }
|
||||
|
||||
//
|
||||
// /**
|
||||
|
@ -162,7 +162,7 @@ public class Device extends TenantEntity {
|
||||
private Date productionDate;
|
||||
|
||||
/**
|
||||
* 在线状态(0离线,1在线)
|
||||
* 在线状态(0离线,1在线,2异常)
|
||||
*/
|
||||
private Integer onlineStatus;
|
||||
}
|
||||
|
@ -36,8 +36,10 @@ public class DeviceAlarm extends TenantEntity {
|
||||
|
||||
/**
|
||||
* 报警事项
|
||||
* 0-强制报警,1-撞击闯入,2-手动报警,3-电子围栏告警,4-强制告警
|
||||
* device_action
|
||||
*/
|
||||
private String deviceAction;
|
||||
private Integer deviceAction;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
@ -92,6 +94,7 @@ public class DeviceAlarm extends TenantEntity {
|
||||
|
||||
/**
|
||||
* 0已处理,1未处理
|
||||
* treatment_state
|
||||
*/
|
||||
private Long treatmentState;
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class DeviceType extends TenantEntity {
|
||||
@Schema(title = "联网方式", example = "0:无;1:4G;2:WIFI")
|
||||
private String networkWay;
|
||||
|
||||
@Schema(title = "通讯方式", example = "0:4G;1:蓝牙")
|
||||
@Schema(title = "通讯方式", example = "0:4G;1:蓝牙,2 4G&蓝牙")
|
||||
private String communicationMode;
|
||||
|
||||
/**
|
||||
|
@ -83,6 +83,7 @@ public class DeviceQueryCriteria extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙
|
||||
* communication_mode
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
|
@ -6,13 +6,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.InstructionRecordDto;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.LocationHistoryVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -72,7 +71,42 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
||||
|
||||
AppDeviceVo getDeviceInfo(@Param("deviceMac") String deviceMac);
|
||||
|
||||
Page<WebDeviceVo> queryWebDeviceList(Page<Object> build,@Param("criteria") DeviceQueryCriteria criteria);
|
||||
Page<WebDeviceVo> queryWebDeviceList(Page<Object> build, @Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
Page<LocationHistoryVo> getLocationHistory(Page<Object> build, @Param("bo") InstructionRecordDto criteria);
|
||||
|
||||
/**
|
||||
* 获取数据总览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
DataOverviewVo getDataOverview();
|
||||
|
||||
/**
|
||||
* 获取设备分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EquipmentClassificationVo getEquipmentClassification();
|
||||
|
||||
/**
|
||||
* 获取告警信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AlarmInformationVo getAlarmInformation();
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param range 时间范围 1:半年 2:一年
|
||||
* @return 每月使用数据列表
|
||||
*/
|
||||
List<Map<String, Object>> getEquipmentUsageData(Long deviceId, Integer range);
|
||||
|
||||
// 在DeviceMapper.java中添加方法
|
||||
int getUsageDataForMonth(@Param("deviceId") Long deviceId,
|
||||
@Param("year") int year,
|
||||
@Param("month") int month);
|
||||
}
|
||||
|
@ -9,12 +9,11 @@ import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DataOverviewVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -122,4 +121,27 @@ public interface DeviceService extends IService<Device> {
|
||||
* @return
|
||||
*/
|
||||
DataOverviewVo getDataOverview();
|
||||
|
||||
/**
|
||||
* 获取设备分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
EquipmentClassificationVo getEquipmentClassification();
|
||||
|
||||
/**
|
||||
* 获取告警信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AlarmInformationVo getAlarmInformation();
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId
|
||||
* @param range
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getEquipmentUsageData(Long deviceId, Integer range);
|
||||
}
|
||||
|
@ -28,9 +28,7 @@ import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DataOverviewVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.*;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
||||
@ -53,11 +51,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -596,8 +592,6 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备MAC号
|
||||
*
|
||||
@ -623,7 +617,46 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
*/
|
||||
@Override
|
||||
public DataOverviewVo getDataOverview() {
|
||||
return null;
|
||||
DataOverviewVo dataOverviewVo = deviceMapper.getDataOverview();
|
||||
return dataOverviewVo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public EquipmentClassificationVo getEquipmentClassification() {
|
||||
EquipmentClassificationVo equipmentClassification = deviceMapper.getEquipmentClassification();
|
||||
return equipmentClassification;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取告警信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AlarmInformationVo getAlarmInformation() {
|
||||
AlarmInformationVo alarmInformation = deviceMapper.getAlarmInformation();
|
||||
return alarmInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备使用数据
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param range 时间范围 1:半年 2:一年
|
||||
* @return 每月使用数据列表
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> getEquipmentUsageData(Long deviceId, Integer range) {
|
||||
List<Map<String, Object>> equipmentUsageData = deviceMapper.getEquipmentUsageData(deviceId, range);
|
||||
return equipmentUsageData;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,6 +74,9 @@
|
||||
<if test="criteria.groupId != null">
|
||||
and d.group_id = #{criteria.groupId}
|
||||
</if>
|
||||
<if test="criteria.communicationMode != null">
|
||||
and t.communication_mode = #{criteria.communicationMode}
|
||||
</if>
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
@ -280,7 +283,7 @@
|
||||
</if>
|
||||
</select>
|
||||
<select id="getLocationHistory" resultType="com.fuyuanshen.equipment.domain.vo.LocationHistoryVo">
|
||||
select a.id,a.device_name,a.device_type,b.type_name deviceTypeName,a.device_imei,a.device_mac from device a
|
||||
select a.id,a.device_name,a.device_type,b.type_name deviceTypeName,a.device_imei,a.device_mac from device a
|
||||
inner join device_type b on a.device_type = b.id
|
||||
|
||||
<if test="bo.deviceType != null">
|
||||
@ -311,4 +314,93 @@
|
||||
a.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 获取数据总览 -->
|
||||
<select id="getDataOverview" resultType="com.fuyuanshen.equipment.domain.vo.DataOverviewVo">
|
||||
SELECT (SELECT COUNT(1) FROM device) AS devicesNumber,
|
||||
(SELECT COUNT(1) FROM device WHERE device_status = 1) AS equipmentOnline,
|
||||
(SELECT COUNT(1) FROM device WHERE DATE (create_time) = CURDATE()) AS bindingNew, (
|
||||
SELECT COUNT (1)
|
||||
FROM device
|
||||
WHERE device_status = 2) AS equipmentAbnormal
|
||||
</select>
|
||||
|
||||
<!-- 获取设备分类 -->
|
||||
<select id="getEquipmentClassification"
|
||||
resultType="com.fuyuanshen.equipment.domain.vo.EquipmentClassificationVo">
|
||||
SELECT (SELECT COUNT(1)
|
||||
FROM device d
|
||||
INNER JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.communication_mode = 0) AS equipment4G,
|
||||
(SELECT COUNT(1)
|
||||
FROM device d
|
||||
INNER JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.communication_mode = 1) AS deviceBluetooth,
|
||||
(SELECT COUNT(1)
|
||||
FROM device d
|
||||
INNER JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.communication_mode = 2) AS devices4GAndBluetooth
|
||||
</select>
|
||||
|
||||
<!-- 获取告警信息 -->
|
||||
<select id="getAlarmInformation" resultType="com.fuyuanshen.equipment.domain.vo.AlarmInformationVo">
|
||||
SELECT (SELECT COUNT(1) FROM device_alarm WHERE treatment_state = 0 AND DATE (create_time) = CURDATE()) AS alarmsTotal, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE treatment_state = 0
|
||||
AND DATE (create_time) = CURDATE()) AS processingAlarm
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 0
|
||||
AND DATE (create_time) = CURDATE()) AS alarmForced
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 1
|
||||
AND DATE (create_time) = CURDATE()) AS intrusionImpact
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 2
|
||||
AND DATE (create_time) = CURDATE()) AS alarmManual
|
||||
, (
|
||||
SELECT COUNT (1)
|
||||
FROM device_alarm
|
||||
WHERE device_action = 3 AND DATE (create_time) = CURDATE()) AS fenceElectronic
|
||||
|
||||
</select>
|
||||
|
||||
<!-- 获取设备使用数据 -->
|
||||
<select id="getEquipmentUsageData" resultType="map">
|
||||
SELECT COUNT(CASE WHEN MONTH (dl.create_time) = 1 THEN 1 END) AS m1,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 2 THEN 1 END) AS m2,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 3 THEN 1 END) AS m3,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 4 THEN 1 END) AS m4,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 5 THEN 1 END) AS m5,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 6 THEN 1 END) AS m6,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 7 THEN 1 END) AS m7,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 8 THEN 1 END) AS m8,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 9 THEN 1 END) AS m9,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 10 THEN 1 END) AS m10,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 11 THEN 1 END) AS m11,
|
||||
COUNT(CASE WHEN MONTH (dl.create_time) = 12 THEN 1 END) AS m12
|
||||
FROM device_log dl
|
||||
LEFT JOIN device d ON dl.device_id = d.id
|
||||
LEFT JOIN device_type dt ON d.device_type = dt.id
|
||||
WHERE dt.id = #{deviceId}
|
||||
AND (
|
||||
(#{range} = 1 AND dl.create_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)) OR
|
||||
(#{range} = 2 AND dl.create_time >= DATE_SUB(NOW(), INTERVAL 12 MONTH))
|
||||
)
|
||||
</select>
|
||||
|
||||
<select id="getUsageDataForMonth" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM device_log dl
|
||||
WHERE dl.device_id = #{deviceId}
|
||||
AND YEAR (
|
||||
dl.create_time) = #{year}
|
||||
AND MONTH (dl.create_time) = #{month}
|
||||
</select>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user