package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Enterprise;
import com.ruoyi.web.work.service.IEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 企业信息
 *
 * @author lsw
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/work/enterprise")
public class EnterpriseController extends BaseController {
    @Autowired
    private IEnterpriseService enterpriseService;

    @PreAuthorize("@ss.hasPermi('work:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(Enterprise enterprise) {
        startPage();
        List<Enterprise> list = enterpriseService.selectList(enterprise);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:enterprise:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return AjaxResult.success(enterpriseService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:enterprise:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Enterprise enterprise) {
        return toAjax(enterpriseService.save(enterprise));
    }

    @PreAuthorize("@ss.hasPermi('work:enterprise:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Enterprise enterprise) {
        return enterpriseService.audit(enterprise);
    }

    @PreAuthorize("@ss.hasPermi('work:enterprise:remove')")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(enterpriseService.removeByIds(Arrays.asList(ids)));
    }
}
