package cn.iocoder.yudao.module.rescue.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.rescue.core.controller.BaseController;
import cn.iocoder.yudao.module.rescue.domain.RescueCustomerInfo;
import cn.iocoder.yudao.module.rescue.service.IRescueCustomerInfoService;
import cn.iocoder.yudao.module.rescue.utils.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 救援的客户信息Controller
 *
 * @author zcy
 * @date 2023-09-14
 */
@RestController
@RequestMapping("/rescueCustomer/rescueCustomer")
public class RescueCustomerInfoController extends BaseController {
    @Autowired
    private IRescueCustomerInfoService rescueCustomerInfoService;

    /**
     * 查询救援的客户信息列表
     */
    @PreAuthorize("@ss.hasPermission('rescueCustomer:rescueCustomer:list')")
    @GetMapping("/list")
    public CommonResult<IPage<?>> list(RescueCustomerInfo rescueCustomerInfo,
                                    @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<RescueCustomerInfo> page = new Page<>(pageNo, pageSize);
        IPage<RescueCustomerInfo> list = rescueCustomerInfoService.selectRescueCustomerInfoList(rescueCustomerInfo, page);
        return success(list);
    }

    /**
     * 导出救援的客户信息列表
     */
    @PreAuthorize("@ss.hasPermission('rescueCustomer:rescueCustomer:list')")
//    @Log(title = "救援的客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueCustomerInfo rescueCustomerInfo) {
        List<RescueCustomerInfo> list = rescueCustomerInfoService.list();
        ExcelUtil<RescueCustomerInfo> util = new ExcelUtil<RescueCustomerInfo>(RescueCustomerInfo.class);
        util.exportExcel(response, list, "救援的客户信息数据");
    }

    /**
     * 获取救援的客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermission('rescueCustomer:rescueCustomer:list')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id) {
        return success(rescueCustomerInfoService.selectRescueCustomerInfoById(id));
    }

    /**
     * 新增救援的客户信息
     */
    @PreAuthorize("@ss.hasPermission('rescueCustomer:rescueCustomer:list')")
//    @Log(title = "救援的客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody RescueCustomerInfo rescueCustomerInfo) {
        return toAjax(rescueCustomerInfoService.insertRescueCustomerInfo(rescueCustomerInfo));
    }

    /**
     * 修改救援的客户信息
     */
    @PreAuthorize("@ss.hasPermission('rescueCustomer:rescueCustomer:list')")
//    @Log(title = "救援的客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody RescueCustomerInfo rescueCustomerInfo) {
        return toAjax(rescueCustomerInfoService.updateRescueCustomerInfo(rescueCustomerInfo));
    }

    /**
     * 删除救援的客户信息
     */
    @PreAuthorize("@ss.hasPermission('rescueCustomer:rescueCustomer:list')")
//    @Log(title = "救援的客户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return toAjax(rescueCustomerInfoService.deleteRescueCustomerInfoByIds(ids));
    }
}

