|
|
@@ -0,0 +1,1355 @@
|
|
|
+/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
|
|
|
+package com.kingdee.shr.base.syssetting.app.io.fileImport;
|
|
|
+
|
|
|
+import com.kingdee.bos.BOSException;
|
|
|
+import com.kingdee.bos.BOSObjectFactory;
|
|
|
+import com.kingdee.bos.Context;
|
|
|
+import com.kingdee.bos.ICommonBOSType;
|
|
|
+import com.kingdee.bos.dao.xml.impl.IStateManager;
|
|
|
+import com.kingdee.bos.metadata.IMetaDataLoader;
|
|
|
+import com.kingdee.bos.metadata.MetaDataLoaderFactory;
|
|
|
+import com.kingdee.bos.metadata.MetaDataPK;
|
|
|
+import com.kingdee.bos.metadata.data.ColumnInfo;
|
|
|
+import com.kingdee.bos.metadata.data.DataTableInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.DataType;
|
|
|
+import com.kingdee.bos.metadata.entity.EntityObjectInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.EntityViewInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.FilterInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.FilterItemCollection;
|
|
|
+import com.kingdee.bos.metadata.entity.FilterItemInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.OwnPropertyInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.PropertyInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.SelectorItemCollection;
|
|
|
+import com.kingdee.bos.metadata.entity.SelectorItemInfo;
|
|
|
+import com.kingdee.bos.metadata.entity.SorterItemCollection;
|
|
|
+import com.kingdee.bos.metadata.entity.SorterItemInfo;
|
|
|
+import com.kingdee.bos.metadata.query.util.CompareType;
|
|
|
+import com.kingdee.bos.sql.ParserException;
|
|
|
+import com.kingdee.bos.util.BOSUuid;
|
|
|
+import com.kingdee.eas.common.EASBizException;
|
|
|
+import com.kingdee.eas.ep.CoreBillBaseCustomInfo;
|
|
|
+import com.kingdee.eas.ep.DataBaseCustomInfo;
|
|
|
+import com.kingdee.eas.framework.CoreBaseCollection;
|
|
|
+import com.kingdee.eas.framework.CoreBaseInfo;
|
|
|
+import com.kingdee.eas.framework.ICoreBase;
|
|
|
+import com.kingdee.eas.tools.datatask.BaseClassConstants;
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
+import com.kingdee.shr.base.permission.api.auth.SHRUserOrgPermissionApi;
|
|
|
+import com.kingdee.shr.base.syssetting.BaseItemCustomInfo;
|
|
|
+import com.kingdee.shr.base.syssetting.IBaseItemRelationHR;
|
|
|
+import com.kingdee.shr.base.syssetting.SHRBasicItemInfo;
|
|
|
+import com.kingdee.shr.base.syssetting.api.bean.BaseItemParam;
|
|
|
+import com.kingdee.shr.base.syssetting.api.service.SHRBaseItemApi;
|
|
|
+import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils;
|
|
|
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
|
|
|
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
|
|
|
+import com.kingdee.shr.base.syssetting.util.BaseItemRelationHRUtil;
|
|
|
+import com.kingdee.shr.base.syssetting.util.LocaleUtils;
|
|
|
+import com.kingdee.shr.base.syssetting.util.SHRBasicItemUtil;
|
|
|
+import com.kingdee.shr.shrimport.ImportTempDisplayEnum;
|
|
|
+import com.kingdee.shr.shrimport.ImportTemplateMutexType;
|
|
|
+import com.kingdee.shr.shrimport.SHRFileTemplateInfo;
|
|
|
+import com.kingdee.shr.shrimport.SHRImportTypeEnum;
|
|
|
+import com.kingdee.util.StringUtils;
|
|
|
+import com.kingdee.util.enums.Enum;
|
|
|
+import com.kingdee.util.enums.EnumUtils;
|
|
|
+import com.kingdee.util.enums.IntEnum;
|
|
|
+import com.kingdee.util.enums.StringEnum;
|
|
|
+import java.lang.reflect.Constructor;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.Set;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+
|
|
|
+public abstract class AbstractBaseImportService implements IBaseImportService {
|
|
|
+ private static Logger logger = Logger
|
|
|
+ .getLogger(AbstractBaseImportService.class);
|
|
|
+ private DynamicModelHelper dynamicModelHelper;
|
|
|
+ private String[] entityFullNames;
|
|
|
+ private ICoreBase coreBase;
|
|
|
+ private Context context;
|
|
|
+ private ImportTaskMonitor monitor;
|
|
|
+ private ImportTask task;
|
|
|
+ private String permItemId;
|
|
|
+ private Map<String, String> customParams;
|
|
|
+ private SHRFileTemplateInfo templateInfo;
|
|
|
+ private CoreBaseInfo currentBaseInfo;
|
|
|
+ private BaseRowInfo currentRow;
|
|
|
+ private boolean dataSource;
|
|
|
+ private List<Object> cacheCompleteRow;
|
|
|
+ private Map<String, Object> localCacheStore;
|
|
|
+
|
|
|
+ public AbstractBaseImportService() {
|
|
|
+ this.dataSource = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final void initService(Context context, ImportTask task,
|
|
|
+ ImportTaskMonitor monitor) throws ImportException {
|
|
|
+ if ((context == null) || (task == null)
|
|
|
+ || (task.getTemplateInfo() == null)) {
|
|
|
+ throw new NullPointerException("方法参数空值");
|
|
|
+ }
|
|
|
+ this.localCacheStore = new HashMap();
|
|
|
+ this.context = context;
|
|
|
+ this.task = task;
|
|
|
+ this.permItemId = task.getPermItemId();
|
|
|
+ this.customParams = task.getCustomParams();
|
|
|
+ this.templateInfo = task.getTemplateInfo();
|
|
|
+ this.dataSource = task.getTemplateInfo().isShowtype();
|
|
|
+ this.monitor = monitor;
|
|
|
+ try {
|
|
|
+ if (this.dataSource) {
|
|
|
+ this.dynamicModelHelper = new DynamicModelHelper(getScheme(),
|
|
|
+ getContext(), this.task.getMapColumnInfo(), this.task
|
|
|
+ .getImportTypeEnum());
|
|
|
+ } else {
|
|
|
+ this.entityFullNames = TemplateUtils
|
|
|
+ .splitEntityFullNames(this.templateInfo
|
|
|
+ .getEntityFullName());
|
|
|
+ if ((this.entityFullNames != null)
|
|
|
+ && (this.entityFullNames.length > 0))
|
|
|
+ this.coreBase = ((ICoreBase) BOSObjectFactory
|
|
|
+ .createCommonBOSObject(context, MetaDataPK
|
|
|
+ .create(this.entityFullNames[0])));
|
|
|
+ }
|
|
|
+ } catch (EASBizException e) {
|
|
|
+ throw new ImportException("导入框架初始化失败" + e.getMessage(), e);
|
|
|
+ } catch (BOSException e) {
|
|
|
+ throw new ImportException("导入框架初始化失败", e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ImportException("导入框架初始化失败", e);
|
|
|
+ }
|
|
|
+ initService();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final void initService(Context context,
|
|
|
+ SHRFileTemplateInfo template, String permItemId,
|
|
|
+ Map<String, String> params) throws SHRWebException {
|
|
|
+ if ((context == null) || (template == null) || (permItemId == null)) {
|
|
|
+ throw new NullPointerException("方法参数空值");
|
|
|
+ }
|
|
|
+ this.context = context;
|
|
|
+ this.templateInfo = template;
|
|
|
+ this.permItemId = permItemId;
|
|
|
+ this.customParams = params;
|
|
|
+ if (!(this.dataSource)) {
|
|
|
+ this.entityFullNames = TemplateUtils
|
|
|
+ .splitEntityFullNames(this.templateInfo.getEntityFullName());
|
|
|
+ }
|
|
|
+ initDownload();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final SHRFileTemplateInfo getTemplateInfo() {
|
|
|
+ return this.templateInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final String[] getEntityFullNames() {
|
|
|
+ return this.entityFullNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final ICoreBase getCoreBase() {
|
|
|
+ return this.coreBase;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final Context getContext() {
|
|
|
+ return this.context;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final ImportTask getTask() {
|
|
|
+ return this.task;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final String getPermItemId() {
|
|
|
+ return this.permItemId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final Map<String, String> getCustomParams() {
|
|
|
+ return this.customParams;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final String getCustomParam(String paramName) {
|
|
|
+ return ((String) this.customParams.get(paramName));
|
|
|
+ }
|
|
|
+
|
|
|
+ public final Map<String, BaseColumnInfo> getColumnMap() {
|
|
|
+ return this.task.getMapColumnInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final BaseColumnInfo getColumn(String propName) {
|
|
|
+ return ((BaseColumnInfo) this.task.getMapColumnInfo().get(propName));
|
|
|
+ }
|
|
|
+
|
|
|
+ public final Iterator<BaseColumnInfo> getColumnIterator() {
|
|
|
+ return new Iterator() {
|
|
|
+ Iterator<Map.Entry<String, BaseColumnInfo>> iter;
|
|
|
+
|
|
|
+ public boolean hasNext() {
|
|
|
+ return this.iter.hasNext();
|
|
|
+ }
|
|
|
+
|
|
|
+ public BaseColumnInfo next() {
|
|
|
+ BaseColumnInfo column = (BaseColumnInfo) ((Map.Entry) this.iter
|
|
|
+ .next()).getValue();
|
|
|
+ return column;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void remove() {
|
|
|
+ this.iter.remove();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public final boolean isStopOnError() {
|
|
|
+ return this.task.isStopOnError();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final boolean hasCallback() {
|
|
|
+ return this.task.isHasCallback();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final SHRImportTypeEnum getImportTypeEnum() {
|
|
|
+ return this.task.getImportTypeEnum();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final boolean isDataSource() {
|
|
|
+ return this.dataSource;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final Iterator<BaseRowInfo> getRowIterator() {
|
|
|
+ return this.task.getRowIterator();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final Iterator<BaseRowInfo> getRowIterator(int startIndex) {
|
|
|
+ return this.task.getRowIterator(startIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ public final String getScheme() {
|
|
|
+ return this.templateInfo.getDatanumber();
|
|
|
+ }
|
|
|
+
|
|
|
+ public final DynamicModelHelper getDynamicModelHelper() {
|
|
|
+ return this.dynamicModelHelper;
|
|
|
+ }
|
|
|
+
|
|
|
+ public final ImportTaskMonitor getMonitor() {
|
|
|
+ return this.monitor;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final boolean isAvailableBaseItem(String hrOrgId,
|
|
|
+ String baseItemId, String entityName) throws SHRWebException {
|
|
|
+ try {
|
|
|
+ SHRBasicItemInfo shrBasicItemInfo = SHRBasicItemUtil
|
|
|
+ .getSHRBasicItemInfoByEntityName(this.context, entityName);
|
|
|
+ IBaseItemRelationHR iBaseItemRelationHR = BaseItemRelationHRUtil
|
|
|
+ .getIBaseItemRelationHR(this.context, shrBasicItemInfo);
|
|
|
+ FilterInfo filter = new FilterInfo();
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("baseInfoId", baseItemId,
|
|
|
+ CompareType.EQUALS));
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("hrOrgUse.id", hrOrgId,
|
|
|
+ CompareType.EQUALS));
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("state", Integer.valueOf(100),
|
|
|
+ CompareType.EQUALS));
|
|
|
+ return iBaseItemRelationHR.exists(filter);
|
|
|
+ } catch (EASBizException e) {
|
|
|
+ throw new ShrWebBizException(e.getMessage(), e);
|
|
|
+ } catch (BOSException e) {
|
|
|
+ throw new SHRWebException(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final boolean hasPermissionOfHrOrgUnit(String hrOrgId,
|
|
|
+ String[] hrOrgIds) throws SHRWebException {
|
|
|
+ String userId = HRFilterUtils.getCurrentUserId(this.context);
|
|
|
+ Set hrOrgUnitSet = SHRUserOrgPermissionApi.getUserHROrgRangeIdSet(
|
|
|
+ this.context, userId, this.permItemId);
|
|
|
+ if (null == hrOrgUnitSet) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean has = false;
|
|
|
+ has = hrOrgUnitSet.contains(hrOrgId);
|
|
|
+ if (has) {
|
|
|
+ return has;
|
|
|
+ }
|
|
|
+ for (String temp : hrOrgIds) {
|
|
|
+ has = hrOrgUnitSet.contains(temp);
|
|
|
+ if (has) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return has;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final void addObjectToCallbackList(Object object) {
|
|
|
+ if (this.cacheCompleteRow == null) {
|
|
|
+ this.cacheCompleteRow = new ArrayList(this.task.getRowCount());
|
|
|
+ }
|
|
|
+ this.cacheCompleteRow.add(object);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final List<BaseColumnInfo> queryDynamicColumnList() {
|
|
|
+ List dynamicColumnList = new ArrayList();
|
|
|
+ Iterator iterator = getColumnMap().entrySet().iterator();
|
|
|
+ BaseColumnInfo columnInfo = null;
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ columnInfo = (BaseColumnInfo) ((Map.Entry) iterator.next())
|
|
|
+ .getValue();
|
|
|
+ if (columnInfo.isDynamicColumn())
|
|
|
+ ;
|
|
|
+ dynamicColumnList.add(columnInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return dynamicColumnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final Object getLocalCache(String key) {
|
|
|
+ return this.localCacheStore.get(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final Object putLocalCache(String key, Object object) {
|
|
|
+ return this.localCacheStore.put(key, object);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void initService() throws ImportException {
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean isUpdateImport() {
|
|
|
+ boolean isUpdate = (getImportTypeEnum().getValue() == 40)
|
|
|
+ || (getImportTypeEnum().getValue() == 30);
|
|
|
+ return isUpdate;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean beforePauseTask() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void beforeResumeTask() {
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getHrOrgUnitIdsSql() {
|
|
|
+ String userId = HRFilterUtils.getCurrentUserId(this.context);
|
|
|
+ return SHRUserOrgPermissionApi.getUserHROrgRangeInSQL(getContext(),
|
|
|
+ userId, this.permItemId);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getAdminOrgUnitIdsSql() {
|
|
|
+ String userId = HRFilterUtils.getCurrentUserId(this.context);
|
|
|
+ return SHRUserOrgPermissionApi.getUserAdminRangeSQL(this.context,
|
|
|
+ userId, this.permItemId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void startSingleImport(BaseRowInfo row) throws ImportException {
|
|
|
+ verifyRow(row);
|
|
|
+ importRow(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getRowUniqueId(BaseRowInfo row) {
|
|
|
+ List columns = row.getKeyColumnInfo();
|
|
|
+ BaseColumnInfo colume = null;
|
|
|
+ StringBuffer uniqueId = new StringBuffer();
|
|
|
+ int i = 0;
|
|
|
+ for (int size = columns.size(); i < size; ++i) {
|
|
|
+ colume = (BaseColumnInfo) columns.get(i);
|
|
|
+ uniqueId.append(row
|
|
|
+ .getValueOfStringByIndex(colume.getColumnIndex()));
|
|
|
+ if (i < size - 1) {
|
|
|
+ uniqueId.append("##");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return uniqueId.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void complete() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean startBatchImport(Iterator<BaseRowInfo> rowIterator) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected abstract void verifyRow(BaseRowInfo paramBaseRowInfo)
|
|
|
+ throws ImportException;
|
|
|
+
|
|
|
+ protected abstract void importRow(BaseRowInfo paramBaseRowInfo)
|
|
|
+ throws ImportException;
|
|
|
+
|
|
|
+ protected final void verifyRowSystem(BaseRowInfo row)
|
|
|
+ throws ImportException {
|
|
|
+ StringBuffer message = new StringBuffer();
|
|
|
+ Map columnInfoMap = row.getMapColumnInfo();
|
|
|
+ Iterator iterator = columnInfoMap.entrySet().iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Map.Entry entry = (Map.Entry) iterator.next();
|
|
|
+ BaseColumnInfo columnInfo = (BaseColumnInfo) entry.getValue();
|
|
|
+ String valueString = row.getValueOfStringByIndex(columnInfo
|
|
|
+ .getColumnIndex());
|
|
|
+ try {
|
|
|
+ verifyCellBlank(columnInfo, valueString);
|
|
|
+ verifyValueLength(columnInfo, valueString);
|
|
|
+
|
|
|
+ Object value = covertCellType(columnInfo, valueString);
|
|
|
+ row.setValueOfObject(columnInfo.getColumnIndex(), value);
|
|
|
+ } catch (ImportException e) {
|
|
|
+ if (e.getState() == ImportException.STATE_LATER) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ message.append(e.getMessage() + ";");
|
|
|
+ if (e.isError())
|
|
|
+ logger.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!(StringUtils.isEmpty(message.toString()))) {
|
|
|
+ if (message.lastIndexOf(";") == message.length() - 1) {
|
|
|
+ message.delete(message.length() - 1, message.length());
|
|
|
+ }
|
|
|
+ ImportException importException = new ImportException(message
|
|
|
+ .toString());
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void vierfyDataExists(BaseRowInfo row) throws ImportException {
|
|
|
+ SHRImportTypeEnum importTypeEnum = getImportTypeEnum();
|
|
|
+ try {
|
|
|
+ if ((importTypeEnum.getValue() == 10) && (existsData(row))) {
|
|
|
+ ImportException importException = new ImportException(
|
|
|
+ "数据已存在,不能重复新增");
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((importTypeEnum.getValue() == 30) && (!(existsData(row)))) {
|
|
|
+ ImportException importException = new ImportException(
|
|
|
+ "未找到数据,不能修改");
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ } catch (ImportException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (EASBizException e) {
|
|
|
+ ImportException importException = new ImportException(e
|
|
|
+ .getMessage(), e);
|
|
|
+ throw importException;
|
|
|
+ } catch (Exception e) {
|
|
|
+ ImportException importException = new ImportException(
|
|
|
+ "导入数据失败请联系管理员", e);
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected CoreBaseInfo getDataObject(BaseRowInfo row)
|
|
|
+ throws ImportException {
|
|
|
+ String selectString = getPKSelectString(row);
|
|
|
+ if (StringUtils.isEmpty(selectString)) {
|
|
|
+ ImportException importException = new ImportException(
|
|
|
+ "导入数据未找到主键字段,请检查导入模板是否配置了主键字段");
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ selectString = "where " + selectString;
|
|
|
+ try {
|
|
|
+ CoreBaseCollection result = getCoreBase().getCollection(
|
|
|
+ selectString);
|
|
|
+ if (result.size() > 1) {
|
|
|
+ List keyColumnList = row.getKeyColumnInfo();
|
|
|
+ StringBuffer sb = new StringBuffer("根据主键获取到多条数据[");
|
|
|
+ int i = 0;
|
|
|
+ for (int size = keyColumnList.size(); i < size; ++i) {
|
|
|
+ BaseColumnInfo column = (BaseColumnInfo) keyColumnList
|
|
|
+ .get(i);
|
|
|
+ sb.append(column.getName()).append("-").append(
|
|
|
+ row
|
|
|
+ .getValueOfStringByIndex(column
|
|
|
+ .getColumnIndex()));
|
|
|
+ if (i < size - 1) {
|
|
|
+ sb.append(";");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sb.append("]");
|
|
|
+ ImportException importException = new ImportException(sb
|
|
|
+ .toString());
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ if (result.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return result.get(0);
|
|
|
+ } catch (ImportException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (BOSException e) {
|
|
|
+ ImportException importException = new ImportException("获取对象出错", e);
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean existsData(BaseRowInfo row) throws ParserException,
|
|
|
+ EASBizException, BOSException {
|
|
|
+ FilterInfo filter = new FilterInfo(getPKSelectString(row));
|
|
|
+ return getCoreBase().exists(filter);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void verifyCellBlank(BaseColumnInfo columnInfo, String valueString)
|
|
|
+ throws ImportException {
|
|
|
+ if ((columnInfo.isNecessary()) && (StringUtils.isEmpty(valueString))) {
|
|
|
+ ImportException importException = new ImportException("["
|
|
|
+ + columnInfo.getName() + "]不能为空");
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ if ((columnInfo.isNecessary()) && (isUpdateImport())
|
|
|
+ && (ValueCovertUtils.UPDATE_BLANK_FLAG.equals(valueString))) {
|
|
|
+ ImportException importException = new ImportException("["
|
|
|
+ + columnInfo.getName() + "]不能更新为空");
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void verifyValueLength(BaseColumnInfo columnInfo,
|
|
|
+ String valueString) throws ImportException {
|
|
|
+ if (columnInfo.getPropTypeClass().equalsIgnoreCase("String")) {
|
|
|
+ int maxL = columnInfo.getLength();
|
|
|
+ if ((maxL > 0) && (valueString.length() > maxL)) {
|
|
|
+ ImportException importException = new ImportException(
|
|
|
+ MessageFormat.format("[{0}]最大长度为{1}", new Object[] {
|
|
|
+ columnInfo.getName(), Integer.valueOf(maxL) }));
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object covertCellType(BaseColumnInfo columnInfo,
|
|
|
+ String valueString) throws ImportException {
|
|
|
+ Object val = valueStringToObject(columnInfo, valueString);
|
|
|
+ return val;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object valueStringToObject(BaseColumnInfo columnInfo,
|
|
|
+ String valueString) throws ImportException {
|
|
|
+ if (StringUtils.isEmpty(valueString)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if ((isUpdateImport())
|
|
|
+ && (ValueCovertUtils.UPDATE_BLANK_FLAG.equals(valueString))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (2 == columnInfo.getDataType()) {
|
|
|
+ try {
|
|
|
+ return complexValueStringToObject(columnInfo, valueString);
|
|
|
+ } catch (ImportException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ String tip = MessageFormat.format("[{0}:{1}]在系统中不存在,请先维护数据。",
|
|
|
+ new Object[] { columnInfo.getName(), valueString });
|
|
|
+ throw new ImportException(tip, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ValueCovertUtils.simpleValueStringToObject(columnInfo,
|
|
|
+ valueString);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object complexValueStringToObject(BaseColumnInfo columnInfo,
|
|
|
+ String valueString) throws ImportException {
|
|
|
+ if (StringUtils.isEmpty(valueString)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ EntityViewInfo viewInfo = new EntityViewInfo();
|
|
|
+
|
|
|
+ SelectorItemCollection selectorItemColl = getComplexConvertSelector(columnInfo);
|
|
|
+ viewInfo.setSelector(selectorItemColl);
|
|
|
+
|
|
|
+ FilterInfo filter = getComplexConvertFilter(columnInfo, valueString);
|
|
|
+ viewInfo.setFilter(filter);
|
|
|
+
|
|
|
+ return getEnableObject(viewInfo, columnInfo, valueString);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected FilterInfo getComplexConvertFilter(BaseColumnInfo columnInfo,
|
|
|
+ String valueString) {
|
|
|
+ String number = null;
|
|
|
+ String name = null;
|
|
|
+ boolean only = false;
|
|
|
+ if (valueString.contains(ValueCovertUtils.NUMBER_NAME_SPLIT)) {
|
|
|
+ String[] sArray = valueString
|
|
|
+ .split(ValueCovertUtils.NUMBER_NAME_SPLIT);
|
|
|
+ number = sArray[0].trim();
|
|
|
+ name = sArray[1].trim();
|
|
|
+ only = true;
|
|
|
+ } else {
|
|
|
+ number = valueString;
|
|
|
+ name = valueString;
|
|
|
+ }
|
|
|
+ FilterInfo filter = new FilterInfo();
|
|
|
+ if (columnInfo.isExtendBaseItemEntity()) {
|
|
|
+ String originalNameInExtend = columnInfo.getOriginalNameInExtend();
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo(originalNameInExtend + ".name", name,
|
|
|
+ CompareType.EQUALS));
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo(originalNameInExtend + ".number",
|
|
|
+ number, CompareType.EQUALS));
|
|
|
+ } else {
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("name", name, CompareType.EQUALS));
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("number", number, CompareType.EQUALS));
|
|
|
+ }
|
|
|
+ if (only)
|
|
|
+ filter.setMaskString("#0 and #1");
|
|
|
+ else {
|
|
|
+ filter.setMaskString("#0 or #1");
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected SelectorItemCollection getComplexConvertSelector(
|
|
|
+ BaseColumnInfo columnInfo) {
|
|
|
+ SelectorItemCollection selectorItemColl = new SelectorItemCollection();
|
|
|
+ selectorItemColl.add(new SelectorItemInfo("id"));
|
|
|
+ selectorItemColl.add(new SelectorItemInfo("name"));
|
|
|
+ selectorItemColl.add(new SelectorItemInfo("number"));
|
|
|
+
|
|
|
+ if (columnInfo.isExtendBaseItemEntity()) {
|
|
|
+ String originalNameInExtend = columnInfo.getOriginalNameInExtend();
|
|
|
+ if (!(StringUtils.isEmpty(originalNameInExtend))) {
|
|
|
+ selectorItemColl.add(new SelectorItemInfo(originalNameInExtend
|
|
|
+ + ".id"));
|
|
|
+ selectorItemColl.add(new SelectorItemInfo(originalNameInExtend
|
|
|
+ + ".name"));
|
|
|
+ selectorItemColl.add(new SelectorItemInfo(originalNameInExtend
|
|
|
+ + ".number"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnInfo.isBaseItemInfo()) {
|
|
|
+ selectorItemColl.add(new SelectorItemInfo("state"));
|
|
|
+ }
|
|
|
+ return selectorItemColl;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object getEnableObject(EntityViewInfo viewInfo,
|
|
|
+ BaseColumnInfo columnInfo, String valueString)
|
|
|
+ throws ImportException {
|
|
|
+ String tempEntityTime = (columnInfo.isExtendBaseItemEntity()) ? columnInfo
|
|
|
+ .getExtendBaseItemEntityName()
|
|
|
+ : columnInfo.getSupplierEntityName();
|
|
|
+
|
|
|
+ CoreBaseCollection coll = null;
|
|
|
+ try {
|
|
|
+ ICoreBase corebase = (ICoreBase) BOSObjectFactory
|
|
|
+ .createCommonBOSObject(this.context, MetaDataPK
|
|
|
+ .create(tempEntityTime));
|
|
|
+ viewInfo.setBaseOnSelector(true);
|
|
|
+ coll = corebase.getCollection(viewInfo);
|
|
|
+ } catch (BOSException e) {
|
|
|
+ String tip = MessageFormat.format("[{0}:{1}]转换为对象时出错",
|
|
|
+ new Object[] { columnInfo.getName(), valueString });
|
|
|
+ throw new ImportException(tip, e);
|
|
|
+ }
|
|
|
+
|
|
|
+ checkCoreBaseCollection(coll, columnInfo, valueString);
|
|
|
+
|
|
|
+ if ("hrJobSystemClassify".equals(columnInfo.getPropName())) {
|
|
|
+ CoreBaseInfo baseInfo = coll.get(0);
|
|
|
+ return baseInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ coll = filterColl(coll, valueString);
|
|
|
+
|
|
|
+ if (columnInfo.isBaseItemInfo()) {
|
|
|
+ return getEnableBaseItem(coll, columnInfo, valueString);
|
|
|
+ }
|
|
|
+ return getEnableCoreBase(coll, columnInfo, valueString);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void checkCoreBaseCollection(CoreBaseCollection coll,
|
|
|
+ BaseColumnInfo columnInfo, String valueString) {
|
|
|
+ if ((coll == null) || (coll.size() == 0)) {
|
|
|
+ String tip = MessageFormat.format("[{0}:{1}]在系统中不存在,请先维护数据。",
|
|
|
+ new Object[] { columnInfo.getName(), valueString });
|
|
|
+ throw new ImportException(tip);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected CoreBaseCollection filterColl(CoreBaseCollection coll,
|
|
|
+ String value) {
|
|
|
+ if (coll == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (!(value.contains(ValueCovertUtils.NUMBER_NAME_SPLIT))) {
|
|
|
+ CoreBaseInfo tempCore = null;
|
|
|
+ CoreBaseCollection tempColl = new CoreBaseCollection();
|
|
|
+ int i = 0;
|
|
|
+ for (int size = coll.size(); i < size; ++i) {
|
|
|
+ tempCore = coll.get(i);
|
|
|
+ if (value.equals(tempCore.getString("number"))) {
|
|
|
+ tempColl.add(tempCore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tempColl.size() != 0) {
|
|
|
+ coll = tempColl;
|
|
|
+ tempColl = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return coll;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object getEnableCoreBase(CoreBaseCollection coll,
|
|
|
+ BaseColumnInfo columnInfo, String valueString) {
|
|
|
+ int total = coll.size();
|
|
|
+ if (total > 1) {
|
|
|
+ String tip = MessageFormat
|
|
|
+ .format(
|
|
|
+ "[{0}:{1}]系统中存在多个名称为{1}的{0},不符合唯一性原则不允许导入,建议您在名称前加入编码,格式如[编码##名称]后再重新导入。",
|
|
|
+ new Object[] { columnInfo.getName(), valueString });
|
|
|
+ throw new ImportException(tip);
|
|
|
+ }
|
|
|
+ return coll.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object getEnableBaseItem(CoreBaseCollection coll,
|
|
|
+ BaseColumnInfo columnInfo, String valueString) {
|
|
|
+ int total = coll.size();
|
|
|
+ boolean isExtendBaseItemEntity = (columnInfo.isBaseItemInfo())
|
|
|
+ && (!(StringUtils.isEmpty(columnInfo
|
|
|
+ .getExtendBaseItemEntityName())));
|
|
|
+ String tempEntityTime = (isExtendBaseItemEntity) ? columnInfo
|
|
|
+ .getExtendBaseItemEntityName() : columnInfo
|
|
|
+ .getSupplierEntityName();
|
|
|
+
|
|
|
+ EntityObjectInfo entityObject = MetaDataLoaderFactory
|
|
|
+ .getRemoteMetaDataLoader().getEntity(
|
|
|
+ MetaDataPK.create(tempEntityTime));
|
|
|
+ PropertyInfo propInfo = entityObject.getPropertyByNameRuntime("state");
|
|
|
+
|
|
|
+ String metadataRef = String.valueOf(propInfo.getStateManager()
|
|
|
+ .getStateValue("metadataRef"));
|
|
|
+ String type = "IntEnum";
|
|
|
+ try {
|
|
|
+ Class clz = Class.forName(metadataRef);
|
|
|
+ clz.asSubclass(IntEnum.class);
|
|
|
+ } catch (ClassCastException e) {
|
|
|
+ type = "StringEnum";
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
+ throw new ImportException(e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ CoreBaseInfo baseInfo = null;
|
|
|
+ CoreBaseInfo enableInfo = null;
|
|
|
+ boolean isMutil = Boolean.FALSE.booleanValue();
|
|
|
+ Object stateValue = getEnableValue(metadataRef);
|
|
|
+ int count = 0;
|
|
|
+ for (int i = 0; i < total; ++i) {
|
|
|
+ baseInfo = coll.get(i);
|
|
|
+ Object stateEnumValue = null;
|
|
|
+
|
|
|
+ if ("IntEnum".equals(type)) {
|
|
|
+ stateEnumValue = Integer.valueOf(baseInfo.getInt("state"));
|
|
|
+ if ((Integer) stateEnumValue == (Integer) stateValue) {
|
|
|
+ if (count > 1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ++count;
|
|
|
+ enableInfo = baseInfo;
|
|
|
+ }
|
|
|
+ } else if ("StringEnum".equals(type)) {
|
|
|
+ stateEnumValue = baseInfo.getString("state");
|
|
|
+ if (((String) stateEnumValue).equals((String) stateValue)) {
|
|
|
+ if (count > 1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ++count;
|
|
|
+ enableInfo = baseInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count > 1) {
|
|
|
+ isMutil = Boolean.TRUE.booleanValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ checkEnableBaseItem(isMutil, enableInfo, columnInfo, valueString);
|
|
|
+ if (columnInfo.isExtendBaseItemEntity()) {
|
|
|
+ Object o = (CoreBaseInfo) enableInfo.get(columnInfo
|
|
|
+ .getOriginalNameInExtend());
|
|
|
+ return ((CoreBaseInfo) o);
|
|
|
+ }
|
|
|
+ return enableInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean checkEnableBaseItem(boolean isMutil,
|
|
|
+ CoreBaseInfo enableInfo, BaseColumnInfo columnInfo,
|
|
|
+ String valueString) {
|
|
|
+ if (isMutil)
|
|
|
+ throw new ImportException(MessageFormat.format(
|
|
|
+ "[{0}:{1}]对应多个启用数据对象", new Object[] { columnInfo.getName(),
|
|
|
+ valueString }));
|
|
|
+ if (null == enableInfo) {
|
|
|
+ throw new ImportException(MessageFormat.format(
|
|
|
+ "[{0}:{1}]使用非启用状态的数据对象", new Object[] {
|
|
|
+ columnInfo.getName(), valueString }));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object getEnableValue(String enumSourceName) {
|
|
|
+ Object stateValue = Integer.valueOf(1);
|
|
|
+ if ("com.kingdee.eas.basedata.hraux.StateEnum".equals(enumSourceName))
|
|
|
+ stateValue = Integer.valueOf(1);
|
|
|
+ else if ("com.kingdee.eas.hr.base.StateEnum".equals(enumSourceName))
|
|
|
+ stateValue = Integer.valueOf(1);
|
|
|
+ else if ("com.kingdee.shr.base.syssetting.BaseItemStateEnum"
|
|
|
+ .equals(enumSourceName)) {
|
|
|
+ stateValue = Integer.valueOf(1);
|
|
|
+ }
|
|
|
+ return stateValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected CoreBaseInfo createBlankCoreObject(String entityFullName)
|
|
|
+ throws ImportException {
|
|
|
+ IMetaDataLoader loader = MetaDataLoaderFactory
|
|
|
+ .getMetaDataLoader(this.context);
|
|
|
+ MetaDataPK metaDataPK = MetaDataPK.create(entityFullName);
|
|
|
+ EntityObjectInfo eoInfo = loader.getEntity(metaDataPK);
|
|
|
+
|
|
|
+ String valueClassName = eoInfo.getObjectValueClass();
|
|
|
+
|
|
|
+ CoreBaseInfo info = null;
|
|
|
+ try {
|
|
|
+ Class c = Class.forName(valueClassName);
|
|
|
+ Constructor cst = c.getConstructor(new Class[0]);
|
|
|
+ info = (CoreBaseInfo) cst.newInstance(new Object[0]);
|
|
|
+ if (info instanceof DataBaseCustomInfo) {
|
|
|
+ ((DataBaseCustomInfo) info).setBOSType(eoInfo.getType());
|
|
|
+ } else if (info instanceof BaseItemCustomInfo) {
|
|
|
+ ((BaseItemCustomInfo) info).setBOSType(eoInfo.getType());
|
|
|
+ } else if (info instanceof CoreBillBaseCustomInfo) {
|
|
|
+ ((CoreBillBaseCustomInfo) info).setBOSType(eoInfo.getType());
|
|
|
+ } else if ((eoInfo.isDynamic()) && (info instanceof ICommonBOSType)) {
|
|
|
+ ICommonBOSType commonObject = (ICommonBOSType) info;
|
|
|
+ commonObject.setBOSType(eoInfo.getType());
|
|
|
+ commonObject.setPK(metaDataPK);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ ImportException importException = new ImportException("创建对象失败", e);
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getPKSelectString(BaseRowInfo row) {
|
|
|
+ List keyColumnList = row.getKeyColumnInfo();
|
|
|
+ StringBuffer pkSelectStringBuffer = new StringBuffer();
|
|
|
+ int i = 0;
|
|
|
+ for (int size = keyColumnList.size(); i < size; ++i) {
|
|
|
+ BaseColumnInfo keyColumn = (BaseColumnInfo) keyColumnList.get(i);
|
|
|
+ if (keyColumn.isCustomField()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (pkSelectStringBuffer.length() > 0) {
|
|
|
+ pkSelectStringBuffer.append(" and ");
|
|
|
+ }
|
|
|
+ if (keyColumn.getDataType() == 2) {
|
|
|
+ CoreBaseInfo info = (CoreBaseInfo) row
|
|
|
+ .getValueOfObjectByIndex(keyColumn.getColumnIndex());
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName()).append(
|
|
|
+ ".id = '").append(info.getId().toString()).append("'");
|
|
|
+ } else {
|
|
|
+ Object value = row.getValueOfObjectByIndex(keyColumn
|
|
|
+ .getColumnIndex());
|
|
|
+ if (value instanceof String) {
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("='").append(value.toString().trim())
|
|
|
+ .append("'");
|
|
|
+ } else if (value instanceof Timestamp) {
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("={ts'").append(value).append("'}");
|
|
|
+ } else if (value instanceof Date) {
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat(
|
|
|
+ "yyyy-MM-dd HH:mm:ss");
|
|
|
+ String valueStr = format.format(value);
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("={ts'").append(valueStr).append("'}");
|
|
|
+ } else if (value instanceof Enum) {
|
|
|
+ if (value instanceof StringEnum) {
|
|
|
+ StringEnum en = (StringEnum) value;
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("='").append(en.getValue()).append("'");
|
|
|
+ } else if (value instanceof IntEnum) {
|
|
|
+ IntEnum en = (IntEnum) value;
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("=").append(en.getValue());
|
|
|
+ }
|
|
|
+ } else if (value instanceof CoreBaseInfo) {
|
|
|
+ CoreBaseInfo coreBaseInfo = (CoreBaseInfo) value;
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("='").append(coreBaseInfo.getId()).append(
|
|
|
+ "'");
|
|
|
+ } else {
|
|
|
+ pkSelectStringBuffer.append(keyColumn.getPropName())
|
|
|
+ .append("=").append(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pkSelectStringBuffer.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected EntityViewInfo getPKEntityViewInfo(BaseRowInfo row) {
|
|
|
+ List keyColumnList = row.getKeyColumnInfo();
|
|
|
+ EntityViewInfo viewInfo = new EntityViewInfo();
|
|
|
+ FilterInfo filter = new FilterInfo();
|
|
|
+ int i = 0;
|
|
|
+ for (int size = keyColumnList.size(); i < size; ++i) {
|
|
|
+ BaseColumnInfo keyColumn = (BaseColumnInfo) keyColumnList.get(i);
|
|
|
+ if (keyColumn.isCustomField()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object value = row.getValueOfObjectByIndex(keyColumn
|
|
|
+ .getColumnIndex());
|
|
|
+ if (value instanceof CoreBaseInfo) {
|
|
|
+ CoreBaseInfo coreBaseInfo = (CoreBaseInfo) value;
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo(keyColumn.getPropName(),
|
|
|
+ coreBaseInfo.getId()));
|
|
|
+ } else {
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo(keyColumn.getPropName(), value));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ viewInfo.setFilter(filter);
|
|
|
+ return viewInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final String getMainEntityFullName() {
|
|
|
+ if ((this.entityFullNames == null)
|
|
|
+ || (this.entityFullNames.length == 0)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return this.entityFullNames[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected final String getRelationEntityFullName(String entityName) {
|
|
|
+ if ((this.entityFullNames == null)
|
|
|
+ || (this.entityFullNames.length == 0)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String fullName = "";
|
|
|
+ int i = 0;
|
|
|
+ for (int size = this.entityFullNames.length; i < size; ++i) {
|
|
|
+ String temp = this.entityFullNames[i];
|
|
|
+ String name = temp.substring(temp.lastIndexOf(".") + 1);
|
|
|
+ if (entityName.equals(name)) {
|
|
|
+ fullName = temp;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fullName;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected CoreBaseInfo transRowToObejct(BaseRowInfo row)
|
|
|
+ throws ImportException {
|
|
|
+
|
|
|
+ if ((this.currentRow == row) && (this.currentBaseInfo != null)) {
|
|
|
+ return this.currentBaseInfo;
|
|
|
+ }
|
|
|
+ CoreBaseInfo baseInfo = createBlankCoreObject(getMainEntityFullName());
|
|
|
+ baseInfo = mergeObjectAndRow(baseInfo, row);
|
|
|
+ this.currentBaseInfo = baseInfo;
|
|
|
+ this.currentRow = row;
|
|
|
+ return baseInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected CoreBaseInfo mergeObjectAndRow(CoreBaseInfo oldObject,
|
|
|
+ BaseRowInfo row) throws ImportException {
|
|
|
+ if (oldObject == null) {
|
|
|
+ throw new ImportException("对象为空,不能赋值");
|
|
|
+ }
|
|
|
+
|
|
|
+ Iterator iterator = getColumnIterator();
|
|
|
+ BaseColumnInfo column = null;
|
|
|
+ Object val = null;
|
|
|
+ boolean hasUpdate = isUpdateImport();
|
|
|
+ try {
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ column = (BaseColumnInfo) iterator.next();
|
|
|
+ val = row.getValueOfObjectByIndex(column.getColumnIndex());
|
|
|
+ if ((hasUpdate) && (oldObject.getId() != null)) {
|
|
|
+ String valString = row.getValueOfStringByIndex(column
|
|
|
+ .getColumnIndex());
|
|
|
+ if (StringUtils.isEmpty(valString)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ValueCovertUtils.UPDATE_BLANK_FLAG.equals(valString)) {
|
|
|
+ val = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ setObjectPropertyValue(oldObject, column, val, row);
|
|
|
+ }
|
|
|
+ } catch (ImportException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ String msg = "赋值出错";
|
|
|
+ if (column != null) {
|
|
|
+ msg = MessageFormat.format("赋值出错[{0}-{1}]", new Object[] {
|
|
|
+ column.getName(),
|
|
|
+ row.getValueOfStringByIndex(column.getColumnIndex()) });
|
|
|
+ }
|
|
|
+ ImportException importException = new ImportException(msg, e);
|
|
|
+ throw importException;
|
|
|
+ }
|
|
|
+ setOtherFieldInfo(oldObject, row);
|
|
|
+ return oldObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setOtherFieldInfo(CoreBaseInfo baseInfo, BaseRowInfo row)
|
|
|
+ throws ImportException {
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setObjectPropertyValue(CoreBaseInfo coreBaseInfo,
|
|
|
+ BaseColumnInfo columnInfo, Object value, BaseRowInfo row)
|
|
|
+ throws ImportException {
|
|
|
+ setObjectPropertyValue(coreBaseInfo, columnInfo, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setObjectPropertyValue(CoreBaseInfo coreBaseInfo,
|
|
|
+ BaseColumnInfo columnInfo, Object value) {
|
|
|
+ if ((columnInfo.isCustomField()) || (columnInfo.isDynamicColumn())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (columnInfo.getPropName().indexOf(".") > 0) {
|
|
|
+ String entityName = columnInfo.getPropName().substring(0,
|
|
|
+ columnInfo.getPropName().indexOf("."));
|
|
|
+ String entityPropName = columnInfo.getPropName().substring(
|
|
|
+ columnInfo.getPropName().lastIndexOf(".") + 1);
|
|
|
+ String coreBasePropName = getPropNameOfEntityNameOnCoreBase(entityName);
|
|
|
+ CoreBaseInfo otherInfo = (CoreBaseInfo) coreBaseInfo
|
|
|
+ .get(coreBasePropName);
|
|
|
+ if (otherInfo == null) {
|
|
|
+ String relationEntityFullName = getRelationEntityFullName(entityName);
|
|
|
+ otherInfo = createBlankCoreObject(relationEntityFullName);
|
|
|
+ coreBaseInfo.put(coreBasePropName, otherInfo);
|
|
|
+ }
|
|
|
+ otherInfo.put(entityPropName, value);
|
|
|
+ if (1 == columnInfo.getDataType()) {
|
|
|
+ otherInfo.put(entityPropName + "_l1", value);
|
|
|
+ otherInfo.put(entityPropName + "_l2", value);
|
|
|
+ otherInfo.put(entityPropName + "_l3", value);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ coreBaseInfo.put(columnInfo.getPropName(), value);
|
|
|
+ if (1 == columnInfo.getDataType()) {
|
|
|
+ coreBaseInfo.put(columnInfo.getPropName() + "_l1", value);
|
|
|
+ coreBaseInfo.put(columnInfo.getPropName() + "_l2", value);
|
|
|
+ coreBaseInfo.put(columnInfo.getPropName() + "_l3", value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getPropNameOfEntityNameOnCoreBase(String entityName) {
|
|
|
+ if (Character.isLowerCase(entityName.charAt(0))) {
|
|
|
+ return entityName;
|
|
|
+ }
|
|
|
+ return Character.toLowerCase(entityName.charAt(0))
|
|
|
+ + entityName.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Object> getCallbackList() {
|
|
|
+ return this.cacheCompleteRow;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void initDownload() throws SHRWebException {
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getValueForFillColumn(BaseColumnInfo clumnInfo)
|
|
|
+ throws SHRWebException {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<String> getColumnSelectValue(BaseColumnInfo clumnInfo)
|
|
|
+ throws ImportException {
|
|
|
+ return getColumnSelectValue(clumnInfo, this.customParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getColumnAnnotate(BaseColumnInfo clumnInfo)
|
|
|
+ throws ImportException {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected List<String> getColumnSelectValue(BaseColumnInfo columnInfo,
|
|
|
+ Map<String, String> customParam) throws ImportException {
|
|
|
+ if (columnInfo == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List datas = new ArrayList();
|
|
|
+
|
|
|
+ if (columnInfo.getDataType() == 0) {
|
|
|
+ String typeClassName = columnInfo.getPropTypeClass();
|
|
|
+ String tmp = BaseClassConstants.getJavaClassName(columnInfo
|
|
|
+ .getPropDataType().getName());
|
|
|
+ if (Enum.class.getName().equals(tmp)) {
|
|
|
+ datas.addAll(getEnumDatas(columnInfo));
|
|
|
+ } else if ((Boolean.class.getName().equals(tmp))
|
|
|
+ || ("boolean".equals(typeClassName))) {
|
|
|
+ datas.add("是");
|
|
|
+ datas.add("否");
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+ }
|
|
|
+ if (columnInfo.getDataType() == 2) {
|
|
|
+ CoreBaseCollection coll = new CoreBaseCollection();
|
|
|
+ boolean dupName = false;
|
|
|
+ boolean isExtendBaseItemEntity = columnInfo
|
|
|
+ .isExtendBaseItemEntity();
|
|
|
+ String tempEntityTime = (isExtendBaseItemEntity) ? columnInfo
|
|
|
+ .getExtendBaseItemEntityName() : columnInfo
|
|
|
+ .getSupplierEntityName();
|
|
|
+
|
|
|
+ coll = getRelatedFieldCollection(tempEntityTime, columnInfo);
|
|
|
+ CoreBaseInfo tempInfo = null;
|
|
|
+ String tempText = null;
|
|
|
+ Map nameMap = new HashMap();
|
|
|
+ int i = 0;
|
|
|
+ for (int size = coll.size(); i < size; ++i) {
|
|
|
+ tempInfo = coll.get(i);
|
|
|
+ String name = (String) tempInfo.get("name");
|
|
|
+ if (nameMap.containsKey(name)) {
|
|
|
+ Integer count = (Integer) nameMap.get(name);
|
|
|
+ nameMap.put(name, Integer.valueOf(count.intValue() + 1));
|
|
|
+ } else {
|
|
|
+ nameMap.put(name, Integer.valueOf(1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ i = 0;
|
|
|
+ for (int size = coll.size(); i < size; ++i) {
|
|
|
+ dupName = false;
|
|
|
+ tempInfo = coll.get(i);
|
|
|
+ if (isExtendBaseItemEntity) {
|
|
|
+ tempInfo = (CoreBaseInfo) tempInfo.get(columnInfo
|
|
|
+ .getOriginalNameInExtend());
|
|
|
+ }
|
|
|
+ String name = (String) tempInfo.get("name");
|
|
|
+ if ((nameMap.get(name) != null)
|
|
|
+ && (((Integer) nameMap.get(name)).intValue() > 1)) {
|
|
|
+ dupName = true;
|
|
|
+ }
|
|
|
+ if (columnInfo.isBaseItemInfo()) {
|
|
|
+ tempText = getSelectText((String) tempInfo.get("number"),
|
|
|
+ (String) tempInfo.get("name"));
|
|
|
+ } else if ((ImportTempDisplayEnum.NAME.toString()
|
|
|
+ .equals(customParam.get("importDisplayFormat")))
|
|
|
+ || (StringUtils.isEmpty((String) customParam
|
|
|
+ .get("importDisplayFormat")))) {
|
|
|
+ if (dupName)
|
|
|
+ tempText = getSelectText((String) tempInfo
|
|
|
+ .get("number"), (String) tempInfo.get("name"));
|
|
|
+ else
|
|
|
+ tempText = (String) tempInfo.get("name");
|
|
|
+ } else if (ImportTempDisplayEnum.NUMBERANDNAME.toString()
|
|
|
+ .equals(customParam.get("importDisplayFormat"))) {
|
|
|
+ tempText = getSelectText((String) tempInfo.get("number"),
|
|
|
+ (String) tempInfo.get("name"));
|
|
|
+ }
|
|
|
+
|
|
|
+ datas.add(tempText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getSelectText(String number, String name) {
|
|
|
+ return number + ValueCovertUtils.NUMBER_NAME_SPLIT + name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void completeGenerateExcel(
|
|
|
+ Map<String, BaseColumnInfo> columnInfoMap, XSSFWorkbook wb,
|
|
|
+ XSSFSheet sheet) {
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean checkRelatedFieldExistDupName(BaseColumnInfo columnInfo)
|
|
|
+ throws BOSException, EASBizException {
|
|
|
+ String entityName = columnInfo.getSupplierEntityName();
|
|
|
+ EntityObjectInfo entityObject = MetaDataLoaderFactory
|
|
|
+ .getLocalMetaDataLoader(this.context).getEntity(
|
|
|
+ MetaDataPK.create(entityName));
|
|
|
+ String tableName = entityObject.getTable().getName();
|
|
|
+
|
|
|
+ PropertyInfo propertyInfo = entityObject.getFieldByFullName("name");
|
|
|
+ OwnPropertyInfo ownPropertyInfo = (OwnPropertyInfo) propertyInfo;
|
|
|
+ String tableColumnName = ownPropertyInfo.getMappingField().getName();
|
|
|
+ if (ownPropertyInfo.isMultilingual()) {
|
|
|
+ tableColumnName = tableColumnName + "_"
|
|
|
+ + LocaleUtils.getShortCode(this.context);
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
+ sql.append("select count(fid) from ");
|
|
|
+ sql.append(tableName);
|
|
|
+ sql.append(" where 1=1 ");
|
|
|
+ sql.append(" group by ").append(tableColumnName).append(
|
|
|
+ " having count(fid)>=2");
|
|
|
+ IRowSet rs = DbUtil.executeQuery(this.context, sql.toString());
|
|
|
+ boolean hasDup = false;
|
|
|
+ try {
|
|
|
+ if (rs.next())
|
|
|
+ hasDup = true;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ throw new BOSException(e);
|
|
|
+ }
|
|
|
+ return hasDup;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String getDefaultFilterStringByEntityInfo(String entityName) {
|
|
|
+ String filter = "";
|
|
|
+ if ("com.kingdee.eas.hr.org.app.JobGrade".equals(entityName)) {
|
|
|
+ filter = " and fid in (select fid from T_HR_JobGradeModule where Fenable=1) ";
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected CoreBaseCollection getRelatedFieldCollection(String entityName,
|
|
|
+ BaseColumnInfo columnInfo) {
|
|
|
+ EntityViewInfo viewInfo = new EntityViewInfo();
|
|
|
+
|
|
|
+ SelectorItemCollection selector = getComplexConvertSelector(columnInfo);
|
|
|
+ viewInfo.setSelector(selector);
|
|
|
+
|
|
|
+ FilterInfo filter = getDefaultFilterByEntityInfo(entityName, columnInfo);
|
|
|
+ if (filter != null) {
|
|
|
+ viewInfo.setFilter(filter);
|
|
|
+ }
|
|
|
+
|
|
|
+ SorterItemCollection sic = getDefalutSorterItemCollection(entityName,
|
|
|
+ columnInfo);
|
|
|
+ if (sic != null) {
|
|
|
+ viewInfo.setSorter(sic);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ ICoreBase corebase = (ICoreBase) BOSObjectFactory
|
|
|
+ .createCommonBOSObject(this.context, MetaDataPK
|
|
|
+ .create(entityName));
|
|
|
+ return corebase.getCollection(viewInfo);
|
|
|
+ } catch (BOSException e) {
|
|
|
+ throw new ImportException("获取列验证信息出错", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected SorterItemCollection getDefalutSorterItemCollection(
|
|
|
+ String entityName, BaseColumnInfo columnInfo) {
|
|
|
+ SorterItemCollection sic = new SorterItemCollection();
|
|
|
+ SorterItemInfo sorterIntemInfo = new SorterItemInfo("number");
|
|
|
+ sic.add(sorterIntemInfo);
|
|
|
+ return sic;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected FilterInfo getDefaultFilterByEntityInfo(String entityName,
|
|
|
+ BaseColumnInfo columnInfo) {
|
|
|
+ FilterInfo filter = new FilterInfo();
|
|
|
+
|
|
|
+ if ("com.kingdee.eas.basedata.org.app.HROrgUnit".equals(entityName)) {
|
|
|
+ String sql = getHrOrgUnitIdsSql();
|
|
|
+ if (!(StringUtils.isEmpty(sql))) {
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("id", sql, CompareType.INNER));
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("com.kingdee.shr.base.syssetting.app.SHRBasicItem"
|
|
|
+ .equals(entityName)) {
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("entityName", getMainEntityFullName(),
|
|
|
+ CompareType.EQUALS));
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("realEntityName",
|
|
|
+ getMainEntityFullName(), CompareType.EQUALS));
|
|
|
+ filter.setMaskString("#0 or #1");
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (SHRBaseItemApi.isSHRBaseItem(getContext(), entityName)) {
|
|
|
+ BaseItemParam param = getBaseItemParam(null, entityName);
|
|
|
+ String filterSql = SHRBaseItemApi
|
|
|
+ .queryAvailableRelationBaseSql(getContext(), param,
|
|
|
+ Boolean.TRUE.booleanValue());
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("id", filterSql, CompareType.INNER));
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+ } catch (EASBizException e) {
|
|
|
+ throw new ImportException(e.getMessage(), e);
|
|
|
+ } catch (BOSException e) {
|
|
|
+ throw new ImportException("获取列验证信息出错", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ EntityObjectInfo entityObject = MetaDataLoaderFactory
|
|
|
+ .getLocalMetaDataLoader(this.context).getEntity(
|
|
|
+ MetaDataPK.create(entityName));
|
|
|
+ PropertyInfo propInfo = entityObject.getPropertyByName("state");
|
|
|
+ if ((propInfo != null)
|
|
|
+ && (propInfo.getStateManager().getStateValue("metadataRef") != null)
|
|
|
+ && (propInfo.getStateManager().getStateValue("metadataRef") instanceof String)) {
|
|
|
+ String metadataRef = (String) propInfo.getStateManager()
|
|
|
+ .getStateValue("metadataRef");
|
|
|
+ if (("com.kingdee.eas.basedata.hraux.StateEnum".equals(metadataRef))
|
|
|
+ || ("com.kingdee.eas.hr.base.StateEnum".equals(metadataRef))) {
|
|
|
+ filter.getFilterItems().add(
|
|
|
+ new FilterItemInfo("state", Integer.valueOf(1),
|
|
|
+ CompareType.EQUALS));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected BaseItemParam getBaseItemParam(String realEntityName,
|
|
|
+ String entityName) {
|
|
|
+ BaseItemParam param = new BaseItemParam();
|
|
|
+ param.setEntityName(entityName);
|
|
|
+ param.setRealEntityName(realEntityName);
|
|
|
+ param.setPermItemId(getPermItemId());
|
|
|
+ param.setRespBaseItemId(Boolean.TRUE.booleanValue());
|
|
|
+ param.setRelationStates("100");
|
|
|
+ return param;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected List<String> getEnumDatas(BaseColumnInfo clumnInfo) {
|
|
|
+ String enumClassString = clumnInfo.getPropTypeClass();
|
|
|
+ if (StringUtils.isEmpty(enumClassString)) {
|
|
|
+ return new ArrayList(0);
|
|
|
+ }
|
|
|
+ String[] enumStrs = EnumUtils.getEnumAliases(enumClassString);
|
|
|
+ List enums = new ArrayList(enumStrs.length);
|
|
|
+ int i = 0;
|
|
|
+ for (int length = enumStrs.length; i < length; ++i) {
|
|
|
+ enums.add(enumStrs[i]);
|
|
|
+ }
|
|
|
+ return enums;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<BaseColumnInfo> getDynamicColumn() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTemplateMutexValue() {
|
|
|
+ String mutexString = "";
|
|
|
+ switch (this.templateInfo.getMutexType().getValue()) {
|
|
|
+ case 20:
|
|
|
+ mutexString = this.templateInfo.getBindFun();
|
|
|
+ break;
|
|
|
+ case 0:
|
|
|
+ mutexString = this.templateInfo.getEntityFullName();
|
|
|
+ }
|
|
|
+
|
|
|
+ return mutexString;
|
|
|
+ }
|
|
|
+}
|