Search in sources :

Example 1 with MeasureDataVO

use of com.netsteadfast.greenstep.vo.MeasureDataVO in project bamboobsc by billchen198318.

the class ImportDataLogicServiceImpl method importMeasureData.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importMeasureData(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN005");
    if (csvResults.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST));
    }
    boolean success = false;
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    StringBuilder msg = new StringBuilder();
    Map<String, Object> paramMap = new HashMap<String, Object>();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String kpiId = data.get("KPI_ID");
        String date = data.get("DATE");
        String target = data.get("TARGET");
        String actual = data.get("ACTUAL");
        String frequency = data.get("FREQUENCY");
        String orgId = data.get("ORG_ID");
        String empId = data.get("EMP_ID");
        if (super.isBlank(kpiId)) {
            msg.append("row: " + row + " kpi id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(date)) {
            msg.append("row: " + row + " date is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(target)) {
            msg.append("row: " + row + " target is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(actual)) {
            msg.append("row: " + row + " actual is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(frequency)) {
            msg.append("row: " + row + " frequency is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(orgId)) {
            msg.append("row: " + row + " organization-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(empId)) {
            msg.append("row: " + row + " employee-no is blank." + Constants.HTML_BR);
            continue;
        }
        if (!SimpleUtils.isDate(date)) {
            msg.append("row: " + row + " is not date " + date + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(target)) {
            msg.append("row: " + row + " target is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(actual)) {
            msg.append("row: " + row + " actual is not number." + Constants.HTML_BR);
            continue;
        }
        if (BscMeasureDataFrequency.getFrequencyMap(false).get(frequency) == null) {
            msg.append("row: " + row + " frequency is not found." + Constants.HTML_BR);
            continue;
        }
        paramMap.clear();
        paramMap.put("id", kpiId);
        if (this.kpiService.countByParams(paramMap) < 1) {
            msg.append("row: " + row + " KPI is not found " + kpiId + Constants.HTML_BR);
            continue;
        }
        if (!BscConstants.MEASURE_DATA_ORGANIZATION_FULL.equals(orgId)) {
            paramMap.clear();
            paramMap.put("orgId", orgId);
            if (this.organizationService.countByParams(paramMap) < 1) {
                msg.append("row: " + row + " organization-id is not found " + orgId + Constants.HTML_BR);
                continue;
            }
        }
        if (!BscConstants.MEASURE_DATA_EMPLOYEE_FULL.equals(empId)) {
            paramMap.clear();
            paramMap.put("empId", empId);
            if (this.employeeService.countByParams(paramMap) < 1) {
                msg.append("row: " + row + " employee-no is not found " + empId + Constants.HTML_BR);
                continue;
            }
        }
        MeasureDataVO measureData = new MeasureDataVO();
        measureData.setKpiId(kpiId);
        measureData.setDate(date);
        measureData.setTarget(Float.valueOf(target));
        measureData.setActual(Float.valueOf(actual));
        measureData.setFrequency(frequency);
        measureData.setOrgId(orgId);
        measureData.setEmpId(empId);
        DefaultResult<MeasureDataVO> oldResult = this.measureDataService.findByUK(measureData);
        if (oldResult.getValue() != null) {
            // update
            measureData.setOid(oldResult.getValue().getOid());
            this.measureDataService.updateObject(measureData);
        } else {
            // insert
            this.measureDataService.saveObject(measureData);
        }
        success = true;
    }
    if (msg.length() > 0) {
        result.setSystemMessage(new SystemMessage(msg.toString()));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    }
    result.setValue(success);
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) HashMap(java.util.HashMap) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) MeasureDataVO(com.netsteadfast.greenstep.vo.MeasureDataVO) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MeasureDataVO

use of com.netsteadfast.greenstep.vo.MeasureDataVO in project bamboobsc by billchen198318.

the class MeasureDataLogicServiceImpl method saveOrUpdate.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE, ServiceMethodType.DELETE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> saveOrUpdate(String kpiOid, String date, String frequency, String dataFor, String organizationId, String employeeId, List<MeasureDataVO> measureDatas) throws ServiceException, Exception {
    if (super.isBlank(kpiOid) || super.isBlank(date) || super.isBlank(frequency) || super.isBlank(dataFor) || super.isBlank(organizationId) || super.isBlank(employeeId)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    KpiVO kpi = new KpiVO();
    kpi.setOid(kpiOid);
    DefaultResult<KpiVO> kResult = this.kpiService.findObjectByOid(kpi);
    if (kResult.getValue() == null) {
        throw new ServiceException(kResult.getSystemMessage().getValue());
    }
    kpi = kResult.getValue();
    this.getOrganizationId(organizationId);
    this.getEmployeeId(employeeId);
    if (BscConstants.MEASURE_DATA_FOR_ORGANIZATION.equals(dataFor) && BscConstants.MEASURE_DATA_ORGANIZATION_FULL.equals(organizationId)) {
        throw new ServiceException("organization is required!");
    }
    if (BscConstants.MEASURE_DATA_FOR_EMPLOYEE.equals(dataFor) && BscConstants.MEASURE_DATA_EMPLOYEE_FULL.equals(employeeId)) {
        throw new ServiceException("employee is required!");
    }
    this.fillMeasureDatas(kpi, organizationId, employeeId, measureDatas);
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
    result.setValue(Boolean.FALSE);
    this.delete(kpi, date, frequency, organizationId, employeeId);
    for (MeasureDataVO measureData : measureDatas) {
        this.measureDataService.saveObject(measureData);
    }
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    result.setValue(Boolean.TRUE);
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) MeasureDataVO(com.netsteadfast.greenstep.vo.MeasureDataVO) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with MeasureDataVO

use of com.netsteadfast.greenstep.vo.MeasureDataVO in project bamboobsc by billchen198318.

the class MeasureDataLogicServiceImpl method fillMeasureDatas.

private void fillMeasureDatas(KpiVO kpi, String organizationId, String employeeId, List<MeasureDataVO> measureDatas) {
    for (MeasureDataVO measureData : measureDatas) {
        measureData.setKpiId(kpi.getId());
        measureData.setEmpId(employeeId);
        measureData.setOrgId(organizationId);
    }
}
Also used : MeasureDataVO(com.netsteadfast.greenstep.vo.MeasureDataVO)

Example 4 with MeasureDataVO

use of com.netsteadfast.greenstep.vo.MeasureDataVO in project bamboobsc by billchen198318.

the class MeasureDataSaveOrUpdateAction method fillMeasureDatas.

private List<MeasureDataVO> fillMeasureDatas() throws Exception {
    List<MeasureDataVO> measureDatas = new ArrayList<MeasureDataVO>();
    String frequency = this.defaultString((String) this.getHttpServletRequest().getParameter("BSC_PROG002D0005Q_frequency"));
    Enumeration<String> parameterNames = this.getHttpServletRequest().getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        if (!(name.startsWith(BscConstants.MEASURE_DATA_TARGET_ID) || name.startsWith(BscConstants.MEASURE_DATA_ACTUAL_ID))) {
            continue;
        }
        String value = this.getHttpServletRequest().getParameter(name);
        if (value.trim().equals("")) {
            continue;
        }
        String date = this.getDateFromInputName(name);
        if (!NumberUtils.isNumber(value)) {
            value = "0";
        }
        float numValue = NumberUtils.toFloat(value);
        if (numValue > MAX_VALUE) {
            numValue = MAX_VALUE;
        }
        if (numValue < MIN_VALUE) {
            numValue = MIN_VALUE;
        }
        MeasureDataVO measureData = this.getMeasureDataFromList(date, measureDatas);
        measureData.setDate(date);
        measureData.setFrequency(frequency);
        if (name.startsWith(BscConstants.MEASURE_DATA_TARGET_ID)) {
            measureData.setTarget(numValue);
        }
        if (name.startsWith(BscConstants.MEASURE_DATA_ACTUAL_ID)) {
            measureData.setActual(numValue);
        }
        this.putMeasureDataToList(measureData, measureDatas);
    }
    return measureDatas;
}
Also used : ArrayList(java.util.ArrayList) MeasureDataVO(com.netsteadfast.greenstep.vo.MeasureDataVO)

Example 5 with MeasureDataVO

use of com.netsteadfast.greenstep.vo.MeasureDataVO in project bamboobsc by billchen198318.

the class LoadMeasureDataCommand method execute.

@SuppressWarnings("unchecked")
@Override
public boolean execute(Context context) throws Exception {
    measureDataService = (IMeasureDataService<MeasureDataVO, BbMeasureData, String>) AppContext.getBean("bsc.service.MeasureDataService");
    String frequency = (String) context.get("frequency");
    String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim();
    String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim();
    String startDate = StringUtils.defaultString((String) context.get("startDate")).trim();
    String endDate = StringUtils.defaultString((String) context.get("endDate")).trim();
    startDate = startDate.replaceAll("/", "").replaceAll("-", "");
    endDate = endDate.replaceAll("/", "").replaceAll("-", "");
    String date1 = startDate;
    String date2 = endDate;
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        date1 = startYearDate + "0101";
        date2 = endYearDate + "12" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12);
    }
    String measureDataOrgaId = (String) context.get("orgId");
    String measureDataEmplId = (String) context.get("empId");
    if (this.getResult(context) == null || !(this.getResult(context) instanceof BscStructTreeObj)) {
        return false;
    }
    BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context);
    for (VisionVO vision : treeObj.getVisions()) {
        for (PerspectiveVO perspective : vision.getPerspectives()) {
            for (ObjectiveVO objective : perspective.getObjectives()) {
                for (KpiVO kpi : objective.getKpis()) {
                    this.fillMeasureData(kpi, frequency, date1, date2, measureDataOrgaId, measureDataEmplId);
                }
            }
        }
    }
    return false;
}
Also used : ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) BscStructTreeObj(com.netsteadfast.greenstep.bsc.model.BscStructTreeObj) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) BbMeasureData(com.netsteadfast.greenstep.po.hbm.BbMeasureData) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) MeasureDataVO(com.netsteadfast.greenstep.vo.MeasureDataVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO)

Aggregations

MeasureDataVO (com.netsteadfast.greenstep.vo.MeasureDataVO)6 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)3 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)3 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)2 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)2 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BscStructTreeObj (com.netsteadfast.greenstep.bsc.model.BscStructTreeObj)1 BbMeasureData (com.netsteadfast.greenstep.po.hbm.BbMeasureData)1 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)1 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)1 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1