package com.chinacreator.video.service;

import com.alibaba.fastjson.JSON;
import com.chinacreator.video.bean.OrderInfo;
import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.mapper.CommConfDao;
import com.chinacreator.video.mapper.QueryOrderByCpDao;
import com.chinacreator.video.util.RedisService;
import com.chinacreator.video.validate.BusiValidate;
import com.chinacreator.video.validate.IpValidate;
import com.chinacreator.video.validate.OrderValidate;
import com.chinacreator.video.validate.TimetampValidate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class QueryOrderByCpService {
    private static final Logger logger = LoggerFactory.getLogger(QueryOrderByCpService.class);

    private static final  Logger log = LoggerFactory.getLogger("qryOrderBycp");

    @Autowired
    private QueryOrderByCpDao queryOrderByCpDao;

    @Autowired
    RedisService redisService;

    @Autowired
    private TimetampValidate timetampValidate;

    @Autowired
    private OrderValidate orderValidate;

    @Autowired
    private IpValidate ipValidate;



    public void checkOrder(OrderInfo orderInfo) throws Exception {
        timetampValidate.validate(orderInfo.getTimestamp());
        orderValidate.checkqueryOrderSign(orderInfo);
        orderValidate.validate(orderInfo);
        ipValidate.volidate(orderInfo,"1");
    }

    public List<OrderInfo> getOrderByCp(OrderInfo orderInfo) throws BussinessException {
        Map result=new HashMap<>();
        List<OrderInfo>  list= queryOrderByCpDao.getOrderByCp(orderInfo.getUserid(),orderInfo.getCpid());
        if(list == null || list.size() <= 0){
            throw new BussinessException("9006", "无订购关系");
        }
        return list;
    }
}
