package com.hw.ems.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hw.ems.base.domain.BaseBuildInfo;
import com.hw.ems.base.domain.BaseBusinessType;
import com.hw.ems.base.domain.BaseMonitorInfo;
import com.hw.ems.base.domain.BaseSubentryType;
import com.hw.ems.base.service.IBaseBuildInfoService;
import com.hw.ems.base.service.IBaseBusinessTypeService;
import com.hw.ems.base.service.IBaseMonitorInfo1Service;
import com.hw.ems.base.service.IBaseSubentryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;

/**
 * 计量设备信息Controller
 *
 * @author sf
 * @date 2023-05-05
 */
@RestController
@RequestMapping("/ShuiMeasurement")
public class BaseMonitorInfo1Controller extends BaseController
{
    @Autowired
    private IBaseMonitorInfo1Service baseMonitorInfoService;

    @Autowired
    private IBaseBuildInfoService baseBuildInfoService;

    @Autowired
    private IBaseSubentryTypeService baseSubentryTypeService;

    @Autowired
    private IBaseBusinessTypeService baseBusinessTypeService;
    /**
     * 查询计量设备信息列表
     */
    @RequiresPermissions("energy:ShuiMeasurement:list")
    @GetMapping("/list")
    public AjaxResult list(BaseMonitorInfo baseMonitorInfo)
    {
        List<BaseMonitorInfo> list = baseMonitorInfoService.selectBaseMonitorInfoList(baseMonitorInfo);
        return success(list);
    }

    /**
     * 导出计量设备信息列表
     */
    @RequiresPermissions("energy:ShuiMeasurement:export")
    @Log(title = "计量设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseMonitorInfo baseMonitorInfo)
    {
        List<BaseMonitorInfo> list = baseMonitorInfoService.selectBaseMonitorInfoList(baseMonitorInfo);
        ExcelUtil<BaseMonitorInfo> util = new ExcelUtil<BaseMonitorInfo>(BaseMonitorInfo.class);
        util.exportExcel(response, list, "计量设备信息数据");
    }

    /**
     * 获取计量设备信息详细信息
     */
    @RequiresPermissions("energy:ShuiMeasurement:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid)
    {
        return success(baseMonitorInfoService.selectBaseMonitorInfoByObjid(objid));
    }

    /**
     * 新增计量设备信息
     */
    @RequiresPermissions("energy:ShuiMeasurement:add")
    @Log(title = "计量设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMonitorInfo baseMonitorInfo)
    {
        return toAjax(baseMonitorInfoService.insertBaseMonitorInfo(baseMonitorInfo));
    }

    /**
     * 修改计量设备信息
     */
    @RequiresPermissions("energy:ShuiMeasurement:edit")
    @Log(title = "计量设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMonitorInfo baseMonitorInfo)
    {
        return toAjax(baseMonitorInfoService.updateBaseMonitorInfo(baseMonitorInfo));
    }

    /**
     * 删除计量设备信息
     */
    @RequiresPermissions("energy:ShuiMeasurement:remove")
    @Log(title = "计量设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids)
    {
        return toAjax(baseMonitorInfoService.deleteBaseMonitorInfoByObjids(objids));
    }

    /**
     * 获取建筑类型下拉树列表
     */
    @GetMapping("/buildTreeSelect")
    public AjaxResult buildTreeSelect(BaseMonitorInfo baseMonitorInfo) {
        List<BaseBuildInfo> builds = baseBuildInfoService.selectBuildList(baseMonitorInfo);
        return success(baseBuildInfoService.buildTreeSelect(builds));
    }

    @GetMapping("/subentryTreeSelect")
    public AjaxResult subentryTreeSelect(BaseMonitorInfo baseMonitorInfo) {
        List<BaseSubentryType> subentrys = baseSubentryTypeService.selectSubentryList(baseMonitorInfo);
        return success(baseSubentryTypeService.buildTreeSelect(subentrys));
    }

    @GetMapping("/businessTreeSelect")
    public AjaxResult businessTreeSelect(BaseMonitorInfo baseMonitorInfo) {
        List<BaseBusinessType> business = baseBusinessTypeService.selectSubentryList(baseMonitorInfo);
        return success(baseBusinessTypeService.buildTreeSelect(business));
    }

    /**
     * 加载对应角色菜单列表树
     */
    @GetMapping(value = "/treeselect/{objid}")
    public AjaxResult roleMenuTreeselect(@PathVariable("objid") Long objid) {
        //Long userId = SecurityUtils.getUserId();
        BaseMonitorInfo baseMonitorInfo = new BaseMonitorInfo();
        List<BaseBuildInfo> builds = baseBuildInfoService.selectBuildList(baseMonitorInfo);
//        List<BaseSubentryType> subentrys = baseSubentryTypeService.selectSubentryList(baseMonitorInfo);
//        List<BaseBusinessType> business = baseBusinessTypeService.selectSubentryList(baseMonitorInfo);

        AjaxResult ajax = AjaxResult.success();
//        ajax.put("buildCheckedKeys", menuService.selectMenuListByRoleId(roleId));
//        ajax.put("subentryCheckedKeys", menuService.selectMenuListByRoleId(roleId));
//        ajax.put("businessCheckedKeys", menuService.selectMenuListByRoleId(roleId));
        ajax.put("builds", baseBuildInfoService.buildTreeSelect(builds));
//        ajax.put("subentrys",baseSubentryTypeService.buildTreeSelect(subentrys));
//        ajax.put("business", baseBusinessTypeService.buildTreeSelect(business));
        return ajax;

    }

}
