Search in sources :

Example 1 with CustomeOperational

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

the class BaseDAO method getQueryByParams.

/**
	 * 只提供給 countByParams, findListByParams 用
	 * 
	 * @param params
	 * @return
	 * @throws Exception
	 */
private Query getQueryByParams(String type, Map<String, Object> params, Map<String, String> likeParams, Map<String, String> orderByParams, Map<String, CustomeOperational> customOperParams) throws Exception {
    StringBuilder sb = new StringBuilder();
    if (Constants.QUERY_TYPE_OF_COUNT.equals(type)) {
        sb.append("select count(*) from ").append(this.getPersisentName()).append(" ");
    } else {
        sb.append("from ").append(this.getPersisentName()).append(" ");
    }
    int field = 0;
    if (params != null && params.size() > 0) {
        // set hql
        sb.append(" where 1=1 ");
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            sb.append(" and ").append(entry.getKey()).append("=?").append(field).append(" ");
            field++;
        }
    }
    if (customOperParams != null && customOperParams.size() > 0) {
        // set hql with >= , <= , >, < , <>
        if (params == null || params.size() < 1) {
            sb.append(" where 1=1 ");
        }
        for (Map.Entry<String, CustomeOperational> entry : customOperParams.entrySet()) {
            sb.append(" and ").append(entry.getValue().getField()).append(entry.getValue().getOp()).append("?").append(field).append(" ");
            field++;
        }
    }
    if (likeParams != null && likeParams.size() > 0) {
        // set hql like
        if ((params == null || params.size() < 1) && (customOperParams == null || customOperParams.size() < 1)) {
            sb.append(" where 1=1 ");
        }
        for (Map.Entry<String, String> entry : likeParams.entrySet()) {
            sb.append(" and ").append(entry.getKey()).append(" like ?").append(field).append(" ");
            field++;
        }
    }
    if (orderByParams != null && orderByParams.size() > 0) {
        // order by
        sb.append(" order by ");
        int order = 0;
        for (Map.Entry<String, String> entry : orderByParams.entrySet()) {
            sb.append(entry.getKey()).append(" ").append(entry.getValue()).append(" ");
            if (++order < orderByParams.size()) {
                sb.append(" , ");
            }
        }
    }
    field = 0;
    Query query = this.getCurrentSession().createQuery(sb.toString());
    if (params != null && params.size() > 0) {
        // set query params value
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            this.setQueryParams(query, String.valueOf(field), entry.getValue());
            field++;
        }
    }
    if (customOperParams != null && customOperParams.size() > 0) {
        // set hql with >= , <= , >, < , <>
        for (Map.Entry<String, CustomeOperational> entry : customOperParams.entrySet()) {
            this.setQueryParams(query, String.valueOf(field), entry.getValue().getValue());
            field++;
        }
    }
    if (likeParams != null && likeParams.size() > 0) {
        // set query params like value
        for (Map.Entry<String, String> entry : likeParams.entrySet()) {
            this.setQueryParams(query, String.valueOf(field), entry.getValue());
            field++;
        }
    }
    return query;
}
Also used : Query(org.hibernate.Query) CustomeOperational(com.netsteadfast.greenstep.base.model.CustomeOperational) Map(java.util.Map)

Example 2 with CustomeOperational

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

the class LoadMeasureDataCommand method fillMeasureData.

private void fillMeasureData(KpiVO kpi, String frequency, String startDate, String endDate, String orgId, String empId) throws Exception {
    Map<String, Object> params = new HashMap<String, Object>();
    Map<String, CustomeOperational> customOperParams = new HashMap<String, CustomeOperational>();
    params.put("kpiId", kpi.getId());
    params.put("frequency", frequency);
    params.put("orgId", orgId);
    params.put("empId", empId);
    CustomeOperational op1 = new CustomeOperational();
    op1.setField("date");
    op1.setOp(">=");
    op1.setValue(startDate);
    CustomeOperational op2 = new CustomeOperational();
    op2.setField("date");
    op2.setOp("<=");
    op2.setValue(endDate);
    customOperParams.put("op1", op1);
    customOperParams.put("op2", op2);
    List<BbMeasureData> measureDatas = this.measureDataService.findListByParams2(params, customOperParams);
    kpi.setMeasureDatas(measureDatas);
}
Also used : HashMap(java.util.HashMap) BbMeasureData(com.netsteadfast.greenstep.po.hbm.BbMeasureData) CustomeOperational(com.netsteadfast.greenstep.base.model.CustomeOperational)

Example 3 with CustomeOperational

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

the class MonitorItemScoreServiceImpl method getHistoryDataList.

@Override
public Map<String, List<MonitorItemScoreVO>> getHistoryDataList(String itemType, String frequency, String dateVal, String orgId, String empId, int daysBeforeRange) throws ServiceException, Exception {
    if (StringUtils.isBlank(itemType) || StringUtils.isBlank(frequency) || StringUtils.isBlank(dateVal)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    if (!SimpleUtils.isDate(dateVal)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_INCORRECT));
    }
    if (daysBeforeRange > MAX_DAYS_BEFORE_RANGE || daysBeforeRange < 0) {
        throw new ServiceException("daysBeforeRange error!");
    }
    Date endDate = DateUtils.parseDate(dateVal, new String[] { "yyyyMMdd" });
    Date startDate = DateUtils.addDays(endDate, (daysBeforeRange * -1));
    String startDateStr = DateFormatUtils.format(startDate, "yyyyMMdd");
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("itemType", itemType);
    paramMap.put("frequency", frequency);
    paramMap.put("orgId", orgId);
    paramMap.put("empId", empId);
    Map<String, CustomeOperational> customeMap = new HashMap<String, CustomeOperational>();
    CustomeOperational op1 = new CustomeOperational();
    op1.setField("dateVal");
    op1.setOp(">=");
    op1.setValue(startDateStr);
    CustomeOperational op2 = new CustomeOperational();
    op2.setField("dateVal");
    op2.setOp("<=");
    op2.setValue(dateVal);
    customeMap.put("op1", op1);
    customeMap.put("op2", op2);
    List<BbMonitorItemScore> searchList = this.findListByParams2(paramMap, customeMap);
    if (null == searchList || searchList.size() < 1) {
        return null;
    }
    Map<String, List<MonitorItemScoreVO>> dataMap = new HashMap<String, List<MonitorItemScoreVO>>();
    List<String> idKeyList = new ArrayList<String>();
    for (BbMonitorItemScore data : searchList) {
        if (idKeyList.contains(data.getItemId())) {
            continue;
        }
        idKeyList.add(data.getItemId());
        dataMap.put(data.getItemId(), new LinkedList<MonitorItemScoreVO>());
    }
    for (int i = 0; i <= daysBeforeRange; i++) {
        Date currentDate = DateUtils.addDays(startDate, i);
        String currentDateStr = DateFormatUtils.format(currentDate, "yyyyMMdd");
        for (String id : idKeyList) {
            MonitorItemScoreVO scoreData = new MonitorItemScoreVO();
            scoreData.setItemType(itemType);
            scoreData.setItemId(id);
            scoreData.setFrequency(frequency);
            scoreData.setOrgId(orgId);
            scoreData.setEmpId(empId);
            scoreData.setDateVal(currentDateStr);
            // 如果沒有當天歷史分數資料的話, 預設就是"0"
            scoreData.setScore("0");
            for (BbMonitorItemScore data : searchList) {
                if (data.getItemId().equals(id) && data.getDateVal().equals(currentDateStr)) {
                    scoreData.setScore(data.getScore());
                }
            }
            dataMap.get(id).add(scoreData);
        }
    }
    return dataMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BbMonitorItemScore(com.netsteadfast.greenstep.po.hbm.BbMonitorItemScore) CustomeOperational(com.netsteadfast.greenstep.base.model.CustomeOperational) Date(java.util.Date) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MonitorItemScoreVO(com.netsteadfast.greenstep.vo.MonitorItemScoreVO)

Aggregations

CustomeOperational (com.netsteadfast.greenstep.base.model.CustomeOperational)3 HashMap (java.util.HashMap)2 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 BbMeasureData (com.netsteadfast.greenstep.po.hbm.BbMeasureData)1 BbMonitorItemScore (com.netsteadfast.greenstep.po.hbm.BbMonitorItemScore)1 MonitorItemScoreVO (com.netsteadfast.greenstep.vo.MonitorItemScoreVO)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Query (org.hibernate.Query)1