Commit 1ef0ce55 by 赵剑炜

添加远程开门的消息队列

parent 4045ad56
......@@ -10,4 +10,5 @@ public class OpenDoorReq {
private String userId;
private String userName;
private String open;
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.List;
@RestController
......@@ -47,7 +48,7 @@ public class WarehouseController {
@PostMapping(path="/OpenDoor",name="远程开门#logType=30")
@ApiOperation("远程开门")
public ApiRes<String> OpenDoor(@RequestBody @Validated(ValidationApi.add.class) OpenDoorReq req) {
public ApiRes<String> OpenDoor(@RequestBody @Validated(ValidationApi.add.class) OpenDoorReq req) throws UnsupportedEncodingException {
return ApiRes.success(warehouseService.OpenDoor(req));
}
......
......@@ -17,6 +17,7 @@ import com.junmp.jyzb.entity.Warehouse;
import com.junmp.jyzb.utils.ResponseResult;
import com.junmp.v2.db.api.page.PageResult;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
......@@ -40,7 +41,7 @@ public interface WarehouseService extends IService<Warehouse> {
*
* @param req
*/
String OpenDoor(OpenDoorReq req);
String OpenDoor(OpenDoorReq req) throws UnsupportedEncodingException;
/**
* 查询单个仓库信息
*
......
......@@ -30,6 +30,7 @@ import com.junmp.jyzb.mapper.*;
import com.junmp.jyzb.service.PubOrgService;
import com.junmp.jyzb.service.WarehouseService;
import com.junmp.jyzb.utils.*;
import com.junmp.v2.auth.api.context.LoginContext;
import com.junmp.v2.common.exception.base.ServiceException;
import com.junmp.v2.common.util.BeanPlusUtil;
import com.junmp.v2.common.util.HttpServletUtil;
......@@ -38,7 +39,13 @@ import com.junmp.v2.db.api.factory.PageResultFactory;
import com.junmp.v2.db.api.page.PageResult;
import com.junmp.v2.office.api.OfficeExcelApi;
import com.junmp.v2.office.api.bean.ExcelExportParam;
import com.junmp.v2.sys.user.entity.SysUser;
import com.junmp.v2.sys.user.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -46,6 +53,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -71,8 +79,13 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper,Warehouse>
private DeviceRedisCache redisCache;
@Resource
private OfficeExcelApi officeExcelApi;
@Resource
private RabbitAdmin rabbitAdmin;
@Resource
private RabbitTemplate rabbitTemplate;
@Resource
private SysUserService sysUserService;
@Override
......@@ -115,7 +128,27 @@ public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper,Warehouse>
}
@Override
public String OpenDoor(OpenDoorReq req) {
public String OpenDoor(OpenDoorReq req) throws UnsupportedEncodingException {
if (ObjectUtil.isNull(req.getUserId()) ) {
// 人员信息没有传入,从上下文获取当前登录用户并设置到请求对象中
SysUser StartUser= sysUserService.getById(LoginContext.getContext().getLoginUser());
req.setUserId(String.valueOf(StartUser.getUserId()));
req.setUserName(StartUser.getRealName());
}
// 将请求对象序列化为JSON字符串
String jsonString = JSON.toJSONString(req);
// 创建广播交换器
FanoutExchange exchange = new FanoutExchange ("DeviceControl");
String exchangeName="DeviceControl";
rabbitAdmin.declareExchange(exchange);
// 将消息体封装到Message对象中
Message message = MessageBuilder.withBody(jsonString.getBytes())
.setExpiration("10000") // 设置消息的过期时间为10秒
.build();
// 发送消息到RabbitMQ
rabbitTemplate.convertAndSend(exchangeName, req.getWarehouseId(), message);
return null;
}
......
......@@ -25,11 +25,11 @@ public class RabbitMQSendMsg {
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(name).noargs());
String jsonString = JSON.toJSONString(msg);
// // 创建 MessageProperties 对象,并设置 TTL
//// // 创建 MessageProperties 对象,并设置 TTL
// MessageProperties messageProperties = new MessageProperties();
// messageProperties.setExpiration(String.valueOf(ttlMillis));
//
// // 发送带有 TTL 的消息
// messageProperties.setExpiration(String.valueOf(10));
////
//// // 发送带有 TTL 的消息
// rabbitTemplate.send(exchangeName, name, new Message(jsonString.getBytes(), messageProperties));
rabbitTemplate.convertAndSend(exchangeName, name, jsonString);
}
......
......@@ -99,9 +99,9 @@ public class WarehouseWebSocketServer implements WebSocketServerListener {
redisCache.put(channel, orgId);
}
//推送消息到对应组织机构
TopicExchange exchange = new TopicExchange("DevMonitorMsg");
TopicExchange exchange = new TopicExchange("topicExchange");
rabbitAdmin.declareExchange(exchange);
String exchangeName="DevMonitorMsg";
String exchangeName="topicExchange";
rabbitTemplate.convertAndSend(exchangeName, orgId, "设备上线");
protocol.response("true");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论