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.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.BizCustomerWarehouse;
import com.cpxt.biz.service.IBizCustomerWarehouseService;
import com.cpxt.common.utils.poi.ExcelUtil;
import com.cpxt.common.core.page.TableDataInfo;

/**
 * 仓库Controller
 * 
 * @author YIN
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/biz/warehouse")
public class BizCustomerWarehouseController extends BaseController
{
    @Autowired
    private IBizCustomerWarehouseService bizCustomerWarehouseService;

    /**
     * 查询仓库列表（分页）
     */
    @PreAuthorize("@ss.hasPermi('biz:warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCustomerWarehouse bizCustomerWarehouse,
                              @RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize)
    {
        Page<BizCustomerWarehouse> recordPage = bizCustomerWarehouseService.selectBizCustomerWarehousePage(bizCustomerWarehouse,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:warehouse:list')")
    @GetMapping("/list2")
    public AjaxResult list(BizCustomerWarehouse bizCustomerWarehouse)
    {
        return AjaxResult.success(bizCustomerWarehouseService.selectBizCustomerWarehouseList(bizCustomerWarehouse));
    }

    /**
     * 导出仓库列表
     */
    @PreAuthorize("@ss.hasPermi('biz:warehouse:export')")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCustomerWarehouse bizCustomerWarehouse)
    {
        List<BizCustomerWarehouse> list = bizCustomerWarehouseService.selectBizCustomerWarehouseList(bizCustomerWarehouse);
        ExcelUtil<BizCustomerWarehouse> util = new ExcelUtil<BizCustomerWarehouse>(BizCustomerWarehouse.class);
        util.exportExcel(response, list, "仓库数据");
    }

    /**
     * 获取仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:warehouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCustomerWarehouseService.selectBizCustomerWarehouseById(id));
    }

    /**
     * 新增仓库
     */
    @PreAuthorize("@ss.hasPermi('biz:warehouse:add')")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCustomerWarehouse bizCustomerWarehouse)
    {
        return toAjax(bizCustomerWarehouseService.insertBizCustomerWarehouse(bizCustomerWarehouse));
    }

    /**
     * 修改仓库
     */
    @PreAuthorize("@ss.hasPermi('biz:warehouse:edit')")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCustomerWarehouse bizCustomerWarehouse)
    {
        return toAjax(bizCustomerWarehouseService.updateBizCustomerWarehouse(bizCustomerWarehouse));
    }

    /**
     * 删除仓库
     */
    @PreAuthorize("@ss.hasPermi('biz:warehouse:remove')")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCustomerWarehouseService.deleteBizCustomerWarehouseByIds(ids));
    }
}
