package com.mortals.xhx.busiz.web;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq;
import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo;
import com.mortals.xhx.module.hik.door.service.IHikDoorService;
import com.mortals.xhx.module.hik.event.model.rsp.EventInfo;
import com.mortals.xhx.module.hik.event.service.IHikEventService;
import com.mortals.xhx.module.hik.person.model.req.org.OrgListReq;
import com.mortals.xhx.module.hik.person.model.req.person.PersonReq;
import com.mortals.xhx.module.hik.person.model.rsp.org.OrgDataInfo;
import com.mortals.xhx.module.hik.person.model.rsp.person.PersonDataInfo;
import com.mortals.xhx.module.hik.person.service.IHikPersonService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 设备
 *
 * @author: zxfei
 * @date: 2021/8/24 20:28
 */
@RestController
@Slf4j
@RequestMapping("/test")
public class TestController {

    @Autowired
    private IHikPersonService hikPersonService;
    @Autowired
    private IHikDoorService hikDoorService;
    @Autowired
    private IHikEventService hikEventService;

    
    @GetMapping("webservice")
    public String webservice() {
        log.info("测试");
        return "ok";
    }
    @PostMapping("getPersonList")
    public String getPersonList(@RequestBody PersonReq personReq) {
        Rest<PersonDataInfo> personList = hikPersonService.getPersonList(personReq);
        return JSON.toJSONString(personList);
    }

    @PostMapping("getOrgList")
    public String getOrgList(@RequestBody OrgListReq orgListReq) {
        Rest<OrgDataInfo> orgList = hikPersonService.getOrgList(orgListReq);
        return JSON.toJSONString(orgList);
    }

    @PostMapping("getDoorEvents")
    public String getDoorEvents(@RequestBody DoorEventReq doorEventReq) {
        Rest<DoorEventDataInfo> doorEvents = hikDoorService.getDoorEvents(doorEventReq);
        return JSON.toJSONString(doorEvents);
    }

    @PostMapping("getEvents")
    public String getEvents() {
        Rest<List<EventInfo>> events = hikEventService.getEvents();
        return JSON.toJSONString(events);
    }




    public static void main(String[] args) {

        DoorEventReq doorEventReq = new DoorEventReq();

        doorEventReq.setStartTime(new Date());
        System.out.println(JSON.toJSONString(doorEventReq));

        String json="{\"startTime\":\"2023-04-13T10:48:22+08:00\"}";


        DoorEventReq doorEventReq1 = JSON.parseObject(json, DoorEventReq.class);

        System.out.println(DateUtils.convertTime2Str(doorEventReq1.getStartTime().getTime(),DateUtils.P_yyyy_MM_dd_HH_mm_ss));



        String respJson="{\n" +
                "    \"code\": \"0\",\n" +
                "    \"msg\": \"success\",\n" +
                "    \"data\": {\n" +
                "        \"pageSize\": 1,\n" +
                "        \"list\": [\n" +
                "            {\n" +
                "                \"eventId\": \"0f3ba98192f02d7f186b9eb33314ef44\",\n" +
                "                \"eventName\": \"acs.acs.eventType.successFace\",\n" +
                "                \"eventTime\": \"2023-04-12T11:59:37+08:00\",\n" +
                "                \"personId\": \"31757ce46e09418ca926094f58935897\",\n" +
                "                \"cardNo\": \"9990000008\",\n" +
                "                \"personName\": \"何肃桃\",\n" +
                "                \"orgIndexCode\": \"36553719-e462-498a-9664-cc7fdaf9c421\",\n" +
                "                \"orgName\": \"默认组织/宜宾市民中心/1A公安大厅/市交警支队\",\n" +
                "                \"doorName\": \"公安大厅1A_门_1\",\n" +
                "                \"doorIndexCode\": \"38419b11af544d45a664dd27db15d8f2\",\n" +
                "                \"doorRegionIndexCode\": \"bd1e680d-662f-45b3-a798-8bae7cd194e6\",\n" +
                "                \"picUri\": null,\n" +
                "                \"svrIndexCode\": null,\n" +
                "                \"eventType\": 196893,\n" +
                "                \"inAndOutType\": 1,\n" +
                "                \"readerDevIndexCode\": \"fc6bc97929bb449e9c2fa91dbd6b1d01\",\n" +
                "                \"readerDevName\": \"读卡器_1\",\n" +
                "                \"devIndexCode\": \"73f5f57cb4cd486fba06e817c7555dd8\",\n" +
                "                \"devName\": \"公安大厅1A\",\n" +
                "                \"identityCardUri\": null,\n" +
                "                \"receiveTime\": \"2023-04-12T11:59:39.727+08:00\",\n" +
                "                \"jobNo\": \"8\",\n" +
                "                \"studentId\": null,\n" +
                "                \"certNo\": \"8\"\n" +
                "            }\n" +
                "        ],\n" +
                "        \"total\": 3903,\n" +
                "        \"totalPage\": 3903,\n" +
                "        \"pageNo\": 1\n" +
                "    }\n" +
                "}";


        Rest<DoorEventDataInfo> rest = JSON.parseObject(respJson, new TypeReference<Rest<DoorEventDataInfo>>() {
        });

        System.out.println(rest.getData().getTotal());

        System.out.println(rest.getData().getList().get(0).getPersonName());


    }


}
