package com.cpxt.web.controller.biz;

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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpxt.biz.domain.BizCarModel;
import com.cpxt.common.constant.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cpxt.common.annotation.Log;
import com.cpxt.common.core.controller.BaseController;
import com.cpxt.common.core.domain.AjaxResult;
import com.cpxt.common.enums.BusinessType;
import com.cpxt.biz.domain.BizCustomer;
import com.cpxt.biz.service.IBizCustomerService;
import com.cpxt.common.utils.poi.ExcelUtil;
import com.cpxt.common.core.page.TableDataInfo;

/**
 * 客户Controller
 * 
 * @author YIN
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/biz/customer")
public class BizCustomerController extends BaseController
{
    @Autowired
    private IBizCustomerService bizCustomerService;

    /**
     * 查询客户列表（分页）
     */
//    @PreAuthorize("@ss.hasPermi('biz:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCustomer bizCustomer,
                              @RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize)
    {
        Page<BizCustomer> recordPage = bizCustomerService.selectBizCustomerPage(bizCustomer,pageNum,pageSize);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(recordPage.getRecords());
        rspData.setTotal(recordPage.getTotal());
        return rspData;
    }

    /**
     * 查询客户列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:customer:list')")
    @GetMapping("/list2")
    public AjaxResult list(BizCustomer bizCustomer)
    {
        return AjaxResult.success(bizCustomerService.selectBizCustomerList(bizCustomer));
    }

    /**
     * 导出客户列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:customer:export')")
    @Log(title = "客户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCustomer bizCustomer)
    {
        List<BizCustomer> list = bizCustomerService.selectBizCustomerList(bizCustomer);
        ExcelUtil<BizCustomer> util = new ExcelUtil<BizCustomer>(BizCustomer.class);
        util.exportExcel(response, list, "客户数据");
    }

    /**
     * 获取客户详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCustomerService.selectBizCustomerById(id));
    }

    /**
     * 新增客户
     */
    @PreAuthorize("@ss.hasPermi('biz:customer:add')")
    @Log(title = "客户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCustomer bizCustomer)
    {
        return toAjax(bizCustomerService.insertBizCustomer(bizCustomer));
    }

    /**
     * 修改客户
     */
    @PreAuthorize("@ss.hasPermi('biz:customer:edit')")
    @Log(title = "客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCustomer bizCustomer)
    {
        return toAjax(bizCustomerService.updateBizCustomer(bizCustomer));
    }

    /**
     * 删除客户
     */
    @PreAuthorize("@ss.hasPermi('biz:customer:remove')")
    @Log(title = "客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCustomerService.deleteBizCustomerByIds(ids));
    }
}
