package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.ZhCompanyInfo;
import com.ruoyi.project.system.service.IZhCompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 企业管理Controller
 *
 * @author zhu
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/system/company")
public class ZhCompanyInfoController extends BaseController {
    @Autowired
    private IZhCompanyInfoService zhCompanyInfoService;

    /**
     * 查询企业管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:zhihui:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhCompanyInfo zhCompanyInfo) {
        startPage();
        List<ZhCompanyInfo> list = zhCompanyInfoService.selectZhCompanyInfoList(zhCompanyInfo);
        return getDataTable(list);
    }

    /**
     * 导出企业管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:zhihui:company:export')")
    @Log(title = "企业管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhCompanyInfo zhCompanyInfo) {
        List<ZhCompanyInfo> list = zhCompanyInfoService.selectZhCompanyInfoList(zhCompanyInfo);
        ExcelUtil<ZhCompanyInfo> util = new ExcelUtil<ZhCompanyInfo>(ZhCompanyInfo.class);
        util.exportExcel(response, list, "企业管理数据");
    }

    /**
     * 获取企业管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:zhihui:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zhCompanyInfoService.selectZhCompanyInfoById(id));
    }

    /**
     * 新增企业管理
     */
    @PreAuthorize("@ss.hasPermi('system:zhihui:company:add')")
    @Log(title = "企业管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhCompanyInfo zhCompanyInfo) {
        return toAjax(zhCompanyInfoService.insertZhCompanyInfo(zhCompanyInfo));
    }

    /**
     * 修改企业管理
     */
    @PreAuthorize("@ss.hasPermi('system:zhihui:company:edit')")
    @Log(title = "企业管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhCompanyInfo zhCompanyInfo) {
        return toAjax(zhCompanyInfoService.updateZhCompanyInfo(zhCompanyInfo));
    }

    /**
     * 删除企业管理
     */
    @PreAuthorize("@ss.hasPermi('system:zhihui:company:remove')")
    @Log(title = "企业管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zhCompanyInfoService.deleteZhCompanyInfoByIds(ids));
    }
}
