Search in sources :

Example 51 with DefaultResult

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

the class MeasureDataCalendarUtils method findMeasureData.

/**
	 * 這個 method 主要給 Expression 使用, 避免近入LogicService 處理時影響到 Transaction
	 * 
	 * @param kpiId
	 * @param date
	 * @param frequency
	 * @param orgaId
	 * @param emplId
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@SuppressWarnings("rawtypes")
public static MeasureDataVO findMeasureData(String kpiId, String date, String frequency, String orgaId, String emplId) throws ServiceException, Exception {
    transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_DEFAULT);
    transactionTemplate.setReadOnly(true);
    MeasureDataVO measureData = null;
    try {
        measureData = (MeasureDataVO) transactionTemplate.execute(new TransactionCallback() {

            @Override
            public Object doInTransaction(TransactionStatus status) {
                MeasureDataVO value = new MeasureDataVO();
                value.setKpiId(kpiId);
                value.setDate(date);
                value.setFrequency(frequency);
                value.setOrgId(orgaId);
                value.setEmpId(emplId);
                try {
                    DefaultResult<MeasureDataVO> mdResult = measureDataService.findByUK(value);
                    if (mdResult.getValue() != null) {
                        value = mdResult.getValue();
                    } else {
                        value = null;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    value = null;
                }
                return value;
            }
        });
    } catch (Exception e) {
        throw e;
    }
    return measureData;
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionStatus(org.springframework.transaction.TransactionStatus) MeasureDataVO(com.netsteadfast.greenstep.vo.MeasureDataVO) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

Example 52 with DefaultResult

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

the class SwotLogicServiceImpl method create.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> create(String visionOid, String organizationOid, List<SwotVO> datas) throws ServiceException, Exception {
    if (super.isBlank(visionOid) || super.isBlank(organizationOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    VisionVO vision = new VisionVO();
    vision.setOid(visionOid);
    DefaultResult<VisionVO> vResult = this.visionService.findObjectByOid(vision);
    if (vResult.getValue() == null) {
        throw new ServiceException(vResult.getSystemMessage().getValue());
    }
    vision = vResult.getValue();
    OrganizationVO organization = this.findOrganizationData(organizationOid);
    //因為 dojo 的 dijit.InlineEditBox 元件特性是, 沒有修改過, 就不會產生editor , 所以修改模式下用全部刪除後->再全部新增會有問題
    //this.delete(vision.getVisId());
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    result.setValue(Boolean.TRUE);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    Map<String, Object> params = new HashMap<String, Object>();
    for (SwotVO swot : datas) {
        if (!vision.getVisId().equals(swot.getVisId()) || !organization.getOrgId().equals(swot.getOrgId())) {
            throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
        }
        this.setStringValueMaxLength(swot, "issues", MAX_ISSUES_LENGTH);
        params.clear();
        params.put("perId", swot.getPerId());
        if (this.perspectiveService.countByParams(params) < 1) {
            throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
        }
        if (this.swotService.countByUK(swot) > 0) {
            // 修改 ISSUES
            this.updateIssues(swot);
        } else {
            // 新增
            this.swotService.saveObject(swot);
        }
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) SwotVO(com.netsteadfast.greenstep.vo.SwotVO) HashMap(java.util.HashMap) OrganizationVO(com.netsteadfast.greenstep.vo.OrganizationVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)52 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)50 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)48 Transactional (org.springframework.transaction.annotation.Transactional)32 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)29 HashMap (java.util.HashMap)13 List (java.util.List)12 Map (java.util.Map)9 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)7 ArrayList (java.util.ArrayList)7 BaseEntity (com.netsteadfast.greenstep.base.model.BaseEntity)6 IOException (java.io.IOException)6 BaseValueObj (com.netsteadfast.greenstep.base.model.BaseValueObj)5 AggregationMethodVO (com.netsteadfast.greenstep.vo.AggregationMethodVO)3 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)3 MeasureDataVO (com.netsteadfast.greenstep.vo.MeasureDataVO)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