package com.diagbot.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.EnShowOptionDTO;
import com.diagbot.dto.GetConsoleOnTrialDTO;
import com.diagbot.dto.GetConsoleOpenedDTO;
import com.diagbot.dto.OpenUpOnTrialDTO;
import com.diagbot.dto.ProductAuthProgressDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.UserAndProdutDTO;
import com.diagbot.dto.WaitExamOrderCouDTO;
import com.diagbot.entity.OpenedProducts;
import com.diagbot.entity.wrapper.ProductOrderWrapper;
import com.diagbot.facade.LantoneProductFacade;
import com.diagbot.facade.OpenedProductsFacade;
import com.diagbot.facade.ProductOrderFacade;
import com.diagbot.vo.ModifyOpeningTimeVO;
import com.diagbot.vo.OpenUpOnTrialVO;
import com.diagbot.vo.ProductOrderVO;
import com.diagbot.vo.StartAndendByUserIdVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * @author rgb
 * @Description 订单产品相关的操作
 * @time 2018年9月25日下午4:06:16
 */
@Api(value = "控制台-产品操作API", tags = { "控制台-产品操作API" })
@RestController
@RequestMapping("/productOrder")
@SuppressWarnings("unchecked")
public class ProductOrderController {
    @Autowired
    private LantoneProductFacade lantoneProductFacade;

    @Autowired
    private ProductOrderFacade productOrderFacade;
    @Autowired
    private OpenedProductsFacade openedProductsFacade;

    @ApiOperation(value = "控制台-产品认证进度[by:rengb]", notes = "控制台-产品认证进度")
    @PostMapping("/productAuthProgress")
    @SysLogger("productAuthProgress")
    public RespDTO<List<ProductAuthProgressDTO>> productAuthProgress() {
        return RespDTO.onSuc(productOrderFacade.productAuthProgress());
    }

    @ApiOperation(value = "控制台-已开通产品[by:rengb]", notes = "控制台-已开通产品")
    @PostMapping("/getConsoleOpened")
    @SysLogger("getConsoleOpened")
    public RespDTO<List<GetConsoleOpenedDTO>> getConsoleOpened() {
        return RespDTO.onSuc(openedProductsFacade.getConsoleOpened());
    }

    @ApiOperation(value = "控制台-可试用产品[by:rengb]", notes = "控制台-可试用产品")
    @PostMapping("/getConsoleOnTrial")
    @SysLogger("getConsoleOnTrial")
    public RespDTO<List<GetConsoleOnTrialDTO>> getConsoleOnTrial() {
        return RespDTO.onSuc(openedProductsFacade.getConsoleOnTrial());
    }

    @ApiOperation(value = "控制台-产品立即试用接口[by:rengb]", notes = "控制台-产品立即试用接口")
    @PostMapping("/openUpOnTrial")
    @SysLogger("openUpOnTrial")
    public RespDTO<OpenUpOnTrialDTO> openUpOnTrial(@RequestBody OpenUpOnTrialVO openUpOnTrialVO) {
        return RespDTO.onSuc(openedProductsFacade.openUpOnTrial(openUpOnTrialVO));
    }

    @ApiOperation(value = "控制台-可展示的选项卡[by:rengb]", notes = "控制台-可展示的选项卡")
    @PostMapping("/enShowOption")
    @SysLogger("enShowOption")
    public RespDTO<EnShowOptionDTO> enShowOption() {
        return RespDTO.onSuc(openedProductsFacade.enShowOption());
    }

    @ApiOperation(value = "控制台-待审核订单个数[by:rengb]", notes = "控制台-待审核订单个数")
    @PostMapping("/waitExamOrderCou")
    @SysLogger("waitExamOrderCou")
    public RespDTO<WaitExamOrderCouDTO> waitExamOrderCou() {
        return RespDTO.onSuc(productOrderFacade.waitExamOrderCou());
    }

    @ApiOperation(value = "客户中心-传入用户id查询已开通的功能(传userId)[by:wangfeng]", notes = "已开通信息")
    @PostMapping("/getInformationAvailableByUserId")
    @SysLogger("getInformationAvailableByUserId")
    public RespDTO getInformationAvailableByUserId(@RequestBody OpenedProducts openedProduct) {
        OpenedProducts openedProducts = new OpenedProducts();
        openedProducts.setUserId(openedProduct.getUserId());
        List<UserAndProdutDTO> UserAndProdutData = openedProductsFacade.getInformationAvailableByUserId(openedProducts);
        return RespDTO.onSuc(UserAndProdutData);
    }

    @ApiOperation(value = "客户中心-传入用户id和产品id，启用和停用功能[by:wangfeng]", notes = "拥护开通的产品")
    @PostMapping("/startAndendByuserId")
    @SysLogger("startAndendByuserId")
    @Transactional
    public RespDTO<StartAndendByUserIdVO> startAndendByuserId(@RequestBody @Valid StartAndendByUserIdVO startAndendByUserIdVO) {

        return openedProductsFacade.startAndendByuserIds(startAndendByUserIdVO);

    }

    @ApiOperation(value = "客户中心-传入用户userId和产品productId，删除开通信息[by:wangfeng]", notes = "删除开通信息")
    @PostMapping("/delInformationAvailable")
    @SysLogger("delInformationAvailable")
    @Transactional
    public RespDTO delInformationAvailable(@RequestBody OpenedProducts openedProduct) {
    	long userId = openedProduct.getUserId(); 
    	long productId = openedProduct.getProductId();
        return openedProductsFacade.delInformationAvailables(userId, productId);
    }

    @ApiOperation(value = "产品续费-传入用户id和产品id，修改服务到期时间[by:wangyu]", notes = "修改服务到期时间")
    @PostMapping("/modifyOpeningTime")
    @SysLogger("modifyOpeningTime")
    @Transactional
    public RespDTO<ModifyOpeningTimeVO> modifyOpeningTime(@RequestBody @Valid ModifyOpeningTimeVO modifyOpeningTimeVO) {

        return openedProductsFacade.modifyOpeningTimes(modifyOpeningTimeVO);
    }

    @ApiOperation(value = "产品申请——显示所有订单[by:wangyu]",
            notes = "current:页数<br>" +
                    "size:每页显示条数<br>" +
                    "auditStatus:审核状态（0.不通过1.通过2.待审核3.部分通过4.部分审核）<br>" +
                    "num:订单编号<br>" +
                    "orgName:机构名称<br>" +
                    "id:订单id<br>" +
                    "userId:用户id<br>" +
                    "time:下单时间<br>" +
                    "linkman:用户名称<br>" +
                    "username:手机号码<br>")
    @PostMapping("/getAllProductOrder")
    @SysLogger("getAllProductOrder")
    public RespDTO<IPage<ProductOrderWrapper>> getAllProductOrder(@RequestBody ProductOrderVO productOrderVO) {
        return productOrderFacade.selectAllProductOrder(productOrderVO);
    }

    @ApiOperation(value = "客户中心-查询用户已开通的功能[by:wangfeng]", notes = "用户已开通信息")
    @PostMapping("/getInformationAvailableAll")
    @SysLogger("getInformationAvailableAll")
    @ApiIgnore
    public RespDTO<List<UserAndProdutDTO>>  getInformationAvailableByUserIds(@RequestBody List<Long> userIds){
    	List<UserAndProdutDTO> UserAndProdutData = openedProductsFacade.getInformationAvailableByUserIds(userIds);
    	return RespDTO.onSuc(UserAndProdutData);
    }
}
