Search in sources :

Example 6 with ServiceException

use of com.duangframework.core.exceptions.ServiceException in project duangframework by tcrct.

the class CurdService method update.

/**
 * 更改记录
 */
public boolean update(T entity) throws ServiceException {
    try {
        updateIdEntityData(entity);
        boolean isOk = getMongoDao().update(entity.getId(), entity);
        if (isOk && (getCacheDao() != null)) {
            T cacheEntity = (T) getCacheDao().findById(entity.getId(), getEntityClass());
            ObjectKit.copyFields(entity, cacheEntity);
            if (ToolsKit.isNotEmpty(entity.getCreateuserid())) {
                cacheEntity.setCreateuserid(entity.getCreateuserid());
            }
            if (ToolsKit.isNotEmpty(entity.getCreatetime())) {
                cacheEntity.setCreatetime(entity.getCreatetime());
            }
            if (ToolsKit.isNotEmpty(entity.getId())) {
                cacheEntity.setId(entity.getId());
            }
            if (ToolsKit.isNotEmpty(entity.getSource())) {
                cacheEntity.setSource(entity.getSource());
            }
            if (ToolsKit.isNotEmpty(entity.getStatus())) {
                cacheEntity.setStatus(entity.getStatus());
            }
            if (ToolsKit.isNotEmpty(entity.getUpdatetime())) {
                cacheEntity.setUpdatetime(entity.getUpdatetime());
            }
            if (ToolsKit.isNotEmpty(entity.getUpdateuserid())) {
                cacheEntity.setUpdateuserid(entity.getUpdateuserid());
            }
            getCacheDao().save(cacheEntity);
        }
        return true;
    } catch (Exception e) {
        throw new ServiceException("update entity[" + entity.getId() + "] record is fail: " + e.getMessage(), e);
    }
}
Also used : ServiceException(com.duangframework.core.exceptions.ServiceException) ServiceException(com.duangframework.core.exceptions.ServiceException) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException)

Aggregations

ServiceException (com.duangframework.core.exceptions.ServiceException)6 EmptyNullException (com.duangframework.core.exceptions.EmptyNullException)4 MongoQuery (com.duangframework.mongodb.common.MongoQuery)2 JSONObject (com.alibaba.fastjson.JSONObject)1 HeadDto (com.duangframework.core.common.dto.result.HeadDto)1 ReturnDto (com.duangframework.core.common.dto.result.ReturnDto)1 IEnums (com.duangframework.core.common.enums.IEnums)1 MongoUpdate (com.duangframework.mongodb.common.MongoUpdate)1 RuleParam (com.duangframework.rule.entity.RuleParam)1 RuleResult (com.duangframework.rule.entity.RuleResult)1 Field (java.lang.reflect.Field)1 RuleNameEndsWithAgendaFilter (org.drools.core.base.RuleNameEndsWithAgendaFilter)1 KieSession (org.kie.api.runtime.KieSession)1