package com.ruoyi.business.controller;

import java.math.BigDecimal;
import java.util.List;
import java.io.IOException;
import java.util.Locale;
import java.util.UUID;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.HwSceneMode;
import com.ruoyi.business.domain.VO.HwSceneVo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.i18n.utils.MessageUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.HwScene;
import com.ruoyi.business.service.IHwSceneService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 场景信息Controller
 *
 * @author xins
 * @date 2023-08-23
 */
@RestController
@RequestMapping("/scene")
public class HwSceneController extends BaseController
{
    @Autowired
    private IHwSceneService hwSceneService;

    @ResponseBody
    @RequestMapping("getLanDemo")
    public String getLanDemo(HttpServletResponse response) {
        Locale locale = LocaleContextHolder.getLocale();
        System.out.printf("%s---%s%n",
                locale.getLanguage(),
                locale.getCountry());
        return MessageUtils.getMessage("user.login.username");

    }

    /**
     * 查询场景信息列表
     */
    @RequiresPermissions("business:scene:list")
    @GetMapping("/list")
    public TableDataInfo list(HwSceneVo hwScene)
    {
        startPage();
        List<HwSceneVo> list = hwSceneService.selectHwSceneList2(hwScene);
        return getDataTable(list);
    }


    /**
     * 导出场景信息列表
     */
    @RequiresPermissions("business:scene:export")
    @Log(title = "场景信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwScene hwScene)
    {
        List<HwScene> list = hwSceneService.selectHwSceneList(hwScene);
        ExcelUtil<HwScene> util = new ExcelUtil<HwScene>(HwScene.class);
        util.exportExcel(response, list, "场景信息数据");
    }

    /**
     * 获取场景信息详细信息
     */
    @RequiresPermissions("business:scene:query")
    @GetMapping(value = "/{sceneId}")
    public AjaxResult getInfo(@PathVariable("sceneId") Long sceneId)
    {
        return success(hwSceneService.selectHwSceneBySceneId(sceneId));
    }

    /**
     * 新增场景信息
     */
    @RequiresPermissions("business:scene:add")
    @Log(title = "场景信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody  HwScene hwScene)
    {

//        System.out.println(hwScene);
        return toAjax(hwSceneService.insertHwScene(hwScene));
    }

    /**
     * 修改场景信息
     */
    @RequiresPermissions("business:scene:edit")
    @Log(title = "场景信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwScene hwScene)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        hwScene.setUpdateBy(sysUser.getNickName());
        return toAjax(hwSceneService.updateHwScene(hwScene));
    }

    /**
     * 删除场景信息
     */
    @RequiresPermissions("business:scene:remove")
    @Log(title = "场景信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sceneIds}")
    public AjaxResult remove(@PathVariable Long[] sceneIds)
    {
        return toAjax(hwSceneService.deleteHwSceneBySceneIds(sceneIds));
    }
    @GetMapping("/isAdmin")
    public Boolean isAdmin(){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
//        System.out.println(sysUser.getUserName());
        if (sysUser.getUserName().equals("admin")){
//            System.out.println("true");
            return true;
        }else {
        return false;
    }
    }

    /**
     * 查询场景信息列表供选择使用（例如下拉列表）
     */
    @GetMapping("/getScenes")
    public AjaxResult getScenes(HwScene hwScene) {
        return success(hwSceneService.selectHwSceneList(hwScene));
    }
}


