|
@ -16,6 +16,7 @@ import com.yihu.jw.basic.standard.service.bo.AdapterVersion;
|
|
|
import com.yihu.jw.basic.standard.service.bo.StandardVersion;
|
|
|
import com.yihu.jw.basic.standard.service.standard.StdDictService;
|
|
|
import com.yihu.jw.basic.standard.dao.SQLGeneralDAO;
|
|
|
import com.yihu.jw.basic.util.LikeHashMap;
|
|
|
import com.yihu.jw.lang.SpringContext;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
@ -23,6 +24,8 @@ import com.yihu.jw.restmodel.web.PageEnvelop;
|
|
|
import com.yihu.jw.util.common.StringUtil;
|
|
|
import com.yihu.jw.util.sql.SqlConstants;
|
|
|
import com.yihu.jw.util.sql.SqlCreator;
|
|
|
import com.yihu.jw.util.thread.ContextAttributes;
|
|
|
import com.yihu.jw.util.thread.LocalContext;
|
|
|
import org.hibernate.Query;
|
|
|
import org.hibernate.Session;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -197,16 +200,16 @@ public class AdapterDictService extends SQLGeneralDAO {
|
|
|
Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
return count;
|
|
|
}
|
|
|
public void strategy(String version,String std_version, String adapter_std_version) throws Exception {
|
|
|
List<AdapterDictEntryModel> unAdapterDictEntryModels= adapterDictEntryService.getAllUnAdaptDictEntry(version);//等待适配的标准字典项
|
|
|
public void strategy(String schemaName, String version,String std_version, String adapter_std_version) throws Exception {
|
|
|
List<AdapterDictEntryModel> unAdapterDictEntryModels= adapterDictEntryService.getAllUnAdaptDictEntry(schemaName,version);//等待适配的标准字典项
|
|
|
List<AdapterDictEntryModel> adapterDictEntryModels = new ArrayList<AdapterDictEntryModel>();//之前已经适配好的适配方案
|
|
|
//查找出 之前已经适配好的适配方案
|
|
|
List<AdapterSchemeVersionModel> all = adapterSchemeVersionService.getAll();//
|
|
|
List<AdapterSchemeVersionModel> all = adapterSchemeVersionService.getAll(schemaName);//
|
|
|
if(all!=null){
|
|
|
for(AdapterSchemeVersionModel adapterSchemeVersionModel:all){
|
|
|
String vers = adapterSchemeVersionModel.getVersion();
|
|
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(vers)){
|
|
|
List<AdapterDictEntryModel> adaptMetadata = adapterDictEntryService.getAllAdaptDictEntry(adapterSchemeVersionModel.getVersion());
|
|
|
List<AdapterDictEntryModel> adaptMetadata = adapterDictEntryService.getAllAdaptDictEntry(schemaName,adapterSchemeVersionModel.getVersion());
|
|
|
adapterDictEntryModels.addAll(adaptMetadata);
|
|
|
}
|
|
|
}
|
|
@ -216,12 +219,12 @@ public class AdapterDictService extends SQLGeneralDAO {
|
|
|
|
|
|
//設置匹配的机构数据緩存
|
|
|
StandardVersion standardVersion = new StandardVersion(adapter_std_version);
|
|
|
List<StdDictionaryEntryModel> dictItems = stdDictService.getDicEntryList(standardVersion, null, null, null, null);
|
|
|
List<StdDictionaryEntryModel> dictItems = stdDictService.getDicEntryList(schemaName,standardVersion, null, null, null, null);//查找源机构字典子项
|
|
|
|
|
|
for (StdDictionaryEntryModel stdDictItem:dictItems){
|
|
|
StdDictionaryModel dictionary = stdDictionaryDao.getDictionaryName(adapter_std_version, stdDictItem.getDictId());
|
|
|
StdDictionaryModel dictionary = stdDictionaryDao.getDictionaryName(schemaName,adapter_std_version, stdDictItem.getDictId());//查找源机构字典项
|
|
|
if(dictionary != null){
|
|
|
DictitemStandardNameStrategy.getNameMap().put(stdDictItem.getValue() + "_" + dictionary.getCode(),stdDictItem);
|
|
|
DictitemStandardNameStrategy.getNameMap().put(stdDictItem.getCode()+"_"+stdDictItem.getValue() + "_" + dictionary.getName(),stdDictItem);//字典子项名_字典名
|
|
|
}
|
|
|
}
|
|
|
|
|
@ -231,16 +234,16 @@ public class AdapterDictService extends SQLGeneralDAO {
|
|
|
Set<String> sqlList = new HashSet<String>();
|
|
|
|
|
|
for (AdapterDictEntryModel unAdapterDictEntryModel : unAdapterDictEntryModels) {
|
|
|
threadPoolTaskExecutor.execute(new DictItemStrategyExecute(unAdapterDictEntryModel, matchVO,std_version,adapter_std_version,version, stdDictionaryDao, stdDictionaryEntryDao,adapterDictEntryService));
|
|
|
threadPoolTaskExecutor.execute(new DictItemStrategyExecute(schemaName,unAdapterDictEntryModel, matchVO,std_version,adapter_std_version,version, stdDictionaryDao, stdDictionaryEntryDao,adapterDictEntryService));
|
|
|
|
|
|
Long unAdaptDicId = unAdapterDictEntryModel.getStdDictId();
|
|
|
StdDictionaryModel adapterDictionaryModel = stdDictionaryDao.getDictionaryName(adapter_std_version, unAdaptDicId);
|
|
|
StdDictionaryModel adapterDictionaryModel = stdDictionaryDao.getDictionaryName(schemaName,adapter_std_version, unAdaptDicId);
|
|
|
if (adapterDictionaryModel != null) {
|
|
|
adapterDictService = SpringContext.getService(AdapterDictService.BEAN_ID);
|
|
|
AdapterDictModel entity = adapterDictService.getAdapterDictByCode(version, adapterDictionaryModel.getCode());
|
|
|
AdapterDictModel entity = adapterDictService.getAdapterDictByCode(schemaName,version, adapterDictionaryModel.getCode());
|
|
|
String sqrSql = null;
|
|
|
if (null != entity) {
|
|
|
sqrSql = adapterDictService.saveAdaptDictSql(entity, adapterDictionaryModel, version);
|
|
|
sqrSql = adapterDictService.saveAdaptDictSql(schemaName,entity, adapterDictionaryModel, version);
|
|
|
}
|
|
|
if (null != sqrSql && !"".equals(sqrSql)) {
|
|
|
sqlList.add(sqrSql);
|
|
@ -260,17 +263,22 @@ public class AdapterDictService extends SQLGeneralDAO {
|
|
|
query.executeUpdate();
|
|
|
}
|
|
|
|
|
|
public String saveAdaptDictSql(AdapterDictModel strategyDict, StdDictionaryModel orgDict, String version) throws Exception {
|
|
|
|
|
|
public String saveAdaptDictSql(String schemaName, AdapterDictModel strategyDict, StdDictionaryModel orgDict, String version) throws Exception {
|
|
|
StringBuilder sqlBuffer = new StringBuilder();
|
|
|
sqlBuffer.append(SqlConstants.UPDATE + new AdapterVersion(version).getDictTableName() + SqlConstants.SET);
|
|
|
sqlBuffer.append(" adapter_dict_id = " + orgDict.getId());
|
|
|
sqlBuffer.append(",adapter_dict_code = '" + orgDict.getCode() + "'");
|
|
|
sqlBuffer.append(",adapter_dict_name = '" + orgDict.getName() + "'");
|
|
|
sqlBuffer.append(" where id=" + strategyDict.getId());
|
|
|
return sqlBuffer.toString();
|
|
|
|
|
|
String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
|
|
|
String completeSql = myCatAnnotation + sqlBuffer.toString();
|
|
|
|
|
|
return completeSql;
|
|
|
}
|
|
|
|
|
|
public AdapterDictModel getAdapterDictByCode(String version, String dictCode) {
|
|
|
public AdapterDictModel getAdapterDictByCode(String schemaName, String version, String dictCode) {
|
|
|
try {
|
|
|
if (StringUtil.isEmpty(dictCode)) {
|
|
|
return null;
|
|
@ -278,11 +286,95 @@ public class AdapterDictService extends SQLGeneralDAO {
|
|
|
SqlCreator sqlCreator = new SqlCreator(AdapterDictModel.class);
|
|
|
sqlCreator.equalCondition("stdDictCode", dictCode);
|
|
|
String sql = sqlCreator.selectData("adapter_dict_" + version);
|
|
|
return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(AdapterDictModel.class)).get(0);
|
|
|
|
|
|
String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
|
|
|
String completeSql = myCatAnnotation + sql;
|
|
|
|
|
|
return jdbcTemplate.query(completeSql,new BeanPropertyRowMapper<>(AdapterDictModel.class)).get(0);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Envelop smartMatch(String std_version, String adapter_version, Long stdDictId, Long adapterDictId) throws Exception {
|
|
|
//获取等待适配的字典项
|
|
|
List<AdapterDictEntryModel> unAdapterDictEntryModels= adapterDictEntryService.getUnAdaptDictEntryByDictId(adapter_version,stdDictId);
|
|
|
|
|
|
//获取源字典项
|
|
|
Map<String, Object> query = new HashMap<>();
|
|
|
query.put("dictId",adapterDictId);
|
|
|
List<StdDictionaryEntryModel> dicEntryList = stdDictService.getDicEntryList(new StandardVersion(std_version), query, null, null, null);
|
|
|
|
|
|
|
|
|
if(dicEntryList!=null && dicEntryList.size()>0){
|
|
|
LikeHashMap<String, StdDictionaryEntryModel> nameMap = new LikeHashMap<String, StdDictionaryEntryModel>();
|
|
|
for(StdDictionaryEntryModel stdDictionaryEntryModel:dicEntryList){
|
|
|
String code = stdDictionaryEntryModel.getCode();
|
|
|
if(!StringUtil.isEmpty(code)){
|
|
|
code = code.trim();
|
|
|
}
|
|
|
String value = stdDictionaryEntryModel.getValue();
|
|
|
if(!StringUtil.isEmpty(value)){
|
|
|
value = value.trim();
|
|
|
}
|
|
|
nameMap.put(code+"@"+value,stdDictionaryEntryModel);
|
|
|
}
|
|
|
if(unAdapterDictEntryModels!=null && unAdapterDictEntryModels.size()>0){
|
|
|
String schemaName = LocalContext.getContext().getAttachment(ContextAttributes.SCHEMA);
|
|
|
|
|
|
//通过code查询,连续十次查询不到,就不再通过code查询
|
|
|
int selectByCode=0;
|
|
|
for(AdapterDictEntryModel model:unAdapterDictEntryModels){
|
|
|
//查询到的匹配字典项
|
|
|
StdDictionaryEntryModel stdDictionaryEntryModel = null;
|
|
|
|
|
|
String code = model.getStdEntryCode();
|
|
|
if(!StringUtil.isEmpty(code)){
|
|
|
code = code.trim();
|
|
|
}
|
|
|
//code长度极长,很大概率是国家标准,直接通过code查询匹配,匹配度更高
|
|
|
//通过code查询,连续十次查询不到,就不再通过code查询(以防不是国家标准,浪费性能)
|
|
|
//if(!StringUtil.isEmpty(code) && code.length()>=5){
|
|
|
if(selectByCode<=10){
|
|
|
query.put("code",code);
|
|
|
List<StdDictionaryEntryModel> dictionaries = stdDictService.getDicEntryList(new StandardVersion(std_version), query, null, null, null);//源字典
|
|
|
if(dictionaries!=null && dictionaries.size()>0){
|
|
|
selectByCode=0;
|
|
|
if(dictionaries.size()==1){
|
|
|
stdDictionaryEntryModel = dictionaries.get(0);
|
|
|
adapterDictEntryService.saveAdapt(schemaName,model,stdDictionaryEntryModel , adapter_version,"2");
|
|
|
nameMap.remove(stdDictionaryEntryModel.getCode()+"@"+stdDictionaryEntryModel.getValue());
|
|
|
}else{
|
|
|
adapterDictEntryService.saveAdapt(schemaName,model, dictionaries.get(0), adapter_version,"1");
|
|
|
}
|
|
|
continue;
|
|
|
}else{
|
|
|
selectByCode++;
|
|
|
}
|
|
|
}
|
|
|
//}
|
|
|
|
|
|
//通过name做适配
|
|
|
String name = model.getStdEntryValue();
|
|
|
if(!StringUtil.isEmpty(name)){
|
|
|
name = name.trim();
|
|
|
}
|
|
|
stdDictionaryEntryModel = nameMap.get("@" + name, true);
|
|
|
if (stdDictionaryEntryModel != null) {
|
|
|
adapterDictEntryService.saveAdapt(schemaName,model, stdDictionaryEntryModel, adapter_version,"1");//只匹配字典项code ,为疑似匹配
|
|
|
}else{
|
|
|
if(!StringUtil.isEmpty(code) && code.length()>=3){//如果code长度足够长,很可能是国家标准规范,也可根据code进行匹配, 这边取>=3 ,若匹配效果不满意,可增大该值
|
|
|
stdDictionaryEntryModel = nameMap.get(code+"@", true);
|
|
|
if(stdDictionaryEntryModel!=null){
|
|
|
adapterDictEntryService.saveAdapt(schemaName,model, stdDictionaryEntryModel, adapter_version,"1");//只匹配字典项code ,为疑似匹配
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return Envelop.getSuccess("匹配成功");
|
|
|
}
|
|
|
|
|
|
}
|