package com.usky.issue.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.issue.annotation.CheckSign;
import com.usky.issue.service.SpHj2017Service;
import com.usky.issue.service.SpRtu2017Service;
import com.usky.issue.service.SpSj2017Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author fu
 * @since 2023-12-13
 */
@CrossOrigin
@RestController
@RequestMapping("/spHj2017")
public class SpHj2017Controller {
    @Autowired
    private SpHj2017Service spHj2017Service;
    @Autowired
    private SpSj2017Service spSj2017Service;
    @Autowired
    private SpRtu2017Service spRtu2017Service;

    @CheckSign
    @PostMapping("eventList")
    ApiResult<Map<String, Object>> eventList(@RequestBody String requestBody) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("firaAlarm", spHj2017Service.statusCount(requestBody));
        resultMap.put("waterAlarm", spSj2017Service.statusCount(requestBody));
        resultMap.put("rtuAlarm", spRtu2017Service.statusCount(requestBody));
            return ApiResult.success(resultMap);
    }

    @CheckSign
    @PostMapping("listCount")
    ApiResult<Map<String, Object>> countList(@RequestBody String requestBody) {
        List<Map<String, Object>> typeList1 = spHj2017Service.typeList(requestBody);
        Long untreatedCount1 = (Long) typeList1.get(0).get("untreated");
        Long processedCount11 = (Long) typeList1.get(0).get("processed");
        List<Map<String, Object>> typeList2 = spSj2017Service.typeList(requestBody);
        Long untreatedCount2 = (Long) typeList2.get(0).get("untreated");
        Long processedCount22 = (Long) typeList2.get(0).get("processed");
        List<Map<String, Object>> typeList3 = spRtu2017Service.typeList(requestBody);
        Long untreatedCount3 = (Long) typeList3.get(0).get("untreated");
        Long processedCount33 = (Long) typeList3.get(0).get("processed");
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("unprocess", untreatedCount1+untreatedCount2+untreatedCount3);
        resultMap.put("processing",0);
        resultMap.put("processed", processedCount11+processedCount22+processedCount33);
            return ApiResult.success(resultMap);
    }


}

