Commit e2bb6b23 by 吕明尚

更改Redis自动任务

parent c55716fa
...@@ -2,7 +2,6 @@ package share.web.controller.system; ...@@ -2,7 +2,6 @@ package share.web.controller.system;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.injector.methods.Insert;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -12,8 +11,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -12,8 +11,11 @@ import org.springframework.web.bind.annotation.RestController;
import share.common.core.domain.R; import share.common.core.domain.R;
import share.common.enums.ReceiptRdeisEnum; import share.common.enums.ReceiptRdeisEnum;
import share.system.domain.vo.SessionVo;
import share.system.service.QPService; import share.system.service.QPService;
import java.text.SimpleDateFormat;
@RestController @RestController
@RequestMapping("/chessCards") @RequestMapping("/chessCards")
...@@ -30,11 +32,8 @@ public class QPController { ...@@ -30,11 +32,8 @@ public class QPController {
} }
@GetMapping("/queryKey") @GetMapping("/queryKey")
public R<String> queryKey() { public R<SessionVo> queryKey() {
JSONObject o = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION.getValue()); return R.ok(qpService.queryKey());
Long expiresIn = (Long) o.get("expires_in");
Integer remainRefreshCount = (Integer) o.get("remain_refresh_count");
return R.ok(new JSONObject().set("expires_in", expiresIn).set("remain_refresh_count", remainRefreshCount).toString());
} }
} }
\ No newline at end of file
...@@ -181,9 +181,5 @@ public class SStoreController extends BaseController ...@@ -181,9 +181,5 @@ public class SStoreController extends BaseController
return toAjax(sStoreService.insertStoreConsumers(storeId, consumerIds)); return toAjax(sStoreService.insertStoreConsumers(storeId, consumerIds));
} }
/**
* 数据同步
*/
} }
...@@ -3,8 +3,8 @@ package share.common.enums; ...@@ -3,8 +3,8 @@ package share.common.enums;
public enum ReceiptRdeisEnum { public enum ReceiptRdeisEnum {
//1:验劵准备 2:session换取 //1:验劵准备 2:session换取
PREPARE(1, "TUANGOU.RECEIPT.PREPARE."), PREPARE(1, "TUANGOU.RECEIPT.PREPARE."),
SESSION(2, "MT_SESSION_KEY"), MT_SESSION_KEY(2, "MT_SESSION_KEY"),
MT_SESSION(3, "MT_SESSION_OBJECT_KEY"); MT_SESSION_OBJECT_KEY(3, "MT_SESSION_OBJECT_KEY");
private Integer code; private Integer code;
......
...@@ -43,13 +43,13 @@ public class RedisTask { ...@@ -43,13 +43,13 @@ public class RedisTask {
} }
public void AutomaticMtSessionKey() { public void AutomaticMtSessionKey() {
Boolean b = redisTemplate.hasKey(ReceiptRdeisEnum.SESSION.getValue()); Boolean b = redisTemplate.hasKey(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
if (!b) { if (!b) {
JSONObject o = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION.getValue()); JSONObject o = (JSONObject) redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue());
String refreshToken = (String) o.get("refresh_token"); String refreshToken = (String) o.get("refresh_token");
CustomerRefreshTokenResponse customerRefreshTokenResponse = qpService.refreshToken(refreshToken); CustomerRefreshTokenResponse customerRefreshTokenResponse = qpService.refreshToken(refreshToken);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION.getValue(), new JSONObject(customerRefreshTokenResponse)); redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), new JSONObject(customerRefreshTokenResponse));
redisTemplate.opsForValue().set(ReceiptRdeisEnum.SESSION.getValue(), new JSONObject(customerRefreshTokenResponse), customerRefreshTokenResponse.getExpires_in() - 60 * 30); redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), new JSONObject(customerRefreshTokenResponse), customerRefreshTokenResponse.getExpires_in() - 60 * 30);
} }
} }
} }
package share.system.domain.vo;
import lombok.Data;
@Data
public class SessionVo {
private long expiresIn;
private Integer remainRefreshCount;
private String expirationTime;
}
...@@ -14,14 +14,14 @@ public interface DeviceOpService { ...@@ -14,14 +14,14 @@ public interface DeviceOpService {
* 小程序订单开门 * 小程序订单开门
* @param deviceParam * @param deviceParam
*/ */
void openDoor(DeviceParamVo deviceParam, String userName); void openDoor(DeviceParamVo deviceParam);
/** /**
* 小程序订单开门 * 小程序订单开门
* @param roomId 房间id * @param roomId 房间id
* @param phone 操作用户 * @param phone 操作用户
*/ */
void openDoor(Long roomId, String phone, String userName); void openDoor(Long roomId, String phone);
/** /**
* 清除网关锁id列表 * 清除网关锁id列表
......
...@@ -95,4 +95,6 @@ public interface ISStoreService extends IService<SStore> ...@@ -95,4 +95,6 @@ public interface ISStoreService extends IService<SStore>
int insertStoreConsumers(Long storeId, Long[] consumerIds); int insertStoreConsumers(Long storeId, Long[] consumerIds);
List<SStore> listVoByCleaner(); List<SStore> listVoByCleaner();
int dataSync();
} }
package share.system.service; package share.system.service;
import com.dianping.openapi.sdk.api.customerauth.session.entity.CustomerKeyShopScopeResponseEntity;
import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse; import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse;
import com.dianping.openapi.sdk.api.tuangou.entity.*; import com.dianping.openapi.sdk.api.tuangou.entity.*;
import share.system.domain.vo.SessionVo;
import share.system.domain.vo.TuangouReceiptPrepareResponseEntityVo; import share.system.domain.vo.TuangouReceiptPrepareResponseEntityVo;
import java.util.List; import java.util.List;
...@@ -24,4 +26,8 @@ public interface QPService { ...@@ -24,4 +26,8 @@ public interface QPService {
List<TuangouDealQueryShopDealResponseEntity> queryshopdeal(String openShopUuid); List<TuangouDealQueryShopDealResponseEntity> queryshopdeal(String openShopUuid);
CustomerRefreshTokenResponse refreshToken(String newToken); CustomerRefreshTokenResponse refreshToken(String newToken);
SessionVo queryKey();
List<CustomerKeyShopScopeResponseEntity> scope();
} }
...@@ -40,7 +40,7 @@ public class DeviceOpServiceImpl implements DeviceOpService { ...@@ -40,7 +40,7 @@ public class DeviceOpServiceImpl implements DeviceOpService {
* 小程序订单开门 * 小程序订单开门
* @param deviceParam * @param deviceParam
*/ */
public void openDoor(DeviceParamVo deviceParam, String userName) { public void openDoor(DeviceParamVo deviceParam) {
SRoom room = roomMapper.selectSRoomById(deviceParam.getRoomId()); SRoom room = roomMapper.selectSRoomById(deviceParam.getRoomId());
if (room != null) { if (room != null) {
Device param = new Device(); Device param = new Device();
...@@ -49,11 +49,11 @@ public class DeviceOpServiceImpl implements DeviceOpService { ...@@ -49,11 +49,11 @@ public class DeviceOpServiceImpl implements DeviceOpService {
for (Device device : list) { for (Device device : list) {
if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) { if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) {
// 门锁 // 门锁
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "10", userName); this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "10");
} }
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) { if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关 // 取电开关
this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "20", userName); this.deviceOpInit(device.getDevId(), deviceParam.getPhone(), "20");
} }
} }
...@@ -65,7 +65,7 @@ public class DeviceOpServiceImpl implements DeviceOpService { ...@@ -65,7 +65,7 @@ public class DeviceOpServiceImpl implements DeviceOpService {
* @param roomId 房间id * @param roomId 房间id
* @param phone 操作用户 * @param phone 操作用户
*/ */
public void openDoor(Long roomId, String phone, String userName) { public void openDoor(Long roomId, String phone) {
SRoom room = roomMapper.selectSRoomById(roomId); SRoom room = roomMapper.selectSRoomById(roomId);
if (room != null) { if (room != null) {
Device param = new Device(); Device param = new Device();
...@@ -74,24 +74,24 @@ public class DeviceOpServiceImpl implements DeviceOpService { ...@@ -74,24 +74,24 @@ public class DeviceOpServiceImpl implements DeviceOpService {
for (Device device : list) { for (Device device : list) {
if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) { if (DeviceType.DEVICE_CCEE.getCode().equals(device.getDevType())) {
// 门锁 // 门锁
this.deviceOpInit(device.getDevId(), phone, "10", userName); this.deviceOpInit(device.getDevId(), phone, "10");
} }
if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) { if (DeviceType.DEVICE_0001.getCode().equals(device.getDevType())) {
// 取电开关 // 取电开关
this.deviceOpInit(device.getDevId(), phone, "20", userName); this.deviceOpInit(device.getDevId(), phone, "20");
} }
} }
} }
} }
private void deviceOpInit(String devId, String phone, String opType, String userName) { private void deviceOpInit(String devId, String phone, String opType) {
// 获取mqtt的topic、payload // 获取mqtt的topic、payload
MqttxVo mqttxVo = mqttxService.openOrCloseDevice(devId, phone, opType); MqttxVo mqttxVo = mqttxService.openOrCloseDevice(devId, phone, opType);
// 发送mqtt消息 // 发送mqtt消息
mqttGatewayComponent.sendToMqtt(mqttxVo.getTopic(), 0, mqttxVo.getPayload()); mqttGatewayComponent.sendToMqtt(mqttxVo.getTopic(), 0, mqttxVo.getPayload());
// 写日志记录 // 写日志记录
deviceLogService.addDeviceLog(mqttxVo, userName); deviceLogService.addDeviceLog(mqttxVo, phone);
} }
/** /**
......
...@@ -526,7 +526,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen ...@@ -526,7 +526,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
} }
} }
SConsumer user = FrontTokenComponent.getWxSConsumerEntry(); SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
deviceOpService.openDoor(sRoomVo.getId(), user.getPhone(), user.getNickName()); deviceOpService.openDoor(sRoomVo.getId(), user.getPhone());
return "开锁成功"; return "开锁成功";
} }
......
...@@ -234,7 +234,7 @@ public class SRoomServiceImpl extends ServiceImpl<SRoomMapper, SRoom> implements ...@@ -234,7 +234,7 @@ public class SRoomServiceImpl extends ServiceImpl<SRoomMapper, SRoom> implements
if (Objects.isNull(one)) { if (Objects.isNull(one)) {
throw new BaseException("设备不存在!"); throw new BaseException("设备不存在!");
} }
deviceOpService.openDoor(id, user.getPhone(), user.getNickName()); deviceOpService.openDoor(id, user.getPhone());
return "开锁成功"; return "开锁成功";
} }
......
...@@ -4,6 +4,8 @@ import java.util.*; ...@@ -4,6 +4,8 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dianping.openapi.sdk.api.customerauth.session.entity.CustomerKeyShopScopeResponseEntity;
import lombok.var;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.record.DVALRecord; import org.apache.poi.hssf.record.DVALRecord;
...@@ -29,6 +31,7 @@ import share.system.request.SStoreRequest; ...@@ -29,6 +31,7 @@ import share.system.request.SStoreRequest;
import share.system.service.IPackService; import share.system.service.IPackService;
import share.system.service.ISRoomService; import share.system.service.ISRoomService;
import share.system.service.ISStoreService; import share.system.service.ISStoreService;
import share.system.service.QPService;
/** /**
* 门店Service业务层处理 * 门店Service业务层处理
...@@ -48,6 +51,8 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme ...@@ -48,6 +51,8 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
private RoomPackMapper roomPackMapper; private RoomPackMapper roomPackMapper;
@Autowired @Autowired
private IPackService packService; private IPackService packService;
@Autowired
private QPService qpService;
/** /**
* 查询门店 * 查询门店
...@@ -280,6 +285,31 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme ...@@ -280,6 +285,31 @@ public class SStoreServiceImpl extends ServiceImpl<SStoreMapper, SStore> impleme
return storeList; return storeList;
} }
@Override
public int dataSync() {
List<SStore> sStores = sStoreMapper.selectSStoreList(new SStore());
//查询美团接口查看改门店是否存在
List<CustomerKeyShopScopeResponseEntity> scope = qpService.scope();
if (CollectionUtils.isEmpty(scope)) {
return 0; //美团接口查不到门店信息,直接返回0,不同步门店信息。
}
//获取差集
List<SStore> collect = sStores.stream().filter(item -> {
boolean flag = true;
for (CustomerKeyShopScopeResponseEntity entity : scope) {
if (item.getName().equals(entity.getShopname() + "(" + entity.getBranchname() + ")")) {
flag = false;
break;
}
}
return flag;
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
return collect.size();
}
return 0;
}
private List<Map> convertOptionList(List<SStore> storeList) { private List<Map> convertOptionList(List<SStore> storeList) {
List<Map> result = new ArrayList<>(); List<Map> result = new ArrayList<>();
if (CollectionUtils.isNotEmpty(storeList)) { if (CollectionUtils.isNotEmpty(storeList)) {
......
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