package com.huimv.video.dhicc.controller.ScreenController;


import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import com.huimv.video.dhicc.result.R;
import com.huimv.video.dhicc.util.GetResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/screen/index")
public class ScreenIndexDataController {

    //返回大屏首页的数据
    @RequestMapping("/dataList")
    public R indexDataList(HttpServletRequest request, @RequestParam(name = "farmId") Integer farmId) throws ClientException, ParseException {
        if (farmId != 1) {
            //返回为空数据
            return R.ok("当前牧场无设备").put("data", null);
        }

        GetResponse getResponse = new GetResponse();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map map = new HashMap<>();
        Calendar c = Calendar.getInstance();
        Date date = new Date();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);

        c.add(Calendar.DATE, +1);
        Date A = c.getTime();
        String formatA = format.format(A);

        c.add(Calendar.DATE, -1);
        Date B = c.getTime();
        String formatB = format.format(B);

        c.add(Calendar.DATE, -6);
        Date C = c.getTime();
        String formatC = format.format(C);

        System.out.println(formatA + formatB);
        //人员刷脸成功
        map.put("personPassSuccess", getResponse.SendMassageGetPagePerson(formatB, formatA));
        //人员刷脸失败
        map.put("personPassFail", getResponse.SendMassageGetPagePersonAlarm(formatB, formatA));
        //车辆出数量统计
        map.put("carPassOut", getResponse.SendMassageCarOut(formatB, formatA));
        //车辆进
        map.put("carPassIn", getResponse.SendMassageCarIn(formatB, formatA));
        //死猪
        map.put("tadaySiZhu", getResponse.SendCountSiZhu(formatB, formatA));
        //七日死猪事件
        map.put("SevenDaySiZhu", getResponse.SendCountSiZhu(formatC, formatA));
        //今日洗消
        map.put("tadayXiXiao", getResponse.SendMassageXixiaoPerson(formatB, formatA));
        //七日洗消事件
        map.put("SevenDayXIxiao", getResponse.SendMassageXixiaoPerson(formatC, formatA));
        //大门七日记录数
        map.put("SevenDayGate", getResponse.SendMassageGateCount(formatC, formatA));
        //大门今日记录数
        map.put("tadayGate", getResponse.SendMassageGateCount(formatB, formatA));

        return R.ok("请求成功").put("data", map);

    }
}
