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"));
|
}
|
}
|