PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/jeecg-framework/src/main/java/test/JeecgInitDB.java

https://github.com/nic9805/jeecg
Java | 336 lines | 255 code | 27 blank | 54 comment | 2 complexity | 26f0257b9da1b14cac9c8763e499d4d8 MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception, MIT
  1. package test;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStreamWriter;
  6. import java.io.Writer;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.ResultSet;
  10. import java.sql.SQLException;
  11. import java.sql.Statement;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import org.jeecgframework.web.cgform.entity.config.CgFormFieldEntity;
  17. import org.jeecgframework.web.cgform.entity.config.CgFormHeadEntity;
  18. import org.jeecgframework.web.system.pojo.base.TSAttachment;
  19. import org.jeecgframework.web.system.pojo.base.TSBaseUser;
  20. import org.jeecgframework.web.system.pojo.base.TSDepart;
  21. import org.jeecgframework.web.system.pojo.base.TSFunction;
  22. import org.jeecgframework.web.system.pojo.base.TSLog;
  23. import org.jeecgframework.web.system.pojo.base.TSRole;
  24. import org.jeecgframework.web.system.pojo.base.TSType;
  25. import org.jeecgframework.web.system.pojo.base.TSTypegroup;
  26. import org.jeecgframework.web.system.pojo.base.TSUser;
  27. import freemarker.template.Configuration;
  28. import freemarker.template.DefaultObjectWrapper;
  29. import freemarker.template.Template;
  30. /**
  31. * @Description
  32. * @ClassName: JeecgInitDB
  33. * @author tanghan
  34. * @date 2013-7-19 下午04:24:51
  35. */
  36. public class JeecgInitDB {
  37. private static Connection con=null;
  38. public static Connection getConnection() throws ClassNotFoundException, SQLException{
  39. if(con == null){
  40. Class.forName("com.mysql.jdbc.Driver");
  41. con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jeecg", "root","root");
  42. }
  43. return con;
  44. }
  45. public static void main(String[] args) throws Exception {
  46. Configuration cfg = new Configuration();
  47. String sql1="select * from t_s_attachment";
  48. String sql2="select * from t_s_base_user";
  49. String sql3="select * from t_s_depart";
  50. String sql4="select * from t_s_role";
  51. String sql5="select * from t_s_user";
  52. String sql6="select * from t_s_typegroup";
  53. String sql7 = "select * from t_s_function";
  54. String sql8 = "select * from t_s_type";
  55. String sql9 = "select * from t_s_log limit 100";
  56. String sql10 = "select * from cgform_field where table_id ="; //此处由于需要更具cgform_head生成,故只能单个生成
  57. String sql11 = "select * from cgform_head ";
  58. Statement st=null;
  59. ResultSet rs=null;
  60. try {
  61. cfg.setDirectoryForTemplateLoading(new File("E:/Workspace-jeecg/jeecg-v3-simple-new/src/test"));
  62. cfg.setObjectWrapper(new DefaultObjectWrapper());
  63. Template temp = cfg.getTemplate("init.ftl","UTF-8");
  64. con=getConnection();
  65. st=con.createStatement();
  66. rs=st.executeQuery(sql1);
  67. int i=1;
  68. Map<String, Object> root = new HashMap<String, Object>();
  69. List att = new ArrayList();
  70. while(rs.next())
  71. {
  72. TSAttachment tsAttachment = new TSAttachment();
  73. tsAttachment.setId(i+"");
  74. tsAttachment.setAttachmenttitle(rs.getString("attachmenttitle"));
  75. tsAttachment.setRealpath(rs.getString("attachmenttitle"));
  76. tsAttachment.setSwfpath(rs.getString("swfpath"));
  77. tsAttachment.setExtend(rs.getString("extend"));
  78. att.add(tsAttachment);
  79. i++;
  80. }
  81. root.put("animals", att);
  82. rs=st.executeQuery(sql2);
  83. i=1;
  84. List user = new ArrayList();
  85. while(rs.next())
  86. {
  87. TSBaseUser baseUser = new TSBaseUser();
  88. baseUser.setId(i+"");
  89. baseUser.setUserKey(rs.getString("userkey"));
  90. baseUser.setStatus(rs.getShort("status"));
  91. baseUser.setRealName(rs.getString("realname"));
  92. baseUser.setUserName(rs.getString("username"));
  93. baseUser.setPassword(rs.getString("password"));
  94. baseUser.setActivitiSync(rs.getShort("activitisync"));
  95. user.add(baseUser);
  96. i++;
  97. }
  98. root.put("baseuser", user);
  99. rs=st.executeQuery(sql3);
  100. List dep = new ArrayList();
  101. i=1;
  102. while(rs.next())
  103. {
  104. TSDepart tsDepart = new TSDepart();
  105. tsDepart.setId(i+"");
  106. tsDepart.setDepartname(rs.getString("departname"));
  107. tsDepart.setDescription(rs.getString("description"));
  108. dep.add(tsDepart);
  109. i++;
  110. }
  111. root.put("depart", dep);
  112. rs=st.executeQuery(sql4);
  113. List role = new ArrayList();
  114. i=1;
  115. while(rs.next())
  116. {
  117. org.jeecgframework.core.util.LogUtil.info(rs.getString("rolename"));
  118. TSRole tsRole = new TSRole();
  119. tsRole.setId(i+"");
  120. tsRole.setRoleName(rs.getString("rolename"));
  121. tsRole.setRoleCode(rs.getString("rolecode"));
  122. role.add(tsRole);
  123. i++;
  124. }
  125. root.put("role", role);
  126. rs=st.executeQuery(sql5);
  127. List susers = new ArrayList();
  128. i=1;
  129. while(rs.next())
  130. {
  131. TSUser suer = new TSUser();
  132. suer.setId(i+"");
  133. // org.jeecgframework.core.util.LogUtil.info(rs.getString("signaturefile"));
  134. // suer.setSignatureFile(rs.getString("signaturefile"));
  135. suer.setMobilePhone(rs.getString("mobilephone"));
  136. suer.setOfficePhone(rs.getString("officephone"));
  137. suer.setEmail(rs.getString("email"));
  138. susers.add(suer);
  139. i++;
  140. }
  141. root.put("suser", susers);
  142. rs=st.executeQuery(sql6);
  143. List typegroup = new ArrayList();
  144. i=1;
  145. while(rs.next())
  146. {
  147. TSTypegroup tsTypegroup = new TSTypegroup();
  148. tsTypegroup.setId(i+"");
  149. // org.jeecgframework.core.util.LogUtil.info(rs.getString("signaturefile"));
  150. // suer.setSignatureFile(rs.getString("signaturefile"));
  151. tsTypegroup.setTypegroupname(rs.getString("typegroupname"));
  152. tsTypegroup.setTypegroupcode(rs.getString("typegroupcode"));
  153. typegroup.add(tsTypegroup);
  154. i++;
  155. }
  156. root.put("typegroup", typegroup);
  157. rs=st.executeQuery(sql7);
  158. List function = new ArrayList();
  159. i=1;
  160. while(rs.next())
  161. {
  162. TSFunction tsFunction = new TSFunction();
  163. tsFunction.setId(i+"");
  164. tsFunction.setFunctionName(rs.getString("functionName"));
  165. tsFunction.setFunctionUrl(rs.getString("functionUrl"));
  166. tsFunction.setFunctionLevel(rs.getShort("functionLevel"));
  167. tsFunction.setFunctionOrder(rs.getString("functionOrder"));
  168. function.add(tsFunction);
  169. i++;
  170. }
  171. root.put("menu", function);
  172. rs=st.executeQuery(sql8);
  173. List type = new ArrayList();
  174. i=1;
  175. while(rs.next())
  176. {
  177. TSType tsType = new TSType();
  178. tsType.setId(i+"");
  179. // org.jeecgframework.core.util.LogUtil.info(rs.getString("signaturefile"));
  180. // suer.setSignatureFile(rs.getString("signaturefile"));
  181. tsType.setTypename(rs.getString("typename"));
  182. tsType.setTypecode(rs.getString("typecode"));
  183. type.add(tsType);
  184. i++;
  185. }
  186. root.put("type", type);
  187. rs=st.executeQuery(sql9);
  188. List log = new ArrayList();
  189. i=1;
  190. while(rs.next())
  191. {
  192. TSLog slog = new TSLog();
  193. slog.setId(i+"");
  194. // org.jeecgframework.core.util.LogUtil.info(rs.getString("signaturefile"));
  195. // suer.setSignatureFile(rs.getString("signaturefile"));
  196. // tsType.setTypename(rs.getString("typename"));
  197. // tsType.setTypecode(rs.getString("typecode"));
  198. // type.add(tsType);
  199. slog.setId(i+"");
  200. // org.jeecgframework.core.util.LogUtil.info(rs.getString("logcontent"));
  201. slog.setLogcontent(rs.getString("logcontent"));
  202. slog.setLoglevel(rs.getShort("loglevel"));
  203. slog.setBroswer(rs.getString("broswer"));
  204. slog.setNote(rs.getString("note"));
  205. slog.setOperatetime(rs.getTimestamp("operatetime"));
  206. slog.setOperatetype(rs.getShort("operatetype"));
  207. log.add(slog);
  208. i++;
  209. }
  210. root.put("log", log);
  211. rs=st.executeQuery(sql11);
  212. List cghead = new ArrayList();
  213. i=1;
  214. while(rs.next())
  215. {
  216. CgFormHeadEntity head = new CgFormHeadEntity();
  217. head.setId(i+"");
  218. head.setTableName(rs.getString("table_name"));
  219. head.setIsTree(rs.getString("is_tree"));
  220. head.setIsPagination(rs.getString("is_pagination"));
  221. head.setQuerymode(rs.getString("queryMode"));
  222. head.setIsCheckbox(rs.getString("is_checkbox"));
  223. head.setIsDbSynch(rs.getString("is_dbsynch"));
  224. head.setContent(rs.getString("content"));
  225. head.setJformVersion(rs.getString("JFORM_VERSION"));
  226. head.setJformType(rs.getInt("jform_type"));
  227. head.setColumns(getCgFormItem(sql10, rs.getString("id")));
  228. cghead.add(head);
  229. i++;
  230. }
  231. root.put("cghead", cghead);
  232. // rs=st.executeQuery(sql10);
  233. // List cgfield = new ArrayList();
  234. // i=1;
  235. // while(rs.next())
  236. // {
  237. // CgFormFieldEntity filed = new CgFormFieldEntity();
  238. // filed.setFieldName(rs.getString("field_name"));
  239. // filed.setLength(rs.getInt("length"));
  240. // filed.setType(rs.getString("type"));
  241. // filed.setPointLength(rs.getInt("point_length"));
  242. // filed.setIsNull(rs.getString("is_null"));
  243. // filed.setIsKey(rs.getString("is_key"));
  244. // filed.setIsQuery(rs.getString("is_query"));
  245. // filed.setIsShow(rs.getString("is_show"));
  246. // filed.setShowType(rs.getString("show_type"));
  247. // filed.setOrderNum(rs.getInt("order_num"));
  248. // filed.setFieldHref(rs.getString("field_href"));
  249. // filed.setFieldLength(rs.getInt("field_length"));
  250. // filed.setFieldValidType(rs.getString("field_valid_type"));
  251. // filed.setQueryMode(rs.getString("query_mode"));
  252. // filed.setContent(rs.getString("content"));
  253. // filed.setDictTable(rs.getString("dict_table"));
  254. // filed.setDictField(rs.getString("dict_field"));
  255. // filed.setMainField(rs.getString("main_field"));
  256. // filed.setMainTable(rs.getString("main_table"));
  257. // cgfield.add(filed);
  258. // i++;
  259. // }
  260. // root.put("cgfield", cgfield);
  261. Writer out = new OutputStreamWriter(new FileOutputStream("RepairServiceImpl.java"), "UTF-8");
  262. temp.process(root, out);
  263. out.flush();
  264. out.close();
  265. org.jeecgframework.core.util.LogUtil.info("Successfull................");
  266. } catch (IOException e) {
  267. e.printStackTrace();
  268. }
  269. }
  270. /**
  271. * 获取表单字段方法
  272. * @param sql10
  273. * @param cgformhead_id
  274. * @return
  275. * @throws Exception
  276. */
  277. public static List getCgFormItem(String sql10,String cgformhead_id) throws Exception{
  278. Statement st =con.createStatement();
  279. ResultSet rs = st.executeQuery(sql10+"'"+cgformhead_id.trim()+"'");
  280. List cgfield = new ArrayList();
  281. int i=1;
  282. while(rs.next())
  283. {
  284. CgFormFieldEntity filed = new CgFormFieldEntity();
  285. filed.setFieldName(rs.getString("field_name"));
  286. filed.setLength(rs.getInt("length"));
  287. filed.setType(rs.getString("type"));
  288. filed.setPointLength(rs.getInt("point_length"));
  289. filed.setIsNull(rs.getString("is_null"));
  290. filed.setIsKey(rs.getString("is_key"));
  291. filed.setIsQuery(rs.getString("is_query"));
  292. filed.setIsShow(rs.getString("is_show"));
  293. filed.setShowType(rs.getString("show_type"));
  294. filed.setOrderNum(rs.getInt("order_num"));
  295. filed.setFieldHref(rs.getString("field_href"));
  296. filed.setFieldLength(rs.getInt("field_length"));
  297. filed.setFieldValidType(rs.getString("field_valid_type"));
  298. filed.setQueryMode(rs.getString("query_mode"));
  299. filed.setContent(rs.getString("content"));
  300. filed.setDictTable(rs.getString("dict_table"));
  301. filed.setDictField(rs.getString("dict_field"));
  302. filed.setMainField(rs.getString("main_field"));
  303. filed.setMainTable(rs.getString("main_table"));
  304. cgfield.add(filed);
  305. i++;
  306. }
  307. return cgfield;
  308. }
  309. }