排期接口,价格接口

排期接口,价格接口

准备物料:

1.排期接口,价格接口
2.微服务工程scheduler-provider
3.根据"商品ID查询商品排期接口"业务和根据"商品排期查询商品价格接口"业务的sql语句实现:
SELECT * FROM dm_item WHERE id = 5;
SELECT * FROM dm_scheduler WHERE itemId = 5;
SELECT * FROM dm_scheduler_seat_price WHERE scheduleId = 12700;
SELECT * FROM dm_scheduler_seat WHERE scheduleId = 12700 AND STATUS = 1;
2.参看排期页面

https://piao.damai.cn/178499.html?spm=a2oeg.home.card_1.ditem_1.26c623e1ckkVsa

3.业务实现:

(1)根据商品ID查询商品排期接口
(2)根据商品排期查询商品价格接口

4.具体实现
(1).实现根据商品ID查询商品排期接口

思路1:定位dm-item-consumer微服务工程
思路2:入口为商品itemId,出口为商品排期集合Dto<List> (vo中包含两张表:dm_item,dm_scheduler)
思路3:定位dm_scheduler排期库中的dm_scheduler表
思路4:组装VOList(itemSchedulerVoList)

步骤1:

*********dm-item-consumer/ItemDetailService*********
    /**
     * 根据商品ID查询排期
     * @param itemId
     * @return
     * @throws Exception
     */
    public Dto<List<ItemSchedulerVo>> queryItemScheduler(Long itemId)throws Exception;
步骤2:
*********dm-item-consumer/ItemDetailServiceImpl*********
附注:(dm-item-consumer\src\main\java\cn\dm\exception加入字符串常量ItemErrorCode.java)

public class ItemDetailServiceImpl implements ItemDetailService {
    //引入
    @Autowired
    private RestDmSchedulerClient restDmSchedulerClient;

	@Override
    public Dto<List<ItemSchedulerVo>> queryItemScheduler(Long id) throws Exception {
        //1.根据商品id查询商品对象信息
        DmItem dmItem = dmItemClient.getDmItemById(id);
	//2.商品对象信息判空校验
        if (EmptyUtils.isEmpty(dmItem)) {
            throw new BaseException(ItemErrorCode.ITEM_NO_DATA);
        }
        //3.根据商品id查询排期对象信息集合
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("itemId", dmItem.getId());
        List<DmScheduler> dmSchedulerList = restDmSchedulerClient.getDmSchedulerListByMap(param);
	//4.排期对象信息判空校验
        if (EmptyUtils.isEmpty(dmSchedulerList)) {
            throw new BaseException(ItemErrorCode.ITEM_NO_DATA);
        }
        //5.组装VOList(itemSchedulerVoList)
        List<ItemSchedulerVo> itemSchedulerVoList = new ArrayList<ItemSchedulerVo>();
        for (int i = 0; i < dmSchedulerList.size(); i++) {
            ItemSchedulerVo itemSchedulerVo = new ItemSchedulerVo();
            BeanUtils.copyProperties(dmItem, itemSchedulerVo);
            BeanUtils.copyProperties(dmSchedulerList.get(i), itemSchedulerVo);
         //6.如果出现vo中的字段和javabean中的字段格式不一样,需要转化
            itemSchedulerVo.setStartTime(DateUtil.format(dmSchedulerList.get(i).getStartTime()));
            itemSchedulerVo.setEndTime(DateUtil.format(dmSchedulerList.get(i).getEndTime()));
            itemSchedulerVoList.add(itemSchedulerVo);
        }
        return DtoUtil.returnDataSuccess(itemSchedulerVoList);
    }	
}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cx49wUy6-1573225130692)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\1573128611272.png)]

步骤3:
*********dm-item-consumer/ItemDetailController*********
@ResponseBody
@RequestMapping(value = "/p/queryItemScheduler",method = RequestMethod.POST)
public Dto<List<ItemSchedulerVo>> queryItemScheduler(@RequestBody Map<String, Object> param) throws Exception {
	Integer id = Integer.parseInt(param.get("itemId").toString());
	return itemDetailService.queryItemScheduler((long)id);
}

2.测试:

步骤1:

1.启动eureka微服务成功
2.启动dm-base-provider微服务
2.启动dm-item-provider微服务
3.启动dm-item-consumer微服务
4.启动dm-scheduler-provider微服务

步骤2:

打开postman:http://localhost:7201/api/p/queryItemScheduler
设置:

header
Content-Type    application/json

body
{
"itemId":5
}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-E7gaJGoi-1573225130693)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\1573136097828.png)]

2.根据商品排期查询商品价格接口

思路1:定位商品微服务工程dm-item-consumer
思路2:根据排期ID查询价格
思路3:条件是保证座位可选
思路4:确定排期价格相关信息在dm_scheduler_seat_price表中
思路5:确定座位状态字段status在dm_scheduler_seat表中
思路6:组装itemPriceVoList

步骤一:
**dm-item-consumer/ItemDetailService**
public Dto<List<ItemPriceVo>> queryItemPrice(Long id) throws Exception;
步骤二:
*********dm-item-consumer/ItemDetailServiceImpl*********
//引入:
    @Autowired
    private RestDmSchedulerSeatPriceClient restDmSchedulerSeatPriceClient;

    @Autowired
    private RestDmSchedulerSeatClient restDmSchedulerSeatClient;

 public Dto<List<ItemPriceVo>> queryItemPrice(Long id) throws Exception {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("scheduleId", id);
        //1.根据排期ID查询排期价格信息
        List<DmSchedulerSeatPrice> dmSchedulerSeatPriceList = restDmSchedulerSeatPriceClient.getDmSchedulerSeatPriceListByMap(param);
        //2.判空校验
	if (EmptyUtils.isEmpty(dmSchedulerSeatPriceList)) {
            throw new BaseException(ItemErrorCode.ITEM_NO_DATA);
        }
        //3.组装itemPriceVoListVo
        List<ItemPriceVo> itemPriceVoList = new ArrayList<ItemPriceVo>();
        for (DmSchedulerSeatPrice dmSchedulerSeatPrice : dmSchedulerSeatPriceList) {
            ItemPriceVo itemPriceVo = new ItemPriceVo();
            BeanUtils.copyProperties(dmSchedulerSeatPrice, itemPriceVo);
            //查询所有是有效的并且没有被锁定的座位
            Map<String, Object> lockMap = new HashMap<String, Object>();
            lockMap.put("status", 1);
            lockMap.put("scheduleId", itemPriceVo.getScheduleId());
            int num = restDmSchedulerSeatClient.getDmSchedulerSeatCountByMap(lockMap);
            int isHaveSeat = num > 0 ? 1 : 0;
            itemPriceVo.setIsHaveSeat(isHaveSeat);
            itemPriceVoList.add(itemPriceVo);
        }
        return DtoUtil.returnDataSuccess(itemPriceVoList);
    }
步骤三:
*********dm-item-consumer/ItemDetailController*********
@ResponseBody
@RequestMapping(value = "/p/queryItemPrice",method = RequestMethod.POST)
public Dto<List<ItemPriceVo>> queryItemPrice(@RequestBody Map<String, Object> param) throws Exception {
	Integer id = Integer.parseInt(param.get("scheduleId").toString());
	return itemDetailService.queryItemPrice((long)id);
}
步骤四:

测试:http://localhost:7201/api/p/queryItemPrice
设置:

raw
{
"scheduleId":12700
}

m.get(“scheduleId”).toString());
return itemDetailService.queryItemPrice((long)id);
}


##### 步骤四:

测试:http://localhost:7201/api/p/queryItemPrice
设置:

```java
raw
{
"scheduleId":12700
}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-onPwHcKc-1573225130694)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\1573136384689.png)]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值