P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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);
    }
    
}