package cn.iocoder.yudao.module.system.controller.admin.biz.device;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExportData;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ScheduleShiftPageListRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ScheduleShiftPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ScheduleShiftSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.DeviceProductDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.DeviceWarnDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ModelFieldDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NurseScheduleDO;
import cn.iocoder.yudao.module.system.dal.mysql.biz.ModelFieldMapper;
import cn.iocoder.yudao.module.system.service.biz.DeviceProductService;
import cn.iocoder.yudao.module.system.service.biz.ModelFieldService;
import cn.iocoder.yudao.module.system.service.biz.ScheduleShiftService;
import cn.iocoder.yudao.module.system.service.biz.SleepthingService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

/**
 * @Author: jinyd
 * @CreateTime: 2024/10/22  10:57
 * @Description:
 * @Version: 4.0
 */

@Slf4j
@Tag(name = "睡小宝")
@RestController
@RequestMapping("/api/sleep")
@Validated
public class SleepthingController {

//    private static final Logger GM_LOG = LoggerFactory.getLogger(SleepthingController.class.getName());

    @Autowired
    private SleepthingService sleepthingService;

    @Autowired
    private DeviceProductService deviceProductService;

    /**
     * 睡眠报告生成通知
     *
     //* @param params
     * @return
     */
    @RequestMapping("/reportIsReady")
    public CommonResult reportIsReady(@RequestBody HashMap<String, Object> params) {
        /*HashMap<String, Object> params = Maps.newHashMap();
        params.put("devID","40F5200F8B1F");
        params.put("day","2021-07-06");*/
        log.info("睡小宝睡眠报告请求参数,{}", params);
        return sleepthingService.generateSleepReport(params);

    }

    /**
     * 异常报警通知
     *
     * @param params
     * @return
     */
    @PostMapping("/alarmNotify")
    public CommonResult alarmNotify(@RequestBody HashMap<String, Object> params) {
        sleepthingService.alarmNotify(params);
        return CommonResult.success("");
    }


}
