package org.dromara.payment.sys.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.payment.sys.domain.vo.SysSydProductVo;
import org.dromara.payment.sys.service.ISysSydProductService;
import org.dromara.system.api.model.LoginUser;
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.sys.domain.bo.SysSydProductBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 服务商产品
 * 前端访问路由地址为:/payment/sydProduct
 *
 * @author LionLi
 * @date 2024-03-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sydProduct")
public class SysSydProductController extends BaseController {

    private final ISysSydProductService sysSydProductService;

    /**
     * 查询服务商产品列表
     */
    //@SaCheckPermission("payment:sydProduct:list")
    @GetMapping("/list")
    public TableDataInfo<SysSydProductVo> list(SysSydProductBo bo, PageQuery pageQuery) {
        return sysSydProductService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/queryList")
    public R<List<SysSydProductVo>> queryList(SysSydProductBo bo) {
        return R.ok(sysSydProductService.queryList(bo));
    }

    /**
     * 导出服务商产品列表
     */
    //@SaCheckPermission("payment:sydProduct:export")
    @Log(title = "服务商产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysSydProductBo bo, HttpServletResponse response) {
        List<SysSydProductVo> list = sysSydProductService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务商产品", SysSydProductVo.class, response);
    }

    /**
     * 获取服务商产品详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("payment:sydProduct:query")
    @GetMapping("/{id}")
    public R<SysSydProductVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysSydProductService.queryById(id));
    }

    /**
     * 新增服务商产品
     */
    //@SaCheckPermission("payment:sydProduct:add")
    @Log(title = "服务商产品", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysSydProductBo bo) {
        LoginUser loginUser = LoginHelper.getLoginUser();
//        bo.setSydId(loginUser.getBusId());
//        bo.setSydNo(loginUser.getBusNo());
        return toAjax(sysSydProductService.insertByBo(bo));
    }

    /**
     * 修改服务商产品
     */
    //@SaCheckPermission("payment:sydProduct:edit")
    @Log(title = "服务商产品", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysSydProductBo bo) {
        return toAjax(sysSydProductService.updateByBo(bo));
    }

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





    @PutMapping("/upDown")
    @Log(title = "服务商产品上下架", businessType = BusinessType.UPDATE)
    public R<Boolean> upDown(Long id,Integer status){
        return R.ok(this.sysSydProductService.upDown(id,status));
    }
}
