package com.taais.demo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.core.utils.poi.ExcelUtil;
import com.taais.common.web.core.BaseController;
import com.taais.demo.domain.DemoCustomer;
import com.taais.demo.service.IDemoCustomerService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户主表(mb)Controller
 *
 * @author wgk
 * 2023-07-11
 */
@RestController
@RequestMapping("/demo/customer")
public class DemoCustomerController extends BaseController {
    @Resource
    private IDemoCustomerService demoCustomerService;

    /**
     * 查询客户主表(mb)列表
     */
    @SaCheckPermission("demo:customer:list")
    @GetMapping("/list")
    public CommonResult<List<DemoCustomer>> list(DemoCustomer demoCustomer) {
        List<DemoCustomer> list = demoCustomerService.selectDemoCustomerList(demoCustomer);
        return CommonResult.success(list);
    }

    /**
     * 导出客户主表(mb)列表
     */
    @SaCheckPermission("demo:customer:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoCustomer demoCustomer) {
        List<DemoCustomer> list = demoCustomerService.selectDemoCustomerList(demoCustomer);
        ExcelUtil<DemoCustomer> util = new ExcelUtil<>(DemoCustomer.class);
        util.exportExcel(response, list, "客户主表(mb)数据");
    }

    /**
     * 获取客户主表(mb)详细信息
     */
    @SaCheckPermission("demo:customer:query")
    @GetMapping(value = "/{customerId}")
    public CommonResult<DemoCustomer> getInfo(@PathVariable("customerId") Long customerId) {
        return CommonResult.success(demoCustomerService.selectDemoCustomerByCustomerId(customerId));
    }

    /**
     * 新增客户主表(mb)
     */
    @SaCheckPermission("demo:customer:add")
    @PostMapping
    public CommonResult<Integer> add(@RequestBody DemoCustomer demoCustomer) {
        return CommonResult.success(demoCustomerService.insertDemoCustomer(demoCustomer));
    }

    /**
     * 修改客户主表(mb)
     */
    @SaCheckPermission("demo:customer:edit")
    @PutMapping
    public CommonResult<Integer> edit(@RequestBody DemoCustomer demoCustomer) {
        return CommonResult.success(demoCustomerService.updateDemoCustomer(demoCustomer));
    }

    /**
     * 删除客户主表(mb)
     */
    @SaCheckPermission("demo:customer:remove")
    @DeleteMapping("/{customerIds}")
    public CommonResult<Integer> remove(@PathVariable Long[] customerIds) {
        return CommonResult.success(demoCustomerService.deleteDemoCustomerByCustomerIds(customerIds));
    }
}
