package cn.ezhizao.project.business.companyProductPackage.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.companyProductPackage.domain.BizCompanyProductPackage;
import cn.ezhizao.project.business.companyProductPackage.service.IBizCompanyProductPackageService;

/**
 * 产品包装客户关联Controller
 *
 * @author ezhizao
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/business/companyProductPackage")
public class BizCompanyProductPackageController extends BaseController
{
    @Resource
    private IBizCompanyProductPackageService bizCompanyProductPackageService;

    /**
     * 查询产品包装客户关联列表
     */
    @PreAuthorize("@ss.hasPermi('business:companyProductPackage:list')")
    @Log(title = "产品包装客户关联查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BizCompanyProductPackage bizCompanyProductPackage) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyProductPackage);
        startPage();
        List<BizCompanyProductPackage> list = bizCompanyProductPackageService.getList(bizCompanyProductPackage);
        return getDataTable(list);
    }

    /**
     * 导出产品包装客户关联列表
     */
    @PreAuthorize("@ss.hasPermi('business:companyProductPackage:export')")
    @Log(title = "产品包装客户关联导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCompanyProductPackage bizCompanyProductPackage) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyProductPackage);
        List<BizCompanyProductPackage> list = bizCompanyProductPackageService.getList(bizCompanyProductPackage);
        ExcelUtil<BizCompanyProductPackage> util = new ExcelUtil<BizCompanyProductPackage>(BizCompanyProductPackage.class);
        util.exportExcel(response, list, "产品包装客户关联数据");
    }

    /**
     * 获取产品包装客户关联详细信息
     */
    @Log(title = "产品包装客户关联查询详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCompanyProductPackageService.getById(id));
    }

    /**
     * 新增产品包装客户关联
     */
    @PreAuthorize("@ss.hasPermi('business:companyProductPackage:add')")
    @Log(title = "产品包装客户关联新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCompanyProductPackage bizCompanyProductPackage) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyProductPackage);
        return toAjax(bizCompanyProductPackageService.save(bizCompanyProductPackage));
    }

    /**
     * 修改产品包装客户关联
     */
    @PreAuthorize("@ss.hasPermi('business:companyProductPackage:edit')")
    @Log(title = "产品包装客户关联修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCompanyProductPackage bizCompanyProductPackage) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyProductPackage);
        return toAjax(bizCompanyProductPackageService.updateById(bizCompanyProductPackage));
    }

    /**
     * 删除产品包装客户关联
     */
    @PreAuthorize("@ss.hasPermi('business:companyProductPackage:remove')")
    @Log(title = "产品包装客户关联删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCompanyProductPackageService.removeBatchByIds(ids));
    }
}
