package com.ruoyi.project.patrol.patrol.controller;

import com.ruoyi.common.jpush.JiGuangPushService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.patrol.patrol.domain.TIndex;
import com.ruoyi.project.patrol.patrol.service.ITIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/patrol/index")
public class TIndexController extends BaseController {
    @Autowired
    private ITIndexService tIndexService;
    @Autowired
    private JiGuangPushService jiGuangPushService;
    @GetMapping("/countNums")
    public AjaxResult getCountNums() {
        TIndex tIndex = new TIndex();
        tIndex.setCreateDate(new Date());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        tIndex.setYear(String.valueOf(calendar.get(Calendar.YEAR)));
        tIndex.setMonth(String.valueOf(calendar.get(Calendar.MONTH) + 1));
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("devNum", tIndexService.getDevNumber());
        resultMap.put("uncheckPlanNum", tIndexService.getUncheckNumber(tIndex));
        resultMap.put("checkedPlanNum", tIndexService.getCheckNumber(tIndex));
        resultMap.put("issueNum", tIndexService.getIssueNumber(tIndex));
        return AjaxResult.success(resultMap);
    }

    @PostMapping
    public void sentTest() {
        jiGuangPushService.send("欢迎使用EHS管理助手", "欢迎使用EHS管理助手！","1");
    }
}
