package cn.pluss.platform.controller.device;


import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.deviceStock.DeviceStockService;
import cn.pluss.platform.dto.DeviceStockDTO;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.vo.DeviceNumVO;
import cn.pluss.platform.vo.DeviceStockVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 设备库存controller
 * </p>
 *
 * @author bzg
 * @since 2020-11-11
 */
@RestController
@RequestMapping("/device/stock")
public class DeviceStockController{

    @Resource
    private UserAppService userAppService;

    @Resource
    private DeviceStockService dsService;

    /**
     * 获取设备统计详情
     * @return
     */
    @GetMapping(value = "/count")
    public Result<DeviceNumVO> count(DeviceStockDTO dto){
        DeviceNumVO vo = dsService.getStockTypeNumList(dto);
        return ResultGenerator.genSuccessResult("获取成功",vo);
    }

    /**
     * 分页查询指定设备类型设备信息
     * @param dto
     * @return
     */
    @GetMapping(value = "/code/page")
    public Result<Page<DeviceStockVO>> codePage(Page<DeviceStockVO> page, DeviceStockDTO dto){
        UserApp userApp = userAppService.checkApiToken();
        dto.setUserId(String.valueOf(userApp.getUserId()));
        MsgException.checkBlank(dto.getCode(),"设备code不能为空");
        page = dsService.pageInfo(page,dto);
        return ResultGenerator.genSuccessResult("获取成功",page);
    }

    /**
     * 查询设备详情
     * @param dto
     * @return
     */
    @GetMapping(value = "/detail")
    public Result<DeviceStockVO> detail(DeviceStockDTO dto){
        DeviceStockVO vo = dsService.detail(dto);
        return ResultGenerator.genSuccessResult("获取成功",vo);
    }

    /**
     * 获取商户信息
     * @param dto
     * @return
     */
    @GetMapping(value = "/mercInfo")
    public Result<DeviceStockVO> mercInfo(DeviceStockDTO dto){
        DeviceStockVO vo = dsService.getMercInfo(dto);
        return ResultGenerator.genSuccessResult("获取成功",vo);
    }

    @GetMapping("/pageMercDevice")
    public Result<Page<DeviceStockVO>> pageMercDevice(Page<DeviceStockVO> page, Long cashPlaceId) {
        Page<DeviceStockVO> data = dsService.apiPageMercDevice(page, cashPlaceId);
        return ResultGenerator.genSuccessResult("获取成功", data);
    }

    /**
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/bind")
    public Result<Object> bindV2(@RequestBody DeviceStockDTO dto){
        dsService.bindDevcieV2(dto);
        return ResultGenerator.genSuccessResult("绑定成功",null);
    }
}
