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];
}
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);
}
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);
}
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;
}
Aggregations