检查设备位置与围栏的关系
This commit is contained in:
@ -0,0 +1,105 @@
|
|||||||
|
package com.fuyuanshen.equipment.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||||
|
import com.fuyuanshen.common.log.annotation.Log;
|
||||||
|
import com.fuyuanshen.common.web.core.BaseController;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||||
|
import com.fuyuanshen.common.core.domain.R;
|
||||||
|
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||||
|
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||||
|
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||||
|
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.DeviceFenceStatusVo;
|
||||||
|
import com.fuyuanshen.equipment.domain.bo.DeviceFenceStatusBo;
|
||||||
|
import com.fuyuanshen.equipment.service.IDeviceFenceStatusService;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/equipment/fenceStatus")
|
||||||
|
public class DeviceFenceStatusController extends BaseController {
|
||||||
|
|
||||||
|
private final IDeviceFenceStatusService deviceFenceStatusService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备进入围栏状态列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("equipment:fenceStatus:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<DeviceFenceStatusVo> list(DeviceFenceStatusBo bo, PageQuery pageQuery) {
|
||||||
|
return deviceFenceStatusService.queryPageList(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出设备进入围栏状态列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("equipment:fenceStatus:export")
|
||||||
|
@Log(title = "设备进入围栏状态", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(DeviceFenceStatusBo bo, HttpServletResponse response) {
|
||||||
|
List<DeviceFenceStatusVo> list = deviceFenceStatusService.queryList(bo);
|
||||||
|
ExcelUtil.exportExcel(list, "设备进入围栏状态", DeviceFenceStatusVo.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备进入围栏状态详细信息
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("equipment:fenceStatus:query")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public R<DeviceFenceStatusVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
|
@PathVariable Long id) {
|
||||||
|
return R.ok(deviceFenceStatusService.queryById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备进入围栏状态
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("equipment:fenceStatus:add")
|
||||||
|
@Log(title = "设备进入围栏状态", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceFenceStatusBo bo) {
|
||||||
|
return toAjax(deviceFenceStatusService.insertByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备进入围栏状态
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("equipment:fenceStatus:edit")
|
||||||
|
@Log(title = "设备进入围栏状态", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceFenceStatusBo bo) {
|
||||||
|
return toAjax(deviceFenceStatusService.updateByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("equipment:fenceStatus:remove")
|
||||||
|
@Log(title = "设备进入围栏状态", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ids) {
|
||||||
|
return toAjax(deviceFenceStatusService.deleteWithValidByIds(List.of(ids), true));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package com.fuyuanshen.equipment.domain;
|
||||||
|
|
||||||
|
import com.fuyuanshen.common.tenant.core.TenantEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import java.util.Date;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态对象 device_fence_status
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("device_fence_status")
|
||||||
|
public class DeviceFenceStatus extends TenantEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备ID
|
||||||
|
*/
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 围栏ID
|
||||||
|
*/
|
||||||
|
private Long fenceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态: 0-在围栏外, 1-在围栏内
|
||||||
|
*/
|
||||||
|
private Long status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上次检查时间
|
||||||
|
*/
|
||||||
|
private Date lastCheckTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package com.fuyuanshen.equipment.domain.bo;
|
||||||
|
|
||||||
|
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||||
|
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||||
|
import com.fuyuanshen.equipment.domain.DeviceFenceStatus;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import java.util.Date;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态业务对象 device_fence_status
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@AutoMapper(target = DeviceFenceStatus.class, reverseConvertGenerate = false)
|
||||||
|
public class DeviceFenceStatusBo extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@NotNull(message = "不能为空", groups = { EditGroup.class })
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备ID
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "设备ID不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 围栏ID
|
||||||
|
*/
|
||||||
|
@NotNull(message = "围栏ID不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
|
private Long fenceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态: 0-在围栏外, 1-在围栏内
|
||||||
|
*/
|
||||||
|
@NotNull(message = "状态: 0-在围栏外, 1-在围栏内不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
|
private Long status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上次检查时间
|
||||||
|
*/
|
||||||
|
@NotNull(message = "上次检查时间不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
|
private Date lastCheckTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package com.fuyuanshen.equipment.domain.vo;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fuyuanshen.equipment.domain.DeviceFenceStatus;
|
||||||
|
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import com.fuyuanshen.common.excel.annotation.ExcelDictFormat;
|
||||||
|
import com.fuyuanshen.common.excel.convert.ExcelDictConvert;
|
||||||
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态视图对象 device_fence_status
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
@AutoMapper(target = DeviceFenceStatus.class)
|
||||||
|
public class DeviceFenceStatusVo implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备ID
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "设备ID")
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 围栏ID
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "围栏ID")
|
||||||
|
private Long fenceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态: 0-在围栏外, 1-在围栏内
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "状态: 0-在围栏外, 1-在围栏内")
|
||||||
|
private Long status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上次检查时间
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "上次检查时间")
|
||||||
|
private Date lastCheckTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.fuyuanshen.equipment.mapper;
|
||||||
|
|
||||||
|
import com.fuyuanshen.equipment.domain.DeviceFenceStatus;
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.DeviceFenceStatusVo;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态Mapper接口
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
public interface DeviceFenceStatusMapper extends BaseMapperPlus<DeviceFenceStatus, DeviceFenceStatusVo> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
package com.fuyuanshen.equipment.service;
|
||||||
|
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.DeviceFenceStatusVo;
|
||||||
|
import com.fuyuanshen.equipment.domain.bo.DeviceFenceStatusBo;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态Service接口
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
public interface IDeviceFenceStatusService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 设备进入围栏状态
|
||||||
|
*/
|
||||||
|
DeviceFenceStatusVo queryById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询设备进入围栏状态列表
|
||||||
|
*
|
||||||
|
* @param bo 查询条件
|
||||||
|
* @param pageQuery 分页参数
|
||||||
|
* @return 设备进入围栏状态分页列表
|
||||||
|
*/
|
||||||
|
TableDataInfo<DeviceFenceStatusVo> queryPageList(DeviceFenceStatusBo bo, PageQuery pageQuery);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询符合条件的设备进入围栏状态列表
|
||||||
|
*
|
||||||
|
* @param bo 查询条件
|
||||||
|
* @return 设备进入围栏状态列表
|
||||||
|
*/
|
||||||
|
List<DeviceFenceStatusVo> queryList(DeviceFenceStatusBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param bo 设备进入围栏状态
|
||||||
|
* @return 是否新增成功
|
||||||
|
*/
|
||||||
|
Boolean insertByBo(DeviceFenceStatusBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param bo 设备进入围栏状态
|
||||||
|
* @return 是否修改成功
|
||||||
|
*/
|
||||||
|
Boolean updateByBo(DeviceFenceStatusBo bo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并批量删除设备进入围栏状态信息
|
||||||
|
*
|
||||||
|
* @param ids 待删除的主键集合
|
||||||
|
* @param isValid 是否进行有效性校验
|
||||||
|
* @return 是否删除成功
|
||||||
|
*/
|
||||||
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备在特定围栏的最新状态
|
||||||
|
*
|
||||||
|
* @param deviceId 设备ID
|
||||||
|
* @param fenceId 围栏ID
|
||||||
|
* @return 最新状态记录,如果不存在则返回null
|
||||||
|
*/
|
||||||
|
DeviceFenceStatusVo getLatestStatusByDeviceAndFence(String deviceId, Long fenceId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,152 @@
|
|||||||
|
package com.fuyuanshen.equipment.service.impl;
|
||||||
|
|
||||||
|
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.fuyuanshen.equipment.domain.bo.DeviceFenceStatusBo;
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.DeviceFenceStatusVo;
|
||||||
|
import com.fuyuanshen.equipment.domain.DeviceFenceStatus;
|
||||||
|
import com.fuyuanshen.equipment.mapper.DeviceFenceStatusMapper;
|
||||||
|
import com.fuyuanshen.equipment.service.IDeviceFenceStatusService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备进入围栏状态Service业务层处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @date 2025-09-15
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class DeviceFenceStatusServiceImpl implements IDeviceFenceStatusService {
|
||||||
|
|
||||||
|
private final DeviceFenceStatusMapper baseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 设备进入围栏状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DeviceFenceStatusVo queryById(Long id){
|
||||||
|
return baseMapper.selectVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询设备进入围栏状态列表
|
||||||
|
*
|
||||||
|
* @param bo 查询条件
|
||||||
|
* @param pageQuery 分页参数
|
||||||
|
* @return 设备进入围栏状态分页列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<DeviceFenceStatusVo> queryPageList(DeviceFenceStatusBo bo, PageQuery pageQuery) {
|
||||||
|
LambdaQueryWrapper<DeviceFenceStatus> lqw = buildQueryWrapper(bo);
|
||||||
|
Page<DeviceFenceStatusVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询符合条件的设备进入围栏状态列表
|
||||||
|
*
|
||||||
|
* @param bo 查询条件
|
||||||
|
* @return 设备进入围栏状态列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DeviceFenceStatusVo> queryList(DeviceFenceStatusBo bo) {
|
||||||
|
LambdaQueryWrapper<DeviceFenceStatus> lqw = buildQueryWrapper(bo);
|
||||||
|
return baseMapper.selectVoList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LambdaQueryWrapper<DeviceFenceStatus> buildQueryWrapper(DeviceFenceStatusBo bo) {
|
||||||
|
Map<String, Object> params = bo.getParams();
|
||||||
|
LambdaQueryWrapper<DeviceFenceStatus> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.orderByAsc(DeviceFenceStatus::getId);
|
||||||
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceId()), DeviceFenceStatus::getDeviceId, bo.getDeviceId());
|
||||||
|
lqw.eq(bo.getFenceId() != null, DeviceFenceStatus::getFenceId, bo.getFenceId());
|
||||||
|
lqw.eq(bo.getStatus() != null, DeviceFenceStatus::getStatus, bo.getStatus());
|
||||||
|
lqw.eq(bo.getLastCheckTime() != null, DeviceFenceStatus::getLastCheckTime, bo.getLastCheckTime());
|
||||||
|
return lqw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param bo 设备进入围栏状态
|
||||||
|
* @return 是否新增成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean insertByBo(DeviceFenceStatusBo bo) {
|
||||||
|
DeviceFenceStatus add = MapstructUtils.convert(bo, DeviceFenceStatus.class);
|
||||||
|
validEntityBeforeSave(add);
|
||||||
|
boolean flag = baseMapper.insert(add) > 0;
|
||||||
|
if (flag) {
|
||||||
|
bo.setId(add.getId());
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备进入围栏状态
|
||||||
|
*
|
||||||
|
* @param bo 设备进入围栏状态
|
||||||
|
* @return 是否修改成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateByBo(DeviceFenceStatusBo bo) {
|
||||||
|
DeviceFenceStatus update = MapstructUtils.convert(bo, DeviceFenceStatus.class);
|
||||||
|
validEntityBeforeSave(update);
|
||||||
|
return baseMapper.updateById(update) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存前的数据校验
|
||||||
|
*/
|
||||||
|
private void validEntityBeforeSave(DeviceFenceStatus entity){
|
||||||
|
//TODO 做一些数据校验,如唯一约束
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验并批量删除设备进入围栏状态信息
|
||||||
|
*
|
||||||
|
* @param ids 待删除的主键集合
|
||||||
|
* @param isValid 是否进行有效性校验
|
||||||
|
* @return 是否删除成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
|
if(isValid){
|
||||||
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
|
}
|
||||||
|
return baseMapper.deleteByIds(ids) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备在特定围栏的最新状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DeviceFenceStatusVo getLatestStatusByDeviceAndFence(String deviceId, Long fenceId) {
|
||||||
|
LambdaQueryWrapper<DeviceFenceStatus> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(DeviceFenceStatus::getDeviceId, deviceId);
|
||||||
|
lqw.eq(DeviceFenceStatus::getFenceId, fenceId);
|
||||||
|
lqw.orderByDesc(DeviceFenceStatus::getLastCheckTime);
|
||||||
|
lqw.last("LIMIT 1");
|
||||||
|
DeviceFenceStatus status = baseMapper.selectOne(lqw);
|
||||||
|
return MapstructUtils.convert(status, DeviceFenceStatusVo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -9,11 +9,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.fuyuanshen.equipment.domain.DeviceGeoFence;
|
import com.fuyuanshen.equipment.domain.DeviceGeoFence;
|
||||||
|
import com.fuyuanshen.equipment.domain.bo.DeviceFenceStatusBo;
|
||||||
import com.fuyuanshen.equipment.domain.bo.DeviceGeoFenceBo;
|
import com.fuyuanshen.equipment.domain.bo.DeviceGeoFenceBo;
|
||||||
import com.fuyuanshen.equipment.domain.dto.FenceCheckResponse;
|
import com.fuyuanshen.equipment.domain.dto.FenceCheckResponse;
|
||||||
import com.fuyuanshen.equipment.domain.query.FenceCheckRequest;
|
import com.fuyuanshen.equipment.domain.query.FenceCheckRequest;
|
||||||
|
import com.fuyuanshen.equipment.domain.vo.DeviceFenceStatusVo;
|
||||||
import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo;
|
import com.fuyuanshen.equipment.domain.vo.DeviceGeoFenceVo;
|
||||||
import com.fuyuanshen.equipment.mapper.DeviceGeoFenceMapper;
|
import com.fuyuanshen.equipment.mapper.DeviceGeoFenceMapper;
|
||||||
|
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -21,10 +24,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电子围栏Service业务层处理
|
* 电子围栏Service业务层处理
|
||||||
@ -39,6 +39,10 @@ public class DeviceGeoFenceServiceImpl implements IDeviceGeoFenceService {
|
|||||||
|
|
||||||
private final DeviceGeoFenceMapper baseMapper;
|
private final DeviceGeoFenceMapper baseMapper;
|
||||||
|
|
||||||
|
private final IDeviceFenceStatusService fenceStatusService; // 添加此行
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询电子围栏
|
* 查询电子围栏
|
||||||
*
|
*
|
||||||
@ -158,42 +162,85 @@ public class DeviceGeoFenceServiceImpl implements IDeviceGeoFenceService {
|
|||||||
bo.setIsActive(1L); // 假设1表示激活状态
|
bo.setIsActive(1L); // 假设1表示激活状态
|
||||||
List<DeviceGeoFenceVo> activeFences = queryList(bo);
|
List<DeviceGeoFenceVo> activeFences = queryList(bo);
|
||||||
|
|
||||||
// 2. 判断设备位置与各围栏的关系
|
// 2. 初始化响应对象
|
||||||
FenceCheckResponse response = new FenceCheckResponse();
|
FenceCheckResponse response = new FenceCheckResponse();
|
||||||
response.setDeviceId(request.getDeviceId());
|
response.setDeviceId(request.getDeviceId());
|
||||||
response.setCheckTime(System.currentTimeMillis());
|
response.setCheckTime(System.currentTimeMillis());
|
||||||
|
response.setEnteredFences(new ArrayList<>());
|
||||||
|
response.setExitedFences(new ArrayList<>());
|
||||||
|
response.setCurrentFences(new ArrayList<>());
|
||||||
|
|
||||||
// 这里需要实现具体的围栏判断逻辑
|
// 3. 遍历所有激活的围栏
|
||||||
// 根据您之前提供的算法实现点在围栏内的判断
|
|
||||||
|
|
||||||
for (DeviceGeoFenceVo fence : activeFences) {
|
for (DeviceGeoFenceVo fence : activeFences) {
|
||||||
String coordinates = fence.getCoordinates();
|
// 解析围栏坐标
|
||||||
|
|
||||||
// 在需要转换的地方
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
List<GeoFenceChecker.Coordinate> coordinateList = List.of();
|
List<GeoFenceChecker.Coordinate> coordinateList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
coordinateList = objectMapper.readValue(coordinates,
|
coordinateList = objectMapper.readValue(fence.getCoordinates(),
|
||||||
new TypeReference<List<GeoFenceChecker.Coordinate>>() {
|
new TypeReference<List<GeoFenceChecker.Coordinate>>() {
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 处理解析异常
|
|
||||||
log.error("坐标数据解析失败: {}", e.getMessage());
|
log.error("坐标数据解析失败: {}", e.getMessage());
|
||||||
|
continue; // 解析失败则跳过该围栏
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查设备是否在围栏内
|
||||||
|
boolean pointInFence = GeoFenceChecker.isPointInFence(
|
||||||
|
request.getLatitude(),
|
||||||
|
request.getLongitude(),
|
||||||
|
fence.getAreaType(),
|
||||||
|
coordinateList,
|
||||||
|
fence.getRadius());
|
||||||
|
|
||||||
|
// 创建围栏信息对象
|
||||||
FenceCheckResponse.FenceInfo fenceInfo = new FenceCheckResponse.FenceInfo();
|
FenceCheckResponse.FenceInfo fenceInfo = new FenceCheckResponse.FenceInfo();
|
||||||
List<FenceCheckResponse.FenceInfo> list = new ArrayList<>();
|
|
||||||
boolean pointInFence = GeoFenceChecker.isPointInFence(request.getLatitude(), request.getLongitude(), fence.getAreaType(), coordinateList, fence.getRadius());
|
|
||||||
if (pointInFence) {
|
|
||||||
fenceInfo.setFenceId(fence.getId());
|
fenceInfo.setFenceId(fence.getId());
|
||||||
fenceInfo.setFenceName(fence.getName());
|
fenceInfo.setFenceName(fence.getName());
|
||||||
fenceInfo.setFenceType(fence.getAreaType());
|
fenceInfo.setFenceType(fence.getAreaType());
|
||||||
response.setEnteredFences(list);
|
|
||||||
|
// // 查询设备在该围栏的历史状态
|
||||||
|
// DeviceFenceStatusBo statusQuery = new DeviceFenceStatusBo();
|
||||||
|
// statusQuery.setDeviceId(request.getDeviceId());
|
||||||
|
// statusQuery.setFenceId(fence.getId());
|
||||||
|
// List<DeviceFenceStatusVo> statusHistory = fenceStatusService.queryList(statusQuery);
|
||||||
|
//
|
||||||
|
// // 获取最新的状态记录
|
||||||
|
// DeviceFenceStatusVo latestStatus = statusHistory.stream()
|
||||||
|
// .max(Comparator.comparing(DeviceFenceStatusVo::getLastCheckTime))
|
||||||
|
// .orElse(null);
|
||||||
|
|
||||||
|
// 查询设备在该围栏的最新状态
|
||||||
|
DeviceFenceStatusVo latestStatus = fenceStatusService.getLatestStatusByDeviceAndFence(
|
||||||
|
request.getDeviceId(), fence.getId());
|
||||||
|
|
||||||
|
// 判断设备与围栏的关系变化
|
||||||
|
Long previousStatus = latestStatus != null ? latestStatus.getStatus() : 0L; // 默认在围栏外
|
||||||
|
Long currentStatus = pointInFence ? 1L : 0L; // 当前状态:1-在围栏内,0-在围栏外
|
||||||
|
|
||||||
|
// 如果状态发生变化,则记录
|
||||||
|
if (!previousStatus.equals(currentStatus)) {
|
||||||
|
// 创建新的状态记录
|
||||||
|
DeviceFenceStatusBo newStatus = new DeviceFenceStatusBo();
|
||||||
|
newStatus.setDeviceId(request.getDeviceId());
|
||||||
|
newStatus.setFenceId(fence.getId());
|
||||||
|
newStatus.setStatus(currentStatus);
|
||||||
|
newStatus.setLastCheckTime(new Date());
|
||||||
|
|
||||||
|
// 保存状态记录
|
||||||
|
fenceStatusService.insertByBo(newStatus);
|
||||||
|
|
||||||
|
// 根据状态变化更新响应
|
||||||
|
if (currentStatus == 1L) {
|
||||||
|
// 设备进入围栏
|
||||||
response.getEnteredFences().add(fenceInfo);
|
response.getEnteredFences().add(fenceInfo);
|
||||||
} else {
|
} else {
|
||||||
response.setExitedFences(list);
|
// 设备离开围栏
|
||||||
response.getExitedFences().add(fenceInfo);
|
response.getExitedFences().add(fenceInfo);
|
||||||
}
|
}
|
||||||
|
} else if (currentStatus == 1L) {
|
||||||
|
// 状态未变,但设备仍在围栏内
|
||||||
|
response.getCurrentFences().add(fenceInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceFenceStatusMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user