package com.xxfc.platform.tour.rest;

import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.tour.biz.TourGoodSpeBiz;
import com.xxfc.platform.tour.common.TourBaseController;
import com.xxfc.platform.tour.dto.TourSpePriceDTO;
import com.xxfc.platform.tour.vo.TourSpePriceVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("spe")
@IgnoreClientToken
@Slf4j
public class TourGoodSpeController extends TourBaseController<TourGoodSpeBiz> {




     //获取价格
    @RequestMapping(value = "/user/prices", method = RequestMethod.POST)
    public ObjectRestResponse<TourSpePriceVo> prices(@RequestBody TourSpePriceDTO priceDto) {
        return baseBiz.getPricesByuserid(priceDto);
    }

    //减库存
    @RequestMapping(value = "/stock", method = RequestMethod.GET)
    public ObjectRestResponse<TourSpePriceVo> stock(
            @RequestParam(value = "speId",defaultValue = "0")Integer speId,
            @RequestParam(value = "number",defaultValue = "0") Integer number,
            @RequestParam(value = "type",defaultValue = "1") Integer type
            ){
        try {
            return   baseBiz.cutStock(speId,number,type);
        }catch (Exception e){
            log.error(e.getMessage(), e);;
            return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"网络异常,稍后重试");
        }

    }

    @GetMapping("/departure_date")
   public Date selectDepartureDataBySpeId(@RequestParam(value = "speIds")Integer spePriceId){
        return baseBiz.selectDepartureDataBySpeId(spePriceId);
    }
}