| | |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysDoorDevice; |
| | | import com.ruoyi.system.domain.SysVisitArea; |
| | | import com.ruoyi.system.domain.SysVisitorMachine; |
| | | import com.ruoyi.system.dto.SysVisitorMachineAddRequest; |
| | |
| | | import com.ruoyi.system.vo.SysVisitorMachineVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | return machine; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int activateDevice(Long deviceId) { |
| | | // 1. 根据deviceId查询设备 |
| | | SysVisitorMachine device = visitorMachineMapper.selectById(deviceId); |
| | | if (device == null || device.getDelFlag().equals("1")) { |
| | | throw new ServiceException("设备不存在,请先添加设备"); |
| | | } |
| | | |
| | | // 2. 检查是否已激活 |
| | | if ("ONLINE".equals(device.getOnlineStatus()) || "ACTIVATED".equals(device.getOnlineStatus())) { |
| | | throw new ServiceException("设备已激活,无需重复操作"); |
| | | } |
| | | |
| | | // 3. 检查设备是否启用 |
| | | if (device.getEnabled() == null || !device.getEnabled()) { |
| | | throw new ServiceException("设备未启用,请先在后台启用设备"); |
| | | } |
| | | |
| | | // 4. 更新状态为激活/在线 |
| | | SysVisitorMachine update = new SysVisitorMachine(); |
| | | update.setMachineId(device.getMachineId()); |
| | | update.setOnlineStatus("ONLINE"); // 或 "ACTIVATED",根据你的枚举定义 |
| | | update.setUpdateTime(new Date()); |
| | | |
| | | return visitorMachineMapper.updateMachine(update); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deactivateDevice(Long deviceId) { |
| | | // 1. 根据deviceId查询设备 |
| | | SysVisitorMachine device = visitorMachineMapper.selectById(deviceId); |
| | | if (device == null || device.getDelFlag().equals("1")) { |
| | | throw new ServiceException("设备不存在"); |
| | | } |
| | | |
| | | // 2. 检查是否已注销 |
| | | if ("OFFLINE".equals(device.getOnlineStatus()) || "UNACTIVATED".equals(device.getOnlineStatus())) { |
| | | throw new ServiceException("设备已注销,无需重复操作"); |
| | | } |
| | | |
| | | // 3. 更新状态为离线/未激活 |
| | | SysVisitorMachine update = new SysVisitorMachine(); |
| | | update.setMachineId(deviceId); |
| | | update.setOnlineStatus("OFFLINE"); // 或 "UNACTIVATED" |
| | | update.setUpdateTime(new Date()); |
| | | |
| | | return visitorMachineMapper.updateMachine(update); |
| | | } |
| | | |
| | | private Long getRequiredAreaId(Long areaId) |
| | | { |
| | | if (areaId == null || areaId <= 0) |