Commit c3ced9b9 by liwenjun

定时修改设备密码,添加延迟

parent 071f1c82
......@@ -7,9 +7,11 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import share.system.domain.DeviceGateway;
import share.system.domain.SStore;
import share.system.service.DeviceGatewayService;
import share.system.service.DeviceService;
import share.system.service.DeviceStatusLogService;
import share.system.service.ISStoreService;
import java.util.List;
......@@ -29,6 +31,8 @@ public class DeviceTask {
private DeviceGatewayService deviceGatewayService;
@Autowired
private DeviceService deviceService;
@Autowired
private ISStoreService storeService;
/**
* 设备异常状态短信提醒任务
......@@ -64,8 +68,20 @@ public class DeviceTask {
if (validTime == null) {
validTime = 15;
}
// 更新所有门锁设备开锁密码
deviceService.updateDeviceDoorLockPassword(validTime);
SStore sStore = new SStore();
sStore.setStatus("1");
List<SStore> storeList = storeService.selectSStoreList(sStore);
for (SStore store : storeList) {
// 更新所有门锁设备开锁密码
deviceService.updateDeviceDoorLockPassword(validTime, store.getId());
// 延时执行操作
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
// e.printStackTrace();
log.error("定期修改门锁设备的开锁密码线程中断:{}", e.getMessage());
}
}
log.debug("updateDeviceDoorLockPassword:每周一修改房间门锁密码结束");
}
......
package share.system.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import share.common.core.page.TableDataInfo;
import share.system.domain.Device;
import share.system.domain.DeviceDto;
import java.util.List;
/**
* 设备信息Service接口
*
......@@ -85,5 +86,5 @@ public interface DeviceService extends IService<Device>
TableDataInfo devicePage(DeviceDto device);
boolean updateDeviceDoorLockPassword(Integer validTime);
boolean updateDeviceDoorLockPassword(Integer validTime, Long storeId);
}
package share.system.service.impl;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
......@@ -12,6 +7,10 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import share.common.core.page.PageDomain;
import share.common.core.page.TableDataInfo;
......@@ -19,15 +18,10 @@ import share.common.core.page.TableSupport;
import share.common.enums.DeviceOpSourceEnum;
import share.common.enums.DeviceType;
import share.common.enums.OpTypeEnum;
import share.common.utils.BaseUtil;
import share.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.utils.SecurityUtils;
import share.common.utils.bean.BeanUtils;
import share.system.domain.*;
import share.system.domain.vo.DeviceVo;
import share.system.domain.vo.SStoreVo;
import share.system.mapper.DeviceMapper;
import share.system.mapper.SRoomMapper;
import share.system.mapper.SStoreMapper;
......@@ -36,6 +30,11 @@ import share.system.service.DevicePasswordLogService;
import share.system.service.DeviceService;
import share.system.service.ISRoomService;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
/**
* 设备信息Service业务层处理
*
......@@ -44,6 +43,9 @@ import share.system.service.ISRoomService;
*/
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
private static final Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);
@Autowired
private DeviceMapper deviceMapper;
@Autowired
......@@ -198,11 +200,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean updateDeviceDoorLockPassword(Integer validTime) {
public boolean updateDeviceDoorLockPassword(Integer validTime, Long storeId) {
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(Device::getDevType, DeviceType.DEVICE_CCEE.getCode());
queryWrapper.isNotNull(Device::getRoomId);
queryWrapper.inSql(Device::getRoomId, "select id from s_room where room_type not in ('4', '5')");
queryWrapper.inSql(Device::getRoomId, "select id from s_room where room_type not in ('4', '5') and store_id = " + storeId);
List<Device> list = deviceMapper.selectList(queryWrapper);
if (list.size() > 0) {
// 默认15天
......@@ -233,6 +235,13 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
deviceOpService.setDevicePassword(list.get(i).getRoomId(), StrUtil.toString(passwordList[i]),
startTime, endTime, "13800000000", OpTypeEnum.OP_DEVICE_PASSWORD.getCode(),
DeviceOpSourceEnum.DEVICE_SOURCE_40.getCode());
// 延时执行操作
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
// e.printStackTrace();
logger.error("定期修改门锁设备的开锁密码线程中断:{}", e.getMessage());
}
}
// 修改房间门锁密码
roomService.updateBatchById(roomList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment