Search in sources :

Example 1 with Department

use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.

the class FormsBuilder method buildModelElements.

/**
 * 构建表单元素
 *
 * @param elements
 * @param entity
 * @param data
 * @param user
 * @param useAdvControl
 */
protected void buildModelElements(JSONArray elements, Entity entity, Record data, ID user, boolean useAdvControl) {
    final User formUser = Application.getUserStore().getUser(user);
    final Date now = CalendarUtils.now();
    // Check and clean
    for (Iterator<Object> iter = elements.iterator(); iter.hasNext(); ) {
        JSONObject el = (JSONObject) iter.next();
        String fieldName = el.getString("field");
        if (DIVIDER_LINE.equalsIgnoreCase(fieldName)) {
            continue;
        }
        // 已删除字段
        if (!MetadataHelper.checkAndWarnField(entity, fieldName)) {
            iter.remove();
            continue;
        }
        // v2.2 高级控制
        Object displayOnCreate = el.remove("displayOnCreate");
        Object displayOnUpdate = el.remove("displayOnUpdate");
        Object requiredOnCreate = el.remove("requiredOnCreate");
        Object requiredOnUpdate = el.remove("requiredOnUpdate");
        if (useAdvControl) {
            // 显示
            if (displayOnCreate != null && !(Boolean) displayOnCreate && data == null) {
                iter.remove();
                continue;
            }
            if (displayOnUpdate != null && !(Boolean) displayOnUpdate && data != null) {
                iter.remove();
                continue;
            }
            // 必填
            if (requiredOnCreate != null && (Boolean) requiredOnCreate && data == null) {
                el.put("nullable", false);
            }
            if (requiredOnUpdate != null && (Boolean) requiredOnUpdate && data != null) {
                el.put("nullable", false);
            }
        }
        // 自动只读的
        final boolean roViaAuto = el.getBooleanValue("readonly");
        final Field fieldMeta = entity.getField(fieldName);
        final EasyField easyField = EasyMetaFactory.valueOf(fieldMeta);
        final DisplayType dt = easyField.getDisplayType();
        el.put("label", easyField.getLabel());
        el.put("type", dt.name());
        el.put("readonly", (data != null && !fieldMeta.isUpdatable()) || roViaAuto);
        // 优先使用指定值
        final Boolean nullable = el.getBoolean("nullable");
        if (nullable != null) {
            el.put("nullable", nullable);
        } else {
            el.put("nullable", fieldMeta.isNullable());
        }
        // 字段扩展配置 FieldExtConfigProps
        JSONObject fieldExtAttrs = easyField.getExtraAttrs(true);
        el.putAll(fieldExtAttrs);
        if (dt == DisplayType.PICKLIST) {
            JSONArray options = PickListManager.instance.getPickList(fieldMeta);
            el.put("options", options);
        } else if (dt == DisplayType.STATE) {
            JSONArray options = StateManager.instance.getStateOptions(fieldMeta);
            el.put("options", options);
            el.remove(EasyFieldConfigProps.STATE_CLASS);
        } else if (dt == DisplayType.MULTISELECT) {
            JSONArray options = MultiSelectManager.instance.getSelectList(fieldMeta);
            el.put("options", options);
        } else if (dt == DisplayType.DATETIME) {
            String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.DATETIME_FORMAT), easyField.getDisplayType().getDefaultFormat());
            el.put(EasyFieldConfigProps.DATETIME_FORMAT, format);
        } else if (dt == DisplayType.DATE) {
            String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.DATE_FORMAT), easyField.getDisplayType().getDefaultFormat());
            el.put(EasyFieldConfigProps.DATE_FORMAT, format);
        } else if (dt == DisplayType.TIME) {
            String format = StringUtils.defaultIfBlank(easyField.getExtraAttr(EasyFieldConfigProps.TIME_FORMAT), easyField.getDisplayType().getDefaultFormat());
            el.put(EasyFieldConfigProps.TIME_FORMAT, format);
        } else if (dt == DisplayType.CLASSIFICATION) {
            el.put("openLevel", ClassificationManager.instance.getOpenLevel(fieldMeta));
        }
        // 编辑/视图
        if (data != null) {
            Object value = wrapFieldValue(data, easyField, user);
            if (value != null) {
                el.put("value", value);
            }
        } else // 新建记录
        {
            if (!fieldMeta.isCreatable()) {
                el.put("readonly", true);
                switch(fieldName) {
                    case EntityHelper.CreatedOn:
                    case EntityHelper.ModifiedOn:
                        el.put("value", CalendarUtils.getUTCDateTimeFormat().format(now));
                        break;
                    case EntityHelper.CreatedBy:
                    case EntityHelper.ModifiedBy:
                    case EntityHelper.OwningUser:
                        el.put("value", FieldValueHelper.wrapMixValue(formUser.getId(), formUser.getFullName()));
                        break;
                    case EntityHelper.OwningDept:
                        Department dept = formUser.getOwningDept();
                        Assert.notNull(dept, "Department of user is unset : " + formUser.getId());
                        el.put("value", FieldValueHelper.wrapMixValue((ID) dept.getIdentity(), dept.getName()));
                        break;
                    case EntityHelper.ApprovalId:
                        el.put("value", FieldValueHelper.wrapMixValue(null, Language.L("未提交")));
                        break;
                    case EntityHelper.ApprovalState:
                        el.put("value", ApprovalState.DRAFT.getState());
                        break;
                    default:
                        break;
                }
            }
            // 默认值
            if (el.get("value") == null) {
                if (dt == DisplayType.SERIES) {
                    el.put("value", Language.L("自动值"));
                } else {
                    Object defaultValue = easyField.exprDefaultValue();
                    if (defaultValue != null) {
                        el.put("value", easyField.wrapValue(defaultValue));
                    }
                }
            }
            // 触发器自动值
            if (roViaAuto && el.get("value") == null) {
                if (dt == DisplayType.EMAIL || dt == DisplayType.PHONE || dt == DisplayType.URL || dt == DisplayType.DATE || dt == DisplayType.DATETIME || dt == DisplayType.NUMBER || dt == DisplayType.DECIMAL || dt == DisplayType.SERIES || dt == DisplayType.TEXT || dt == DisplayType.NTEXT) {
                    el.put("value", Language.L("自动值"));
                }
            }
        }
    // end 新建记录
    }
// end for
}
Also used : User(com.rebuild.core.privileges.bizz.User) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSONArray(com.alibaba.fastjson.JSONArray) EasyField(com.rebuild.core.metadata.easymeta.EasyField) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) Department(com.rebuild.core.privileges.bizz.Department) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID)

Example 2 with Department

use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.

the class DepartmentService method update.

@Override
public Record update(Record record) {
    checkAdminGuard(BizzPermission.UPDATE, record.getPrimary());
    // 检查父子循环依赖
    if (record.hasValue("parentDept", false)) {
        ID parentDept = record.getID("parentDept");
        if (parentDept.equals(record.getPrimary())) {
            throw new DataSpecificationException(Language.L("父级部门不能选择自己"));
        }
        Department parent = Application.getUserStore().getDepartment(parentDept);
        Department that = Application.getUserStore().getDepartment(record.getPrimary());
        if (that.isChildren(parent, true)) {
            throw new DataSpecificationException(Language.L("子级部门不能同时作为父级部门"));
        }
    }
    record = super.update(record);
    Application.getUserStore().refreshDepartment(record.getPrimary());
    return record;
}
Also used : Department(com.rebuild.core.privileges.bizz.Department) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

Example 3 with Department

use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.

the class DepartmentService method deleteAndTransfer.

/**
 * TODO 删除后转移成员到其他部门
 *
 * @param deptId
 * @param transferTo
 */
public void deleteAndTransfer(ID deptId, ID transferTo) {
    checkAdminGuard(BizzPermission.DELETE, null);
    Department dept = Application.getUserStore().getDepartment(deptId);
    if (!dept.getMembers().isEmpty()) {
        throw new OperationDeniedException(Language.L("部门下有用户禁止删除"));
    }
    if (!dept.getChildren().isEmpty()) {
        throw new OperationDeniedException(Language.L("部门下有子部门禁止删除"));
    }
    super.delete(deptId);
    Application.getUserStore().removeDepartment(deptId, transferTo);
}
Also used : Department(com.rebuild.core.privileges.bizz.Department)

Example 4 with Department

use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.

the class FlowNode method getSpecUsers.

/**
 * 获取相关人员(提交人/审批人/抄送人)
 *
 * @param operator
 * @param record
 * @return
 */
public Set<ID> getSpecUsers(ID operator, ID record) {
    JSONArray userDefs = getDataMap().getJSONArray("users");
    if (userDefs == null || userDefs.isEmpty()) {
        return Collections.emptySet();
    }
    String userType = userDefs.getString(0);
    if (USER_SELF.equalsIgnoreCase(userType)) {
        Set<ID> users = new HashSet<>();
        ID owning = Application.getRecordOwningCache().getOwningUser(record);
        users.add(owning);
        return users;
    }
    Set<ID> users = new HashSet<>();
    List<String> defsList = new ArrayList<>();
    for (Object o : userDefs) {
        String def = (String) o;
        if (def.startsWith(ApprovalHelper.APPROVAL_SUBMITOR) || def.startsWith(ApprovalHelper.APPROVAL_APPROVER)) {
            ApprovalState state = ApprovalHelper.getApprovalState(record);
            boolean isSubmitted = state == ApprovalState.PROCESSING || state == ApprovalState.APPROVED;
            ID whichUser = operator;
            if (def.startsWith(ApprovalHelper.APPROVAL_SUBMITOR)) {
                if (isSubmitted) {
                    whichUser = ApprovalHelper.getSubmitter(record);
                } else {
                // 提交人即发起人
                }
            } else {
                if (isSubmitted) {
                // 提交人即审批人
                } else {
                    // 未提交
                    whichUser = null;
                }
            }
            if (whichUser != null) {
                Field userField = ApprovalHelper.checkVirtualField(def);
                if (userField != null) {
                    Object[] ud;
                    // 部门中的用户(如上级)
                    if (userField.getOwnEntity().getEntityCode() == EntityHelper.Department) {
                        Department d = Application.getUserStore().getUser(whichUser).getOwningDept();
                        ud = Application.getQueryFactory().uniqueNoFilter((ID) d.getIdentity(), userField.getName());
                    } else {
                        ud = Application.getQueryFactory().uniqueNoFilter(whichUser, userField.getName());
                    }
                    if (ud != null && ud[0] != null) {
                        if (userField.getReferenceEntity().getEntityCode() == EntityHelper.Department) {
                            defsList.add(ud[0].toString());
                        } else {
                            users.add((ID) ud[0]);
                        }
                    }
                }
            }
        } else {
            defsList.add(def);
        }
    }
    users.addAll(UserHelper.parseUsers(defsList, record));
    users.removeIf(id -> !UserHelper.isActive(id));
    return users;
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) Field(cn.devezhao.persist4j.Field) Department(com.rebuild.core.privileges.bizz.Department) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID)

Example 5 with Department

use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.

the class UserInfoController method userInfo.

@GetMapping("/account/user-info")
public JSON userInfo(@IdParam ID id) {
    User u = Application.getUserStore().getUser(id);
    Department dept = u.getOwningDept();
    return JSONUtils.toJSONObject(new String[] { "name", "dept", "email", "phone", "isActive" }, new Object[] { u.getFullName(), dept == null ? null : dept.getName(), u.getEmail(), u.getWorkphone(), u.isActive() });
}
Also used : Department(com.rebuild.core.privileges.bizz.Department) User(com.rebuild.core.privileges.bizz.User) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Department (com.rebuild.core.privileges.bizz.Department)12 Field (cn.devezhao.persist4j.Field)4 JSONArray (com.alibaba.fastjson.JSONArray)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ID (cn.devezhao.persist4j.engine.ID)3 BusinessUnit (cn.devezhao.bizz.security.member.BusinessUnit)2 Entity (cn.devezhao.persist4j.Entity)2 DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)2 User (com.rebuild.core.privileges.bizz.User)2 Test (org.junit.jupiter.api.Test)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 DepthEntry (cn.devezhao.bizz.privileges.DepthEntry)1 Privileges (cn.devezhao.bizz.privileges.Privileges)1 BizzDepthEntry (cn.devezhao.bizz.privileges.impl.BizzDepthEntry)1 EasyField (com.rebuild.core.metadata.easymeta.EasyField)1 CustomEntityPrivileges (com.rebuild.core.privileges.bizz.CustomEntityPrivileges)1 DataSpecificationException (com.rebuild.core.service.DataSpecificationException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1