Browse Source

自动适配字典,未适配字典bug修复

huangzhiyong 7 years ago
parent
commit
8ffa91072a

+ 3 - 3
hos-arbiter/src/main/resources/application.yml

@ -31,21 +31,21 @@ spring:
  profiles: test
  data:
    mongodb:
      host: 172.19.103.58
      host: 172.19.103.42
      port: 27017
      username: esb
      password: esb
      authenticationDatabase: admin
      database: runtime
  activemq:
    broker-url: tcp://172.19.103.58:61616
    broker-url: tcp://172.19.103.42:61616
    user: admin
    password: admin
arbiter:
  timer:
    period: 10000
  central:
    url: 172.19.103.58:9020
    url: 172.19.103.37:9020
  tenant:
    name: jkzl
---

+ 4 - 4
hos-broker/src/main/resources/application.yml

@ -65,12 +65,12 @@ hos:
spring:
  profiles: test
  activemq:
      broker-url: tcp://172.19.103.58:61616
      broker-url: tcp://172.19.103.42:61616
      user: admin
      password: admin
  data:
    mongodb:
      host: 172.19.103.58
      host: 172.19.103.42
      port: 27017
      username: esb
      password: esb
@ -89,7 +89,7 @@ log:
  level: info
hos:
  filesystem:
    url: http://172.19.103.58:9010/dfs/file
    url: http://172.19.103.37:9010/dfs/file
  arbiter:
    enable: true
    url: http://localhost:10135
@ -103,7 +103,7 @@ hos:
    path: /usr/local/mycat/   ##mycat的安装目录
  #jcraft shell操作
  jcraft:
    host: 172.19.103.58
    host: 172.19.103.37
    port: 22
    user: root
    password: ceshi

+ 1 - 1
hos-dfs/src/main/resources/application.yml

@ -25,7 +25,7 @@ spring:
  profiles: test
  data:
    mongodb:
      host: 172.19.103.58
      host: 172.19.103.42
      port: 27017
      username: esb
      password: esb

+ 1 - 1
hos-rest/src/main/resources/application.yml

@ -42,7 +42,7 @@ spring:
  profiles: test
  data:
    mongodb:
      host: 172.19.103.58
      host: 172.19.103.42
      port: 27017
      username: esb
      password: esb

+ 1 - 1
src/main/java/com/yihu/hos/standard/controller/AdapterDictController.java

@ -129,7 +129,7 @@ public class AdapterDictController extends BaseController {
                    return actionResult;
                }
            }
            dictService.strategy(version,adapter_std_version);
            dictService.strategy(version,std_version,adapter_std_version);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());

+ 15 - 7
src/main/java/com/yihu/hos/standard/dao/StdDictionaryEntryModelDao.java

@ -12,15 +12,23 @@ import java.util.List;
 * Created by Administrator on 2017/4/19 0019.
 */
@Repository("stdDictionaryEntryDao")
public class StdDictionaryEntryModelDao extends SQLGeneralDAO implements IStdDictionaryEntryModelDao  {
public class StdDictionaryEntryModelDao extends SQLGeneralDAO implements IStdDictionaryEntryModelDao {
    @Override
    public List<StdDictionaryEntryModel> getDictionaryEntry(String adapter_std_version, String orgDicEntryValue, String orgName) {
        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 '%" + orgDicEntryValue + "%' and d.name like '%" + orgName+"%'");
        Query query = getCurrentSession().createSQLQuery(sql.toString());
        query.setResultTransformer(new BeanTransformer(StdDictionaryEntryModel.class));
        List<StdDictionaryEntryModel> list = query.list();
        return list;
        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 ?");
        try {
            Query query = getCurrentSession().createSQLQuery(sql.toString());
            query.setParameter(0, "%" + orgDicEntryValue + "%");
            query.setParameter(1, "%" + orgName + "%");
            query.setResultTransformer(new BeanTransformer(StdDictionaryEntryModel.class));
            List<StdDictionaryEntryModel> list = query.list();
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("错误Dict Like SQL:" + sql.toString());
            return null;
        }
    }
}

+ 11 - 5
src/main/java/com/yihu/hos/standard/dao/StdDictionaryModelDao.java

@ -14,10 +14,16 @@ public class StdDictionaryModelDao extends SQLGeneralDAO implements IStdDictiona
    @Override
    public StdDictionaryModel getDictionaryName(String version, Integer id) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT d.*").append(" FROM std_dictionary_").append(version).append(" d where d.id ="+id);
        Query query = getCurrentSession().createSQLQuery(sql.toString());
        query.setResultTransformer(new BeanTransformer(StdDictionaryModel.class));
        StdDictionaryModel stdDictionaryModel =(StdDictionaryModel) query.uniqueResult();
        return stdDictionaryModel;
        sql.append("SELECT d.*").append(" FROM std_dictionary_").append(version).append(" d where d.id =" + id);
        try {
            Query query = getCurrentSession().createSQLQuery(sql.toString());
            query.setResultTransformer(new BeanTransformer(StdDictionaryModel.class));
            StdDictionaryModel stdDictionaryModel = (StdDictionaryModel) query.uniqueResult();
            return stdDictionaryModel;
        } catch (Exception e) {
            System.out.println("错误Dict SQL:" + sql.toString());
            e.printStackTrace();
            return null;
        }
    }
}

+ 5 - 2
src/main/java/com/yihu/hos/standard/match/dictionary/DictItemStrategyExecute.java

@ -20,6 +20,7 @@ public class DictItemStrategyExecute implements Runnable {
    private DictItemMatchVO matchVO;
    private DictitemStandardExistStrategy standardExistStrategy;
    private AdapterDictEntryModel adapterDictEntryModel;
    private String std_version;
    private String adapter_std_version;
    private String version;
    private IStdDictionaryModelDao stdDictionaryDao;
@ -31,6 +32,7 @@ public class DictItemStrategyExecute implements Runnable {
    public DictItemStrategyExecute(
            AdapterDictEntryModel adapterDictEntryModel,
            DictItemMatchVO matchVO,
            String std_version,
            String adapter_std_version,
            String version,
            IStdDictionaryModelDao stdDictionaryDao,
@ -38,6 +40,7 @@ public class DictItemStrategyExecute implements Runnable {
                    AdapterDictEntryService adapterDictEntryService) {
        this.adapterDictEntryModel = adapterDictEntryModel;
        this.matchVO = matchVO;
        this.std_version = std_version;
        this.adapter_std_version = adapter_std_version;
        this.version = version;
@ -58,7 +61,7 @@ public class DictItemStrategyExecute implements Runnable {
    public void run() {
        try {
            if (matchVO != null) {
                if (standardExistStrategy.match(adapterDictEntryModel, matchVO,adapter_std_version, version)) {
                if (standardExistStrategy.match(adapterDictEntryModel, matchVO,std_version,adapter_std_version, version)) {
                    updateAdapt(version);
                    return;
                }
@ -105,7 +108,7 @@ public class DictItemStrategyExecute implements Runnable {
    public synchronized static Map getAllNumAndAdaptNum(String version) {
        Map<String, Integer> adapt = new HashMap<String, Integer>();
        List<Integer> list = size.get(version);
        if(list!=null){
        if(list!=null && !list.isEmpty()){
            adapt.put("all", list.get(0));
            adapt.put("adapt", list.get(1));
        }

+ 17 - 2
src/main/java/com/yihu/hos/standard/match/dictionary/DictitemStandardExistStrategy.java

@ -4,10 +4,13 @@ import com.yihu.hos.standard.dao.IStdDictionaryModelDao;
import com.yihu.hos.standard.dao.StdDictionaryEntryModelDao;
import com.yihu.hos.standard.match.matchModel.DictItemMatchVO;
import com.yihu.hos.standard.model.adapter.AdapterDictEntryModel;
import com.yihu.hos.standard.model.adapter.AdapterDictModel;
import com.yihu.hos.standard.model.standard.StdDictionaryEntryModel;
import com.yihu.hos.standard.model.standard.StdDictionaryModel;
import com.yihu.hos.standard.service.adapter.AdapterDictEntryService;
import com.yihu.hos.standard.service.adapter.AdapterDictService;
import com.yihu.hos.standard.util.GetChineseFirst;
import com.yihu.hos.web.framework.util.springutil.SpringBeanUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -25,6 +28,7 @@ public class DictitemStandardExistStrategy {
    private StdDictionaryEntryModelDao stdDictionaryEntryDao;
    private AdapterDictEntryService adapterDictEntryService;
    private AdapterDictService adapterDictService;
    public DictitemStandardExistStrategy(IStdDictionaryModelDao stdDictionaryDao, StdDictionaryEntryModelDao stdDictionaryEntryDao, AdapterDictEntryService adapterDictEntryService) {
        this.stdDictionaryDao = stdDictionaryDao;
@ -62,13 +66,15 @@ public class DictitemStandardExistStrategy {
    @Transactional
    public boolean match(AdapterDictEntryModel adapterDictEntryModel, DictItemMatchVO matchVO, String adapter_std_version,String version) throws Exception {
    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) {
            Integer unAdaptDicId = adapterDictEntryModel.getStdDictId();
            StdDictionaryModel stdDictionaryModel = stdDictionaryDao.getDictionaryName(adapter_std_version,unAdaptDicId);
            StdDictionaryModel stdDictionaryModel = stdDictionaryDao.getDictionaryName(std_version,unAdaptDicId);
            StdDictionaryModel adapterDictionaryModel = stdDictionaryDao.getDictionaryName(adapter_std_version,unAdaptDicId);
            String orgName = stdDictionaryModel.getName();
            for (AdapterDictEntryModel adapterDictEntry : matchList) {
                if(adapterDictEntry.getStdEntryValue().contains(adapterDictEntryModel.getStdEntryValue())){
@ -88,6 +94,15 @@ public class DictitemStandardExistStrategy {
                    }
                }
            }
            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();
        }
        return flag;
    }

+ 31 - 2
src/main/java/com/yihu/hos/standard/service/adapter/AdapterDictService.java

@ -12,6 +12,7 @@ import com.yihu.hos.standard.model.adapter.AdapterDictEntryModel;
import com.yihu.hos.standard.model.adapter.AdapterDictModel;
import com.yihu.hos.standard.model.adapter.AdapterSchemeVersionModel;
import com.yihu.hos.standard.model.standard.StdDictionaryEntryModel;
import com.yihu.hos.standard.model.standard.StdDictionaryModel;
import com.yihu.hos.standard.service.bo.AdapterVersion;
import com.yihu.hos.standard.service.bo.StandardVersion;
import com.yihu.hos.standard.service.standard.StdDictService;
@ -200,7 +201,7 @@ public class AdapterDictService extends SQLGeneralDAO {
        Integer count = Integer.parseInt(StringUtil.toString(query.list().get(0)));
        return count;
    }
    public void strategy(String version, String adapter_std_version) {
    public void strategy(String version,String std_version, String adapter_std_version) {
        List<AdapterDictEntryModel> unAdapterDictEntryModels= adapterDictEntryService.getAllUnAdaptDictEntry(version);//等待适配的标准字典项
        List<AdapterDictEntryModel> adapterDictEntryModels = new ArrayList<AdapterDictEntryModel>();//之前已经适配好的适配方案
        //查找出  之前已经适配好的适配方案
@ -229,7 +230,35 @@ public class AdapterDictService extends SQLGeneralDAO {
        DictItemStrategyExecute.setFirst(version, unAdapterDictEntryModels.size());//设置第一次匹配
        for (AdapterDictEntryModel unAdapterDictEntryModel : unAdapterDictEntryModels) {
            threadPoolTaskExecutor.execute(new DictItemStrategyExecute(unAdapterDictEntryModel, matchVO,adapter_std_version,version, stdDictionaryDao, stdDictionaryEntryDao,adapterDictEntryService));
            threadPoolTaskExecutor.execute(new DictItemStrategyExecute(unAdapterDictEntryModel, matchVO,std_version,adapter_std_version,version, stdDictionaryDao, stdDictionaryEntryDao,adapterDictEntryService));
        }
    }
    public void saveAdaptDict(AdapterDictModel strategyDict,StdDictionaryModel orgDict,String version) throws Exception {
        strategyDict.setAdapterDictId(orgDict.getId());
        strategyDict.setAdapterDictCode(orgDict.getCode());
        strategyDict.setAdapterDictName(orgDict.getName());
        JsonNode jsonNode = objectMapper.readTree(objectMapper.writeValueAsString(strategyDict));
        SqlCreator sqlCreator = new SqlCreator(AdapterDictModel.class);
        String sql = sqlCreator.updateDataByTableKey(new AdapterVersion(version).getDictTableName(), jsonNode);
        Query query = getExeuteQuery(sqlCreator, sql);
        query.executeUpdate();
    }
    public AdapterDictModel getAdapterDictByCode(String version, String dictCode) {
        try {
            if (StringUtil.isEmpty(dictCode)) {
                return null;
            }
            SqlCreator sqlCreator = new SqlCreator(AdapterDictModel.class);
            sqlCreator.equalCondition("stdDictCode", dictCode);
            String sql = sqlCreator.selectData("adapter_dict_" + version);
            Query query = getQuery(sqlCreator, sql);
            return (AdapterDictModel) query.uniqueResult();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

+ 5 - 5
src/main/resources/application.yml

@ -72,7 +72,7 @@ spring:
  #SAAS管理员账号,暂时配置在此处
  datasource:
      driverClassName: com.mysql.jdbc.Driver
      url: jdbc:mysql://172.19.103.57:8066/global_db?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
      url: jdbc:mysql://172.19.103.42:8066/global_db?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
      username: hos
      password: 123456
      test-on-borrow: true
@ -91,7 +91,7 @@ spring:
    show-sql: false
  data:
    mongodb:
      host: 172.19.103.57
      host: 172.19.103.42
      port: 27017
      username: esb
      password: esb
@ -102,12 +102,12 @@ spring:
    proxy-target-class: true
hos:
  zbus:
    url: 172.19.103.57:9020
    url: 172.19.103.37:9020
  filesystem:
    url: http://172.19.103.57:9010/dfs/file
    url: http://172.19.103.37:9010/dfs/file
  mysql:
    filePath: /usr/local/esb/esb.sql   #租户基础表 sql文件位置
service-gateway:
  portalUrl: http://192.168.1.221:10280/api/v1.0/portal
  adminUrl: http://192.168.1.221:10000/api/v1.0/admin
  url: http://172.19.103.70:9999/api
  url: http://172.19.103.37:9999/api