package com.yida.data.school.smart.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeGuideRoster;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeGuideRosterRelation;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeGuideStep;
import com.yida.data.school.dto.smart.AddUploadFileStepDTO;
import com.yida.data.school.dto.smart.StaffPassStepDTO;
import com.yida.data.school.dto.smart.h5.CreateGuideStepOrderDTO;
import com.yida.data.school.dto.smart.h5.RosterFaceMatchDTO;
import com.yida.data.school.dto.smart.h5.RosterPageDTO;
import com.yida.data.school.smart.service.EduSmartWelcomeGuideRosterService;
import com.yida.data.school.smart.service.EduSmartWelcomeGuideStepService;
import com.yida.data.school.smart.service.H5EduSmartWelcomeService;
import com.yida.data.school.vo.smart.h5.RosterFaceMatchVO;
import com.yida.data.school.vo.smart.h5.RosterStepPayInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 智慧迎新api
 *
 * @author ZYJ
 * @date 2023-05-15 15:33:18
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "智慧迎新api(登录后接口)")
@RequestMapping("/h5/eduSmartWelcomeGuide")
public class H5EduSmartWelcomeController {

    private final H5EduSmartWelcomeService h5EduSmartWelcomeService;
    private final EduSmartWelcomeGuideStepService eduSmartWelcomeGuideStepService;
    private final EduSmartWelcomeGuideRosterService eduSmartWelcomeGuideRosterService;

    @PostMapping("/addUploadFile")
    @ApiOperation("提交上传附件(家长端使用)")
    ResultBean addUploadFile(@RequestBody AddUploadFileStepDTO dto) {
        eduSmartWelcomeGuideStepService.addUploadFile(dto);
        return ResultBean.buildSuccess();
    }


    @GetMapping("/getStudentStepInfo")
    @ApiOperation("查询学生步骤信息列表(家长端使用)")
    ResultBean<List<EduSmartWelcomeGuideStep>> getStudentStepInfo(
        @RequestParam @ApiParam(value = "关联关系id", required = true) Long relationId,
        @RequestParam @ApiParam(value = "指南id", required = true) Long guideId) {
        return ResultBean.buildSuccess(eduSmartWelcomeGuideStepService.listStepInfo(relationId, guideId));
    }

    @GetMapping("/staff/getRosterInfo")
    @ApiOperation("职工扫码后查询花名册人员详细信息")
    ResultBean<EduSmartWelcomeGuideRosterRelation> getRosterInfo(
        @RequestParam @ApiParam(value = "花名册id", required = true) Long rosterId,
        @RequestParam @ApiParam(value = "职工id", required = true) Long staffId) {
        return ResultBean.buildSuccess(eduSmartWelcomeGuideRosterService.getRosterInfo(rosterId, staffId));
    }

    @PostMapping(value = "/staff/passStep", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "职工通过步骤", consumes = MediaType.APPLICATION_JSON_VALUE)
    ResultBean<String> passStep(@RequestBody StaffPassStepDTO dto) {
        eduSmartWelcomeGuideRosterService.passStep(dto);
        return ResultBean.buildSuccess();
    }

    @GetMapping(value = "/staff/getPayQrCodeUrl")
    @ApiOperation(value = "职工获取缴费二维码地址")
    ResultBean<String> getPayQrCodeUrl(@RequestParam Long deptId) {
        return ResultBean.buildSuccess(h5EduSmartWelcomeService.getPayQrCodeUrl(deptId));
    }

    @PostMapping("/createGuideStepOrder")
    @ApiOperation("生成迎新步骤订单")
    public ResultBean<RosterStepPayInfoVO> createGuideStepOrder(@RequestBody CreateGuideStepOrderDTO dto) {
        return ResultBean.buildSuccess(h5EduSmartWelcomeService.createGuideStepOrder(dto));
    }

    @GetMapping("/guideStepOrderSuccess")
    @ApiOperation("迎新步骤订单完成(前台支付完成后调用)")
    public ResultBean<String> guideStepOrderSuccess(
        @ApiParam(value = "订单号", required = true) @RequestParam String orderCode) {
        h5EduSmartWelcomeService.guideStepOrderSuccess(orderCode);
        return ResultBean.buildSuccess();
    }

    @PostMapping("/rosterFaceMatch")
    @ApiOperation("花名册人脸对比")
    public ResultBean<RosterFaceMatchVO> rosterFaceMatch(@RequestBody RosterFaceMatchDTO dto) {
        return ResultBean.buildSuccess(h5EduSmartWelcomeService.rosterFaceMatch(dto));
    }

    @GetMapping("/getUserQrCodeUrl")
    @ApiOperation("获取花名册二维码")
    public ResultBean<EduSmartWelcomeGuideRoster> getUserQrCodeUrl(@RequestParam Long rosterId) {
        return ResultBean.buildSuccess(h5EduSmartWelcomeService.getUserQrCodeUrl(rosterId));
    }

    @PostMapping("/listRoster")
    @ApiOperation("根据名称查询花名册列表信息")
    public ResultBean<IPage<EduSmartWelcomeGuideRosterRelation>> listRoster(@RequestBody RosterPageDTO dto) {
        return ResultBean.buildSuccess(h5EduSmartWelcomeService.listRoster(dto));
    }
}
