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.RescueConfig;
import cn.iocoder.yudao.module.rescue.service.IRescueConfigService;
import cn.iocoder.yudao.module.rescue.utils.ExcelUtil;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 救援司机提成配置Controller
 *
 * @author zcy
 * @date 2023-12-01
 */
@RestController
@RequestMapping("/rescue/rescueConfig")
public class RescueConfigController extends BaseController {
    @Resource
    private IRescueConfigService rescueConfigService;

    @Resource
    private AdminUserApi adminUserApi;

    /**
     * 查询救援司机提成配置列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueConfig:list')")
    @GetMapping("/list")
    public CommonResult list(RescueConfig rescueConfig,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<RescueConfig> page = new Page<>(pageNum, pageSize);
        IPage<RescueConfig> list = rescueConfigService.selectRescueConfigList(page,rescueConfig);
        return success(list);
    }

    /**
     * 导出救援司机提成配置列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueConfig:export')")
//    @Log(title = "救援司机提成配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueConfig rescueConfig,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<RescueConfig> page = new Page<>(pageNum, pageSize);
        IPage<RescueConfig> list = rescueConfigService.selectRescueConfigList(page,rescueConfig);
        ExcelUtil<RescueConfig> util = new ExcelUtil<RescueConfig>(RescueConfig.class);
        util.exportExcel(response, list.getRecords(), "救援司机提成配置数据");
    }

    /**
     * 获取救援司机提成配置详细信息
     */
    @GetMapping(value = "/getInfo")
    public CommonResult getInfo() {
        return success(rescueConfigService.selectRescueConfigByDeptId());
    }

    /**
     * 新增救援司机提成配置
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueConfig:add')")
//    @Log(title = "救援司机提成配置", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody RescueConfig rescueConfig) {
        return toAjax(rescueConfigService.insertRescueConfig(rescueConfig));
    }

    /**
     * 修改救援司机提成配置
     */
//    @PreAuthorize("@ss.hasPermission('rescue:rescueConfig:edit')")
//    @Log(title = "救援司机提成配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody RescueConfig rescueConfig) {
        return toAjax(rescueConfigService.updateRescueConfig(rescueConfig));
    }

    /**
     * 删除救援司机提成配置
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueConfig:remove')")
//    @Log(title = "救援司机提成配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return toAjax(rescueConfigService.deleteRescueConfigByIds(ids));
    }
}
