コード例 #1
0
ファイル: FormulaServiceImpl.java プロジェクト: helenarth/ssq
  @Override
  public Serializable addARedFormula(String name, String formulaValue, String desc) {

    RedFormula rFormula = new RedFormula();
    rFormula.setDesc(desc);
    rFormula.setName(name);
    rFormula.setValue(formulaValue);

    return getBaseDao().add(rFormula);
  }
コード例 #2
0
ファイル: FormulaServiceImpl.java プロジェクト: helenarth/ssq
  @Override
  public void caclAllRedFormula() throws Exception {

    // 获取所有公式
    List<RedFormula> redFormulaes = getFormulaDao().findRedFormulasByHql("from RedFormula");

    // 获取还未计算过的开奖记录
    List<SsqRecord> ssqRecords =
        ssqRecordDao.findSsqRecordsByHql(
            "from SsqRecord where ssqIndex > ( select max(ssqIndex) from RedFormulaCacl )");

    List<BaseEntity> caclVerifies = new ArrayList<BaseEntity>();

    for (int i = 0; i < ssqRecords.size(); i++) {
      RedFormulaCacl cacl = new RedFormulaCacl();
      cacl.setSsqIndex(ssqRecords.get(i).getSsqIndex());
      cacl.setTargetSsqIndex(ssqRecords.get(i).getNextSsqIndex());

      for (int j = 0; j < redFormulaes.size(); j++) {
        RedFormula redFormula = redFormulaes.get(j);
        String formulaStr = redFormula.getValue();
        String formulaName = redFormula.getName();

        // 计算公式
        int result = FormulaUtil.calculate(formulaStr, formulaName, ssqRecords.get(i), expMap);

        formulaName = formulaName.substring(0, 1).toUpperCase() + formulaName.substring(1);

        // 根据公式名称反射赋值到RedFormulaCacl对应字段
        String methodName = "set" + formulaName + "Value";
        Method method = null;
        if (methodMap.get(methodName) == null) {
          method = RedFormulaCacl.class.getMethod(methodName, int.class);
          methodMap.put(methodName, method);
        } else {
          method = methodMap.get(methodName);
        }
        method.invoke(cacl, result);
      }

      caclVerifies.add(cacl);
    }

    getBaseDao().batchAddBaseEntityes(caclVerifies);
  }
コード例 #3
0
ファイル: FormulaServiceImpl.java プロジェクト: helenarth/ssq
  @Override
  public void initAllRedFormula() throws IOException {

    // 从开奖记录文件中获取开奖记录集合
    List<String> strRecords = FileUtil.readLineFile(USERHOME + RED_FORMULA_FILE);

    List<BaseEntity> records = new ArrayList<BaseEntity>();

    int index = 1;
    for (String str : strRecords) {

      RedFormula rFormula = new RedFormula();
      rFormula.setDesc("");
      rFormula.setName("formula" + index);
      rFormula.setValue(str.trim());

      records.add(rFormula);
      index++;
    }

    // 保存所有开奖记录
    getBaseDao().batchAddBaseEntityes(records);
  }
コード例 #4
0
ファイル: FormulaServiceImpl.java プロジェクト: helenarth/ssq
  @Override
  public void verifyAllRedFormula() throws Exception {

    // 删除所有RedFormulaCaclVerify
    //		getBaseDao().deleteByHql("delete from RedFormulaCaclVerify");

    List<RedFormula> redFormulaes = getFormulaDao().findRedFormulasByHql("from RedFormula");

    // 获取还未验证过的红球公式计算值
    List<BaseEntity> redFormulaCacles =
        getFormulaDao()
            .find(
                "from RedFormulaCacl where ssqIndex > ( select max(ssqIndex) from RedFormulaCaclVerify ) ");

    List<BaseEntity> caclVerifies = new ArrayList<BaseEntity>();

    for (int i = 0; i < redFormulaCacles.size(); i++) {

      RedFormulaCaclVerify caclVerify = new RedFormulaCaclVerify();

      RedFormulaCacl redFormulaCacl = (RedFormulaCacl) redFormulaCacles.get(i);

      caclVerify.setSsqIndex(redFormulaCacl.getSsqIndex());

      int targetSsqIndex = redFormulaCacl.getTargetSsqIndex();

      caclVerify.setTargetSsqIndex(targetSsqIndex);

      // 获取目标期的双色球开奖记录
      SsqRecord targetSsqRecord = ssqRecordDao.findSsqRecordBySsqIndex(targetSsqIndex);

      if (targetSsqRecord == null) {
        continue;
      }

      Map<Integer, String> redMap = new HashMap<Integer, String>();
      redMap.put(targetSsqRecord.getR1(), null);
      redMap.put(targetSsqRecord.getR2(), null);
      redMap.put(targetSsqRecord.getR3(), null);
      redMap.put(targetSsqRecord.getR4(), null);
      redMap.put(targetSsqRecord.getR5(), null);
      redMap.put(targetSsqRecord.getR6(), null);

      for (int j = 0; j < redFormulaes.size(); j++) {
        RedFormula redFormula = redFormulaes.get(j);

        String formulaName = redFormula.getName();

        // 获取计算值
        formulaName = formulaName.substring(0, 1).toUpperCase() + formulaName.substring(1);

        // 根据公式名称反射赋值到RedFormulaCacl对应字段
        String methodName = "get" + formulaName + "Value";
        Method method = null;
        if (methodMap1.get(methodName) == null) {
          method = RedFormulaCacl.class.getMethod(methodName);
          methodMap1.put(methodName, method);
        } else {
          method = methodMap1.get(methodName);
        }

        int result = ((Integer) method.invoke(redFormulaCacl)).intValue();

        boolean killRight = false;
        if (!redMap.containsKey(result)) {
          killRight = true;
        }

        methodName = "setKill" + formulaName + "Right";
        Method method1 = null;
        if (methodMap2.get(methodName) == null) {
          method1 = RedFormulaCaclVerify.class.getMethod(methodName, boolean.class);
          methodMap2.put(methodName, method1);
        } else {
          method1 = methodMap2.get(methodName);
        }
        method1.invoke(caclVerify, killRight);
      }
      caclVerifies.add(caclVerify);
    }

    getBaseDao().batchAddBaseEntityes(caclVerifies);
  }