package com.yida.data.school.visitor.controller.h5;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.visitor.EduVisitorRecord;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.visitor.ListVisitorRecordToStaffDTO;
import com.yida.data.school.visitor.service.EduVisitorRecordService;
import com.yida.data.school.vo.visitor.ListVisitorRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "访客管理-访客记录(前台)")
@Slf4j
@Validated
@RestController
@RequestMapping("/h5/visitor/record")
@RequiredArgsConstructor
public class H5EduVisitorRecordController {

    private final EduVisitorRecordService eduVisitorRecordService;

    @ApiOperation("生成邀请码")
    @GetMapping("/generateInviteCode")
    public ResultBean<String> generateInviteCode() {
        Long schoolId = FebsUtil.getTopDeptId();
        return ResultBean.buildSuccess(eduVisitorRecordService.generateInviteCode(schoolId));
    }

    @ApiOperation("查询教职工未处理的申请数量")
    @GetMapping("/countNotDealRecord")
    public ResultBean<Long> countNotDealRecord(Long staffId) {
        return ResultBean.buildSuccess(eduVisitorRecordService.count(Wrappers.<EduVisitorRecord>lambdaQuery()
            .eq(EduVisitorRecord::getStaffId, staffId)
            .eq(EduVisitorRecord::getResult, 0)));
    }

    @ApiOperation("查询对教职工的访问")
    @GetMapping("/listRecordToStaffPage")
    public ResultBean<IPage<ListVisitorRecordVO>> listRecordToStaffPage(ListVisitorRecordToStaffDTO dto) {
        return ResultBean.buildSuccess(eduVisitorRecordService.listRecordToStaff(dto));
    }

    @ApiOperation("改变访客申请的处理结果")
    @GetMapping("/changeResult")
    public ResultBean changeResult(Long id, Integer result, String reason) {
        eduVisitorRecordService.changeResult(id, result, reason);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("提交访客入校(保安)")
    @GetMapping("/visitorInSchool")
    public ResultBean visitorInSchool(@ApiParam("安保人员id") Long staffId,
        @ApiParam("记录id") Long recordId,
        @ApiParam("体温") Double temp) {
        eduVisitorRecordService.visitorInSchool(staffId, recordId, temp);
        return ResultBean.buildSuccess();
    }


    @ApiOperation("提交访客出校(保安)")
    @GetMapping("/visitorOutSchool")
    public ResultBean visitorOutSchool(@ApiParam("安保人员id") Long staffId,
        @ApiParam("记录id") Long recordId) {
        eduVisitorRecordService.visitorOutSchool(staffId, recordId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("根据邀请码查询详情")
    @GetMapping("/getInfo")
    public ResultBean getInfo(@ApiParam("邀请码") String inviteCode) {
        return ResultBean.buildSuccess(eduVisitorRecordService.getInfoByInviteCode(inviteCode));
    }
}
