微服务SaaS平台

来自ling
跳转至: 导航搜索

文档

文件:181005 IIT Reform 需求清单及状态跟踪.xlsx

常用链接

http://tmslnxdev2.ling2.cn:8500/iit/ http://localhost:8500/iit/ http://tmslnxdev1.ling2.cn/jenkins/
http://tmslnxdev1.ling2.cn/gitlab/ 用户:	root/Tax!23456

maven settings.xml

dtt_cloud_settings.xml

服务器配置

1、开发服务器 tmslnxdev1, ip为47.99.166.187 使用deloitte.pem免密ssh登录


2、代码版本管控服务器gitlab: 地址:http://tmslnxdev1/gitlab/ 用户: root/Tax!23456

3、私有的nexus3管理工具: http://tmslnxdev1:8081/ 用户: admin/Tax.123456 tmsuser/Tms_123456

4、jenkins发布工具:http://tmslnxdev1:8080/ 用户:admin/Tax.123456 developer/Dev_123456


开发设置说明

1、开发服务器tmslnxdev1.ling2.cn, ip为47.99.166.187
上面运行docker服务:
	gitlab, jenkins2, activemq, postgres10, mongodb3, redis4, rocketmq4.3等项目所需要的镜像
在本机的hosts文件(c:\windows\system32\drivers\etc\hosts)里加上解析:
47.99.166.187	tmslnxdev1.ling2.cn
47.99.158.165 	tmslnxdev2.ling2.cn


2、maven的setting.xml使用附件,新增了私有的nexus3管理工具: http://tmslnxdev1.ling2.cn:8081/
 把 <localRepository>/Users/duyj/.m2/repository</localRepository> 替换为当前用户的路径
 

3、代码版本管控服务器gitlab:
地址:http://tmslnxdev1.ling2.cn/gitlab/

4、项目开发IDE:
	1) 前端:tms-portal使用visual studio code
		下载地址:https://code.visualstudio.com/
		安装angular 6 snippets、ng-zorro snippets, ng-alain snippets, TSLint等扩展插件
	2)后端:Eclipse Oxygen/Photon
		安装Git、Sonar等插件
	3) 数据库管理工具dbeaver
		下载地址:https://dbeaver.io/download/
		
5、tms-portal基于Angular 6开发
	1) 安装 Node.js 和 npm: https://nodejs.org/en/download/
	2)安装Angular CLI: npm install -g @angular/cli
	3) 项目基于开源的ng-alain脚手架搭建,基于NG-ZORRO-ANTD前端框架
	   ng-alain文档说明: https://ng-alain.com/zh
	   ng-alian的demo样例:https://ng-alain.github.io/ng-alain/#/dashboard/v1
	   demo样例的源码:https://github.com/cipchk/ng-alain.git
	   NG-ZORRO-ANTD前端框架介绍:https://ant.design/docs/react/introduce-cn
	4)通过git获取项目源码:
		cd workspace目录
		git clone http://tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-portal.git tms-portal
	5) 初始化安装node组件,参考备注信息
		cd tms-portal
		npm install
	6)启动项目:
		ng serve
	7) 本地浏览器访问 http://localhost:4200
	
	备注:如果npm install比较慢,可以使用更快的其他数据源:
		1、先安装nrm: npm install nrm
		2、nrm ls可以查看npm的数据源,通过nrm use xxx进行切换
		3、nrm use taobao
		4、npm install
	
	
		   
6、jenkins发布工具:http://tmslnxdev1.ling2.cn/jenkins
	用户:developer/Dev_123456
	
	

建模和前后端接口规范.

项目git

git init 脚本

#git用户名和邮箱配置
#git config --global user.name "xxxx"
#git config --global user.email "xxx@deloitte.com.cn"

git clone http://tmslnxdev1/gitlab/tmsdev/tms-api-interface.git
cd tms.framework.config.repository
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master


cd existing_folder
git init
git remote add origin http://tmslnxdev1/gitlab/tmsdev/tms-api-interface.git
git add .
git commit -m "Initial commit"
git push -u origin master


cd existing_repo
git remote rename origin old-origin
git remote add origin http://tmslnxdev1/gitlab/tmsdev/tms-api-interface.git
git push -u origin --all
git push -u origin --tags
git config --global user.name "jasonbwang"
git config --global user.email "jasonbwang@deloitte.com.cn"

代码获取

内网注意配置git的代理

#---------- 微服务基础能力框架 begin--------------#
#微服务配置中心-git repository
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-config-repository.git

#微服务配置服务
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-config-service.git

#微服务注册及监控中心
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-discovery-service.git
#---------- 微服务基础能力框架 end--------------#




#---------- 微服务TMS框架 begin--------------#
#微服务TMS框架-核心库
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-core-lib.git

#微服务TMS框架-单元测试
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-core-test.git

#微服务TMS框架-分布式日志服务
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-log-service.git

#微服务TMS框架-WebSocket消息服务
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-websocket-service.git

#微服务TMS框架-核心服务
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-core-service.git
#---------- 微服务TMS框架 end--------------#




#---------- 微服务TMS业务模块 begin--------------#
#微服务TMS业务模块-基础服务接口
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-base-interface.git

#微服务TMS业务模块-基础服务实现
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-base-service.git

#微服务TMS业务模块-API服务接口
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-api-interface.git

#微服务TMS业务模块-API服务实现
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-api-service.git
#---------- 微服务TMS业务模块 end--------------#



#---------- 微服务SasS云平台 begin--------------#
#微服务SasS云平台-Portal
http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-portal.git
#---------- 微服务SasS云平台 end--------------#

http://tmslnxdev1/gitlab/tmsdev/HibernateTools.git
git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-config-repository.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-config-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-discovery-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-core-lib.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-core-test.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-log-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-websocket-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-core-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-base-interface.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-base-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-api-interface.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-api-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-portal.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-iit-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-iit-interface.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/HibernateTools.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-design.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-file-interface.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-sso-service.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmsdev/tms-quartz-interface.git

git clone http://jason:Dtt!23456789@tmslnxdev1.ling2.cn/gitlab/tmscore/tms-websocket-service.git

ng-alain

参考ng-alain

安装基础组件

nodejs(不能安装cnpm)

nogejs https://nodejs.org/en/download/ 更多参考Linux下使用淘宝镜像安装nodejs和npm NODE_HOME=D:\server\nodejs8.12.0 Cnpm替换npm 搭建kafka源码环境

NODE_HOME=D:\server\nodejs8.12.0
--NPM_CHECK_INSTALLER=cnpm

PATH

%NODE_HOME%;
%NODE_HOME%\node_global\node_modules\cnpm\bin
%NODE_HOME%\node_global
npm config set cache "D:\server\nodejs8.12.0\node_cache"
npm config set prefix "D:\server\nodejs8.12.0\node_global"
npm config ls

npm install -g cnpm --registry=https://registry.npm.taobao.org

npm install -g yarn
npm install -g nrm
nrm ls #可以查看npm的数据源,通过nrm use xxx进行切换
nrm use taobao
npm install
npm config set registry https://registry.npm.taobao.org
npm config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass
yarn config set registry https://registry.npm.taobao.org
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass
npm uninstall cnpm -g
  1. 恢复
yarn config delete registry
yarn config delete sass_binary_site
npm config delete registry
npm config delete sass_binary_site

networkEnv

在国内使用 npm 或 yarn 始终是一个“痛”,因此你可以增加一个使用淘宝镜像配置文件 .npmrc 或 .yarnrc,来解决网络问题。

ng g ng-alain:plugin networkEnv -packageManager=npm
ng g ng-alain:plugin networkEnv -packageManager=yarn
ng g ng-alain:plugin networkEnv -packageManager=npm -t=remove
ng g ng-alain:plugin networkEnv -packageManager=yarn -t=remove

Linux

alias cnpm="npm --registry=https://registry.npm.taobao.org --cache=$HOME/.npm/.cache/cnpm --disturl=https://npm.taobao.org/dist --userconfig=$HOME/.cnpmrc"

node -v

使用 cnpm 安装依赖包,会遇到无法找到样式文件。这是由于 cnpm 采用的是软链接路径形式,导致 ng-zorro-antd 文件夹名有所变动,因此建议改用 npm 安装依赖包。

npm install -g @angular/cli
npm install -g ng-alain@next

tms-portal

d:
cd D:\workspace\source\tms
ng new tms-portal --style less
cd tms-portal
ng add ng-alain@next
ng g ng-alain:plugin hmr
ng serve


git config --global user.name "bo.wang"
git config --global user.email "102010cncger@sina.com"
git init
git remote add origin https://gitee.com/ling2/tms-portal.git

错误解决

Could not find module "ng-alain" from

不安装cnpm 注意当环境变量中当前用户的path中的参数.

删除cnpm后 'cnpm' 不是内部或外部命令

修改 C:\Users\bo.wang\.angular-cli.json 中packageManager为npm

hql备份

/******************* bo.wang begin **************************/
	protected Session getSession() {
		// 事务必须是开启的(Required),否则获取不到
		// Session session=sessionFactory.getCurrentSession();
		// return session;
		Session session = (Session) getSessionFactory().getCurrentSession();
		return session;

	}

	/**
	 * @param queryString
	 * @param values
	 * @return
	 */
	public List find(final String queryString, final Map values) {
		Assert.hasText(queryString);
		Assert.notNull(values);
		Assert.notEmpty(values);

		List mapParams = new ArrayList();
		List mapValues = new ArrayList();
		for (Iterator iter = values.keySet().iterator(); iter.hasNext();) {
			String key = (String) iter.next();
			Object value = values.get(key);
			mapParams.add(key);
			mapValues.add(value);
		}
		return this.findByNamedParam(queryString, (String[]) mapParams.toArray(new String[0]), mapValues.toArray());
	}

	/**
	 * @param queryString
	 * @param paramNames
	 * @param values
	 * @return
	 */
	public List findByNamedParam(String queryString, String[] paramNames, Object[] values) {
		List paramArray = new ArrayList();
		List paramValue = new ArrayList();
		for (int i = 0; i < values.length; i++) {
			if (values[i] instanceof Collection) {
				Collection c = (Collection) values[i];
				if (c.size() > 1000) {
					paramArray.clear();
					paramValue.clear();
					queryString = splitCollection(queryString, paramNames, values, i, paramArray, paramValue);
					paramNames = (String[]) paramArray.toArray(new String[0]);
					values = paramValue.toArray();
				}
			}
		}
		Session session = getSession();
		Query queryObject = session.createQuery(queryString);
		if (values != null) {
			for (int i = 0; i < values.length; i++) {
				applyNamedParameterToQuery(queryObject, paramNames[i], values[i]);
			}
		}
		return queryObject.list();
	}

	/**
	 * 如果有超过1000条记录,分割之
	 *
	 * @param queryString
	 * @param paramNames
	 * @param values
	 * @param i
	 * @param paramArray
	 * @param paramValue
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String splitCollection(String queryString, String[] paramNames, Object[] values, int i, List paramArray,
			List paramValue) {
		StringBuffer query = new StringBuffer();
		for (int k = 0; k < i; k++) {
			paramArray.add(paramNames[k]);
			paramValue.add(values[k]);
		}
		String paramName = paramNames[i];
		Collection value = (Collection) values[i];
		List list = new ArrayList(value);

		double f = value.size() / 1000.0;
		if (value.size() % 1000 == 0) {
			f = value.size() / 1000;
		} else {
			f = f > 1 ? f + 1 : f;
		}

		int length = new Double(f).intValue();
		if (length > 1) {
			// (where/and deptid in (:deptid))
			// where trim(riskClass.classCode) in (:classCode)
			int index = queryString.indexOf(":" + paramName);
			int startIndex = queryString.lastIndexOf("and", index);
			int w = queryString.lastIndexOf("where", index);
			if (startIndex < 0 || w > startIndex) {
				startIndex = w + 5;
			} else {
				startIndex = startIndex + 3;
			}

			int endIndex = queryString.indexOf(' ', index);
			endIndex = endIndex < 0 ? queryString.length() : endIndex;
			if (queryString.charAt(index - 1) == '(') {
				int k = index + paramName.length() + 2;
				if (k < endIndex) {
					endIndex = k;
				}
			}

			query.append(queryString.substring(0, startIndex)).append(" (");
			String repeat = queryString.substring(startIndex, endIndex);
			// int k = repeat.indexOf(paramName) + paramName.length();
			int k = repeat.indexOf(":" + paramName) + paramName.length() + 1;
			for (int j = 0; j < length - 1; j++) {
				query.append(repeat.substring(0, k)).append(j);
				query.append(repeat.substring(k));
				query.append(" or ");
				paramArray.add(paramName + j);
				value = list.subList(j * 1000, j * 1000 + 1000);
				paramValue.add(value);
			}
			query.append(repeat.substring(0, k));
			query.append(length - 1).append(repeat.substring(k));
			query.append(") ").append(queryString.substring(endIndex));
			paramArray.add(paramName + (length - 1));
			value = list.subList((length - 1) * 1000, list.size());
			paramValue.add(value);

			queryString = query.toString();
		}
		for (int k = i + 1; k < values.length; k++) {
			paramArray.add(paramNames[k]);
			paramValue.add(values[k]);
		}
		return queryString;
	}

	protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value)
			throws HibernateException {

		buildParam(queryObject, paramName, value);
	}

	private void buildParam(Query queryObject, String key, Object value) {
		if (value instanceof Collection) {
			queryObject.setParameterList(key, (Collection) value);
		} else if (value instanceof Object[]) {
			queryObject.setParameterList(key, (Object[]) value);
		} else {
			queryObject.setParameter(key, value);
		}
	}

	/**
	 * 分页查询
	 * 
	 * @param query
	 * @param values
	 * @param pageIndex
	 * @param pageSize
	 * @return
	 */
	public PageResult pageBy(final StringBuffer query, final Map<String, Object> values, final Integer pageIndex,
			final Integer pageSize) {
		Assert.notNull(query);
		String queryString = query.toString();
		Assert.hasText(queryString);

		String queryCountString = "select count(*) " + removeSelect(queryString);
		queryCountString = removeOrders(queryCountString);

		StringBuffer queryCount = new StringBuffer();
		queryCount.append(queryCountString);
		return pageBy(query, queryCount, values, pageIndex, pageSize);
	}

	protected PageResult pageBy(StringBuffer query, StringBuffer queryCount, final Map<String, Object> values,
			final int pageIndex, final int pageSize) {
		Assert.notNull(query);
		Assert.notNull(queryCount);

		final String queryString = query.toString();
		final String queryCountString = queryCount.toString();

		Assert.hasText(queryString);
		Assert.hasText(queryCountString);
		Session session = getSession();
		Query hibernateQuery = session.createQuery(queryString);
		Query hibernateQueryCount = session.createQuery(queryCountString);
		for (Iterator iter = values.keySet().iterator(); iter.hasNext();) {
			String key = (String) iter.next();
			Object value = values.get(key);

			if (value instanceof Collection) {
				hibernateQuery.setParameterList(key, (Collection) value);
				hibernateQueryCount.setParameterList(key, (Collection) value);
			} else if (value instanceof Object[]) {
				hibernateQuery.setParameterList(key, (Object[]) value);
				hibernateQueryCount.setParameterList(key, (Object[]) value);
			} else {
				hibernateQuery.setParameter(key, value);
				hibernateQueryCount.setParameter(key, value);
			}
		}
		int recordCount = 0;
		Object o = hibernateQueryCount.uniqueResult();
		if (null != o) {
			recordCount = ((Number) o).intValue();
		}
		List result = hibernateQuery.setFirstResult(getRecordIndex(pageIndex, pageSize)).setMaxResults(pageSize).list();
		return new PageResult(recordCount, result, pageIndex, pageSize);
	}

	/**
	 * 根据每页记录数和当前页页数返回当前页首条在数据库里的位置
	 *
	 * @param pageIndex
	 * @param pageSize
	 * @return
	 * @author dada
	 */
	public static int getRecordIndex(int pageIndex, int pageSize) {
		return (pageIndex - 1) * pageSize;
	}

	public static String removeOrders(String queryString) {
		Pattern pattern = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(queryString);
		StringBuffer stringBuffer = new StringBuffer();
		while (matcher.find()) {
			matcher.appendReplacement(stringBuffer, "");
		}
		matcher.appendTail(stringBuffer);
		return stringBuffer.toString();
	}

	/**
	 * <pre>
	 * 去除HQL语句前的select部分,用来生成查询总记录条数的HQL语句。
	 *
	 * <strong>程序范例:</strong>
	 * String queryCountString = "select count(*) " + HqlUtils.removeSelect(queryString);
	 *
	 * </pre>
	 *
	 * @param queryString
	 * @return
	 * @author dada
	 */
	public static String removeSelect(String queryString) {
		Assert.notNull(queryString);
		queryString = removeFetch(queryString);
		int beginPos = queryString.toLowerCase().indexOf("from");
		Assert.isTrue(beginPos != -1, " the hql : " + queryString + " must has a keyword 'from'");
		return queryString.substring(beginPos);
	}

	/**
	 * <pre>
	 * 去除HQL语句内的fetch部分
	 *
	 * <strong>程序范例:</strong>
	 * queryString = removeFetch(queryString);
	 *
	 * </pre>
	 *
	 * @param queryString
	 * @return
	 * @author dada
	 */
	public static String removeFetch(String queryString) {
		Assert.notNull(queryString);
		return StringUtils.remove(queryString, " fetch");
	}
	/******************* bo.wang end **************************/