Пример #1
0
  public User get(final String id) throws ClassNotFoundException, SQLException {

    String sql = "select * from userinfo where id =?";
    Object[] args = new String[] {id};
    User queryForObject = null;

    try {
      queryForObject =
          getJdbcTemplate()
              .queryForObject(
                  sql,
                  args,
                  new RowMapper<User>() {

                    @Override
                    public User mapRow(ResultSet resultSet, int i) throws SQLException {
                      User user = new User();
                      user.setId(resultSet.getString("id"));
                      user.setName(resultSet.getString("name"));
                      user.setPassword(resultSet.getString("password"));
                      return user;
                    }
                  });
    } catch (EmptyResultDataAccessException e) {
      e.printStackTrace();
    }
    return queryForObject;
  }
Пример #2
0
    @Override
    public AcademicKPI mapRow(ResultSet rs, int rowNum) throws SQLException {
      AcademicKPI domain = new AcademicKPI();
      domain.setAcademicKPIId(rs.getLong("academic_kpi_id"));
      domain.setName(rs.getString("name"));
      domain.setCode(rs.getString("code"));
      domain.setWorkTypeCode(rs.getString("work_type_code"));
      domain.setDescription(rs.getString("description"));
      domain.setStatus(rs.getString("status"));
      domain.setAcademicYear(rs.getString("academic_year"));
      domain.setMark(rs.getBigDecimal("mark"));
      domain.setUnitCode(rs.getString("unit_code"));
      domain.setMultiplyValue(rs.getString("rule_code"));
      domain.setOrderNo(rs.getString("order_no"));

      domain.setSpecialP1(rs.getString("special_p1"));
      domain.setSpecialP2(rs.getString("special_p2"));
      domain.setSpecialP3(rs.getString("special_p3"));
      domain.setSpecialP4(rs.getString("special_p4"));
      domain.setTotalStudentFrom(rs.getString("total_student_from"));
      domain.setTotalStudentTo(rs.getString("total_student_to"));
      domain.setFromRegis(rs.getString("from_reg"));
      // logger.info(" ###### Multiply Value:"+rs.getString("rule_code"));

      try {
        domain.setUnitDesc(
            schoolUtil.getUnitDescMyCode(rs.getString("unit_code"), rs.getString("academic_year")));
      } catch (org.springframework.dao.EmptyResultDataAccessException ex) {
        ex.printStackTrace();
      }

      return domain;
    }
Пример #3
0
  public static String updateUserSettings(Map<String, String[]> settings, String user) {
    String message = "Internal error";
    if (settings == null || settings.size() == 0) {
      return "Empty post body";
    }

    String defaultView = "";
    if (settings.containsKey("detail_default_view")) {
      String[] defaultViewArray = settings.get("detail_default_view");
      if (defaultViewArray != null && defaultViewArray.length > 0) {
        defaultView = defaultViewArray[0];
      }
    }
    String defaultWatch = "";
    if (settings.containsKey("default_watch")) {
      String[] defaultWatchArray = settings.get("default_watch");
      if (defaultWatchArray != null && defaultWatchArray.length > 0) {
        defaultWatch = defaultWatchArray[0];
      }
    }
    Integer userId = 0;
    if (StringUtils.isNotBlank(user)) {
      try {
        userId = (Integer) getJdbcTemplate().queryForObject(GET_USER_ID, Integer.class, user);
      } catch (EmptyResultDataAccessException e) {
        Logger.error("UserDAO updateUserSettings get user id failed, username = "******"Exception = " + e.getMessage());
      }
    }
    if (userId != null && userId > 0) {
      if (StringUtils.isBlank(defaultView)) {
        defaultView = DEFAULT_DETAIL_VIEW;
      }

      if (StringUtils.isBlank(defaultWatch)) {
        defaultWatch = DEFAULT_WATCH;
      }

      int row =
          getJdbcTemplate()
              .update(
                  UPDATE_USER_SETTINGS,
                  userId,
                  defaultView,
                  defaultWatch,
                  defaultView,
                  defaultWatch);
      if (row > 0) {
        message = "";
      }
    } else {
      message = "User not found";
    }
    return message;
  }
Пример #4
0
  @Override
  public AcademicKPIWrapper getAllByAcademicYear(String getByAcademicYear) {

    String sqlpbp_work_type =
        " select *  from pbp_work_type where academic_year ='" + getByAcademicYear + "'";

    logger.info("  getAllByAcademicYear  sqlpbp_work_type:" + sqlpbp_work_type);

    AcademicKPIWrapper academicKPIWrapper = new AcademicKPIWrapper();

    List<PBPWorkType> pBPWorkTypeList =
        this.jdbcTemplate.query(sqlpbp_work_type, new PBPWorkTypeMapper());

    for (PBPWorkType tmp : pBPWorkTypeList) {

      String sqlkpi =
          " select *  from academic_kpi where academic_year ='"
              + getByAcademicYear
              + "' and work_type_code ='"
              + tmp.getCode()
              + "' order by order_no";
      logger.info(" sqlkpi:" + sqlkpi);
      List<AcademicKPI> academicKPIList = null;

      try {
        academicKPIList = this.jdbcTemplate.query(sqlkpi, new AcademicKPIMapper());

      } catch (org.springframework.dao.EmptyResultDataAccessException ex) {
        ex.printStackTrace();
      }

      for (AcademicKPI tmpxx : academicKPIList) {
        String sqlAttribute =
            " select *  from academic_kpi_attribute where academic_year ='"
                + tmpxx.getAcademicYear()
                + "' and academic_kpi_code ='"
                + tmpxx.getCode()
                + "'";
        List<AcademicKPIAttribute> academicKPIAttributeList = new ArrayList();
        try {
          academicKPIAttributeList =
              this.jdbcTemplate.query(sqlAttribute, new AcademicKPIAttributeMapper());
        } catch (org.springframework.dao.EmptyResultDataAccessException ex) {
          ex.printStackTrace();
        }

        tmpxx.setAcademicKPIAttributeList(academicKPIAttributeList);
      }
      tmp.setAcademicKPIList(academicKPIList);
    }

    academicKPIWrapper.setpBPWorkTypeList(pBPWorkTypeList);

    return academicKPIWrapper;
  }
Пример #5
0
  public static Integer getUserIDByUserName(String userName) {
    Integer userId = 0;
    if (StringUtils.isNotBlank(userName)) {
      try {
        userId = (Integer) getJdbcTemplate().queryForObject(GET_USER_ID, Integer.class, userName);
      } catch (EmptyResultDataAccessException e) {
        userId = 0;
        Logger.error("Get user id failed, user name = " + userName);
        Logger.error("Exception = " + e.getMessage());
      }
    }

    return userId;
  }
Пример #6
0
  @Override
  public AcademicKPIWrapper getByAcademicYear(String getByAcademicYear) {
    String sql = " select *  from academic_kpi where academic_year ='" + getByAcademicYear + "'";
    logger.info(" sql:" + sql);
    List<AcademicKPI> academicKPIList = null;

    try {
      academicKPIList = this.jdbcTemplate.query(sql, new AcademicKPIMapper());
    } catch (org.springframework.dao.EmptyResultDataAccessException ex) {
      ex.printStackTrace();
    }
    AcademicKPIWrapper academicKPIWrapper = new AcademicKPIWrapper();
    academicKPIWrapper.setAcademicKPIList(academicKPIList);
    return academicKPIWrapper;
  }
Пример #7
0
  public static User getCurrentUser(String username) {
    User user = new User();
    try {
      if (StringUtils.isNotBlank(username)) {
        user =
            (User)
                getJdbcTemplate()
                    .queryForObject(GET_CURRENT_USER_INFO, new UserRowMapper(), username);
      }
    } catch (EmptyResultDataAccessException e) {
      Logger.error("UserDAO getCurrentUser failed, username = "******"Exception = " + e.getMessage());
    }

    return user;
  }
Пример #8
0
  @Override
  public AcademicKPI getByCodeAcademicYear(String code, String getByAcademicYear) {
    String sql =
        " select *  from academic_kpi where academic_year ='"
            + getByAcademicYear
            + "' and code ='"
            + code
            + "'";
    logger.info(" sql:" + sql);
    AcademicKPI academicKPI = null;

    try {
      academicKPI = this.jdbcTemplate.queryForObject(sql, new AcademicKPIMapper());

    } catch (org.springframework.dao.EmptyResultDataAccessException ex) {
      ex.printStackTrace();
    }

    if (academicKPI != null) {
      // Get KPI Attribute
      String sqlAttribute =
          " select *  from academic_kpi_attribute where academic_year ='"
              + getByAcademicYear
              + "' and academic_kpi_code ='"
              + code
              + "'";
      List<AcademicKPIAttribute> academicKPIAttributeList = new ArrayList();
      try {
        academicKPIAttributeList =
            this.jdbcTemplate.query(sqlAttribute, new AcademicKPIAttributeMapper());
      } catch (org.springframework.dao.EmptyResultDataAccessException ex) {
        ex.printStackTrace();
      }

      academicKPI.setAcademicKPIAttributeList(academicKPIAttributeList);
    }

    return academicKPI;
  }