feat:预定广播
This commit is contained in:
1 parent
30ee1ed8e3
commit
4a70d142dd
11 files changed
+150
-90
No files matched your search
+2
-2
@@ -23,10 +23,10 @@ public class HardBroadcastEntity extends Model<HardBroadcastEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 编号
|
||||
* 广播编号
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "编号")
|
||||
@Schema(description = "广播编号")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.HardBroadcastDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardBroadcastEntity;
|
||||
@@ -15,7 +16,7 @@ public interface HardBroadcastService extends IService<HardBroadcastEntity> {
|
||||
/**
|
||||
* 添加线下食堂预约订单广播
|
||||
*/
|
||||
void addReserveOrderTask(HardOrderEntity orderdetail);
|
||||
void addReserveOrderTask(HardOrderEntity orderdetail, UserInfo userInfo);
|
||||
|
||||
/**
|
||||
* 完成硬件广播
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
@@ -92,5 +93,5 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
/**
|
||||
* 创建订单后发送mq消息
|
||||
*/
|
||||
void createOrderAfterSendMqMsg(Long orderId);
|
||||
void createOrderAfterSendMqMsg(Long orderId, UserInfo userInfo);
|
||||
}
|
||||
+43
-7
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.admin.api.utils.DataUtil;
|
||||
import com.bsd.pjcloud.admin.api.vo.UserVO;
|
||||
@@ -24,6 +25,9 @@ import com.bsd.pjcloud.hard.api.vo.HardBroadcastVo;
|
||||
import com.bsd.pjcloud.hard.mapper.HardBroadcastMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardBroadcastService;
|
||||
import com.bsd.pjcloud.mqtt.api.feign.RemoteMqttEventService;
|
||||
import com.bsd.pjcloud.mqtt.constant.MqttActionEnum;
|
||||
import com.bsd.pjcloud.mqtt.dto.hard.HardTakeFoodBroadcastMsg;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -47,6 +51,8 @@ public class HardBroadcastServiceImpl extends ServiceImpl<HardBroadcastMapper, H
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
private final RemoteMqttEventService remoteMqttEventService;
|
||||
|
||||
@Override
|
||||
public Page<HardBroadcastVo> scopePageJoin(Page page, HardBroadcastDto dto, DataScope dataScope) {
|
||||
Page<HardBroadcastVo> pageList = baseMapper.scopePageJoin(page, dto, dataScope);
|
||||
@@ -58,17 +64,17 @@ public class HardBroadcastServiceImpl extends ServiceImpl<HardBroadcastMapper, H
|
||||
* 添加线下食堂预约订单广播
|
||||
*/
|
||||
@Override
|
||||
public void addReserveOrderTask(HardOrderEntity orderdetail) {
|
||||
public void addReserveOrderTask(HardOrderEntity orderdetail, UserInfo userInfo) {
|
||||
if (ObjectUtil.isEmpty(orderdetail)) return;
|
||||
HardTypeEnum hardTypeEnum = HardTypeEnum.valueOfByType(orderdetail.getSysType());
|
||||
if (ObjectUtil.isEmpty(orderdetail)) {
|
||||
log.error("|{}|addReserveOrderTask发送mq消息失败,设备类型错误hardType不存在hardType|{}|", TAG, orderdetail.getSysType());
|
||||
log.error("|{}|发送线下订餐mq消息失败,设备类型错误hardType不存在hardType|{}|", TAG, orderdetail.getSysType());
|
||||
return;
|
||||
}
|
||||
if (ObjectUtil.notEqual(hardTypeEnum, HardTypeEnum.CANTEEN)) return;
|
||||
HardOrderTypeEnum hardOrderType = HardOrderTypeEnum.valueOfByType(orderdetail.getOrderType());
|
||||
if (ObjectUtil.isEmpty(hardOrderType)) {
|
||||
log.error("|{}|addReserveOrderTask发送mq消息失败,订餐类型错误hardType不存在hardType|{}|", TAG, orderdetail.getOrderType());
|
||||
log.error("|{}|发送线下订餐mq消息失败,订餐类型错误hardType不存在hardType|{}|", TAG, orderdetail.getOrderType());
|
||||
return;
|
||||
}
|
||||
if (ObjectUtil.notEqual(hardOrderType, HardOrderTypeEnum.RESERVE)) return;
|
||||
@@ -77,25 +83,55 @@ public class HardBroadcastServiceImpl extends ServiceImpl<HardBroadcastMapper, H
|
||||
.eq(HardBroadcastEntity::getBizId, orderdetail.getId())
|
||||
);
|
||||
if (ObjectUtil.isNotEmpty(broadcastDetail)) {
|
||||
log.error("|{}|addReserveOrderTask发送mq消息失败,广播已存在|{}|", TAG, orderdetail.getId());
|
||||
log.error("|{}|发送线下订餐mq消息失败,广播已存在|{}|", TAG, orderdetail.getId());
|
||||
return;
|
||||
}
|
||||
// 查询设备
|
||||
|
||||
HardManagerEntity hardDetail = hardManagerMapper.selectOne(new LambdaQueryWrapper<HardManagerEntity>()
|
||||
.eq(HardManagerEntity::getMerchantId, orderdetail.getMerchantId())
|
||||
.eq(HardManagerEntity::getIsTakeFood, YesNoEnum.YES.getCode())
|
||||
);
|
||||
if (ObjectUtil.isEmpty(hardDetail)) {
|
||||
log.error("|{}|发送线下订餐mq消息失败,默认订餐设备不存在|{}|", TAG, orderdetail.getId());
|
||||
return;
|
||||
}
|
||||
String content = "";
|
||||
String phone = userInfo.getSysUser().getPhone();
|
||||
if (ObjectUtil.isNotEmpty(phone) && phone.length() >= 4) {
|
||||
content = phone.substring(phone.length() - 4);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(content)) {
|
||||
log.error("|{}|发送线下订餐mq消息失败,生成发送消息错误|{}|", TAG, orderdetail.getId());
|
||||
return;
|
||||
}
|
||||
HardBroadcastEntity saveObj = HardBroadcastEntity.builder()
|
||||
.userId(orderdetail.getUserId())
|
||||
.hardId(orderdetail.getHardId())
|
||||
.topic("")
|
||||
.topic(hardDetail.getMainTopic())
|
||||
.bizType(HardBroadcastEnum.OFFLINE_CANTEEN_RESERVE.getType())
|
||||
.bizId(String.valueOf(orderdetail.getId()))
|
||||
.title(HardBroadcastEnum.OFFLINE_CANTEEN_RESERVE.getDescription())
|
||||
.content("")
|
||||
.content(content)
|
||||
.broadcastCount(0)
|
||||
.broadcastMaxCount(20)
|
||||
.isBroadcast(YesNoEnum.YES.getCode())
|
||||
.isDone(YesNoEnum.NO.getCode())
|
||||
.build();
|
||||
baseMapper.insert(saveObj);
|
||||
// 发送mq
|
||||
HardTakeFoodBroadcastMsg msg = new HardTakeFoodBroadcastMsg();
|
||||
msg.setTopic(saveObj.getTopic());
|
||||
msg.setAction(MqttActionEnum.TAKE_FOOD_BROADCAST);
|
||||
msg.setUserId(String.valueOf(userInfo.getSysUser().getUserId()));
|
||||
msg.setUserName(userInfo.getSysUser().getName());
|
||||
msg.setUserMobile(userInfo.getSysUser().getPhone());
|
||||
msg.setId(String.valueOf(saveObj.getId()));
|
||||
msg.setTitle(saveObj.getTitle());
|
||||
msg.setContent(saveObj.getContent());
|
||||
msg.setBroadcastMaxCount(saveObj.getBroadcastMaxCount());
|
||||
msg.setProductDesc(orderdetail.getProductDesc());
|
||||
msg.setPayPrice(orderdetail.getPayPrice());
|
||||
remoteMqttEventService.sendTakeFoodBroadcast(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-4
@@ -287,7 +287,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
// 钱包扣款
|
||||
if (isPay) getSelf().fastReduceBalance(orderObj);
|
||||
// 发送mq消息
|
||||
getSelf().createOrderAfterSendMqMsg(orderObj.getId());
|
||||
getSelf().createOrderAfterSendMqMsg(orderObj.getId(), userDetail);
|
||||
return orderObj.getId();
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
// 是否需要创建二维码
|
||||
getSelf().generateCode(orderObj);
|
||||
// 发送mq消息
|
||||
getSelf().createOrderAfterSendMqMsg(orderObj.getId());
|
||||
getSelf().createOrderAfterSendMqMsg(orderObj.getId(), userDetail);
|
||||
// 扣减库存
|
||||
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
|
||||
return orderObj.getId();
|
||||
@@ -719,7 +719,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
|
||||
// 发送mq消息
|
||||
@Override
|
||||
public void createOrderAfterSendMqMsg(Long orderId) {
|
||||
public void createOrderAfterSendMqMsg(Long orderId, UserInfo userInfo) {
|
||||
try {
|
||||
HardOrderEntity orderdetail = baseMapper.selectById(orderId);
|
||||
if (ObjectUtil.isEmpty(orderdetail)) {
|
||||
@@ -747,7 +747,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
// 发送订餐mq
|
||||
if (ObjectUtil.equals(hardOrderType, HardOrderTypeEnum.RESERVE)) {
|
||||
hardBroadcastService.addReserveOrderTask(orderdetail);
|
||||
hardBroadcastService.addReserveOrderTask(orderdetail, userInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -5,6 +5,7 @@ import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.mqtt.dto.MqttBaseDto;
|
||||
import com.bsd.pjcloud.mqtt.dto.hard.HardPrintMsg;
|
||||
import com.bsd.pjcloud.mqtt.dto.hard.HardTakeFoodBroadcastMsg;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -63,9 +64,16 @@ public interface RemoteMqttEventService {
|
||||
R<Boolean> sendFaceChangeMsg(@RequestParam Long userDeptId, @RequestParam Long userId, @RequestParam(required = false) Boolean isGlobalFace);
|
||||
|
||||
/**
|
||||
* 人脸变化
|
||||
* 打印机
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/mqtt/send-print")
|
||||
R<Boolean> sendPrint(@RequestBody HardPrintMsg dto);
|
||||
|
||||
/**
|
||||
* 订餐广播
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/mqtt/send-take-food-broadcast")
|
||||
R<Boolean> sendTakeFoodBroadcast(@RequestBody HardTakeFoodBroadcastMsg dto);
|
||||
}
|
||||
+1
@@ -16,6 +16,7 @@ public enum MqttActionEnum {
|
||||
SUPERMARKET_CLASSIFY("超市分类变化"),
|
||||
PRINT("打印变化"),
|
||||
FACE("人脸变化"),
|
||||
TAKE_FOOD_BROADCAST("定餐广播"),
|
||||
;
|
||||
private final String description;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.bsd.pjcloud.mqtt.dto.hard;
|
||||
|
||||
import com.bsd.pjcloud.mqtt.dto.MqttHardBaseMsg;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HardTakeFoodBroadcastMsg extends MqttHardBaseMsg {
|
||||
|
||||
/**
|
||||
* 发送硬件的topic
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
/**
|
||||
* 预定用户id
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 预定用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 预定用户手机号
|
||||
*/
|
||||
private String userMobile;
|
||||
|
||||
/**
|
||||
* 广播id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 预定标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 广播内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 最大广播次数
|
||||
*/
|
||||
private Integer broadcastMaxCount;
|
||||
|
||||
/**
|
||||
* 商品介绍
|
||||
*/
|
||||
private String productDesc;
|
||||
|
||||
/**
|
||||
* 支付价格
|
||||
*/
|
||||
private Integer payPrice;
|
||||
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
package com.bsd.pjcloud.mqtt.broadcast;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 硬件语音广播
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class BroadcastVideoService {
|
||||
|
||||
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
// 用于管理定时任务
|
||||
private ScheduledFuture<?> scheduledFuture;
|
||||
// 用于管理自动停止任务
|
||||
private ScheduledFuture<?> autoStopFuture;
|
||||
|
||||
private final int interval = 60;
|
||||
private final int autoInterval = 60 * 5;
|
||||
|
||||
/**
|
||||
* 启动广播
|
||||
*/
|
||||
public void startBroadcast() {
|
||||
if (scheduledFuture == null || scheduledFuture.isDone()) {
|
||||
scheduledFuture = executorService.scheduleAtFixedRate(() -> {
|
||||
playAudio();
|
||||
}, 0, interval, TimeUnit.SECONDS);
|
||||
log.info("广播已启动");
|
||||
startAutoStopTask();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止广播
|
||||
*/
|
||||
public void stopBroadcast() {
|
||||
if (scheduledFuture == null) return;
|
||||
scheduledFuture.cancel(false);
|
||||
scheduledFuture = null;
|
||||
if (autoStopFuture != null) {
|
||||
autoStopFuture.cancel(false);
|
||||
autoStopFuture = null;
|
||||
}
|
||||
log.info("广播已停止");
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动关闭广播任务
|
||||
*/
|
||||
private void startAutoStopTask() {
|
||||
autoStopFuture = executorService.schedule(() -> {
|
||||
if (scheduledFuture != null && !scheduledFuture.isDone()) {
|
||||
log.info("{}秒内未收到消息,自动停止广播", autoInterval);
|
||||
stopBroadcast();
|
||||
}
|
||||
}, autoInterval, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放音频
|
||||
*/
|
||||
private void playAudio() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -7,6 +7,7 @@ import com.bsd.pjcloud.mqtt.constant.MqttActionEnum;
|
||||
import com.bsd.pjcloud.mqtt.dto.MqttBaseDto;
|
||||
import com.bsd.pjcloud.mqtt.dto.hard.HardCustomerMsg;
|
||||
import com.bsd.pjcloud.mqtt.dto.hard.HardPrintMsg;
|
||||
import com.bsd.pjcloud.mqtt.dto.hard.HardTakeFoodBroadcastMsg;
|
||||
import com.bsd.pjcloud.mqtt.service.MqttEventService;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -133,4 +134,15 @@ public class MqttEventController {
|
||||
return R.ok(mqttEventService.defaultAction(mqttBaseDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订餐广播
|
||||
*/
|
||||
@Inner
|
||||
@PostMapping("/send-take-food-broadcast")
|
||||
public R<Boolean> sendTakeFoodBroadcast(@RequestBody HardTakeFoodBroadcastMsg dto) {
|
||||
MqttBaseDto mqttBaseDto = new MqttBaseDto();
|
||||
mqttBaseDto.setAction(dto.getAction());
|
||||
mqttBaseDto.setData(dto);
|
||||
return R.ok(mqttEventService.sendTakeFoodBroadcast(mqttBaseDto, dto.getTopic()));
|
||||
}
|
||||
}
|
||||
+16
@@ -39,4 +39,20 @@ public class MqttEventService {
|
||||
}
|
||||
dto.setHardGroupId(dept.getHardGroupId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 订餐广播
|
||||
*/
|
||||
public Boolean sendTakeFoodBroadcast(MqttBaseDto dto, String topic) {
|
||||
try {
|
||||
MqttHardBaseMsg msg = dto.getData();
|
||||
if (ObjectUtil.isEmpty(msg)) msg = new MqttHardBaseMsg();
|
||||
msg.setAction(dto.getAction());
|
||||
mqttService.publish(dto.getQos(), false, topic, JSON.toJSONString(msg));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|发送订餐广播失败dto:|{}|", TAG, JSON.toJSONString(dto), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user