package com.jiayue.ipfcst.service;

import com.jiayue.ipfcst.common.data.constant.enums.EquipmentTypeEnum;
import com.jiayue.ipfcst.common.data.entity.EquipmentAttribute;
import com.jiayue.ipfcst.common.data.entity.ProtocolGatherDataPoint;
import com.jiayue.ipfcst.common.data.entity.WeatherStationStatusData;
import com.jiayue.ipfcst.common.data.repository.WeatherStationStatusDataRepository;
import com.jiayue.ipfcst.common.data.service.BaseService;
import com.jiayue.ipfcst.repository.ProtocolGatherDataPointRepository;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.criteria.Predicate;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 *设备接入点位属性业务层
 *
 * @author yh
 * @version 1.0
 * @since 2019/8/5 16:02
 */
@Service
public class ProtocolGatherDataPointService extends BaseService {


    private final ProtocolGatherDataPointRepository protocolGatherDataPointRepository;
    @Autowired
    public ProtocolGatherDataPointService(ProtocolGatherDataPointRepository protocolGatherDataPointRepository){
        this.protocolGatherDataPointRepository = protocolGatherDataPointRepository;
    }


    /**
     * 查询设备接入点位属性
   * @param id 设备ID
   * @return 点位属性集合
   */
  public List<EquipmentAttribute> getEquipmentAttribute(Integer id,String equipmentType){

    List<EquipmentAttribute> result = new ArrayList<>();
    ProtocolGatherDataPoint g=new ProtocolGatherDataPoint();
    g.setEquipmentId(id);
    if(equipmentType.equals("WEATHERSTATION")){
      g.setEquipmentType(EquipmentTypeEnum.WEATHERSTATION);
    }else if(equipmentType.equals("WINDTOWER")){
      g.setEquipmentType(EquipmentTypeEnum.WINDTOWER);
    }
    List<ProtocolGatherDataPoint> pList = protocolGatherDataPointRepository.findAll(Example.of(g));
    for(ProtocolGatherDataPoint p : pList){
      String ea = p.getEquipmentAttribute().getFieldName();
      //去掉status 和备用字段， 扫码环境数据类型 不需要这些数据
      if(ea.equals("status") || ea.equals("data1") || ea.equals("data2") ||
        ea.equals("data3") || ea.equals("data4") || ea.equals("data5") ||
        ea.equals("data6") || ea.equals("data7") || ea.equals("data8") ||
        ea.equals("data9") || ea.equals("data10")
      ){
        continue;
      }else{
        result.add(p.getEquipmentAttribute());
      }
    }
    return result;
  }




}
