@Override
 public ModelStaffAttendanceView getRecordByCondition(String staffId, Date day, String districtId)
     throws ServiceException {
   // TODO Auto-generated method stub
   DetachedCriteria criteria = DetachedCriteria.forClass(ModelStaffAttendanceView.class);
   if (UtilString.isNotEmpty(staffId)) {
     criteria.add(Restrictions.eq("staffId", staffId));
   }
   if (day != null) {
     criteria.add(Restrictions.eq("workDate", day));
   }
   if (UtilString.isNotEmpty(districtId)) {
     criteria.add(Restrictions.eq("districtId", districtId));
   }
   List<ModelStaffAttendanceView> list = null;
   try {
     list = this.getDaoStaffAttendanceView().getListByCriteria(criteria);
   } catch (DAOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   if (list != null && list.size() > 0) {
     return list.get(0);
   }
   return null;
 }
예제 #2
0
 /*
  * (non-Javadoc)
  * @see cn.trymore.core.dao.DAOGeneric#getListByCriteria(org.hibernate.criterion.DetachedCriteria, boolean)
  */
 @SuppressWarnings("unchecked")
 public List<T> getListByCriteria(final DetachedCriteria criteria, final boolean dataFilter)
     throws DAOException {
   if (dataFilter && UtilString.isNotEmpty(this.getQueryFilter())) {
     criteria.add(Restrictions.sqlRestriction(this.getQueryFilter()));
     this.setQueryFilter(null);
   }
   return (List<T>) getHibernateTemplate().findByCriteria(criteria);
 }
  // 封装检索条件
  private DetachedCriteria getCriterias(ModelStaffAttendanceView entity) {
    DetachedCriteria criteria = DetachedCriteria.forClass(ModelStaffAttendanceView.class);

    if (entity != null) {
      if (entity.getStaffName() != null && UtilString.isNotEmpty(entity.getStaffName())) {
        criteria.add(Restrictions.like("staffName", entity.getStaffName(), MatchMode.ANYWHERE));
      }

      if (entity.getWorkType() != null && UtilString.isNotEmpty(entity.getWorkType())) {
        criteria.add(Restrictions.eq("workType", entity.getWorkType()));
      }
      if (entity.getWorkStatus() != null && UtilString.isNotEmpty(entity.getWorkStatus())) {
        criteria.add(Restrictions.eq("workStatus", entity.getWorkStatus()));
      }
      if (entity.getWorkDate() != null) {
        criteria.add(Restrictions.eq("workDate", entity.getWorkDate()));
      }
      if (entity.getFilterStart() != null) {
        criteria.add(Restrictions.ge("workDate", entity.getFilterStart()));
      }
      if (entity.getFilterEnd() != null) {
        criteria.add(Restrictions.le("workDate", entity.getFilterEnd()));
      }
      if (entity.getAttendanceResult() != null
          && UtilString.isNotEmpty(entity.getAttendanceResult())) {
        criteria.add(Restrictions.eq("attendanceResult", entity.getAttendanceResult()));
      }
      if (entity.getException() != null && "1".equals(entity.getException())) {
        criteria.add(Restrictions.eq("exception", entity.getException()));
      }
    }
    criteria.addOrder(Order.asc("workDate"));
    criteria.addOrder(Order.asc("workTime"));
    criteria.addOrder(Order.asc("staffName"));

    return criteria;
  }
예제 #4
0
  /*
   * (non-Javadoc)
   * @see cn.trymore.core.dao.DAOGeneric#findPageByCriteria(org.hibernate.criterion.DetachedCriteria, int, int, boolean)
   */
  @SuppressWarnings({"unchecked"})
  public PaginationSupport<T> findPageByCriteria(
      final DetachedCriteria criteria,
      final int pageSize,
      final int startIndex,
      final boolean dataFilter)
      throws DAOException {
    if (dataFilter && UtilString.isNotEmpty(this.getQueryFilter())) {
      criteria.add(Restrictions.sqlRestriction(this.getQueryFilter()));
      this.setQueryFilter(null);
    }

    return (PaginationSupport<T>)
        getHibernateTemplate()
            .execute(
                new HibernateCallback() {
                  public Object doInHibernate(Session session)
                      throws HibernateException, SQLException {
                    Criteria execCriteria = criteria.getExecutableCriteria(session);

                    int rowCount =
                        ((Integer)
                                execCriteria.setProjection(Projections.rowCount()).uniqueResult())
                            .intValue();
                    execCriteria.setProjection(null);
                    execCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
                    // execCriteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
                    execCriteria.setFirstResult(startIndex);

                    if (pageSize > 0) {
                      execCriteria.setMaxResults(pageSize);
                    } else {
                      execCriteria.setMaxResults(rowCount);
                    }
                    List<T> items = execCriteria.list();
                    return rowCount > 0
                        ? new PaginationSupport<T>(
                            items, rowCount, startIndex, pageSize > 0 ? pageSize : rowCount)
                        : null;
                  }
                });
  }
예제 #5
0
  /*
   * (non-Javadoc)
   * @see cn.trymore.core.dao.DAOGeneric#getAffectedNumByQueryFilter(java.lang.String, java.lang.String)
   */
  @Override
  @SuppressWarnings("rawtypes")
  public int getAffectedNumByQueryFilter(Class clas, String whereCloud)
      throws DAOException, ClassNotFoundException {
    SingleTableEntityPersister entityPersister =
        (SingleTableEntityPersister) this.getSessionFactory().getClassMetadata(clas);

    StringBuilder nativeSql = new StringBuilder("SELECT COUNT(*) as count FROM ");
    nativeSql.append(entityPersister.getTableName());
    nativeSql.append(" WHERE 1=1 ");

    if (UtilString.isNotEmpty(whereCloud)) {
      if (!whereCloud.trim().toLowerCase().startsWith("and")) {
        nativeSql.append(" AND ");
      }

      nativeSql.append(whereCloud);
    }

    return getCountByNativeSQL(nativeSql.toString());
  }
  /**
   * <b>[WebAction]</b> <br>
   * 消息详细页面
   */
  public ActionForward dialogMessagePage(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    String msgId = request.getParameter("msgId");

    if (UtilString.isNotEmpty(msgId)) {
      if (this.isObjectIdValid(msgId)) {
        try {
          ModelShortMessage entity = this.serviceShortMessage.get(msgId);
          if (entity != null) {
            String msgInId = request.getParameter("msgInId");
            if (UtilString.isNotEmpty(msgInId)) {
              if (this.isObjectIdValid(msgInId)) {
                ModelInMessage msgIn = this.serviceInMessage.get(msgInId);
                if (msgIn == null) {
                  return ajaxPrint(response, getErrorCallback("消息不存在或者已删除..."));
                } else {
                  if (msgIn.getReadFlag().equals(ModelInMessage.FLAG_UNREAD)) {
                    msgIn.setReadFlag(ModelInMessage.FLAG_READ);
                    this.serviceInMessage.save(msgIn);

                    ModelAppUser user = this.serviceAppUser.get(String.valueOf(msgIn.getUserId()));
                    if (user != null) {
                      // 消息推送, 减少消息提醒数量
                      this.messagePush.pushMessage(
                          user.getEmployeeId(),
                          WebActionUtil.scriptMessageNotify,
                          WebActionUtil.scriptArgMessageKey,
                          -1);
                    }
                  }
                }
              } else {
                return ajaxPrint(response, getErrorCallback("需传入合法的接收消息Id..."));
              }
            }

            request.setAttribute("entity", entity);

            // 回复动作.
            String action = request.getParameter("op");
            if (UtilString.isNotEmpty(action) && "reply".equalsIgnoreCase(action)) {
              request.setAttribute("reply", true);

              ModelHrmEmployee employee =
                  this.serviceHrmEmployee.get(String.valueOf(entity.getSenderId()));
              if (employee != null) {
                StringBuilder receiver = new StringBuilder();
                receiver.append("[");
                receiver.append(
                    "{\"id\":\""
                        + employee.getId()
                        + "\", \"empName\":\""
                        + employee.getEmpName()
                        + "\", \"empNo\":\""
                        + employee.getEmpNo()
                        + "\"}");
                receiver.append("]");
                request.setAttribute("receiver", receiver.toString());
              }
            }
          } else {
            return ajaxPrint(response, getErrorCallback("消息(id:" + msgId + ")不存在..."));
          }
        } catch (Exception e) {
          LOGGER.error("Exception raised when open the dialog page of message.", e);
          return ajaxPrint(response, getErrorCallback("页面加载失败:" + e.getMessage()));
        }
      } else {
        return ajaxPrint(response, getErrorCallback("您传入的消息Id不合法..."));
      }

      request.setAttribute("msgId", msgId);
    } else {

      // 填充短消息内容...
      String msgSubject = request.getParameter("msubject");
      if (UtilString.isNotEmpty(msgSubject)) {
        if (msgSubject.indexOf("msg.subject.conference") == -1) {
          request.setAttribute("subject", this.getMessageFromResource(request, msgSubject, null));
        } else {
          String conferenceName = null;
          String mid = request.getParameter("mid");
          if (this.isObjectIdValid(mid)) {
            try {
              ModelConference conference = this.serviceConference.get(mid);
              if (conference != null) {
                conferenceName = conference.getConferenceName();

                ModelHrmEmployee employee = conference.getSponsor().getEmployee();

                StringBuilder receiver = new StringBuilder();
                receiver.append("[");
                receiver.append(
                    "{\"id\":\""
                        + employee.getId()
                        + "\", \"empName\":\""
                        + employee.getEmpName()
                        + "\", \"empNo\":\""
                        + employee.getEmpNo()
                        + "\"}");

                // Temporary solution and it should be enhanced in the future.
                // (Regarding to the entity field not defined employee object).
                List<ModelHrmEmployee> contractor =
                    this.serviceHrmEmployee.findByFullName(conference.getContactor());
                if (contractor != null && contractor.size() > 0) {
                  receiver.append(",");
                  receiver.append(
                      "{\"id\":\""
                          + contractor.get(0).getId()
                          + "\", \"empName\":\""
                          + contractor.get(0).getEmpName()
                          + "\"}");
                  receiver.append("]");
                } else {
                  receiver.append("]");
                }

                request.setAttribute("receiver", receiver.toString());
              }
            } catch (Exception e) {
              LOGGER.error("Exception raised when fetching conference object.", e);
            }
          }

          request.setAttribute(
              "subject",
              this.getMessageFromResource(
                  request,
                  msgSubject,
                  new Object[] {
                    ContextUtil.getCurrentUser().getEmployee().getEmpName(), conferenceName
                  }));
        }

        String msgBody = request.getParameter("mbody");
        if (UtilString.isNotEmpty(msgBody)) {
          request.setAttribute("body", this.getMessageFromResource(request, msgBody));
        }
      }

      try {
        // 设置为个人消息发送
        request.setAttribute("msgType", ModelShortMessage.EMessageType.TYPE_PERSONAL.getValue());

        this.loadOrganizationTree(request);
      } catch (Exception e) {
        LOGGER.error("Exception raised when open the dialog page of message..", e);
        return ajaxPrint(response, getErrorCallback("页面加载失败: " + e.getMessage()));
      }
    }

    return mapping.findForward("dialog.info.msg.page");
  }