| | |
| | | import com.ruoyi.system.mapper.SysDoorDeviceMapper; |
| | | import com.ruoyi.system.mapper.SysVisitAreaMapper; |
| | | import com.ruoyi.system.service.ISysDoorDeviceService; |
| | | import com.ruoyi.system.utils.AreaIdUtils; |
| | | import com.ruoyi.system.utils.DoorDeviceCredentialCrypto; |
| | | import com.ruoyi.system.vo.SysDoorDeviceVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.nio.charset.Charset; |
| | | |
| | | /** |
| | | * 门禁设备服务实现 |
| | |
| | | public PageInfo<SysDoorDeviceVO> pageList(SysDoorDevicePageRequest request) |
| | | { |
| | | SysDoorDevicePageRequest query = request == null ? new SysDoorDevicePageRequest() : request; |
| | | query.setAreaId(StringUtils.trim(query.getAreaId())); |
| | | query.setDeviceName(StringUtils.trim(query.getDeviceName())); |
| | | query.setDeviceId(StringUtils.trim(query.getDeviceId())); |
| | | query.setOnlineStatus(StringUtils.trim(query.getOnlineStatus())); |
| | | PageInfo<SysDoorDeviceVO> pageInfo = new PageInfo<SysDoorDeviceVO>(query.getPageNum(), query.getPageSize()); |
| | | List<SysDoorDeviceVO> list = doorDeviceMapper.pageList(query, pageInfo); |
| | | List<SysDoorDeviceVO> list = doorDeviceMapper.pageList(query, |
| | | AreaIdUtils.parseLocalAreaId(query.getAreaId()), pageInfo); |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | |
| | | } |
| | | SysDoorDevice doorDevice = buildDoorDevice(request.getAreaId(), request.getDeviceName(), request.getBrand(), |
| | | request.getDeviceId(), request.getRemark(), request.getEnabled(), null); |
| | | fillConnectionSettings(doorDevice, request.getDevicePort(), request.getLoginUsername(), |
| | | request.getLoginPassword(), request.getDoorNo(), request.getTimeSectionNo(), request.getCharset(), |
| | | null, true); |
| | | doorDevice.setOnlineStatus(ONLINE_STATUS_UNACTIVATED); |
| | | doorDevice.setCreateBy(username); |
| | | return doorDeviceMapper.insertDoorDevice(doorDevice); |
| | |
| | | throw new ServiceException("门禁设备内容不能为空"); |
| | | } |
| | | Long doorId = getRequiredDoorId(request.getDoorId()); |
| | | if (doorDeviceMapper.selectById(doorId) == null) |
| | | SysDoorDevice existing = doorDeviceMapper.selectById(doorId); |
| | | if (existing == null) |
| | | { |
| | | throw new ServiceException("门禁设备不存在"); |
| | | } |
| | | SysDoorDevice doorDevice = buildDoorDevice(request.getAreaId(), request.getDeviceName(), request.getBrand(), |
| | | request.getDeviceId(), request.getRemark(), request.getEnabled(), doorId); |
| | | fillConnectionSettings(doorDevice, request.getDevicePort(), request.getLoginUsername(), |
| | | request.getLoginPassword(), request.getDoorNo(), request.getTimeSectionNo(), request.getCharset(), |
| | | existing.getLoginPasswordCipher(), StringUtils.isEmpty(existing.getLoginPasswordCipher())); |
| | | doorDevice.setDoorId(doorId); |
| | | doorDevice.setUpdateBy(username); |
| | | return doorDeviceMapper.updateDoorDevice(doorDevice); |
| | |
| | | return doorDevice; |
| | | } |
| | | |
| | | private void fillConnectionSettings(SysDoorDevice doorDevice, Integer devicePort, String loginUsername, |
| | | String loginPassword, Integer doorNo, Integer timeSectionNo, String charset, |
| | | String existingPasswordCipher, boolean requirePassword) |
| | | { |
| | | int resolvedPort = devicePort == null ? 37777 : devicePort; |
| | | if (resolvedPort <= 0 || resolvedPort > 65535) |
| | | { |
| | | throw new ServiceException("设备端口必须在1到65535之间"); |
| | | } |
| | | int resolvedDoorNo = doorNo == null ? 0 : doorNo; |
| | | if (resolvedDoorNo < 0) |
| | | { |
| | | throw new ServiceException("门通道序号不能小于0"); |
| | | } |
| | | int resolvedTimeSectionNo = timeSectionNo == null ? 255 : timeSectionNo; |
| | | if (resolvedTimeSectionNo < 0 || resolvedTimeSectionNo > 255) |
| | | { |
| | | throw new ServiceException("时间模板序号必须在0到255之间"); |
| | | } |
| | | String resolvedCharset = StringUtils.isEmpty(StringUtils.trim(charset)) ? "GBK" : StringUtils.trim(charset); |
| | | try |
| | | { |
| | | Charset.forName(resolvedCharset); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | throw new ServiceException("设备姓名编码无效"); |
| | | } |
| | | |
| | | String password = StringUtils.trim(loginPassword); |
| | | if (requirePassword && StringUtils.isEmpty(password)) |
| | | { |
| | | throw new ServiceException("设备登录密码不能为空"); |
| | | } |
| | | doorDevice.setDevicePort(resolvedPort); |
| | | doorDevice.setLoginUsername(StringUtils.isEmpty(StringUtils.trim(loginUsername)) |
| | | ? "admin" : StringUtils.trim(loginUsername)); |
| | | doorDevice.setLoginPasswordCipher(StringUtils.isEmpty(password) |
| | | ? existingPasswordCipher : DoorDeviceCredentialCrypto.encrypt(password)); |
| | | doorDevice.setDoorNo(resolvedDoorNo); |
| | | doorDevice.setTimeSectionNo(resolvedTimeSectionNo); |
| | | doorDevice.setCharset(resolvedCharset); |
| | | } |
| | | |
| | | private Long getRequiredAreaId(Long areaId) |
| | | { |
| | | if (areaId == null || areaId <= 0) |