package com.pqs9200.serviceimpl.data;

import com.njcn.mapper.data.EventPzMapper;
import com.njcn.pojo.commons.AreaGeneralData;
import com.njcn.pojo.commons.area.EventPz;
import com.njcn.service.user.DeptsService;
import com.njcn.utils.UserUtil;
import com.pqs9200.service.data.IEventPzService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hongawen
 * @Date: 2018/11/2 13:59
 */
@Service
public class EventPzServiceImpl implements IEventPzService {
    private static final Logger logger = LoggerFactory.getLogger(EventPzServiceImpl.class);
    @Autowired
    DeptsService depts;
    @Autowired
    private UserUtil userUtil;
    @Autowired
    EventPzMapper ep;

    @Override
    public List<List> getZjsj() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<List> eventList = new ArrayList<List>();
        //增加用户判断部门信息并获取详细事件信息
        List<AreaGeneralData> areaGeneral = userUtil.getAreaGeneral();
        List<Integer> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        for (AreaGeneralData data : areaGeneral) {
            Integer lineId = 0;
            list = data.getLineIndexs();// 获取监测点ID
            if (list.isEmpty() == false) {
                for (int i = 0; i < list.size(); i++) {
                    lineId = list.get(i);
                    list1.add(lineId);
                }
            }
        }
        try {
            List<EventPz> eventdetail = ep.getZjsj(list1);
            if (eventdetail.isEmpty()) {
                return eventList;
            } else {
                for (EventPz detail : eventdetail) {
                    List<String> temp = new ArrayList<String>();
                    temp.add(detail.getLineName());
                    temp.add(detail.getTime() + "."
                            + detail.getMsec());
                    temp.add(detail.getPersistTime().toString());
                    temp.add(String.format("%.2f", detail.getEventValue() * 100));
                    temp.add(detail.getNameGD());
                    temp.add(detail.getNameBD());
                    temp.add(detail.getEventType());
                    eventList.add(temp);
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return eventList;
    }

    @Override
    public boolean dealEventWarn(List<String> eventIds){
        ep.dealEventWarn(eventIds);
        return true;
    }
}
