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.ProductServiceDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.wrapper.ProductServiceWrapper;
import com.diagbot.facade.ProductServiceFacade;
import com.diagbot.vo.ProductServiceSaveVO;
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;

/**
 * <p>
 * 服务端维护表 前端控制器
 * </p>
 *
 * @author zhaops
 * @since 2018-09-17
 */
@RestController
@Api(value="产品服务端API", tags={"产品服务端API"})
@RequestMapping("/productService")
@SuppressWarnings("unchecked")
public class ProductServiceController {
    @Autowired
    private ProductServiceFacade productServiceFacade;

    @ApiOperation(value = "服务端关联到产品接口[by:zhaops]",
            notes = "productId：产品Id，必填<br>" +
                    "serviceId：服务Id，必填<br> " +
                    "type：令牌类型，必填<br> ")
    @PostMapping("/genProductService")
    @SysLogger("genProductService")
    @Transactional
    public RespDTO<ProductServiceDTO> genProductService(ProductServiceSaveVO productServiceSaveVO) {
        ProductServiceDTO productServiceDTO = productServiceFacade.genProductService(productServiceSaveVO);
        return RespDTO.onSuc(productServiceDTO);
    }

    @ApiOperation(value = "删除产品服务端[by:zhaops]",
            notes = "productId：产品Id，必填<br>" +
                    "serviceId：服务Id，必填<br> " +
                    "type：令牌类型，必填<br> ")
    @PostMapping("/deleteProductService")
    @SysLogger("deleteProductService")
    @Transactional
    public RespDTO<Boolean> deleteProductService(ProductServiceSaveVO productServiceSaveVO) {
        Boolean isSuccess = productServiceFacade.deleteProductService(productServiceSaveVO);
        return RespDTO.onSuc(isSuccess);
    }

    @ApiOperation(value = "根据用户id获取产品服务关联信息[by:zhaops]", notes = "根据用户id获取产品服务关联信息")
    @PostMapping("/getProductServiceByCurrentUser")
    @SysLogger("getProductServiceByCurrentUser")
    public RespDTO getProductServiceByCurrentUser(Page page) {
        IPage<ProductServiceWrapper> psPage = productServiceFacade.selectProductServiceByCurrentUserPage(page);
        return RespDTO.onSuc(psPage);
    }
}

