package foundation.capacity;
|
|
import foundation.capacity.role.Role;
|
import foundation.capacity.sight.Sight;
|
import foundation.data.entity.DictionaryTranslator;
|
import foundation.data.entity.Entity;
|
import foundation.data.object.DataObject;
|
import foundation.json.IJSONProvider;
|
import foundation.json.IJSONWriter;
|
import foundation.org.Org;
|
import foundation.org.Position;
|
import foundation.token.IActorTarget;
|
import foundation.user.User;
|
import foundation.util.Util;
|
|
public class ActorTarget implements IActorTarget, IJSONProvider {
|
|
private String id;
|
private String actorId;
|
private String companyId;
|
private String buId;
|
private String targetId;
|
private String typeCode;
|
private TargetType targetType;
|
private Actor actor;
|
private Org org;
|
private Position position;
|
private User user;
|
private Entity account;
|
|
|
public ActorTarget() {
|
|
}
|
|
public void load(Entity entity) throws Exception {
|
id = entity.getString("id");
|
actorId = entity.getString("actor_id");
|
companyId = entity.getString("company_id");
|
buId = entity.getString("bu_id");
|
targetId = entity.getString("target_id");
|
typeCode = entity.getString("type_code");
|
|
targetType = TargetType.parse(entity.getString("type_code"));
|
}
|
|
public void loadAccount() throws Exception {
|
DataObject dataObject = DataObject.getInstance("md_org_account");
|
account = dataObject.getTableEntity(targetId);
|
}
|
|
public static void createInstance(String actorId, Position position) throws Exception {
|
DataObject dataObject = DataObject.getInstance("sys_right_actor_target");
|
Entity entity = dataObject.createTableEmptyEntity();
|
entity.set("actor_id", actorId);
|
entity.set("type_code", ActorType.Position);
|
entity.set("company_id", position.getComapnyId());
|
entity.set("bu_id", position.getBUId());
|
entity.set("target_id", position.getId());
|
int cnt = dataObject.insertEntity(entity);
|
|
ActorBucket actorBucket = ActorBucket.getInstance();
|
ActorTarget target = new ActorTarget();
|
target.load(entity);
|
|
Actor actor = actorBucket.get(actorId);
|
|
if (actor == null) {
|
return;
|
}
|
|
target.setActor(actor);
|
target.setPosition(position);
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public String getActorId() {
|
return actorId;
|
}
|
|
public String getCompanyId() {
|
return companyId;
|
}
|
|
public String getCompanyName() {
|
if (Util.isEmpty(companyId)) {
|
return null;
|
}
|
|
DictionaryTranslator dictionaryTranslator = DictionaryTranslator.getInstance("company");
|
String result = dictionaryTranslator.toValue(companyId);
|
return result;
|
}
|
|
public String getBuId() {
|
return buId;
|
}
|
|
public String getBUName() {
|
if (Util.isEmpty(buId)) {
|
return null;
|
}
|
|
DictionaryTranslator dictionaryTranslator = DictionaryTranslator.getInstance("bu");
|
String result = dictionaryTranslator.toValue(buId);
|
return result;
|
}
|
|
public String getTargetId() {
|
return targetId;
|
}
|
|
public String getTypeCode() {
|
return typeCode;
|
}
|
|
public TargetType getTargetType() {
|
return targetType;
|
}
|
|
public Actor getActor() {
|
return actor;
|
}
|
|
public void setActor(Actor actor) {
|
this.actor = actor;
|
}
|
|
public Org getOrg() {
|
return org;
|
}
|
|
public Position getPosition() {
|
return position;
|
}
|
|
public void setPosition(Position position) {
|
this.position = position;
|
}
|
|
public User getUser() {
|
return user;
|
}
|
|
public Entity getAccount() {
|
return account;
|
}
|
|
public String getAccountId() {
|
if (account == null) {
|
return null;
|
}
|
|
return account.getString("id");
|
}
|
|
public String getAccountCode() {
|
if (account == null) {
|
return null;
|
}
|
|
return account.getString("code");
|
}
|
|
public String getAccountName() {
|
if (account == null) {
|
return null;
|
}
|
|
return account.getString("account_name");
|
}
|
|
public Role getRoleRuntime() {
|
return actor.getRoleRuntime();
|
}
|
|
public Sight getSightRuntime() {
|
return actor.getSightRuntime();
|
}
|
|
public void writeJSON(IJSONWriter writer) {
|
writer.beginObject();
|
writeJSONBody(writer);
|
writer.endObject();
|
}
|
|
public void writeJSONBody(IJSONWriter writer) {
|
//1. 打印角色来源(公司、岗位、用户)
|
writer.write("id", id);
|
writer.write("source", typeCode);
|
|
//2. 打印角色分配的公司和BU
|
writer.write("company_id", companyId);
|
writer.write("company_name", getCompanyName());
|
writer.write("bu_id", buId);
|
writer.write("bu_name", getBUName());
|
writer.write("target_id", targetId);
|
|
//4. 打印岗位
|
if (position != null) {
|
writer.write("position", position.getName());
|
writer.write("position_duty", position.getDuty());
|
}
|
else {
|
writer.writeNull("position");
|
writer.writeNull("position_duty");
|
}
|
|
//5. 打印角色内容
|
actor.writeJSONBody(writer);
|
}
|
|
}
|