/*根据院校层次id删除对应专业
  * (non-Javadoc)
  * @see net.cedu.biz.enrollment.AcademyMajorBiz#deleteAcademyMajorByAcademyLevelId(int)
  */
 @SuppressWarnings("unchecked")
 public int deleteAcademyMajorByAcademyLevelId(int id) {
   List list = new ArrayList();
   list.add(id);
   String sql = " and academyLevelId= " + Constants.PLACEHOLDER;
   return academyMajorDao.deleteByProperty(sql, list);
 }
  /*
   * 查询某层次下的所有专业
   * @see net.cedu.biz.enrollment.AcademyMajorBiz#findAcademyMajorByLevel(int)
   */
  public List<AcademyMajor> findAcademyMajorByLevel(int academyLevelId) throws Exception {

    List<AcademyMajor> academyMajorlst = null;
    PageParame p = new PageParame();
    String hqlparam = "";
    String params = "";
    if (academyLevelId != 0) {
      hqlparam += " and  academyLevelId=" + Constants.PLACEHOLDER;
      params += academyLevelId + ",";
    } else {
      return null;
    }
    hqlparam += " and deleteFlag = " + Constants.PLACEHOLDER;
    params += Constants.DELETE_FALSE;
    if (!params.equals("")) {
      p.setHqlConditionExpression(hqlparam);
      p.setValues(params.split(","));
    }
    Long[] academyMajorits = academyMajorDao.getIDs(p);
    if (academyMajorits != null && academyMajorits.length != 0) {
      academyMajorlst = new ArrayList<AcademyMajor>();
      for (int i = 0; i < academyMajorits.length; i++) {
        AcademyMajor am = this.findById(Integer.valueOf(academyMajorits[i].toString()));
        AcademyMajor academymajor = am;
        Major major = majorBiz.findMajorById(academymajor.getMajorId());
        if (major != null) {
          academymajor.setMajorName(major.getName());
          academymajor.setMajorCode(major.getCode());
        }
        academyMajorlst.add(academymajor);
      }
    }

    return academyMajorlst;
  }
 /**
  * 查询某层次下的所有专业
  *
  * @param levelId
  * @return
  * @throws Exception
  */
 public List<AcademyMajor> findByLevel(int levelId) throws Exception {
   String sql =
       " and academyLevelId = "
           + Constants.PLACEHOLDER
           + " and deleteFlag = "
           + Constants.PLACEHOLDER
           + " order by majorId";
   return academyMajorDao.getByProperty(sql, new Object[] {levelId, Constants.DELETE_FALSE});
 }
  /**
   * 查询院校某批次下对应基础层次ID为levelId的MajorLevel下的所有基础专业
   *
   * @param batchId 院校招生批次ID
   * @param levelId 基础层次ID
   * @return
   * @throws Exception
   */
  public List<AcademyMajor> findAcademyMajorByLevelId(int batchId, int levelId) throws Exception {
    AcademyLevel al = academyLevelBiz.findByBatchAndLevel(batchId, levelId);

    if (al == null) return null;

    List<AcademyMajor> list =
        academyMajorDao.getByProperty(
            " and academyLevelId="
                + Constants.PLACEHOLDER
                + " and deleteFlag = "
                + Constants.PLACEHOLDER
                + " order by majorId",
            new Object[] {al.getId(), Constants.DELETE_FALSE});

    return list;
  }
 /*根据多个院校层次ID删除每个院校层次对应的院校专业
  * (non-Javadoc)
  * @see net.cedu.biz.enrollment.AcademyMajorBiz#deleteAcademyMajorByAcademyLevelId(int)
  */
 public int deleteAcademyMajorByAcademyLevelId(List<AcademyLevel> collegelist) {
   String sql = "";
   Object[] objs = null;
   if (null != collegelist && collegelist.size() > 0) {
     objs = new Object[collegelist.size() + 1];
     sql = " and academyLevelId in ('-1'";
     StringBuffer idsSB = new StringBuffer("");
     for (int i = 0, len = collegelist.size(); i < len; i++) {
       objs[i] = collegelist.get(i).getId();
       //				sql+=","+Constants.PLACEHOLDER;
       idsSB.append("," + Constants.PLACEHOLDER);
     }
     sql += idsSB.toString();
     sql += ") order by majorId";
     return academyMajorDao.deleteByProperty(sql, objs);
   } else {
     return 0;
   }
 }
 /**
  * 查询某层次下的所有专业_定时任务
  *
  * @param levelId
  * @return
  * @throws Exception
  */
 public List<AcademyMajor> findByLevelForTask(List<Integer> idList) throws Exception {
   String sql = " and deleteFlag = " + Constants.PLACEHOLDER;
   List<Object> paramList = new ArrayList<Object>();
   paramList.add(Constants.DELETE_FALSE);
   if (null != idList) {
     sql += " and academyLevelId in(";
     StringBuffer idsSB = new StringBuffer("0");
     for (int i = 0; i < idList.size(); i++) {
       if (0 == i) {
         //					sql+=Constants.PLACEHOLDER;
         idsSB = new StringBuffer(Constants.PLACEHOLDER);
       } else {
         //					sql+=","+Constants.PLACEHOLDER;
         idsSB.append("," + Constants.PLACEHOLDER);
       }
       paramList.add(idList.get(i));
     }
     sql += idsSB.toString();
     sql += ")";
   }
   sql += " order by majorId";
   return academyMajorDao.getByProperty(sql, paramList.toArray());
 }
 /**
  * 根据Id查询专业
  *
  * @param id
  * @return
  * @throws Exception
  */
 public AcademyMajor findById(int id) throws Exception {
   return academyMajorDao.findById(id);
 }
 // 添加
 public Object addAcademyMajor(AcademyMajor academyMajor) {
   return academyMajorDao.save(academyMajor);
 }