package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.iot.domain.DmpProductInfo;
import com.usky.iot.service.DmpProductInfoService;
import com.usky.iot.service.vo.DmpProductInfoRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 产品信息表
 *
 * @author ya
 * @since 2022-10-08
 */
@RestController
@RequestMapping("/dmpProductInfo")
public class DmpProductInfoController {


    @Autowired
    private DmpProductInfoService dmpProductInfoService;

    /**
     * 新增
     * @param dmpProductInfo
     * @return
     */
    @PostMapping
    public ApiResult<Void> add(@RequestBody List<DmpProductInfo> dmpProductInfo){
        dmpProductInfoService.add(dmpProductInfo);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param dmpProductInfo
     * @return
     */
    @PutMapping
    public ApiResult<Void> edit(@RequestBody DmpProductInfo dmpProductInfo){
        dmpProductInfoService.update(dmpProductInfo);
        return ApiResult.success();
    }


    /**
     * 分页
     * @param dmpProductInfoRequest
     * @return
     */
    @Log(title = "分页", businessType = BusinessType.OTHER)
    @PostMapping("/page")
    public ApiResult<CommonPage<DmpProductInfo>> page(@RequestBody DmpProductInfoRequest dmpProductInfoRequest)
    {
        return ApiResult.success(dmpProductInfoService.page(dmpProductInfoRequest));
    }



    /**
     * 删除记录
     */
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Integer id)
    {
        dmpProductInfoService.remove(id);
        return ApiResult.success();
    }

    /**
     * 汇总
     * @return
     */
    @GetMapping("/collect")
    public ApiResult<List<Map<String,Object>>> collect(@RequestParam(value = "tenantId", required = false) Integer tenantId){
        return ApiResult.success(dmpProductInfoService.collect(tenantId));
    }

    /**
     * 综合云图-设备统计接口
     *
     * @param deptId 部门ID
     * @return
     */
    @GetMapping("deviceStatistic")
    public ApiResult<List<Map<String,Object>>> deviceStatistic(@RequestParam(value = "deptId", required = false) Integer deptId){
        return ApiResult.success(dmpProductInfoService.deviceCollect(deptId));
    }

    /**
     * 综合云图-设备工况统计接口
     *
     * @param deptId 部门ID
     * @param productCode 产品编码
     * @return
     */
    @GetMapping("deviceStatusStatistic")
    public ApiResult<List<Object>> deviceStatusStatistic(@RequestParam(value = "deptId", required = false) Integer deptId,
                                                   @RequestParam(value = "productCode", required = false) String productCode) {
        return ApiResult.success(dmpProductInfoService.deviceStatusStatistic(deptId,productCode));
    }
}

