package com.yeejoin.equipmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.equipmanage.common.utils.*;
import com.yeejoin.equipmanage.service.IEquipmentSpecificAlarmService;
import com.yeejoin.equipmanage.service.IFireFightingSystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Jianqiang Gao
 * @title: DCenterController
 * <pre>
 * @description: 设备告警
 * </pre>
 * @date 2022/11/15 09:54
 */
@RestController
@Api(tags = "总部直流中心监管页面Api")
@RequestMapping(value = "/dc-center", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DCenterController extends AbstractBaseController {

    @Autowired
    private IEquipmentSpecificAlarmService equipmentSpecificAlarmService;

    @Autowired
    private IFireFightingSystemService fireFightingSystemService;

    /**
     * 直流中心告警列表分页，用于直流中心大数据查询分页，不建议再扩展联表查询
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(httpMethod = "GET", value = "列表分页查询", produces = "application/json;charset=UTF-8", notes = "列表分页查询")
    public ResponseModel listPage(@RequestParam(value = "alarmType", required = false) String alarmType,
                                  CommonPageable commonPageable) {
        if (commonPageable.getPageNumber() == 0) {
            commonPageable.setPageNumber(1);
        }
        List<CommonRequest> queryRequests = new ArrayList<>();
        CommonRequest request = new CommonRequest();
        request.setName("alarmType");
        request.setValue(StringUtil.isNotEmpty(alarmType) ? StringUtils.trimToNull(alarmType) : null);
        queryRequests.add(request);
        CommonPageInfoParam param = CommonPageParamUtil.fillCommonPageInfoParam(queryRequests, commonPageable);
        Page<Map<String, Object>> list = equipmentSpecificAlarmService.zlzxListPage(param);
        return CommonResponseUtil.success(list);
    }

    /**
     * 消防系统运行状态分页查询
     * @param bizOrgCode
     * @param commonPageable
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "消防系统运行状态分页查询")
    @GetMapping("/fireSysRunStatusPage")
    public ResponseModel fireSysRunStatusPage(@RequestParam(value = "bizOrgCode", required = false) String bizOrgCode,
                                              CommonPageable commonPageable) {
        if (commonPageable.getPageNumber() == 0) {
            commonPageable.setPageNumber(1);
        }
        if (StringUtils.isBlank(bizOrgCode)) {
            ReginParams reginParams = getSelectedOrgInfo();
            if (!ValidationUtil.isEmpty(reginParams.getPersonIdentity())) {
                bizOrgCode = reginParams.getPersonIdentity().getBizOrgCode();
            }
        }
        Page page = new Page<>(commonPageable.getPageNumber(), commonPageable.getPageSize());
        return CommonResponseUtil.success(fireFightingSystemService.fireSysRunStatusPage(page, bizOrgCode));
    }


}
