package com.ruoyi.web.controller.enterprise;

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

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.enterprise.SysUserEnterprise;
import com.ruoyi.system.service.enterprise.ISysUserEnterpriseService;
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.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.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户企业信息Controller
 *
 * @author boman
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/enterprise")
public class SysUserEnterpriseController extends BaseController {
    @Autowired
    private ISysUserEnterpriseService sysUserEnterpriseService;

    /**
     * 查询用户企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserEnterprise sysUserEnterprise) {
        startPage();
        List<SysUserEnterprise> list = sysUserEnterpriseService.selectSysUserEnterpriseList(sysUserEnterprise);
        return getDataTable(list);
    }

    /**
     * 查询用户企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:listNoPage')")
    @GetMapping("/listNoPage")
    public TableDataInfo listNoPage(SysUserEnterprise sysUserEnterprise) {
        List<SysUserEnterprise> list = sysUserEnterpriseService.selectSysUserEnterpriseList(sysUserEnterprise);
        return getDataTable(list);
    }

    /**
     * 导出用户企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:export')")
    @Log(title = "用户企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserEnterprise sysUserEnterprise) {
        List<SysUserEnterprise> list = sysUserEnterpriseService.selectSysUserEnterpriseList(sysUserEnterprise);
        ExcelUtil<SysUserEnterprise> util = new ExcelUtil<SysUserEnterprise>(SysUserEnterprise.class);
        util.exportExcel(response, list, "用户企业信息数据");
    }

/*    *//**
     * 获取用户企业信息详细信息
     *//*
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(sysUserEnterpriseService.selectSysUserEnterpriseByUserId(userId));
    }*/

    /**
     * 获取用户企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:query')")
    @GetMapping(value = "/{enterpriseId}")
    public AjaxResult getInfo(@PathVariable("enterpriseId") Long enterpriseId) {
        return success(sysUserEnterpriseService.selectSysUserEnterpriseByEnterpriseId(enterpriseId));
    }

    /**
     * 新增用户企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:add')")
    @Log(title = "用户企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<SysUserEnterprise> sysUserEnterpriseList) {
        for (SysUserEnterprise sysUserEnterprise : sysUserEnterpriseList) {
            return toAjax(sysUserEnterpriseService.insertSysUserEnterprise(sysUserEnterprise));
        }
        return AjaxResult.success();
    }

    /**
     * 修改用户企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:edit')")
    @Log(title = "用户企业信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody SysUserEnterprise sysUserEnterprise) {
        return toAjax(sysUserEnterpriseService.updateSysUserEnterprise(sysUserEnterprise));
    }

/*    *//**
     * 删除用户企业信息
     *//*
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:remove')")
    @Log(title = "用户企业信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(sysUserEnterpriseService.deleteSysUserEnterpriseByUserIds(userIds));
    }*/

    /**
     * 删除用户企业信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:remove')")
    @Log(title = "用户企业信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{enterpriseIds}")
    public AjaxResult remove(@PathVariable Long[] enterpriseIds) {
        return toAjax(sysUserEnterpriseService.deleteSysUserEnterpriseByEnterpriseIds(enterpriseIds));
    }
}
