package org.dromara.payment.channel.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.payment.channel.mapper.BusChannelSalesmanMapper;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.payment.channel.domain.vo.BusChannelSalesmanVo;
import org.dromara.payment.channel.domain.bo.BusChannelSalesmanBo;
import org.dromara.payment.channel.service.IBusChannelSalesmanService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 代理商业务员
 * 前端访问路由地址为:/payment/channelSalesman
 *
 * @author LionLi
 * @date 2024-04-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/channelSalesman")
public class BusChannelSalesmanController extends BaseController {

    private final IBusChannelSalesmanService busChannelSalesmanService;

    private final BusChannelSalesmanMapper  salesmanMapper;



    @RequestMapping("/test")
    public R<Void> test(){
         R.ok(salesmanMapper.selectDataTest());
         return this.toAjax(1);
    }

    /**
     * 查询代理商业务员列表
     */
    @SaCheckPermission("payment:channelSalesman:list")
    @GetMapping("/list")
    public TableDataInfo<BusChannelSalesmanVo> list(BusChannelSalesmanBo bo, PageQuery pageQuery) {
        return busChannelSalesmanService.selectSaleMans(bo, pageQuery);
    }

    /***
     * @Param
     * @Return
     * @Author sunzexing
     * @Date 2024-04-20 11:41
     * 说明： 查询业务员集合不分页
     **/
    @GetMapping("/ywyList")
    @SaCheckPermission("payment:channelSalesman:ywyList")
    public R<List<BusChannelSalesmanVo>> list(BusChannelSalesmanBo bo) {
        return R.ok(busChannelSalesmanService.queryList(bo));
    }


    /**
     * 导出代理商业务员列表
     */
    @SaCheckPermission("payment:channelSalesman:export")
    @Log(title = "代理商业务员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusChannelSalesmanBo bo, HttpServletResponse response) {
        List<BusChannelSalesmanVo> list = busChannelSalesmanService.queryList(bo);
        ExcelUtil.exportExcel(list, "代理商业务员", BusChannelSalesmanVo.class, response);
    }

    /**
     * 获取代理商业务员详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("payment:channelSalesman:query")
    @GetMapping("/{id}")
    public R<BusChannelSalesmanVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(busChannelSalesmanService.queryById(id));
    }

    /**
     * 新增代理商业务员
     */
    @SaCheckPermission("payment:channelSalesman:add")
    @Log(title = "代理商业务员", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class)  BusChannelSalesmanBo bo) {
        return toAjax(busChannelSalesmanService.insertByBo(bo));
    }

    /**
     * 修改代理商业务员
     */
    @SaCheckPermission("payment:channelSalesman:edit")
    @Log(title = "代理商业务员", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class)  BusChannelSalesmanBo bo) {
        return toAjax(busChannelSalesmanService.updateByBo(bo));
    }

    /**
     * 删除代理商业务员
     *
     * @param ids 主键串
     */
    @SaCheckPermission("payment:channelSalesman:remove")
    @Log(title = "代理商业务员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busChannelSalesmanService.deleteWithValidByIds(List.of(ids), true));
    }
}
