package com.huimv.video.dhicc.test.ScreenTestController;


import com.dahuatech.icc.exception.ClientException;
import com.huimv.video.dhicc.icc.CommonConstant;
import com.huimv.video.dhicc.result.R;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
import com.huimv.video.dhicc.util.GetResponse;
import org.springframework.beans.factory.annotation.Autowired;
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 ScreenIndexDataTestController {

    @Autowired
    private OauthConfigBaseInfo oauthConfigBaseInfo;
    @Autowired
    private OauthConfigBaseInfo02 oauthConfigBaseInfo02;
    @Autowired
    private OauthConfigBaseInfo03 oauthConfigBaseInfo03;
    //返回大屏首页的数据
    @RequestMapping("/dataList")
    public R indexDataList(HttpServletRequest request, @RequestParam(name = "farmId") String farmId) throws ClientException, ParseException {
        System.out.println(farmId);
        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);
        if ("1".equals(farmId)){
            //人员刷脸成功
            map.put("personPassSuccess", getResponse.SendMassageGetPagePersonAlarm(formatB, formatA,null,61,oauthConfigBaseInfo));
            //人员刷脸失败
            map.put("personPassFail", getResponse.SendMassageGetPagePersonAlarm(formatB, formatA,0,null,oauthConfigBaseInfo));
            //车辆出数量统计
            map.put("carPassOut", getResponse.carCount(formatB, formatA,"9",oauthConfigBaseInfo));
            //车辆进
            map.put("carPassIn", getResponse.carCount(formatB, formatA,"8",oauthConfigBaseInfo));
            //死猪
            map.put("tadaySiZhu", getResponse.SendMassageXixiaoPerson(formatB, formatA,oauthConfigBaseInfo,CommonConstant.SIZhuChannle));
            //七日死猪事件
            map.put("SevenDaySiZhu", getResponse.SendMassageXixiaoPerson(formatC, formatA,oauthConfigBaseInfo,CommonConstant.SIZhuChannle));
            //今日洗消
            map.put("tadayXiXiao", getResponse.SendMassageXixiaoPerson(formatB, formatA,oauthConfigBaseInfo, CommonConstant.XixiaoChannle));
            //七日洗消事件
            map.put("SevenDayXIxiao", getResponse.SendMassageXixiaoPerson(formatC, formatA,oauthConfigBaseInfo, CommonConstant.XixiaoChannle));
            //大门七日记录数
            map.put("SevenDayGate", getResponse.SendMassageXixiaoPerson(formatC, formatA,oauthConfigBaseInfo,CommonConstant.DoorChannle));
            //大门今日记录数
            map.put("tadayGate", getResponse.SendMassageXixiaoPerson(formatB, formatA,oauthConfigBaseInfo,CommonConstant.DoorChannle));

            return R.ok("请求成功").put("data", map);
        }
        //海宁
        if ("22".equals(farmId)){
            //人员刷脸成功
            map.put("personPassSuccess", getResponse.SendMassageGetPagePersonAlarm02(formatB, formatA,null,61,oauthConfigBaseInfo02));
            //人员刷脸失败
            map.put("personPassFail", getResponse.SendMassageGetPagePersonAlarm02(formatB, formatA,0,null,oauthConfigBaseInfo02));
            //车辆出数量统计
            map.put("carPassOut", getResponse.carCount02(formatB, formatA,"9",oauthConfigBaseInfo02));
            //车辆进
            map.put("carPassIn", getResponse.carCount02(formatB, formatA,"8",oauthConfigBaseInfo02));
            //死猪
            map.put("tadaySiZhu", getResponse.SendMassageXixiaoPerson02(formatB, formatA,oauthConfigBaseInfo02,CommonConstant.SIZhuChannle));
            //七日死猪事件
            map.put("SevenDaySiZhu", getResponse.SendMassageXixiaoPerson02(formatC, formatA,oauthConfigBaseInfo02,CommonConstant.SIZhuChannle));
            //今日洗消
            map.put("tadayXiXiao", getResponse.SendMassageXixiaoPerson02(formatB, formatA,oauthConfigBaseInfo02, CommonConstant.XixiaoChannle));
            //七日洗消事件
            map.put("SevenDayXIxiao", getResponse.SendMassageXixiaoPerson02(formatC, formatA,oauthConfigBaseInfo02, CommonConstant.XixiaoChannle));
            //大门七日记录数
            map.put("SevenDayGate", getResponse.SendMassageXixiaoPerson02(formatC, formatA,oauthConfigBaseInfo02,CommonConstant.DoorChannle));
            //大门今日记录数
            map.put("tadayGate", getResponse.SendMassageXixiaoPerson02(formatB, formatA,oauthConfigBaseInfo02,CommonConstant.DoorChannle));

            return R.ok("请求成功").put("data", map);
        }
        //苍南
        if ("21".equals(farmId)){
            //人员刷脸成功
            map.put("personPassSuccess", getResponse.SendMassageGetPagePersonAlarm03(formatB, formatA,null,61,oauthConfigBaseInfo03));
            //人员刷脸失败
            map.put("personPassFail", getResponse.SendMassageGetPagePersonAlarm03(formatB, formatA,0,null,oauthConfigBaseInfo03));
            //车辆出数量统计
            map.put("carPassOut", getResponse.carCount03(formatB, formatA,"9",oauthConfigBaseInfo03));
            //车辆进
            map.put("carPassIn", getResponse.carCount03(formatB, formatA,"8",oauthConfigBaseInfo03));
            //死猪
            map.put("tadaySiZhu", getResponse.SendMassageXixiaoPerson03(formatB, formatA,oauthConfigBaseInfo03,CommonConstant.SIZhuChannle));
            //七日死猪事件
            map.put("SevenDaySiZhu", getResponse.SendMassageXixiaoPerson03(formatC, formatA,oauthConfigBaseInfo03,CommonConstant.SIZhuChannle));
            //今日洗消
            map.put("tadayXiXiao", getResponse.SendMassageXixiaoPerson03(formatB, formatA,oauthConfigBaseInfo03, CommonConstant.XixiaoChannle));
            //七日洗消事件
            map.put("SevenDayXIxiao", getResponse.SendMassageXixiaoPerson03(formatC, formatA,oauthConfigBaseInfo03, CommonConstant.XixiaoChannle));
            //大门七日记录数
            map.put("SevenDayGate", getResponse.SendMassageXixiaoPerson03(formatC, formatA,oauthConfigBaseInfo03,CommonConstant.DoorChannle));
            //大门今日记录数
            map.put("tadayGate", getResponse.SendMassageXixiaoPerson03(formatB, formatA,oauthConfigBaseInfo03,CommonConstant.DoorChannle));

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

        return R.ok("当前牧场无设备").put("data", null);
    }
}
