Search in sources :

Example 76 with ServiceMethodAuthority

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

the class ImportDataLogicServiceImpl method importVisionCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importVisionCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN001");
    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 visId = data.get("VIS_ID");
        String title = data.get("TITLE");
        String content = data.get("CONTENT");
        if (super.isBlank(visId)) {
            msg.append("row: " + row + " id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(title)) {
            msg.append("row: " + row + " title is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(content)) {
            msg.append("row: " + row + " content is blank." + Constants.HTML_BR);
            continue;
        }
        VisionVO vision = new VisionVO();
        vision.setVisId(visId);
        vision.setTitle(title);
        vision.setContent(content.getBytes(Constants.BASE_ENCODING));
        paramMap.put("visId", visId);
        if (this.visionService.countByParams(paramMap) > 0) {
            // update
            DefaultResult<VisionVO> oldResult = this.visionService.findByUK(vision);
            vision.setOid(oldResult.getValue().getOid());
            this.visionLogicService.update(vision);
        } else {
            // insert
            this.visionLogicService.create(vision);
        }
        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) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with ServiceMethodAuthority

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

the class ImportDataLogicServiceImpl method importKPIsCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importKPIsCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN004");
    if (csvResults.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST));
    }
    List<String> organizationOids = new ArrayList<String>();
    List<String> employeeOids = new ArrayList<String>();
    boolean success = false;
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    StringBuilder msg = new StringBuilder();
    // import mode cannot update KPI's attachment/documents, because KPI export no attachment/documents data.
    List<String> kpiAttacDocs = new ArrayList<String>();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String id = data.get("ID");
        String objId = data.get("OBJ_ID");
        String name = data.get("NAME");
        String weight = data.get("WEIGHT");
        String target = data.get("TARGET");
        String min = data.get("MIN");
        String unit = data.get("UNIT");
        String forId = data.get("FOR_ID");
        String management = data.get("MANAGEMENT");
        String compareType = data.get("COMPARE_TYPE");
        String cal = data.get("CAL");
        String dataType = data.get("DATA_TYPE");
        String orgaMeasureSeparate = data.get("ORGA_MEASURE_SEPARATE");
        String userMeasureSeparate = data.get("USER_MEASURE_SEPARATE");
        String quasiRange = data.get("QUASI_RANGE");
        String description = data.get("DESCRIPTION");
        String max = data.get("MAX");
        String trendsForId = data.get("TRENDS_FOR_ID");
        String activate = data.get("ACTIVATE");
        String errMsg = this.checkKPIsDataError(row, id, objId, name, weight, target, min, unit, forId, management, compareType, cal, dataType, orgaMeasureSeparate, userMeasureSeparate, quasiRange, description, max);
        if (!"".equals(errMsg)) {
            msg.append(errMsg);
            continue;
        }
        ObjectiveVO objective = new ObjectiveVO();
        objective.setObjId(objId);
        DefaultResult<ObjectiveVO> objResult = this.objectiveService.findByUK(objective);
        if (objResult.getValue() == null) {
            throw new ServiceException("row: " + row + " strategy-objectives is not found " + objId);
        }
        objective = objResult.getValue();
        /*
			FormulaVO formula = new FormulaVO();
			formula.setForId(forId);
			DefaultResult<FormulaVO> forResult = this.formulaService.findByUK(formula);
			if ( forResult.getValue() == null ) {
				throw new ServiceException( "row: " + row + " formula is not found " + objId );
			}
			formula = forResult.getValue();
			*/
        KpiVO kpi = new KpiVO();
        kpi.setId(id);
        kpi.setName(name);
        kpi.setWeight(new BigDecimal(weight));
        kpi.setMax(Float.valueOf(max));
        kpi.setTarget(Float.valueOf(target));
        kpi.setMin(Float.valueOf(min));
        kpi.setCompareType(compareType);
        kpi.setUnit(unit);
        kpi.setManagement(management);
        kpi.setQuasiRange(Integer.parseInt(quasiRange));
        kpi.setDataType(dataType);
        kpi.setDescription(description);
        kpi.setOrgaMeasureSeparate(YesNo.NO);
        kpi.setUserMeasureSeparate(YesNo.NO);
        kpi.setActivate(YesNo.NO);
        if (YesNo.YES.equals(orgaMeasureSeparate) || YesNo.YES.equals(userMeasureSeparate)) {
            msg.append("row: " + row + " import mode no support organization/personal measure separate data. please manual settings." + Constants.HTML_BR);
        }
        if (YesNo.YES.equals(activate)) {
            kpi.setActivate(YesNo.YES);
        }
        DefaultResult<KpiVO> kResult = this.kpiService.findByUK(kpi);
        if (kResult.getValue() != null) {
            // update
            kpi.setOid(kResult.getValue().getOid());
            this.kpiLogicService.update(kpi, objective.getOid(), BscFormulaUtils.getFormulaById(forId).getOid(), AggregationMethodUtils.findSimpleById(cal).getOid(), organizationOids, employeeOids, BscFormulaUtils.getFormulaById(trendsForId).getOid(), kpiAttacDocs);
        } else {
            // insert
            this.kpiLogicService.create(kpi, objective.getOid(), BscFormulaUtils.getFormulaById(forId).getOid(), AggregationMethodUtils.findSimpleById(cal).getOid(), organizationOids, employeeOids, BscFormulaUtils.getFormulaById(trendsForId).getOid(), kpiAttacDocs);
        }
        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) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) ArrayList(java.util.ArrayList) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) BigDecimal(java.math.BigDecimal) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with ServiceMethodAuthority

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

the class ImportDataLogicServiceImpl method importPerspectivesCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importPerspectivesCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN002");
    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 perId = data.get("PER_ID");
        String visId = data.get("VIS_ID");
        String name = data.get("NAME");
        String weight = data.get("WEIGHT");
        String target = data.get("TARGET");
        String min = data.get("MIN");
        String description = data.get("DESCRIPTION");
        if (super.isBlank(perId)) {
            msg.append("row: " + row + " perspective-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(visId)) {
            msg.append("row: " + row + " vision-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(name)) {
            msg.append("row: " + row + " name is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(weight)) {
            msg.append("row: " + row + " weight is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(target)) {
            msg.append("row: " + row + " target is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(min)) {
            msg.append("row: " + row + " min is blank." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(weight)) {
            msg.append("row: " + row + " weight is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(target)) {
            msg.append("row: " + row + " target is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(min)) {
            msg.append("row: " + row + " min is not number." + Constants.HTML_BR);
            continue;
        }
        paramMap.clear();
        paramMap.put("visId", visId);
        if (this.visionService.countByParams(paramMap) < 1) {
            throw new ServiceException("row: " + row + " vision is not found " + visId);
        }
        DefaultResult<VisionVO> visionResult = this.visionService.findForSimpleByVisId(visId);
        if (visionResult.getValue() == null) {
            throw new ServiceException(visionResult.getSystemMessage().getValue());
        }
        PerspectiveVO perspective = new PerspectiveVO();
        perspective.setPerId(perId);
        perspective.setVisId(visId);
        perspective.setName(name);
        perspective.setWeight(new BigDecimal(weight));
        perspective.setTarget(Float.valueOf(target));
        perspective.setMin(Float.valueOf(min));
        perspective.setDescription(description);
        paramMap.clear();
        paramMap.put("perId", perId);
        if (this.perspectiveService.countByParams(paramMap) > 0) {
            // update
            DefaultResult<PerspectiveVO> oldResult = this.perspectiveService.findByUK(perspective);
            perspective.setOid(oldResult.getValue().getOid());
            this.perspectiveLogicService.update(perspective, visionResult.getValue().getOid());
        } else {
            // insert
            this.perspectiveLogicService.create(perspective, visionResult.getValue().getOid());
        }
        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) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) BigDecimal(java.math.BigDecimal) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 79 with ServiceMethodAuthority

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

the class ImportDataLogicServiceImpl method importObjectivesCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importObjectivesCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN003");
    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();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String objId = data.get("OBJ_ID");
        String perId = data.get("PER_ID");
        String name = data.get("NAME");
        String weight = data.get("WEIGHT");
        String target = data.get("TARGET");
        String min = data.get("MIN");
        String description = data.get("DESCRIPTION");
        if (super.isBlank(objId)) {
            msg.append("row: " + row + " objective-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(perId)) {
            msg.append("row: " + row + " perspective-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(name)) {
            msg.append("row: " + row + " name is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(weight)) {
            msg.append("row: " + row + " weight is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(target)) {
            msg.append("row: " + row + " target is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(min)) {
            msg.append("row: " + row + " min is blank." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(weight)) {
            msg.append("row: " + row + " weight is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(target)) {
            msg.append("row: " + row + " target is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(min)) {
            msg.append("row: " + row + " min is not number." + Constants.HTML_BR);
            continue;
        }
        PerspectiveVO perspective = new PerspectiveVO();
        perspective.setPerId(perId);
        DefaultResult<PerspectiveVO> perResult = this.perspectiveService.findByUK(perspective);
        if (perResult.getValue() == null) {
            throw new ServiceException("row: " + row + " perspective is not found " + perId);
        }
        perspective = perResult.getValue();
        ObjectiveVO objective = new ObjectiveVO();
        objective.setObjId(objId);
        DefaultResult<ObjectiveVO> oldResult = this.objectiveService.findByUK(objective);
        objective.setObjId(objId);
        objective.setPerId(perId);
        objective.setName(name);
        objective.setWeight(new BigDecimal(weight));
        objective.setTarget(Float.valueOf(target));
        objective.setMin(Float.valueOf(min));
        objective.setDescription(description);
        if (oldResult.getValue() != null) {
            // update
            objective.setOid(oldResult.getValue().getOid());
            this.objectiveLogicService.update(objective, perspective.getOid());
        } else {
            // insert
            this.objectiveLogicService.create(objective, perspective.getOid());
        }
        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) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) BigDecimal(java.math.BigDecimal) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 80 with ServiceMethodAuthority

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

the class AggregationMethodLogicServiceImpl method update.

@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<AggregationMethodVO> update(AggregationMethodVO aggregationMethod) throws ServiceException, Exception {
    if (null == aggregationMethod || super.isBlank(aggregationMethod.getName()) || super.isBlank(aggregationMethod.getOid())) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    AggregationMethodVO oldAggregationMethod = AggregationMethodUtils.findSimpleByOid(aggregationMethod.getOid());
    // ID 是 UK 不能改
    aggregationMethod.setAggrId(oldAggregationMethod.getAggrId());
    long countName1 = 0;
    long countName2 = 0;
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("name", aggregationMethod.getName());
    countName1 = this.aggregationMethodService.countByParams(paramMap);
    paramMap.put("aggrId", aggregationMethod.getAggrId());
    countName2 = this.aggregationMethodService.countByParams(paramMap);
    if (countName1 > 0 && countName2 == 0) {
        // 有別筆資料名稱是一樣的
        throw new ServiceException("Please change another name!");
    }
    this.setStringValueMaxLength(aggregationMethod, "description", MAX_DESCRIPTION_LENGTH);
    return this.aggregationMethodService.updateObject(aggregationMethod);
}
Also used : AggregationMethodVO(com.netsteadfast.greenstep.vo.AggregationMethodVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)95 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)91 Transactional (org.springframework.transaction.annotation.Transactional)84 HashMap (java.util.HashMap)32 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)31 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)29 SysVO (com.netsteadfast.greenstep.vo.SysVO)13 LinkedHashMap (java.util.LinkedHashMap)13 Map (java.util.Map)12 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)7 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)7 BaseEntity (com.netsteadfast.greenstep.base.model.BaseEntity)6 EmployeeVO (com.netsteadfast.greenstep.vo.EmployeeVO)6 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)6 IOException (java.io.IOException)6 BaseValueObj (com.netsteadfast.greenstep.base.model.BaseValueObj)5 RoleVO (com.netsteadfast.greenstep.vo.RoleVO)5 SysProgVO (com.netsteadfast.greenstep.vo.SysProgVO)5 UserRoleVO (com.netsteadfast.greenstep.vo.UserRoleVO)5 BbReportRoleView (com.netsteadfast.greenstep.po.hbm.BbReportRoleView)4