Example #1
0
  public static int delete(JUser user, Connection con, String[] sk_ids) throws Exception {
    int delRows = 0; // 删除的行数

    if (sk_ids == null) return delRows;
    PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null;
    ResultSet rs = null;
    String sql = null;

    // 下个月的 两个工作日内 可以修改
    java.util.Date two_workDate = CommonOptions.getConfirmerCanMoidyDate();

    sql = "delete from shinyway.emp_fl_sales where sk_id=? ";
    pstmt = con.prepareStatement(sql);

    sql = "delete from t_flschool_money where sk_id=? and sk_status !=1";
    pstmt1 = con.prepareStatement(sql);

    sql = "select count(*) from t_flschool_money where stu_id=?";
    pstmt2 = con.prepareStatement(sql);

    Connection con_igo = com.gemway.igo.JDatabase.getJDatabase().getConnection();
    String szOperateCompanyCodes = user.getOperateCompanyCodeClause(con_igo, "money", "fl_confirm");
    con_igo.close();

    for (int i = 0; i < sk_ids.length; i++) {
      boolean canDel = false;
      FLSchoolMoney moneyObj = FLSchoolMoney.getFLSchoolMoney(con, sk_ids[i]);

      java.util.Date oldSkDate = JUtil.str2SQLDate(moneyObj.getSk_date()); // 修改前的收款日期

      if ((moneyObj.getSk_status() == 0 || moneyObj.getSk_status() == 2)
          && JUtil.daysAfter(oldSkDate, two_workDate) <= 0) {
        // 审核状态的数据不能删除
        if (user.HasFunc("fl_confirm", "money")
            && szOperateCompanyCodes.indexOf(moneyObj.getCompany_code()) != -1) {
          canDel = true; // 有审核权限的人只能删除一个工作日之内的数据
        } else if (moneyObj.getCreater().equals(user.getUserId())) {
          canDel = true; // 无审核权限的人只能删除自己录入的一个工作日之内的数据
        }
      }
      if (canDel) {
        int updateCount = 0;

        pstmt.setString(1, sk_ids[i]);
        pstmt.executeUpdate();

        pstmt1.setString(1, sk_ids[i]);
        updateCount = pstmt1.executeUpdate();
        if (updateCount > 1) throw new Exception("删除记录超过一条");
        delRows++;

        String stu_id = moneyObj.getStu_id();

        pstmt2.setString(1, stu_id);
        rs = pstmt2.executeQuery();
        rs.next();
        int count = rs.getInt(1);
        rs.close();

        FLSchoolStu.setStatData(con, stu_id);

        if (count == 0) FLSchoolStu.delete(con, stu_id);
        rs.close();
      }
    }
    pstmt.close();
    pstmt1.close();
    pstmt2.close();

    return delRows;
  }