package com.pusong.business.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
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.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.PsApproverRecordVo;
import com.pusong.business.domain.bo.PsApproverRecordBo;
import com.pusong.business.service.IPsApproverRecordService;
import com.pusong.common.mybatis.core.page.TableDataInfo;

/**
 * 审批记录
 *
 * @author wls
 * @date 2024-08-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/approverRecord")
@SaIgnore
public class PsApproverRecordController extends BaseController {

    private final IPsApproverRecordService psApproverRecordService;
    private final IPsContractInfoService contractInfoService;

    /**
     * 查询审批记录列表
     */
    @SaCheckPermission("business:approverRecord:list")
    @GetMapping("/list")
    public TableDataInfo<PsApproverRecordVo> list(PsApproverRecordBo bo, PageQuery pageQuery) {
        return psApproverRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 审批
     *
     * @param operate （2 通过 3拒绝）
     * @param id 审批表id
     * @param desc 备注（通过/拒绝原因）
     * @return
     */
    @SaCheckPermission("business:approverRecord:list")
    @RepeatSubmit()
    @GetMapping("/approver")
    public R<Void> approver(@NotBlank(message = "操作类型不能为空") String operate,
                            @NotNull(message = "数据id不能为空") Long id, String desc) {
        contractInfoService.finish(psApproverRecordService.approver(operate, id, desc));
        return R.ok();
    }

//    /**
//     * 导出审批记录列表
//     */
//    @SaCheckPermission("business:approverRecord:export")
//    @Log(title = "审批记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(PsApproverRecordBo bo, HttpServletResponse response) {
//        List<PsApproverRecordVo> list = psApproverRecordService.queryList(bo);
//        ExcelUtil.exportExcel(list, "审批记录", PsApproverRecordVo.class, response);
//    }

    /**
     * 获取审批记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:approverRecord:query")
    @GetMapping("/getById")
    public R<PsApproverRecordVo> getInfo(@NotNull(message = "主键不能为空") Long id) {
        return R.ok(psApproverRecordService.queryById(id));
    }

/*    *//**
     * 新增审批记录
     *//*
    @SaCheckPermission("business:approverRecord:add")
    @Log(title = "审批记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PsApproverRecordBo bo) {
        return toAjax(psApproverRecordService.insertByBo(bo));
    }*/

//    /**
//     * 修改审批记录
//     */
//    @SaCheckPermission("business:approverRecord:edit")
//    @Log(title = "审批记录", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PsApproverRecordBo bo) {
//        return toAjax(psApproverRecordService.updateByBo(bo));
//    }

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