package com.zehong.web.controller.supervise;

import java.util.List;

import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.core.domain.model.LoginUser;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.common.utils.ServletUtils;
import com.zehong.framework.web.service.TokenService;
import com.zehong.system.domain.TDetectorUserCount;
import com.zehong.system.domain.vo.TDetectorUserInspectVo;
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.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TDetectorUser;
import com.zehong.system.service.ITDetectorUserService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 燃气用户Controller
 *
 * @author zehong
 * @date 2022-02-07
 */
@RestController
@RequestMapping("/supervise/user")
public class TDetectorUserController extends BaseController
{
    @Autowired
    private ITDetectorUserService tDetectorUserService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询燃气用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TDetectorUser tDetectorUser)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tDetectorUser.setBeyondEnterpriseId(user.getDeptId());
        startPage();
        List<TDetectorUser> list = tDetectorUserService.selectTDetectorUserList(tDetectorUser);
        return getDataTable(list);
    }

    /**
     * 查询用户安检状态
     * @param tDetectorUser
     * @return
     */
    @GetMapping("/liststatus")
    public TableDataInfo liststatus(TDetectorUser tDetectorUser)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tDetectorUser.setBeyondEnterpriseId(user.getDeptId());
        startPage();
        List<TDetectorUser> list = tDetectorUserService.selectTDetectorListstatus(tDetectorUser);
        return getDataTable(list);
    }

    /**
     * 获取燃气用户统计信息
     */
    @GetMapping("/userStatistics")
    public AjaxResult userStatistics()
    {
        //获取当前登录用户信息
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        TDetectorUserCount tDetectorUserCount = tDetectorUserService.userStatistics(user.getDeptId());
        return AjaxResult.success(tDetectorUserCount);
    }

    /**
     * 获取探测器用户列表
     * @return
     */
    @GetMapping("/detectorUserList")
    public AjaxResult detectorUserList(TDetectorUser tDetectorUser){
        return AjaxResult.success(tDetectorUserService.detectorUserList(tDetectorUser));
    }

    /**
     * 获取探测器用户列表 大屏地图 massMarks 标注的方式
     * @return ajaxResult
     */
    @GetMapping("/massMarksDetectorUserList")
    public AjaxResult massMarksDetectorUserList(TDetectorUser tDetectorUser){
        return AjaxResult.success(tDetectorUserService.detectorUserList(tDetectorUser));
    }

    /**
     * 获取探测器用户列表 大屏地图 labelsLayer 标注的方式
     * @return ajaxResult
     */
    @GetMapping("/labelsLayerMarksDetectorUserList")
    public AjaxResult labelsLayerMarksDetectorUserList(TDetectorUser tDetectorUser){
        return AjaxResult.success(tDetectorUserService.labelsLayerMarksDetectorUserList(tDetectorUser));
    }



    /**
     * 获取探测器用户列表
     * @return
     */
    @GetMapping("/getDetectorUserAlarmList")
    public AjaxResult getDetectorUserAlarmList(){
        return AjaxResult.success(tDetectorUserService.getDetectorUserAlarmList());
    }

    /**
     * 导出燃气用户列表
     */
    @Log(title = "燃气用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDetectorUser tDetectorUser)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tDetectorUser.setBeyondEnterpriseId(user.getDeptId());
        List<TDetectorUser> list = tDetectorUserService.selectTDetectorUserList(tDetectorUser);
        ExcelUtil<TDetectorUser> util = new ExcelUtil<TDetectorUser>(TDetectorUser.class);
        return util.exportExcel(list, "燃气用户数据");
    }

    /**
     * 获取燃气用户详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(tDetectorUserService.selectTDetectorUserById(userId));
    }

    /**
     * 新增燃气用户
     */
    @Log(title = "燃气用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDetectorUser tDetectorUser)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        tDetectorUser.setBeyondEnterpriseId(user.getDeptId());
        return toAjax(tDetectorUserService.insertTDetectorUser(tDetectorUser));
    }

    /**
     * 修改燃气用户
     */
    @Log(title = "燃气用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDetectorUser tDetectorUser)
    {
        return toAjax(tDetectorUserService.updateTDetectorUser(tDetectorUser));
    }

    /**
     * 删除燃气用户
     */
    @Log(title = "燃气用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(tDetectorUserService.deleteTDetectorUserByIds(userIds));
    }

    /**
     * 获取用户安检信息
     * @param inspectVo
     * @return
     */
    @GetMapping("/getDetectorUserInspectInfo")
    public TableDataInfo getDetectorUserInspectInfo(TDetectorUserInspectVo inspectVo){
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        inspectVo.setBeyondEnterpriseId(user.getDeptId());
        startPage();
        return  getDataTable(tDetectorUserService.getDetectorUserInspectInfo(inspectVo));
    }


    /**
     * 导出用户安检信息导出
     */
    @Log(title = "用户安检信息导出", businessType = BusinessType.EXPORT)
    @GetMapping("/detectorUserExport")
    public AjaxResult detectorUserExport(TDetectorUserInspectVo inspectVo)
    {
        //获取用户信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        inspectVo.setBeyondEnterpriseId(user.getDeptId());
        List<TDetectorUserInspectVo> list = tDetectorUserService.getDetectorUserInspectInfo(inspectVo);
        ExcelUtil<TDetectorUserInspectVo> util = new ExcelUtil<>(TDetectorUserInspectVo.class);
        return util.exportExcel(list, "用户安检数据");
    }

}
