package thyyxxk.webserver.controller.examinations;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.examinations.inspections.request.ReportIndexInquiry;
import thyyxxk.webserver.entity.examinations.lisdock.HealthCardResult;
import thyyxxk.webserver.entity.examinations.lisdock.PushResultParam;
import thyyxxk.webserver.entity.examinations.inspections.response.JyIndexResponse;
import thyyxxk.webserver.service.examinations.LisDockService;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @author dj
 */
@RestController
@RequestMapping("/lisDock")
public class LisDockController {
    private final LisDockService service;

    @Autowired
    public LisDockController(LisDockService service) {
        this.service = service;
    }

    @PostMapping("/scanBarCode")
    public ResultVo<Map<String, Object>> scanBarCode(@RequestBody ReportIndexInquiry param) throws Exception {
        return service.scanBarCode(param);
    }

    @PostMapping("/getIndexByTjNo")
    public ResultVo<List<JyIndexResponse>> getIndexByTjNo(@RequestBody ReportIndexInquiry param) throws Exception {
        return service.getIndexByTjNo(param);
    }

    @PostMapping("/pushSelectedResult")
    public ResultVo<Map<String, String>> pushSelectedResult(@RequestBody PushResultParam param) throws ExecutionException, InterruptedException {
        return service.pushSelectedResult(param);
    }

    @PassToken
    @GetMapping("/pushResult")
    public JSONObject pushResult() {
        String jsonstr = "{\n" +
                "\"timeStamp\": \"1636592613865\",\n" +
                "\"itemResults\": [\n" +
                "{\n" +
                "\"opter\": \"沈湘云\",\n" +
                "\"reference\": \"\",\n" +
                "\"result\": \"阴性(－)\",\n" +
                "\"itemName\": \"新型冠状病毒感染性肺炎\",\n" +
                "\"unit\": \"\",\n" +
                "\"auditTime\": \"2021-11-09\",\n" +
                "\"itemCode\": \"JK03\",\n" +
                "\"testTime\": \"2021-11-09\",\n" +
                "\"auditOpter\": \"陈刘旭\",\n" +
                "\"status\": \"0\"\n" +
                "}\n" +
                "],\n" +
                "\"signature\": \"7ec41e0f01b6fe210f433cf121bb59ac\",\n" +
                "\"appId\": \"jkzd5e26bf01c5a0d79\",\n" +
                "\"customerInfo\": {\n" +
                "\"idCard\": \"430224200011080009\",\n" +
                "\"sex\": \"女\",\n" +
                "\"name\": \"王五司\",\n" +
                "\"reportUrl\": \"https://staticweb.hnthyy.cn/inspections/211108146000083-729301168284567552.jpg\",\n" +
                "\"type\": \"2\",\n" +
                "\"age\": \"21\",\n" +
                "\"barCode\": \"211111146000001\"\n" +
                "}\n" +
                "}";
        HealthCardResult entity = JSONObject.parseObject(jsonstr, HealthCardResult.class);
        return service.pushResult(entity);
    }
}
