package com.yanzhu.jh.work.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.yanzhu.jh.work.domain.WorkFileUser;
import com.yanzhu.jh.work.service.IWorkFileUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件访问用户Controller
 * 
 * @author JiangYuQi
 * @date 2023-10-22
 */
@RestController
@RequestMapping("/work/workUser")
public class WorkFileUserController extends BaseController
{
    @Autowired
    private IWorkFileUserService workFileUserService;

    /**
     * 查询文件访问用户列表
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkFileUser workFileUser)
    {
        startPage();
        List<WorkFileUser> list = workFileUserService.selectWorkFileUserList(workFileUser);
        return getDataTable(list);
    }

    /**
     * 统计文件访问用户列表
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:list')")
    @GetMapping("/queryCount")
    public AjaxResult queryCount(WorkFileUser workFileUser)
    {
        List<Map<String,Object>> list = workFileUserService.queryCountByDeptType(workFileUser);
        return success(list);
    }

    /**
     * 导出文件访问用户列表
     */
    @PreAuthorize("@ss.hasPermi('work:workUser:export')")
    @Log(title = "文件访问用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkFileUser workFileUser)
    {
        List<WorkFileUser> list = workFileUserService.selectWorkFileUserList(workFileUser);
        ExcelUtil<WorkFileUser> util = new ExcelUtil<WorkFileUser>(WorkFileUser.class);
        util.exportExcel(response, list, "文件访问用户数据");
    }

    /**
     * 获取文件访问用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:workUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workFileUserService.selectWorkFileUserById(id));
    }

    /**
     * 新增文件访问用户
     */
    @PreAuthorize("@ss.hasPermi('work:workUser:add')")
    @Log(title = "文件访问用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkFileUser workFileUser)
    {
        return toAjax(workFileUserService.insertWorkFileUser(workFileUser));
    }

    /**
     * 修改文件访问用户
     */
    @PreAuthorize("@ss.hasPermi('work:workUser:edit')")
    @Log(title = "文件访问用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkFileUser workFileUser)
    {
        return toAjax(workFileUserService.updateWorkFileUser(workFileUser));
    }

    /**
     * 删除文件访问用户
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:remove')")
    @Log(title = "文件访问用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workFileUserService.deleteWorkFileUserByIds(ids));
    }
}
