#update
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
package com.maibu.controller;
|
||||
|
||||
import com.maibu.annotation.Log;
|
||||
import com.maibu.core.controller.BaseController;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.page.TableDataInfo;
|
||||
import com.maibu.domain.Device;
|
||||
import com.maibu.domain.DeviceRunStatistics;
|
||||
import com.maibu.enums.BusinessType;
|
||||
import com.maibu.mapper.DeviceRunStatisticsMapper;
|
||||
import com.maibu.mybatis.LambdaQueryWrapperX;
|
||||
import com.maibu.service.IDeviceService;
|
||||
import com.maibu.utils.StringUtils;
|
||||
import com.maibu.utils.poi.ExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 设备Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "设备管理")
|
||||
@RestController
|
||||
@RequestMapping("/iot/device")
|
||||
public class DeviceController extends BaseController {
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private DeviceRunStatisticsMapper deviceRunStatisticsMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("设备分页列表")
|
||||
public TableDataInfo list(Device device) {
|
||||
startPage();
|
||||
// 限制当前用户机构
|
||||
if (null == device.getDeptId()) {
|
||||
device.setDeptId(getLoginUser().getDeptId());
|
||||
}
|
||||
return getDataTable(deviceService.selectDeviceList(device));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/userDevice")
|
||||
public AjaxResult userDevice(Device device) {
|
||||
if (null == device.getDeptId()) {
|
||||
device.setDeptId(100L);
|
||||
}
|
||||
return AjaxResult.success(deviceService.selectDeviceList(device));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:export')")
|
||||
@Log(title = "设备", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出设备")
|
||||
public void export(HttpServletResponse response, Device device) {
|
||||
List<Device> list = deviceService.selectDeviceList(device);
|
||||
ExcelUtil<Device> util = new ExcelUtil<Device>(Device.class);
|
||||
util.exportExcel(response, list, "设备数据");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据设备编号详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/getDeviceBySerialNumber/{serialNumber}")
|
||||
@ApiOperation("根据设备编号获取设备详情")
|
||||
public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber) {
|
||||
return AjaxResult.success(deviceService.selectDeviceBySerialNumber(serialNumber));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重置设备状态
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
|
||||
@Log(title = "重置设备状态", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/reset/{serialNumber}")
|
||||
@ApiOperation("重置设备状态")
|
||||
public AjaxResult resetDeviceStatus(@PathVariable String serialNumber) {
|
||||
Device device = new Device();
|
||||
device.setSerialNumber(serialNumber);
|
||||
return toAjax(deviceService.resetDeviceStatus(device.getSerialNumber()));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getDeviceRunStatistics")
|
||||
public AjaxResult getDeviceRunStatistics(@RequestParam("deviceId") String deviceId) {
|
||||
if (StringUtils.isEmpty(deviceId)) {
|
||||
return error("请选择设备");
|
||||
}
|
||||
LambdaQueryWrapperX<DeviceRunStatistics> queryWrapperX = new LambdaQueryWrapperX<>();
|
||||
queryWrapperX.eq(DeviceRunStatistics::getDeviceId, deviceId);
|
||||
queryWrapperX.orderByDesc(DeviceRunStatistics::getEndTime);
|
||||
queryWrapperX.last("LIMIT 10");
|
||||
return AjaxResult.success(deviceRunStatisticsMapper.selectList(queryWrapperX));
|
||||
}
|
||||
|
||||
@GetMapping("/getDeviceIntradayData")
|
||||
public AjaxResult getDeviceIntradayData(@RequestParam("deviceId") String deviceId) {
|
||||
List<DeviceRunStatistics> resultList = getIntradayData();
|
||||
DeviceRunStatistics statistics = null;
|
||||
if (!CollectionUtils.isEmpty(resultList)) {
|
||||
statistics = resultList.stream().filter(x -> deviceId.equals(x.getDeviceId())).findFirst().orElse(null);
|
||||
}
|
||||
return AjaxResult.success(statistics);
|
||||
}
|
||||
|
||||
public List<DeviceRunStatistics> getIntradayData() {
|
||||
LambdaQueryWrapperX<DeviceRunStatistics> wrapper = new LambdaQueryWrapperX<>();
|
||||
LocalDateTime start = LocalDate.now().atStartOfDay(); // 今天 00:00:00
|
||||
LocalDateTime end = LocalDate.now().plusDays(1).atStartOfDay(); // 明天 00:00:00
|
||||
|
||||
wrapper.ge(DeviceRunStatistics::getStartTime, start)
|
||||
.lt(DeviceRunStatistics::getStartTime, end);
|
||||
|
||||
List<DeviceRunStatistics> list = deviceRunStatisticsMapper.selectList(wrapper);
|
||||
List<DeviceRunStatistics> resultList = new ArrayList<>();
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
resultList = list.stream()
|
||||
.collect(Collectors.groupingBy(DeviceRunStatistics::getDeviceId))
|
||||
.values()
|
||||
.stream()
|
||||
.map(group -> {
|
||||
DeviceRunStatistics sum = new DeviceRunStatistics();
|
||||
sum.setDeviceId(group.get(0).getDeviceId());
|
||||
|
||||
sum.setWorkArea(
|
||||
group.stream().mapToDouble(DeviceRunStatistics::getWorkArea).sum()
|
||||
);
|
||||
|
||||
sum.setTime(
|
||||
group.stream().mapToLong(DeviceRunStatistics::getTime).sum()
|
||||
);
|
||||
|
||||
return sum;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<String> l = resultList.stream().map(DeviceRunStatistics::getDeviceId).collect(Collectors.toList());
|
||||
Device d = new Device();
|
||||
d.setParams(new HashMap<>());
|
||||
List<Device> query = deviceService.selectDeviceList(d);
|
||||
if (!CollectionUtils.isEmpty(query) && !CollectionUtils.isEmpty(l)) {
|
||||
for (Device device : query) {
|
||||
if (!l.contains(device.getDeviceName())) {
|
||||
DeviceRunStatistics statistics = new DeviceRunStatistics();
|
||||
statistics.setDeviceId(device.getDeviceName());
|
||||
statistics.setTime(0L);
|
||||
statistics.setWorkArea(0.0);
|
||||
resultList.add(statistics);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@GetMapping("/generateOperationReport")
|
||||
public void generateOperationReport(HttpServletResponse response) throws UnsupportedEncodingException {
|
||||
List<DeviceRunStatistics> resultList = getIntradayData();
|
||||
// ✅ 4. 响应头(下载)
|
||||
response.setContentType(
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
|
||||
String fileName = URLEncoder.encode("设备统计.xlsx", "UTF-8");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + fileName);
|
||||
try (Workbook workbook = new XSSFWorkbook();
|
||||
OutputStream os = response.getOutputStream()) {
|
||||
|
||||
Sheet sheet = workbook.createSheet("当日工作量统计");
|
||||
|
||||
// ✅ 1. 表头
|
||||
Row header = sheet.createRow(0);
|
||||
header.createCell(0).setCellValue("设备号");
|
||||
header.createCell(1).setCellValue("工作面积(m2)");
|
||||
header.createCell(2).setCellValue("工作时长(分钟)");
|
||||
|
||||
// ✅ 2. 数据
|
||||
for (int i = 0; i < resultList.size(); i++) {
|
||||
DeviceRunStatistics d = resultList.get(i);
|
||||
Row row = sheet.createRow(i + 1);
|
||||
|
||||
row.createCell(0).setCellValue(d.getDeviceId());
|
||||
row.createCell(1).setCellValue(d.getWorkArea());
|
||||
row.createCell(2).setCellValue(d.getTime());
|
||||
}
|
||||
|
||||
// ✅ 3. 自动列宽(可选)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sheet.autoSizeColumn(i);
|
||||
}
|
||||
|
||||
|
||||
// ✅ 5. 写出
|
||||
workbook.write(os);
|
||||
os.flush();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.maibu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 数据桥接对象 bridge
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-08-20
|
||||
*/
|
||||
|
||||
@ApiModel(value = "Bridge", description = "数据桥接 bridge")
|
||||
@Data
|
||||
@TableName("bridge" )
|
||||
public class Bridge implements Serializable{
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/** id唯一标识 */
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@ApiModelProperty("id唯一标识")
|
||||
private Long id;
|
||||
|
||||
/** 桥接配置信息 */
|
||||
@ApiModelProperty("桥接配置信息")
|
||||
private String configJson;
|
||||
|
||||
/** 连接器名称 */
|
||||
@ApiModelProperty("连接器名称")
|
||||
private String name;
|
||||
|
||||
/** 是否生效(0-不生效,1-生效) */
|
||||
@ApiModelProperty("是否生效")
|
||||
private String enable;
|
||||
|
||||
/** 状态(0-未连接,1-连接中) */
|
||||
@ApiModelProperty("状态")
|
||||
private String status;
|
||||
|
||||
/** 桥接类型(3=Http推送,4=Mqtt桥接,5=数据库存储) */
|
||||
@ApiModelProperty("桥接类型(3=Http推送,4=Mqtt桥接,5=数据库存储 2=Mqtt外部服务器连接)")
|
||||
private Integer type;
|
||||
|
||||
/** 桥接方向(1=输入,2=输出) */
|
||||
@ApiModelProperty("桥接方向(1=输入,2=输出)")
|
||||
private Integer direction;
|
||||
|
||||
/** 转发路由(mqtt topic,http url) */
|
||||
@ApiModelProperty("转发路由")
|
||||
private String route;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
@ApiModelProperty("删除标志")
|
||||
private String delFlag;
|
||||
|
||||
/** 创建者 */
|
||||
@ApiModelProperty("创建者")
|
||||
private String createBy;
|
||||
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/** 更新者 */
|
||||
@ApiModelProperty("更新者")
|
||||
private String updateBy;
|
||||
|
||||
/** 更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@ApiModelProperty("更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/** 备注 */
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Setter
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty("请求参数")
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private Map<String, Object> params;
|
||||
|
||||
public Map<String, Object> getParams(){
|
||||
if (params == null){
|
||||
params = new HashMap<>();
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.maibu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.maibu.annotation.Excel;
|
||||
import com.maibu.core.domain.BaseDO;
|
||||
import com.maibu.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -27,14 +30,18 @@ import java.util.List;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@TableName("iot_device")
|
||||
public class Device extends BaseEntity {
|
||||
public class Device extends BaseDO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
* 设备编号
|
||||
*/
|
||||
@ApiModelProperty("设备ID")
|
||||
private Long deviceId;
|
||||
@ApiModelProperty("设备编号")
|
||||
@Excel(name = "设备编号")
|
||||
private String serialNumber;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
@@ -79,13 +86,6 @@ public class Device extends BaseEntity {
|
||||
@Excel(name = "租户名称")
|
||||
private String tenantName;
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
@ApiModelProperty("设备编号")
|
||||
@Excel(name = "设备编号")
|
||||
private String serialNumber;
|
||||
|
||||
/**
|
||||
* 固件版本
|
||||
*/
|
||||
@@ -246,7 +246,6 @@ public class Device extends BaseEntity {
|
||||
private Boolean showChild;
|
||||
|
||||
private List<Device> subDeviceList;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除)
|
||||
*/
|
||||
@@ -262,23 +261,6 @@ public class Device extends BaseEntity {
|
||||
*/
|
||||
private String protocolCode;
|
||||
|
||||
/**
|
||||
* 关联组态,来源产品
|
||||
*/
|
||||
private String guid;
|
||||
|
||||
// private List<SipRelation> sipRelationList;
|
||||
|
||||
/**
|
||||
* 是否可以配置轮询
|
||||
*/
|
||||
private Boolean canConfigPoll = false;
|
||||
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
@TableField(exist = false)
|
||||
private DeviceRunningStatusHistory lastRunningStatus;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.maibu.mapper;
|
||||
|
||||
import com.maibu.core.device.DeviceAndProtocol;
|
||||
import com.maibu.domain.Device;
|
||||
import com.maibu.model.*;
|
||||
import com.maibu.mybatis.mapper.BaseMapperX;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -15,7 +14,7 @@ import java.util.List;
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Repository
|
||||
public interface DeviceMapper {
|
||||
public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
<artifactId>maibu-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.maibu</groupId>
|
||||
<artifactId>maibu-framework</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.maibu.mapper;
|
||||
|
||||
import com.maibu.core.domain.entity.SysOrg;
|
||||
import com.maibu.mybatis.mapper.BaseMapperX;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 设备历史状态
|
||||
*/
|
||||
@Repository
|
||||
public interface SysOrgMapper extends BaseMapperX<SysOrg> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.maibu.mapper;
|
||||
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.mybatis.mapper.BaseMapperX;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 设备历史状态
|
||||
*/
|
||||
@Repository
|
||||
public interface SysSiteMapper extends BaseMapperX<SysSite> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.maibu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.maibu.core.domain.entity.SysOrg;
|
||||
import com.maibu.mapper.SysOrgMapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysOrgService {
|
||||
|
||||
@Autowired
|
||||
private SysOrgMapper sysOrgMapper;
|
||||
|
||||
|
||||
public List<SysOrg> list(SysOrg org) {
|
||||
LambdaQueryWrapper<SysOrg> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (org != null && !StringUtils.isEmpty(org.getOrgCode())) {
|
||||
queryWrapper.eq(SysOrg::getOrgCode, org.getOrgCode());
|
||||
}
|
||||
if (org != null && !StringUtils.isEmpty(org.getOrgName())) {
|
||||
queryWrapper.like(SysOrg::getOrgName, org.getOrgName());
|
||||
}
|
||||
return sysOrgMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
public boolean save(SysOrg org) {
|
||||
return sysOrgMapper.saveOrUpdate(org);
|
||||
}
|
||||
|
||||
public int delete(Long id) {
|
||||
return sysOrgMapper.updateById(id);
|
||||
}
|
||||
|
||||
public SysOrg selectById(Long id) {
|
||||
return sysOrgMapper.selectById(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.maibu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.maibu.core.domain.entity.SysOrg;
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.mapper.SysOrgMapper;
|
||||
import com.maibu.mapper.SysSiteMapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class SysSiteService {
|
||||
|
||||
@Autowired
|
||||
private SysSiteMapper sysSiteMapper;
|
||||
|
||||
|
||||
public List<SysSite> list(SysSite site) {
|
||||
LambdaQueryWrapper<SysSite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (site != null && !StringUtils.isEmpty(site.getSiteName())) {
|
||||
queryWrapper.like(SysSite::getSiteName, site.getSiteName());
|
||||
}
|
||||
return sysSiteMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
public boolean save(SysSite org) {
|
||||
return sysSiteMapper.saveOrUpdate(org);
|
||||
}
|
||||
|
||||
public int delete(Long id) {
|
||||
return sysSiteMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public SysSite selectById(Long id) {
|
||||
return sysSiteMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<SysSite> selectByOrgId(Long id) {
|
||||
LambdaQueryWrapper<SysSite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysSite::getOrgId, id);
|
||||
return sysSiteMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user