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

/**
 * 门店Controller
 * 
 * @author YIN
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/biz/shop")
public class BizCustomerShopController extends BaseController
{
    @Autowired
    private IBizCustomerShopService bizCustomerShopService;

    /**
     * 查询门店列表（分页）
     */
    @PreAuthorize("@ss.hasPermi('biz:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCustomerShop bizCustomerShop,
                              @RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize)
    {
        Page<BizCustomerShop> recordPage = bizCustomerShopService.selectBizCustomerShopPage(bizCustomerShop,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:shop:list')")
    @GetMapping("/list2")
    public AjaxResult list(BizCustomerShop bizCustomerShop)
    {
        return AjaxResult.success(bizCustomerShopService.selectBizCustomerShopList(bizCustomerShop));
    }

    /**
     * 导出门店列表
     */
    @PreAuthorize("@ss.hasPermi('biz:shop:export')")
    @Log(title = "门店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCustomerShop bizCustomerShop)
    {
        List<BizCustomerShop> list = bizCustomerShopService.selectBizCustomerShopList(bizCustomerShop);
        ExcelUtil<BizCustomerShop> util = new ExcelUtil<BizCustomerShop>(BizCustomerShop.class);
        util.exportExcel(response, list, "门店数据");
    }

    /**
     * 获取门店详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCustomerShopService.selectBizCustomerShopById(id));
    }

    /**
     * 新增门店
     */
    @PreAuthorize("@ss.hasPermi('biz:shop:add')")
    @Log(title = "门店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCustomerShop bizCustomerShop)
    {
        return toAjax(bizCustomerShopService.insertBizCustomerShop(bizCustomerShop));
    }

    /**
     * 修改门店
     */
    @PreAuthorize("@ss.hasPermi('biz:shop:edit')")
    @Log(title = "门店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCustomerShop bizCustomerShop)
    {
        return toAjax(bizCustomerShopService.updateBizCustomerShop(bizCustomerShop));
    }

    /**
     * 删除门店
     */
    @PreAuthorize("@ss.hasPermi('biz:shop:remove')")
    @Log(title = "门店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCustomerShopService.deleteBizCustomerShopByIds(ids));
    }
}
