private int getAuthorId(String _sAuthorName) throws PureException { IStatement query = null; IObjects result = null; try { ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class); // 1. formal table String strSQL = "SELECT * FROM {this} WHERE {this.trueName}=?"; query = userMgr.createQuery(strSQL, 1); query.setString(0, _sAuthorName); result = query.executeQuery(); SRMUser user = (SRMUser) result.next(); if (user != null) return user.getId(); // 2. temp table strSQL = "SELECT * FROM {this}0 WHERE {this.trueName}=?"; query = userMgr.createQuery(strSQL, 1); query.setString(0, _sAuthorName); result = query.executeQuery(); user = (SRMUser) result.next(); if (user != null) return user.getId(); return 0; } finally { DolphinHelper.clear(result, query); } }
/** * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject, * com.pureinfo.dolphin.model.DolphinObject, java.lang.String, java.lang.String, * com.pureinfo.dolphin.persister.ISession, com.pureinfo.dolphin.persister.ISession, * com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String, java.lang.String) */ public Object convert( DolphinObject _old, DolphinObject _new, String _sFromProperty, String _sToProperty, ISession _fromSession, ISession _toSession, EntityMetadata _metadata, String _sKey, String _sToTable) throws PureException { String sAdminName = _old.getStrProperty(_sFromProperty); if (sAdminName == null) return null; String sDeptCode = _old.getStrProperty("单位代码"); _new.setProperty("firstAuthorName", sAdminName); IObjects users = null; IStatement query = null; SRMUser user = null; int nUserId = 0; try { ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class); query = userMgr.createQuery( "SELECT * FROM {this} WHERE {this.trueName}=?", DolphinConstants.MAXSIZE_UNLIMITED); query.setString(0, sAdminName); users = query.executeQuery(); SRMUser[] aUsers = (SRMUser[]) users.toList().toArray(new SRMUser[0]); if (aUsers.length == 0) { nUserId = 0; } else if (aUsers.length == 1) { user = aUsers[0]; nUserId = user.getId(); } else { if (sDeptCode == null) { sDeptCode = _old.getStrProperty("字段1"); } String sCollege = sDeptCode.substring(0, 2); for (int i = 0; i < aUsers.length; i++) { Organization org = aUsers[i].getDepartment(); String sCode = null; if (org != null) sCode = org.getCode(); if (sCode != null && sCode.length() > 2) sCode = sCode.substring(0, 2); if (sCode != null && sCode.equals(sCollege)) { user = aUsers[i]; nUserId = user.getId(); break; } } if (user == null) { logger.error(_old.getStrProperty("成果名称") + "," + _old.getStrProperty("负责人")); user = aUsers[0]; nUserId = user.getId(); } } LocalContextHelper.currentSession().autoGenerateProperty(_new, "id"); int nProductId = _new.getIntProperty("id", -1); ObjUserMapping author = new ObjUserMapping(); author.setObjType(SRMTypes.PRODUCT); author.setUserType("1"); author.setUserId(nUserId); author.setUserName(sAdminName); author.setOrderNo(1); author.setObjId(nProductId); author.setWeightYear(WeightConstants.WEIGHT_YEAR_DEFAULT_VALUE); IObjUserMappingMgr puMgr = (IObjUserMappingMgr) ArkContentHelper.getContentMgrOf(ObjUserMapping.class); puMgr.save(author); } finally { DolphinHelper.clear(users, query); } return "" + nUserId; }