Search in sources :

Example 6 with NoRecordFoundException

use of com.rebuild.core.service.NoRecordFoundException in project rebuild by getrebuild.

the class GeneralEntityService method getMainId.

/**
 * 获取主记录ID
 *
 * @param detailEntity
 * @param detailId
 * @return
 * @throws NoRecordFoundException
 */
private ID getMainId(Entity detailEntity, ID detailId) throws NoRecordFoundException {
    Field dtmField = MetadataHelper.getDetailToMainField(detailEntity);
    Object[] o = Application.getQueryFactory().uniqueNoFilter(detailId, dtmField.getName());
    if (o == null) {
        throw new NoRecordFoundException(detailId);
    }
    return (ID) o[0];
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField) NoRecordFoundException(com.rebuild.core.service.NoRecordFoundException) ID(cn.devezhao.persist4j.engine.ID)

Example 7 with NoRecordFoundException

use of com.rebuild.core.service.NoRecordFoundException in project rebuild by getrebuild.

the class ApprovalList method build.

@Override
public JSON build() {
    final int viewState = ObjectUtils.toInt(getExtraParams().get("state"), ApprovalState.DRAFT.getState());
    final String baseWhere = "where isCanceled = 'F' and isWaiting = 'F' and approver = ?" + " and approvalId <> '' and recordId <> '' and ";
    Object[][] array = Application.createQueryNoFilter("select createdBy,modifiedOn,recordId,approvalId from RobotApprovalStep " + baseWhere + " state = ? order by modifiedOn desc").setParameter(1, this.getUser()).setParameter(2, viewState).setLimit(// 最多显示
    500).array();
    List<Object> rearray = new ArrayList<>();
    int deleted = 0;
    for (Object[] o : array) {
        final ID recordId = (ID) o[2];
        String label;
        try {
            label = FieldValueHelper.getLabel(recordId);
        } catch (NoRecordFoundException ignored) {
            deleted++;
            continue;
        }
        final ApprovalState currentState = ApprovalHelper.getApprovalState(recordId);
        if (currentState == ApprovalState.CANCELED) {
            deleted++;
            continue;
        }
        Entity entity = MetadataHelper.getEntity(recordId.getEntityCode());
        ID s = ApprovalHelper.getSubmitter(recordId, (ID) o[3]);
        rearray.add(new Object[] { s, UserHelper.getName(s), I18nUtils.formatDate((Date) o[1]), o[2], label, o[3], EasyMetaFactory.getLabel(entity), entity.getName() });
    }
    Object[][] stats = Application.createQueryNoFilter("select state,count(state) from RobotApprovalStep " + baseWhere + " state < ? group by state").setParameter(1, this.getUser()).setParameter(2, ApprovalState.CANCELED.getState()).array();
    // FIXME 排除删除的(可能导致不同状态下数据不一致)
    if (deleted > 0) {
        for (Object[] o : stats) {
            if ((Integer) o[0] == viewState) {
                o[1] = ObjectUtils.toInt(o[1]) - deleted;
                if ((Integer) o[1] < 0) {
                    o[1] = 0;
                }
            }
        }
    }
    Map<String, Object> ret = new HashMap<>();
    ret.put("data", rearray);
    ret.put("stats", stats);
    return (JSON) JSON.toJSON(ret);
}
Also used : Entity(cn.devezhao.persist4j.Entity) NoRecordFoundException(com.rebuild.core.service.NoRecordFoundException) ApprovalState(com.rebuild.core.service.approval.ApprovalState) JSON(com.alibaba.fastjson.JSON) ID(cn.devezhao.persist4j.engine.ID)

Example 8 with NoRecordFoundException

use of com.rebuild.core.service.NoRecordFoundException in project rebuild by getrebuild.

the class ReferenceSearchController method referenceLabel.

// 获取记录的名称字段值
@GetMapping("read-labels")
public RespBody referenceLabel(HttpServletRequest request) {
    final String ids = getParameter(request, "ids", null);
    if (StringUtils.isBlank(ids)) {
        return RespBody.ok();
    }
    final ID user = getRequestUser(request);
    // 不存在的记录不返回
    boolean ignoreMiss = getBoolParameter(request, "ignoreMiss", false);
    // 检查权限,无权限的不返回
    boolean checkPrivileges = getBoolParameter(request, "checkPrivileges", false);
    Map<String, String> labels = new HashMap<>();
    for (String id : ids.split("[|,]")) {
        if (!ID.isId(id))
            continue;
        ID recordId = ID.valueOf(id);
        if (checkPrivileges && !Application.getPrivilegesManager().allowRead(user, recordId))
            continue;
        if (ignoreMiss) {
            try {
                labels.put(id, FieldValueHelper.getLabel(recordId));
            } catch (NoRecordFoundException ignored) {
            }
        } else {
            labels.put(id, FieldValueHelper.getLabelNotry(recordId));
        }
    }
    return RespBody.ok(labels);
}
Also used : NoRecordFoundException(com.rebuild.core.service.NoRecordFoundException) ID(cn.devezhao.persist4j.engine.ID) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 9 with NoRecordFoundException

use of com.rebuild.core.service.NoRecordFoundException in project rebuild by getrebuild.

the class ObservableService method record.

/**
 * 用于操作前获取原记录
 *
 * @param base
 * @return
 */
protected Record record(Record base) {
    final ID primaryId = base.getPrimary();
    Assert.notNull(primaryId, "Record primary cannot be null");
    StringBuilder sql = new StringBuilder("select ");
    for (Iterator<String> iter = base.getAvailableFieldIterator(); iter.hasNext(); ) {
        sql.append(iter.next()).append(',');
    }
    sql.deleteCharAt(sql.length() - 1);
    sql.append(" from ").append(base.getEntity().getName()).append(" where ").append(base.getEntity().getPrimaryField().getName()).append(" = ?");
    Record snap = Application.createQueryNoFilter(sql.toString()).setParameter(1, primaryId).record();
    if (snap == null) {
        throw new NoRecordFoundException(primaryId);
    }
    N2NReferenceSupport.fillN2NValues(snap);
    return snap;
}
Also used : NoRecordFoundException(com.rebuild.core.service.NoRecordFoundException) Record(cn.devezhao.persist4j.Record) ID(cn.devezhao.persist4j.engine.ID)

Aggregations

NoRecordFoundException (com.rebuild.core.service.NoRecordFoundException)9 ID (cn.devezhao.persist4j.engine.ID)8 Entity (cn.devezhao.persist4j.Entity)4 EasyField (com.rebuild.core.metadata.easymeta.EasyField)3 Field (cn.devezhao.persist4j.Field)2 ApprovalState (com.rebuild.core.service.approval.ApprovalState)2 PrivilegesException (cn.devezhao.bizz.privileges.PrivilegesException)1 Record (cn.devezhao.persist4j.Record)1 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DataSpecificationException (com.rebuild.core.service.DataSpecificationException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1