P15GEN2\59518
2025-10-10 9f6890646993d16260d4201d613c092132856127
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
package foundation.system;
 
import java.util.ArrayList;
import java.util.List;
 
import foundation.dao.DataPackage;
import foundation.dao.DataReader;
import foundation.dao.DataWriter;
import foundation.data.entity.Entity;
import foundation.data.object.DataObject;
import foundation.state.approve.IHierarchyStepsCreator;
import foundation.state.approve.Step;
import foundation.state.approve.StepType;
import foundation.token.IOnlineUser;
import foundation.user.User;
import foundation.util.Util;
import foundation.workflow.WorkStep;
 
 
public class CustomerStepsCreator implements IHierarchyStepsCreator {
 
    private static CustomerStepsCreator instance;
    
    private CustomerStepsCreator() {
 
    }
    
    public static synchronized CustomerStepsCreator getInstance() {
        if (instance == null) {
            instance = new CustomerStepsCreator();
        }
        
        return instance;
    }
    
    @Override
    public List<Step> createSteps(StepType type, Step template, IOnlineUser user, WorkStep step) throws Exception {
        DataWriter dataWriter = step.getDataWriter();
        List<Step> result = new ArrayList<Step>();
        
        DataPackage dataPackage = step.getDataPackage();
        if (dataPackage == null) {
            DataReader dataReader = step.getDataReader();
            dataPackage = dataReader.getDataPackage();
        }
        
        Entity master = dataPackage.getMasterEntity();
        User accountUser = getAccountUser(master);
        
        if (accountUser == null && dataWriter != null) {
            dataWriter.writeError("当前客户不存在");
        }
        
        int i = template.getIndexNo() - 1;
        String id = type.name() + i;
        
        if (!template.isCopy()) {
            i = i + 1;
        }
        
        Step flowStep = new Step(id, template.getName());
        flowStep.setIndexNo(i);
        flowStep.setCopy(template.isCopy());
        flowStep.addOneUser(accountUser.getId(), accountUser.getRemark());
        result.add(flowStep);
        
        return result;
    }
 
    private User getAccountUser(Entity entity) throws Exception {
        String accountId = entity.getString("account_id");
        
        if (Util.isEmpty(accountId)) {
            accountId = entity.getString("customer_id");;
        }
        
        if (Util.isEmpty(accountId)) {
            accountId = entity.getString("lecturer_account_id");;
        }
        
        DataObject dataObject = DataObject.getInstance("md_org_account");
        Entity account = dataObject.getBrowseEntity(accountId);
        
        if (account == null) {
            return null;
        }
        
        return User.getInstance(account.getString("sys_user__id"));
    }
}