package com.ruoyi.database.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.database.domain.BaseCustomerInfo;
import com.ruoyi.database.service.BaseCustomerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/BaseCustomerInfo")
@Api(tags = "客户管理")
@RestController
@RequiredArgsConstructor
public class BaseCustomerInfoController extends BaseController {

    private final BaseCustomerInfoService baseCustomerInfoService;

    @GetMapping
    @ApiOperation("基础管理-查询客户管理")
    public TableDataInfo<BaseCustomerInfo> list(BaseCustomerInfo baseCustomerInfo) {
        startPage();
        QueryWrapper<BaseCustomerInfo> queryWrapper = new QueryWrapper<>(baseCustomerInfo);
        List<BaseCustomerInfo> list = baseCustomerInfoService.list(queryWrapper);
        long size = baseCustomerInfoService.count(queryWrapper);
        return getDataTableEnhance(list,size);
    }

    @PostMapping
    @ApiOperation("基础管理-新增客户管理")
    @Log(title = "客户管理表", businessType = BusinessType.INSERT)
    public AjaxResult insert(@RequestBody BaseCustomerInfo baseCustomerInfo) {
        return toAjax(baseCustomerInfoService.save(baseCustomerInfo));
    }

    @PutMapping
    @ApiOperation("基础管理-修改客户管理")
    @Log(title = "客户管理表", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody BaseCustomerInfo baseCustomerInfo) {
        return toAjax(baseCustomerInfoService.updateById(baseCustomerInfo));
    }

    @DeleteMapping
    @ApiOperation("基础管理-删除客户管理")
    @Log(title = "客户管理表", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return toAjax(baseCustomerInfoService.removeByIds(idList));
    }
}
