Compare commits

3 Commits

Author SHA1 Message Date
e2821566c8 事件地址 2025-09-22 18:18:05 +08:00
5b3a92c80d 查询所有设备类型 2025-09-22 16:34:32 +08:00
9d642f4913 分页查询围栏进出记录列表 2025-09-22 15:58:00 +08:00
9 changed files with 157 additions and 28 deletions

View File

@ -69,4 +69,9 @@ public class DeviceFenceAccessRecord extends BaseEntity {
*/ */
private Date eventTime; private Date eventTime;
/**
* 事件地址
*/
private String eventAddress;
} }

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.equipment.domain.bo; package com.fuyuanshen.equipment.domain.bo;
import cn.idev.excel.annotation.ExcelProperty;
import com.fuyuanshen.common.core.validate.AddGroup; import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup; import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity; import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
@ -8,7 +9,9 @@ import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import java.util.Date; import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
/** /**
@ -25,19 +28,24 @@ public class DeviceFenceAccessRecordBo extends BaseEntity {
/** /**
* 记录ID * 记录ID
*/ */
@NotNull(message = "记录ID不能为空", groups = { EditGroup.class }) @NotNull(message = "记录ID不能为空", groups = {EditGroup.class})
private Long id; private Long id;
/** /**
* 围栏ID * 围栏ID
*/ */
@NotNull(message = "围栏ID不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "围栏ID不能为空", groups = {AddGroup.class, EditGroup.class})
private Long fenceId; private Long fenceId;
/**
* 围栏名称
*/
private String fenceName;
/** /**
* 设备标识 * 设备标识
*/ */
@NotBlank(message = "设备标识不能为空", groups = { AddGroup.class, EditGroup.class }) @NotBlank(message = "设备标识不能为空", groups = {AddGroup.class, EditGroup.class})
private String deviceId; private String deviceId;
/** /**
@ -48,19 +56,19 @@ public class DeviceFenceAccessRecordBo extends BaseEntity {
/** /**
* 事件类型 * 事件类型
*/ */
@NotNull(message = "事件类型不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "事件类型不能为空", groups = {AddGroup.class, EditGroup.class})
private Long eventType; private Long eventType;
/** /**
* 纬度 * 纬度
*/ */
@NotNull(message = "纬度不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "纬度不能为空", groups = {AddGroup.class, EditGroup.class})
private Double latitude; private Double latitude;
/** /**
* 经度 * 经度
*/ */
@NotNull(message = "经度不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "经度不能为空", groups = {AddGroup.class, EditGroup.class})
private Double longitude; private Double longitude;
/** /**
@ -71,9 +79,14 @@ public class DeviceFenceAccessRecordBo extends BaseEntity {
/** /**
* 事件时间 * 事件时间
*/ */
@NotNull(message = "事件时间不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "事件时间不能为空", groups = {AddGroup.class, EditGroup.class})
private Date eventTime; private Date eventTime;
/**
* 事件地址
*/
private String eventAddress;
/** /**
* 开始时间 * 开始时间
*/ */

View File

@ -97,6 +97,12 @@ public class DeviceFenceAccessRecordVo implements Serializable {
@ExcelProperty(value = "事件时间") @ExcelProperty(value = "事件时间")
private Date eventTime; private Date eventTime;
/**
* 事件地址
*/
@ExcelProperty(value = "事件地址")
private String eventAddress;
/** /**
* 记录创建时间 * 记录创建时间
*/ */

View File

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus; import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
import com.fuyuanshen.equipment.domain.DeviceFenceAccessRecord; import com.fuyuanshen.equipment.domain.DeviceFenceAccessRecord;
import com.fuyuanshen.equipment.domain.bo.DeviceFenceAccessRecordBo;
import com.fuyuanshen.equipment.domain.vo.DeviceFenceAccessRecordVo; import com.fuyuanshen.equipment.domain.vo.DeviceFenceAccessRecordVo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -29,5 +30,14 @@ public interface DeviceFenceAccessRecordMapper extends BaseMapperPlus<DeviceFenc
List<DeviceFenceAccessRecordVo> selectVoPageWithFenceAndDeviceName(@Param(Constants.WRAPPER) Wrapper<DeviceFenceAccessRecord> wrapper); List<DeviceFenceAccessRecordVo> selectVoPageWithFenceAndDeviceName(@Param(Constants.WRAPPER) Wrapper<DeviceFenceAccessRecord> wrapper);
/**
* 分页查询围栏进出记录列表纯XML形式
*
* @param page 分页参数
* @param bo 查询条件
* @return 围栏进出记录分页列表
*/
Page<DeviceFenceAccessRecordVo> selectVoPageByXml(Page<DeviceFenceAccessRecord> page, @Param("bo") DeviceFenceAccessRecordBo bo);
} }

View File

@ -54,7 +54,8 @@ public class DeviceFenceAccessRecordServiceImpl implements IDeviceFenceAccessRec
@Override @Override
public TableDataInfo<DeviceFenceAccessRecordVo> queryPageList(DeviceFenceAccessRecordBo bo, PageQuery pageQuery) { public TableDataInfo<DeviceFenceAccessRecordVo> queryPageList(DeviceFenceAccessRecordBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<DeviceFenceAccessRecord> lqw = buildQueryWrapper(bo); LambdaQueryWrapper<DeviceFenceAccessRecord> lqw = buildQueryWrapper(bo);
Page<DeviceFenceAccessRecordVo> result = baseMapper.selectVoPageWithFenceAndDeviceName(pageQuery.build(), lqw); // Page<DeviceFenceAccessRecordVo> result = baseMapper.selectVoPageWithFenceAndDeviceName(pageQuery.build(), lqw);
Page<DeviceFenceAccessRecordVo> result = baseMapper.selectVoPageByXml(pageQuery.build(), bo);
return TableDataInfo.build(result); return TableDataInfo.build(result);
} }
@ -85,6 +86,9 @@ public class DeviceFenceAccessRecordServiceImpl implements IDeviceFenceAccessRec
lqw.eq(bo.getAccuracy() != null, DeviceFenceAccessRecord::getAccuracy, bo.getAccuracy()); lqw.eq(bo.getAccuracy() != null, DeviceFenceAccessRecord::getAccuracy, bo.getAccuracy());
lqw.eq(bo.getEventTime() != null, DeviceFenceAccessRecord::getEventTime, bo.getEventTime()); lqw.eq(bo.getEventTime() != null, DeviceFenceAccessRecord::getEventTime, bo.getEventTime());
lqw.eq(bo.getCreateTime() != null, DeviceFenceAccessRecord::getCreateTime, bo.getCreateTime()); lqw.eq(bo.getCreateTime() != null, DeviceFenceAccessRecord::getCreateTime, bo.getCreateTime());
if (StringUtils.isNotBlank(bo.getFenceName())) {
params.put("fenceName", bo.getFenceName());
}
return lqw; return lqw;
} }

View File

@ -21,6 +21,7 @@ import com.fuyuanshen.equipment.service.IDeviceFenceAccessRecordService;
import com.fuyuanshen.equipment.service.IDeviceFenceStatusService; import com.fuyuanshen.equipment.service.IDeviceFenceStatusService;
import com.fuyuanshen.equipment.service.IDeviceGeoFenceService; import com.fuyuanshen.equipment.service.IDeviceGeoFenceService;
import com.fuyuanshen.equipment.utils.map.GeoFenceChecker; import com.fuyuanshen.equipment.utils.map.GeoFenceChecker;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -240,6 +241,9 @@ public class DeviceGeoFenceServiceImpl implements IDeviceGeoFenceService {
recordBo.setFenceId(fence.getId()); recordBo.setFenceId(fence.getId());
recordBo.setLatitude(request.getLatitude()); recordBo.setLatitude(request.getLatitude());
recordBo.setLongitude(request.getLongitude()); recordBo.setLongitude(request.getLongitude());
String address = GetAddressFromLatUtil.getAdd(request.getLongitude().toString(), request.getLatitude().toString());
recordBo.setEventAddress(address);
recordBo.setEventTime(new Date()); recordBo.setEventTime(new Date());
// 1表示进入围栏2表示离开围栏 // 1表示进入围栏2表示离开围栏
recordBo.setEventType(currentStatus); recordBo.setEventType(currentStatus);

View File

@ -98,18 +98,35 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
public List<DeviceType> queryDeviceTypes() { public List<DeviceType> queryDeviceTypes() {
DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria(); DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
// 管理员 // // 管理员
String username = LoginHelper.getUsername(); // String username = LoginHelper.getUsername();
if (!username.equals("admin")) { // if (!username.equals("admin")) {
criteria.setCustomerId(LoginHelper.getUserId()); // criteria.setCustomerId(LoginHelper.getUserId());
//
// Long userId = LoginHelper.getUserId();
// criteria.setCustomerId(userId);
// }
Long userId = LoginHelper.getUserId(); // 角色管理员
criteria.setCustomerId(userId); Long userId = LoginHelper.getUserId();
List<SysRoleVo> roles = roleService.selectRolesAuthByUserId(userId);
boolean isAdmin = false;
if (CollectionUtil.isNotEmpty(roles)) {
for (SysRoleVo role : roles) {
if (role.getRoleKey().contains("admin")) {
isAdmin = true;
break;
}
}
}
if (!isAdmin) {
criteria.setCustomerId(LoginHelper.getUserId());
} }
return deviceTypeMapper.findAll(criteria); return deviceTypeMapper.findAll(criteria);
} }
/** /**
* 根据设备类型名称查询设备类型 * 根据设备类型名称查询设备类型
* *

View File

@ -8,6 +8,8 @@ import org.slf4j.LoggerFactory;
import java.net.URL; import java.net.URL;
/** /**
* 根据经纬度获取地址信息工具类
*
* @author: 默苍璃 * @author: 默苍璃
* @date: 2025-07-2615:59 * @date: 2025-07-2615:59
*/ */
@ -74,5 +76,6 @@ public class GetAddressFromLatUtil {
System.out.println("通过API获取到具体位置:" + res); System.out.println("通过API获取到具体位置:" + res);
return res; return res;
} }
} }

View File

@ -8,22 +8,89 @@
<select id="selectVoPageWithFenceAndDeviceName" <select id="selectVoPageWithFenceAndDeviceName"
resultType="com.fuyuanshen.equipment.domain.vo.DeviceFenceAccessRecordVo"> resultType="com.fuyuanshen.equipment.domain.vo.DeviceFenceAccessRecordVo">
SELECT r.id, SELECT r.id,
r.fence_id, r.fence_id,
f.name AS fence_name, f.name AS fence_name,
r.device_id, r.device_id,
d.device_name, d.device_name,
r.user_id, r.user_id,
r.event_type, r.event_type,
r.latitude, r.latitude,
r.longitude, r.longitude,
r.accuracy, r.accuracy,
r.event_time, r.event_time,
r.create_time r.create_time
FROM device_fence_access_record r FROM device_fence_access_record r
LEFT JOIN device_geo_fence f ON r.fence_id = f.id LEFT JOIN device_geo_fence f ON r.fence_id = f.id
LEFT JOIN device d ON r.device_id = d.id LEFT JOIN device d ON r.device_id = d.id
${ew.customSqlSegment} ${ew.customSqlSegment}
<where>
<if test="ew.params != null">
<if test="ew.params.fenceName != null and ew.params.fenceName != ''">
AND f.name LIKE CONCAT('%', #{ew.params.fenceName}, '%')
</if>
</if>
</where>
ORDER BY r.id ASC ORDER BY r.id ASC
</select> </select>
<!-- 分页查询围栏进出记录列表纯XML形式 -->
<select id="selectVoPageByXml" resultType="com.fuyuanshen.equipment.domain.vo.DeviceFenceAccessRecordVo">
SELECT r.id,
r.fence_id,
f.name AS fence_name,
r.device_id,
d.device_name,
r.user_id,
r.event_type,
r.latitude,
r.longitude,
r.accuracy,
r.event_time, r.event_address,
r.create_time
FROM device_fence_access_record r
LEFT JOIN device_geo_fence f ON r.fence_id = f.id
LEFT JOIN device d ON r.device_id = d.id
<where>
<if test="bo.fenceId != null">
AND r.fence_id = #{bo.fenceId}
</if>
<if test="bo.deviceId != null and bo.deviceId != ''">
AND r.device_id = #{bo.deviceId}
</if>
<if test="bo.userId != null">
AND r.user_id = #{bo.userId}
</if>
<if test="bo.eventType != null">
AND r.event_type = #{bo.eventType}
</if>
<if test="bo.latitude != null">
AND r.latitude = #{bo.latitude}
</if>
<if test="bo.longitude != null">
AND r.longitude = #{bo.longitude}
</if>
<if test="bo.accuracy != null">
AND r.accuracy = #{bo.accuracy}
</if>
<if test="bo.eventTime != null">
AND r.event_time = #{bo.eventTime}
</if>
<if test="bo.createTime != null">
AND r.create_time = #{bo.createTime}
</if>
<if test="bo.fenceName != null and bo.fenceName != ''">
AND f.name LIKE CONCAT('%', #{bo.fenceName}, '%')
</if>
<!-- 添加时间范围筛选条件 -->
<if test="bo.beginTime != null and bo.beginTime != ''">
AND r.event_time >= #{bo.beginTime}
</if>
<if test="bo.endTime != null and bo.endTime != ''">
AND r.event_time <![CDATA[ <= ]]> #{bo.endTime}
</if>
</where>
ORDER BY r.event_time DESC
</select>
</mapper> </mapper>