java版代码生成器

之前实现的JRT代码生成器是M版的,那么用户必须用M库才能有代码生成器的功能。为了提供给就是不用M库的用户使用,JRT再提供脚本版的java代码生成器,方便直接连关系库生成JRT的代码。

实现:

import JRT.Core.MultiPlatform.JRTContext;
import JRTBLLBase.BaseHttpHandlerNoSession;
import JRTBLLBase.Helper;import java.io.File;
import java.nio.file.Paths;
import java.util.List;/*** 基于当前连接的数据库生成全部表或者指定表的代码供开发使用,从而减少开发工作量* 所有数据库都可以基于此代码生成器生成JRT业务代码,不同库如果查表结构有差异,调整查询sql即可* JRT连的哪个数据库,执行逻辑就是针对的哪个数据库,由于关系库把表名称大小写丢失了,约定表说明用英文冒号分割第一位有东西就用那个名字当实体名称,* 否则就按小写的表名生成代码*/
public class JRTGenerateCode extends BaseHttpHandlerNoSession {/*** 生成所有表的代码到D:\\JRTCode** @return*/public String GenerateAllTable() throws Exception {//查询所有表的sql,不同数据库的拷贝或者修改这个sql,只要输出名称符合约定即可String qryTableSql = "SELECT table_name \"TableName\"  FROM information_schema.tables where table_schema='dbo'";//查询所有表List<JRTGenerateCodeColDto> tableList = EntityManager().FindListBySqlAll(JRTGenerateCodeColDto.class, qryTableSql, null, -1, -1);//为每个表生成代码for (JRTGenerateCodeColDto one : tableList) {CollectTableInfoAndGenerate(one.TableName);}return "完成";}/*** 生成一个表的代码到D:\\JRTCode,Url请求通过Name传入不带模式的表名称** @return*/public String GenerateOneTable() throws Exception {String tableName = Helper.ValidParam(JRTContext.GetRequest(Request, "Name"), "");if (tableName.isEmpty()) {return "请传入表名属性Name";}CollectTableInfoAndGenerate(tableName);return "完成";}/*** 搜集表的信息并且执行编译** @param tableName 表名称*/private void CollectTableInfoAndGenerate(String tableName) throws Exception {List<JRTGenerateCodeColDto> colList = GetTableInfo(tableName);MakeCode(colList);}/*** 搜集表的信息** @param tableName 表名称*/private List<JRTGenerateCodeColDto> GetTableInfo(String tableName) throws Exception {//查询外键信息的sql,不同数据库的拷贝或者修改这个sql,只要输出名称符合约定即可String qryFkRefSql = "SELECT \n" +"    a.table_name AS \"TableName\",\n" +"    b.column_name AS \"ColName\",\n" +"    c.table_name AS \"RefTableName\",\n" +"    c.column_name AS \"RefColName\" \n" +"FROM\n" +" information_schema.table_constraints a\n" +"INNER JOIN information_schema.key_column_usage AS b ON a.constraint_name = b.constraint_name AND a.constraint_schema = b.constraint_schema AND a.table_name = b.table_name\n" +"INNER JOIN information_schema.constraint_column_usage AS c ON c.constraint_name = a.constraint_name AND a.constraint_schema = c.constraint_schema\n" +"WHERE a.constraint_type = 'FOREIGN KEY' AND a.table_name = '" + tableName + "' AND a.constraint_schema = 'dbo'";//查询表和列信息的sql,不同数据库的拷贝或者修改这个sql,只要输出名称符合约定即可。由于表明都是小写,约定实体名在表说明用:分割第一位,否则就用原生表名生成实体类String qryTableColSql = "select\n" +"\tc.relname \"TableName\",\n" +"\tcast (\n" +"\t\tobj_description (relfilenode, 'pg_class') as varchar\n" +"\t) \"TableRemark\",\n" +"\ta.attname \"ColName\",\n" +"\td.description \"ColRemark\",\n" +"\tconcat_ws (\n" +"\t\t'',\n" +"\t\tt.typname,\n" +"\t\tSUBSTRING (\n" +"\t\t\tformat_type (a.atttypid, a.atttypmod)\n" +"\t\t\tfrom\n" +"\t\t\t\t'\\(.*\\)'\n" +"\t\t)\n" +"\t) as \"ColType\",attnotnull \"NotNull\"\n" +"from\n" +"\tpg_class c,\n" +"\tpg_attribute a,\n" +"\tpg_type t,\n" +"\tpg_description d\n" +"where\n" +"\ta.attnum > 0\n" +"and a.attrelid = c.oid\n" +"and a.atttypid = t.oid\n" +"and d.objoid = a.attrelid\n" +"and d.objsubid = a.attnum\n" +"and c.relname in (\n" +"\tselect\n" +"\t\ttablename\n" +"\tfrom\n" +"\t\tpg_tables\n" +"\twhere\n" +"\t\tschemaname = 'dbo'\n" +"\tand position ('_2' in tablename) = 0\n" +")\n" +"and c.relname='" + tableName + "'\n" +"order by\n" +"\tc.relname,\n" +"\ta.attnum\n";//得到参照信息List<JRTGenerateCodeFkRefDto> refList = EntityManager().FindListBySqlAll(JRTGenerateCodeFkRefDto.class, qryFkRefSql, null, -1, -1);//得到表的列信息List<JRTGenerateCodeColDto> colList = EntityManager().FindListBySqlAll(JRTGenerateCodeColDto.class, qryTableColSql, null, -1, -1);for (JRTGenerateCodeColDto one : colList) {if (one.ColRemark.isEmpty()) {one.ColRemark = one.ColName;}DealType(one);//把参照信息并入列信息if (refList != null && refList.size() > 0) {for (JRTGenerateCodeFkRefDto r : refList) {if (one.ColName.equals(r.ColName)) {one.RefTableName = r.RefTableName;one.RefColName = r.RefColName;}}}}return colList;}/*** 通过表的列信息生成代码** @param colList 表的列信息*/private void MakeCode(List<JRTGenerateCodeColDto> colList) throws Exception {//生成代码的根地址String basePath = "D:\\JRTCode";File base = new File(basePath);//没有就创建if (!base.exists()) {base.mkdir();}//生成实体代码MakeModelCode(colList, basePath);//生成业务代码MakeBllCode(colList, basePath);//生成界面代码MakeAspxCode(colList, basePath);}/*** 生成实体代码** @param colList  表信息* @param basePath 根地址*/private void MakeModelCode(List<JRTGenerateCodeColDto> colList, String basePath) throws Exception {System.out.println("生成实体代码");StringBuilder sb = new StringBuilder();String modelName = colList.get(0).ModelName;sb.append("package JRT.Model.Entity;" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("import JRT.Core.CustomAttributes.*;" + System.lineSeparator());sb.append("import JRT.Core.JsonAttributes.*;" + System.lineSeparator());sb.append("import com.fasterxml.jackson.databind.annotation.JsonDeserialize;" + System.lineSeparator());sb.append("import com.fasterxml.jackson.databind.annotation.JsonSerialize;" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("/**" + System.lineSeparator());sb.append("*[功能描述:本代码由LIS内部代码生成工具生成,请不要手动修改,如要修改,请写修改变更记录]" + System.lineSeparator());sb.append("*[创建者:JRT.Entity生成器]" + System.lineSeparator());sb.append("*/" + System.lineSeparator());String rowIDCol = "";for (JRTGenerateCodeColDto c : colList) {if (rowIDCol.isEmpty()) {rowIDCol = c.ColName;sb.append("@UniqueAttribute(ColNames = \"" + rowIDCol + "\")" + System.lineSeparator());sb.append("@TableAttribute(Name=\"dbo." + c.TableName + "\")" + System.lineSeparator());sb.append("public class " + modelName + System.lineSeparator());sb.append("{" + System.lineSeparator());}sb.append("	/**" + System.lineSeparator());sb.append("	* " + c.ColRemark + System.lineSeparator());sb.append("	*/" + System.lineSeparator());//非空特性if (c.NotNull == true) {sb.append("	@NotNullAttribute" + System.lineSeparator());}//主键特性if (c.ColName.equals(rowIDCol)) {sb.append("	@IdAttribute(Name = \"" + rowIDCol + "\")" + System.lineSeparator());}//日期if (c.ColName.length() > 4 && c.ColName.substring(c.ColName.length() - 4, c.ColName.length() - 1).equals("Date")) {sb.append("	@JsonSerialize(using = JRTDateSerializer.class)" + System.lineSeparator());sb.append("	@JsonDeserialize(using = JRTDateDeserializer.class)" + System.lineSeparator());sb.append("	@DateAttribute" + System.lineSeparator());}//时间if (c.ColName.length() > 4 && c.ColName.substring(c.ColName.length() - 4, c.ColName.length() - 1).equals("Time")) {sb.append("	@JsonSerialize(using = JRTTimeSerializer.class)" + System.lineSeparator());sb.append("	@JsonDeserialize(using = JRTTimeDeserializer.class)" + System.lineSeparator());sb.append("	@TimeAttribute" + System.lineSeparator());}//外键参照if (c.RefTableName != null && !c.RefTableName.isEmpty()) {String associaField = GetAssociaField(c.RefTableName);sb.append("	@FrekeyAttribute(Name = \"" + associaField.split("\\^")[0] + "\", RefColumnName = \"" + c.RefColName + "\", AssociaField = \"" + associaField.split("\\^")[1] + "\")" + System.lineSeparator());}//长度特性if (c.Len != null) {sb.append("	@LengthAttribute(MaxLen = " + c.Len + ")" + System.lineSeparator());}sb.append("	public " + c.JavaType + " " + c.ColName + ";" + System.lineSeparator());sb.append("" + System.lineSeparator());}sb.append("}" + System.lineSeparator());String saveName = Paths.get(basePath, modelName + ".java").toString();System.out.println("生成实体代码到:" + saveName);JRT.Core.Util.TxtUtil.WriteText2File(saveName, sb.toString());}/*** 得到拉取的字段** @param tableName* @return* @throws Exception*/private String GetAssociaField(String tableName) throws Exception {List<JRTGenerateCodeColDto> colList = GetTableInfo(tableName);String refTabelName = colList.get(0).ModelName;String ret = "";int curLev = 0;for (JRTGenerateCodeColDto c : colList) {if (ret.isEmpty()) {ret = c.ColName;}int lev = 0;if (c.ColName.equals("CName")) {lev = 999;} else if (c.ColName.equals("IName")) {lev = 99;} else if (c.ColName.equals("XName")) {lev = 99;}if (lev > curLev) {curLev = lev;ret = c.ColName;}}return refTabelName + "^" + ret;}/*** 生成后台代码** @param colList  表信息* @param basePath 根地址*/private void MakeBllCode(List<JRTGenerateCodeColDto> colList, String basePath) throws Exception {System.out.println("生成业务代码");StringBuilder sb = new StringBuilder();String modelName = colList.get(0).ModelName;sb.append("import JRTBLLBase.BaseHttpHandlerNoSession;" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("import JRTBLLBase.Helper;" + System.lineSeparator());sb.append("import JRT.Core.Dto.HashParam;" + System.lineSeparator());sb.append("import JRT.Core.Dto.ParamDto;" + System.lineSeparator());sb.append("import JRT.Core.Dto.OutParam;" + System.lineSeparator());sb.append("import JRT.Model.Entity.*;" + System.lineSeparator());sb.append("import JRT.Core.Util.Convert;" + System.lineSeparator());sb.append("import JRT.Core.MultiPlatform.JRTContext;" + System.lineSeparator());sb.append("import java.util.ArrayList;" + System.lineSeparator());sb.append("import java.util.List;" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("/**" + System.lineSeparator());sb.append("*由代码生成器生成的后台代码" + System.lineSeparator());sb.append("*/" + System.lineSeparator());sb.append("public class ash" + modelName + " extends BaseHttpHandlerNoSession {" + System.lineSeparator());//构造增加方法的代码sb.append("" + System.lineSeparator());sb.append("	/**" + System.lineSeparator());sb.append("	 * 保存数据,前台按表的属性名提交" + System.lineSeparator());sb.append("	 * @return 字符串" + System.lineSeparator());sb.append("	 */" + System.lineSeparator());sb.append("	public String Save" + modelName + "() throws Exception" + System.lineSeparator());sb.append("    {" + System.lineSeparator());sb.append("		" + modelName + " dto=new " + modelName + "();" + System.lineSeparator());String rowIDCol = "";for (JRTGenerateCodeColDto c : colList) {if (rowIDCol.isEmpty()) {rowIDCol = c.ColName;}sb.append("		//" + c.ColRemark + System.lineSeparator());sb.append("		dto." + c.ColName + "=Helper.ValidParam(JRTContext.GetRequest(Request, \"" + c.ColName + "\"), dto." + c.ColName + ");" + System.lineSeparator());}sb.append("		OutParam out=new OutParam();" + System.lineSeparator());sb.append("		int ret=0;" + System.lineSeparator());sb.append("		//更新" + System.lineSeparator());sb.append("		if(dto." + rowIDCol + ">0)" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			ret=EntityManager().Update(dto,null, out, null, null, null);" + System.lineSeparator());sb.append("		}" + System.lineSeparator());sb.append("		//插入数据" + System.lineSeparator());sb.append("		else" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			ret=EntityManager().Save(dto,out);" + System.lineSeparator());sb.append("		}" + System.lineSeparator());sb.append("		if(ret==1)" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			return Helper.Success();" + System.lineSeparator());sb.append("		}" + System.lineSeparator());sb.append("		else" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			return Helper.Error(out);" + System.lineSeparator());sb.append("		}" + System.lineSeparator());sb.append("    }" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());//构造删除方法sb.append("	/**" + System.lineSeparator());sb.append("	 * 删除数据,多个RowID以上尖号分割" + System.lineSeparator());sb.append("	 * @return 字符串" + System.lineSeparator());sb.append("	 */" + System.lineSeparator());sb.append("	public String Delete" + modelName + "() throws Exception" + System.lineSeparator());sb.append("    {" + System.lineSeparator());sb.append("		String RowIDS=Helper.ValidParam(JRTContext.GetRequest(Request, \"RowIDS\"), \"\");" + System.lineSeparator());sb.append("		if(RowIDS.isEmpty())" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			return Helper.Error(\"请传入要删除数据的RowID,多个以^分割!\");" + System.lineSeparator());sb.append("		}" + System.lineSeparator());sb.append("		//分割主键" + System.lineSeparator());sb.append("		String [] arr=RowIDS.split(\"^\");" + System.lineSeparator());sb.append("		//out参数" + System.lineSeparator());sb.append("		OutParam out=new OutParam();" + System.lineSeparator());sb.append("		//循环删除数据" + System.lineSeparator());sb.append("		for(int i=0;i<arr.length;i++)" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			int ret=EntityManager().RemoveById(" + modelName + ".class,Convert.ToInt32(arr[i]),out);" + System.lineSeparator());sb.append("			if(ret!=1)" + System.lineSeparator());sb.append("			{" + System.lineSeparator());sb.append("				return Helper.Error(out);" + System.lineSeparator());sb.append("			}" + System.lineSeparator());sb.append("		}" + System.lineSeparator());sb.append("		return Helper.Success();" + System.lineSeparator());sb.append("	}" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());//构造查询方法的代码sb.append("" + System.lineSeparator());sb.append("	/**" + System.lineSeparator());sb.append("	 * 查询数据,前台按表的属性名提交" + System.lineSeparator());sb.append("	 * @return 字符串" + System.lineSeparator());sb.append("	 */" + System.lineSeparator());sb.append("	public String Qry" + modelName + "() throws Exception" + System.lineSeparator());sb.append("    {" + System.lineSeparator());sb.append("		//预留的取前台参数代码" + System.lineSeparator());sb.append("		//参数" + System.lineSeparator());sb.append("		List<ParamDto> para=new ArrayList<>();" + System.lineSeparator());sb.append("		//sql连接符号" + System.lineSeparator());sb.append("		List<String> joiner=new ArrayList<>();" + System.lineSeparator());sb.append("		//sql比较符号" + System.lineSeparator());sb.append("		List<String> operators=new ArrayList<>();" + System.lineSeparator());sb.append("		//模糊查询" + System.lineSeparator());sb.append("		String Filter=Helper.ValidParam(JRTContext.GetRequest(Request, \"Filter\"), \"\");" + System.lineSeparator());sb.append("		//预留参数" + System.lineSeparator());for (JRTGenerateCodeColDto c : colList) {sb.append("		//" + c.ColRemark + System.lineSeparator());sb.append("		dto." + c.ColName + "=Helper.ValidParam(JRTContext.GetRequest(Request, \"" + c.ColName + "\"), dto." + c.ColName + ");" + System.lineSeparator());}sb.append("		//模糊查询" + System.lineSeparator());sb.append("		if(!Filter.isEmpty())" + System.lineSeparator());sb.append("		{" + System.lineSeparator());sb.append("			ParamDto p=null;" + System.lineSeparator());for (JRTGenerateCodeColDto c : colList) {if (!c.JavaType.equals("String")) {continue;}sb.append("			//" + c.ColRemark + System.lineSeparator());sb.append("			p=new ParamDto();" + System.lineSeparator());sb.append("			p.Key=\"" + c.ColName + "\";" + System.lineSeparator());sb.append("			p.Value=\"%\"+Filter+\"%\";" + System.lineSeparator());sb.append("			para.add(p);" + System.lineSeparator());sb.append("			joiner.add(\"or\");" + System.lineSeparator());sb.append("			operators.add(\"like\");" + System.lineSeparator());}sb.append("		}" + System.lineSeparator());sb.append("		//调用查询" + System.lineSeparator());sb.append("		String json=EntityManager().QueryAllWithFK(" + modelName + ".class,para,\"\",true,-1,-1,\"\",joiner,operators);" + System.lineSeparator());sb.append("		return json;" + System.lineSeparator());sb.append("	}" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());//收尾sb.append("}" + System.lineSeparator());String saveName = Paths.get(basePath, "ash" + modelName + ".java").toString();System.out.println("生成业务代码到:" + saveName);JRT.Core.Util.TxtUtil.WriteText2File(saveName, sb.toString());}/*** 生成界面代码** @param colList  表信息* @param basePath 根地址*/private void MakeAspxCode(List<JRTGenerateCodeColDto> colList, String basePath) throws Exception {System.out.println("生成界面代码");StringBuilder sb = new StringBuilder();String modelName = colList.get(0).ModelName;String rowIDCol = "";for (JRTGenerateCodeColDto c : colList) {if (rowIDCol.isEmpty()) {rowIDCol = c.ColName;}}sb.append("<!DOCTYPE html PUBLIC \"\"-//W3C//DTD XHTML 1.0 Transitional//EN\"\" \"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"\">" + System.lineSeparator());sb.append("<html xmlns=\"\"http://www.w3.org/1999/xhtml\"\">" + System.lineSeparator());sb.append("<head>" + System.lineSeparator());sb.append("    <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />" + System.lineSeparator());sb.append("    <title>" + modelName + "供拷贝代码使用</title>" + System.lineSeparator());sb.append("    <link rel=\"shortcut icon\" href=\"../../resource/common/images/favicon.ico\" />" + System.lineSeparator());sb.append("    <script src=\"../../resource/common/js/JRTBSBase.js\" type=\"text/javascript\"></script>" + System.lineSeparator());sb.append("    <script language=\"javascript\" type=\"text/javascript\">" + System.lineSeparator());sb.append("        SYSPageCommonInfo.Init();" + System.lineSeparator());sb.append("        var BasePath = '';" + System.lineSeparator());sb.append("        var ResourcePath = '';" + System.lineSeparator());sb.append("        var WebServicAddress = SYSPageCommonInfo.Data.WebServicAddress;" + System.lineSeparator());sb.append("        var UserDR = SYSPageCommonInfo.Data.Sesssion.UserDR;" + System.lineSeparator());sb.append("        var WorkGroupDR = SYSPageCommonInfo.Data.Sesssion.WorkGroupDR;" + System.lineSeparator());sb.append("        var sysTheme = SYSPageCommonInfo.Data.Sesssion.Theme;" + System.lineSeparator());sb.append("        var SessionStr = SYSPageCommonInfo.Data.SessionStr;" + System.lineSeparator());sb.append("    </script>" + System.lineSeparator());sb.append("    <script type=\"text/javascript\">" + System.lineSeparator());sb.append("        //全局变量" + System.lineSeparator());sb.append("        var me = {" + System.lineSeparator());sb.append("            actionUrl: '../ashx/ash" + modelName + ".ashx'" + System.lineSeparator());sb.append("        };" + System.lineSeparator());sb.append("");sb.append("        //jquery入口" + System.lineSeparator());sb.append("        $(function () {" + System.lineSeparator());sb.append("");sb.append("            //新增数据点击" + System.lineSeparator());sb.append("            $(\"#btnAdd" + modelName + "\").click(function () {" + System.lineSeparator());sb.append("                $(\"#txt" + modelName + "" + rowIDCol + "\").val(\"\"); " + System.lineSeparator());sb.append("				$('#winEdit" + modelName + "').window({" + System.lineSeparator());sb.append("                    title: TranslateDataMTHD('Add Data', '新增数据', '')," + System.lineSeparator());sb.append("                    modal: true" + System.lineSeparator());sb.append("                });" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("            //修改数据点击" + System.lineSeparator());sb.append("            $(\"#btnUpdate" + modelName + "\").click(function () {" + System.lineSeparator());sb.append("				Update" + modelName + "();" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("			//修改数据" + System.lineSeparator());sb.append("			function Update" + modelName + "(row)" + System.lineSeparator());sb.append("			{" + System.lineSeparator());sb.append("                var selectRow = $('#dg" + modelName + "').datagrid(\"getSelected\");" + System.lineSeparator());sb.append("                if(row!=null)" + System.lineSeparator());sb.append("                {" + System.lineSeparator());sb.append("                	selectRow=row;" + System.lineSeparator());sb.append("                }" + System.lineSeparator());sb.append("                if (selectRow == null) {" + System.lineSeparator());sb.append("                    $.messager.alert(TranslateDataMTHD('Info', '提示', ''), TranslateDataMTHD('Please select the data to modify', '请选择要修改的数据!', ''), 'info');" + System.lineSeparator());sb.append("                    return;" + System.lineSeparator());sb.append("                }" + System.lineSeparator());sb.append("				$(\"#form" + modelName + "\").form('load', selectRow);" + System.lineSeparator());sb.append("				$('#winEdit" + modelName + "').window({" + System.lineSeparator());sb.append("                    title: TranslateDataMTHD('Update Data', '修改数据', '')," + System.lineSeparator());sb.append("                    modal: true" + System.lineSeparator());sb.append("                });" + System.lineSeparator());sb.append("			}" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("            //删除数据点击" + System.lineSeparator());sb.append("            $(\"#btnDelete" + modelName + "\").click(function () {" + System.lineSeparator());sb.append("                var checkRow = $('#dg" + modelName + "').datagrid(\"getChecked\");" + System.lineSeparator());sb.append("                var selectRow = $('#dg" + modelName + "').datagrid(\"getSelected\");" + System.lineSeparator());sb.append("                if ((checkRow == null || checkRow.length == 0)&&selectRow==null) {" + System.lineSeparator());sb.append("                    $.messager.alert(TranslateDataMTHD('Info', '提示', ''), TranslateDataMTHD('Please select the data to delete', '请勾选要删除的数据!', ''), 'info');" + System.lineSeparator());sb.append("                    return;" + System.lineSeparator());sb.append("                }" + System.lineSeparator());sb.append("                if ((checkRow == null || checkRow.length == 0)) {" + System.lineSeparator());sb.append("                    checkRow=[selectRow];" + System.lineSeparator());sb.append("                }" + System.lineSeparator());sb.append("                var RowIDS = \"\";" + System.lineSeparator());sb.append("                for (var i = 0; i < checkRow.length; i++) {" + System.lineSeparator());sb.append("                    if (i == 0) {" + System.lineSeparator());sb.append("                        RowIDS = checkRow[i]." + rowIDCol + ";" + System.lineSeparator());sb.append("                    }" + System.lineSeparator());sb.append("                    else {" + System.lineSeparator());sb.append("                        RowIDS += \"^\" + checkRow[i]." + rowIDCol + ";" + System.lineSeparator());sb.append("                    }" + System.lineSeparator());sb.append("                }" + System.lineSeparator());sb.append("                $.messager.confirm(TranslateDataMTHD('Info', '提示', ''), TranslateDataMTHD('Do you want to delete the selected data', '是否要删除选择的数据?', '') , function (r) {" + System.lineSeparator());sb.append("                    if (r) {" + System.lineSeparator());sb.append("                		//开启等待" + System.lineSeparator());sb.append("                		$.messager.progress({ text: TranslateDataMTHD(\"Deleting data\",\"正在删除数据\", \"\"), interval: 500 });" + System.lineSeparator());sb.append("                		setTimeout(function () {" + System.lineSeparator());sb.append("                    		$.messager.progress('close');" + System.lineSeparator());sb.append("                		}, 8000);" + System.lineSeparator());sb.append("                		//往后台提交数据" + System.lineSeparator());sb.append("                		$.ajax({" + System.lineSeparator());sb.append("                    		type: \"post\"," + System.lineSeparator());sb.append("                    		dataType: \"json\"," + System.lineSeparator());sb.append("                    		cache: false, //" + System.lineSeparator());sb.append("                    		async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asir" + System.lineSeparator());sb.append("                    		url: me.actionUrl + '?Method=Delete" + modelName + "'," + System.lineSeparator());sb.append("                    		data: { RowIDS: RowIDS }," + System.lineSeparator());sb.append("                    		success: function (data, status) {" + System.lineSeparator());sb.append("                        		$.messager.progress('close');" + System.lineSeparator());sb.append("                        		if (!FilterBackData(data)) {" + System.lineSeparator());sb.append("                            		return;" + System.lineSeparator());sb.append("                        		}" + System.lineSeparator());sb.append("                        		if (!data.IsOk) {" + System.lineSeparator());sb.append("                            		$.messager.alert(TranslateDataMTHD(\"Error message\", \"错误提示\", \"\"), TranslateDataMTHD(\"failed to dalete data, error message:\", \"删除失败,错误信息:\", \"\") + data.Message);" + System.lineSeparator());sb.append("                        		}" + System.lineSeparator());sb.append("                        		else {" + System.lineSeparator());sb.append("                            		Qry" + modelName + "();" + System.lineSeparator());sb.append("                            		$.messager.show({" + System.lineSeparator());sb.append("                                		title: TranslateDataMTHD(\"Info\", \"提示\", \"\")," + System.lineSeparator());sb.append("                               		 	msg: TranslateDataMTHD(\"Successfully deleted!\", \"删除成功!\", \"\")," + System.lineSeparator());sb.append("                                		timeout: 500," + System.lineSeparator());sb.append("                                		showType: 'slide'" + System.lineSeparator());sb.append("                            		});" + System.lineSeparator());sb.append("                        		}" + System.lineSeparator());sb.append("                    		}" + System.lineSeparator());sb.append("                		});" + System.lineSeparator());sb.append("                    }" + System.lineSeparator());sb.append("                });" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("");sb.append("");sb.append("            //保存数据" + System.lineSeparator());sb.append("            $(\"#btnSave" + modelName + "\").click(function () {" + System.lineSeparator());sb.append("                var saveData = jQuery.parseJSON($(\"#form" + modelName + "\").serializeObject());" + System.lineSeparator());sb.append("                //开启等待" + System.lineSeparator());sb.append("                $.messager.progress({ text: TranslateDataMTHD(\"Saving data\",\"正在保存数据\", \"\"), interval: 500 });" + System.lineSeparator());sb.append("                setTimeout(function () {" + System.lineSeparator());sb.append("                    $.messager.progress('close');" + System.lineSeparator());sb.append("                }, 8000);" + System.lineSeparator());sb.append("                //往后台提交数据" + System.lineSeparator());sb.append("                $.ajax({" + System.lineSeparator());sb.append("                    type: \"post\"," + System.lineSeparator());sb.append("                    dataType: \"json\"," + System.lineSeparator());sb.append("                    cache: false, //" + System.lineSeparator());sb.append("                    async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asir" + System.lineSeparator());sb.append("                    url: me.actionUrl + '?Method=Save" + modelName + "'," + System.lineSeparator());sb.append("                    data: saveData," + System.lineSeparator());sb.append("                    success: function (data, status) {" + System.lineSeparator());sb.append("                        $.messager.progress('close');" + System.lineSeparator());sb.append("                        if (!FilterBackData(data)) {" + System.lineSeparator());sb.append("                            return;" + System.lineSeparator());sb.append("                        }" + System.lineSeparator());sb.append("                        if (!data.IsOk) {" + System.lineSeparator());sb.append("                            $.messager.alert(TranslateDataMTHD(\"Error message\", \"错误提示\", \"\"), TranslateDataMTHD(\"failed to dalete data, error message:\", \"删除失败,错误信息:\", \"\") + data.Message);" + System.lineSeparator());sb.append("                        }" + System.lineSeparator());sb.append("                        else {" + System.lineSeparator());sb.append("                            Qry" + modelName + "();" + System.lineSeparator());sb.append("                            $.messager.show({" + System.lineSeparator());sb.append("                                title: TranslateDataMTHD(\"Info\", \"提示\", \"\")," + System.lineSeparator());sb.append("                                msg: TranslateDataMTHD(\"Successfully saveed!\", \"保存成功!\", \"\")," + System.lineSeparator());sb.append("                                timeout: 500," + System.lineSeparator());sb.append("                                showType: 'slide'" + System.lineSeparator());sb.append("                            });" + System.lineSeparator());sb.append("                            $('#winEdit" + modelName + "').window(\"close\");" + System.lineSeparator());sb.append("                        }" + System.lineSeparator());sb.append("                    }" + System.lineSeparator());sb.append("                });" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("");sb.append("");sb.append("            //关闭窗口" + System.lineSeparator());sb.append("            $(\"#btnClose" + modelName + "\").click(function () {" + System.lineSeparator());sb.append("				$('#winEdit" + modelName + "').window(\"close\");" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("            //构造查询事件" + System.lineSeparator());sb.append("            $(\"#txtFilter" + modelName + "\").searchbox({" + System.lineSeparator());sb.append("                searcher: function (value, name) {" + System.lineSeparator());sb.append("                    Qry" + modelName + "();" + System.lineSeparator());sb.append("                }," + System.lineSeparator());sb.append("                prompt: TranslateDataMTHD('Enter query', '回车查询', '')" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());for (JRTGenerateCodeColDto c : colList) {//外键参照列if (c.RefTableName != null && !c.RefTableName.isEmpty()) {String aa = GetAssociaField(c.RefTableName);String refModelName = GetAssociaField(c.RefTableName).split("\\^")[0];String associaField = GetAssociaField(c.RefTableName).split("\\^")[1];sb.append("            //" + c.ColRemark + "下拉表格渲染" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').combogrid({" + System.lineSeparator());sb.append("                panelWidth: 350," + System.lineSeparator());sb.append("                idField: '" + rowIDCol + "'," + System.lineSeparator());sb.append("                width: 205," + System.lineSeparator());sb.append("                textField: '" + associaField + "'," + System.lineSeparator());sb.append("                url: me.actionUrl + '?Method=CommonQueryView&data='+JSON.stringify({ ModelName: \"" + refModelName + "\", Pram: [], IsDisplayCount: false, Joiner: [], Operators: [] })," + System.lineSeparator());sb.append("                columns: [[" + System.lineSeparator());sb.append("                    { field: '" + rowIDCol + "', title: '主键', width: 60 }," + System.lineSeparator());sb.append("                    { field: '" + associaField + "', title: '名称', width: 260 }" + System.lineSeparator());sb.append("                ]]" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').combogrid(\"showSelectWin\");" + System.lineSeparator());sb.append("" + System.lineSeparator());} else {if (c.JavaType.equals("Boolean") || c.JavaType.equals("boolean")) {sb.append("            //" + c.ColRemark + "布尔渲染" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').combobox({" + System.lineSeparator());sb.append("                valueField:'RowID'," + System.lineSeparator());sb.append("                textField:'CName'," + System.lineSeparator());sb.append("                width: 205," + System.lineSeparator());sb.append("                data: [{\"RowID\":\"0\",\"CName\":TranslateDataMTHD('No', '否', '')},{\"RowID\":\"1\",\"CName\":TranslateDataMTHD('Yes', '是', '')}]" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("" + System.lineSeparator());}if (c.ColName.length() > 4) {String LastName = c.ColName.substring(c.ColName.length() - 4, c.ColName.length() - 1);if (LastName.equals("Date")) {sb.append("            //" + c.ColRemark + "日期渲染" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').datebox({" + System.lineSeparator());sb.append("                required:false," + System.lineSeparator());sb.append("                editable: true," + System.lineSeparator());sb.append("                width: 205," + System.lineSeparator());sb.append("                formatter: DateFormatter," + System.lineSeparator());sb.append("                parser: DateParser" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("            //设置默认日期" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').datebox(\"setValue\",GetCurentDate())" + System.lineSeparator());sb.append("");}if (LastName.equals("Time")) {sb.append("            //" + c.ColRemark + "时间渲染" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').timespinner({" + System.lineSeparator());sb.append("                required:false," + System.lineSeparator());sb.append("                editable: true," + System.lineSeparator());sb.append("                width: 205," + System.lineSeparator());sb.append("                showSeconds: true" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("            //设置默认日期" + System.lineSeparator());sb.append("            $('#txt" + modelName + c.ColName + "').timespinner(\"setValue\",GetCurentTime())" + System.lineSeparator());sb.append("");}}}}//构造表格代码sb.append("            //" + modelName + "表格" + System.lineSeparator());sb.append("            $('#dg" + modelName + "').datagrid({" + System.lineSeparator());sb.append("                remoteSort:false," + System.lineSeparator());sb.append("                singleSelect: true," + System.lineSeparator());sb.append("                toolbar: \"#dg" + modelName + "ToolBar\"," + System.lineSeparator());sb.append("                fit: true," + System.lineSeparator());sb.append("                onSelect: function (index, row) {" + System.lineSeparator());sb.append("                    //方便拷贝到子表查询用" + System.lineSeparator());sb.append("                	var select" + modelName + "=$('#dg" + modelName + "').datagrid(\"getSelected\");" + System.lineSeparator());sb.append("                }," + System.lineSeparator());sb.append("                onDblClickRow: function (index, row) {" + System.lineSeparator());sb.append("                    Update" + modelName + "(row);" + System.lineSeparator());sb.append("                }," + System.lineSeparator());sb.append("");sb.append("                columns: [[" + System.lineSeparator());sb.append("                    { field: 'ChkFlag', title: TranslateDataMTHD('Check', '选择', ''), width: 20, sortable: true, align: 'center', checkbox: true }," + System.lineSeparator());int index = 0;//构造表格列for (JRTGenerateCodeColDto c : colList) {String endChar = ",";if (c.RefTableName != null && !c.RefTableName.isEmpty()) {String colName = c.ColName;if (!c.RefColName.equals(rowIDCol)) {colName = colName + "Name";}}index++;if (index == colList.size()) {endChar = "";}sb.append("                    { field: '" + c.ColName + "', title: TranslateDataMTHD('" + c.ColName + "', '" + c.ColRemark + "', '') , width: 150, sortable: true }" + endChar + System.lineSeparator());}sb.append("                ]]" + System.lineSeparator());sb.append("            });" + System.lineSeparator());sb.append("");sb.append("");//构造查询表格方法代码sb.append("            //查询" + modelName + System.lineSeparator());sb.append("            function Qry" + modelName + "() {" + System.lineSeparator());sb.append("                var Filter = $(\"#txtFilter" + modelName + "\").searchbox(\"getValue\");" + System.lineSeparator());sb.append("                //开启等待,默认注释,在单击事件调用的逻辑启用等待会冲掉双击事件,按需要开启" + System.lineSeparator());sb.append("                //$.messager.progress({ text: TranslateDataMTHD(\"Querying data\",\"正在查询数据\", \"\"), interval: 500 });" + System.lineSeparator());sb.append("                //setTimeout(function () {" + System.lineSeparator());sb.append("                    //$.messager.progress('close');" + System.lineSeparator());sb.append("                //}, 8000);" + System.lineSeparator());sb.append("                $.ajax({" + System.lineSeparator());sb.append("                    type: \"post\"," + System.lineSeparator());sb.append("                    dataType: \"json\"," + System.lineSeparator());sb.append("                    cache: false, //" + System.lineSeparator());sb.append("                    async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asir" + System.lineSeparator());sb.append("                    url: me.actionUrl + '?Method=Qry" + modelName + "'," + System.lineSeparator());sb.append("                    data: { Filter: Filter }," + System.lineSeparator());sb.append("                    success: function (data, status) {" + System.lineSeparator());sb.append("                        //结束等待" + System.lineSeparator());sb.append("                        //$.messager.progress('close');" + System.lineSeparator());sb.append("                        if (!FilterBackData(data)) {" + System.lineSeparator());sb.append("                           return;" + System.lineSeparator());sb.append("                        }" + System.lineSeparator());sb.append("                        $('#dg" + modelName + "').datagrid(\"loadData\", data);" + System.lineSeparator());sb.append("                    }" + System.lineSeparator());sb.append("                });" + System.lineSeparator());sb.append("            };" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("            //执行查询数据" + System.lineSeparator());sb.append("            Qry" + modelName + "();" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("" + System.lineSeparator());sb.append("		});" + System.lineSeparator());sb.append("    </script>" + System.lineSeparator());sb.append("</head>" + System.lineSeparator());sb.append("<body>" + System.lineSeparator());sb.append("    <div class=\"easyui-layout\" fit=\"true\" style=\"border: none;\">" + System.lineSeparator());sb.append("        <div data-options=\"region:'center',title:''\" style=\"border: none;\">" + System.lineSeparator());sb.append("            <div id=\"dg" + modelName + "ToolBar\" style=\"padding: 3px 0px 3px 10px;\">" + System.lineSeparator());sb.append("                <a id=\"btnAdd" + modelName + "\" href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-add'\" plain=\"true\" listranslate=\"html~Add\">新增</a>" + System.lineSeparator());sb.append("                <a id=\"btnUpdate" + modelName + "\" href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-write-order'\" plain=\"true\" listranslate=\"html~Mod\">修改</a>" + System.lineSeparator());sb.append("                <a id=\"btnDelete" + modelName + "\" href=\"#\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-cancel'\" plain=\"true\" listranslate=\"html~Del\">删除</a>" + System.lineSeparator());sb.append("                <input id=\"txtFilter" + modelName + "\" style=\"margin-left: 14px; width: 240px;\"></input>" + System.lineSeparator());sb.append("            </div>" + System.lineSeparator());sb.append("            <table id=\"dg" + modelName + "\" title=\"\" iconcls=\"icon-paper\" listranslate=\"title~" + modelName + "\"></table>" + System.lineSeparator());sb.append("        </div>" + System.lineSeparator());int allColNum = colList.size();int ColNum = 1;if (allColNum > 6) {ColNum = 2;}if (allColNum > 12) {ColNum = 3;}int winWidth = 370 * ColNum + 30;int windowHeight = allColNum * 37 / ColNum + 120;sb.append("        <div id=\"winEdit" + modelName + "\" style=\"padding: 10px 0px 0px 10px;width:" + winWidth + "px;height:" + windowHeight + "px;display: none;\">" + System.lineSeparator());sb.append("            <form id=\"form" + modelName + "\" name=\"edit_form\" method=\"post\">" + System.lineSeparator());sb.append("                <input type=\"hidden\" id=\"txt" + modelName + "RowID\" name=\"RowID\" value=\"0\" />" + System.lineSeparator());sb.append("                <table>" + System.lineSeparator());//构造弹窗编辑的HTMLint outColNum = 0;for (JRTGenerateCodeColDto c : colList) {if (c.ColName.equals(rowIDCol)) {continue;}outColNum = outColNum + 1;if ((ColNum == 1) || (outColNum == 1) || ((outColNum % ColNum) == 1)) {sb.append("                    <tr>" + System.lineSeparator());}sb.append("                        <td class=\"lisar\" jrttranslate=\"html~" + c.ColName + "\">" + c.ColRemark + "</td>" + System.lineSeparator());if (c.RefTableName != null && !c.RefTableName.isEmpty()) {sb.append("                        <td class=\"lisal\"><input id=\"txt" + modelName + c.ColName + "\" type=\"text\" name=\"" + c.ColName + "\" style=\"width:200px;\"/></td>" + System.lineSeparator());} else {sb.append("                        <td class=\"lisal\"><input id=\"txt" + modelName + c.ColName + "\" type=\"text\" name=\"" + c.ColName + "\" style=\"width:200px;\" class=\"easyui-validatebox\"  maxlength=\"" + c.Len + "\"/></td>" + System.lineSeparator());}if ((ColNum == 1) || ((outColNum % ColNum) == 0) || (outColNum == allColNum)) {sb.append("                    </tr>" + System.lineSeparator());}}sb.append("                </table>" + System.lineSeparator());sb.append("                <div region=\"south\" border=\"fale\" style=\"text-align: center; padding: 5px 0 0;\">" + System.lineSeparator());sb.append("                    <a id=\"btnSave" + modelName + "\" href=\"#\" class=\"easyui-linkbutton\" plain=\"false\" listranslate=\"html~Save\">保存</a>" + System.lineSeparator());sb.append("                    <span class=\"sp6\"></span>" + System.lineSeparator());sb.append("                    <a id=\"btnClose" + modelName + "\" href=\"#\" class=\"easyui-linkbutton\" plain=\"false\" listranslate=\"html~Cancel\">取消</a>" + System.lineSeparator());sb.append("                </div>" + System.lineSeparator());sb.append("            </form>" + System.lineSeparator());sb.append("        </div>" + System.lineSeparator());sb.append("   </div>" + System.lineSeparator());sb.append("</body>" + System.lineSeparator());sb.append("</html>" + System.lineSeparator());sb.append("" + System.lineSeparator());String saveName = Paths.get(basePath, "frm" + modelName + ".aspx").toString();System.out.println("生成界面代码到:" + saveName);JRT.Core.Util.TxtUtil.WriteText2File(saveName, sb.toString());}/*** 处理类型,根据数据库类型得到对应实体的Jave类型,同时处理在表说明里面可能的实体名称** @param col 一列信息*/private void DealType(JRTGenerateCodeColDto col) {col.ModelName = col.TableName.replace("_", "");//没表说明就取表名称if (col.TableRemark == null) {col.TableRemark = col.ColName;}//表说明附带的实体名称提取if (col.TableRemark.contains(":")) {System.out.println("TableRemark:"+col.TableRemark);String [] arr=col.TableRemark.split(":");col.ModelName = arr[0];if(arr.length>1) {col.TableRemark = arr[1];}else{col.TableRemark = col.TableName;}}//intif (col.ColType.equals("int4")) {col.Len = 10;if (col.NotNull) {col.JavaType = "int";} else {col.JavaType = "Integer";}}//字符串else if (col.ColType.contains("varchar")) {String len = col.ColType.replace("varchar(", "");len = len.replace(")", "");col.Len = Integer.valueOf(len);if (col.NotNull) {if (col.Len == 1 && col.ColName.contains("Is")) {col.JavaType = "boolean";} else {col.JavaType = "String";}} else {if (col.Len == 1 && col.ColName.contains("Is")) {col.JavaType = "Boolean";} else {col.JavaType = "String";}}}//布尔else if (col.ColType.contains("boolean")) {if (col.NotNull) {col.JavaType = "boolean";} else {col.JavaType = "Boolean";}}//浮点数else if (col.ColType.equals("numeric")) {if (col.NotNull) {col.JavaType = "double";} else {col.JavaType = "Double";}}//其他else {col.JavaType = col.ColType;}}/*** 外键信息实体*/public static class JRTGenerateCodeFkRefDto {/*** 表名*/public String TableName;/*** 列名*/public String ColName;/*** 参照表名*/public String RefTableName;/*** 参照列名*/public String RefColName;}/*** 表和列信息实体*/public static class JRTGenerateCodeColDto {/*** 表名*/public String TableName;/*** 表说明*/public String TableRemark;/*** 列名*/public String ColName;/*** 参列说明*/public String ColRemark;/*** 列数据类型*/public String ColType;/*** 不为空*/public boolean NotNull;/*** 参照表名*/public String RefTableName;/*** 参照列名*/public String RefColName;/*** 长度*/public Integer Len;/*** java类型*/public String JavaType;/*** 实体名称*/public String ModelName;}
}

测试
在这里插入图片描述

生成的代码ashJRTPrintImage

import JRTBLLBase.BaseHttpHandlerNoSession;import JRTBLLBase.Helper;
import JRT.Core.Dto.HashParam;
import JRT.Core.Dto.ParamDto;
import JRT.Core.Dto.OutParam;
import JRT.Model.Entity.*;
import JRT.Core.Util.Convert;
import JRT.Core.MultiPlatform.JRTContext;
import java.util.ArrayList;
import java.util.List;/**
*由代码生成器生成的后台代码
*/
public class ashJRTPrintImage extends BaseHttpHandlerNoSession {/*** 保存数据,前台按表的属性名提交* @return 字符串*/public String SaveJRTPrintImage() throws Exception{JRTPrintImage dto=new JRTPrintImage();//主键dto.RowID=Helper.ValidParam(JRTContext.GetRequest(Request, "RowID"), dto.RowID);//代码dto.Code=Helper.ValidParam(JRTContext.GetRequest(Request, "Code"), dto.Code);//名称dto.CName=Helper.ValidParam(JRTContext.GetRequest(Request, "CName"), dto.CName);//产品组唯一标识dto.ProductGroup=Helper.ValidParam(JRTContext.GetRequest(Request, "ProductGroup"), dto.ProductGroup);//产品组存的业务IDdto.ProductBllID=Helper.ValidParam(JRTContext.GetRequest(Request, "ProductBllID"), dto.ProductBllID);//开始日期dto.StartDate=Helper.ValidParam(JRTContext.GetRequest(Request, "StartDate"), dto.StartDate);//结束日期dto.EndDate=Helper.ValidParam(JRTContext.GetRequest(Request, "EndDate"), dto.EndDate);//图片Base64串dto.ImgBase64String=Helper.ValidParam(JRTContext.GetRequest(Request, "ImgBase64String"), dto.ImgBase64String);//图片类别dto.ImgType=Helper.ValidParam(JRTContext.GetRequest(Request, "ImgType"), dto.ImgType);OutParam out=new OutParam();int ret=0;//更新if(dto.RowID>0){ret=EntityManager().Update(dto,null, out, null, null, null);}//插入数据else{ret=EntityManager().Save(dto,out);}if(ret==1){return Helper.Success();}else{return Helper.Error(out);}}/*** 删除数据,多个RowID以上尖号分割* @return 字符串*/public String DeleteJRTPrintImage() throws Exception{String RowIDS=Helper.ValidParam(JRTContext.GetRequest(Request, "RowIDS"), "");if(RowIDS.isEmpty()){return Helper.Error("请传入要删除数据的RowID,多个以^分割!");}//分割主键String [] arr=RowIDS.split("^");//out参数OutParam out=new OutParam();//循环删除数据for(int i=0;i<arr.length;i++){int ret=EntityManager().RemoveById(JRTPrintImage.class,Convert.ToInt32(arr[i]),out);if(ret!=1){return Helper.Error(out);}}return Helper.Success();}/*** 查询数据,前台按表的属性名提交* @return 字符串*/public String QryJRTPrintImage() throws Exception{//预留的取前台参数代码//参数List<ParamDto> para=new ArrayList<>();//sql连接符号List<String> joiner=new ArrayList<>();//sql比较符号List<String> operators=new ArrayList<>();//模糊查询String Filter=Helper.ValidParam(JRTContext.GetRequest(Request, "Filter"), "");//预留参数//主键dto.RowID=Helper.ValidParam(JRTContext.GetRequest(Request, "RowID"), dto.RowID);//代码dto.Code=Helper.ValidParam(JRTContext.GetRequest(Request, "Code"), dto.Code);//名称dto.CName=Helper.ValidParam(JRTContext.GetRequest(Request, "CName"), dto.CName);//产品组唯一标识dto.ProductGroup=Helper.ValidParam(JRTContext.GetRequest(Request, "ProductGroup"), dto.ProductGroup);//产品组存的业务IDdto.ProductBllID=Helper.ValidParam(JRTContext.GetRequest(Request, "ProductBllID"), dto.ProductBllID);//开始日期dto.StartDate=Helper.ValidParam(JRTContext.GetRequest(Request, "StartDate"), dto.StartDate);//结束日期dto.EndDate=Helper.ValidParam(JRTContext.GetRequest(Request, "EndDate"), dto.EndDate);//图片Base64串dto.ImgBase64String=Helper.ValidParam(JRTContext.GetRequest(Request, "ImgBase64String"), dto.ImgBase64String);//图片类别dto.ImgType=Helper.ValidParam(JRTContext.GetRequest(Request, "ImgType"), dto.ImgType);//模糊查询if(!Filter.isEmpty()){ParamDto p=null;//代码p=new ParamDto();p.Key="Code";p.Value="%"+Filter+"%";para.add(p);joiner.add("or");operators.add("like");//名称p=new ParamDto();p.Key="CName";p.Value="%"+Filter+"%";para.add(p);joiner.add("or");operators.add("like");//产品组唯一标识p=new ParamDto();p.Key="ProductGroup";p.Value="%"+Filter+"%";para.add(p);joiner.add("or");operators.add("like");//产品组存的业务IDp=new ParamDto();p.Key="ProductBllID";p.Value="%"+Filter+"%";para.add(p);joiner.add("or");operators.add("like");//图片Base64串p=new ParamDto();p.Key="ImgBase64String";p.Value="%"+Filter+"%";para.add(p);joiner.add("or");operators.add("like");//图片类别p=new ParamDto();p.Key="ImgType";p.Value="%"+Filter+"%";para.add(p);joiner.add("or");operators.add("like");}//调用查询String json=EntityManager().QueryAllWithFK(JRTPrintImage.class,para,"",true,-1,-1,"",joiner,operators);return json;}}

生成的代码frmJRTPrintImage.aspx

<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>JRTPrintImage供拷贝代码使用</title><link rel="shortcut icon" href="../../resource/common/images/favicon.ico" /><script src="../../resource/common/js/JRTBSBase.js" type="text/javascript"></script><script language="javascript" type="text/javascript">SYSPageCommonInfo.Init();var BasePath = '';var ResourcePath = '';var WebServicAddress = SYSPageCommonInfo.Data.WebServicAddress;var UserDR = SYSPageCommonInfo.Data.Sesssion.UserDR;var WorkGroupDR = SYSPageCommonInfo.Data.Sesssion.WorkGroupDR;var sysTheme = SYSPageCommonInfo.Data.Sesssion.Theme;var SessionStr = SYSPageCommonInfo.Data.SessionStr;</script><script type="text/javascript">//全局变量var me = {actionUrl: '../ashx/ashJRTPrintImage.ashx'};//jquery入口$(function () {//新增数据点击$("#btnAddJRTPrintImage").click(function () {$("#txtJRTPrintImageRowID").val(""); $('#winEditJRTPrintImage').window({title: TranslateDataMTHD('Add Data', '新增数据', ''),modal: true});});//修改数据点击$("#btnUpdateJRTPrintImage").click(function () {UpdateJRTPrintImage();});//修改数据function UpdateJRTPrintImage(row){var selectRow = $('#dgJRTPrintImage').datagrid("getSelected");if(row!=null){selectRow=row;}if (selectRow == null) {$.messager.alert(TranslateDataMTHD('Info', '提示', ''), TranslateDataMTHD('Please select the data to modify', '请选择要修改的数据!', ''), 'info');return;}$("#formJRTPrintImage").form('load', selectRow);$('#winEditJRTPrintImage').window({title: TranslateDataMTHD('Update Data', '修改数据', ''),modal: true});}//删除数据点击$("#btnDeleteJRTPrintImage").click(function () {var checkRow = $('#dgJRTPrintImage').datagrid("getChecked");var selectRow = $('#dgJRTPrintImage').datagrid("getSelected");if ((checkRow == null || checkRow.length == 0)&&selectRow==null) {$.messager.alert(TranslateDataMTHD('Info', '提示', ''), TranslateDataMTHD('Please select the data to delete', '请勾选要删除的数据!', ''), 'info');return;}if ((checkRow == null || checkRow.length == 0)) {checkRow=[selectRow];}var RowIDS = "";for (var i = 0; i < checkRow.length; i++) {if (i == 0) {RowIDS = checkRow[i].RowID;}else {RowIDS += "^" + checkRow[i].RowID;}}$.messager.confirm(TranslateDataMTHD('Info', '提示', ''), TranslateDataMTHD('Do you want to delete the selected data', '是否要删除选择的数据?', '') , function (r) {if (r) {//开启等待$.messager.progress({ text: TranslateDataMTHD("Deleting data","正在删除数据", ""), interval: 500 });setTimeout(function () {$.messager.progress('close');}, 8000);//往后台提交数据$.ajax({type: "post",dataType: "json",cache: false, //async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asirurl: me.actionUrl + '?Method=DeleteJRTPrintImage',data: { RowIDS: RowIDS },success: function (data, status) {$.messager.progress('close');if (!FilterBackData(data)) {return;}if (!data.IsOk) {$.messager.alert(TranslateDataMTHD("Error message", "错误提示", ""), TranslateDataMTHD("failed to dalete data, error message:", "删除失败,错误信息:", "") + data.Message);}else {QryJRTPrintImage();$.messager.show({title: TranslateDataMTHD("Info", "提示", ""),msg: TranslateDataMTHD("Successfully deleted!", "删除成功!", ""),timeout: 500,showType: 'slide'});}}});}});});//保存数据$("#btnSaveJRTPrintImage").click(function () {var saveData = jQuery.parseJSON($("#formJRTPrintImage").serializeObject());//开启等待$.messager.progress({ text: TranslateDataMTHD("Saving data","正在保存数据", ""), interval: 500 });setTimeout(function () {$.messager.progress('close');}, 8000);//往后台提交数据$.ajax({type: "post",dataType: "json",cache: false, //async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asirurl: me.actionUrl + '?Method=SaveJRTPrintImage',data: saveData,success: function (data, status) {$.messager.progress('close');if (!FilterBackData(data)) {return;}if (!data.IsOk) {$.messager.alert(TranslateDataMTHD("Error message", "错误提示", ""), TranslateDataMTHD("failed to dalete data, error message:", "删除失败,错误信息:", "") + data.Message);}else {QryJRTPrintImage();$.messager.show({title: TranslateDataMTHD("Info", "提示", ""),msg: TranslateDataMTHD("Successfully saveed!", "保存成功!", ""),timeout: 500,showType: 'slide'});$('#winEditJRTPrintImage').window("close");}}});});//关闭窗口$("#btnCloseJRTPrintImage").click(function () {$('#winEditJRTPrintImage').window("close");});//构造查询事件$("#txtFilterJRTPrintImage").searchbox({searcher: function (value, name) {QryJRTPrintImage();},prompt: TranslateDataMTHD('Enter query', '回车查询', '')});//JRTPrintImage表格$('#dgJRTPrintImage').datagrid({remoteSort:false,singleSelect: true,toolbar: "#dgJRTPrintImageToolBar",fit: true,onSelect: function (index, row) {//方便拷贝到子表查询用var selectJRTPrintImage=$('#dgJRTPrintImage').datagrid("getSelected");},onDblClickRow: function (index, row) {UpdateJRTPrintImage(row);},columns: [[{ field: 'ChkFlag', title: TranslateDataMTHD('Check', '选择', ''), width: 20, sortable: true, align: 'center', checkbox: true },{ field: 'RowID', title: TranslateDataMTHD('RowID', '主键', '') , width: 150, sortable: true },{ field: 'Code', title: TranslateDataMTHD('Code', '代码', '') , width: 150, sortable: true },{ field: 'CName', title: TranslateDataMTHD('CName', '名称', '') , width: 150, sortable: true },{ field: 'ProductGroup', title: TranslateDataMTHD('ProductGroup', '产品组唯一标识', '') , width: 150, sortable: true },{ field: 'ProductBllID', title: TranslateDataMTHD('ProductBllID', '产品组存的业务ID', '') , width: 150, sortable: true },{ field: 'StartDate', title: TranslateDataMTHD('StartDate', '开始日期', '') , width: 150, sortable: true },{ field: 'EndDate', title: TranslateDataMTHD('EndDate', '结束日期', '') , width: 150, sortable: true },{ field: 'ImgBase64String', title: TranslateDataMTHD('ImgBase64String', '图片Base64串', '') , width: 150, sortable: true },{ field: 'ImgType', title: TranslateDataMTHD('ImgType', '图片类别', '') , width: 150, sortable: true }]]});//查询JRTPrintImagefunction QryJRTPrintImage() {var Filter = $("#txtFilterJRTPrintImage").searchbox("getValue");//开启等待,默认注释,在单击事件调用的逻辑启用等待会冲掉双击事件,按需要开启//$.messager.progress({ text: TranslateDataMTHD("Querying data","正在查询数据", ""), interval: 500 });//setTimeout(function () {//$.messager.progress('close');//}, 8000);$.ajax({type: "post",dataType: "json",cache: false, //async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asirurl: me.actionUrl + '?Method=QryJRTPrintImage',data: { Filter: Filter },success: function (data, status) {//结束等待//$.messager.progress('close');if (!FilterBackData(data)) {return;}$('#dgJRTPrintImage').datagrid("loadData", data);}});};//执行查询数据QryJRTPrintImage();});</script>
</head>
<body><div class="easyui-layout" fit="true" style="border: none;"><div data-options="region:'center',title:''" style="border: none;"><div id="dgJRTPrintImageToolBar" style="padding: 3px 0px 3px 10px;"><a id="btnAddJRTPrintImage" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" plain="true" listranslate="html~Add">新增</a><a id="btnUpdateJRTPrintImage" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-write-order'" plain="true" listranslate="html~Mod">修改</a><a id="btnDeleteJRTPrintImage" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" plain="true" listranslate="html~Del">删除</a><input id="txtFilterJRTPrintImage" style="margin-left: 14px; width: 240px;"></input></div><table id="dgJRTPrintImage" title="" iconcls="icon-paper" listranslate="title~JRTPrintImage"></table></div><div id="winEditJRTPrintImage" style="padding: 10px 0px 0px 10px;width:770px;height:286px;display: none;"><form id="formJRTPrintImage" name="edit_form" method="post"><input type="hidden" id="txtJRTPrintImageRowID" name="RowID" value="0" /><table><tr><td class="lisar" jrttranslate="html~Code">代码</td><td class="lisal"><input id="txtJRTPrintImageCode" type="text" name="Code" style="width:200px;" class="easyui-validatebox"  maxlength="20"/></td><td class="lisar" jrttranslate="html~CName">名称</td><td class="lisal"><input id="txtJRTPrintImageCName" type="text" name="CName" style="width:200px;" class="easyui-validatebox"  maxlength="40"/></td></tr><tr><td class="lisar" jrttranslate="html~ProductGroup">产品组唯一标识</td><td class="lisal"><input id="txtJRTPrintImageProductGroup" type="text" name="ProductGroup" style="width:200px;" class="easyui-validatebox"  maxlength="30"/></td><td class="lisar" jrttranslate="html~ProductBllID">产品组存的业务ID</td><td class="lisal"><input id="txtJRTPrintImageProductBllID" type="text" name="ProductBllID" style="width:200px;" class="easyui-validatebox"  maxlength="30"/></td></tr><tr><td class="lisar" jrttranslate="html~StartDate">开始日期</td><td class="lisal"><input id="txtJRTPrintImageStartDate" type="text" name="StartDate" style="width:200px;" class="easyui-validatebox"  maxlength="10"/></td><td class="lisar" jrttranslate="html~EndDate">结束日期</td><td class="lisal"><input id="txtJRTPrintImageEndDate" type="text" name="EndDate" style="width:200px;" class="easyui-validatebox"  maxlength="10"/></td></tr><tr><td class="lisar" jrttranslate="html~ImgBase64String">图片Base64</td><td class="lisal"><input id="txtJRTPrintImageImgBase64String" type="text" name="ImgBase64String" style="width:200px;" class="easyui-validatebox"  maxlength="827670"/></td><td class="lisar" jrttranslate="html~ImgType">图片类别</td><td class="lisal"><input id="txtJRTPrintImageImgType" type="text" name="ImgType" style="width:200px;" class="easyui-validatebox"  maxlength="10"/></td></tr></table><div region="south" border="fale" style="text-align: center; padding: 5px 0 0;"><a id="btnSaveJRTPrintImage" href="#" class="easyui-linkbutton" plain="false" listranslate="html~Save">保存</a><span class="sp6"></span><a id="btnCloseJRTPrintImage" href="#" class="easyui-linkbutton" plain="false" listranslate="html~Cancel">取消</a></div></form></div></div>
</body>
</html>

生成的代码JRTPrintImage.java

package JRT.Model.Entity;import JRT.Core.CustomAttributes.*;
import JRT.Core.JsonAttributes.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;/**
*[功能描述:本代码由LIS内部代码生成工具生成,请不要手动修改,如要修改,请写修改变更记录]
*[创建者:JRT.Entity生成器]
*/
@UniqueAttribute(ColNames = "RowID")
@TableAttribute(Name="dbo.jrt_printimage")
public class JRTPrintImage
{/*** 主键*/@NotNullAttribute@IdAttribute(Name = "RowID")@LengthAttribute(MaxLen = 10)public int RowID;/*** 代码*/@NotNullAttribute@LengthAttribute(MaxLen = 20)public String Code;/*** 名称*/@NotNullAttribute@LengthAttribute(MaxLen = 40)public String CName;/*** 产品组唯一标识*/@NotNullAttribute@LengthAttribute(MaxLen = 30)public String ProductGroup;/*** 产品组存的业务ID*/@NotNullAttribute@LengthAttribute(MaxLen = 30)public String ProductBllID;/*** 开始日期*/@NotNullAttribute@LengthAttribute(MaxLen = 10)public int StartDate;/*** 结束日期*/@NotNullAttribute@LengthAttribute(MaxLen = 10)public int EndDate;/*** 图片Base64串*/@NotNullAttribute@LengthAttribute(MaxLen = 827670)public String ImgBase64String;/*** 图片类别*/@NotNullAttribute@LengthAttribute(MaxLen = 10)public String ImgType;}

工具脚本系列快齐了
在这里插入图片描述

M把表生成SQL脚本代码

Class Jbase.ImportTableToPostGresql Extends %RegisteredObject
{/// 生成创建PostgreSql的SQL语句脚本
/// w ##class(Jbase.ImportTableToPostGresql).MakePGScript("D:\mktablesql.sql","")
ClassMethod MakePGScript(path, onlyInsert)
{s path=$g(path)s onlyInsert=$g(onlyInsert)s file=##class(%File).%New(path)//存在就追加i ##class(%File).Exists(path) d.d ##class(%File).Delete(path).d file.Open("WSN:/SHARED:/IOTABLE=""UTF8""")//不存在就新建e  d.d file.Open("WSN:/SHARED:/IOTABLE=""UTF8""")//创建隐士转换//d ..WriteLineWithCode(file,"CREATE CAST (INTEGER AS VARCHAR) WITH INOUT AS IMPLICIT;")//d ..WriteLineWithCode(file,"CREATE CAST (VARCHAR AS INTEGER) WITH INOUT AS IMPLICIT;")//d ..WriteLineWithCode(file,"CREATE CAST (BIGINT AS VARCHAR) WITH INOUT AS IMPLICIT;")//d ..WriteLineWithCode(file,"CREATE CAST (VARCHAR AS BIGINT) WITH INOUT AS IMPLICIT;")//d ..WriteLineWithCode(file,"CREATE CAST (TEXT AS INTEGER) WITH INOUT AS IMPLICIT;")s rset1 = ##class(%ResultSet).%New()d rset1.Prepare("select TABLE_NAME,DESCRIPTION FROM information_schema.Tables where TABLE_SCHEMA='dbo'")s exeret1=rset1.Execute()s colCount1=rset1.GetColumnCount()s dealNum1=0s ViewNameMap=""While(rset1.Next()){s colField=rset1.GetColumnName(1)s ColValue=rset1.GetDataByName(colField)i $e(ColValue,1,2)="V_" d  continue.s ViewNameMap(ColValue)=""s colField2=rset1.GetColumnName(2)s ColValue2=rset1.GetDataByName(colField2)s ColValue2=$tr(ColValue2,$c(10))s ColValue2=$tr(ColValue2,$c(13))//i $e(ColValue,1,3)'="SYS" continuei onlyInsert'="1" d.//创建表的sql,先设置主键不自增.s oneCreateSql=..MakeOneCreateTableSql(ColValue).d ..WriteLineWithCode(file,oneCreateSql_";").s tableName="dbo."_ColValue.//添加表说明sql.s tableRemarkSql="comment on table "_tableName_" is '"_$tr(ColValue,"_","")_":"_ColValue2_"'".d ..WriteLineWithCode(file,tableRemarkSql_";").d ..WriteLineWithCode(file,"").//添加列说明sql.s ColRemarkList=..MakeOneColRemarkSql(ColValue).i $ll(ColRemarkList) d..f ci=1:1:$ll(ColRemarkList) d...d ..WriteLineWithCode(file,$lg(ColRemarkList,ci)_";") .d ..WriteLineWithCode(file,"").d ..WriteLineWithCode(file,"")//构造insert语句d ..MakeOneInsertSql(file,ColValue)//构造索引语句d ..MakeOneIndexSql(file,ColValue)d ..WriteLineWithCode(file,"")d ..WriteLineWithCode(file,"")d ..WriteLineWithCode(file,"")}//构造外键参照s rset2 = ##class(%ResultSet).%New()d rset2.Prepare("select TABLE_NAME,DESCRIPTION FROM information_schema.Tables where TABLE_SCHEMA='dbo'")s exeret2=rset2.Execute()s colCount2=rset2.GetColumnCount()s dealNum2=0While(rset2.Next()){s colField=rset2.GetColumnName(1)s ColValue=rset2.GetDataByName(colField)i $e(ColValue,1,2)="V_" continues colField2=rset2.GetColumnName(2)s ColValue2=rset2.GetDataByName(colField2)//i $e(ColValue,1,3)'="SYS" continue//构造外键约束语句d ..MakeOneFKSql(file,ColValue)}//构造创建视图语句s ViewName="" f  s ViewName=$o(ViewNameMap(ViewName)) q:ViewName=""  d.s ClassName="dbo."_$tr(ViewName,"_").s pathTmp=path_".xml".s ret=$system.OBJ.Export(ClassName_".cls",pathTmp).s file1=##class(%File).%New(pathTmp).Do file1.Open("R:/SHARED").s AllStr="".f i=1:1:300 d..s Str=file1.Read(32000,.sc)..s AllStr=AllStr_Str_" ".d file1.Close().s ResponseXml= ##class(LIS.Util.COM.XML).FromXML(AllStr).s SqlTableName=ResponseXml.Class.SqlTableName.s Sql=ResponseXml.Class.ViewQuery.s SqlTmp=$replace(Sql,"dbo.",$c(0)).s SqlTmp=$replace(SqlTmp,"AS ",$c(1)_"""").s SqlTmp=$replace(SqlTmp,".",".""").s SqlTmp1="".s FlagNum=0.f j=1:1:$l(SqlTmp) d..s OneChar=$e(SqlTmp,j,j)..i OneChar="""" s FlagNum=FlagNum+1..i (OneChar=" ")||(OneChar=",") d...i FlagNum>0 d....s FlagNum=FlagNum-1....s SqlTmp1=SqlTmp1_""""..s SqlTmp1=SqlTmp1_OneChar.i FlagNum>0 s SqlTmp1=SqlTmp1_"""".s SqlTmp=$replace(SqlTmp1,$c(0),"dbo.").s SqlTmp=$replace(SqlTmp,$c(1),"AS ").s ViewSql="create view dbo."_SqlTableName_" as "_SqlTmp_";".d ..WriteLineWithCode(file,ViewSql)q "完成"
}/// 生成一个表的创建表语句
/// w ##class(Jbase.ImportTableToPostGresql).MakeOneCreateTableSql("SYS_User")
ClassMethod MakeOneCreateTableSql(TableName)
{s TableName=$g(TableName)s rset = ##class(%ResultSet).%New()d rset.Prepare("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,DESCRIPTION,IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='dbo'  and TABLE_NAME='"_TableName_"'")s exeret=rset.Execute()s colCount=rset.GetColumnCount()s retSql="create table dbo."_TableNames retSql=retSql_"("s retSql=retSql_"""RowID"" serial primary key"While(rset.Next()){s outStr=""s colField=rset.GetColumnName(1)s colName=rset.GetDataByName(colField)s colField1=rset.GetColumnName(2)s colType=rset.GetDataByName(colField1)s colField2=rset.GetColumnName(3)s colLen=rset.GetDataByName(colField2)i colLen>10485760 s colLen=10485760s colField3=rset.GetColumnName(4)s colDesc=rset.GetDataByName(colField3)s colField4=rset.GetColumnName(5)s NULLABLE=rset.GetDataByName(colField4)i '$l(colDesc) s colDesc=colNames NullStr=""i NULLABLE="NO" d.s NullStr=" not null"i colName="RowID" continues type=colTypes lenStr=""i colType="integer" d.s type="integer".s colLen=10i colType="bigint" d.s type="integer".s colLen=10i colType="smallint" d.s type="integer".s colLen=10i colType="tinyint" d.s type="integer".s colLen=10e  i colType="varchar" d.s type="varchar".s lenStr="("_colLen_")"e  i colType="bit" d.s type="boolean".s colLen=1e  i type="longvarbinary".s type="varchar".s colLen=10485760e  i colType="double" d.s type="numeric".s colLen=10e  i colType="numeric" d.s type="numeric".s colLen=10s retSql=retSql_","""_colName_""" "_type_lenStr_NullStr}s retSql=retSql_")"q retSql
}/// 生成一个表的列说明
/// w ##class(Jbase.ImportTableToPostGresql).MakeOneColRemarkSql("SYS_User")
ClassMethod MakeOneColRemarkSql(TableName)
{s TableName=$g(TableName)s rset = ##class(%ResultSet).%New()d rset.Prepare("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,DESCRIPTION,IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='dbo'  and TABLE_NAME='"_TableName_"'")s exeret=rset.Execute()s colCount=rset.GetColumnCount()s tableName="dbo."_TableNames retList=""While(rset.Next()){s outStr=""s colField=rset.GetColumnName(1)s colName=rset.GetDataByName(colField)s colField1=rset.GetColumnName(2)s colType=rset.GetDataByName(colField1)s colField2=rset.GetColumnName(3)s colLen=rset.GetDataByName(colField2)i colLen>10485760 s colLen=10485760s colField3=rset.GetColumnName(4)s colDesc=rset.GetDataByName(colField3)s colField4=rset.GetColumnName(5)s NULLABLE=rset.GetDataByName(colField4)s colDesc=$tr(colDesc,$c(10))s colDesc=$tr(colDesc,$c(13))i '$l(colDesc) s colDesc=colNames sql="comment on column "_tableName_"."""_colName_""" is '"_colDesc_"'"s retList=retList_$lb(sql)}q retList
}/// 构造一个表的insert语句
/// w ##class(Jbase.ImportTableToPostGresql).MakeOneInsertSql("","JRT_PrintTemplateEle")
ClassMethod MakeOneInsertSql(file, TableName)
{s TableName=$g(TableName)//替换下划线s tableName=$tr(TableName,"_")s MaxRowID=0i $d(@("^dbo."_tableName_"D")) d.s MaxRowID="".&sql(SELECT count(*) INTO MaxRowID FROM dbo."_TableName_")//大于10000的不认为是基础数据//i ($e(tableName,1,3)'="SYS")&&(MaxRowID>10000) q ""//i ($e(tableName,1,3)'="SYS") q ""i MaxRowID>10000 q ""i ($e(tableName,$l(tableName)-2,$l(tableName))="Log") q ""s rset = ##class(%ResultSet).%New()d rset.Prepare("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,DESCRIPTION,IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='dbo'  and TABLE_NAME='"_TableName_"'")s exeret=rset.Execute()s colCount=rset.GetColumnCount()s tableName="dbo."_TableNames retList=""s insertHead="insert into "_tableName_"("s index=0s typeStr=""While(rset.Next()){s outStr=""s colField=rset.GetColumnName(1)s colName=rset.GetDataByName(colField)s colField1=rset.GetColumnName(2)s colType=rset.GetDataByName(colField1)s colField2=rset.GetColumnName(3)s colLen=rset.GetDataByName(colField2)i colLen>10485760 s colLen=10485760s colField3=rset.GetColumnName(4)s colDesc=rset.GetDataByName(colField3)s colField4=rset.GetColumnName(5)s NULLABLE=rset.GetDataByName(colField4)i '$l(colDesc) s colDesc=colNamei colName="RowID" continues type=colTypei colType="integer" d.s type="integer"i colType="bigint" d.s type="integer"i colType="smallint" d.s type="integer"i colType="tinyint" d.s type="integer"e  i colType="varchar" d.s type="varchar".s lenStr="("_colLen_")"e  i colType="bit" d.s type="varchar".s lenStr="("_colLen_")"e  i type="longvarbinary".s type="varchar"e  i colType="double" d.s type="numeric"e  i colType="numeric" d.s type="numeric"s typeStr=typeStr_type_","s index=index+1i index>1 d.s insertHead=insertHead_","""_colName_""""e  d.s insertHead=insertHead_""""_colName_""""}s insertHead=insertHead_") values("s rset1 = ##class(%ResultSet).%New()d rset1.Prepare("select * FROM dbo."_TableName_" order by RowID asc")s exeret=rset1.Execute()s colCount=rset1.GetColumnCount()s rowNum=0s newRowID=0While(rset1.Next()){s index=0s valSql=""s rowNum=rowNum+1s rowID=0f i=1:1:colCount d.s colField=rset1.GetColumnName(i).s colVal=rset1.GetDataByName(colField).s colVal=..DealNotSeeChar(colVal).i i=1 s rowID=colVal q.s type=$p(typeStr,",",i-1).s OutChar="'".i (type="integer")||(type="numeric") d..s OutChar=""..i '$l(colVal) s colVal="null".//帮助里面有特殊字符.i colField="FormHelp" s colVal="".s index=index+1.i index>1 d..s valSql=valSql_","_OutChar_colVal_OutChar.e  d..s valSql=valSql_""_OutChar_colVal_OutChari rowNum<rowID d.//比实际RowID少就删除让RowID增长.f j=1:1:(rowID-rowNum) d..i $l(file) d...d ..WriteLineWithCode(file,insertHead_valSql_");")...s newRowID=newRowID+1...//对齐RowID...d ..WriteLineWithCode(file,"delete from dbo."_TableName_" where ""RowID""="_newRowID_"")i $l(file) d.d ..WriteLineWithCode(file,insertHead_valSql_");").s newRowID=newRowID+1s rowNum=newRowID}i $l(file) d ..WriteLineWithCode(file,"")q ""
}/// 构造生成索引语句
ClassMethod MakeOneIndexSql(file, TableName)
{s TableName=$g(TableName)//替换下划线s tableName=$tr(TableName,"_")s rset = ##class(%ResultSet).%New()d rset.Prepare("SELECT INDEX_NAME,COLUMN_NAME,NON_UNIQUE FROM information_schema.INDEXES WHERE TABLE_SCHEMA='dbo' and TABLE_NAME='"_TableName_"' order by ORDINAL_POSITION asc")s exeret=rset.Execute()s colCount=rset.GetColumnCount()s tableName="dbo."_TableNames MapObj=""While(rset.Next()){s outStr=""s colField=rset.GetColumnName(1)s IndexName=rset.GetDataByName(colField)s colField1=rset.GetColumnName(2)s ColName=rset.GetDataByName(colField1)s colField2=rset.GetColumnName(3)s NoUnique=rset.GetDataByName(colField2)s IndexName=$tr(IndexName,".")i '$d(MapObj(NoUnique,IndexName)) d.s MapObj(NoUnique,IndexName)=$lb(ColName)e  d.s MapObj(NoUnique,IndexName)=MapObj(NoUnique,IndexName)_$lb(ColName)}s NoUnique="" f  s NoUnique=$o(MapObj(NoUnique)) q:NoUnique=""  d.s IndexName="" f  s IndexName=$o(MapObj(NoUnique,IndexName)) q:IndexName=""  d..s NoUniqueStr=""..i NoUnique="0" s NoUniqueStr="unique"..s sql="create "_NoUniqueStr_" index "_TableName_"_"_IndexName_" on dbo."_TableName_" ("..s ListCol=$g(MapObj(NoUnique,IndexName))..f j=1:1:$ll(ListCol) d...s ColName=$lg(ListCol,j)...i j=1 s sql=sql_""""_ColName_""""...e  s sql=sql_","""_ColName_"""" ..s sql=sql_");"..i $l(file) d ..WriteLineWithCode(file,sql)i $l(file) d ..WriteLineWithCode(file,"")
}/// 构造生成索引语句
ClassMethod MakeOneFKSql(file, TableName)
{s TableName=$g(TableName)//替换下划线s tableName=$tr(TableName,"_")s rset = ##class(%ResultSet).%New()d rset.Prepare("SELECT constraint_name,column_name,referenced_table_name,referenced_column_name FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA='dbo' and TABLE_NAME='"_TableName_"'")s exeret=rset.Execute()s colCount=rset.GetColumnCount()s tableName="dbo."_TableNameWhile(rset.Next()){s outStr=""s colField=rset.GetColumnName(1)s fkName=rset.GetDataByName(colField)s colField1=rset.GetColumnName(2)s ColName=rset.GetDataByName(colField1)s colField2=rset.GetColumnName(3)s refTableName=rset.GetDataByName(colField2)i '$l(refTableName) continues colField3=rset.GetColumnName(4)s refColName=rset.GetDataByName(colField3)i '$l(refColName) continues sql="alter table dbo."_TableName_" add constraint "_TableName_"_"_fkName_" foreign key ("""_ColName_""") references dbo."_refTableName_" ("""_refColName_""");"i $l(file) d ..WriteLineWithCode(file,sql)}i $l(file) d ..WriteLineWithCode(file,"")
}/// 带编码转换写字符
ClassMethod WriteLineWithCode(file, str)
{d file.WriteLine(str)//d file.WriteLine($zcvt(str,"O","UTF8"))
}/// 去除不可见字符
ClassMethod DealNotSeeChar(Data As %String) As %String
{s Data=$g(Data)i $l(Data) d.f i=0:1:31  d..s Data=$tr(Data,$c(i)).s Data=$tr(Data,$c(127))q Data
}}

在这里插入图片描述

在这里插入图片描述

越来越接近发布了,像一个精致的艺术品,越来越喜欢了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/434004.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

接口测试怎么测?接口测试的流程和步骤(超详细)

&#x1f345; 视频学习&#xff1a;文末有免费的配套视频可观看 &#x1f345; 点击文末小卡片 &#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;薪资嘎嘎涨 一、什么是接口测试 我们要想知道接口测试怎么做&#xff0c;首先要明白接口测试是什么?一般…

<蓝桥杯软件赛>零基础备赛20周--第18周--动态规划初步

报名明年4月蓝桥杯软件赛的同学们&#xff0c;如果你是大一零基础&#xff0c;目前懵懂中&#xff0c;不知该怎么办&#xff0c;可以看看本博客系列&#xff1a;备赛20周合集 20周的完整安排请点击&#xff1a;20周计划 每周发1个博客&#xff0c;共20周。 在QQ群上交流答疑&am…

HCS-华为云Stack-FusionSphere

HCS-华为云Stack-FusionSphere FusionSphere是华为面向多行业客户推出的云操作系统解决方案。 FusionSphere基于开放的OpenStack架构&#xff0c;并针对企业云计算数据中心场景进行设计和优化&#xff0c;提供了强大的虚拟化功能和资源池管理能力、丰富的云基础服务组件和工具…

栈和队列的动态实现(C语言实现)

✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅ ✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨ &#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1f33f;&#x1…

【LeetCode】112. 路径总和(简单)——代码随想录算法训练营Day18

题目链接&#xff1a;112. 路径总和 题目描述 给你二叉树的根节点 root 和一个表示目标和的整数 targetSum 。判断该树中是否存在 根节点到叶子节点 的路径&#xff0c;这条路径上所有节点值相加等于目标和 targetSum 。如果存在&#xff0c;返回 true &#xff1b;否则&…

ENVI下基于知识决策树提取地表覆盖信息

基于知识的决策树分类是基于遥感影像数据及其他空间数据,通过专家经验总结、简单的数学统计和归纳方法等,获得分类规则并进行遥感分类。分类规则易于理解,分类过程也符合人的认知过程,最大的特点是利用的多源数据。 决策树分类主要的工作是获取规则,本文介绍使用CART算法…

第17章_反射机制(理解Class类并获取Class实例,类的加载与ClassLoader的理解,反射的基本应用,读取注解信息,体会反射的动态性)

文章目录 第17章_反射机制本章专题与脉络1. 反射(Reflection)的概念1.1 反射的出现背景1.2 反射概述1.3 Java反射机制研究及应用1.4 反射相关的主要API1.5 反射的优缺点 2. 理解Class类并获取Class实例2.1 理解Class2.1.1 理论上2.1.2 内存结构上 2.2 获取Class类的实例(四种方…

每日一题——LeetCode1346.检查整数及其两倍数是否存在

方法一 循环查找 用indexOf查找每个元素的两倍是否存在在数组中&#xff0c;找到了就直接return true&#xff0c;循环结束还没找到就return false var checkIfExist function(arr) {for(let i0;i<arr.length;i){let index arr.indexOf(arr[i]*2)if(index>0 &&…

小土堆pytorch学习笔记003 | 下载数据集dataset 及报错处理

目录 1、下载数据集 2、展示数据集里面的内容 3、DataLoader 的使用 例子&#xff1a; 结果展示&#xff1a; 1、下载数据集 # 数据集import torchvisiontrain_set torchvision.datasets.CIFAR10(root"./test10_dataset", trainTrue, downloadTrue) test_set …

CAD-autolisp(二)——选择集、命令行设置对话框、符号表

目录 一、选择集1.1 选择集的创建1.2 选择集的编辑1.3 操作选择集 二、命令行设置对话框2.1 设置图层2.2 加载线型2.3 设置字体样式2.4 设置标注样式&#xff08;了解即可&#xff09; 三、符号表3.1 简介3.2 符号表查找3.2 符号表删改增 一、选择集 定义&#xff1a;批量选择…

基于springboot+vue的校园资料分享平台(前后端分离)

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战 主要内容&#xff1a;毕业设计(Javaweb项目|小程序等)、简历模板、学习资料、面试题库、技术咨询 文末联系获取 项目背景…

VS如何打包环境

以VS2005为例子,做好的软件需要发给客户现场升级,有时候总是因为系统,环境变量不同导致软件不能正常运行打开,这也是程序员非常头疼的问题,今天我们就一起看下打包环境变量. 这样我们的环境变量就打包到setup中了,目标机台安装即可!!!