package cn.ezhizao.project.business.company.controller;

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

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.project.business.company.domain.BizCompany;
import cn.ezhizao.project.business.company.service.IBizCompanyService;

/**
 * 客户名称Controller
 *
 * @author ezhizao
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/business/company")
public class BizCompanyController extends BaseController
{
    @Resource
    private IBizCompanyService bizCompanyService;

    /**
     * 查询客户名称列表
     */
    @Log(title = "客户名称查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BizCompany bizCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompany);
        startPage();
        List<BizCompany> list = bizCompanyService.getList(bizCompany);
        return getDataTable(list);
    }

    /**
     * 导出客户名称列表
     */
    @PreAuthorize("@ss.hasPermi('business:company:export')")
    @Log(title = "客户名称导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCompany bizCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompany);
        List<BizCompany> list = bizCompanyService.getList(bizCompany);
        ExcelUtil<BizCompany> util = new ExcelUtil<BizCompany>(BizCompany.class);
        util.exportExcel(response, list, "客户名称数据");
    }

    /**
     * 获取客户名称详细信息
     */
    @Log(title = "客户名称查询详细信息", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasPermi('business:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCompanyService.getById(id));
    }

    /**
     * 新增客户名称
     */
    @PreAuthorize("@ss.hasPermi('business:company:add')")
    @Log(title = "客户名称新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCompany bizCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompany);
        return toAjax(bizCompanyService.save(bizCompany));
    }

    /**
     * 修改客户名称
     */
    @PreAuthorize("@ss.hasPermi('business:company:edit')")
    @Log(title = "客户名称修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCompany bizCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompany);
        return toAjax(bizCompanyService.updateById(bizCompany));
    }

    /**
     * 删除客户名称
     */
    @PreAuthorize("@ss.hasPermi('business:company:remove')")
    @Log(title = "客户名称删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCompanyService.removeBatchByIds(ids));
    }
}
