package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.LantoneProductDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.wrapper.LantoneProductWrapper;
import com.diagbot.entity.wrapper.OpendProductWrapper;
import com.diagbot.facade.LantoneProductFacade;
import com.diagbot.vo.AddProductsVO;
import com.diagbot.vo.LantoneProductSelectVO;
import com.diagbot.vo.OppendedProductVO;
import com.diagbot.vo.UpdateProductVO;
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 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>" +
                    "access_type：接入模式，必填<br>" +
                    "trialStatus：试用状态（是否可试用）,必填<br>")
    @PostMapping("/addProducts")
    @SysLogger("addProducts")
    @Transactional
    public RespDTO<Boolean> addProducts(@RequestBody AddProductsVO addProductsVO) {
        return RespDTO.onSuc(lantoneProductFacade.addProducts(addProductsVO));
    }

    @ApiOperation(value = "产品线管理——查询[by:wangyu]",
            notes = "name：添加后则根据产品名称查询，选填<br>" +
                    "根据每页显示条数，默认 10，和当前页<br>" +
                    "oppendedNum:开通机构数量")
    @PostMapping("/selectProduct")
    @SysLogger("selectProduct")
    public RespDTO<IPage<LantoneProductDTO>> selectProduct(@RequestBody LantoneProductSelectVO lantoneProductSelectVO) {
        return lantoneProductFacade.index(lantoneProductSelectVO);
    }

    @ApiOperation(value = "产品线管理——修改[by:wangyu]",
            notes = "id：根据产品id修改产品内容，必填<br>" +
                    "name：产品名称,选填<br>" +
                    "url：产品访问路径,选填<br>" +
                    "decription：产品描述,选填<br>" +
                    "access_type：接入模式,选填<br>" +
                    "charge_type：计费方式,选填<br>" +
                    "trialStatus：试用状态（是否可试用）,选填<br>")
    @PostMapping("/updateProduct")
    @SysLogger("updateProduct")
    @Transactional
    public RespDTO<Boolean> updateProduct(@RequestBody UpdateProductVO updateProductVO) {
        return RespDTO.onSuc(lantoneProductFacade.updateProduct(updateProductVO));
    }

    @ApiOperation(value = "产品线管理——(启用/禁用)[by:wangyu]",
            notes = "id：根据产品id修改产品内容，必填<br>" +
                    "serviceStatus：产品线状态（启用/禁用），必填<br>")
    @PostMapping("/updateServiceStatus")
    @SysLogger("updateServiceStatus")
    @Transactional
    public RespDTO<Boolean> updateServiceStatus(@RequestBody UpdateProductVO updateProductVO) {
        return RespDTO.onSuc(lantoneProductFacade.stopProduct(updateProductVO));
    }

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

    @ApiOperation(value = "产品线管理——详情[by:wangyu]",
            notes = "productId：根据产品id查询所有已开通本产品用户，必填<br>" +
                    "current:页数<br>" +
                    "size:每页显示条数<br>" +
                    "orgName:机构名称"
    )
    @PostMapping("/opendedProduct")
    @SysLogger("opendedProduct")
    public RespDTO<IPage<OpendProductWrapper>> opendedProduct(@RequestBody OppendedProductVO oppendedProductVO) {
        return RespDTO.onSuc(lantoneProductFacade.opendedProduct(oppendedProductVO));
    }

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

