package com.xy.controller;

import cn.hutool.core.collection.CollUtil;
import com.xy.annotate.RestMappingController;
import com.xy.dto.DeviceDataDto;
import com.xy.service.DeviceDataServiceImpl;
import com.xy.utils.MercAuthUtils;
import com.xy.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

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

/**
 * 商户PC端首页数据统计
 *
 * @author 谭斌
 * @date 2023/12/12
 */
@RestMappingController("merc-pc/homePage/data")
@RequiredArgsConstructor
@Api(tags = "商户PC端首页数据统计")
public class MercHomePageController {

    private final DeviceDataServiceImpl deviceDataService;
    private final MercMiniDeviceController mercMiniDeviceController;


    @ApiOperation("设备统计")
    @PostMapping("device")
    public R<DeviceDataDto.MercHomePageCountVO> device(@RequestBody @Valid DeviceDataDto.MercHomePageCount dto) {

        List<Long> myDevices = mercMiniDeviceController.getMyDevices();
        if (CollUtil.isEmpty(myDevices)) {
            R.ok();
        }
        dto.setMercId(MercAuthUtils.getMercId());
        dto.setMyDeviceIds(myDevices);
        return R.ok(deviceDataService.deviceCount(dto));
    }


}
