public List insertUser(User user, String piority, String usernameInsert, boolean isPM) { // user.setId(1); Integer countPiority = 0; StringBuffer newPiority = new StringBuffer(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US); Date date = new Date(); String dateStr = dateFormat.format(date); HibernateUtil.beginTransaction(); if (user.getStatus() == 3) { user.setValidateStu(0); user.setViewEav(0); } else { user.setValidateStu(1); } user.setUserCreate(usernameInsert); user.setDateCreate(dateStr); if (isPM) { countPiority = 0; } else { countPiority = findPiority(piority, user.getStatus()); } if (countPiority > 0) { if (countPiority < 10) { newPiority.append("00" + countPiority); } else if (countPiority < 100) { newPiority.append("0" + countPiority); } else { newPiority.append(countPiority); } } else { newPiority.append(""); } user.setPiority(piority + newPiority.toString()); getSession().save(user); HibernateUtil.commitTransaction(); closeSession(); Criteria criteria = getSession().createCriteria(User.class); criteria.add(Restrictions.eq("userName", user.getUserName())); List<User> list = criteria.list(); closeSession(); return list; }
public float saldo(Conta conta, Date data) { StringBuffer sql = new StringBuffer(); sql.append("select sum(l.valor * c.fator)"); sql.append(" from LANCAMENTO l,"); sql.append(" CATEGORIA c"); sql.append(" where l.categoria = c.codigo"); sql.append(" and l.conta = :conta"); sql.append(" and l.data <= :data"); SQLQuery query = this.session.createSQLQuery(sql.toString()); query.setParameter("conta", conta.getConta()); query.setParameter("data", data); BigDecimal saldo = (BigDecimal) query.uniqueResult(); if (saldo != null) { return saldo.floatValue(); } return 0f; }
public void editProfileStaff(User user, String pioruty) { User user1 = getUserDatas(user.getUserId()); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US); Date date = new Date(); String dateStr = dateFormat.format(date); user.setUserUpdate(user.getUserName()); user.setDateUpdate(dateStr); user.setPassword(user1.getPassword()); user.setValidateStu(user1.getValidateStu()); user.setStatus(user1.getStatus()); user.setUserCreate(user1.getUserCreate()); user.setDateCreate(user1.getDateCreate()); user.setImange(user1.getImange()); if (user.getTeamId().toString().equals(user1.getTeamId().toString())) { // No change team user.setPiority(user1.getPiority()); } else { // Chang teame if (pioruty.length() <= 0) { // Not PM StringBuffer newPiority = new StringBuffer(); Integer countPiority = findPiority(user.getPiority(), 2); if (countPiority > 0) { if (countPiority < 10) { newPiority.append("00" + countPiority); } else if (countPiority < 100) { newPiority.append("0" + countPiority); } else { newPiority.append(countPiority); } } else { newPiority.append(""); } user.setPiority(user.getPiority() + newPiority.toString()); } else { // PM of new team user.setPiority(pioruty); // edit team and section } } HibernateUtil.beginTransaction(); getSession().merge(user); HibernateUtil.commitTransaction(); }
public void EditProfile(User user) { User user1 = getUserDatas(user.getUserId()); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US); Date date = new Date(); String dateStr = dateFormat.format(date); user.setViewEav(user1.getViewEav()); user.setUserUpdate(user.getUserName()); user.setDateUpdate(dateStr); user.setPassword(user1.getPassword()); user.setValidateStu(user1.getValidateStu()); user.setStatus(user1.getStatus()); user.setUserCreate(user1.getUserCreate()); user.setDateCreate(user1.getDateCreate()); user.setPiority(user1.getPiority()); user.setImange(user1.getImange()); if (!user.getStaffId().equals(user1.getStaffId())) { StringBuffer newPiority = new StringBuffer(); User userBuffer = getUserDatas(user.getStaffId()); Integer countPiority = findPiority(userBuffer.getPiority(), 3); if (countPiority > 0) { if (countPiority < 10) { newPiority.append("00" + countPiority); } else if (countPiority < 100) { newPiority.append("0" + countPiority); } else { newPiority.append(countPiority); } } else { newPiority.append(""); } user.setPiority(userBuffer.getPiority() + newPiority.toString()); } HibernateUtil.beginTransaction(); getSession().merge(user); HibernateUtil.commitTransaction(); }
public static Integer findPiority(String pior, Integer status) { Integer sizePioruty = 0; StringBuffer piorityBuffer = new StringBuffer(); Criteria criteria = getSession().createCriteria(User.class); criteria.add(Restrictions.like("piority", pior + "%")); criteria.add(Restrictions.eq("status", status)); criteria.add(new LengthExpression("piority", pior.length() + 3)); criteria.addOrder(Order.asc("piority")); List<User> list = (List<User>) criteria.list(); sizePioruty = list.size(); if ((list.size() > 0 && status == 3) || (status == 2 && list.size() > 0)) { piorityBuffer.append( list.get(list.size() - 1) .getPiority() .charAt(list.get(list.size() - 1).getPiority().length() - 3) + ""); piorityBuffer.append( list.get(list.size() - 1) .getPiority() .charAt(list.get(list.size() - 1).getPiority().length() - 2) + ""); piorityBuffer.append( list.get(list.size() - 1) .getPiority() .charAt(list.get(list.size() - 1).getPiority().length() - 1) + ""); sizePioruty = Integer.parseInt(piorityBuffer.toString()) + 1; } if (list.size() <= 0 && status == 2) { sizePioruty++; } if (list.size() <= 0 && status == 3) { sizePioruty++; } return sizePioruty; }