This commit is contained in:
lu7213 committed 2026-03-05 22:42:55 +08:00
1 parent 7cd697187c
commit 6c73388fdd
25 files changed
+454 -33

No files matched your search

@@ -0,0 +1,38 @@
package com.luqj.ec.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.luqj.ec.domain.dto.EcDeviceHeartbeatDto;
import com.luqj.ec.domain.dto.EcDeviceReportDto;
import com.luqj.ec.service.IEcDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/ec/device-api")
public class EcDeviceApiController extends BaseController {
@Autowired
private IEcDeviceService ecDeviceService;
@PostMapping("/report")
public AjaxResult report(@RequestBody EcDeviceReportDto reportDto) {
if (reportDto.getDeviceCode() == null || reportDto.getDeviceCode().isEmpty()) {
return AjaxResult.error("deviceCode不能为空");
}
ecDeviceService.reportDevice(reportDto);
return AjaxResult.success("设备上报成功");
}
@PostMapping("/heartbeat")
public AjaxResult heartbeat(@RequestBody EcDeviceHeartbeatDto heartbeatDto) {
if (heartbeatDto.getDeviceCode() == null || heartbeatDto.getDeviceCode().isEmpty()) {
return AjaxResult.error("deviceCode不能为空");
}
ecDeviceService.heartbeat(heartbeatDto);
return AjaxResult.success("心跳成功");
}
}
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -18,6 +21,7 @@ public class EcCommandResult extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 命令ID */
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -21,6 +24,7 @@ public class EcCommandResultPlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 命令ID */
@Excel(name = "命令ID")
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -18,6 +21,7 @@ public class EcControlTask extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 任务名称 */
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -21,6 +24,7 @@ public class EcControlTaskPlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 任务名称 */
@Excel(name = "任务名称")
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -18,6 +21,7 @@ public class EcDevice extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 设备唯一标识 */
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -18,6 +21,7 @@ public class EcDeviceCommand extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 设备ID */
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -21,6 +24,7 @@ public class EcDeviceCommandPlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 设备ID */
@Excel(name = "设备ID")
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -21,6 +24,7 @@ public class EcDevicePlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 设备唯一标识 */
@Excel(name = "设备唯一标识")
@@ -2,6 +2,9 @@ package com.luqj.ec.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -19,6 +22,7 @@ public class EcDeviceStatus extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 设备ID */
@@ -2,6 +2,9 @@ package com.luqj.ec.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -22,6 +25,7 @@ public class EcDeviceStatusPlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 设备ID */
@Excel(name = "设备ID")
@@ -1,5 +1,7 @@
package com.luqj.ec.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
@@ -16,6 +18,7 @@ public class EcTaskCommand extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 任务ID */
@@ -1,5 +1,7 @@
package com.luqj.ec.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
@@ -19,6 +21,7 @@ public class EcTaskCommandPlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 任务ID */
@Excel(name = "任务ID")
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -18,6 +21,7 @@ public class EcTaskDevice extends BaseEntity
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 任务ID */
@@ -1,6 +1,9 @@
package com.luqj.ec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -21,6 +24,7 @@ public class EcTaskDevicePlus implements Serializable
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(type = IdType.AUTO)
private Long id;
/** 任务ID */
@Excel(name = "任务ID")
@@ -0,0 +1,26 @@
package com.luqj.ec.domain.dto;
import java.io.Serializable;
public class EcDeviceHeartbeatDto implements Serializable {
private static final long serialVersionUID = 1L;
private String deviceCode;
private String ipAddress;
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
}
@@ -0,0 +1,125 @@
package com.luqj.ec.domain.dto;
import java.io.Serializable;
public class EcDeviceReportDto implements Serializable {
private static final long serialVersionUID = 1L;
private String deviceCode;
private String brand;
private String model;
private String osType;
private String osVersion;
private String appVersion;
private String ipAddress;
private Integer widthNum;
private Integer heightNum;
private Integer controlType;
private Long appId;
private Long userId;
private String secretKey;
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getOsType() {
return osType;
}
public void setOsType(String osType) {
this.osType = osType;
}
public String getOsVersion() {
return osVersion;
}
public void setOsVersion(String osVersion) {
this.osVersion = osVersion;
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public Integer getWidthNum() {
return widthNum;
}
public void setWidthNum(Integer widthNum) {
this.widthNum = widthNum;
}
public Integer getHeightNum() {
return heightNum;
}
public void setHeightNum(Integer heightNum) {
this.heightNum = heightNum;
}
public Integer getControlType() {
return controlType;
}
public void setControlType(Integer controlType) {
this.controlType = controlType;
}
public Long getAppId() {
return appId;
}
public void setAppId(Long appId) {
this.appId = appId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
}
@@ -1,21 +1,25 @@
package com.luqj.ec.service;
import java.util.Map;
import java.util.List;
import com.luqj.ec.domain.EcDevice;
import com.luqj.ec.domain.EcDevicePlus;
import com.luqj.ec.domain.dto.EcDeviceHeartbeatDto;
import com.luqj.ec.domain.dto.EcDeviceReportDto;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.ruoyi.common.select.SelectItem;
/**
* 设备(手机设备)Service接口
*
* @author luqj
* @date 2026-02-27
*/
public interface IEcDeviceService extends IService<EcDevicePlus>
{
public interface IEcDeviceService extends IService<EcDevicePlus> {
List<SelectItem> select(String keyword);
/**
* 查询设备(手机设备)
*
@@ -86,4 +90,10 @@ public interface IEcDeviceService extends IService<EcDevicePlus>
Long count(String where);
<T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass);
EcDevicePlus selectEcDeviceByDeviceCode(String deviceCode);
void reportDevice(EcDeviceReportDto reportDto);
void heartbeat(EcDeviceHeartbeatDto heartbeatDto);
}
@@ -1,4 +1,5 @@
package com.luqj.ec.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -6,6 +7,7 @@ import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import com.ruoyi.common.utils.StringUtils;
import com.alibaba.fastjson.JSONArray;
@@ -16,10 +18,13 @@ import org.springframework.stereotype.Service;
import com.luqj.ec.mapper.EcDeviceMapper;
import com.luqj.ec.domain.EcDevice;
import com.luqj.ec.domain.EcDevicePlus;
import com.luqj.ec.domain.dto.EcDeviceHeartbeatDto;
import com.luqj.ec.domain.dto.EcDeviceReportDto;
import com.luqj.ec.service.IEcDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import com.ruoyi.common.select.SelectItem;
/**
* 设备(手机设备)Service业务层处理
*
@@ -27,8 +32,7 @@ import com.ruoyi.common.select.SelectItem;
* @date 2026-02-27
*/
@Service
public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlus> implements IEcDeviceService
{
public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlus> implements IEcDeviceService {
@Autowired
private EcDeviceMapper ecDeviceMapper;
@Autowired
@@ -40,14 +44,15 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
.select(columns).in(EcDevicePlus::getId, ids);
return this.list(lambdaQueryWrapper);
}
@Override
public List<SelectItem> select(String keyword) {
LambdaQueryWrapper<EcDevicePlus> lambdaQueryWrapper = new LambdaQueryWrapper<EcDevicePlus>()
.select(EcDevicePlus::getId, EcDevicePlus::getDeviceCode)
.like(EcDevicePlus::getDeviceCode, keyword);
List<EcDevicePlus> list = this.list(lambdaQueryWrapper);
List<SelectItem> result =new ArrayList<>();
for (EcDevicePlus item : list){
List<SelectItem> result = new ArrayList<>();
for (EcDevicePlus item : list) {
SelectItem selectItem = new SelectItem();
selectItem.setName(item.getDeviceCode());
selectItem.setId(item.getId());
@@ -55,6 +60,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
}
return result;
}
@Override
public EcDevicePlus getById(Long id, SFunction<EcDevicePlus, ?>... columns) {
LambdaQueryWrapper<EcDevicePlus> lambdaQueryWrapper = new LambdaQueryWrapper<EcDevicePlus>()
@@ -84,7 +90,8 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
@Override
public List<EcDevicePlus> getByIds(List<Long> ids) {
LambdaQueryWrapper<EcDevicePlus> lambdaQueryWrapper = new LambdaQueryWrapper<EcDevicePlus>().in(EcDevicePlus::getId, ids);
LambdaQueryWrapper<EcDevicePlus> lambdaQueryWrapper = new LambdaQueryWrapper<EcDevicePlus>()
.in(EcDevicePlus::getId, ids);
return this.list(lambdaQueryWrapper);
}
@@ -131,6 +138,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
List<T> tList = JSONArray.parseArray(JSONArray.toJSONString(result), tClass);
return tList;
}
/**
* 查询设备(手机设备)
*
@@ -138,8 +146,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
* @return 设备(手机设备)
*/
@Override
public EcDevice selectEcDeviceById(Long id)
{
public EcDevice selectEcDeviceById(Long id) {
return ecDeviceMapper.selectEcDeviceById(id);
}
@@ -150,8 +157,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
* @return 设备(手机设备)
*/
@Override
public List<EcDevice> selectEcDeviceList(EcDevice ecDevice)
{
public List<EcDevice> selectEcDeviceList(EcDevice ecDevice) {
return ecDeviceMapper.selectEcDeviceList(ecDevice);
}
@@ -162,8 +168,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
* @return 结果
*/
@Override
public int insertEcDevice(EcDevice ecDevice)
{
public int insertEcDevice(EcDevice ecDevice) {
return ecDeviceMapper.insertEcDevice(ecDevice);
}
@@ -174,8 +179,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
* @return 结果
*/
@Override
public int updateEcDevice(EcDevice ecDevice)
{
public int updateEcDevice(EcDevice ecDevice) {
return ecDeviceMapper.updateEcDevice(ecDevice);
}
@@ -186,8 +190,7 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
* @return 结果
*/
@Override
public int deleteEcDeviceByIds(Long[] ids)
{
public int deleteEcDeviceByIds(Long[] ids) {
return ecDeviceMapper.deleteEcDeviceByIds(ids);
}
@@ -198,8 +201,74 @@ public class EcDeviceServiceImpl extends ServiceImpl<EcDeviceMapper, EcDevicePlu
* @return 结果
*/
@Override
public int deleteEcDeviceById(Long id)
{
public int deleteEcDeviceById(Long id) {
return ecDeviceMapper.deleteEcDeviceById(id);
}
@Override
public EcDevicePlus selectEcDeviceByDeviceCode(String deviceCode) {
LambdaQueryWrapper<EcDevicePlus> queryWrapper = new LambdaQueryWrapper<EcDevicePlus>()
.eq(EcDevicePlus::getDeviceCode, deviceCode);
return this.getOne(queryWrapper);
}
@Override
public void reportDevice(EcDeviceReportDto reportDto) {
EcDevicePlus existDevice = selectEcDeviceByDeviceCode(reportDto.getDeviceCode());
Date now = new Date();
if (existDevice != null) {
existDevice.setBrand(reportDto.getBrand());
existDevice.setModel(reportDto.getModel());
existDevice.setOsType(reportDto.getOsType());
existDevice.setOsVersion(reportDto.getOsVersion());
existDevice.setAppVersion(reportDto.getAppVersion());
existDevice.setIpAddress(reportDto.getIpAddress());
existDevice.setWidthNum(reportDto.getWidthNum());
existDevice.setHeightNum(reportDto.getHeightNum());
existDevice.setControlType(reportDto.getControlType());
existDevice.setAppId(reportDto.getAppId());
existDevice.setUserId(reportDto.getUserId());
existDevice.setSecretKey(reportDto.getSecretKey());
existDevice.setStatus(1);
existDevice.setLastOnlineTime(now);
existDevice.setUpdatedAt(now);
this.updateById(existDevice);
} else {
EcDevicePlus newDevice = new EcDevicePlus();
newDevice.setDeviceCode(reportDto.getDeviceCode());
newDevice.setBrand(reportDto.getBrand());
newDevice.setModel(reportDto.getModel());
newDevice.setOsType(reportDto.getOsType());
newDevice.setOsVersion(reportDto.getOsVersion());
newDevice.setAppVersion(reportDto.getAppVersion());
newDevice.setIpAddress(reportDto.getIpAddress());
newDevice.setWidthNum(reportDto.getWidthNum());
newDevice.setHeightNum(reportDto.getHeightNum());
newDevice.setControlType(reportDto.getControlType());
newDevice.setAppId(reportDto.getAppId());
newDevice.setUserId(reportDto.getUserId());
newDevice.setSecretKey(reportDto.getSecretKey());
newDevice.setStatus(1);
newDevice.setLastOnlineTime(now);
newDevice.setCreatedAt(now);
newDevice.setUpdatedAt(now);
this.save(newDevice);
}
}
@Override
public void heartbeat(EcDeviceHeartbeatDto heartbeatDto) {
EcDevicePlus existDevice = selectEcDeviceByDeviceCode(heartbeatDto.getDeviceCode());
if (existDevice != null) {
Date now = new Date();
existDevice.setStatus(1);
existDevice.setLastOnlineTime(now);
existDevice.setUpdatedAt(now);
if (StringUtils.isNotBlank(heartbeatDto.getIpAddress())) {
existDevice.setIpAddress(heartbeatDto.getIpAddress());
}
this.updateById(existDevice);
}
}
}