package com.cirle.scientific.controller.miniapp;/*
 *24901
 *2022/12/21
 *10:50
 */

import com.cirle.scientific.po.QkjPatientApp;
import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.PatientAppService;
import com.cirle.scientific.utils.QRCodeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 24901
 */
@Controller
@RequestMapping("/app/PatientApp")
@Api("app扫描二维码填写患者信息接口")
public class PatientAppController {

    private PatientAppService patientAppService;

    @Autowired
    public void setPatientAppService(PatientAppService patientAppService) {
        this.patientAppService = patientAppService;
    }

    @GetMapping("/jumpPage")
    @ApiOperation(value = "跳转页面接口")
    public String jumpPage(){
        return "html5/index/index";
    }

    @GetMapping("/jumpPage/question")
    @ApiOperation(value = "跳转页面接口")
    public String jumpPageRub(){
        return "html5/index/question";
    }

    @GetMapping("/createQrCode")
    @ResponseBody
    @ApiOperation(value = "创建二维码")
    public Result createQrCode(@RequestParam(name = "content") String content) throws Exception {
        if(null == content){
            return Result.failed("请填写二维码内容");
        }
        return Result.success(QRCodeUtil.createQr(content, 300, 300, 1, "http://files.qkyxzx.com/test/conference/20230105/4adc1706383142757e2e26e85d63c0b-20230105164929.png"));
    }

    @GetMapping("/findPatient")
    @ResponseBody
    @ApiOperation(value = "扫描二维码之后获取保存患者信息接口")
    public Result patientMes(@ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(name = "memCard", required = false)  String memCard,
                             @RequestParam(name = "objType") Integer objType,
                             @RequestParam(name = "objId") Integer objId){
//        if(null == memCard){
//            return Result.failed("用户未登录");
//        }
        QkjPatientApp patient = patientAppService.findPatient(memCard, objType, objId);
        return Result.success(patient);
    }

    @PostMapping("/patientMes")
    @ResponseBody
    @ApiOperation(value = "扫描二维码之后保存患者信息接口")
    public Result patientMes(@ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(name = "memCard", required = false)  String memCard, @RequestBody QkjPatientApp qkjPatientApp){
        qkjPatientApp.setMemCard(memCard);
        Integer patient = patientAppService.createPatient(qkjPatientApp);
        return Result.success(patient);
    }


}
