Newer
Older
zq-big-sreen / src / main / java / com / casic / service / impl / MapDataServiceImpl.java
chaizhuang on 19 Oct 2022 4 KB 没有改变
package com.casic.service.impl;

import com.casic.dao.smartwell.MapDataMapper;
import com.casic.model.AlarmNowView;
import com.casic.model.BusWellInfoDto;
import com.casic.model.ResponseData;
import com.casic.service.MapDataService;
import com.casic.util.DeviceDataFieldTableEnum;
import com.casic.util.DeviceDataTableEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class MapDataServiceImpl implements MapDataService {

    @Autowired
    private MapDataMapper mapDataMapper;

    @Override
    public Object getNowAlarmRecords() {
        ResponseData responseData = new ResponseData();
        try {
            List<AlarmNowView> alarmNowViewList = this.mapDataMapper.getNowAlarmRecords();
            for (AlarmNowView alarmNowView : alarmNowViewList) {
                alarmNowView.setWellTypeName(mapDataMapper.getDictNameByCode(alarmNowView.getWellType()));
            }
            responseData.setData(alarmNowViewList);
            responseData.setCode(200);
            responseData.setMessage("查询成功");
        } catch (DataAccessException dex) {
            log.error("主题:最新报警记录查询异常,异常信息:{}", dex);
            responseData.setCode(500);
            responseData.setMessage("查询异常");
        }
        return responseData;
    }


    @Override
    public Object getWellList(String keywords, String wellType, String deptid, String isAlarm) {

        ResponseData responseData = new ResponseData();
        try {
            List<BusWellInfoDto> wellList = new ArrayList<>();
            if (null == isAlarm || isAlarm.equals("") == true) {
                // 查询并添加当前部门的闸井
                List<BusWellInfoDto> myList = mapDataMapper.getWellList(keywords, wellType, deptid);
                if (null != myList && myList.isEmpty() == false) {
                    wellList.addAll(myList);
                }
            } else if (isAlarm.equals("1")) {
                // isAlarm = 1 查询所有报警状态的闸井
                wellList = mapDataMapper.getAlarmWellList(keywords, wellType, deptid);
            } else {
                // isAlarm = 0 查询所有不是报警状态的闸井
                wellList = mapDataMapper.getNotAlarmWellList(keywords, wellType, deptid);
            }
            responseData.setData(wellList);
            responseData.setCode(200);
            responseData.setMessage("查询成功");
        } catch (DataAccessException dex) {
            log.error("主题:点位记录列表查询异常,异常信息:{}", dex);
            responseData.setCode(500);
            responseData.setMessage("查询异常");
        }
        return responseData;
    }

    public  Object  getWellInfo(String  devcode,String deviceType){
        ResponseData responseData = new ResponseData();
        try {
            DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType));
            String tableName = deviceDataTableEnum.getTableName();
            List<Map<String,Object>> wellInfoList=new ArrayList<>();
            if(deviceType.equals("10")){
                String []   tableNameList=tableName.split(",");

                for(String tableNames:tableNameList){
                    Map<String,Object> wellInfoMap=mapDataMapper.getDeviceStatus(devcode,tableNames,
                            DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName));
                    if(!wellInfoMap.containsKey("dataValue")){
                        wellInfoMap.put("dataValue",0.0);
                    }
                    wellInfoList.add(wellInfoMap);
                }
            }else {
                Map<String,Object> wellInfoMap=mapDataMapper.getDeviceStatus(devcode,tableName,
                        DeviceDataFieldTableEnum.TABLE_FIELD.getTableFieldMap().get(tableName));
                if(!wellInfoMap.containsKey("dataValue")){
                    wellInfoMap.put("dataValue",0.0);
                }
                wellInfoList.add(wellInfoMap);
            }
            responseData.setData(wellInfoList);
            responseData.setCode(200);
            responseData.setSuccess(true);
            responseData.setMessage("查询成功");
        } catch (DataAccessException dex) {
            log.error("主题:点位详情查询异常,异常信息:{}", dex);
            responseData.setCode(500);
            responseData.setMessage("查询异常");
        }
        return responseData;
    }

}