目录
1. 需求分析
(1) 点击“确认挂号” 按钮,生成挂号订单,存入订单表
(2) 调用医院系统进行挂号确认,挂号成功需要更新订单表
(3) 挂号成功,更新号源信息,通知就诊人挂号成功 (异步MQ)
接口分析:
(1) 根据排班id查询相关信息
(2) 根据就诊人id查询就诊人的相关信息
2. 确认库表
设计表:故意添加冗余字段,保证读的效率,牺牲写的效率
3. 搭建订单模块 service_orders
- <dependencies>
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>service_cmn_clientartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
- dependencies>
application.properties
- # 服务端口
- server.port=8206
- # 服务名
- spring.application.name=service-orders
- # 环境设置:dev、test、prod
- spring.profiles.active=dev
-
- # mysql数据库连接
- spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
- spring.datasource.url=jdbc:mysql://localhost:3306/yygh_order?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
- spring.datasource.username=root
- spring.datasource.password=*******
-
- #返回json的全局时间格式
- spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
- spring.jackson.time-zone=GMT+8
- #mybatis日志
- mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
-
- # mongodb
- spring.data.mongodb.uri=mongodb://192.168.86.86:27017/test
-
- # nacos服务地址
- spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
-
- #rabbitmq地址
- #spring.rabbitmq.host=192.168.44.165
- #spring.rabbitmq.port=5672
- #spring.rabbitmq.username=guest
- #spring.rabbitmq.password=guest
-
gateway 添加路由
- #设置路由id
- spring.cloud.gateway.routes[6].id=service-orders
- #设置路由的uri
- spring.cloud.gateway.routes[6].uri=lb://service-orders
- #设置路由断言,代理servicerId为auth-service的/auth/路径
- spring.cloud.gateway.routes[6].predicates= Path=/*/order/**
启动类
- @SpringBootApplication
- @ComponentScan(basePackages = {"com.atguigu"})
- @EnableDiscoveryClient
- @EnableFeignClients(basePackages = {"com.atguigu"})
- @MapperScan("com.atguigu.yygh.order.mapper")
- public class ServiceOrderApplication {
- public static void main(String[] args) {
- SpringApplication.run(ServiceOrderApplication.class, args);
- }
- }
1. 分析接口
*参数:scheduleId、patientId
*返回值:orderId
2. controller
- @ApiOperation(value = "创建订单")
- @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
- public R submitOrder(@PathVariable String scheduleId,
- @PathVariable Long patientId) {
-
- Long orderId = orderService.saveOrder(scheduleId, patientId);
- return R.ok().data("orderId",orderId);
- }
3. service
- //创建订单
- @Override
- public Long saveOrder(String scheduleId, Long patientId) {
- //1.根据patientId 跨模块查询就诊人信息
- //2.跨模块查询医院排班信息(医院、科室、排班、预约规则) scheduleId
- //3.整合数据,创建订单,插入数据库
- //4.调用医院系统进行挂号确认
- //5.TODO 发送MQ消息通知就诊人,更新号源
- return null;
- }
(1). 分析接口
*参数:patientId
*返回值:patient
(2). PatientApiController
- @ApiOperation(value = "获取就诊人(远程调用)")
- @GetMapping("inner/get/{id}")
- public Patient getPatientOrder(
- @PathVariable("id") Long id) {
- //模块间调用,不需要翻译字段
- Patient patient = patientService.getById(id);
- return patient;
- }
(3). 创建user模块远程调用接口
搭建service_user_client模块
- @FeignClient(value = "service-user")
- @Repository
- public interface PatientFeignClient {
- //获取就诊人,注意@PathVariable("id")不能省略,路径必须完整
- @GetMapping("/api/user/patient/inner/get/{id}")
- Patient getPatientOrder(@PathVariable("id") Long id);
- }
(1). 分析接口:
*参数:scheduleId
*返回值:ScheduleOrderVo
(2). HospitalApiController
- @ApiOperation(value = "根据排班id获取预约下单数据")
- @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
- public ScheduleOrderVo getScheduleOrderVo(
- @PathVariable("scheduleId") String scheduleId) {
- ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
- return scheduleOrderVo;
- }
(3). service
- //根据排班id获取预约下单数据
- @Override
- public ScheduleOrderVo getScheduleOrderVo(String scheduleId) {
- //1.根据排班id获取排班信息
- Schedule schedule = scheduleRepository.findById(scheduleId).get();
- if(schedule==null){
- throw new YyghException(20001,"排班信息有误");
- }
-
- //2.根据hoscode查询医院信息
- String hoscode = schedule.getHoscode();
- Hospital hospital = hospitalService.getHospital(hoscode);
- if(hospital==null){
- throw new YyghException(20001,"医院信息有误");
- }
-
- //3.从医院信息中取出预约规则
- BookingRule bookingRule = hospital.getBookingRule();
-
- //4.封装基础数据
- ScheduleOrderVo scheduleOrderVo = new ScheduleOrderVo();
- scheduleOrderVo.setHoscode(hospital.getHoscode());
- scheduleOrderVo.setHosname(hospital.getHosname());
-
- scheduleOrderVo.setDepcode(schedule.getDepcode());
- scheduleOrderVo.setDepname(departmentService.getDepartment(schedule.getHoscode(), schedule.getDepcode()).getDepname());
- scheduleOrderVo.setHosScheduleId(schedule.getHosScheduleId());
- scheduleOrderVo.setAvailableNumber(schedule.getAvailableNumber());
- scheduleOrderVo.setTitle(schedule.getTitle());
- scheduleOrderVo.setReserveDate(schedule.getWorkDate());
- scheduleOrderVo.setReserveTime(schedule.getWorkTime());
- scheduleOrderVo.setAmount(schedule.getAmount());
-
- //5.封装根据预约规则推算的时间信息
- //5.1推算可以退号的截止日期+时间
- //退号截止天数(如:就诊前一天为-1,当天为0)
- DateTime quitDate = new DateTime(schedule.getWorkDate())
- .plusDays(bookingRule.getQuitDay()); //plusDays 负数,往回推算
- //日期+时间拼装
- DateTime quitDateTime = this.getDateTime(quitDate.toDate(), bookingRule.getQuitTime());
- scheduleOrderVo.setQuitTime(quitDateTime.toDate());
-
- //预约开始时间
- DateTime startTime = this.getDateTime(new Date(), bookingRule.getReleaseTime());
- scheduleOrderVo.setStartTime(startTime.toDate());
-
- //预约截止时间
- DateTime endTime = this.getDateTime(
- new DateTime().plusDays(bookingRule.getCycle()).toDate(),
- bookingRule.getStopTime());
- scheduleOrderVo.setEndTime(endTime.toDate());
-
- //当天停止挂号时间
- DateTime stopTime = this.getDateTime(new Date(), bookingRule.getStopTime());
- scheduleOrderVo.setStartTime(startTime.toDate());
-
- return scheduleOrderVo;
- }
(4). 创建远程调用接口
搭建service_hosp_client
- @FeignClient(value = "service-hosp")
- @Repository
- public interface HospitalFeignClient {
- //根据排班id获取预约下单数据
- @GetMapping("/api/hosp/hospital/inner/getScheduleOrderVo/{scheduleId}")
- ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId);
-
- }
1. 准备工作
(1). 确认启动类注解 @EnableFeignClients
(2). 引入相关模块依赖
- <dependencies>
-
- <dependency>
- <groupId>joda-timegroupId>
- <artifactId>joda-timeartifactId>
- dependency>
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>service_cmn_clientartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>service_hosp_clientartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>service_user_clientartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
- dependencies>
(3). 封装工具类
(4). 省略签名校验,注释掉医院平台放校验代码
如果是Mysql5.5,添加自动填充
2. service
- @Service
- public class OrderServiceImpl
- extends ServiceImpl
implements OrderService { -
- @Autowired
- private PatientFeignClient patientFeignClient;
- @Autowired
- private HospitalFeignClient hospitalFeignClient;
-
- //创建订单
- @Override
- public Long saveOrder(String scheduleId, Long patientId) {
- //1.根据patientId 跨模块查询就诊人信息
- Patient patient = patientFeignClient.getPatientOrder(patientId);
- if(patient==null){
- throw new YyghException(20001,"获取就诊人信息有误");
- }
-
- //2.跨模块查询医院排班信息(医院、科室、排班、预约规则) scheduleId
- ScheduleOrderVo scheduleOrderVo = hospitalFeignClient.getScheduleOrderVo(scheduleId);
- if(scheduleOrderVo==null){
- throw new YyghException(20001,"获取排班相关信息有误");
- }
-
- //2.1 创建订单前,时间合法性校验 (大于开始时间 小于结束时间)
- if(new DateTime(scheduleOrderVo.getStartTime()).isAfterNow() ||
- new DateTime(scheduleOrderVo.getEndTime()).isBeforeNow()){
- throw new YyghException(20001,"未到挂号时间");
- }
- //2.2 确认是否有号源
- if(scheduleOrderVo.getAvailableNumber()<=0){
- throw new YyghException(20001,"号源已挂满");
- }
-
- //3.整合数据,创建订单,插入数据库
- OrderInfo orderInfo = new OrderInfo();
- BeanUtils.copyProperties(scheduleOrderVo, orderInfo);
- String outTradeNo = System.currentTimeMillis() + ""+ new Random().nextInt(100);
- orderInfo.setOutTradeNo(outTradeNo);
-
- orderInfo.setUserId(patient.getUserId());
- orderInfo.setPatientId(patientId);
- orderInfo.setPatientName(patient.getName());
- orderInfo.setPatientPhone(patient.getPhone());
- orderInfo.setOrderStatus(OrderStatusEnum.UNPAID.getStatus());
- this.save(orderInfo);
-
- //4.调用医院系统进行挂号确认 (参考API接口文档)
- //4.1封装调用医院接口参数
- Map
paramMap = new HashMap<>(); - paramMap.put("hoscode",orderInfo.getHoscode());
- paramMap.put("depcode",orderInfo.getDepcode());
- paramMap.put("hosScheduleId",orderInfo.getHosScheduleId());
- paramMap.put("reserveDate",new DateTime(orderInfo.getReserveDate()).toString("yyyy-MM-dd"));
- paramMap.put("reserveTime", orderInfo.getReserveTime());
- paramMap.put("amount",orderInfo.getAmount());
- paramMap.put("name", patient.getName());
- paramMap.put("certificatesType",patient.getCertificatesType());
- paramMap.put("certificatesNo", patient.getCertificatesNo());
- paramMap.put("sex",patient.getSex());
- paramMap.put("birthdate", patient.getBirthdate());
- paramMap.put("phone",patient.getPhone());
- paramMap.put("isMarry", patient.getIsMarry());
- paramMap.put("provinceCode",patient.getProvinceCode());
- paramMap.put("cityCode", patient.getCityCode());
- paramMap.put("districtCode",patient.getDistrictCode());
- paramMap.put("address",patient.getAddress());
- //联系人
- paramMap.put("contactsName",patient.getContactsName());
- paramMap.put("contactsCertificatesType", patient.getContactsCertificatesType());
- paramMap.put("contactsCertificatesNo",patient.getContactsCertificatesNo());
- paramMap.put("contactsPhone",patient.getContactsPhone());
- paramMap.put("timestamp", HttpRequestHelper.getTimestamp());
- //MD5加密签名校验,省略
- paramMap.put("sign", "");
-
- //4.2通过工具发送请求,获取响应
- JSONObject result = HttpRequestHelper.sendRequest(
- paramMap, "http://localhost:9998/order/submitOrder");
- //4.3判断挂号确认是否成功
- if(result.getInteger("code") == 200){ //ResultCodeEnum.SUCCESS 200
-
- //4.4取出返回结果,更新订单信息
- JSONObject jsonObject = result.getJSONObject("data");
- //预约记录唯一标识(医院预约记录主键)
- String hosRecordId = jsonObject.getString("hosRecordId");
- //预约序号
- Integer number = jsonObject.getInteger("number");;
- //取号时间
- String fetchTime = jsonObject.getString("fetchTime");;
- //取号地址
- String fetchAddress = jsonObject.getString("fetchAddress");;
- //更新订单
- orderInfo.setHosRecordId(hosRecordId);
- orderInfo.setNumber(number);
- orderInfo.setFetchTime(fetchTime);
- orderInfo.setFetchAddress(fetchAddress);
- baseMapper.updateById(orderInfo);
-
- //排班可预约数
- Integer reservedNumber = jsonObject.getInteger("reservedNumber");
- //排班剩余预约数
- Integer availableNumber = jsonObject.getInteger("availableNumber");
-
- //5.TODO 发送MQ消息通知就诊人,更新号源
-
- }else {
- throw new YyghException(20001,"确认挂号失败");
- }
- return orderInfo.getId();
- }
- }
1. 确认入口
2. 创建 api/orderinfo.js
- import request from '@/utils/request'
-
- const api_name = `/api/order/orderInfo`
-
- export default {
- submitOrder(scheduleId, patientId) {
- return request({
- url: `${api_name}/auth/submitOrder/${scheduleId}/${patientId}`,
- method: 'post'
- })
- }
- }
3. 实现JS方法
booking.vue
- import orderinfoApi from '@/api/orderinfo'
-
- ...
- //确认挂号
- submitOrder() {
- //校验就诊人id
- if (this.patient.id == null) {
- this.$message.error('请选择就诊人')
- return
- }
- // 防止重复提交
- if (this.submitBnt == '正在提交...') {
- this.$message.error('重复提交')
- return
- }
- this.submitBnt = '正在提交...'
- orderinfoApi.submitOrder(this.scheduleId, this.patient.id)
- .then(response => {
- let orderId = response.data.orderId
- window.location.href = '/order/show?orderId=' + orderId
- }).catch(e => {
- this.submitBnt = '确认挂号'
- })
- },
4. 测试
503 访问不到服务 Nacos 配置错误,服务名错误
削峰填谷:异步处理、流量消峰
#拉取镜像
docker pull rabbitmq:management#创建容器启动
docker run -d --restart=always -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq:management
访问:http://192.168.86.86:15672/
默认用户名密码:guest
在common搭建rabbit_util模块,引入依赖
- <dependencies>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-actuatorartifactId>
- dependency>
- <dependency>
- <groupId>org.springframework.cloudgroupId>
- <artifactId>spring-cloud-starter-bus-amqpartifactId>
- dependency>
- <dependency>
- <groupId>com.alibabagroupId>
- <artifactId>fastjsonartifactId>
- dependency>
- dependencies>
添加service方法
- @Service
- public class RabbitService {
- @Autowired
- private RabbitTemplate rabbitTemplate;
- /**
- * 发送消息
- * @param exchange 交换机
- * @param routingKey 路由键
- * @param message 消息
- */
- public boolean sendMessage(String exchange, String routingKey, Object message) {
- rabbitTemplate.convertAndSend(exchange, routingKey, message);
- return true;
- }
- }
配置mq消息转换器 默认是字符串转换器
- @Configuration
- public class MQConfig {
- @Bean
- public MessageConverter messageConverter(){
- return new Jackson2JsonMessageConverter();
- }
- }
添加常量类
- public class MqConst {
- /**
- * 预约下单
- */
- public static final String EXCHANGE_DIRECT_ORDER = "exchange.direct.order";
- public static final String ROUTING_ORDER = "order";
- //队列
- public static final String QUEUE_ORDER = "queue.order";
-
- /**
- * 短信
- */
- public static final String EXCHANGE_DIRECT_MSM = "exchange.direct.msm";
- public static final String ROUTING_MSM_ITEM = "msm.item";
- //队列
- public static final String QUEUE_MSM_ITEM = "queue.msm.item";
- }
1. service_msm引入依赖
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>rabbit_utilartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
2. 添加mq配置信息
- #rabbitmq地址
- spring.rabbitmq.host=192.168.86.86
- spring.rabbitmq.port=5672
- spring.rabbitmq.username=guest
- spring.rabbitmq.password=guest
3. 确认实体
4. service 新增短信发送方法
阿里云短信服务 营销签名、模板申请不下来,用发送验证码模拟
- //发送挂号成功短信
- boolean send(MsmVo msmVo);
-
- //发送挂号成功短信
- @Override
- public boolean send(MsmVo msmVo) {
- String phone = msmVo.getPhone();
- String templateCode = msmVo.getTemplateCode();
- Map
param = msmVo.getParam(); - //模拟发送
- String code = RandomUtil.getFourBitRandom();
- Map
paramMap = new HashMap<>(); - paramMap.put("code",code);
- boolean isSend = this.send(phone, paramMap);
- return isSend;
- }
5. 创建rabbit监听器
receiver.SmsReceiver
- @Component
- public class SmsReceiver {
- @Autowired
- private MsmService msmService;
- //指定队列、交换机、路由key
- @RabbitListener(bindings = @QueueBinding(
- value = @Queue(value = MqConst.QUEUE_MSM_ITEM, durable = "true"),
- exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_MSM),
- key = {MqConst.ROUTING_MSM_ITEM}
- ))
- public void send(MsmVo msmVo, Message message, Channel channel) {
- msmService.send(msmVo);
- }
- }
1. hosp 引入依赖
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>rabbit_utilartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
2. 添加rabbit配置
- #rabbitmq地址
- spring.rabbitmq.host=192.168.86.86
- spring.rabbitmq.port=5672
- spring.rabbitmq.username=guest
- spring.rabbitmq.password=guest
-
- #redis
- spring.redis.host=192.168.86.86
- spring.redis.port=6379
- spring.redis.database= 0
- spring.redis.timeout=1800000
启动,radis报错
rabbit 触发了redis自动配置类,所以还需添加redis相关配置 (或启动类进行排除)
3. 确认实体
4. 实现服务接口
ScheduleService 新增方法
- //修改排班
- void update(Schedule schedule);
- //根据医院编码、医院排班id获取排班信息
- Schedule getScheduleByIds(String hoscode, String scheduleId);
-
- //修改排班
- @Override
- public void update(Schedule schedule) {
- scheduleRepository.save(schedule);
- }
- //根据医院编码、医院排班id获取排班信息
- @Override
- public Schedule getScheduleByIds(String hoscode, String scheduleId) {
- Schedule schedule = scheduleRepository.getByHoscodeAndHosScheduleId(hoscode, scheduleId);
- return schedule;
- }
-
5. 创建监听器
receiver.HospitalReceiver
- @Component
- public class HospitalReceiver {
- @Autowired
- private ScheduleService scheduleService;
- @Autowired
- private RabbitService rabbitService;
- @RabbitListener(bindings = @QueueBinding(
- value = @Queue(value = MqConst.QUEUE_ORDER, durable = "true"),
- exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_ORDER),
- key = {MqConst.ROUTING_ORDER}
- ))
- public void receiver(OrderMqVo orderMqVo, Message message, Channel channel) throws IOException {
- //1.取出参数
- String hoscode = orderMqVo.getHoscode();
- String hosScheduleId = orderMqVo.getScheduleId();
- Integer reservedNumber = orderMqVo.getReservedNumber();
- Integer availableNumber = orderMqVo.getAvailableNumber();
- MsmVo msmVo = orderMqVo.getMsmVo();
-
- //2.根据参数查询排班信息
- Schedule schedule = scheduleService.getScheduleByIds(hoscode, hosScheduleId);
-
- //3.更新排班信息
- schedule.setReservedNumber(reservedNumber);
- schedule.setAvailableNumber(availableNumber);
- schedule.setUpdateTime(new Date()); //MongoDB不会自动更新时间
- scheduleService.update(schedule);
-
- //4.发送短信相关MQ消息
- if(msmVo!=null){
- rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MSM, MqConst.ROUTING_MSM_ITEM, msmVo);
- }
- }
- }
1. orders 模块引入依赖
- <dependency>
- <groupId>com.atguigugroupId>
- <artifactId>rabbit_utilartifactId>
- <version>0.0.1-SNAPSHOTversion>
- dependency>
2. orders 模块引入配置
- #rabbitmq地址
- spring.rabbitmq.host=192.168.86.86
- spring.rabbitmq.port=5672
- spring.rabbitmq.username=guest
- spring.rabbitmq.password=guest
-
- #redis
- spring.redis.host=192.168.86.86
- spring.redis.port=6379
- spring.redis.database= 0
- spring.redis.timeout=1800000
3. 补全接口
发送MQ消息通知就诊人,更新号源信息
- //创建订单
- @Override
- public Long saveOrder(String scheduleId, Long patientId) {
- //1.根据patientId 跨模块查询就诊人信息
- Patient patient = patientFeignClient.getPatientOrder(patientId);
- if(patient==null){
- throw new YyghException(20001,"获取就诊人信息有误");
- }
-
- //2.跨模块查询医院排班信息(医院、科室、排班、预约规则) scheduleId
- ScheduleOrderVo scheduleOrderVo = hospitalFeignClient.getScheduleOrderVo(scheduleId);
- if(scheduleOrderVo==null){
- throw new YyghException(20001,"获取排班相关信息有误");
- }
-
- //2.1 创建订单前,时间合法性校验 (大于开始时间 小于结束时间)
- if(new DateTime(scheduleOrderVo.getStartTime()).isAfterNow() ||
- new DateTime(scheduleOrderVo.getEndTime()).isBeforeNow()){
- throw new YyghException(20001,"未到挂号时间");
- }
- //2.2 确认是否有号源
- if(scheduleOrderVo.getAvailableNumber()<=0){
- throw new YyghException(20001,"号源已挂满");
- }
-
- //3.整合数据,创建订单,插入数据库
- OrderInfo orderInfo = new OrderInfo();
- BeanUtils.copyProperties(scheduleOrderVo, orderInfo);
- String outTradeNo = System.currentTimeMillis() + ""+ new Random().nextInt(100);
- orderInfo.setOutTradeNo(outTradeNo);
-
- orderInfo.setUserId(patient.getUserId());
- orderInfo.setPatientId(patientId);
- orderInfo.setPatientName(patient.getName());
- orderInfo.setPatientPhone(patient.getPhone());
- orderInfo.setOrderStatus(OrderStatusEnum.UNPAID.getStatus());
- this.save(orderInfo);
-
- //4.调用医院系统进行挂号确认 (参考API接口文档)
- //4.1封装调用医院接口参数
- Map
paramMap = new HashMap<>(); - paramMap.put("hoscode",orderInfo.getHoscode());
- paramMap.put("depcode",orderInfo.getDepcode());
- paramMap.put("hosScheduleId",orderInfo.getHosScheduleId());
- paramMap.put("reserveDate",new DateTime(orderInfo.getReserveDate()).toString("yyyy-MM-dd"));
- paramMap.put("reserveTime", orderInfo.getReserveTime());
- paramMap.put("amount",orderInfo.getAmount());
- paramMap.put("name", patient.getName());
- paramMap.put("certificatesType",patient.getCertificatesType());
- paramMap.put("certificatesNo", patient.getCertificatesNo());
- paramMap.put("sex",patient.getSex());
- paramMap.put("birthdate", patient.getBirthdate());
- paramMap.put("phone",patient.getPhone());
- paramMap.put("isMarry", patient.getIsMarry());
- paramMap.put("provinceCode",patient.getProvinceCode());
- paramMap.put("cityCode", patient.getCityCode());
- paramMap.put("districtCode",patient.getDistrictCode());
- paramMap.put("address",patient.getAddress());
- //联系人
- paramMap.put("contactsName",patient.getContactsName());
- paramMap.put("contactsCertificatesType", patient.getContactsCertificatesType());
- paramMap.put("contactsCertificatesNo",patient.getContactsCertificatesNo());
- paramMap.put("contactsPhone",patient.getContactsPhone());
- paramMap.put("timestamp", HttpRequestHelper.getTimestamp());
- //MD5加密签名校验,省略
- paramMap.put("sign", "");
-
- //4.2通过工具发送请求,获取响应
- JSONObject result = HttpRequestHelper.sendRequest(
- paramMap, "http://localhost:9998/order/submitOrder");
- //4.3判断挂号确认是否成功
- if(result.getInteger("code") == 200){ //ResultCodeEnum.SUCCESS 200
-
- //4.4取出返回结果,更新订单信息
- JSONObject jsonObject = result.getJSONObject("data");
- //预约记录唯一标识(医院预约记录主键)
- String hosRecordId = jsonObject.getString("hosRecordId");
- //预约序号
- Integer number = jsonObject.getInteger("number");;
- //取号时间
- String fetchTime = jsonObject.getString("fetchTime");;
- //取号地址
- String fetchAddress = jsonObject.getString("fetchAddress");;
- //更新订单
- orderInfo.setHosRecordId(hosRecordId);
- orderInfo.setNumber(number);
- orderInfo.setFetchTime(fetchTime);
- orderInfo.setFetchAddress(fetchAddress);
- baseMapper.updateById(orderInfo);
-
- //排班可预约数
- Integer reservedNumber = jsonObject.getInteger("reservedNumber");
- //排班剩余预约数
- Integer availableNumber = jsonObject.getInteger("availableNumber");
-
- //5.TODO 发送MQ消息通知就诊人,更新号源
- //发送mq信息更新号源和短信通知
- OrderMqVo orderMqVo = new OrderMqVo();
- orderMqVo.setHoscode(orderInfo.getHoscode());
- orderMqVo.setScheduleId(orderInfo.getHosScheduleId());
- orderMqVo.setReservedNumber(reservedNumber);
- orderMqVo.setAvailableNumber(availableNumber);
-
- //短信提示
- MsmVo msmVo = new MsmVo();
- msmVo.setPhone(orderInfo.getPatientPhone());
- String reserveDate =
- new DateTime(orderInfo.getReserveDate()).toString("yyyy-MM-dd")
- + (orderInfo.getReserveTime()==0 ? "上午": "下午");
- Map
param = new HashMap(){{ - put("title", orderInfo.getHosname()+"|"+orderInfo.getDepname()+"|"+orderInfo.getTitle());
- put("amount", orderInfo.getAmount());
- put("reserveDate", reserveDate);
- put("name", orderInfo.getPatientName());
- put("quitTime", new DateTime(orderInfo.getQuitTime()).toString("yyyy-MM-dd HH:mm"));
- }};
- msmVo.setParam(param);
-
- orderMqVo.setMsmVo(msmVo);
- //发送消息到队列,更新号源,发送短信
- rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_ORDER, MqConst.ROUTING_ORDER, orderMqVo);
-
- }else {
- throw new YyghException(20001,"确认挂号失败");
- }
- return orderInfo.getId();
- }
4. 重新提交订单测试,收到短信