Search in sources :

Example 36 with SystemMessage

use of com.netsteadfast.greenstep.base.model.SystemMessage in project bamboobsc by billchen198318.

the class BaseDAO method findPageQueryResult.

/**
	 * 頁面查詢grid資料用 
	 * 
	 * map 放入 key為 persisent obj 欄位名稱
	 * 
	 */
@SuppressWarnings("unchecked")
public <RO extends QueryResult<List<VO>>, VO extends java.io.Serializable> QueryResult<List<VO>> findPageQueryResult(String findHQL, String countHQL, Map<String, Object> params, int offset, int limit) throws Exception {
    QueryResult<List<VO>> result = new QueryResult<List<VO>>();
    List<VO> list = null;
    long count = 0L;
    Session hbmSession = this.getCurrentSession();
    try {
        Query query = hbmSession.createQuery(countHQL);
        if (params != null) {
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                if (entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_ORDER_BY) || entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_SORT_TYPE)) {
                    continue;
                }
                this.setQueryParams(query, entry.getKey(), entry.getValue());
            }
        }
        count = ((Long) query.uniqueResult()).longValue();
        int newOffset = offset;
        if (count > 0) {
            if (offset >= count) {
                // 改掉原本頁面上一次查詢的欄位值 , 2014-10-08 offset>count
                newOffset = (int) (count - Long.valueOf(limit));
                if (newOffset < 0) {
                    newOffset = 0;
                }
            }
            query = hbmSession.createQuery(findHQL);
            if (params != null) {
                for (Map.Entry<String, Object> entry : params.entrySet()) {
                    if (entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_ORDER_BY) || entry.getKey().equals(Constants._RESERVED_PARAM_NAME_QUERY_SORT_TYPE)) {
                        continue;
                    }
                    this.setQueryParams(query, entry.getKey(), entry.getValue());
                }
            }
            //offset
            query.setFirstResult(newOffset);
            query.setMaxResults(limit);
            list = (List<VO>) query.list();
        }
        result.setRowCount(count);
        // 2017-06-30 bug fix, result.setOffset(offset);
        result.setOffset(newOffset);
        result.setLimit(limit);
        result.setFindHQL(findHQL);
        result.setCountHQL(countHQL);
        if (list != null && list.size() > 0) {
            result.setValue(list);
        } else {
            result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)));
        }
    } catch (Exception e) {
        e.printStackTrace();
        result.setSystemMessage(new SystemMessage(e.getMessage()));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) Query(org.hibernate.Query) DataAccessException(org.springframework.dao.DataAccessException) QueryResult(com.netsteadfast.greenstep.base.model.QueryResult) List(java.util.List) Map(java.util.Map) Session(org.hibernate.Session) SqlSession(org.apache.ibatis.session.SqlSession)

Example 37 with SystemMessage

use of com.netsteadfast.greenstep.base.model.SystemMessage in project bamboobsc by billchen198318.

the class BaseService method ibatisSelectListByParams.

// ------------------------------------------------------------------------------------
@Transactional(isolation = Isolation.READ_COMMITTED, timeout = 25, readOnly = true)
public DefaultResult<List<E>> ibatisSelectListByParams(Map<String, Object> params) throws ServiceException, Exception {
    if (params == null) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<List<E>> result = new DefaultResult<List<E>>();
    List<E> searchList = (List<E>) this.getBaseDataAccessObject().ibatisSelectListByParams(params);
    if (searchList != null && searchList.size() > 0) {
        result.setValue(searchList);
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ArrayList(java.util.ArrayList) List(java.util.List) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with SystemMessage

use of com.netsteadfast.greenstep.base.model.SystemMessage in project bamboobsc by billchen198318.

the class BaseService method deleteObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
@ServiceMethodAuthority(type = { ServiceMethodType.DELETE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
public DefaultResult<Boolean> deleteObject(T object) throws ServiceException, Exception {
    if (object == null || !(object instanceof BaseValueObj)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    Class<E> entityObjectClass = GenericsUtils.getSuperClassGenricType(getClass(), 1);
    E entityObject = entityObjectClass.newInstance();
    ((BaseEntity) entityObject).setOid(((BaseValueObj) object).getOid());
    boolean status = false;
    if (this.countByOid(entityObject) > 0) {
        this.delete(entityObject);
        status = true;
    }
    result.setValue(status);
    if (status) {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_SUCCESS)));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_FAIL)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BaseEntity(com.netsteadfast.greenstep.base.model.BaseEntity) BaseValueObj(com.netsteadfast.greenstep.base.model.BaseValueObj) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with SystemMessage

use of com.netsteadfast.greenstep.base.model.SystemMessage in project bamboobsc by billchen198318.

the class DegreeFeedbackScoreServiceImpl method findResultsByProjectAndOwner.

@Override
public DefaultResult<List<BbDegreeFeedbackScore>> findResultsByProjectAndOwner(String projectOid, String ownerId) throws Exception {
    if (StringUtils.isBlank(projectOid) || StringUtils.isBlank(ownerId)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    List<BbDegreeFeedbackScore> searchList = this.degreeFeedbackScoreDAO.findForListByProjectAndOwner(projectOid, ownerId);
    DefaultResult<List<BbDegreeFeedbackScore>> result = new DefaultResult<List<BbDegreeFeedbackScore>>();
    if (null != searchList && searchList.size() > 0) {
        result.setValue(searchList);
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BbDegreeFeedbackScore(com.netsteadfast.greenstep.po.hbm.BbDegreeFeedbackScore) List(java.util.List) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult)

Example 40 with SystemMessage

use of com.netsteadfast.greenstep.base.model.SystemMessage in project bamboobsc by billchen198318.

the class AggregationMethodServiceImpl method findSimpleByOid.

@Override
public DefaultResult<AggregationMethodVO> findSimpleByOid(String aggrOid) throws ServiceException, Exception {
    if (StringUtils.isBlank(aggrOid) || super.isNoSelectId(aggrOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    AggregationMethodVO aggr = this.aggregationMethodDAO.findSimpleByOid(aggrOid);
    DefaultResult<AggregationMethodVO> result = new DefaultResult<AggregationMethodVO>();
    if (aggr != null && !StringUtils.isBlank(aggr.getOid())) {
        result.setValue(aggr);
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) AggregationMethodVO(com.netsteadfast.greenstep.vo.AggregationMethodVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult)

Aggregations

SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)53 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)50 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)49 Transactional (org.springframework.transaction.annotation.Transactional)34 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)31 HashMap (java.util.HashMap)13 List (java.util.List)12 Map (java.util.Map)10 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)7 BaseEntity (com.netsteadfast.greenstep.base.model.BaseEntity)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 BaseValueObj (com.netsteadfast.greenstep.base.model.BaseValueObj)5 AggregationMethodVO (com.netsteadfast.greenstep.vo.AggregationMethodVO)3 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)3 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)3 OrganizationVO (com.netsteadfast.greenstep.vo.OrganizationVO)3 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)3 RoleVO (com.netsteadfast.greenstep.vo.RoleVO)3 BigDecimal (java.math.BigDecimal)3