package com.pusong.business.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import com.pusong.business.domain.vo.PsRefundVo;
import com.pusong.business.service.IPsContractInfoService;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.pusong.common.idempotent.annotation.RepeatSubmit;
import com.pusong.common.log.annotation.Log;
import com.pusong.common.web.core.BaseController;
import com.pusong.common.mybatis.core.page.PageQuery;
import com.pusong.common.core.domain.R;
import com.pusong.common.core.validate.AddGroup;
import com.pusong.common.core.validate.EditGroup;
import com.pusong.common.log.enums.BusinessType;
import com.pusong.common.excel.utils.ExcelUtil;
import com.pusong.business.domain.vo.PsContractPayVo;
import com.pusong.business.domain.bo.PsContractPayBo;
import com.pusong.business.service.IPsContractPayService;
import com.pusong.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 合同回款记录
 *
 * @author wls
 * @date 2024-08-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/contractPay")
@SaIgnore
public class PsContractPayController extends BaseController {

    private final IPsContractPayService psContractPayService;
    private final IPsContractInfoService contractInfoService;

  /**
     * 查询合同回款记录列表
     */
    @SaCheckPermission("business:contractPay:list")
    @GetMapping("/list")
    public R<List<PsContractPayVo>> list(@NotBlank(message = "合同编码不能为空") String contractCode) {
        return R.ok(psContractPayService.queryAllListByContractCode(contractCode));
    }
    /**
     * 获取合同回款记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:contractPay:query")
    @GetMapping("/{id}")
    public R<PsContractPayVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long id) {
        return R.ok(psContractPayService.queryById(id));
    }


    /**
     *  退款列表查询
     * @param customManageName 客户经理
     * @param companyName 公司名
     * @param mobile 电话
     * @param name 客户名
     * @param payStatus 支付状态
     * @param pageQuery
     * @return
     */
    @SaCheckPermission("business:contractPay:query")
    @GetMapping("/queryRefundList")
    public TableDataInfo<PsRefundVo> queryRefundList(String customManageName,String companyName,String mobile,String name, String payStatus,PageQuery pageQuery) {
        return psContractPayService.queryRefundList(customManageName,companyName,mobile,name,pageQuery,payStatus);
    }
    /**
     * 完成退款
     * @param files 附件图片
     * @param id 任务id
     * @return
     */
    @RepeatSubmit()
    @SaCheckPermission("business:contractPay:query")
    @PostMapping(value = "/refundFinish",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Void> refundFinish(@RequestPart("files") List<MultipartFile> files, @NotNull  Long id) {
        contractInfoService.dealReturn(psContractPayService.refundFinish(files,id));
        return R.ok();
    }

    /**
     * 导出合同回款记录列表
     *//*
    @SaCheckPermission("business:contractPay:export")
    @Log(title = "合同回款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PsContractPayBo bo, HttpServletResponse response) {
        List<PsContractPayVo> list = psContractPayService.queryList(bo);
        ExcelUtil.exportExcel(list, "合同回款记录", PsContractPayVo.class, response);
    }

    *//**
     * 获取合同回款记录详细信息
     *
     * @param id 主键
     *//*
    @SaCheckPermission("business:contractPay:query")
    @GetMapping("/{id}")
    public R<PsContractPayVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(psContractPayService.queryById(id));
    }

    *//**
     * 新增合同回款记录
     *//*
    @SaCheckPermission("business:contractPay:add")
    @Log(title = "合同回款记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PsContractPayBo bo) {
        return toAjax(psContractPayService.insertByBo(bo));
    }

    *//**
     * 修改合同回款记录
     *//*
    @SaCheckPermission("business:contractPay:edit")
    @Log(title = "合同回款记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PsContractPayBo bo) {
        return toAjax(psContractPayService.updateByBo(bo));
    }

    *//**
     * 删除合同回款记录
     *
     * @param ids 主键串
     *//*
    @SaCheckPermission("business:contractPay:remove")
    @Log(title = "合同回款记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(psContractPayService.deleteWithValidByIds(List.of(ids), true));
    }*/
}
