Ver código fonte

代码修改

LAPTOP-KB9HII50\70708 2 anos atrás
pai
commit
838edf44dd

+ 19 - 1
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/controller/AdapterDictController.java

@ -5,6 +5,8 @@ import com.yihu.jw.basic.standard.service.adapter.AdapterDictService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.thread.ContextAttributes;
import com.yihu.jw.util.thread.LocalContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -108,7 +110,8 @@ public class AdapterDictController extends EnvelopRestEndpoint {
                    return Envelop.getSuccess("操作成功");
                }
            }
            dictService.strategy(version,std_version,adapter_std_version);
            String schemaName = LocalContext.getContext().getAttachment(ContextAttributes.SCHEMA);
            dictService.strategy(schemaName,version,std_version,adapter_std_version);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError("操作失败",-1);
@ -116,6 +119,7 @@ public class AdapterDictController extends EnvelopRestEndpoint {
        return Envelop.getSuccess("操作成功");
    }
    @RequestMapping(value = "/getStrategyDicSize", method = RequestMethod.POST)
    @ApiOperation(value = "智能匹配进行",  produces = "application/json", notes = "智能匹配进行")
    public Envelop getStrategyDicSize(
@ -143,4 +147,18 @@ public class AdapterDictController extends EnvelopRestEndpoint {
        }
    }
    /**
     * 单个字典智能匹配
     */
    @ResponseBody
    @RequestMapping(value = "/smartMatch", method = RequestMethod.GET,produces = "application/json")
    @ApiOperation(value = "单个字典智能匹配", response = Envelop.class, produces = "application/json", notes = "单个字典智能匹配")
    public Envelop smartMatch(
            @ApiParam(value = "源version", required = true) @RequestParam("std_version") String std_version,
            @ApiParam(value = "适配方案版本号", required = true) @RequestParam("adapter_version") String adapter_version,
            @ApiParam(value = "适配表的stdDictId(目标的stdDictId)", required = true) @RequestParam("stdDictId") Long stdDictId,
            @ApiParam(value = "适配表的adapterDictId(源的stdDictId)", required = true) @RequestParam("adapterDictId") Long adapterDictId) throws Exception {
        return dictService.smartMatch(std_version,adapter_version,stdDictId,adapterDictId);
    }
}

+ 1 - 1
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/dao/IStdDictionaryEntryModelDao.java

@ -10,5 +10,5 @@ import java.util.List;
 */
public interface IStdDictionaryEntryModelDao extends XSQLGeneralDAO {
    List<StdDictionaryEntryModel> getDictionaryEntry(String adapter_std_version, String orgDicEntryValue,String orgDicValue);
    List<StdDictionaryEntryModel> getDictionaryEntry(String schemaName, String adapter_std_version, String orgDicEntryValue, String orgDicValue);
}

+ 1 - 1
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/dao/IStdDictionaryModelDao.java

@ -8,5 +8,5 @@ import com.yihu.jw.basic.standard.dao.XSQLGeneralDAO;
 * Created by Administrator on 2016/5/4.
 */
public interface IStdDictionaryModelDao extends XSQLGeneralDAO {
    public StdDictionaryModel getDictionaryName(String version, Long id);
    public StdDictionaryModel getDictionaryName(String schemaName, String version, Long id);
}

+ 6 - 3
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/dao/StdDictionaryEntryModelDao.java

@ -17,13 +17,16 @@ import java.util.List;
@CacheConfig(cacheNames = "StdDictionaryEntryModelCache")
public class StdDictionaryEntryModelDao extends SQLGeneralDAO implements IStdDictionaryEntryModelDao {
    @Override
    @Cacheable
    public List<StdDictionaryEntryModel> getDictionaryEntry(String adapter_std_version, String orgDicEntryValue, String dictName) {
    public List<StdDictionaryEntryModel> getDictionaryEntry(String schemaName,String adapter_std_version, String orgDicEntryValue, String dictName) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT m.*").append(" FROM std_dictionary_entry_" + adapter_std_version).append(" m inner join std_dictionary_" + adapter_std_version)
                .append(" d on d.id= m.dict_id where m.value like ? and d.name like ?");
        String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
        String completeSql = myCatAnnotation + sql;
        try {
            Query query = getCurrentSession().createSQLQuery(sql.toString());
            Query query = getCurrentSession().createSQLQuery(completeSql);
            query.setCacheable(true);
            query.setParameter(0, "%" + orgDicEntryValue + "%");
            query.setParameter(1, "%" + dictName + "%");

+ 6 - 3
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/dao/StdDictionaryModelDao.java

@ -18,12 +18,15 @@ public class StdDictionaryModelDao extends SQLGeneralDAO implements IStdDictiona
    public final static String BEAN_ID = "stdDictionaryDao";
    @Override
    @Cacheable
    public StdDictionaryModel getDictionaryName(String version, Long id) {
    public StdDictionaryModel getDictionaryName(String schemaName,String version, Long id) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT d.*").append(" FROM std_dictionary_").append(version).append(" d where d.id =" + id);
        String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
        String completeSql = myCatAnnotation + sql;
        try {
            Query query = getCurrentSession().createSQLQuery(sql.toString());
            Query query = getCurrentSession().createSQLQuery(completeSql);
            query.setResultTransformer(new BeanTransformer(StdDictionaryModel.class));
            StdDictionaryModel stdDictionaryModel = (StdDictionaryModel) query.uniqueResult();
            return stdDictionaryModel;

+ 10 - 2
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/match/dictionary/DictItemStrategyExecute.java

@ -1,5 +1,6 @@
package com.yihu.jw.basic.standard.match.dictionary;
import com.yihu.jw.basic.standard.dao.IStdDictionaryModelDao;
import com.yihu.jw.basic.standard.dao.StdDictionaryEntryModelDao;
import com.yihu.jw.basic.standard.match.matchModel.DictItemMatchVO;
@ -29,18 +30,23 @@ public class DictItemStrategyExecute implements Runnable {
    private IStdDictionaryModelDao stdDictionaryDao;
    private StdDictionaryEntryModelDao stdDictionaryEntryDao;
    private AdapterDictEntryService adapterDictEntryService;
    private String schemaName;
    private DictitemStandardNameStrategy dictitemStandardNameStrategy;
    public DictItemStrategyExecute(
            String schemaName,
            AdapterDictEntryModel adapterDictEntryModel,
            DictItemMatchVO matchVO,
            String std_version,
            String adapter_std_version,
            String version,
            IStdDictionaryModelDao stdDictionaryDao,
                    StdDictionaryEntryModelDao stdDictionaryEntryDao,
                    AdapterDictEntryService adapterDictEntryService) {
            StdDictionaryEntryModelDao stdDictionaryEntryDao,
            AdapterDictEntryService adapterDictEntryService) {
        this.schemaName = schemaName;
        this.adapterDictEntryModel = adapterDictEntryModel;
        this.matchVO = matchVO;
        this.std_version = std_version;
@ -51,9 +57,11 @@ public class DictItemStrategyExecute implements Runnable {
        standardExistStrategy.setStdDictionaryDao(stdDictionaryDao);
        standardExistStrategy.setStdDictionaryEntryDao(stdDictionaryEntryDao);
        standardExistStrategy.setAdapterDictEntryService(adapterDictEntryService);
        standardExistStrategy.setSchemaName(schemaName);
        dictitemStandardNameStrategy = new DictitemStandardNameStrategy();
        dictitemStandardNameStrategy.setAdapterDictEntryService(adapterDictEntryService);
        dictitemStandardNameStrategy.setStdDictionaryDao(stdDictionaryDao);
        dictitemStandardNameStrategy.setSchemaName(schemaName);
    }
    public static void setVersionYes(String version) {

+ 42 - 29
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/match/dictionary/DictitemStandardExistStrategy.java

@ -1,5 +1,6 @@
package com.yihu.jw.basic.standard.match.dictionary;
import com.yihu.jw.basic.standard.dao.IStdDictionaryModelDao;
import com.yihu.jw.basic.standard.dao.StdDictionaryEntryModelDao;
import com.yihu.jw.basic.standard.match.matchModel.DictItemMatchVO;
@ -27,8 +28,10 @@ public class DictitemStandardExistStrategy {
    private AdapterDictEntryService adapterDictEntryService;
    private AdapterDictService adapterDictService;
    private String schemaName;
    public DictitemStandardExistStrategy(IStdDictionaryModelDao stdDictionaryDao, StdDictionaryEntryModelDao stdDictionaryEntryDao, AdapterDictEntryService adapterDictEntryService) {
    public DictitemStandardExistStrategy(String schemaName,IStdDictionaryModelDao stdDictionaryDao, StdDictionaryEntryModelDao stdDictionaryEntryDao, AdapterDictEntryService adapterDictEntryService) {
        this.schemaName = schemaName;
        this.stdDictionaryDao = stdDictionaryDao;
        this.stdDictionaryEntryDao = stdDictionaryEntryDao;
        this.adapterDictEntryService = adapterDictEntryService;
@ -58,6 +61,22 @@ public class DictitemStandardExistStrategy {
        this.adapterDictEntryService = adapterDictEntryService;
    }
    public AdapterDictService getAdapterDictService() {
        return adapterDictService;
    }
    public void setAdapterDictService(AdapterDictService adapterDictService) {
        this.adapterDictService = adapterDictService;
    }
    public String getSchemaName() {
        return schemaName;
    }
    public void setSchemaName(String schemaName) {
        this.schemaName = schemaName;
    }
    public DictitemStandardExistStrategy() {
    }
@ -67,39 +86,33 @@ public class DictitemStandardExistStrategy {
    public boolean match(AdapterDictEntryModel adapterDictEntryModel, DictItemMatchVO matchVO, String std_version, String adapter_std_version, String version) throws Exception {
        boolean flag = false;
        try {
        String dictitemNameFirstCode = GetChineseFirst.cn2py(adapterDictEntryModel.getStdEntryValue());//待匹配
        List<AdapterDictEntryModel> matchList = matchVO.getCodeAdapter().get(dictitemNameFirstCode);//已存在
        if (matchList != null && matchList.size() > 0) {
            Long unAdaptDicId = adapterDictEntryModel.getStdDictId();
            StdDictionaryModel stdDictionaryModel = stdDictionaryDao.getDictionaryName(std_version,unAdaptDicId);
            StdDictionaryModel adapterDictionaryModel = stdDictionaryDao.getDictionaryName(adapter_std_version,unAdaptDicId);
            if(stdDictionaryModel!=null){
                String dictName = stdDictionaryModel.getName();
                for (AdapterDictEntryModel adapterDictEntry : matchList) {
                    if(adapterDictEntry.getStdEntryValue().contains(adapterDictEntryModel.getStdEntryValue())){
                        String orgDicEntryValue= adapterDictEntry.getAdapterEntryValue();
                        //根据值查找出 该项目下面的字典项
                        List<StdDictionaryEntryModel> dictionaryEntryTemps = stdDictionaryEntryDao.getDictionaryEntry(adapter_std_version,orgDicEntryValue,dictName);
                        if(dictionaryEntryTemps!=null&&dictionaryEntryTemps.size()>0){
                            String adapterInfo = "1";//查找到就默认疑似适配
                            if(dictionaryEntryTemps.size()==1){//查找到的条数为1,则为完全适配
                                adapterInfo = "2";
            String dictitemNameFirstCode = GetChineseFirst.cn2py(adapterDictEntryModel.getStdEntryValue());//待匹配
            List<AdapterDictEntryModel> matchList = matchVO.getCodeAdapter().get(dictitemNameFirstCode);//已存在
            if (matchList != null && matchList.size() > 0) {
                Long unAdaptDicId = adapterDictEntryModel.getStdDictId();
                StdDictionaryModel stdDictionaryModel = stdDictionaryDao.getDictionaryName(schemaName,std_version,unAdaptDicId);
                if(stdDictionaryModel!=null){
                    String dictName = stdDictionaryModel.getName();
                    for (AdapterDictEntryModel adapterDictEntry : matchList) {
                        if(adapterDictEntry.getStdEntryValue().contains(adapterDictEntryModel.getStdEntryValue())){
                            String orgDicEntryValue= adapterDictEntry.getAdapterEntryValue();
                            //根据值查找出 该项目下面的字典项
                            List<StdDictionaryEntryModel> dictionaryEntryTemps = stdDictionaryEntryDao.getDictionaryEntry(schemaName,adapter_std_version,orgDicEntryValue,dictName);
                            if(dictionaryEntryTemps!=null&&dictionaryEntryTemps.size()>0){
                                String adapterInfo = "1";//查找到就默认疑似适配
                                if(dictionaryEntryTemps.size()==1){//查找到的条数为1,则为完全适配
                                    adapterInfo = "2";
                                }
                                StdDictionaryEntryModel stdDictionaryEntryModel = dictionaryEntryTemps.get(0);
                                //保存适配
                                adapterDictEntryService.saveAdapt(schemaName,adapterDictEntryModel, stdDictionaryEntryModel, version,adapterInfo);
                                flag=true;
                                break;
                            }
                            StdDictionaryEntryModel stdDictionaryEntryModel = dictionaryEntryTemps.get(0);
                            //保存适配
                            adapterDictEntryService.saveAdapt(adapterDictEntryModel, stdDictionaryEntryModel, version,adapterInfo);
                            flag=true;
                            break;
                        }
                    }
                }
            }
//            if (adapterDictionaryModel != null) {
//                adapterDictService = SpringBeanUtil.getService(AdapterDictService.BEAN_ID);
//                AdapterDictModel entity = adapterDictService.getAdapterDictByCode(version, adapterDictionaryModel.getCode());
//                adapterDictService.saveAdaptDict(entity, adapterDictionaryModel,version);
//            }
        }
        } catch (Exception e) {
            e.printStackTrace();
        }

+ 33 - 8
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/match/dictionary/DictitemStandardNameStrategy.java

@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
/**
 * Created by Administrator on 2016/7/4.
 */
@ -28,6 +29,8 @@ public class DictitemStandardNameStrategy {
        return stdDictionaryDao;
    }
    private String schemaName;
    public void setStdDictionaryDao(IStdDictionaryModelDao stdDictionaryDao) {
        this.stdDictionaryDao = stdDictionaryDao;
    }
@ -45,7 +48,15 @@ public class DictitemStandardNameStrategy {
        this.adapterDictEntryService = adapterDictEntryService;
    }
    private static LikeHashMap<String,StdDictionaryEntryModel> nameMap=new LikeHashMap<String,StdDictionaryEntryModel>();//机构字典项值的map
    public String getSchemaName() {
        return schemaName;
    }
    public void setSchemaName(String schemaName) {
        this.schemaName = schemaName;
    }
    private static LikeHashMap<String, StdDictionaryEntryModel> nameMap=new LikeHashMap<String,StdDictionaryEntryModel>();//机构字典项值的map
    public DictitemStandardNameStrategy() {
@ -54,17 +65,31 @@ public class DictitemStandardNameStrategy {
    @Transactional
    public boolean match(AdapterDictEntryModel adapterDictEntryModel, String version,String std_version) throws Exception {
        if (adapterDictEntryModel==null){
            System.out.println(adapterDictEntryModel);
        }
        StdDictionaryModel dictionary = stdDictionaryDao.getDictionaryName(std_version, adapterDictEntryModel.getStdDictId());
    public boolean match(AdapterDictEntryModel adapterDictEntryModel, String version, String std_version) throws Exception {
        StdDictionaryModel dictionary = stdDictionaryDao.getDictionaryName(schemaName,std_version, adapterDictEntryModel.getStdDictId());//查找目标字典
        StdDictionaryEntryModel orgDictItem = nameMap.get(adapterDictEntryModel.getStdEntryValue()+ "_" + dictionary.getCode(), true);
        StdDictionaryEntryModel orgDictItem = nameMap.get(adapterDictEntryModel.getStdEntryCode()+"_"+adapterDictEntryModel.getStdEntryValue()+ "_" + dictionary.getName(), true);
        if (orgDictItem != null ) {
            adapterDictEntryService.saveAdapt(adapterDictEntryModel, orgDictItem, version,"2");
            adapterDictEntryService.saveAdapt(schemaName,adapterDictEntryModel, orgDictItem, version,"2");//字典名和字典项名字一样,即为完全匹配
            return true;
        }
        orgDictItem = nameMap.get(adapterDictEntryModel.getStdEntryCode()+"_"+adapterDictEntryModel.getStdEntryValue()+ "_" , true);//疑似适配,//根据字典项的code和名称
        if (orgDictItem != null ) {
            adapterDictEntryService.saveAdapt(schemaName,adapterDictEntryModel, orgDictItem, version,"1");//只匹配字典项code ,为疑似匹配--->>匹配度已经很高了,但是仍然设置为疑似适配,方便校验
            return true;
        }
        orgDictItem = nameMap.get("_"+adapterDictEntryModel.getStdEntryValue()+ "_" , true);//疑似适配 ,//只根据字典项的value
        if (orgDictItem != null ) {
            adapterDictEntryService.saveAdapt(schemaName,adapterDictEntryModel, orgDictItem, version,"1");//只匹配字典项 名字,为疑似匹配--->>匹配度较低
            return true;
        }
        if(adapterDictEntryModel.getStdEntryCode().length()>=5){// (code如果复杂的情况时(icd10等字典那些),匹配度也很高了,否则匹配度极低)
            orgDictItem = nameMap.get(adapterDictEntryModel.getStdEntryCode()+ "_" , true);//疑似适配,//只根据字典项的code
            if (orgDictItem != null ) {
                adapterDictEntryService.saveAdapt(schemaName,adapterDictEntryModel, orgDictItem, version,"1");//只匹配字典项code ,为疑似匹配
                return true;
            }
        }
        return false;
    }

+ 5 - 8
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/service/adapter/AdapterDatasetService.java

@ -9,10 +9,8 @@ import com.yihu.jw.basic.standard.match.metadata.MetadataStrategyExecute;
import com.yihu.jw.basic.standard.match.metadata.MetatdataStandardNameStrategy;
import com.yihu.jw.basic.standard.model.TreeView;
import com.yihu.jw.basic.standard.model.adapter.AdapterDatasetModel;
import com.yihu.jw.basic.standard.model.adapter.AdapterDictModel;
import com.yihu.jw.basic.standard.model.adapter.AdapterMetadataModel;
import com.yihu.jw.basic.standard.model.adapter.AdapterSchemeVersionModel;
import com.yihu.jw.basic.standard.model.standard.StandardVersionModel;
import com.yihu.jw.basic.standard.model.standard.StdDataSetModel;
import com.yihu.jw.basic.standard.model.standard.StdMetaDataModel;
import com.yihu.jw.basic.standard.service.bo.AdapterVersion;
@ -35,7 +33,7 @@ import com.yihu.jw.util.sql.SqlCreator;
import com.yihu.jw.util.thread.ContextAttributes;
import com.yihu.jw.util.thread.LocalContext;
import org.apache.commons.collections.CollectionUtils;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@ -783,7 +781,7 @@ public class AdapterDatasetService extends SQLGeneralDAO {
        //执行匹配
        MetadataStrategyExecute.setFirst(version, unAdapterMetadataModels.size());//设置第一次匹配
        Set<String> sqlList = new HashSet<String>();
        Set<String> sqlList = new HashSet<>();
        for (AdapterMetadataModel unAdapterMetadataModel : unAdapterMetadataModels) {
            threadPoolTaskExecutor.execute(new MetadataStrategyExecute(schemaName,unAdapterMetadataModel, matchVO, std_version,adapter_std_version,version, stdMetaDataModelDao,stdDataSetModelDao,adapterMetadataService));
@ -809,10 +807,9 @@ public class AdapterDatasetService extends SQLGeneralDAO {
        }
        if(CollectionUtils.isNotEmpty(sqlList)){
            List list=new ArrayList();
            Iterator it=sqlList.iterator();
            while(it.hasNext()){
                list.add((String) it.next());
            List<String> list=new ArrayList<>();
            for (String s : sqlList) {
                list.add(s);
            }
            super.insertBatch(list);
        }

+ 24 - 6
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/service/adapter/AdapterDictEntryService.java

@ -339,21 +339,28 @@ public class AdapterDictEntryService extends SQLGeneralDAO {
            return null;
        }
    }
    public List<AdapterDictEntryModel> getAllUnAdaptDictEntry(String version){
    public List<AdapterDictEntryModel> getAllUnAdaptDictEntry(String schemaName, String version){
        AdapterVersion adapterVersion = new AdapterVersion(version);
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT m.*").append(" FROM "+adapterVersion.getDictEntryTableName()).append(" m where m.adapter_entry_id is null");
        return jdbcTemplate.query(sql.toString(),new BeanPropertyRowMapper<>(AdapterDictEntryModel.class));
        String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
        String completeSql = myCatAnnotation + sql;
        return jdbcTemplate.query(completeSql,new BeanPropertyRowMapper<>(AdapterDictEntryModel.class));
    }
    public List<AdapterDictEntryModel> getAllAdaptDictEntry(String version) {
    public List<AdapterDictEntryModel> getAllAdaptDictEntry(String schemaName, String version) {
        AdapterVersion adapterVersion = new AdapterVersion(version);
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT m.*").append(" FROM "+adapterVersion.getDictEntryTableName()).append(" m where m.adapter_entry_id is not null");
        return jdbcTemplate.query(sql.toString(),new BeanPropertyRowMapper<>(AdapterDictEntryModel.class));
        String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
        String completeSql = myCatAnnotation + sql;
        return jdbcTemplate.query(completeSql, new BeanPropertyRowMapper<>(AdapterDictEntryModel.class));
    }
    public void saveAdapt(AdapterDictEntryModel adapterDictEntryModel, StdDictionaryEntryModel stdDictionaryEntryModel, String version,String adapterInfo) throws  Exception{
    public void saveAdapt(String schemaName, AdapterDictEntryModel adapterDictEntryModel, StdDictionaryEntryModel stdDictionaryEntryModel, String version, String adapterInfo) throws  Exception{
        adapterDictEntryModel.setAdapterDictId(stdDictionaryEntryModel.getDictId());
        adapterDictEntryModel.setAdapterEntryId(stdDictionaryEntryModel.getId());
        adapterDictEntryModel.setAdapterEntryCode(stdDictionaryEntryModel.getCode());
@ -362,7 +369,11 @@ public class AdapterDictEntryService extends SQLGeneralDAO {
        JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(adapterDictEntryModel));
        SqlCreator sqlCreator = new SqlCreator(AdapterDictEntryModel.class);
        String sql = sqlCreator.updateDataByTableKey(new AdapterVersion(version).getDictEntryTableName(), jsonNode);
        Query query = getExeuteQuery(sqlCreator, sql);
        String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
        String completeSql = myCatAnnotation + sql;
        Query query = getExeuteQuery(sqlCreator, completeSql);
        query.executeUpdate();
    }
@ -429,4 +440,11 @@ public class AdapterDictEntryService extends SQLGeneralDAO {
        jdbcTemplate.execute("delete from " + dictEntryTableName + " WHERE id = "+id);
        return Envelop.getSuccess("删除成功");
    }
    public List<AdapterDictEntryModel> getUnAdaptDictEntryByDictId(String version,Long stdDictId){
        AdapterVersion adapterVersion = new AdapterVersion(version);
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT m.*").append(" FROM "+adapterVersion.getDictEntryTableName()).append(" m where m.adapter_entry_id is null and m.std_dict_id="+stdDictId);
        return jdbcTemplate.query(sql.toString(),new BeanPropertyRowMapper<>(AdapterDictEntryModel.class));
    }
}

+ 107 - 15
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/service/adapter/AdapterDictService.java

@ -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("匹配成功");
    }
}

+ 29 - 0
svr/svr-basic/src/main/java/com/yihu/jw/basic/standard/service/standard/StdDictService.java

@ -274,6 +274,35 @@ public class StdDictService extends SQLGeneralDAO {
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(StdDictionaryEntryModel.class));
    }
    public List<StdDictionaryEntryModel> getDicEntryList(String schemaName,StandardVersion standardVersion, Map<String, Object> query, Map<String, String> order, Integer limit, Integer offset) {
        SqlCreator sqlCreator = new SqlCreator(StdDictionaryEntryModel.class);
        if(null!=query){
            for (String key : query.keySet()) {
                sqlCreator.equalCondition(key, query.get(key));
            }
        }
        if(order!=null){
            for (String key : order.keySet()) {
                sqlCreator.order(key, order.get(key));
            }
        }
        String sql = sqlCreator.selectData(standardVersion.getDictEntryTableName());
        String myCatAnnotation = "/*#mycat:schema=" + schemaName + "*/ ";
        String completeSql = myCatAnnotation + sql;
        if (limit != null) {
            if (offset != null &&offset>0) {
                sql += " limit "+(offset - 1) * limit+","+limit;
            }else {
                sql += " limit "+limit;
            }
        }
        return jdbcTemplate.query(completeSql,new BeanPropertyRowMapper<>(StdDictionaryEntryModel.class));
    }
    public ListEnvelop getDictionaryList(String stdVersion, String query, String order, Integer rows, Integer page) {
        try {
            List<StdDictionaryModel> stdDictionaryModelList = getList(stdVersion, query, order, rows, page);