package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.LantoneProduct;
import com.diagbot.entity.wrapper.LantoneProductWrapper;
import com.diagbot.entity.wrapper.OpendProductWrapper;
import com.diagbot.facade.LantoneProductFacade;
import com.diagbot.vo.OppendedProductVO;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 朗通产品 前端控制器
 * @Author: wangyu
 * @Date: 15:46 2018/9/17
 */
@RestController
@Api(value="朗通产品API", tags={"朗通产品API"})
@RequestMapping("/diagLantoneProduct")
@SuppressWarnings("unchecked")
public class DiagLantoneProductController {
    @Autowired
    private LantoneProductFacade lantoneProductFacade;

    @ApiOperation(value = "添加产品线[by:wangyu]",
            notes = "name：产品名，必填<br>" +
                    "decription：产品描述，必填<br> " +
                    "url：产品访问路径，必填<br>" +
                    "charge_type：支付方式，必填<br>")
    @PostMapping("/addProducts")
    @SysLogger("addProducts")
    @Transactional
    public RespDTO<Boolean> addProducts(LantoneProduct lantoneProduct){
        return RespDTO.onSuc(lantoneProductFacade.addProducts(lantoneProduct));
    }

    @ApiOperation(value = "分页查询查询产品线[by:wangyu]",
            notes = "name：添加后则根据产品名称查询，选填<br>"+
                    "根据每页显示条数，默认 10，和当前页<br>")
    @PostMapping("/selectProduct")
    @SysLogger("selectProduct")
    public RespDTO<IPage<LantoneProduct>> selectProduct(Page page , String name){
        IPage<LantoneProduct> pages = lantoneProductFacade.selectProduct(page,name);
        return RespDTO.onSuc(pages);
    }

    @ApiOperation(value = "修改产品(产品启用同接口)[by:wangyu]",
            notes = "id：根据产品id修改产品内容，必填<br>")
    @PostMapping("/updateProduct")
    @SysLogger("updateProduct")
    @Transactional
    public RespDTO<Boolean> updateProduct(LantoneProduct lantoneProduct){
        return RespDTO.onSuc(lantoneProductFacade.updateProduct(lantoneProduct));
    }

    @ApiOperation(value = "删除产品[by:wangyu]",
            notes = "id：根据产品id删除产品，必填<br>")
    @PostMapping("/deleteProduct")
    @SysLogger("deleteProduct")
    @Transactional
    public RespDTO<Boolean> deleteProduct(LantoneProduct lantoneProduct){
        return RespDTO.onSuc(lantoneProductFacade.deleteProduct(lantoneProduct));
    }

    @ApiOperation(value = "更改产品状态（启用/停用）[by:wangyu]",
            notes = "id：根据产品id更改产品状态，必填<br>")
    @PostMapping("/productStatus")
    @SysLogger("productStatus")
    @Transactional
    public RespDTO<Boolean> productStatus(LantoneProduct lantoneProduct){
        return RespDTO.onSuc(lantoneProductFacade.productStatus(lantoneProduct));
    }

    @ApiOperation(value = "查询当条产品线所有已开通用户[by:wangyu]",
            notes = "id：根据产品id查询所有已开通本产品用户，必填<br>"+
                    "current:页数<br>"+
                    "size:每页显示条数"
    )
    @PostMapping("/opendedProduct")
    @SysLogger("opendedProduct")
    public RespDTO<List<OpendProductWrapper>> opendedProduct(OppendedProductVO oppendedProductVO){

        return RespDTO.onSuc(lantoneProductFacade.opendedProduct(oppendedProductVO));
    }

    @ApiOperation(value = "根据用户id查询当前用户已开通产品[by:zhaops]")
    @PostMapping("/opendedProductByCurrentUser")
    @SysLogger("opendedProductByCurrentUser")
    public RespDTO<List<LantoneProductWrapper>> opendedProductByCurrentUser() {
        List<LantoneProductWrapper> list = lantoneProductFacade.opendedProductByCurrentUser();
        return RespDTO.onSuc(list);
    }
}

