/**
  * 检查操作员是否有操作某种设备类型的数据权限
  *
  * @param optr
  * @param devices
  * @throws Exception
  */
 protected void checkDeviceOperRight(SOptr optr, List<DeviceDto> devices) throws Exception {
   String dataRight = null;
   try {
     dataRight = this.queryDataRightCon(optr, DataRight.DEVICE_TYPE_MNG.toString());
   } catch (Exception e) {
     dataRight = SystemConstants.DEFAULT_DATA_RIGHT;
   }
   // 若无此数据权限,默认为所有设备都能操作
   if (StringHelper.isNotEmpty(dataRight)
       && !dataRight.equals(SystemConstants.DEFAULT_DATA_RIGHT)) {
     String[] arr =
         dataRight
             .substring(dataRight.indexOf("(") + 1, dataRight.lastIndexOf(")"))
             .replaceAll("'", "")
             .split(",");
     List<String> deviceTypeList = Arrays.asList(arr);
     for (DeviceDto dto : devices) {
       if (deviceTypeList.indexOf(dto.getDevice_type()) == -1) {
         throw new ComponentException(
             "您没有操作 "
                 + MemoryDict.getDictName(DictKey.DEVICE_TYPE, dto.getDevice_type())
                 + " 类型的数据权限!");
       }
     }
   }
 }
  /**
   * 检查设备智能卡是否16位,设备编号是否含有特殊字符
   *
   * @param d
   * @return
   * @throws ComponentException
   */
  protected boolean checkDeviceCodeNum(DeviceDto d) throws ComponentException {
    String type = d.getDevice_type();
    String deviceCode = d.getDevice_code();
    String pairDeviceCode = d.getPair_device_code();
    //		if(type.equals(SystemConstants.DEVICE_TYPE_CARD)&&deviceCode.length()!= 16){
    //			 throw new ComponentException("该智能卡号【"+deviceCode+"】不符合标准16位!");
    //		}
    //		if(type.equals(SystemConstants.DEVICE_TYPE_STB)&&
    // StringHelper.isNotEmpty(pairDeviceCode)&&pairDeviceCode.length()!= 16){
    //			 throw new ComponentException("该智能卡号【"+pairDeviceCode+"】不符合标准16位!");
    //		}

    Pattern p = Pattern.compile("[^a-zA-Z0-9]");
    Matcher m = p.matcher(deviceCode);
    String newDeviceCode = m.replaceAll("");
    if (newDeviceCode.length() != deviceCode.length()) {
      if (type.equals(SystemConstants.DEVICE_TYPE_CARD)) {
        throw new ComponentException("该智能卡号【" + deviceCode + "】含有特殊字符!");
      }
      if (type.equals(SystemConstants.DEVICE_TYPE_STB)) {
        throw new ComponentException("该机顶盒号【" + deviceCode + "】含有特殊字符!");
      }
    }

    if (StringHelper.isNotEmpty(pairDeviceCode)) {
      m = p.matcher(pairDeviceCode);
      newDeviceCode = m.replaceAll("");
      if (newDeviceCode.length() != pairDeviceCode.length()) {
        throw new ComponentException("该智能卡号【" + pairDeviceCode + "】含有特殊字符!");
      }
    }
    return true;
  }
  /**
   * 根据设备型号 填入设备类型 是虚拟卡的 填入虚拟信息 验证配对的设备信号
   *
   * @param ls
   * @param deviceModel
   * @return true 设备了虚拟设备 flase 未设置虚拟设备
   * @throws ComponentException
   */
  protected boolean fillDeviceModel(
      Map<String, RStbModel> stbModels,
      Map<String, RCardModel> cardModels,
      Map<String, RModemModel> modemModels,
      List<RPairCfg> pairs,
      DeviceDto device)
      throws ComponentException {

    if (StringHelper.isNotEmpty(device.getPair_device_model())) {
      for (RPairCfg p : pairs) {
        if (p.getStb_model().equals(device.getDevice_model())
            && p.getCard_model().equals(device.getPair_device_model())) {
          return true;
        }
      }
      throw new ComponentException(
          "设备型号:"
              + device.getDevice_model_text()
              + "与"
              + device.getPair_device_model_text()
              + "不能配对使用,请检查");
    } else {
      // 配对设备号空,设置相应的虚拟卡信息
      RStbModel model = stbModels.get(device.getDevice_model());
      //			if (model == null)
      //				throw new ComponentException("错误的设备型号:"
      //						+ device.getDevice_model()+",请检查该型号是否适用当前地区");

      if (StringHelper.isNotEmpty(model.getVirtual_card_model())) {
        RCardModel cardM = cardModels.get(model.getVirtual_card_model());
        if (cardM.getIs_virtual().equals(SystemConstants.BOOLEAN_TRUE)) {
          if (StringHelper.isNotEmpty(device.getPair_device_code())) {
            throw new ComponentException("设备为机卡一体设备,不需要指定卡号,请确认设备号" + device.getDevice_code());
          } else {
            device.setDiffence_type(device.getDiffence_type());
            device.setPair_device_code(device.getDevice_code());
            device.setPair_device_model(model.getVirtual_card_model());
          }
        }
      } else if (StringHelper.isNotEmpty(model.getVirtual_modem_model())) {
        RModemModel modemM = modemModels.get(model.getVirtual_modem_model());
        if (modemM.getIs_virtual().equals(SystemConstants.BOOLEAN_TRUE)) {
          if (StringHelper.isNotEmpty(device.getPair_device_modem_code())) {
            throw new ComponentException("设备为机卡一体设备,不需要指定卡号,请确认设备号" + device.getDevice_code());
          } else {
            device.setDiffence_type(device.getDiffence_type());
            device.setPair_device_modem_code(device.getDevice_code());
            device.setPair_device_model(model.getVirtual_modem_model());
          }
        }
      }
      return true;
    }
  }