package com.template.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.template.api.SmartFaceDiscernControllerAPI;
import com.template.common.utils.*;
import com.template.config.ControlConfig;
import com.template.model.pojo.SmartFaceDiscern;
import com.template.model.pojo.SmartUser;
import com.template.model.result.CommonResult;
import com.template.services.SmartFaceDiscernService;
import com.template.services.SmartUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


import static com.template.common.utils.AesTestOne.decrypt;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ceshi
 * @since 2024-01-18
 */
@RestController
public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI {

    @Autowired
    SmartFaceDiscernService smartFaceDiscernService;


    @Override
    public CommonResult track(Integer id,int dateTime) {
        JSONObject date = getDate(dateTime);

        String stateTime = date.getString("stateTime");
        String endTime = date.getString("endTime");

        List<SmartFaceDiscern> smartFaceDiscerns =smartFaceDiscernService.track(stateTime,endTime,id);

        return CommonResult.ok(smartFaceDiscerns);
    }

    public static JSONObject getDate(Integer date){
        JSONObject jsonObject = new JSONObject();

        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime stateTime = now.withHour(0).withMinute(0).withSecond(0).minusDays(date);

        LocalDateTime endTime = now.withHour(23).withMinute(59).withSecond(59).minusDays(date);

        jsonObject.put("stateTime",stateTime.format(dateTimeFormatter1));
        jsonObject.put("endTime",endTime.format(dateTimeFormatter1));

        return jsonObject;

    }

    public static void main(String[] args) {
        JSONObject date = getDate(1);
        System.out.println("date = " + date);
    }

}

