package com.bonus.zlpt.bigscreen.controller;

import com.bonus.zlpt.bigscreen.domain.vo.MaIdVo;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.bigscreen.domain.MaDevInfo;
import com.bonus.zlpt.bigscreen.domain.vo.CoTypeVo;
import com.bonus.zlpt.bigscreen.domain.vo.CompanyInfoVo;
import com.bonus.zlpt.bigscreen.domain.vo.TypeVo;
import com.bonus.zlpt.bigscreen.service.MaDevInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 设备信息表(MaDevInfo)表控制层
 *
 * @author makejava
 * @since 2023-11-30 12:57:58
 */
@RestController
@RequestMapping("maDevInfo")
public class MaDevInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private MaDevInfoService maDevInfoService;

    /**
     * 查询平台入驻设备总数
     * @return
     */
    @GetMapping("/list")
    public AjaxResult List()
    {
        return success(maDevInfoService.selectList());
    }

    /**
     * 根据类型查询设备总数
     * @param
     * @return
     */
    @GetMapping("/type-list")
    public AjaxResult typeList()
    {
        List<TypeVo> list = maDevInfoService.selectTypeList();
        HashMap<String, Object> map = new HashMap<>(2);
        for (TypeVo typeVo : list) {
            if (typeVo.getMaStatus().equals("自有")){
                map.put("self", typeVo);
            } else {
                map.put("rent", typeVo);
            }
        }
        return success(map);
    }

    /**
     * 根据设备类型查询数量
     * @param
     * @return
     */
    @GetMapping("/matype-list")
    public AjaxResult maTypeList()
    {
        List<TypeVo> list = maDevInfoService.selectMaTypeList();
        HashMap<String, Object> map = new HashMap<>(2);
        for (TypeVo typeVo : list) {
            if (typeVo.getMaStatus().equals("在租")){
                map.put("use", typeVo);
            } else {
                map.put("rent", typeVo);
            }
        }
        return success(map);
    }

    /**
     * 获取企业所属设备状态为自有的设备数量
     * @return
     */
    @GetMapping("/company-list")
    public AjaxResult companyList()
    {
        List<CoTypeVo> maDevInfos = maDevInfoService.selectMaDevInfoList();
        return success(maDevInfos);
    }

    /**
     * 查询设备状态为在租的设备名称及数量
     * @return
     */
    @GetMapping("/ma-list")
    public AjaxResult maList()
    {
        List<CompanyInfoVo> maDevInfos = maDevInfoService.selectmaList();
        return success(maDevInfos);
    }

    /**
     * 查询公司对应的热门设备数量
     * @return
     */
    @GetMapping("/hot-list")
    public AjaxResult hotList()
    {
        List<CompanyInfoVo> maHotInfos = maDevInfoService.selecthotList();
        return success(maHotInfos);
    }

    /**
     * 根据设备id查询设备详情相关信息
     * @param maId 设备id
     * @return
     */
    @GetMapping("/list/{maId}")
    public AjaxResult listById(@PathVariable("maId") String maId)
    {
        MaIdVo maIdVo = maDevInfoService.selectListById(maId);
        return success(maIdVo);
    }
}

