package com.ruoyi.web.controller.api.xcxManager;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.CSMemberUserLoginToken;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.dto.CsApprovalRecordCheckDTO;
import com.ruoyi.cs.domain.dto.MemberResOrderApplyQueryDTO;
import com.ruoyi.cs.domain.dto.XcxApprovalListDTO;
import com.ruoyi.cs.domain.vo.MemberCsResourceOrderApplyVO;
import com.ruoyi.cs.domain.vo.XcxCsOrderApplyVO;
import com.ruoyi.cs.domain.vo.XcxResOrderApplyDetailVO;
import com.ruoyi.cs.service.ICsApprovalConfigService;
import com.ruoyi.cs.service.ICsResourceOrderApplyService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: cc
 * @Date: 2024/5/11
 * @Description: 小程序工单接口
 */
@Api("小程序管理端/审核流")
@RestController
@RequestMapping("/xcx/apply")
public class ApiXcxApprovalController extends BaseController {

    @Resource
    private ICsResourceOrderApplyService resourceOrderApplyService;

    @Resource
    private ICsApprovalConfigService csApprovalConfigService;

    /**
     *  工单列表
     * @return 结果
     */
    @GetMapping("/getApprovalList")
    public AjaxResult getApprovalList(XcxApprovalListDTO paramDto,
                                      @RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<XcxCsOrderApplyVO> result = resourceOrderApplyService.selectOrderApplyListForXcx(paramDto);
        return AjaxResult.success( new PageInfo<>(result));
    }

    /**
     *  工单详情
     * @return 结果
     */
    @GetMapping("/getApplyDetail")
    public AjaxResult getApplyDetail(XcxApprovalListDTO paramDto){
        XcxResOrderApplyDetailVO result = resourceOrderApplyService.selectOrderApplyDetailForXcx(paramDto);
        return AjaxResult.success(result);
    }

    /**
     * 提交审核(审核流程)
     */
    @PostMapping("/checkConfigs")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    public AjaxResult checkConfigs(@RequestBody CsApprovalRecordCheckDTO dto)
    {
        return toAjax(csApprovalConfigService.checkFlowNode(dto));
    }

    /**
     *  消息
     * @return 结果
     */
    @GetMapping("/getMsgList")
    public AjaxResult getMsgList(@RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize){
        return AjaxResult.success(resourceOrderApplyService.getMsgList(pageNum,pageSize));
    }
}
