Commit 9cc440ee7617623fc4e0f9f9a287f2604a741485

Authored by 王彬
0 parents
Exists in master

1.初次提交

Showing 59 changed files with 7995 additions and 0 deletions   Show diff stats
.gitignore 0 → 100644
  1 +++ a/.gitignore
... ... @@ -0,0 +1,11 @@
  1 +bin
  2 +.project
  3 +.classpath
  4 +.settings
  5 +.idea/compiler.xml
  6 +.idea/copyright/
  7 +.idea/misc.xml
  8 +.idea/modules.xml
  9 +.idea/taover-java-generater.iml
  10 +.idea/workspace.xml
  11 +src/default.properties
... ...
lib/commons-lang-2.6.jar 0 → 100644
No preview for this file type
lib/freemarker-2.3.15.jar 0 → 100644
No preview for this file type
lib/mysql-connector-java-5.1.26-bin.jar 0 → 100644
No preview for this file type
src/com/taover/base/template/.svn/entries 0 → 100644
  1 +++ a/src/com/taover/base/template/.svn/entries
... ... @@ -0,0 +1,133 @@
  1 +10
  2 +
  3 +dir
  4 +115305
  5 +svn://119.254.17.138/repos/%E6%B2%B1%E6%B2%B1%E7%94%9F%E6%B4%BB%E7%BD%91%E8%B6%85/code/soa.tootoo.cn/trunk/generate-tootoo-dao-po/src/cn/tootoo/base/template
  6 +svn://119.254.17.138/repos
  7 +
  8 +
  9 +
  10 +2015-02-04T12:03:01.165689Z
  11 +87604
  12 +zhuruisong
  13 +
  14 +
  15 +svn:special svn:externals svn:needs-lock
  16 +
  17 +
  18 +
  19 +
  20 +
  21 +
  22 +
  23 +
  24 +
  25 +
  26 +
  27 +5351f05e-98f4-42cc-8e6a-33022518c94f
  28 +
  29 +DAOTemplate.ftl
  30 +file
  31 +120059
  32 +
  33 +
  34 +
  35 +2015-08-26T08:17:12.564000Z
  36 +56d88466e50d589a4459ed064d4ac052
  37 +2015-09-10T02:21:44.128446Z
  38 +120059
  39 +wangzhangyu
  40 +
  41 +
  42 +
  43 +
  44 +
  45 +
  46 +
  47 +
  48 +
  49 +
  50 +
  51 +
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +66099
  62 +
  63 +POTemplate.ftl
  64 +file
  65 +
  66 +
  67 +
  68 +
  69 +2015-08-10T05:52:55.994000Z
  70 +1738d433df84ecb7349bfaf1f38109d4
  71 +2014-07-16T08:31:16.396207Z
  72 +66550
  73 +wangpeng
  74 +
  75 +
  76 +
  77 +
  78 +
  79 +
  80 +
  81 +
  82 +
  83 +
  84 +
  85 +
  86 +
  87 +
  88 +
  89 +
  90 +
  91 +
  92 +
  93 +
  94 +
  95 +3290
  96 +
  97 +createTableTemplate.ftl
  98 +file
  99 +
  100 +
  101 +
  102 +
  103 +2015-08-10T05:52:55.971000Z
  104 +77e6408085e1fc552a74e199f2c0b762
  105 +2014-10-17T09:18:28.728707Z
  106 +76466
  107 +zhuruisong
  108 +
  109 +
  110 +
  111 +
  112 +
  113 +
  114 +
  115 +
  116 +
  117 +
  118 +
  119 +
  120 +
  121 +
  122 +
  123 +
  124 +
  125 +
  126 +
  127 +
  128 +
  129 +1127
  130 +
  131 +model
  132 +dir
  133 +
... ...
src/com/taover/base/template/.svn/text-base/DAOTemplate.ftl.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/.svn/text-base/DAOTemplate.ftl.svn-base
... ... @@ -0,0 +1,1545 @@
  1 +//${tableName}
  2 +<#--包名 -->
  3 +package ${packages}
  4 +
  5 +<#-- 所有的引入-->
  6 +<#list imports as ilist>
  7 +<#if ilist?exists>${ilist}<#else><#rt></#if>
  8 +</#list>
  9 +import java.math.BigDecimal;
  10 +
  11 +/**
  12 + <#if version?exists>
  13 + * @version ${version}
  14 + </#if>
  15 + */
  16 +
  17 +<#--类, 还是接口 名称, 继承的类, 实现的接口 -->
  18 +public class ${beanName}Dao {
  19 +<#--变量 -->
  20 +<#if propertys?exists>
  21 +<#list propertys as prolist>
  22 + <#if prolist?exists>
  23 + ${prolist}<#rt></#if>
  24 +</#list>
  25 +</#if>
  26 +
  27 + /**
  28 + * 初始化
  29 + */
  30 + public ${beanName}Dao() {
  31 + }
  32 +
  33 + /**
  34 + * 初始化
  35 + */
  36 + public ${beanName}Dao(String uuid) {
  37 + this.uuid = uuid;
  38 + }
  39 +
  40 + /**
  41 + * 初始化
  42 + */
  43 + public ${beanName}Dao(String uuid, Logger logger) {
  44 + this.uuid = uuid;
  45 +// if(logger != null){
  46 +// this.logger = logger;
  47 +// }
  48 + }
  49 +
  50 + /**
  51 + * 提交
  52 + */
  53 + public void commit() {
  54 + JdbcUtil.commit(writeConnectionName);
  55 + }
  56 +
  57 + /**
  58 + * 回滚
  59 + */
  60 + public void rollback() {
  61 + JdbcUtil.rollback(writeConnectionName);
  62 + }
  63 +
  64 + /**
  65 + * 初始化cacheColums
  66 + */
  67 + public static void initCache() {
  68 + cacheColums = new ArrayList<String>();
  69 + }
  70 +
  71 + /**
  72 + * 线程修改cacheColums
  73 + */
  74 + public static void threadResetCache(ArrayList<String> list) {
  75 + if (cacheColums == null)
  76 + initCache();
  77 + cacheColums.clear();
  78 + for (int i = 0; i < list.size(); i++)
  79 + cacheColums.add((String) list.get(i));
  80 + }
  81 +
  82 + /**
  83 + * 重置cache
  84 + */
  85 + public void resetCache(final List<${beanName}PO> list) {
  86 + if (null == list || list.size() <= 0)
  87 + return;
  88 + Thread thread = new Thread() {
  89 + public void run() {
  90 + List<String> haveResetList = new ArrayList<String>();
  91 + for (${beanName}PO po : list) {
  92 + Memcached.delete("1_${tableName}_PK_" + po.get${pkBeanName}());
  93 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"一级缓存删除 key[1_${tableName}_PK_" + po.get${pkBeanName}() + "]");
  94 + Long keyTime = System.currentTimeMillis();
  95 + for (int i = 0; i < cacheColums.size(); i++) {
  96 + String key = (String) cacheColums.get(i);
  97 + String cache_key = "2_${tableName}_" + key + "_" + StringUtil.getValueFromObjectByName(po, key);
  98 + if (!haveResetList.contains(cache_key)) {
  99 + Memcached.add(2, cache_key, keyTime);
  100 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  101 + haveResetList.add(cache_key);
  102 + }
  103 + }
  104 + }
  105 + Memcached.add(4, "4_${tableName}", System.currentTimeMillis());
  106 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  107 + }
  108 + };
  109 + thread.start();
  110 + }
  111 +
  112 + /**
  113 + * 从缓存中获取缓存列
  114 + */
  115 + public Object[] getCacheColFromCache(List<Object[]> condition) {
  116 + Object[] obj = { null, null };
  117 + for (Object[] arg : condition) {
  118 + if (cacheColums.contains((String) arg[0])) {
  119 + if(!"=".equals((String)arg[1])){ //操作符为"="允许使用缓存列
  120 + continue;
  121 + }
  122 + obj[0] = arg[0] + "_" + arg[2];
  123 + obj[1] = Memcached.get("2_${tableName}_" + obj[0]);
  124 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存获取 key["+obj[0]+"],value["+obj[1]+"]");
  125 + return obj;
  126 + }
  127 + }
  128 + return null;
  129 + }
  130 +
  131 + /**
  132 + * 根据Request Map 生成PO对象
  133 + */
  134 + public ${beanName}PO get${beanName}POFromRequest(Map<String, Object> map) throws Exception {
  135 + ${beanName}PO po = new ${beanName}PO();
  136 + <#if reqParameterToPOMap?exists>
  137 + <#list reqParameterToPOMap?keys as poKey>
  138 + po.set${reqParameterToPOMap[poKey]};
  139 + </#list>
  140 + </#if>
  141 + return po;
  142 + }
  143 +
  144 + /**
  145 + * 按主键查询
  146 + */
  147 + public ${beanName}PO find${beanName}POByID(${pkType} id) {
  148 + return find${beanName}POByID(id, false, true, true, false);
  149 + }
  150 +
  151 + /**
  152 + * 按主键查询
  153 + * isLock 是否锁定, 默认不锁
  154 + * isUseCache 是否用缓存, 默认用
  155 + * isAddCache 查询结果是否添加到缓存, 默认添加
  156 + */
  157 + public ${beanName}PO find${beanName}POByID(${pkType} id, boolean isLock, boolean isUseCache, boolean isAddCache, boolean fromWriteDB) {
  158 + Date starttime = null;
  159 + if (isLogInfo()) {
  160 + starttime = new Date();
  161 + }
  162 + if (isUseCache) {// 从缓存中查询
  163 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"从一级缓存中查询,查询条件"+id);
  164 + Object obj = Memcached.get("1_${tableName}_PK_" + id);
  165 + if (obj != null) {
  166 + if (isLogInfo()) {
  167 + Date endtime = new Date();
  168 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  169 + "${beanName}Dao.find${beanName}POByID(" + id + ", " + isLock + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  170 + + "一级缓存命中 key[1_${tableName}_PK_" + id +"]\n"+uuid
  171 + + "一级缓存查询结果:" + ((${beanName}PO) obj).toString() +"\n"+uuid
  172 + + "一级缓存查询时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  173 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  174 + + "*-*"
  175 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  176 + + ")");
  177 + }
  178 + return (${beanName}PO) obj;
  179 + }
  180 + }
  181 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName}");
  182 + StringBuffer pql = new StringBuffer(sql.toString());
  183 + sql.append(" WHERE ${pkColumName} = ?");
  184 + pql.append(" WHERE ${pkColumName} = " + id);
  185 + if (isLock) {
  186 + sql.append(" FOR UPDATE");
  187 + pql.append(" FOR UPDATE");
  188 + }
  189 + List<${beanName}PO> resultList = null;
  190 + try {
  191 + if (isLogInfo()) {
  192 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  193 + "${beanName}Dao.find${beanName}POByID(" + id + ", " + isLock + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  194 + + "连接名:" + (isLock ? writeConnectionName : (fromWriteDB ? writeConnectionName : readConnectionName)) + "\n"+uuid
  195 + + "准备执行SQL:" + pql.toString());
  196 + }
  197 + resultList = JdbcUtil.executeQuery(uuid, (isLock ? writeConnectionName : (fromWriteDB ? writeConnectionName : readConnectionName)), sql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), id);
  198 + if (resultList == null || resultList.size() == 0) {
  199 + Memcached.delete("1_${tableName}_PK_" + id);
  200 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"一级缓存删除 key[1_${tableName}_PK_" + id + "]");
  201 + return null;
  202 + }
  203 + if (isAddCache) {// 把结果添加到缓存
  204 + Memcached.add(1, "1_${tableName}_PK_" + id, resultList.get(0));
  205 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"一级缓存添加 key[1_${tableName}_PK_" + id + "]");
  206 + }
  207 + return resultList.get(0);
  208 + } catch (Exception e) {
  209 + Log.error("error:[UUID:"+uuid+"]", logger, e, pql.toString(), id);
  210 + } finally {
  211 + if (isLogInfo()) {
  212 + Date endtime = new Date();
  213 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  214 + "${beanName}Dao.find${beanName}POByID(" + id + ", " + isLock + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  215 + + "连接名:" + (isLock ? writeConnectionName : (fromWriteDB ? writeConnectionName : readConnectionName)) + "\n"+uuid
  216 + + "执行SQL:" + pql.toString() + "\n"+uuid
  217 + + "返回数据条数:" + (resultList==null?0:resultList.size()) + "\n"+uuid
  218 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  219 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  220 + + "*-*"
  221 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  222 + + ")");
  223 + }
  224 + }
  225 + return null;
  226 + }
  227 +
  228 + /**
  229 + * 根据条件List<Object[]>查询
  230 + * Object[]数组长度是3
  231 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  232 + */
  233 + public List<${beanName}PO> find${beanName}POListByCondition(List<Object[]> condition) {
  234 + return find${beanName}POListByCondition(condition, true, true, false);
  235 + }
  236 +
  237 + /**
  238 + * 根据条件List<Object[]>查询
  239 + * Object[]数组长度是3
  240 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  241 + * boolean isUseCache, 是否用缓存,默认用。
  242 + * boolean isAddCache, 是否添加缓存,默认添加。
  243 + */
  244 + public List<${beanName}PO> find${beanName}POListByCondition(List<Object[]> condition, boolean isUseCache, boolean isAddCache, boolean fromWriteDB) {
  245 + if (StringUtil.isAutowired(condition)) {
  246 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  247 + return null;
  248 + }
  249 + Date starttime = null;
  250 + if (isLogInfo()) {
  251 + starttime = new Date();
  252 + }
  253 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName}");
  254 + StringBuffer pql = new StringBuffer(sql.toString());
  255 + List<Object> list = new ArrayList<Object>();
  256 + JdbcUtil.appendWhereCondition(sql, pql, list, condition);
  257 + List<${beanName}PO> resultList = null;
  258 + Object oColumAndTimeKey[] = null;
  259 + Object oTime = null;
  260 + if (isUseCache) {// 从缓存中查询
  261 +
  262 + Log.info(logger,uuid,"从二级缓存中查询","查询条件",StringUtil.transferObjectList(condition));
  263 + oColumAndTimeKey = getCacheColFromCache(condition);
  264 + oTime = (oColumAndTimeKey == null) ? null : oColumAndTimeKey[1];
  265 + if (null != oTime) {
  266 + Object object = Memcached.get("3_" + MD5.md5(pql.toString() + oTime.toString()));
  267 + if (object != null) {
  268 + List<${beanName}PO> r = (List<${beanName}PO>) object;
  269 + if (isLogInfo()) {
  270 + Date endtime = new Date();
  271 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  272 + "${beanName}Dao.find${beanName}POListByCondition(" + condition.toString() + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  273 + + "二级三级缓存命中 key[3_" + MD5.md5(pql.toString() + oTime.toString()) + "]\n"+uuid
  274 + + "三级缓存查询返回条数:" + (r==null?0:r.size()) + "\n"+uuid
  275 + + "三级缓存查询时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  276 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  277 + + "*-*"
  278 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  279 + + ")");
  280 + }
  281 + return r;
  282 + }
  283 + }
  284 + }
  285 + try {
  286 + if (isLogInfo()) {
  287 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  288 + "${beanName}Dao.find${beanName}POListByCondition(" + condition.toString() + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  289 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  290 + + "准备执行SQL:" + pql.toString() );
  291 +
  292 + }
  293 + resultList = JdbcUtil.executeQuery(uuid, fromWriteDB ? writeConnectionName : readConnectionName, sql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), list.toArray());
  294 + if (isAddCache) {// 把结果添加到缓存
  295 + if (oColumAndTimeKey == null && !isUseCache)
  296 + oColumAndTimeKey = getCacheColFromCache(condition);
  297 + if (oColumAndTimeKey != null) {
  298 + if (oColumAndTimeKey[1] == null) {
  299 + oColumAndTimeKey[1] = System.currentTimeMillis();
  300 + Memcached.add(2, "2_${tableName}_" + oColumAndTimeKey[0], oColumAndTimeKey[1]);
  301 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存添加 key[2_${tableName}_" + oColumAndTimeKey[0] + "]" );
  302 + }
  303 + Memcached.add(3, "3_" + MD5.md5(pql.toString() + oColumAndTimeKey[1]), resultList);
  304 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"三级缓存添加 key[3_" + MD5.md5(pql.toString() + oColumAndTimeKey[1]) + "]" );
  305 + }
  306 + }
  307 + return resultList;
  308 + } catch (Exception e) {
  309 + Log.error("error:[UUID:"+uuid+"]", logger, e, pql.toString(), null);
  310 + } finally {
  311 + if (isLogInfo()) {
  312 + Date endtime = new Date();
  313 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  314 + "${beanName}Dao.find${beanName}POListByCondition(" + condition.toString() + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  315 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  316 + + "执行SQL:" + pql.toString() + "\n"+uuid
  317 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"+uuid
  318 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  319 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  320 + + "*-*"
  321 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  322 + + ")");
  323 +
  324 + }
  325 + }
  326 + return null;
  327 + }
  328 +
  329 + /**
  330 + * 根据条件sql查询
  331 + * sqlCondition 为where 后面的条件。
  332 + */
  333 + public List<${beanName}PO> find${beanName}POListBySql(String sqlCondition) {
  334 + return find${beanName}POListBySql(sqlCondition, true, true, false);
  335 + }
  336 +
  337 + /**
  338 + * 根据条件sql查询
  339 + * sqlCondition 为where 后面的条件。
  340 + */
  341 + public List<${beanName}PO> find${beanName}POListBySql(String sqlCondition, boolean isUseCache, boolean isAddCache, boolean fromWriteDB) {
  342 + if (StringUtil.isAutowired(sqlCondition)) {
  343 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  344 + return null;
  345 + }
  346 + Date starttime = null;
  347 + if (isLogInfo()) {
  348 + starttime = new Date();
  349 + }
  350 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName} WHERE " + sqlCondition);
  351 + List<${beanName}PO> resultList = null;
  352 + Object oTime = null;
  353 + if (isUseCache) {// 从缓存中查询
  354 + oTime = Memcached.get("4_${tableName}");
  355 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存中获取 key[4_${tableName}],value[" + oTime + "]");
  356 + if (null != oTime) {
  357 + Object object = Memcached.get("3_" + MD5.md5(sql.toString() + oTime.toString()));
  358 + if (null != object) {
  359 + List<${beanName}PO> r = (List<${beanName}PO>) object;
  360 + if (isLogInfo()) {
  361 + Date endtime = new Date();
  362 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  363 + "${beanName}Dao.find${beanName}POListBySql(" + sqlCondition + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  364 + + "四级三级缓存命中 key[3_" + MD5.md5(sql.toString() + oTime.toString()) + "]\n"+uuid
  365 + + "三级缓存返回条数:" + (r==null?0:r.size()) + "\n"+uuid
  366 + + "三级缓存查询时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  367 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  368 + + "*-*"
  369 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  370 + + ")");
  371 + }
  372 + return r;
  373 + }
  374 + }
  375 + }
  376 + try {
  377 + if (isLogInfo()) {
  378 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  379 + "${beanName}Dao.find${beanName}POListBySql(" + sqlCondition + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  380 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"
  381 + + "准备执行SQL:" + sql.toString() );
  382 + }
  383 + resultList = JdbcUtil.executeQuery(uuid, fromWriteDB ? writeConnectionName : readConnectionName, sql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class));
  384 + if (isAddCache) {// 重置缓存
  385 + long keyTime = 0;
  386 + if (oTime != null) {
  387 + keyTime = (Long) oTime;
  388 + } else {
  389 + keyTime = System.currentTimeMillis();
  390 + Memcached.add(4, "4_${tableName}", keyTime);
  391 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  392 + }
  393 + Memcached.add(3, "3_" + MD5.md5(sql.toString() + keyTime), resultList);
  394 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"三级缓存添加 key[3_" + MD5.md5(sql.toString() + keyTime) + "]");
  395 + }
  396 + return resultList;
  397 + } catch (Exception e) {
  398 + Log.error("error:[UUID:"+uuid+"]", logger, e, sql.toString(), null);
  399 + } finally {
  400 + if (isLogInfo()) {
  401 + Date endtime = new Date();
  402 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  403 + "${beanName}Dao.find${beanName}POListBySql(" + sqlCondition + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  404 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  405 + + "执行SQL:" + sql.toString() + "\n"
  406 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"+uuid
  407 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  408 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  409 + + "*-*"
  410 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  411 + + ")");
  412 + }
  413 + }
  414 + return null;
  415 + }
  416 +
  417 + /**
  418 + * 按条件分页查询
  419 + * Object[]数组长度是3
  420 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  421 + */
  422 + public Map<String, Object> findPageByCondition(List<Object[]> condition, int page, int pageSize, String sortCondition) {
  423 + return findPageByCondition(condition, page, pageSize, true, true, sortCondition, false);
  424 + }
  425 +
  426 + /**
  427 + * 按条件分页查询
  428 + * Object[]数组长度是3
  429 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  430 + * boolean isUseCache, 是否用缓存,默认用。
  431 + * boolean isAddCache, 是否添加缓存,默认添加。
  432 + */
  433 + public Map<String, Object> findPageByCondition(List<Object[]> condition, int page, int pageSize, boolean isUseCache, boolean isAddCache, String sortCondition, boolean fromWriteDB) {
  434 + if (StringUtil.isAutowired(condition)) {
  435 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  436 + return null;
  437 + }
  438 + Date starttime = null;
  439 + if (isLogInfo()) {
  440 + starttime = new Date();
  441 + }
  442 + <#if dbType = "mysql">
  443 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName}");
  444 + StringBuffer pql = new StringBuffer(sql.toString());
  445 + <#else>
  446 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str}, ROWNUM RN FROM ${tableName}");
  447 + StringBuffer pql = new StringBuffer(sql.toString());
  448 + </#if>
  449 + StringBuffer sqlCount = new StringBuffer("SELECT COUNT(1) FROM ${tableName}");
  450 +
  451 + List<Object> count_list = new ArrayList<Object>();
  452 + List<Object> page_list = new ArrayList<Object>();
  453 + JdbcUtil.appendWhereConditionForCount(sqlCount, condition);
  454 + JdbcUtil.appendWhereCondition(sql, pql, count_list, condition);
  455 + for (int i = 0; i < count_list.size(); i++)
  456 + page_list.add(count_list.get(i));
  457 +
  458 + <#if dbType == "mysql">
  459 + page_list.add((page - 1) * pageSize);
  460 + page_list.add(page * pageSize);
  461 + if(StringUtil.isEmpty(sortCondition)){
  462 + String pageSql = sql.toString() + " limit ?, ?";
  463 + String pagePql = pql.toString() + " limit " + (page -1) * pageSize + ", " + page * pageSize;
  464 + }else{
  465 + String pageSql = sql.toString() + sortCondition + " limit ?, ?";
  466 + String pagePql = pql.toString() + sortCondition + " limit " + (page -1) * pageSize + ", " + page * pageSize;
  467 + }
  468 +
  469 + <#else>
  470 + String pageSql = null;
  471 + String pagePql = null;
  472 + if (page_list.size() == 0) {
  473 + if(StringUtil.isEmpty(sortCondition)){
  474 + pageSql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= ?" + ") A WHERE A.RN >= ?";
  475 + pagePql = "SELECT * FROM (" + pql.toString() + " AND ROWNUM <= " + page * pageSize + ") A WHERE A.RN >= " + ((page -1) * pageSize + 1);
  476 + }else{
  477 + pageSql = "SELECT * FROM (SELECT B.*,ROWNUM RNN FROM (" + sql.toString() + " " + sortCondition + ") B WHERE ROWNUM <= ?"+" ) A WHERE A.RNN >= ?";
  478 + pagePql = "SELECT * FROM (SELECT B.*,ROWNUM RNN FROM (" + pql.toString() + " " + sortCondition + ") B WHERE ROWNUM <= " + page * pageSize + ") A WHERE A.RNN >= " + ((page -1) * pageSize + 1);
  479 + }
  480 +
  481 + } else {
  482 + if(StringUtil.isEmpty(sortCondition)){
  483 + pageSql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= ?" + ") A WHERE A.RN >= ?";
  484 + pagePql = "SELECT * FROM (" + pql.toString() + " AND ROWNUM <= " + page * pageSize + ") A WHERE A.RN >= " + ((page -1) * pageSize + 1);
  485 + }else{
  486 + pageSql = "SELECT * FROM (SELECT B.*,ROWNUM RNN FROM (" + sql.toString() + " " + sortCondition + ") B WHERE ROWNUM <= ?"+" ) A WHERE A.RNN >= ?";
  487 + pagePql = "SELECT * FROM (SELECT B.*,ROWNUM RNN FROM (" + pql.toString() + " " + sortCondition + ") B WHERE ROWNUM <= " + page * pageSize + ") A WHERE A.RNN >= " + ((page -1) * pageSize + 1);
  488 + }
  489 + }
  490 + page_list.add(page * pageSize);
  491 + page_list.add((page - 1) * pageSize + 1);
  492 + </#if>
  493 +
  494 + Object oColumAndTimeKey[] = null;
  495 + Object oTime = null;
  496 + if (isUseCache) {// 从缓存中查询
  497 + Log.info(logger,uuid,"从二级缓存中查询","查询条件",StringUtil.transferObjectList(condition));
  498 + oColumAndTimeKey = getCacheColFromCache(condition);
  499 + oTime = (oColumAndTimeKey == null) ? null : oColumAndTimeKey[1];
  500 + if (null != oTime) {
  501 + Object object = Memcached.get("3_" + MD5.md5(pagePql.toString() + oTime.toString()));
  502 + if (null != object) {
  503 + if (isLogInfo()) {
  504 + Date endtime = new Date();
  505 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  506 + "${beanName}Dao.findPageByCondition(" + condition.toString() + ", " + page + ", " + pageSize + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  507 + + "二级三级缓存命中 key[3_" + MD5.md5(pagePql.toString() + oTime.toString()) + "]\n"+uuid
  508 + + "三级缓存返回条数:" + (((Map<String, Object>) object).get("list") == null?0:((List<${beanName}PO>)((Map<String, Object>) object).get("list")).size()) + "\n"+uuid
  509 + + "三级缓存查询时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  510 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  511 + + "*-*"
  512 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  513 + + ")");
  514 + }
  515 + return (Map<String, Object>) object;
  516 + }
  517 + }
  518 + }
  519 + List<${beanName}PO> resultList = null;
  520 + try {
  521 + if (isLogInfo()) {
  522 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  523 + "${beanName}Dao.findPageByCondition(" + condition.toString() + ", " + page + ", " + pageSize + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  524 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  525 + + "准备执行SQL:" + pagePql.toString() );
  526 + }
  527 + int totalPages = 0;
  528 + int totalRows = JdbcUtil.queryForInt(uuid, fromWriteDB ? writeConnectionName : readConnectionName, sqlCount.toString(), count_list.toArray()) ;
  529 + if (totalRows % pageSize == 0) {
  530 + totalPages = totalRows / pageSize;
  531 + } else {
  532 + totalPages = (totalRows / pageSize) + 1;
  533 + }
  534 + Map<String, Object> resultMap = new HashMap<String, Object>();
  535 + resultMap.put("rows", totalRows);
  536 + resultMap.put("page", page);
  537 + resultMap.put("records", totalRows);
  538 + resultMap.put("total", totalPages);
  539 + resultList = JdbcUtil.executeQuery(uuid, fromWriteDB ? writeConnectionName : readConnectionName, pageSql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), page_list.toArray());
  540 + resultMap.put("list", resultList);
  541 + if (isAddCache) {// 把结果添加到缓存
  542 + if (oColumAndTimeKey == null && !isUseCache)
  543 + oColumAndTimeKey = getCacheColFromCache(condition);
  544 + if (oColumAndTimeKey != null) {
  545 + if (oColumAndTimeKey[1] == null) {
  546 + oColumAndTimeKey[1] = System.currentTimeMillis();
  547 + Memcached.add(2, "2_${tableName}_" + oColumAndTimeKey[0], oColumAndTimeKey[1]);
  548 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[2_${tableName}_" + oColumAndTimeKey[0] + "]");
  549 + }
  550 + Memcached.add(3, "3_" + MD5.md5(pagePql.toString() + oColumAndTimeKey[1]), resultMap);
  551 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"三级缓存添加 key[3_" + MD5.md5(pagePql.toString() + oColumAndTimeKey[1]) + "]");
  552 + }
  553 + }
  554 + return resultMap;
  555 + } catch (Exception e) {
  556 + Log.error("error:[UUID:"+uuid+"]", logger, e, pagePql.toString(), page_list.toArray());
  557 + } finally {
  558 + if (isLogInfo()) {
  559 + Date endtime = new Date();
  560 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  561 + "${beanName}Dao.findPageByCondition(" + condition.toString() + ", " + page + ", " + pageSize + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  562 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  563 + + "执行SQL:" + pagePql.toString() + "\n"+uuid
  564 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"+uuid
  565 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  566 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  567 + + "*-*"
  568 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  569 + + ")");
  570 + }
  571 + }
  572 + return null;
  573 + }
  574 +
  575 + /**
  576 + * 按sql分页查询, sqlCondition为where 后条件sql
  577 + */
  578 + public Map<String, Object> findPageBySql(String sqlCondition, int page, int pageSize, String sortCondition) {
  579 + return findPageBySql(sqlCondition, page, pageSize, true, true, sortCondition, false);
  580 + }
  581 +
  582 + /**
  583 + * 按sql分页查询, sqlCondition为where 后条件sql
  584 + */
  585 + public Map<String, Object> findPageBySql(String sqlCondition, int page, int pageSize, boolean isUseCache, boolean isAddCache, String sortCondition, boolean fromWriteDB) {
  586 + if (StringUtil.isAutowired(sqlCondition)) {
  587 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  588 + return null;
  589 + }
  590 + Date starttime = null;
  591 + if (isLogInfo()) {
  592 + starttime = new Date();
  593 + }
  594 +
  595 + <#if dbType = "mysql">
  596 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName} WHERE " + sqlCondition + sortCondition);
  597 + StringBuffer sqlCount = new StringBuffer("SELECT count(1) from ${tableName} WHERE " + sqlCondition);
  598 + String pageSql = sql.toString() + " limit ?, ?";
  599 + String pagePql = sql.toString() + " limit " + ((page -1) * pageSize) + ", " + (page * pageSize);
  600 + List<Object> page_list = new ArrayList<Object>();
  601 + page_list.add((page - 1) * pageSize);
  602 + page_list.add(page * pageSize);
  603 + <#else>
  604 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str}, ROWNUM RN FROM ${tableName} WHERE " + sqlCondition);
  605 + StringBuffer sqlCount = new StringBuffer("SELECT count(1) from ${tableName} WHERE " + sqlCondition);
  606 + String pageSql = null;
  607 + String pagePql = null;
  608 + if(StringUtil.isEmpty(sortCondition)){
  609 + pageSql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= ?" + ") A WHERE A.RN >= ?";
  610 + pagePql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= " + page * pageSize + ") A WHERE A.RN >= " + ((page -1) * pageSize + 1);
  611 + }else{
  612 + pageSql = "SELECT * FROM (SELECT B.*,ROWNUM RNN FROM (" + sql.toString() + " " + sortCondition + ") B WHERE ROWNUM <= ?"+" ) A WHERE A.RNN >= ?";
  613 + pagePql = "SELECT * FROM (SELECT B.*,ROWNUM RNN FROM (" + sql.toString() + " " + sortCondition + ") B WHERE ROWNUM <= " + page * pageSize + ") A WHERE A.RNN >= " + ((page -1) * pageSize + 1);
  614 + }
  615 +
  616 + List<Object> page_list = new ArrayList<Object>();
  617 + page_list.add(page * pageSize);
  618 + page_list.add((page - 1) * pageSize + 1);
  619 + </#if>
  620 +
  621 +
  622 + Object oTime = null;
  623 + if (isUseCache) {// 从缓存中查询
  624 + oTime = Memcached.get("4_${tableName}");
  625 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存中获取 key[4_${tableName}],value[" + oTime + "]");
  626 + if (null != oTime) {
  627 + Object object = Memcached.get("3_" + MD5.md5(pagePql.toString() + oTime.toString()));
  628 + if (null != object) {
  629 + if (isLogInfo()) {
  630 + Date endtime = new Date();
  631 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  632 + "${beanName}Dao.findPageBySql(" + sqlCondition + ", " + page + ", " + pageSize + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"
  633 + + "四级三级缓存命中 key[3_" + MD5.md5(pagePql.toString() + oTime.toString()) + "]\n"+uuid
  634 + + "三级缓存返回条数:" + (((Map<String, Object>) object).get("list") == null?0:((List<${beanName}PO>)((Map<String, Object>) object).get("list")).size()) + "\n"+uuid
  635 + + "三级缓存查询时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  636 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  637 + + "*-*"
  638 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  639 + + ")");
  640 + }
  641 + return (Map<String, Object>) object;
  642 + }
  643 + }
  644 + }
  645 + List<${beanName}PO> resultList = null;
  646 + try {
  647 + if (isLogInfo()) {
  648 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  649 + "${beanName}Dao.findPageBySql(" + sqlCondition + ", " + page + ", " + pageSize + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"
  650 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  651 + + "准备执行SQL:" + pagePql.toString() );
  652 + }
  653 + int totalPages = 0;
  654 + int totalRows = JdbcUtil.queryForInt(uuid, fromWriteDB ? writeConnectionName : readConnectionName, sqlCount.toString());
  655 + if (totalRows % pageSize == 0) {
  656 + totalPages = totalRows / pageSize;
  657 + } else {
  658 + totalPages = (totalRows / pageSize) + 1;
  659 + }
  660 + Map<String, Object> resultMap = new HashMap<String, Object>();
  661 + resultMap.put("rows", totalRows);
  662 + resultMap.put("page", page);
  663 + resultMap.put("records", totalRows);
  664 + resultMap.put("total", totalPages);
  665 + resultList = JdbcUtil.executeQuery(uuid, fromWriteDB ? writeConnectionName : readConnectionName, pageSql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), page_list.toArray());
  666 + resultMap.put("list", resultList);
  667 + if (isAddCache) {// 重置缓存
  668 + long keyTime = 0;
  669 + if (oTime != null) {
  670 + keyTime = (Long) oTime;
  671 + } else {
  672 + keyTime = System.currentTimeMillis();
  673 + Memcached.add(4, "4_${tableName}", keyTime);
  674 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  675 + }
  676 + Memcached.add(3, "3_" + MD5.md5(pagePql.toString() + keyTime), resultMap);
  677 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"三级缓存添加 key[3_" + MD5.md5(pagePql.toString() + keyTime) + "]");
  678 + }
  679 + return resultMap;
  680 + } catch (Exception e) {
  681 + Log.error("error:[UUID:"+uuid+"]", logger, e, pagePql.toString(), null);
  682 + } finally {
  683 + if (isLogInfo()) {
  684 + Date endtime = new Date();
  685 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  686 + "${beanName}Dao.findPageBySql(" + sqlCondition + ", " + page + ", " + pageSize + ", " + isUseCache + ", " + isAddCache + ", " + fromWriteDB + ")\n"+uuid
  687 + + "连接名:" + (fromWriteDB ? writeConnectionName : readConnectionName) + "\n"+uuid
  688 + + "执行SQL:" + pagePql.toString() + "\n"+uuid
  689 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"+uuid
  690 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  691 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  692 + + "*-*"
  693 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  694 + + ")");
  695 + }
  696 + }
  697 + return null;
  698 + }
  699 + /**
  700 + *添加
  701 + */
  702 + public int directAdd${beanName}PO(${beanName}PO ${beanName}) {
  703 + if (null == ${beanName}) {
  704 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,${beanName}不能为空!"), null, null);
  705 + return -1;
  706 + }
  707 + Date starttime = null;
  708 + if (isLogInfo()) {
  709 + starttime = new Date();
  710 + }
  711 + <#--
  712 + if (${beanName}.get${pkBeanName}() == null) {
  713 + ${beanName}.set${pkBeanName}(this.find${beanName}POSeqNextVal());
  714 + }
  715 + -->
  716 + <#if columnList?exists>
  717 + <#list columnList as clist>
  718 + <#if clist.seqName?exists>
  719 + if (${beanName}.get${pkBeanName}() == null) {
  720 + ${beanName}.set${clist.columnUName}(this.findSeqNextVal("${clist.seqName}"));
  721 + }
  722 + </#if>
  723 + </#list>
  724 + </#if>
  725 + StringBuffer sql = new StringBuffer("INSERT INTO ${tableName}(" + "${column_list_str}" + ") VALUES (");
  726 + StringBuffer pql = new StringBuffer(sql.toString());
  727 + List<Object> list = new ArrayList<Object>();
  728 + <#if columnList?exists>
  729 + <#list columnList as clist>
  730 + sql.append(" ?, ");
  731 + pql.append(${beanName}.get${clist.columnUName}() + ", ");
  732 + list.add(${beanName}.get${clist.columnUName}());
  733 + </#list>
  734 + </#if>
  735 +
  736 + int count = 0;
  737 + try {
  738 + if (isLogInfo()) {
  739 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  740 + "${beanName}Dao.directAdd${beanName}PO (${beanName}PO ${beanName})\n"+uuid
  741 + + "连接名:" + writeConnectionName + "\n"+uuid
  742 + + "准备执行SQL:" + StringUtil.removeLast(pql.toString()) + ")" );
  743 + }
  744 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, StringUtil.removeLast(sql.toString()) + ")", list.toArray());
  745 +
  746 + return count;
  747 + } catch (Exception e) {
  748 + Log.error("error:[UUID:"+uuid+"]", logger, e, StringUtil.removeLast(pql.toString()) + ")", null);
  749 + } finally {
  750 + if (isLogInfo()) {
  751 + Date endtime = new Date();
  752 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  753 + "${beanName}Dao.directAdd${beanName}PO (${beanName}PO ${beanName})\n"+uuid
  754 + + "连接名:" + writeConnectionName + "\n"+uuid
  755 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + ")" + "\n"+uuid
  756 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  757 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  758 + + "*-*"
  759 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  760 + + ")");
  761 + }
  762 + }
  763 + return -1;
  764 + }
  765 + /**
  766 + * 添加
  767 + */
  768 + public int add${beanName}PO(${beanName}PO ${beanName}) {
  769 + if (null == ${beanName}) {
  770 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,${beanName}不能为空!"), null, null);
  771 + return -1;
  772 + }
  773 + Date starttime = null;
  774 + if (isLogInfo()) {
  775 + starttime = new Date();
  776 + }
  777 + <#--
  778 + if (${beanName}.get${pkBeanName}() == null) {
  779 + ${beanName}.set${pkBeanName}(this.find${beanName}POSeqNextVal());
  780 + }
  781 + -->
  782 + <#if columnList?exists>
  783 + <#list columnList as clist>
  784 + <#if clist.seqName?exists>
  785 + if (${beanName}.get${pkBeanName}() == null) {
  786 + ${beanName}.set${clist.columnUName}(this.findSeqNextVal("${clist.seqName}"));
  787 + }
  788 + </#if>
  789 + </#list>
  790 + </#if>
  791 + StringBuffer sql = new StringBuffer("INSERT INTO ${tableName}(" + "${column_list_str}" + ") VALUES (");
  792 + StringBuffer sqlI = new StringBuffer("INSERT INTO ${tableName}(");
  793 + StringBuffer sqlC = new StringBuffer(") VALUES (");
  794 + StringBuffer pql = new StringBuffer(sql.toString());
  795 + List<Object> list = new ArrayList<Object>();
  796 + <#if columnList?exists>
  797 + <#list columnList as clist>
  798 + if(${beanName}.get${clist.columnUName}() != null){
  799 + sqlI.append("${clist.columnName},");
  800 + sqlC.append(" ?, ");
  801 + pql.append(${beanName}.get${clist.columnUName}() + ", ");
  802 + list.add(${beanName}.get${clist.columnUName}());
  803 + }
  804 +
  805 + </#list>
  806 + </#if>
  807 +
  808 + int count = 0;
  809 + try {
  810 + if (isLogInfo()) {
  811 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  812 + "${beanName}Dao.add${beanName}PO (${beanName}PO ${beanName})\n"+uuid
  813 + + "连接名:" + writeConnectionName + "\n"+uuid
  814 + + "准备执行SQL:" + StringUtil.removeLast(pql.toString()) + ")" );
  815 + }
  816 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, StringUtil.removeLast(StringUtil.removeLast(sqlI.toString())+sqlC.toString()) + ")", list.toArray());
  817 + if (count > 0) {
  818 + long keyTime = System.currentTimeMillis();
  819 + for (int i = 0; i < cacheColums.size(); i++) {
  820 + String key = cacheColums.get(i);
  821 + String cache_key = "2_${tableName}_" + key + "_" + StringUtil.getValueFromObjectByName(${beanName}, key);
  822 + Memcached.add(2, cache_key, keyTime);
  823 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  824 + }
  825 + Memcached.add(4, "4_${tableName}", keyTime);
  826 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  827 + }
  828 + return count;
  829 + } catch (Exception e) {
  830 + Log.error("error:[UUID:"+uuid+"]", logger, e, StringUtil.removeLast(pql.toString()) + ")", null);
  831 + } finally {
  832 + if (isLogInfo()) {
  833 + Date endtime = new Date();
  834 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  835 + "${beanName}Dao.add${beanName}PO (${beanName}PO ${beanName})\n"+uuid
  836 + + "连接名:" + writeConnectionName + "\n"+uuid
  837 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + ")" + "\n"+uuid
  838 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  839 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  840 + + "*-*"
  841 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  842 + + ")");
  843 + }
  844 + }
  845 + return -1;
  846 + }
  847 + /**
  848 + * 批量添加
  849 + */
  850 + public int add${beanName}POList(List<${beanName}PO> ${beanName}list) {
  851 + Date starttime = null;
  852 + if (isLogInfo()) {
  853 + starttime = new Date();
  854 + }
  855 + int count = 0;
  856 + for (${beanName}PO ${beanName} : ${beanName}list) {
  857 + count += add${beanName}PO(${beanName});
  858 + }
  859 + if (isLogInfo()) {
  860 + Date endtime = new Date();
  861 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  862 + "${beanName}Dao.add${beanName}POList(List<${beanName}PO> ${beanName}list)\n"+uuid
  863 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  864 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  865 + + "*-*"
  866 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  867 + + ")");
  868 + }
  869 + return count;
  870 + }
  871 + /**
  872 + * 按ID删除
  873 + */
  874 + public int remove${beanName}POByID(${pkType} id) {
  875 + Date starttime = null;
  876 + if (isLogInfo()) {
  877 + starttime = new Date();
  878 + }
  879 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName} WHERE");
  880 + StringBuffer pql = new StringBuffer(sql.toString());
  881 + pql.append(" ${pkColumName} = " + id);
  882 + sql.append(" ${pkColumName} = ?");
  883 + int count = 0;
  884 + try {
  885 + ${beanName}PO oldPO = find${beanName}POByID(id, false, true, false, false);
  886 + if (isLogInfo()) {
  887 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  888 + "${beanName}Dao.remove${beanName}POByID(${pkType} id)\n"+uuid
  889 + + "连接名:" + writeConnectionName + "\n"+uuid
  890 + + "准备执行SQL:" + pql.toString() );
  891 + }
  892 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, sql.toString(), id);
  893 + if (count > 0) {
  894 +
  895 + long keyTime = System.currentTimeMillis();
  896 + Memcached.delete("1_${tableName}_PK_" + id);
  897 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"一级缓存删除 key[1_${tableName}_PK_" + id + "]");
  898 + for (int i = 0; i < cacheColums.size(); i++) {
  899 + String key = cacheColums.get(i);
  900 + String cache_key = "2_${tableName}_" + key + "_" + StringUtil.getValueFromObjectByName(oldPO, key);
  901 + Memcached.add(2, cache_key, keyTime);
  902 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  903 + }
  904 + Memcached.add(4, "4_${tableName}", keyTime);
  905 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  906 + }
  907 + return count;
  908 + } catch (Exception e) {
  909 + Log.error("error:[UUID:"+uuid+"]", logger, e, pql.toString(), null);
  910 + } finally {
  911 + if (isLogInfo()) {
  912 + Date endtime = new Date();
  913 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  914 + "${beanName}Dao.remove${beanName}POByID(${pkType} id)\n"+uuid
  915 + + "连接名:" + writeConnectionName + "\n"+uuid
  916 + + "执行SQL:" + pql.toString() + "\n"+uuid
  917 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  918 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  919 + + "*-*"
  920 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  921 + + ")");
  922 + }
  923 + }
  924 + return -1;
  925 + }
  926 + /**
  927 + *根据ID删除,不走缓存
  928 + */
  929 + public int directRemove${beanName}POByID(${pkType} id) {
  930 + Date starttime = null;
  931 + if (isLogInfo()) {
  932 + starttime = new Date();
  933 + }
  934 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName} WHERE");
  935 + StringBuffer pql = new StringBuffer(sql.toString());
  936 + pql.append(" ${pkColumName} = " + id);
  937 + sql.append(" ${pkColumName} = ?");
  938 + int count = 0;
  939 + try {
  940 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, sql.toString(), id);
  941 + return count;
  942 + } catch (Exception e) {
  943 + Log.error("error:[UUID:"+uuid+"]", logger, e, pql.toString(), null);
  944 + } finally {
  945 + if (isLogInfo()) {
  946 + Date endtime = new Date();
  947 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  948 + "${beanName}Dao.directRemove${beanName}POByID(${pkType} id)\n"+uuid
  949 + + "连接名:" + writeConnectionName + "\n"+uuid
  950 + + "执行SQL:" + pql.toString() + "\n"+uuid
  951 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  952 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  953 + + "*-*"
  954 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  955 + + ")");
  956 + }
  957 + }
  958 + return -1;
  959 + }
  960 + /**
  961 + * 删除按List<Object[]>条件
  962 + * Object[]数组长度是3
  963 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  964 + */
  965 + public int remove${beanName}POByCondition(List<Object[]> condition) {
  966 + if (null == condition || condition.size() == 0) {
  967 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求条件List<Object[]> condition不能为空!"), null, null);
  968 + return -1;
  969 + }
  970 + if (StringUtil.isAutowired(condition)) {
  971 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  972 + return -1;
  973 + }
  974 + Date starttime = null;
  975 + if (isLogInfo()) {
  976 + starttime = new Date();
  977 + }
  978 + List<Object> list = new ArrayList<Object>();
  979 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName}");
  980 + StringBuffer pql = new StringBuffer(sql.toString());
  981 + JdbcUtil.appendWhereCondition(sql, pql, list, condition);
  982 + int count = 0;
  983 + try {
  984 + List<${beanName}PO> oldList = find${beanName}POListByCondition(condition, true, false, false);
  985 + if (isLogInfo()) {
  986 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  987 + "${beanName}Dao.remove${beanName}POByCondition(List<Object[]> condition)\n"+uuid
  988 + + "连接名:" + writeConnectionName + "\n"+uuid
  989 + + "准备执行SQL:" + pql.toString() );
  990 + }
  991 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, sql.toString(), list.toArray());
  992 + if (count > 0) {// 重置缓存
  993 + resetCache(oldList);
  994 + }
  995 + return count;
  996 + } catch (Exception e) {
  997 + Log.error("error:[UUID:"+uuid+"]", logger, e, pql.toString(), null);
  998 + } finally {
  999 + if (isLogInfo()) {
  1000 + Date endtime = new Date();
  1001 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1002 + "${beanName}Dao.remove${beanName}POByCondition(List<Object[]> condition)\n"
  1003 + + "连接名:" + writeConnectionName + "\n"
  1004 + + "执行SQL:" + pql.toString() + "\n"
  1005 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1006 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1007 + + "*-*"
  1008 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1009 + + ")");
  1010 + }
  1011 + }
  1012 + return -1;
  1013 + }
  1014 +
  1015 + /**
  1016 + * 删除按condition条件
  1017 + * 建议使用remove${beanName}POByCondition(List<Object[]> condition), 如果remove${beanName}POByCondition(List<Object[]> condition)满足不了where条件可以使用此方法。
  1018 + * condition为where后面的条件,condition不能为空。
  1019 + */
  1020 + public int remove${beanName}POBySql(String sqlCondition) {
  1021 + if (StringUtil.isEmpty(sqlCondition)) {
  1022 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求条件String sqlCondition不能为空!"), null, null);
  1023 + return -1;
  1024 + }
  1025 + if (StringUtil.isAutowired(sqlCondition)) {
  1026 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  1027 + return -1;
  1028 + }
  1029 + Date starttime = null;
  1030 + if (isLogInfo()) {
  1031 + starttime = new Date();
  1032 + }
  1033 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName} WHERE ");
  1034 + int count = 0;
  1035 + try {
  1036 + List<${beanName}PO> oldList = find${beanName}POListBySql(sqlCondition, true, false, false);
  1037 + if (isLogInfo()) {
  1038 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1039 + "${beanName}Dao.remove${beanName}POBySql(String sqlCondition)\n"+uuid
  1040 + + "连接名:" + writeConnectionName + "\n"+uuid
  1041 + + "准备执行SQL:" + sql.toString() + sqlCondition );
  1042 + }
  1043 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, sql.toString() + sqlCondition);
  1044 + if (count > 0) {// 重置缓存
  1045 + resetCache(oldList);
  1046 + }
  1047 + return count;
  1048 + } catch (Exception e) {
  1049 + Log.error("error:[UUID:"+uuid+"]", logger, e, sql.toString() + sqlCondition, null);
  1050 + } finally {
  1051 + if (isLogInfo()) {
  1052 + Date endtime = new Date();
  1053 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1054 + "${beanName}Dao.remove${beanName}POBySql(String sqlCondition)\n"+uuid
  1055 + + "连接名:" + writeConnectionName + "\n"+uuid
  1056 + + "执行SQL:" + sql.toString() + sqlCondition + "\n"+uuid
  1057 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1058 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1059 + + "*-*"
  1060 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1061 + + ")");
  1062 + }
  1063 + }
  1064 + return -1;
  1065 + }
  1066 +
  1067 + /**
  1068 + * 根据list对象逐个删除。
  1069 + */
  1070 + public int remove${beanName}POList(List<${beanName}PO> ${beanName}list) {
  1071 + Date starttime = null;
  1072 + if (isLogInfo()) {
  1073 + starttime = new Date();
  1074 + }
  1075 + int count = 0;
  1076 + for (${beanName}PO ${beanName} : ${beanName}list) {
  1077 + count += remove${beanName}POByID(${beanName}.get${pkBeanName}());
  1078 + }
  1079 + if (isLogInfo()) {
  1080 + Date endtime = new Date();
  1081 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1082 + "${beanName}Dao.remove${beanName}POList(List<${beanName}PO> ${beanName}list)\n"+uuid
  1083 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1084 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1085 + + "*-*"
  1086 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1087 + + ")");
  1088 + }
  1089 + return count;
  1090 + }
  1091 +
  1092 + /**
  1093 + * 根据对象ID修改。
  1094 + */
  1095 + public int update${beanName}PO(${beanName}PO ${beanName}) {
  1096 + if (null == ${beanName} || null == ${beanName}.get${pkBeanName}()) {
  1097 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求对象和对象ID不能为空!"), null, null);
  1098 + return -1;
  1099 + }
  1100 + Date starttime = null;
  1101 + if (isLogInfo()) {
  1102 + starttime = new Date();
  1103 + }
  1104 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  1105 + StringBuffer pql = new StringBuffer(sql.toString());
  1106 + List<Object> list = new ArrayList<Object>();
  1107 + <#if columnList?exists>
  1108 + <#list columnList as clist>
  1109 + <#if clist.seqName?exists>
  1110 + <#else>
  1111 + <#if clist.columnJAVAType = "Long" || clist.columnJAVAType = "Integer" || clist.columnJAVAType = "Short" || clist.columnJAVAType = "Float" || clist.columnJAVAType = "Double">
  1112 + boolean ${clist.columnUName}IsZero = false;
  1113 + Object variation${clist.columnUName} = ${beanName}.getVariation${clist.columnUName}();
  1114 + if (variation${clist.columnUName} instanceof BigDecimal) {
  1115 + ${clist.columnUName}IsZero = (((BigDecimal)variation${clist.columnUName}).compareTo(BigDecimal.ZERO) == 0);
  1116 + } else {
  1117 + Long l${clist.columnUName} = Long.parseLong(String.valueOf(variation${clist.columnUName}));
  1118 + ${clist.columnUName}IsZero = (l${clist.columnUName} == 0);
  1119 + }
  1120 + if (!${clist.columnUName}IsZero) {
  1121 + sql.append(" ${clist.columnName} = ${clist.columnName} + ?, ");
  1122 + pql.append(" ${clist.columnName} = ${clist.columnName} + " + ${beanName}.getVariation${clist.columnUName}() + ",");
  1123 + list.add(${beanName}.getVariation${clist.columnUName}());
  1124 + } else {
  1125 + sql.append(" ${clist.columnName} = ?, ");
  1126 + pql.append(" ${clist.columnName} = " + ${beanName}.get${clist.columnUName}() + ",");
  1127 + list.add(${beanName}.get${clist.columnUName}());
  1128 + }
  1129 + <#elseif clist.columnJAVAType = "java.math.BigDecimal">
  1130 + if (${beanName}.getVariation${clist.columnUName}().compareTo(BigDecimal.ZERO) != 0) {
  1131 + sql.append(" ${clist.columnName} = ${clist.columnName} + ?, ");
  1132 + pql.append(" ${clist.columnName} = ${clist.columnName} + " + ${beanName}.getVariation${clist.columnUName}() + ",");
  1133 + list.add(${beanName}.getVariation${clist.columnUName}());
  1134 + } else {
  1135 + sql.append(" ${clist.columnName} = ?, ");
  1136 + pql.append(" ${clist.columnName} = " + ${beanName}.get${clist.columnUName}() + ",");
  1137 + list.add(${beanName}.get${clist.columnUName}());
  1138 + }
  1139 + <#else>
  1140 + sql.append(" ${clist.columnName} = ?, ");
  1141 + pql.append(" ${clist.columnName} = " + ${beanName}.get${clist.columnUName}() + ",");
  1142 + list.add(${beanName}.get${clist.columnUName}());
  1143 + </#if>
  1144 + </#if>
  1145 + </#list>
  1146 + </#if>
  1147 +
  1148 + String where = " WHERE ${pkColumName} = ?";
  1149 + String pwhere = " WHERE ${pkColumName} = " + ${beanName}.get${pkBeanName}();
  1150 + list.add(${beanName}.get${pkBeanName}());
  1151 + int count = 0;
  1152 + try {
  1153 + List<${beanName}PO> oldList = find${beanName}POListBySql("${pkColumName} = " + ${beanName}.get${pkBeanName}(), true, false, false);
  1154 + if (isLogInfo()) {
  1155 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1156 + "${beanName}Dao.update${beanName}PO(${beanName}PO ${beanName})\n"+uuid
  1157 + + "连接名:" + writeConnectionName + "\n"+uuid
  1158 + + "准备执行SQL:" + StringUtil.removeLast(pql.toString()) + pwhere );
  1159 + }
  1160 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, StringUtil.removeLast(sql.toString()) + where, list.toArray());
  1161 + if (count > 0) {
  1162 + long keyTime = System.currentTimeMillis();
  1163 +
  1164 + //重置旧数据缓存
  1165 + for (${beanName}PO po : oldList) {
  1166 + for (int i = 0; i < cacheColums.size(); i++) {
  1167 + String key = (String) cacheColums.get(i);
  1168 + String cache_key = "2_${tableName}_" + key + "_" + StringUtil.getValueFromObjectByName(po, key);
  1169 + Memcached.add(2, cache_key, keyTime);
  1170 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  1171 + }
  1172 + }
  1173 +
  1174 + //重置新数据缓存
  1175 + Memcached.add(1, "1_${tableName}_PK_" + ${beanName}.get${pkBeanName}(), ${beanName});
  1176 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"一级缓存添加 key[1_${tableName}_PK_" + ${beanName}.get${pkBeanName}() + "]");
  1177 + for (int i = 0; i < cacheColums.size(); i++) {
  1178 + String key = cacheColums.get(i);
  1179 + String cache_key = "2_${tableName}_" + key + "_" + StringUtil.getValueFromObjectByName(${beanName}, key);
  1180 + Memcached.add(2, cache_key, keyTime);
  1181 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  1182 + }
  1183 + Memcached.add(4, "4_${tableName}", keyTime);
  1184 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  1185 + }
  1186 + return count;
  1187 + } catch (Exception e) {
  1188 + Log.error("error:[UUID:"+uuid+"]", logger, e, StringUtil.removeLast(pql.toString()) + pwhere, null);
  1189 + } finally {
  1190 + if (isLogInfo()) {
  1191 + Date endtime = new Date();
  1192 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1193 + "${beanName}Dao.update${beanName}PO(${beanName}PO ${beanName})\n"+uuid
  1194 + + "连接名:" + writeConnectionName + "\n"+uuid
  1195 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + pwhere + "\n"+uuid
  1196 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1197 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1198 + + "*-*"
  1199 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1200 + + ")");
  1201 + }
  1202 + }
  1203 + return -1;
  1204 + }
  1205 +
  1206 + /**
  1207 + * 根据ID修改指定的值
  1208 + */
  1209 + public int update${beanName}FieldById(List<Object[]> changeList, ${pkType} id) {
  1210 + if (null == id) {
  1211 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求对象和对象ID不能为空!"), null, null);
  1212 + return -1;
  1213 + }
  1214 + Date starttime = null;
  1215 + if (isLogInfo()) {
  1216 + starttime = new Date();
  1217 + }
  1218 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  1219 + StringBuffer pql = new StringBuffer(sql.toString());
  1220 + List<Object> list = new ArrayList<Object>();
  1221 + Map<Object,Object> map = new HashMap<Object,Object>();
  1222 + for (int i = 0, iLen = changeList.size(); i < iLen; i++) {
  1223 + String name = (String) changeList.get(i)[0];
  1224 + Object value = changeList.get(i)[1];
  1225 + String variationOpt = "=";
  1226 + if (changeList.get(i).length > 2)
  1227 + variationOpt = (String)changeList.get(i)[2];
  1228 + if (variationOpt.equals("=")) {
  1229 + sql.append(" " + name + " = ?,");
  1230 + list.add(value);
  1231 + if (value == null) {
  1232 + pql.append(" " + name + "=null,");
  1233 + } else {
  1234 + pql.append(" " + name + "=\"" + value.toString() + "\",");
  1235 + }
  1236 + map.put(name, value);
  1237 + } else {
  1238 + sql.append(" " + name + " = " + name + " + ?,");
  1239 + list.add(value);
  1240 + pql.append(" " + name + " = " + name + " + " + value.toString() + ",");
  1241 + <#--会有问题 暂留
  1242 + map.put(name, value);-->
  1243 + }
  1244 + }
  1245 +
  1246 + String where = " WHERE ${pkColumName}=?";
  1247 + String pwhere = " WHERE ${pkColumName}=\"" + id + "\"";
  1248 + list.add(id);
  1249 + int count = 0;
  1250 + try {
  1251 + List<${beanName}PO> oldList = find${beanName}POListBySql("${pkColumName} = " + id, true, false, false);
  1252 + if (isLogInfo()) {
  1253 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1254 + "${beanName}Dao.update${beanName}PO(List<Object[]> changeList, ${pkType} id)\n"+uuid
  1255 + + "连接名:" + writeConnectionName + "\n"+uuid
  1256 + + "准备执行SQL:" + StringUtil.removeLast(pql.toString()) + pwhere );
  1257 + }
  1258 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, StringUtil.removeLast(sql.toString()) + where, list.toArray());
  1259 + if (count > 0) {
  1260 + resetCache(oldList);// 重置缓存
  1261 +
  1262 + //重置新数据缓存
  1263 + long keyTime = System.currentTimeMillis();
  1264 + Memcached.delete("1_${tableName}_PK_" + id);
  1265 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"一级缓存删除 key[1_${tableName}_PK_" + id + "]");
  1266 + for (int i = 0; i < cacheColums.size(); i++) {
  1267 + String key = cacheColums.get(i);
  1268 + if(map.containsKey(key)){
  1269 + String cache_key = "2_${tableName}_" + key + "_" + map.get(key);
  1270 + Memcached.add(2, cache_key, keyTime);
  1271 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  1272 + }
  1273 + }
  1274 + Memcached.add(4, "4_${tableName}", keyTime);
  1275 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  1276 + }
  1277 + return count;
  1278 + } catch (Exception e) {
  1279 + Log.error("error:[UUID:"+uuid+"]", logger, e, StringUtil.removeLast(pql.toString()) + pwhere, null);
  1280 + } finally {
  1281 + if (isLogInfo()) {
  1282 + Date endtime = new Date();
  1283 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1284 + "${beanName}Dao.update${beanName}PO(List<Object[]> changeList, ${pkType} id)\n"+uuid
  1285 + + "连接名:" + writeConnectionName + "\n"+uuid
  1286 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + pwhere + "\n"+uuid
  1287 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1288 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1289 + + "*-*"
  1290 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1291 + + ")");
  1292 + }
  1293 + }
  1294 + return -1;
  1295 + }
  1296 +
  1297 + /**
  1298 + * 批量修改。
  1299 + */
  1300 + public int update${beanName}POList(List<${beanName}PO> ${beanName}list) {
  1301 + Date starttime = null;
  1302 + if (isLogInfo()) {
  1303 + starttime = new Date();
  1304 + }
  1305 + int count = 0;
  1306 + for (${beanName}PO ${beanName} : ${beanName}list) {
  1307 + count += update${beanName}PO(${beanName});
  1308 + }
  1309 + if (isLogInfo()) {
  1310 + Date endtime = new Date();
  1311 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1312 + "${beanName}Dao.update${beanName}POList(List<${beanName}PO> ${beanName}list)\n"
  1313 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1314 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1315 + + "*-*"
  1316 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1317 + + ")");
  1318 + }
  1319 + return count;
  1320 + }
  1321 +
  1322 + /**
  1323 + * List<Object[]> updateObj 要修改成的值,数组长度为2,第一个值为列名,第二个值是要改成的值。
  1324 + * List<Object[]> condition 修改的条件, 数组长度是3, 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  1325 + */
  1326 + public int update${beanName}POByCondition(List<Object[]> updateObj, List<Object[]> condition) {
  1327 + if (null == updateObj || updateObj.size() == 0) {
  1328 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求条件List<Object[]> updateObj不能为空!"), null, null);
  1329 + return -1;
  1330 + }
  1331 + if (null == condition || condition.size() == 0) {
  1332 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求条件List<Object[]> condition不能为空!"), null, null);
  1333 + return -1;
  1334 + }
  1335 + if (StringUtil.isAutowired(condition)) {
  1336 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  1337 + return -1;
  1338 + }
  1339 + Date starttime = null;
  1340 + if (isLogInfo()) {
  1341 + starttime = new Date();
  1342 + }
  1343 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  1344 + StringBuffer pql = new StringBuffer(sql.toString());
  1345 + List<Object> list = new ArrayList<Object>();
  1346 + JdbcUtil.appendSql(sql, pql, list, updateObj);
  1347 + StringBuffer where = new StringBuffer("");
  1348 + StringBuffer pwhere = new StringBuffer("");
  1349 + JdbcUtil.appendWhereCondition(where, pwhere, list, condition);
  1350 + int count = 0;
  1351 + try {
  1352 + List<${beanName}PO> oldList = find${beanName}POListByCondition(condition, true, false, false);
  1353 + if (isLogInfo()) {
  1354 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1355 + "${beanName}Dao.update${beanName}POByCondition(List<Object[]> updateObj, List<Object[]> condition)\n"+uuid
  1356 + + "连接名:" + writeConnectionName + "\n"+uuid
  1357 + + "准备执行SQL:" + StringUtil.removeLast(pql.toString())+pwhere.toString() );
  1358 + }
  1359 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, StringUtil.removeLast(sql.toString()) + where.toString(), list.toArray());
  1360 + if (count > 0) {
  1361 + resetCache(oldList);// 重置缓存
  1362 +
  1363 + //重置新数据缓存
  1364 + Map<Object, Object> map = new HashMap<Object,Object>();
  1365 + for(int i = 0; i < updateObj.size(); i++){
  1366 + map.put(updateObj.get(i)[0], updateObj.get(i)[1]);
  1367 + }
  1368 + long keyTime = System.currentTimeMillis();
  1369 + for (int i = 0; i < cacheColums.size(); i++) {
  1370 + String key = cacheColums.get(i);
  1371 + if(map.containsKey(key)){
  1372 + String cache_key = "2_${tableName}_" + key + "_" + map.get(key);
  1373 + Memcached.add(2, cache_key, keyTime);
  1374 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  1375 + }
  1376 + }
  1377 + Memcached.add(4, "4_${tableName}", keyTime);
  1378 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  1379 + }
  1380 + return count;
  1381 + } catch (Exception e) {
  1382 + Log.error("error:[UUID:"+uuid+"]", logger, e, StringUtil.removeLast(pql.toString())+pwhere.toString(), null, null);
  1383 + } finally {
  1384 + if (isLogInfo()) {
  1385 + Date endtime = new Date();
  1386 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1387 + "${beanName}Dao.update${beanName}POByCondition(List<Object[]> updateObj, List<Object[]> condition)\n"
  1388 + + "连接名:" + writeConnectionName + "\n"+uuid
  1389 + + "执行SQL:" + StringUtil.removeLast(pql.toString())+pwhere.toString() + "\n"+uuid
  1390 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1391 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1392 + + "*-*"
  1393 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1394 + + ")");
  1395 + }
  1396 + }
  1397 + return -1;
  1398 + }
  1399 +
  1400 + /**
  1401 + * List<Object[]> updateObj 要修改成的值,数组长度为2,第一个值为列名,第二个值是要改成的值。
  1402 + * String sqlCondition 修改的条件。
  1403 + */
  1404 + public int update${beanName}POBySql(List<Object[]> updateObj, String sqlCondition) {
  1405 + if (null == updateObj || updateObj.size() == 0) {
  1406 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求条件List<Object[]> updateObj不能为空!"), null, null);
  1407 + return -1;
  1408 + }
  1409 + if (StringUtil.isEmpty(sqlCondition)) {
  1410 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,请求条件sqlCondition不能为空!"), null, null);
  1411 + return -1;
  1412 + }
  1413 + if (StringUtil.isAutowired(sqlCondition)) {
  1414 + Log.error("error:[UUID:"+uuid+"]", logger, new Exception("请求条件异常,无效请求!"), null, null);
  1415 + return -1;
  1416 + }
  1417 + Date starttime = null;
  1418 + if (isLogInfo()) {
  1419 + starttime = new Date();
  1420 + }
  1421 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  1422 + StringBuffer pql = new StringBuffer(sql.toString());
  1423 + List<Object> list = new ArrayList<Object>();
  1424 + JdbcUtil.appendSql(sql, pql, list, updateObj);
  1425 + int count = 0;
  1426 + try {
  1427 + List<${beanName}PO> oldList = find${beanName}POListBySql(sqlCondition, true, false, false);
  1428 + if (isLogInfo()) {
  1429 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1430 + "${beanName}Dao.update${beanName}POBySql(List<Object[]> updateObj, String sqlCondition)\n"+uuid
  1431 + + "连接名:" + writeConnectionName + "\n"+uuid
  1432 + + "准备执行SQL:" + StringUtil.removeLast(pql.toString()) + " WHERE " + sqlCondition );
  1433 + }
  1434 + count = JdbcUtil.executeUpdate(uuid, writeConnectionName, StringUtil.removeLast(sql.toString()) + " WHERE "+sqlCondition, list.toArray());
  1435 + if (count > 0) {
  1436 + resetCache(oldList);// 重置缓存
  1437 +
  1438 + //重置新数据缓存
  1439 + Map<Object, Object> map = new HashMap<Object,Object>();
  1440 + for(int i = 0; i < updateObj.size(); i++){
  1441 + map.put(updateObj.get(i)[0], updateObj.get(i)[1]);
  1442 + }
  1443 + long keyTime = System.currentTimeMillis();
  1444 + for (int i = 0; i < cacheColums.size(); i++) {
  1445 + String key = cacheColums.get(i);
  1446 + if(map.containsKey(key)){
  1447 + String cache_key = "2_${tableName}_" + key + "_" + map.get(key);
  1448 + Memcached.add(2, cache_key, keyTime);
  1449 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"二级缓存重置 key[" + cache_key + "]");
  1450 + }
  1451 + }
  1452 + Memcached.add(4, "4_${tableName}", keyTime);
  1453 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,"四级缓存重置 key[4_${tableName}]");
  1454 + }
  1455 + return count;
  1456 + } catch (Exception e) {
  1457 + Log.error("error:[UUID:"+uuid+"]", logger, e, StringUtil.removeLast(pql.toString()) + " WHERE " + sqlCondition, null, null);
  1458 + } finally {
  1459 + if (isLogInfo()) {
  1460 + Date endtime = new Date();
  1461 + Log.info("cacheinfo:[UUID:"+uuid+"]", logger,
  1462 + "${beanName}Dao.update${beanName}POBySql(List<Object[]> updateObj, String sqlCondition)\n"+uuid
  1463 + + "连接名:" + writeConnectionName + "\n"+uuid
  1464 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + " WHERE " + sqlCondition + "\n"+uuid
  1465 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  1466 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  1467 + + "*-*"
  1468 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  1469 + + ")");
  1470 + }
  1471 + }
  1472 + return -1;
  1473 + }
  1474 + <#--
  1475 + /**
  1476 + * 获取自增长ID
  1477 + */
  1478 + public Integer find${beanName}POSeqNextVal() {
  1479 + String sql = "SELECT SEQ_${tableName}_PK.NEXTVAL FROM DUAL";
  1480 + try {
  1481 + return JdbcUtil.queryForInt(uuid, writeConnectionName, sql);
  1482 + } catch (Exception e) {
  1483 + Log.error("error:[UUID:"+uuid+"]", logger, e, sql.toString());
  1484 + }
  1485 + return -1;
  1486 + }
  1487 + -->
  1488 +
  1489 + /**
  1490 +
  1491 + * 获取自增长列的值(仅支持数值类型)
  1492 + */
  1493 + <#-- public ${pkType} -->
  1494 + public Long findSeqNextVal(String seq_name) {
  1495 + String sql = "SELECT " + seq_name + ".NEXTVAL FROM DUAL";
  1496 +
  1497 + try {
  1498 + return Long.parseLong(JdbcUtil.queryForInt(uuid, writeConnectionName, sql)+"");
  1499 + } catch (Exception e) {
  1500 + Log.error("error:[UUID:"+uuid+"]", logger, e, sql.toString());
  1501 + }
  1502 + return -1l;
  1503 + }
  1504 +
  1505 + /**
  1506 + * 获取多个自增长ID
  1507 + */
  1508 + public List<${pkType}> find${beanName}POSeqNextVal(Integer step, String seqName) {
  1509 + String sql = "SELECT " + seqName + ".NEXTVAL FROM (SELECT 1 FROM ALL_OBJECTS WHERE ROWNUM <= "+step+" ) ";
  1510 + try {
  1511 + List<${pkType}> re = JdbcUtil.executeQuery(uuid, readConnectionName, sql.toString(), new DAORowMapper<${pkType}>(${pkType}.class));
  1512 + return re;
  1513 +
  1514 + } catch (Exception e) {
  1515 + Log.error("error:[UUID:"+uuid+"]", logger, e, sql.toString());
  1516 + }
  1517 + return null;
  1518 + }
  1519 +
  1520 +<#--get, set方法集合 -->
  1521 +<#if funlist?exists>
  1522 +<#list funlist as flist>
  1523 +<#--方法注释 -->
  1524 + <#if flist.function_param?exists>
  1525 + /**
  1526 + <#list flist.function_param as param>
  1527 + <#if param?exists>*@param ${param}<#else><#rt></#if>
  1528 + </#list>
  1529 + <#list flist.function_exception as exception>
  1530 + <#if exception?exists>*@throws ${exception}<#else><#rt></#if>
  1531 + </#list>
  1532 + <#if flist.function_description?exists>*@Description:${flist.function_description}<#else><#rt></#if>
  1533 + */
  1534 + </#if>
  1535 + <#--是否是override的 -->
  1536 + <#if flist.over?exists>@Override<#else><#rt></#if>
  1537 + <#--类或者接口的方法不同所有有两个方法体 -->
  1538 + <#-- 方法的定义-->
  1539 + public ${flist.function_return} ${flist.function_name}(<#if flist.function_params?exists>${flist.function_params}<#else></#if>)<#if flist.function_exceptions?exists> throws ${flist.function_exceptions}<#else></#if> {
  1540 + <#--方法体-->
  1541 + ${flist.function_body}
  1542 + }
  1543 +</#list>
  1544 +</#if>
  1545 +}
0 1546 \ No newline at end of file
... ...
src/com/taover/base/template/.svn/text-base/POTemplate.ftl.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/.svn/text-base/POTemplate.ftl.svn-base
... ... @@ -0,0 +1,108 @@
  1 +<#--包名 -->
  2 +package ${packages}
  3 +import java.util.HashMap;
  4 +import java.util.Map;
  5 +import org.json.JSONException;
  6 +import org.json.JSONObject;
  7 +import java.io.Serializable;
  8 +/**
  9 + <#if version?exists>
  10 + * @version ${version}
  11 + </#if>
  12 + */
  13 +
  14 + public class ${name}PO implements Serializable {
  15 + /**
  16 + *
  17 + */
  18 + private static final long serialVersionUID = 1L;
  19 + <#--变量 ,get,set方法-->
  20 +<#if tablemodel.columnlist?exists>
  21 + <#list tablemodel.columnlist as clist>
  22 + private ${clist.columnJAVAType} ${clist.columnName};
  23 +
  24 + <#if clist.columnRemarks?exists>
  25 + /**
  26 + * ${clist.columnRemarks}
  27 + */
  28 + <#else>
  29 + </#if>
  30 + public ${clist.columnJAVAType} get${clist.columnMethodName}(){
  31 + return ${clist.columnName};
  32 + }
  33 +
  34 + public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){
  35 + this.${clist.columnName} = ${clist.columnName};
  36 + }
  37 +
  38 + <#if clist.columnJAVAType = "Long" || clist.columnJAVAType = "java.math.BigDecimal" || clist.columnJAVAType = "Integer" || clist.columnJAVAType = "Short" || clist.columnJAVAType = "Float" || clist.columnJAVAType = "Double">
  39 + <#if clist.columnJAVAType = "Long">
  40 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0L;
  41 + </#if>
  42 + <#if clist.columnJAVAType = "java.math.BigDecimal">
  43 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = new java.math.BigDecimal(0.0);
  44 + </#if>
  45 + <#if clist.columnJAVAType = "Integer">
  46 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0;
  47 + </#if>
  48 + <#if clist.columnJAVAType = "Short">
  49 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0;
  50 + </#if>
  51 + <#if clist.columnJAVAType = "Double">
  52 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0d;
  53 + </#if>
  54 + <#if clist.columnJAVAType = "Float">
  55 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0f;
  56 + </#if>
  57 + public ${clist.columnJAVAType} getVariation${clist.columnMethodName}(){
  58 + return variation${clist.columnMethodName};
  59 + }
  60 +
  61 + public void setVariation${clist.columnMethodName}(${clist.columnJAVAType} variation${clist.columnName}){
  62 + this.variation${clist.columnMethodName} = variation${clist.columnName};
  63 + }
  64 +
  65 + </#if>
  66 + </#list>
  67 +</#if>
  68 +
  69 + @Override
  70 + public String toString() {
  71 + return "${name}PO: ${toStringMethodBody};
  72 + }
  73 +
  74 +
  75 + public JSONObject toJson() {
  76 + JSONObject json = null;
  77 + try {
  78 + json = new JSONObject();
  79 +<#if tablemodel.columnlist?exists>
  80 + <#list tablemodel.columnlist as clist>
  81 + json.put("${clist.columnName}", get${clist.columnMethodName}());
  82 + </#list>
  83 +</#if>
  84 + } catch (JSONException e) {
  85 + e.printStackTrace();
  86 + }
  87 + return json;
  88 + }
  89 +
  90 + public Map<String, Object> toMap() {
  91 + Map<String, Object> map = new HashMap<String, Object>();
  92 +<#if tablemodel.columnlist?exists>
  93 + <#list tablemodel.columnlist as clist>
  94 + map.put("${clist.columnName}", get${clist.columnMethodName}());
  95 + </#list>
  96 +</#if>
  97 + return map;
  98 + }
  99 + public ${name}PO JsonToPo(JSONObject json)throws JSONException{
  100 + ${name}PO po = new ${name}PO();
  101 +<#if tablemodel.columnlist?exists>
  102 + <#list tablemodel.columnlist as clist>
  103 + po.set${clist.columnMethodName}((${clist.columnJAVAType})json.get("${clist.columnName}"));
  104 + </#list>
  105 + return po;
  106 +</#if>
  107 + }
  108 + }
0 109 \ No newline at end of file
... ...
src/com/taover/base/template/.svn/text-base/createTableTemplate.ftl.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/.svn/text-base/createTableTemplate.ftl.svn-base
... ... @@ -0,0 +1,31 @@
  1 +-- Create table
  2 +create table ${tableName}
  3 +(
  4 +<#list columnlist as clist>
  5 + ${clist.columnName} ${clist.columnSQLType}<#if clist.columnSize?exists>${clist.columnSize}</#if><#if clist.columnDefaults?exists && clist.columnDefaults != '' && clist.columnDefaults != 'null'> default ${clist.columnDefaults}</#if><#if !clist.nullable> not null</#if><#if clist_has_next>,</#if>
  6 +</#list>
  7 +);
  8 +<#if tableRemarks?exists>
  9 +-- Add comments to the table
  10 +comment on table ${tableName} is '${tableRemarks}';
  11 +</#if>
  12 +-- Add comments to the columns
  13 +<#list columnlist as clist>
  14 + <#if clist.columnRemarks?exists && clist.columnRemarks != clist.columnName>
  15 +comment on column ${tableName}.${clist.columnName} is '${clist.columnRemarks}';
  16 + </#if>
  17 +</#list>
  18 +<#if tablePk?exists>
  19 +-- Create index
  20 +CREATE UNIQUE INDEX PK_${tableName} ON ${tableName}(${tablePk});
  21 +ALTER TABLE ${tableName} ADD
  22 + PRIMARY KEY (${tablePk})
  23 + USING INDEX PK_${tableName};
  24 +</#if>
  25 +-- Create sequence
  26 +create sequence SEQ_${tableName}<#if tableName?length lt 24>_PK</#if>
  27 +minvalue 1
  28 +maxvalue 99999999999999999
  29 +start with 1
  30 +increment by 1
  31 +cache 20;
... ...
src/com/taover/base/template/ControllerExportTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/ControllerExportTemplate.ftl
... ... @@ -0,0 +1,51 @@
  1 +package ${mainPackageInfo}.${moduleName}.export;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Date;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +import javax.annotation.Resource;
  10 +import javax.servlet.http.HttpServletRequest;
  11 +
  12 +import org.apache.commons.lang.StringUtils;
  13 +import org.apache.commons.logging.Log;
  14 +import org.apache.commons.logging.LogFactory;
  15 +
  16 +import org.springframework.beans.propertyeditors.CustomDateEditor;
  17 +import org.springframework.stereotype.Controller;
  18 +import org.springframework.ui.Model;
  19 +import org.springframework.web.bind.WebDataBinder;
  20 +import org.springframework.web.bind.annotation.InitBinder;
  21 +import org.springframework.web.bind.annotation.RequestMapping;
  22 +import org.springframework.web.bind.annotation.RequestMethod;
  23 +import org.springframework.web.bind.annotation.RequestParam;
  24 +import org.springframework.web.bind.annotation.ResponseBody;
  25 +
  26 +import com.taover.base.ResultInfo;
  27 +import ${mainPackageInfo}.contants.ResultInfoCode;
  28 +import com.taover.tools.CustomTimestampEditor;
  29 +
  30 +@Controller
  31 +@RequestMapping("/export/${moduleName}")
  32 +public class ${moduleNameFirstBig}ExportController {
  33 +
  34 + Log log = LogFactory.getLog(this.getClass());
  35 +
  36 + /**
  37 + * 绑定日期参数
  38 + * @param request
  39 + * @param binder
  40 + */
  41 + @InitBinder
  42 + protected void init(HttpServletRequest request, WebDataBinder binder){
  43 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  44 + dateFormat.setLenient(false);
  45 + binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
  46 + SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  47 + datetimeFormat.setLenient(false);
  48 + binder.registerCustomEditor(java.sql.Timestamp.class,new CustomTimestampEditor(datetimeFormat, true));
  49 + }
  50 +
  51 +}
... ...
src/com/taover/base/template/ControllerTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/ControllerTemplate.ftl
... ... @@ -0,0 +1,133 @@
  1 +package ${mainPackageInfo}.${moduleName}.controller;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.ArrayList;
  5 +import java.util.Date;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +import javax.annotation.Resource;
  10 +import javax.servlet.http.HttpServletRequest;
  11 +
  12 +import org.apache.commons.lang.StringUtils;
  13 +import org.apache.commons.logging.Log;
  14 +import org.apache.commons.logging.LogFactory;
  15 +
  16 +import org.springframework.beans.propertyeditors.CustomDateEditor;
  17 +import org.springframework.stereotype.Controller;
  18 +import org.springframework.ui.Model;
  19 +import org.springframework.web.bind.WebDataBinder;
  20 +import org.springframework.web.bind.annotation.InitBinder;
  21 +import org.springframework.web.bind.annotation.RequestMapping;
  22 +import org.springframework.web.bind.annotation.RequestMethod;
  23 +import org.springframework.web.bind.annotation.RequestParam;
  24 +import org.springframework.web.bind.annotation.ResponseBody;
  25 +
  26 +import com.taover.base.ResultInfo;
  27 +import ${mainPackageInfo}.contants.ResultInfoCode;
  28 +import ${poPackageInfo}.${poClassName};
  29 +import ${mainPackageInfo}.${moduleName}.service.${serviceImplClassName};
  30 +import com.taover.tools.CustomTimestampEditor;
  31 +
  32 +@Controller
  33 +@RequestMapping("/${controllerUri}")
  34 +public class ${controllerClassName} {
  35 + @Resource
  36 + private ${serviceImplClassName} ${serviceImplFieldName};
  37 +
  38 + Log log = LogFactory.getLog(this.getClass());
  39 +
  40 + /**
  41 + * 绑定日期参数
  42 + * @param request
  43 + * @param binder
  44 + */
  45 + @InitBinder
  46 + protected void init(HttpServletRequest request, WebDataBinder binder){
  47 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  48 + dateFormat.setLenient(false);
  49 + binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
  50 + SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  51 + datetimeFormat.setLenient(false);
  52 + binder.registerCustomEditor(java.sql.Timestamp.class,new CustomTimestampEditor(datetimeFormat, true));
  53 + }
  54 +
  55 + @RequestMapping(value="/add", method=RequestMethod.POST)
  56 + @ResponseBody
  57 + public ResultInfo add(
  58 + ${poClassName} ${poFieldName},
  59 + Model model,
  60 + HttpServletRequest request){
  61 + return this.${serviceImplFieldName}.add(${poFieldName});
  62 + }
  63 +
  64 + @RequestMapping(value="/delete")
  65 + @ResponseBody
  66 + public ResultInfo delete(
  67 + @RequestParam(value="ids", required=false) String ids,
  68 + Model model,
  69 + HttpServletRequest request){
  70 + //创建返回对象
  71 + ResultInfo result = new ResultInfo();
  72 +
  73 + //参数检验
  74 + if(ids == null || ids.length() == 0){
  75 + result.setResultId("200");
  76 + result.setResultMessage("删除失败,缺少主键信息");
  77 + return result;
  78 + }
  79 +
  80 + return result = this.${serviceImplFieldName}.delete(ids);
  81 + }
  82 +
  83 + @RequestMapping(value="/edit", method=RequestMethod.POST)
  84 + @ResponseBody
  85 + public ResultInfo edit(
  86 + ${poClassName} ${poFieldName},
  87 + Model model,
  88 + HttpServletRequest request){
  89 +
  90 + return this.${serviceImplFieldName}.edit(${poFieldName});
  91 + }
  92 +
  93 +
  94 + /**
  95 + * 分页条件查询
  96 + * @param page
  97 + * @param pageSize
  98 + * @return
  99 + */
  100 + @RequestMapping(value = "/query")
  101 + @ResponseBody
  102 + public Map<String, Object> query(
  103 + @RequestParam(value="sort", required=false) String sort,
  104 + @RequestParam(value="order", required=false) String order,
  105 + @RequestParam(value="page", required=false) Integer page,
  106 + @RequestParam(value="rows", required=false) Integer pageSize,
  107 + HttpServletRequest request) {
  108 + //参数检验
  109 + if(page == null){
  110 + page = 1;
  111 + }
  112 + if(pageSize == null){
  113 + pageSize = 20;
  114 + }
  115 + if("".equals(sort)){
  116 + sort = "id";
  117 + order = "desc";
  118 + }
  119 +
  120 + //调用Service层查询方法
  121 + List<Object[]> arrayCondition = new ArrayList<Object[]>();
  122 +
  123 + <#list fields as tempField>
  124 + ${tempField["conditionCode"]}
  125 + </#list>
  126 +
  127 + Map<String, Object> result = this.${serviceImplFieldName}.query(arrayCondition, sort, order, page, pageSize);
  128 + result.put("resultId", "200");
  129 + result.put("resultMessage", "请求成功");
  130 + return result;
  131 + }
  132 +
  133 +}
... ...
src/com/taover/base/template/DAOTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/DAOTemplate.ftl
... ... @@ -0,0 +1,804 @@
  1 +//${tableName}
  2 +<#--包名 -->
  3 +package ${packages}
  4 +
  5 +<#-- 所有的引入-->
  6 +<#list imports as ilist>
  7 +<#if ilist?exists>${ilist}<#else><#rt></#if>
  8 +</#list>
  9 +import java.math.BigDecimal;
  10 +
  11 +/**
  12 + <#if version?exists>
  13 + * @version ${version}
  14 + </#if>
  15 + */
  16 +@Repository
  17 +<#--类, 还是接口 名称, 继承的类, 实现的接口 -->
  18 +public class ${beanName}Dao {
  19 +<#--变量 -->
  20 + @Resource
  21 + private JdbcTemplate jdbcegroceryRead;
  22 + @Resource
  23 + private JdbcTemplate jdbcegroceryWrite;
  24 +
  25 + Log logger = LogFactory.getLog(this.getClass());
  26 +
  27 +
  28 + /**
  29 + * 根据Request Map 生成PO对象
  30 + */
  31 + public ${beanName}PO get${beanName}POFromRequest(Map<String, Object> map) throws Exception {
  32 + ${beanName}PO po = new ${beanName}PO();
  33 + <#if reqParameterToPOMap?exists>
  34 + <#list reqParameterToPOMap?keys as poKey>
  35 + po.set${reqParameterToPOMap[poKey]};
  36 + </#list>
  37 + </#if>
  38 + return po;
  39 + }
  40 +
  41 + /**
  42 + * 按主键查询
  43 + */
  44 + public ${beanName}PO findPOByID(${pkType} id) {
  45 + return findPOByID(id, true, false);
  46 + }
  47 +
  48 + /**
  49 + * 按主键查询
  50 + * isLock 是否锁定, 默认不锁
  51 + * fromWriteDB 是否从写库读写,默认从读库查询
  52 + */
  53 + public ${beanName}PO findPOByID(${pkType} id, boolean isLock, boolean fromWriteDB) {
  54 + Date starttime = new Date();
  55 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName}");
  56 + StringBuffer pql = new StringBuffer(sql.toString());
  57 + sql.append(" WHERE ${pkColumName} = ?");
  58 + pql.append(" WHERE ${pkColumName} = " + id);
  59 + if (isLock) {
  60 + sql.append(" FOR UPDATE");
  61 + pql.append(" FOR UPDATE");
  62 + }
  63 + List<${beanName}PO> resultList = null;
  64 + try {
  65 + resultList = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).query(sql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), id);
  66 + if (resultList == null || resultList.size() == 0) {
  67 + return null;
  68 + }
  69 + return resultList.get(0);
  70 + } catch (Exception e) {
  71 + LogUtils.error("error:findPOByID", logger, e, pql.toString(), id);
  72 + } finally {
  73 + Date endtime = new Date();
  74 + if(false)LogUtils.info("info:", logger,
  75 + "${beanName}Dao.findPOByID(" + id + ", " + isLock + ", " + ", " + fromWriteDB + ")\n"
  76 + + "返回数据条数:" + (resultList==null?0:resultList.size())
  77 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  78 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  79 + + "*-*"
  80 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  81 + + ")");
  82 + }
  83 + return null;
  84 + }
  85 +
  86 + /**
  87 + * 根据条件List<Object[]>查询
  88 + * Object[]数组长度是3
  89 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  90 + */
  91 + public ${beanName}PO findPOByCondition(List<Object[]> condition) {
  92 + List<${beanName}PO> tempList = findListByCondition(condition,null, false);
  93 + if(tempList == null || tempList.size() == 0){
  94 + return null;
  95 + }else{
  96 + return tempList.get(0);
  97 + }
  98 + }
  99 +
  100 + /**
  101 + * 根据条件sql查询
  102 + * sqlCondition 为where 后面的条件。
  103 + */
  104 + public ${beanName}PO findPOBySql(String sqlCondition) {
  105 + List<${beanName}PO> tempList = findListBySql(sqlCondition, false);
  106 + if(tempList == null || tempList.size() == 0){
  107 + return null;
  108 + }else{
  109 + return tempList.get(0);
  110 + }
  111 + }
  112 +
  113 + /**
  114 + * 根据条件List<Object[]>查询
  115 + * Object[]数组长度是3
  116 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  117 + */
  118 + public List<${beanName}PO> findListByCondition(List<Object[]> condition) {
  119 + return findListByCondition(condition,null, false);
  120 + }
  121 +
  122 + /**
  123 + * 根据条件List<Object[]>查询
  124 + * Object[]数组长度是3
  125 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  126 + */
  127 + public List<${beanName}PO> findListByCondition(List<Object[]> condition,String sortCondition, boolean fromWriteDB) {
  128 + if (StringUtil.isAutowired(condition)) {
  129 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  130 + return null;
  131 + }
  132 + Date starttime = new Date();
  133 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName}");
  134 + StringBuffer pql = new StringBuffer(sql.toString());
  135 + List<Object> list = new ArrayList<Object>();
  136 + JdbcUtil.appendWhereCondition(sql, pql, list, condition);
  137 + if(!StringUtils.isEmpty(sortCondition)){
  138 + sql.append(" " + sortCondition + " ");
  139 + pql.append(" " + sortCondition + " ");
  140 + }
  141 + List<${beanName}PO> resultList = null;
  142 + try {
  143 + resultList = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).query(sql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), list.toArray());
  144 + return resultList;
  145 + } catch (Exception e) {
  146 + LogUtils.error("error:", logger, e, pql.toString(), null);
  147 + } finally {
  148 + Date endtime = new Date();
  149 + if(false)LogUtils.info("info", logger,
  150 + "${beanName}Dao.findListByCondition(" + condition.toString() + ", " + fromWriteDB + ")\n"
  151 + + "fromWriteDB:" + fromWriteDB
  152 + + "执行SQL:" + pql.toString() + "\n"
  153 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"
  154 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  155 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  156 + + "*-*"
  157 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  158 + + ")");
  159 +
  160 + }
  161 + return null;
  162 + }
  163 +
  164 + /**
  165 + * 根据条件sql查询
  166 + * sqlCondition 为where 后面的条件。
  167 + */
  168 + public List<${beanName}PO> findListBySql(String sqlCondition) {
  169 + return findListBySql(sqlCondition, false);
  170 + }
  171 +
  172 + /**
  173 + * 根据条件sql查询
  174 + * sqlCondition 为where 后面的条件。
  175 + */
  176 + public List<${beanName}PO> findListBySql(String sqlCondition,boolean fromWriteDB) {
  177 + if (StringUtil.isAutowired(sqlCondition)) {
  178 + LogUtils.error("error", logger, new Exception("请求条件异常,无效请求!"), null, null);
  179 + return null;
  180 + }
  181 + Date starttime = new Date();
  182 +
  183 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName} WHERE " + sqlCondition);
  184 + List<${beanName}PO> resultList = null;
  185 + try {
  186 + resultList = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).query(sql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class));
  187 + return resultList;
  188 + } catch (Exception e) {
  189 + LogUtils.error("error:", logger, e, sql.toString(), null);
  190 + } finally {
  191 + Date endtime = new Date();
  192 + if(false)LogUtils.info("info", logger,
  193 + "${beanName}Dao.findListBySql(" + sqlCondition + ", " + fromWriteDB + ")\n"
  194 + + "fromWriteDB:" + fromWriteDB + "\n"
  195 + + "执行SQL:" + sql.toString() + "\n"
  196 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"
  197 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  198 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  199 + + "*-*"
  200 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  201 + + ")");
  202 + }
  203 + return null;
  204 + }
  205 +
  206 + /**
  207 + * 按条件分页查询
  208 + * Object[]数组长度是3
  209 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  210 + */
  211 + public Map<String, Object> findPageByCondition(List<Object[]> condition,int page, int pageSize) {
  212 + return findPageByCondition(condition, null , page, pageSize, false);
  213 + }
  214 +
  215 + /**
  216 + * 按条件分页查询
  217 + * Object[]数组长度是3
  218 + * Object[]第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  219 + * boolean isUseCache, 是否用缓存,默认用。
  220 + * boolean isAddCache, 是否添加缓存,默认添加。
  221 + */
  222 + public Map<String, Object> findPageByCondition(List<Object[]> condition,String sortCondition, int page, int pageSize, boolean fromWriteDB) {
  223 + if (StringUtil.isAutowired(condition)) {
  224 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  225 + return null;
  226 + }
  227 + Date starttime = new Date();
  228 + <#if dbType = "mysql">
  229 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName}");
  230 + StringBuffer pql = new StringBuffer(sql.toString());
  231 + <#else>
  232 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str}, ROWNUM RN FROM ${tableName}");
  233 + StringBuffer pql = new StringBuffer(sql.toString());
  234 + </#if>
  235 + StringBuffer sqlCount = new StringBuffer("SELECT COUNT(1) FROM ${tableName}");
  236 +
  237 + List<Object> count_list = new ArrayList<Object>();
  238 + List<Object> page_list = new ArrayList<Object>();
  239 + JdbcUtil.appendWhereConditionForCount(sqlCount, condition);
  240 + JdbcUtil.appendWhereCondition(sql, pql, count_list, condition);
  241 + for (int i = 0; i < count_list.size(); i++)
  242 + page_list.add(count_list.get(i));
  243 +
  244 + <#if dbType == "mysql">
  245 + page_list.add((page - 1) * pageSize);
  246 + page_list.add(pageSize);
  247 +
  248 + if(!StringUtils.isEmpty(sortCondition)){
  249 + sql.append(" " + sortCondition + " ");
  250 + pql.append(" " + sortCondition + " ");
  251 + }
  252 +
  253 + String pageSql = sql.toString() + " limit ?, ?";
  254 + String pagePql = pql.toString() + " limit " + (page -1) * pageSize + ", " + pageSize;
  255 +
  256 + <#else>
  257 + String pageSql = null;
  258 + String pagePql = null;
  259 + if (page_list.size() == 0) {
  260 +
  261 + pageSql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= ?" + ") A WHERE A.RN >= ?";
  262 + pagePql = "SELECT * FROM (" + pql.toString() + " AND ROWNUM <= " + page * pageSize + ") A WHERE A.RN >= " + ((page -1) * pageSize + 1);
  263 + } else {
  264 + pageSql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= ?" + ") A WHERE A.RN >= ?";
  265 + pagePql = "SELECT * FROM (" + pql.toString() + " AND ROWNUM <= " + page * pageSize + ") A WHERE A.RN >= " + ((page -1) * pageSize + 1);
  266 + }
  267 + page_list.add(page * pageSize);
  268 + page_list.add((page - 1) * pageSize + 1);
  269 + </#if>
  270 + List<${beanName}PO> resultList = null;
  271 + try {
  272 + int totalPages = 0;
  273 + int totalRows = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).queryForInt(sqlCount.toString(), count_list.toArray()) ;
  274 + if (totalRows % pageSize == 0) {
  275 + totalPages = totalRows / pageSize;
  276 + } else {
  277 + totalPages = (totalRows / pageSize) + 1;
  278 + }
  279 + Map<String, Object> resultMap = new HashMap<String, Object>();
  280 + resultMap.put("page", page);
  281 + resultMap.put("total", totalRows);
  282 + resultList = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).query( pageSql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), page_list.toArray());
  283 + resultMap.put("rows", resultList);
  284 + return resultMap;
  285 + } catch (Exception e) {
  286 + LogUtils.error("error:", logger, e, pagePql.toString(), page_list.toArray());
  287 + } finally {
  288 + Date endtime = new Date();
  289 + if(false)LogUtils.info("info:", logger,
  290 + "${beanName}Dao.findPageByCondition(" + condition.toString() + ", " + page + ", " + pageSize + ", " + fromWriteDB + ")\n"
  291 + + "执行SQL:" + pagePql.toString() + "\n"
  292 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"
  293 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  294 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  295 + + "*-*"
  296 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  297 + + ")");
  298 + }
  299 + return null;
  300 + }
  301 +
  302 + /**
  303 + * 按sql分页查询, sqlCondition为where 后条件sql
  304 + */
  305 + public Map<String, Object> findPageBySql(String sqlCondition, int page, int pageSize) {
  306 + return findPageBySql(sqlCondition, page, pageSize, false);
  307 + }
  308 +
  309 + /**
  310 + * 按sql分页查询, sqlCondition为where 后条件sql
  311 + */
  312 + public Map<String, Object> findPageBySql(String sqlCondition, int page, int pageSize,boolean fromWriteDB) {
  313 + if (StringUtil.isAutowired(sqlCondition)) {
  314 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  315 + return null;
  316 + }
  317 + Date starttime = new Date();
  318 +
  319 + <#if dbType = "mysql">
  320 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str} FROM ${tableName} WHERE " + sqlCondition );
  321 + StringBuffer sqlCount = new StringBuffer("SELECT count(1) from ${tableName} WHERE " + sqlCondition);
  322 + String pageSql = sql.toString() + " limit ?, ?";
  323 + String pagePql = sql.toString() + " limit " + ((page -1) * pageSize) + ", " + (page * pageSize);
  324 + List<Object> page_list = new ArrayList<Object>();
  325 + page_list.add((page - 1) * pageSize);
  326 + page_list.add(page * pageSize);
  327 + <#else>
  328 + StringBuffer sql = new StringBuffer("SELECT ${column_list_str}, ROWNUM RN FROM ${tableName} WHERE " + sqlCondition);
  329 + StringBuffer sqlCount = new StringBuffer("SELECT count(1) from ${tableName} WHERE " + sqlCondition);
  330 + String pageSql = null;
  331 + String pagePql = null;
  332 +
  333 + pageSql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= ?" + ") A WHERE A.RN >= ?";
  334 + pagePql = "SELECT * FROM (" + sql.toString() + " AND ROWNUM <= " + page * pageSize + ") A WHERE A.RN >= " + ((page -1) * pageSize + 1);
  335 +
  336 +
  337 + List<Object> page_list = new ArrayList<Object>();
  338 + page_list.add(page * pageSize);
  339 + page_list.add((page - 1) * pageSize + 1);
  340 + </#if>
  341 +
  342 +
  343 + List<${beanName}PO> resultList = null;
  344 + try {
  345 +
  346 + int totalPages = 0;
  347 + int totalRows = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).queryForInt(sqlCount.toString());
  348 + if (totalRows % pageSize == 0) {
  349 + totalPages = totalRows / pageSize;
  350 + } else {
  351 + totalPages = (totalRows / pageSize) + 1;
  352 + }
  353 + Map<String, Object> resultMap = new HashMap<String, Object>();
  354 + resultMap.put("page", page);
  355 + resultMap.put("total", totalRows);
  356 + resultList = (fromWriteDB ? jdbcegroceryWrite : jdbcegroceryRead).query(pageSql.toString(), new DAORowMapper<${beanName}PO>(${beanName}PO.class), page_list.toArray());
  357 + resultMap.put("rows", resultList);
  358 + return resultMap;
  359 + } catch (Exception e) {
  360 + LogUtils.error("error:", logger, e, pagePql.toString(), null);
  361 + } finally {
  362 + Date endtime = new Date();
  363 + if(false)LogUtils.info("info:", logger,
  364 + "${beanName}Dao.findPageBySql(" + sqlCondition + ", " + page + ", " + pageSize + ", " + fromWriteDB + ")\n"
  365 + + "fromWriteDB:" +fromWriteDB + "\n"
  366 + + "执行SQL:" + pagePql.toString() + "\n"
  367 + + "返回条数:" + (resultList==null?0:resultList.size()) + "\n"
  368 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒("
  369 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  370 + + "*-*"
  371 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  372 + + ")");
  373 + }
  374 + return null;
  375 + }
  376 +
  377 + /**
  378 + * 添加
  379 + */
  380 + public int add${beanName}PO(${beanName}PO ${beanName}) {
  381 + if (null == ${beanName}) {
  382 + LogUtils.error("error:", logger, new Exception("请求条件异常,${beanName}不能为空!"), null, null);
  383 + return -1;
  384 + }
  385 + Date starttime = new Date();
  386 + <#--
  387 + if (${beanName}.get${pkBeanName}() == null) {
  388 + ${beanName}.set${pkBeanName}(this.find${beanName}POSeqNextVal());
  389 + }
  390 + -->
  391 + <#if columnList?exists>
  392 + <#list columnList as clist>
  393 + <#if clist.seqName?exists>
  394 + if (${beanName}.get${pkBeanName}() == null) {
  395 + ${beanName}.set${clist.columnUName}(this.find${beanName}POSeqNextVal());
  396 + }
  397 + </#if>
  398 + </#list>
  399 + </#if>
  400 + StringBuffer sql = new StringBuffer("INSERT INTO ${tableName}(" + "${column_list_str}" + ") VALUES (");
  401 + StringBuffer sqlI = new StringBuffer("INSERT INTO ${tableName}(");
  402 + StringBuffer sqlC = new StringBuffer(") VALUES (");
  403 + StringBuffer pql = new StringBuffer(sql.toString());
  404 + List<Object> list = new ArrayList<Object>();
  405 + <#if columnList?exists>
  406 + <#list columnList as clist>
  407 + if(${beanName}.get${clist.columnUName}() != null){
  408 + sqlI.append("${clist.columnName},");
  409 + sqlC.append(" ?, ");
  410 + pql.append(${beanName}.get${clist.columnUName}() + ", ");
  411 + list.add(${beanName}.get${clist.columnUName}());
  412 + }
  413 +
  414 + </#list>
  415 + </#if>
  416 +
  417 + int count = 0;
  418 + try {
  419 + jdbcegroceryWrite.update(StringUtil.removeLast(StringUtil.removeLast(sqlI.toString())+sqlC.toString()) + ")", list.toArray());
  420 + count = jdbcegroceryWrite.queryForInt("SELECT LAST_INSERT_ID()");
  421 + return count;
  422 + } catch (Exception e) {
  423 + LogUtils.error("error:", logger, e, StringUtil.removeLast(pql.toString()) + ")", null);
  424 + } finally {
  425 + Date endtime = new Date();
  426 + LogUtils.info("info:", logger,
  427 + "${beanName}Dao.add${beanName}PO (${beanName}PO ${beanName})\n"
  428 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + ")" + "\n"
  429 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  430 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  431 + + "*-*"
  432 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  433 + + ")");
  434 + }
  435 + return -1;
  436 + }
  437 + /**
  438 + * 批量添加
  439 + */
  440 + public int add${beanName}POList(List<${beanName}PO> ${beanName}list) {
  441 + Date starttime = new Date();
  442 + int count = 0;
  443 + for (${beanName}PO ${beanName} : ${beanName}list) {
  444 + count += add${beanName}PO(${beanName});
  445 + }
  446 + Date endtime = new Date();
  447 + LogUtils.info("info:", logger,
  448 + "${beanName}Dao.add${beanName}POList(List<${beanName}PO> ${beanName}list)\n"
  449 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  450 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  451 + + "*-*"
  452 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  453 + + ")");
  454 + return count;
  455 + }
  456 + /**
  457 + * 按ID删除
  458 + */
  459 + public int delete${beanName}POByID(${pkType} id) {
  460 + Date starttime = new Date();
  461 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName} WHERE");
  462 + StringBuffer pql = new StringBuffer(sql.toString());
  463 + pql.append(" ${pkColumName} = " + id);
  464 + sql.append(" ${pkColumName} = ?");
  465 + int count = 0;
  466 + try {
  467 + count = jdbcegroceryWrite.update(sql.toString(), id);
  468 + return count;
  469 + } catch (Exception e) {
  470 + LogUtils.error("error:", logger, e, pql.toString(), null);
  471 + } finally {
  472 + Date endtime = new Date();
  473 + LogUtils.info("info:", logger,
  474 + "${beanName}Dao.delete${beanName}POByID(${pkType} id)\n"
  475 + + "执行SQL:" + pql.toString() + "\n"
  476 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  477 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  478 + + "*-*"
  479 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  480 + + ")");
  481 + }
  482 + return -1;
  483 + }
  484 + /**
  485 + * 删除按List<Object[]>条件
  486 + * Object[]数组长度是3
  487 + * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  488 + */
  489 + public int delete${beanName}POByCondition(List<Object[]> condition) {
  490 + if (null == condition || condition.size() == 0) {
  491 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求条件List<Object[]> condition不能为空!"), null, null);
  492 + return -1;
  493 + }
  494 + if (StringUtil.isAutowired(condition)) {
  495 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  496 + return -1;
  497 + }
  498 + Date starttime = new Date();
  499 + List<Object> list = new ArrayList<Object>();
  500 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName}");
  501 + StringBuffer pql = new StringBuffer(sql.toString());
  502 + JdbcUtil.appendWhereCondition(sql, pql, list, condition);
  503 + int count = 0;
  504 + try {
  505 + count = jdbcegroceryWrite.update( sql.toString(), list.toArray());
  506 + return count;
  507 + } catch (Exception e) {
  508 + LogUtils.error("error:", logger, e, pql.toString(), null);
  509 + } finally {
  510 + Date endtime = new Date();
  511 + LogUtils.info("cacheinfo:", logger,
  512 + "${beanName}Dao.delete${beanName}POByCondition(List<Object[]> condition)\n"
  513 + + "执行SQL:" + pql.toString() + "\n"
  514 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  515 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  516 + + "*-*"
  517 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  518 + + ")");
  519 + }
  520 + return -1;
  521 + }
  522 +
  523 + /**
  524 + * 删除按condition条件
  525 + * 建议使用delete${beanName}POByCondition(List<Object[]> condition), 如果remove${beanName}POByCondition(List<Object[]> condition)满足不了where条件可以使用此方法。
  526 + * condition为where后面的条件,condition不能为空。
  527 + */
  528 + public int delete${beanName}POBySql(String sqlCondition) {
  529 + if (StringUtil.isEmpty(sqlCondition)) {
  530 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求条件String sqlCondition不能为空!"), null, null);
  531 + return -1;
  532 + }
  533 + if (StringUtil.isAutowired(sqlCondition)) {
  534 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  535 + return -1;
  536 + }
  537 + Date starttime = new Date();
  538 +
  539 + StringBuffer sql = new StringBuffer("DELETE FROM ${tableName} WHERE ");
  540 + int count = 0;
  541 + try {
  542 + count = jdbcegroceryWrite.update( sql.toString() + sqlCondition);
  543 + return count;
  544 + } catch (Exception e) {
  545 + LogUtils.error("error:", logger, e, sql.toString() + sqlCondition, null);
  546 + } finally {
  547 + Date endtime = new Date();
  548 + LogUtils.info("info", logger,
  549 + "${beanName}Dao.delete${beanName}POBySql(String sqlCondition)\n"
  550 + + "执行SQL:" + sql.toString() + sqlCondition + "\n"
  551 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  552 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  553 + + "*-*"
  554 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  555 + + ")");
  556 + }
  557 + return -1;
  558 + }
  559 +
  560 + /**
  561 + * 根据list对象逐个删除。
  562 + */
  563 + public int delete${beanName}POList(List<${beanName}PO> ${beanName}list) {
  564 + int count = 0;
  565 + for (${beanName}PO ${beanName} : ${beanName}list) {
  566 + count += delete${beanName}POByID(${beanName}.get${pkBeanName}());
  567 + }
  568 + return count;
  569 + }
  570 +
  571 + /**
  572 + * 根据对象ID修改。
  573 + */
  574 + public int update${beanName}PO(${beanName}PO ${beanName}) {
  575 + if (null == ${beanName} || null == ${beanName}.get${pkBeanName}()) {
  576 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求对象和对象ID不能为空!"), null, null);
  577 + return -1;
  578 + }
  579 + Date starttime = new Date();
  580 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  581 + StringBuffer pql = new StringBuffer(sql.toString());
  582 + List<Object> list = new ArrayList<Object>();
  583 + <#if columnList?exists>
  584 + <#list columnList as clist>
  585 + <#if clist.seqName?exists>
  586 + <#else>
  587 + <#if clist.columnJAVAType = "Long" || clist.columnJAVAType = "Integer" || clist.columnJAVAType = "Short" || clist.columnJAVAType = "Float" || clist.columnJAVAType = "Double">
  588 + boolean ${clist.columnUName}IsZero = false;
  589 + Object variation${clist.columnUName} = ${beanName}.getVariation${clist.columnUName}();
  590 + if (variation${clist.columnUName} instanceof BigDecimal) {
  591 + ${clist.columnUName}IsZero = (((BigDecimal)variation${clist.columnUName}).compareTo(BigDecimal.ZERO) == 0);
  592 + } else {
  593 + Long l${clist.columnUName} = Long.parseLong(String.valueOf(variation${clist.columnUName}));
  594 + ${clist.columnUName}IsZero = (l${clist.columnUName} == 0);
  595 + }
  596 + if (!${clist.columnUName}IsZero) {
  597 + sql.append(" ${clist.columnName} = ${clist.columnName} + ?, ");
  598 + pql.append(" ${clist.columnName} = ${clist.columnName} + " + ${beanName}.getVariation${clist.columnUName}() + ",");
  599 + list.add(${beanName}.getVariation${clist.columnUName}());
  600 + } else {
  601 + sql.append(" ${clist.columnName} = ?, ");
  602 + pql.append(" ${clist.columnName} = " + ${beanName}.get${clist.columnUName}() + ",");
  603 + list.add(${beanName}.get${clist.columnUName}());
  604 + }
  605 + <#elseif clist.columnJAVAType = "java.math.BigDecimal">
  606 + if (${beanName}.getVariation${clist.columnUName}().compareTo(BigDecimal.ZERO) != 0) {
  607 + sql.append(" ${clist.columnName} = ${clist.columnName} + ?, ");
  608 + pql.append(" ${clist.columnName} = ${clist.columnName} + " + ${beanName}.getVariation${clist.columnUName}() + ",");
  609 + list.add(${beanName}.getVariation${clist.columnUName}());
  610 + } else {
  611 + sql.append(" ${clist.columnName} = ?, ");
  612 + pql.append(" ${clist.columnName} = " + ${beanName}.get${clist.columnUName}() + ",");
  613 + list.add(${beanName}.get${clist.columnUName}());
  614 + }
  615 + <#else>
  616 + sql.append(" ${clist.columnName} = ?, ");
  617 + pql.append(" ${clist.columnName} = " + ${beanName}.get${clist.columnUName}() + ",");
  618 + list.add(${beanName}.get${clist.columnUName}());
  619 + </#if>
  620 + </#if>
  621 + </#list>
  622 + </#if>
  623 +
  624 + String where = " WHERE ${pkColumName} = ?";
  625 + String pwhere = " WHERE ${pkColumName} = " + ${beanName}.get${pkBeanName}();
  626 + list.add(${beanName}.get${pkBeanName}());
  627 + int count = 0;
  628 + try {
  629 + count = jdbcegroceryWrite.update(StringUtil.removeLast(sql.toString()) + where, list.toArray());
  630 + return count;
  631 + } catch (Exception e) {
  632 + LogUtils.error("error:", logger, e, StringUtil.removeLast(pql.toString()) + pwhere, null);
  633 + } finally {
  634 + Date endtime = new Date();
  635 + LogUtils.info("info", logger,
  636 + "${beanName}Dao.update${beanName}PO(${beanName}PO ${beanName})\n"
  637 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + pwhere + "\n"
  638 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  639 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  640 + + "*-*"
  641 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  642 + + ")");
  643 + }
  644 + return -1;
  645 + }
  646 +
  647 + /**
  648 + * 根据ID修改指定的值
  649 + */
  650 + public int update${beanName}FieldById(List<Object[]> changeList, ${pkType} id) {
  651 + if (null == id) {
  652 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求对象和对象ID不能为空!"), null, null);
  653 + return -1;
  654 + }
  655 + Date starttime =new Date();
  656 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  657 + StringBuffer pql = new StringBuffer(sql.toString());
  658 + List<Object> list = new ArrayList<Object>();
  659 + Map<Object,Object> map = new HashMap<Object,Object>();
  660 + for (int i = 0, iLen = changeList.size(); i < iLen; i++) {
  661 + String name = (String) changeList.get(i)[0];
  662 + Object value = changeList.get(i)[1];
  663 + String variationOpt = "=";
  664 + if (changeList.get(i).length > 2)
  665 + variationOpt = (String)changeList.get(i)[2];
  666 + if (variationOpt.equals("=")) {
  667 + sql.append(" " + name + " = ?,");
  668 + list.add(value);
  669 + if (value == null) {
  670 + pql.append(" " + name + "=null,");
  671 + } else {
  672 + pql.append(" " + name + "=\"" + value.toString() + "\",");
  673 + }
  674 + map.put(name, value);
  675 + } else {
  676 + sql.append(" " + name + " = " + name + " + ?,");
  677 + list.add(value);
  678 + pql.append(" " + name + " = " + name + " + " + value.toString() + ",");
  679 + <#--会有问题 暂留
  680 + map.put(name, value);-->
  681 + }
  682 + }
  683 +
  684 + String where = " WHERE ${pkColumName}=?";
  685 + String pwhere = " WHERE ${pkColumName}=\"" + id + "\"";
  686 + list.add(id);
  687 + int count = 0;
  688 + try {
  689 + count = jdbcegroceryWrite.update(StringUtil.removeLast(sql.toString()) + where, list.toArray());
  690 + return count;
  691 + } catch (Exception e) {
  692 + LogUtils.error("error:", logger, e, StringUtil.removeLast(pql.toString()) + pwhere, null);
  693 + } finally {
  694 + Date endtime = new Date();
  695 + LogUtils.info("info", logger,
  696 + "${beanName}Dao.update${beanName}PO(List<Object[]> changeList, ${pkType} id)\n"
  697 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + pwhere + "\n"
  698 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  699 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  700 + + "*-*"
  701 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  702 + + ")");
  703 + }
  704 + return -1;
  705 + }
  706 +
  707 + /**
  708 + * 批量修改。
  709 + */
  710 + public int update${beanName}POList(List<${beanName}PO> ${beanName}list) {
  711 + int count = 0;
  712 + for (${beanName}PO ${beanName} : ${beanName}list) {
  713 + count += update${beanName}PO(${beanName});
  714 + }
  715 + return count;
  716 + }
  717 +
  718 + /**
  719 + * List<Object[]> updateObj 要修改成的值,数组长度为2,第一个值为列名,第二个值是要改成的值。
  720 + * List<Object[]> condition 修改的条件, 数组长度是3, 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。
  721 + */
  722 + public int update${beanName}POByCondition(List<Object[]> updateObj, List<Object[]> condition) {
  723 + if (null == updateObj || updateObj.size() == 0) {
  724 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求条件List<Object[]> updateObj不能为空!"), null, null);
  725 + return -1;
  726 + }
  727 + if (null == condition || condition.size() == 0) {
  728 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求条件List<Object[]> condition不能为空!"), null, null);
  729 + return -1;
  730 + }
  731 + if (StringUtil.isAutowired(condition)) {
  732 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  733 + return -1;
  734 + }
  735 + Date starttime = new Date();
  736 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  737 + StringBuffer pql = new StringBuffer(sql.toString());
  738 + List<Object> list = new ArrayList<Object>();
  739 + JdbcUtil.appendSql(sql, pql, list, updateObj);
  740 + StringBuffer where = new StringBuffer("");
  741 + StringBuffer pwhere = new StringBuffer("");
  742 + JdbcUtil.appendWhereCondition(where, pwhere, list, condition);
  743 + int count = 0;
  744 + try {
  745 + count = jdbcegroceryWrite.update(StringUtil.removeLast(sql.toString()) + where.toString(), list.toArray());
  746 + return count;
  747 + } catch (Exception e) {
  748 + LogUtils.error("error:", logger, e, StringUtil.removeLast(pql.toString())+pwhere.toString(), null, null);
  749 + } finally {
  750 + Date endtime = new Date();
  751 + LogUtils.info("info", logger,
  752 + "${beanName}Dao.update${beanName}POByCondition(List<Object[]> updateObj, List<Object[]> condition)\n"
  753 + + "执行SQL:" + StringUtil.removeLast(pql.toString())+pwhere.toString() + "\n"
  754 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  755 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  756 + + "*-*"
  757 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  758 + + ")");
  759 + }
  760 + return -1;
  761 + }
  762 +
  763 + /**
  764 + * List<Object[]> updateObj 要修改成的值,数组长度为2,第一个值为列名,第二个值是要改成的值。
  765 + * String sqlCondition 修改的条件。
  766 + */
  767 + public int update${beanName}POBySql(List<Object[]> updateObj, String sqlCondition) {
  768 + if (null == updateObj || updateObj.size() == 0) {
  769 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求条件List<Object[]> updateObj不能为空!"), null, null);
  770 + return -1;
  771 + }
  772 + if (StringUtil.isEmpty(sqlCondition)) {
  773 + LogUtils.error("error:", logger, new Exception("请求条件异常,请求条件sqlCondition不能为空!"), null, null);
  774 + return -1;
  775 + }
  776 + if (StringUtil.isAutowired(sqlCondition)) {
  777 + LogUtils.error("error:", logger, new Exception("请求条件异常,无效请求!"), null, null);
  778 + return -1;
  779 + }
  780 + Date starttime = new Date();
  781 + StringBuffer sql = new StringBuffer("UPDATE ${tableName} SET");
  782 + StringBuffer pql = new StringBuffer(sql.toString());
  783 + List<Object> list = new ArrayList<Object>();
  784 + JdbcUtil.appendSql(sql, pql, list, updateObj);
  785 + int count = 0;
  786 + try {
  787 + count = jdbcegroceryWrite.update(StringUtil.removeLast(sql.toString()) + " WHERE "+sqlCondition, list.toArray());
  788 + return count;
  789 + } catch (Exception e) {
  790 + LogUtils.error("error:", logger, e, StringUtil.removeLast(pql.toString()) + " WHERE " + sqlCondition, null, null);
  791 + } finally {
  792 + Date endtime = new Date();
  793 + LogUtils.info("info", logger,
  794 + "${beanName}Dao.update${beanName}POBySql(List<Object[]> updateObj, String sqlCondition)\n"
  795 + + "执行SQL:" + StringUtil.removeLast(pql.toString()) + " WHERE " + sqlCondition + "\n"
  796 + + "方法执行时长:" + (endtime.getTime()-starttime.getTime()) + "毫秒, 影响记录数:" + count + "("
  797 + + StringUtil.dateToFormatStr(starttime, "yyyy-MM-dd HH:mm:ss.SSS")
  798 + + "*-*"
  799 + + StringUtil.dateToFormatStr(endtime, "yyyy-MM-dd HH:mm:ss.SSS")
  800 + + ")");
  801 + }
  802 + return -1;
  803 + }
  804 +}
0 805 \ No newline at end of file
... ...
src/com/taover/base/template/HtmlLayuiTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/HtmlLayuiTemplate.ftl
... ... @@ -0,0 +1,398 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <meta charset="utf-8">
  5 + <title>八爪云ERP系统</title>
  6 + <meta name="renderer" content="webkit">
  7 + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8 + <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  9 + <link rel="stylesheet" href="/plugins/layuiadmin/layui/css/layui.css" media="all">
  10 + <link rel="stylesheet" href="/plugins/layuiadmin/style/admin.css" media="all">
  11 +</head>
  12 +<body>
  13 +
  14 + <div class="layui-fluid">
  15 + <div class="layui-card">
  16 +
  17 + <!-- 筛选条件栏 -->
  18 + <div class="layui-form layui-card-header layuiadmin-card-header-auto">
  19 + <div class="layui-form-item">
  20 + <#list fields as tempField>
  21 + ${tempField["layui-search-item"]}
  22 + </#list>
  23 +
  24 + <div class="layui-inline">
  25 + <button class="layui-btn" lay-submit lay-filter="btn-search-bar">
  26 + <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  27 + </button>
  28 + </div>
  29 + </div>
  30 + </div>
  31 +
  32 + <!-- 表格窗体 -->
  33 + <div class="layui-card-body">
  34 + <div class="layui-btn-group" style="padding-bottom: 10px;">
  35 + <button class="layui-btn " onclick="add();">添加</button>
  36 + <button class="layui-btn " onclick="batchDelete();">删除</button>
  37 + </div>
  38 +
  39 + <table id="table-data-main" class="layui-table" lay-filter="table-data-main"></table>
  40 +
  41 + <script type="text/html" id="table-operation">
  42 + <a class="layui-btn layui-btn-normal layui-btn-xs " lay-event="operationLog"><i class="layui-icon layui-icon-log"></i>操作记录</a>
  43 + <a class="layui-btn layui-btn-normal layui-btn-xs " lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  44 + <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
  45 + </script>
  46 + </div>
  47 + </div>
  48 + </div>
  49 +
  50 + <!-- 添加表单 -->
  51 + <form id="form-data-add" class="layui-hide layui-form" lay-filter="form-data-add">
  52 + <#list fields as tempField>
  53 + <#if (tempField["name"]!="id")>
  54 + ${tempField["layui-form-item"]}
  55 + </#if>
  56 + </#list>
  57 +
  58 + <div class="layui-form-item">
  59 + <div class="layui-input-block">
  60 + <button type="button" class="layui-btn" onclick="addSubmit();">立即提交</button>
  61 + <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  62 + </div>
  63 + </div>
  64 + </form>
  65 +
  66 + <!-- 修改表单 -->
  67 + <form id="form-data-edit" class="layui-hide layui-form" lay-filter="form-data-edit">
  68 + <#list fields as tempField>
  69 + ${tempField["layui-form-item"]}
  70 + </#list>
  71 +
  72 + <div class="layui-form-item">
  73 + <div class="layui-input-block">
  74 + <button type="button" class="layui-btn" onclick="editSubmit();">立即提交</button>
  75 + <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  76 + </div>
  77 + </div>
  78 + </form>
  79 +
  80 + <!-- 隐藏信息 -->
  81 + <input id="data-checkList" type="hidden" name="ids" value=""/>
  82 +
  83 + <script src="/plugins/layuiadmin/layui/layui.js"></script>
  84 + <script>
  85 + layui.config({
  86 + base: '/plugins/layuiadmin/' //静态资源所在路径
  87 + }).extend({
  88 + index: 'lib/index' //主入口模块
  89 + }).use(['table', 'laydate', 'layer', 'form'], function(){
  90 + var $ = layui.$, form = layui.form, table = layui.table, laydate = layui.laydate;
  91 +
  92 + table.render({
  93 + elem: '#table-data-main',
  94 + url:'/${controllerPathMap}/query.htm',
  95 + request:{
  96 + pageName:'page',
  97 + limitName:'pageSize'
  98 + },
  99 + page:true,
  100 + loading:true,
  101 + response: {
  102 + statusName: 'resultId',
  103 + statusCode: 200,
  104 + msgName: 'resultMessage',
  105 + countName: 'total',
  106 + dataName: 'rows'
  107 + },
  108 + cols: [[
  109 + {checkbox: true},
  110 + <#list fields as tempField>
  111 + ${tempField["layui-table-item"]}
  112 + </#list>
  113 + {title:'操作', field:'id', fixed:'right', width:240, toolbar: '#table-operation'}
  114 + ]],
  115 + done: function(res, curr, count){
  116 + //将请求返回的数据存入document全局变量中
  117 + window.document.global_tableData = res;
  118 + }
  119 + });
  120 +
  121 + //日期组件初始化
  122 + $('.me-date-range').each(function(index, element){
  123 + laydate.render({
  124 + elem: element,
  125 + range: true
  126 + });
  127 + });
  128 +
  129 + //表格服务器端排序监听
  130 + table.on('sort(table-data-main)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值"
  131 + //尽管我们的 table 自带排序功能,但并没有请求服务端。
  132 + //有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
  133 + table.reload('table-data-main', {
  134 + initSort: obj //记录初始排序,如果不设的话,将无法标记表头的排序状态。 layui 2.1.1 新增参数
  135 + ,where: { //请求参数(注意:这里面的参数可任意定义,并非下面固定的格式)
  136 + sort: obj.field //排序字段
  137 + ,order: obj.type //排序方式
  138 + }
  139 + });
  140 + });
  141 +
  142 + //监听工具条
  143 + table.on('tool(table-data-main)', function(obj){
  144 + var data = obj.data;
  145 +
  146 + //表格操作栏动作入口
  147 + if(obj.event === 'operationLog'){ //查看操作日志动作监听入口
  148 + layer.open({
  149 + type: 1,
  150 + content: '<table id="form-data-operation-table" ></table>',
  151 + btn: null,
  152 + success: function(layero, index){
  153 + table.render({
  154 + elem: '#form-data-operation-table'
  155 + ,url: '/logtableoper/queryRecord.htm?recordId='+data.id
  156 + ,cols: [[
  157 + {field: 'userName', width: 150, title: '操作用户'}
  158 + ,{field: 'logName', width: 100, title: '操作类型'}
  159 + ,{field: 'createTime', width: 150, title: '创建时间'}
  160 + ,{field: 'description', width: 200, title: '备注信息'}
  161 + ]],
  162 + request:{pageName:'page',limitName:'pageSize'},
  163 + response: {statusName: 'resultId',statusCode: 200,msgName: 'resultMessage',countName: 'total',dataName: 'rows'},
  164 + page:true,
  165 + loading:true,
  166 + done: function(data){
  167 + $('#form-data-operation-table').parent('.layui-layer-content').css({marginTop:'-10px',marginBottom:'-10px'});
  168 + layero.resize();
  169 + }
  170 + });
  171 + }
  172 + });
  173 + } else if(obj.event === 'delete'){ //删除按钮操作入口
  174 + if(!data){
  175 + layer.alert('没有找到需要删除的记录~');
  176 + return;
  177 + }else{
  178 + layer.confirm('您选择了一条记录,确认删除', function(){
  179 + $.ajax({
  180 + url: '/${controllerPathMap}/delete.htm',
  181 + type: 'post',
  182 + data: {
  183 + ids: data.id
  184 + },
  185 + success: function(data){
  186 + if(data && data.resultMessage){
  187 + layer.alert(data.resultMessage);
  188 + table.reload('table-data-main');
  189 + }else{
  190 + layer.alert('返回的数据无法解析,请反馈到管理员');
  191 + }
  192 + },
  193 + error: function(data){
  194 + layer.alert('请求出错,请检查网络连接是否正常');
  195 + }
  196 + });
  197 + });
  198 + }
  199 + } else if(obj.event === 'edit'){ //修改按钮操作入口
  200 + var formHtml = '<form id="activeForm" class="layui-form" lay-filter="activeForm" style="padding:20px;">' + $('#form-data-edit').html() + '</form>';
  201 + layer.open({
  202 + title: '修改窗口',
  203 + type: 1,
  204 + content: formHtml,
  205 + btn: null
  206 + });
  207 + form.val('activeForm', data);
  208 + form.render();
  209 + $('.me-date-form').each(function(index, element){
  210 + laydate.render({
  211 + elem: element,
  212 + type: 'datetime'
  213 + });
  214 + });
  215 + }
  216 + });
  217 +
  218 + //表格的checkbox事件
  219 + table.on('checkbox(table-data-main)', function(obj){
  220 + var ids = $('#data-checkList').val();
  221 + var idsArray = new Array();
  222 + var resultArray = new Array();
  223 + if(ids != ''){
  224 + idsArray = ids.split(',');
  225 + resultArray = ids.split(',');
  226 + }
  227 +
  228 + if(obj.checked){
  229 + if(obj.type === 'one'){
  230 + resultArray.push(obj.data.id);
  231 + }else{
  232 + var tempData = window.document.global_tableData.rows;
  233 + for(var i=0; i<tempData.length; ++i){
  234 + resultArray.push(tempData[i].id);
  235 + }
  236 + }
  237 + }else{
  238 + if(obj.type === 'one'){
  239 + resultArray = new Array();
  240 + $(idsArray).each(function(index, item){
  241 + if(obj.data.id != item){
  242 + resultArray.push(item);
  243 + }
  244 + });
  245 + }else{
  246 + resultArray = new Array();
  247 + }
  248 + }
  249 +
  250 + var tempResult = '';
  251 + if(resultArray.length > 0){
  252 + tempResult = resultArray.join(',');
  253 + }
  254 + $('#data-checkList').val(tempResult);
  255 + });
  256 +
  257 + //搜索按钮点击事件
  258 + form.on('submit(btn-search-bar)', function(data){
  259 + var field = data.field;
  260 + //执行重载
  261 + table.reload('table-data-main', {
  262 + where: field
  263 + });
  264 + });
  265 +
  266 + });
  267 +
  268 + //添加按钮监听方法
  269 + function add(){
  270 + var $ = layui.$;
  271 + layui.use(['layer', 'form', 'laydate'], function(){
  272 + var layer = layui.layer;
  273 + var form = layui.form;
  274 + var laydate = layui.laydate;
  275 + var formHtml = '<form id="activeForm" class="layui-form " style="padding:20px;">' + $('#form-data-add').html() + '</form>';
  276 + layer.open({
  277 + title: '添加窗口',
  278 + type: 1,
  279 + content: formHtml,
  280 + btn: null
  281 + });
  282 + form.render();
  283 + $('#activeForm .me-date-form').each(function(index, element){
  284 + laydate.render({
  285 + elem: element,
  286 + type: 'datetime'
  287 + });
  288 + });
  289 + });
  290 + }
  291 +
  292 + //添加窗口表单提交方法
  293 + function addSubmit(){
  294 + var $ = layui.$;
  295 + layui.use(['layer', 'form', 'table'], function(){
  296 + var layer = layui.layer;
  297 + var form = layui.form;
  298 + var table = layui.table;
  299 + var formArray = $('#activeForm').serializeArray();
  300 + var params = {};
  301 + layui.each(formArray, function(index, item){
  302 + params[item.name] = item.value;
  303 + });
  304 + $.ajax({
  305 + url: '/${controllerPathMap}/add.htm',
  306 + type: 'post',
  307 + data: params,
  308 + success: function(data){
  309 + layer.closeAll();
  310 + if(data && data.resultMessage){
  311 + layer.alert(data.resultMessage);
  312 + table.reload('table-data-main');
  313 + }else{
  314 + layer.alert('返回的数据无法解析,请反馈到管理员');
  315 + }
  316 + },
  317 + error: function(data){
  318 + layer.closeAll();
  319 + layer.alert('请求出错,请检查网络连接是否正常');
  320 + }
  321 + });
  322 + });
  323 + }
  324 +
  325 + //批量删除按钮监听方法
  326 + function batchDelete(){
  327 + var $ = layui.$;
  328 + layui.use(['layer', 'form', 'table'], function(){
  329 + var layer = layui.layer;
  330 + var form = layui.form;
  331 + var table = layui.table;
  332 + var ids = $('#data-checkList').val();
  333 + if(ids == '' || ids.length == 0){
  334 + layer.alert('没有选择任何选项,请选择需要删除记录再进行该操作');
  335 + return;
  336 + }else{
  337 + var idsArray = ids.split(',');
  338 + layer.confirm('您当前选择了'+idsArray.length+'条记录,是否确认删除?', function(){
  339 + $.ajax({
  340 + url: '/${controllerPathMap}/delete.htm',
  341 + type: 'post',
  342 + data: {
  343 + ids: ids
  344 + },
  345 + success: function(data){
  346 + layer.closeAll();
  347 + if(data && data.resultMessage){
  348 + layer.alert(data.resultMessage);
  349 + table.reload('table-data-main');
  350 + }else{
  351 + layer.alert('返回的数据无法解析,请反馈到管理员');
  352 + }
  353 + },
  354 + error: function(data){
  355 + layer.closeAll();
  356 + layer.alert('请求出错,请检查网络连接是否正常');
  357 + }
  358 + });
  359 + });
  360 + }
  361 + });
  362 + }
  363 +
  364 + //修改按钮表单提交方法
  365 + function editSubmit(){
  366 + var $ = layui.$;
  367 + layui.use(['layer', 'form', 'table'], function(){
  368 + var layer = layui.layer;
  369 + var form = layui.form;
  370 + var table = layui.table;
  371 + var formArray = $('#activeForm').serializeArray();
  372 + var params = {};
  373 + layui.each(formArray, function(index, item){
  374 + params[item.name] = item.value;
  375 + });
  376 + $.ajax({
  377 + url: '/${controllerPathMap}/edit.htm',
  378 + type: 'post',
  379 + data: params,
  380 + success: function(data){
  381 + layer.closeAll();
  382 + if(data && data.resultMessage){
  383 + layer.alert(data.resultMessage);
  384 + table.reload('table-data-main');
  385 + }else{
  386 + layer.alert('返回的数据无法解析,请反馈到管理员');
  387 + }
  388 + },
  389 + error: function(data){
  390 + layer.closeAll();
  391 + layer.alert('请求出错,请检查网络连接是否正常');
  392 + }
  393 + });
  394 + });
  395 + }
  396 + </script>
  397 +</body>
  398 +</html>
... ...
src/com/taover/base/template/HtmlTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/HtmlTemplate.ftl
... ... @@ -0,0 +1,58 @@
  1 +<div class="easyui-layout" data-options="fit:true">
  2 + <div region="center">
  3 + <table id="${controllerPathMap}_list"></table>
  4 + </div>
  5 +</div>
  6 +
  7 +<div id="${controllerPathMap}_toolbar" class="grid-toolbar">
  8 + <form id="${controllerPathMap}_toolbarForm">
  9 + <#list fields as tempField>
  10 + ${tempField["easyui-search-item"]}
  11 + </#list>
  12 + <span>
  13 + <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="${controllerPathMap}Page.searchObjects();">查询</a>
  14 + </span>
  15 + </form>
  16 + <div>
  17 + <a href="#" iconCls="icon-add" class="easyui-linkbutton" onclick="${controllerPathMap}Page.addObject();">添加</a>
  18 + <a href="#" iconCls="icon-cancel" class="easyui-linkbutton" onclick="${controllerPathMap}Page.deleteObjects();">删除</a>
  19 + </div>
  20 +</div>
  21 +
  22 +<!--
  23 + 表单呈现样式:
  24 + 数字类型--numberbox
  25 + 文本类型--validatebox
  26 + 日期类型--datetimebox
  27 + 密码类型--passwordbox
  28 + ...等等
  29 + 表单验证方式:
  30 + 必填--requried
  31 + 数字验证--numberbox[precision,min,max]
  32 + 自定义验证--validType[url,email,length[0,100],remote['http://.../action.do','paramName']]
  33 + -->
  34 +<form id="${controllerPathMap}_add">
  35 + <table class="dialog-form-table">
  36 + <#list fields as tempField>
  37 + <#if (tempField["name"]!="id")>
  38 + <tr>
  39 + <td><span>${tempField["cnName"]}:</span></td>
  40 + <td><input type="text" name="${tempField["name"]!""}" class="easyui-${tempField["easyui"]!""} textbox" ${tempField["required"]!""} ${tempField["attr"]!""} /></td>
  41 + </tr>
  42 + </#if>
  43 + </#list>
  44 + </table>
  45 +</form>
  46 +
  47 +<form id="${controllerPathMap}_edit">
  48 + <table class="dialog-form-table">
  49 + <#list fields as tempField>
  50 + <tr>
  51 + <td><span>${tempField["cnName"]}:</span></td>
  52 + <td><input type="text" name="${tempField["name"]!""}" class="easyui-${tempField["easyui"]!""} textbox" ${tempField["required"]!""} ${tempField["attr"]!""} /></td>
  53 + </tr>
  54 + </#list>
  55 + </table>
  56 +</form>
  57 +
  58 +<script type="text/javascript" src="/manage/js/${controllerPathMap}.js?v=1234"></script>
... ...
src/com/taover/base/template/JsTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/JsTemplate.ftl
... ... @@ -0,0 +1,33 @@
  1 +$(function(){
  2 + var controllerPathMap = "${controllerPathMap}";
  3 + var addDialogId = controllerPathMap+"_add";
  4 + var editDialogId = controllerPathMap+"_edit";
  5 + var gridId = controllerPathMap+"_list";
  6 + var gridToolbarId = controllerPathMap+"_toolbar"
  7 + var gridColumns = [{
  8 + field: 'selectedItem',
  9 + checkbox: true
  10 + },
  11 + <#list fields as tempField>
  12 + <#if tempField["name"] != "id">
  13 + {
  14 + field: '${tempField["name"]}',
  15 + title: '${tempField["cnName"]}',
  16 + sortable: true,
  17 + },
  18 + </#if>
  19 + </#list>
  20 + {
  21 + field : 'id',
  22 + title : '操作',
  23 + width : 10,
  24 + formatter : function(value, rows, index){
  25 + return '<a style="color: green" onclick="${controllerPathMap}Page.editObject(' + index + ');">修改</a>&nbsp;|&nbsp;' +
  26 + '<a style="color: red" target="_self" onclick="${controllerPathMap}Page.deleteObject('+value+');">删除</a>';
  27 + },
  28 + },
  29 + ];
  30 +
  31 + ${controllerPathMap}Page = tabInit(controllerPathMap, addDialogId, editDialogId, gridId, gridToolbarId, gridColumns);
  32 +});
  33 +
... ...
src/com/taover/base/template/POTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/POTemplate.ftl
... ... @@ -0,0 +1,75 @@
  1 +<#--包名 -->
  2 +package ${packages}
  3 +import java.util.HashMap;
  4 +import java.util.Map;
  5 +import java.io.Serializable;
  6 +/**
  7 + <#if version?exists>
  8 + * @version ${version}
  9 + </#if>
  10 + */
  11 +
  12 + public class ${name}PO implements Serializable {
  13 +
  14 + <#--变量 ,get,set方法-->
  15 +<#if tablemodel.columnlist?exists>
  16 + <#list tablemodel.columnlist as clist>
  17 + private ${clist.columnJAVAType} ${clist.columnName};
  18 +
  19 + <#if clist.columnRemarks?exists>
  20 + /**
  21 + * ${clist.columnRemarks}
  22 + */
  23 + <#else>
  24 + </#if>
  25 + <#if clist.columnJAVAType = "java.sql.Timestamp" >
  26 + @org.codehaus.jackson.map.annotate.JsonSerialize(using = com.taover.tools.DateTimeSerializer.class)
  27 + </#if>
  28 + <#if clist.columnJAVAType = "java.util.Date" >
  29 + @org.codehaus.jackson.map.annotate.JsonSerialize(using = com.taover.tools.DateSerializer.class)
  30 + </#if>
  31 + public ${clist.columnJAVAType} get${clist.columnMethodName}(){
  32 + return ${clist.columnName};
  33 + }
  34 +
  35 + public void set${clist.columnMethodName}(${clist.columnJAVAType} ${clist.columnName}){
  36 + this.${clist.columnName} = ${clist.columnName};
  37 + }
  38 +
  39 + <#if clist.columnJAVAType = "Long" || clist.columnJAVAType = "java.math.BigDecimal" || clist.columnJAVAType = "Integer" || clist.columnJAVAType = "Short" || clist.columnJAVAType = "Float" || clist.columnJAVAType = "Double">
  40 + <#if clist.columnJAVAType = "Long">
  41 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0L;
  42 + </#if>
  43 + <#if clist.columnJAVAType = "java.math.BigDecimal">
  44 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = new java.math.BigDecimal(0.0);
  45 + </#if>
  46 + <#if clist.columnJAVAType = "Integer">
  47 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0;
  48 + </#if>
  49 + <#if clist.columnJAVAType = "Short">
  50 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0;
  51 + </#if>
  52 + <#if clist.columnJAVAType = "Double">
  53 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0d;
  54 + </#if>
  55 + <#if clist.columnJAVAType = "Float">
  56 + private ${clist.columnJAVAType} variation${clist.columnMethodName} = 0f;
  57 + </#if>
  58 + public ${clist.columnJAVAType} getVariation${clist.columnMethodName}(){
  59 + return variation${clist.columnMethodName};
  60 + }
  61 +
  62 + public void setVariation${clist.columnMethodName}(${clist.columnJAVAType} variation${clist.columnName}){
  63 + this.variation${clist.columnMethodName} = variation${clist.columnName};
  64 + }
  65 +
  66 + </#if>
  67 +
  68 + </#list>
  69 +</#if>
  70 +
  71 + @Override
  72 + public String toString() {
  73 + return "${name}PO: ${toStringMethodBody};
  74 + }
  75 + }
0 76 \ No newline at end of file
... ...
src/com/taover/base/template/ServiceExportTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/ServiceExportTemplate.ftl
... ... @@ -0,0 +1,21 @@
  1 +package ${mainPackageInfo}.${moduleName}.export;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +
  8 +import javax.annotation.Resource;
  9 +
  10 +import org.apache.commons.lang.StringUtils;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +import com.taover.base.ResultInfo;
  14 +import ${mainPackageInfo}.contants.ResultInfoCode;
  15 +import ${mainPackageInfo}.utils.UtilsString;
  16 +import ${mainPackageInfo}.utils.UtilsSql;
  17 +
  18 +@Service
  19 +public class ${moduleNameFirstBig}ExportService{
  20 +
  21 +}
... ...
src/com/taover/base/template/ServiceImplTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/ServiceImplTemplate.ftl
... ... @@ -0,0 +1,111 @@
  1 +package ${mainPackageInfo}.${moduleName}.service.impl;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +
  8 +import javax.annotation.Resource;
  9 +
  10 +import org.apache.commons.lang.StringUtils;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +import com.taover.base.ResultInfo;
  14 +import ${mainPackageInfo}.contants.ResultInfoCode;
  15 +import ${mainPackageInfo}.utils.UtilsString;
  16 +import ${mainPackageInfo}.utils.UtilsSql;
  17 +import ${mainPackageInfo}.${moduleName}.service.${beanClassName}Service;
  18 +
  19 +import ${poPackageInfo}.${beanClassName}Dao;
  20 +import ${poPackageInfo}.${beanClassName}PO;
  21 +
  22 +@Service
  23 +public class ${beanClassName}ServiceImpl implements ${beanClassName}Service{
  24 + @Resource
  25 + private ${beanClassName}Dao ${beanFieldName}Dao;
  26 +
  27 + @Override
  28 + public ResultInfo add(${beanClassName}PO ${beanFieldName}PO){
  29 + //创建返回对象
  30 + ResultInfo result = new ResultInfo();
  31 +
  32 + //调用Service方法
  33 + int addResult = this.${beanFieldName}Dao.add${beanClassName}PO(${beanFieldName}PO);
  34 +
  35 + if(addResult < 1){
  36 + result.setResultId(ResultInfoCode.RESULTID_FAILURE_210);
  37 + result.setResultMessage("添加失败");
  38 + }else{
  39 + result.setResultId(ResultInfoCode.RESULTID_SUCCESS_200);
  40 + result.setResultMessage("添加成功");
  41 + }
  42 + return result;
  43 + }
  44 +
  45 + @Override
  46 + public ResultInfo delete(String ids){
  47 + //创建返回对象
  48 + ResultInfo result = new ResultInfo();
  49 +
  50 + //参数检验
  51 + if(ids == null || ids.length() == 0){
  52 + result.setResultId(ResultInfoCode.RESULTID_FAILURE_210);
  53 + result.setResultMessage("删除失败,缺少主键信息");
  54 + return result;
  55 + }
  56 +
  57 + Integer[] idsArray = UtilsString.transIdStringToArray(ids, ",");
  58 + if(idsArray == null || idsArray.length == 0){
  59 + result.setResultId(ResultInfoCode.RESULTID_FAILURE_210);
  60 + result.setResultMessage("删除失败,缺少主键信息");
  61 + return result;
  62 + }
  63 +
  64 + String idsCondition = " id in(" + idsArray[0];
  65 + for(int i=1; i<idsArray.length; ++i){
  66 + idsCondition += ","+idsArray[i];
  67 + }
  68 + idsCondition += ")";
  69 +
  70 + //调用Service方法
  71 + int deleteResult = this.${beanFieldName}Dao.delete${beanClassName}POBySql(idsCondition);
  72 + if(deleteResult < 1){
  73 + result.setResultId(ResultInfoCode.RESULTID_FAILURE_210);
  74 + result.setResultMessage("删除失败");
  75 + }else{
  76 + result.setResultId(ResultInfoCode.RESULTID_SUCCESS_200);
  77 + result.setResultMessage("删除成功");
  78 + }
  79 + return result;
  80 + }
  81 +
  82 + @Override
  83 + public ResultInfo edit(${beanClassName}PO ${beanFieldName}PO){
  84 + //创建返回对象
  85 + ResultInfo result = new ResultInfo();
  86 +
  87 + //参数检验
  88 + if(${beanFieldName}PO == null || ${beanFieldName}PO.getId() == null){
  89 + result.setResultId(ResultInfoCode.RESULTID_FAILURE_210);
  90 + result.setResultMessage("更新失败,缺少主键信息");
  91 + return result;
  92 + }
  93 +
  94 + //调用Service方法
  95 + int updateResult = this.${beanFieldName}Dao.update${beanClassName}PO(${beanFieldName}PO);
  96 + if(updateResult < 1){
  97 + result.setResultId(ResultInfoCode.RESULTID_FAILURE_210);
  98 + result.setResultMessage("更新失败");
  99 + }else{
  100 + result.setResultId(ResultInfoCode.RESULTID_SUCCESS_200);
  101 + result.setResultMessage("更新成功");
  102 + }
  103 + return result;
  104 + }
  105 +
  106 + @Override
  107 + public Map<String, Object> query(List<Object[]> arrayCondition, String sort, String order, int page, int pageSize){
  108 + String sortCondition = UtilsSql.getSortCondition(sort, order, null);
  109 + return this.${beanFieldName}Dao.findPageByCondition(arrayCondition, sortCondition, page, pageSize, false);
  110 + }
  111 +}
... ...
src/com/taover/base/template/ServiceTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/ServiceTemplate.ftl
... ... @@ -0,0 +1,37 @@
  1 +package ${mainPackageInfo}.${moduleName}.service;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import com.taover.base.ResultInfo;
  7 +
  8 +import ${poPackageInfo}.${beanClassName}PO;
  9 +
  10 +public interface ${beanClassName}Service {
  11 + /**
  12 + * 业务层添加接口
  13 + */
  14 + public ResultInfo add(${beanClassName}PO ${beanFieldName}PO);
  15 +
  16 + /**
  17 + * 业务层删除接口
  18 + */
  19 + public ResultInfo delete(String ids);
  20 +
  21 + /**
  22 + * 业务层更新接口
  23 + */
  24 + public ResultInfo edit(${beanClassName}PO ${beanFieldName}PO);
  25 +
  26 + /**
  27 + * 依据arrayCondition查询条件查询单条记录,如果存在多条记录,则取第一条
  28 + * @param arrayCondition
  29 + * @param sort
  30 + * @param order
  31 + * @param page
  32 + * @param pageSize
  33 + * @return 返回实体引用,如果未找到返回null
  34 + */
  35 + public Map<String, Object> query(List<Object[]> arrayCondition, String sort, String order, int page, int pageSize);
  36 +
  37 +}
... ...
src/com/taover/base/template/Temp.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/Temp.ftl
... ... @@ -0,0 +1,8 @@
  1 +//${cnFunc}
  2 +//${enFunc}
  3 +<#list propertyList as property >
  4 +var ${property} = getNumberBoxValue('${property}', 0);
  5 +</#list>
  6 +
  7 +var ${enFunc};
  8 +$('#${result}').numberbox('setValue', ${result});
0 9 \ No newline at end of file
... ...
src/com/taover/base/template/createTableTemplate.ftl 0 → 100644
  1 +++ a/src/com/taover/base/template/createTableTemplate.ftl
... ... @@ -0,0 +1,31 @@
  1 +-- Create table
  2 +create table ${tableName}
  3 +(
  4 +<#list columnlist as clist>
  5 + ${clist.columnName} ${clist.columnSQLType}<#if clist.columnSize?exists>${clist.columnSize}</#if><#if clist.columnDefaults?exists && clist.columnDefaults != '' && clist.columnDefaults != 'null'> default ${clist.columnDefaults}</#if><#if !clist.nullable> not null</#if><#if clist_has_next>,</#if>
  6 +</#list>
  7 +);
  8 +<#if tableRemarks?exists>
  9 +-- Add comments to the table
  10 +comment on table ${tableName} is '${tableRemarks}';
  11 +</#if>
  12 +-- Add comments to the columns
  13 +<#list columnlist as clist>
  14 + <#if clist.columnRemarks?exists && clist.columnRemarks != clist.columnName>
  15 +comment on column ${tableName}.${clist.columnName} is '${clist.columnRemarks}';
  16 + </#if>
  17 +</#list>
  18 +<#if tablePk?exists>
  19 +-- Create index
  20 +CREATE UNIQUE INDEX PK_${tableName} ON ${tableName}(${tablePk});
  21 +ALTER TABLE ${tableName} ADD
  22 + PRIMARY KEY (${tablePk})
  23 + USING INDEX PK_${tableName};
  24 +</#if>
  25 +-- Create sequence
  26 +create sequence SEQ_${tableName}<#if tableName?length lt 24>_PK</#if>
  27 +minvalue 1
  28 +maxvalue 99999999999999999
  29 +start with 1
  30 +increment by 1
  31 +cache 20;
... ...
src/com/taover/base/template/model/.svn/entries 0 → 100644
  1 +++ a/src/com/taover/base/template/model/.svn/entries
... ... @@ -0,0 +1,37 @@
  1 +10
  2 +
  3 +dir
  4 +115305
  5 +svn://119.254.17.138/repos/%E6%B2%B1%E6%B2%B1%E7%94%9F%E6%B4%BB%E7%BD%91%E8%B6%85/code/soa.tootoo.cn/trunk/generate-tootoo-dao-po/src/cn/tootoo/base/template/model
  6 +svn://119.254.17.138/repos
  7 +
  8 +
  9 +
  10 +2014-10-16T09:45:05.710295Z
  11 +76282
  12 +zhuruisong
  13 +
  14 +
  15 +svn:special svn:externals svn:needs-lock
  16 +
  17 +
  18 +
  19 +
  20 +
  21 +
  22 +
  23 +
  24 +
  25 +
  26 +
  27 +5351f05e-98f4-42cc-8e6a-33022518c94f
  28 +
  29 +createTable
  30 +dir
  31 +
  32 +dao
  33 +dir
  34 +
  35 +po
  36 +dir
  37 +
... ...
src/com/taover/base/template/model/bussiness/ControllerModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/bussiness/ControllerModel.java
... ... @@ -0,0 +1,179 @@
  1 +package com.taover.base.template.model.bussiness;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +import java.util.Vector;
  8 +
  9 +import com.taover.business.Utils;
  10 +import com.taover.db.TableColumn;
  11 +import com.taover.tools.StringUtil;
  12 +
  13 +public class ControllerModel {
  14 + private String mainPackageInfo;
  15 + private String dbPackageInfo;
  16 + private String poClassName;
  17 + private String poFieldName;
  18 + private String serviceImplClassName;
  19 + private String serviceImplFieldName;
  20 + private String controllerClassName;
  21 + private String moduleName;
  22 + private String moduleNameFirstBig;
  23 + private String controllerUri;
  24 + private List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
  25 +
  26 + private ControllerModel(){}
  27 + public static ControllerModel createControllerModel(String packageInfo, String poPackageInfo, String serviceImplPackageInfo, String beanClassName, String mainPackageInfo, String moduleName, Vector<TableColumn> tableColumns){
  28 + ControllerModel model = new ControllerModel();
  29 + model.moduleName = moduleName;
  30 + model.mainPackageInfo = mainPackageInfo;
  31 + model.dbPackageInfo = poPackageInfo;
  32 + model.poClassName = beanClassName+"PO";
  33 + model.controllerUri = beanClassName.toLowerCase();
  34 + model.poFieldName = Utils.getFirstLetterLower(model.poClassName);
  35 + model.serviceImplClassName = beanClassName + "Service";
  36 + model.serviceImplFieldName = Utils.getFirstLetterLower(model.serviceImplClassName);
  37 + model.controllerClassName = beanClassName + "Controller";
  38 + model.moduleNameFirstBig = moduleName.toUpperCase().substring(0, 1)+moduleName.substring(1);
  39 +
  40 + for(TableColumn column : tableColumns){
  41 + String fieldName = column.getColumnName();
  42 + String varName = column.getColumBeanLName();
  43 + String fieldType = column.getJAVADataType();
  44 +
  45 + Map<String, String> columnMap = new HashMap<String, String>();
  46 + String conditionCode = "";
  47 + if("java.util.Date|java.sql.Time|java.sql.Timestamp".indexOf(fieldType) != -1){
  48 + conditionCode = ControllerModel.parseConditionDate(varName, fieldName);
  49 + }else if("Byte|Long|Integer|Short".indexOf(fieldType) != -1){
  50 + conditionCode = ControllerModel.parseConditionNumber(varName, fieldName);
  51 + }else{
  52 + conditionCode = ControllerModel.parseConditionString(varName, fieldName);
  53 + }
  54 + columnMap.put("conditionCode", conditionCode);
  55 + model.fields.add(columnMap);
  56 + }
  57 +
  58 + return model;
  59 + }
  60 +
  61 + /**
  62 + *
  63 + String toList = request.getParameter("to");
  64 + if(StringUtils.isNotEmpty(toList)){
  65 + arrayCondition.add(new Object[]{"to_list", "like", "%"+toList+"%"});
  66 + }
  67 + * @param name
  68 + * @return
  69 + */
  70 + public static String parseConditionString(String name, String fieldName){
  71 + String lowName = StringUtil.formatBeanNameFirstLow(name);
  72 + String sqlCondition = "String "+lowName+" = request.getParameter(\""+lowName+"\");\n"
  73 + +"\t\tif(StringUtils.isNotEmpty("+lowName+")){ \n"
  74 + +"\t\t\tarrayCondition.add(new Object[]{\""+fieldName+"\", \"like\", \"%\"+"+lowName+"+\"%\"}); \n"
  75 + +"\t\t}\n";
  76 + return sqlCondition;
  77 + }
  78 +
  79 + /**
  80 + *
  81 + String toList = request.getParameter("to");
  82 + if(StringUtils.isNotEmpty(toList) && StringUtils.isNumeric(toList)){
  83 + arrayCondition.add(new Object[]{"to_list", "like", "%"+toList+"%"});
  84 + }
  85 + * @param name
  86 + * @return
  87 + */
  88 + public static String parseConditionNumber(String name, String fieldName){
  89 + String lowName = StringUtil.formatBeanNameFirstLow(name);
  90 + String sqlCondition = "String "+lowName+" = request.getParameter(\""+lowName+"\");\n"
  91 + +"\t\tif(StringUtils.isNotEmpty("+lowName+") && StringUtils.isNumeric("+lowName+") ){ \n"
  92 + +"\t\t\tarrayCondition.add(new Object[]{\""+fieldName+"\", \"=\", "+lowName+"}); \n"
  93 + +"\t\t}\n";
  94 + return sqlCondition;
  95 + }
  96 +
  97 + /**
  98 + *
  99 + String date = request.getParameter("date");
  100 + if(StringUtils.isNotEmpty(date)){
  101 + String[] dateGap = date.split("+-+");
  102 + if(dateGap.length == 1){
  103 + arrayCondition.add(new Object[]{" datediff(`date`, '"+dateGap[0]+"')>=0 ", null});
  104 + }else if(dateGap.length == 2){
  105 + arrayCondition.add(new Object[]{"( datediff(`date`, '"+dateGap[0]+"')>=0 and datediff(`date`, '"+dateGap[1]+"')<=0 )", null});
  106 + }
  107 + }
  108 + * @param name
  109 + * @return
  110 + */
  111 + public static String parseConditionDate(String name, String fieldName){
  112 + String lowName = StringUtil.formatBeanNameFirstLow(name);
  113 + String sqlCondition = "String "+lowName+" = request.getParameter(\""+lowName+"\");\n"
  114 + + "\t\tif(StringUtils.isNotEmpty("+lowName+")){\n"
  115 + + "\t\t\tString[] dateGap = "+lowName+".split(\"+-+\");\n"
  116 + + "\t\t\tif(dateGap.length == 1){\n"
  117 + +"\t\t\t\tarrayCondition.add(new Object[]{\" datediff(`"+fieldName+"`, '\"+dateGap[0]+\"')>=0 \", null});\n"
  118 + + "\t\t\t}else if(dateGap.length == 2){ \n"
  119 + +"\t\t\t\tarrayCondition.add(new Object[]{\"( datediff(`"+fieldName+"`, '\"+dateGap[0]+\"')>=0 and datediff(`"+fieldName+"`, '\"+dateGap[1]+\"')<=0 )\", null});\n"
  120 + +"\t\t\t}\n"
  121 + +"\t\t}\n";
  122 + return sqlCondition;
  123 + }
  124 +
  125 + public String getControllerUri() {
  126 + return controllerUri;
  127 + }
  128 + public String getMainPackageInfo() {
  129 + return mainPackageInfo;
  130 + }
  131 + public void setMainPackageInfo(String packageInfo) {
  132 + this.mainPackageInfo = packageInfo;
  133 + }
  134 + public String getPoPackageInfo() {
  135 + return dbPackageInfo;
  136 + }
  137 + public void setPoPackageInfo(String poPackageInfo) {
  138 + this.dbPackageInfo = poPackageInfo;
  139 + }
  140 + public String getPoClassName() {
  141 + return poClassName;
  142 + }
  143 + public void setPoClassName(String poClassName) {
  144 + this.poClassName = poClassName;
  145 + }
  146 + public String getPoFieldName() {
  147 + return poFieldName;
  148 + }
  149 + public void setPoFieldName(String poFieldName) {
  150 + this.poFieldName = poFieldName;
  151 + }
  152 + public String getServiceImplClassName() {
  153 + return serviceImplClassName;
  154 + }
  155 + public void setServiceImplClassName(String serviceImplClassName) {
  156 + this.serviceImplClassName = serviceImplClassName;
  157 + }
  158 + public String getServiceImplFieldName() {
  159 + return serviceImplFieldName;
  160 + }
  161 + public void setServiceImplFieldName(String serviceImplFieldName) {
  162 + this.serviceImplFieldName = serviceImplFieldName;
  163 + }
  164 + public String getControllerClassName() {
  165 + return controllerClassName;
  166 + }
  167 + public String getModuleName() {
  168 + return moduleName;
  169 + }
  170 + public String getModuleNameFirstBig() {
  171 + return moduleNameFirstBig;
  172 + }
  173 + public void setControllerClassName(String controllerClassName) {
  174 + this.controllerClassName = controllerClassName;
  175 + }
  176 + public List<Map<String, String>> getFields() {
  177 + return fields;
  178 + }
  179 +}
... ...
src/com/taover/base/template/model/bussiness/EnvironmentModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/bussiness/EnvironmentModel.java
... ... @@ -0,0 +1,75 @@
  1 +package com.taover.base.template.model.bussiness;
  2 +
  3 +import java.io.File;
  4 +
  5 +public class EnvironmentModel {
  6 + private String controllerPackageInfo;
  7 + private String poPackageInfo;
  8 + private String servicePackageInfo;
  9 + private String controllerFilePath;
  10 + private String serviceFilePath;
  11 + private String beanClassName;
  12 + private String mainPackageInfo;
  13 + private String subModuleName;
  14 +
  15 + private EnvironmentModel(){}
  16 + public static EnvironmentModel createEnvironmentModel(String modulePackageInfo, String moduleFilePath, String poPackageInfo, String beanClassName, String subModuluName){
  17 + EnvironmentModel envir = new EnvironmentModel();
  18 + envir.controllerPackageInfo = modulePackageInfo + "." + subModuluName + "." +"controller";
  19 + envir.poPackageInfo = poPackageInfo;
  20 + envir.servicePackageInfo = modulePackageInfo + "." + subModuluName + "." +"service";
  21 + envir.controllerFilePath = moduleFilePath + File.separator + subModuluName + File.separator +"controller";
  22 + envir.serviceFilePath = moduleFilePath + File.separator + subModuluName + File.separator+"service";
  23 + envir.beanClassName = beanClassName;
  24 + envir.mainPackageInfo = modulePackageInfo;
  25 + envir.subModuleName = subModuluName;
  26 + return envir;
  27 + }
  28 +
  29 + public String getControllerPackageInfo() {
  30 + return controllerPackageInfo;
  31 + }
  32 + public void setControllerPackageInfo(String controllerPackageInfo) {
  33 + this.controllerPackageInfo = controllerPackageInfo;
  34 + }
  35 + public String getPoPackageInfo() {
  36 + return poPackageInfo;
  37 + }
  38 + public void setPoPackageInfo(String poPackageInfo) {
  39 + this.poPackageInfo = poPackageInfo;
  40 + }
  41 + public String getServicePackageInfo() {
  42 + return servicePackageInfo;
  43 + }
  44 + public void setServicePackageInfo(String servicePackageInfo) {
  45 + this.servicePackageInfo = servicePackageInfo;
  46 + }
  47 + public String getControllerFilePath() {
  48 + return controllerFilePath;
  49 + }
  50 + public void setControllerFilePath(String controllerFilePath) {
  51 + this.controllerFilePath = controllerFilePath;
  52 + }
  53 + public String getServiceFilePath() {
  54 + return serviceFilePath;
  55 + }
  56 + public void setServiceFilePath(String serviceFilePath) {
  57 + this.serviceFilePath = serviceFilePath;
  58 + }
  59 + public String getBeanClassName() {
  60 + return beanClassName;
  61 + }
  62 + public void setBeanClassName(String beanClassName) {
  63 + this.beanClassName = beanClassName;
  64 + }
  65 + public String getMainPackageInfo() {
  66 + return mainPackageInfo;
  67 + }
  68 + public String getSubModuleName() {
  69 + return subModuleName;
  70 + }
  71 + public void setUtilPackageInfo(String utilPackageInfo) {
  72 + this.mainPackageInfo = utilPackageInfo;
  73 + }
  74 +
  75 +}
... ...
src/com/taover/base/template/model/bussiness/ServiceModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/bussiness/ServiceModel.java
... ... @@ -0,0 +1,53 @@
  1 +package com.taover.base.template.model.bussiness;
  2 +
  3 +import com.taover.business.Utils;
  4 +
  5 +public class ServiceModel {
  6 + private String poPackageInfo;
  7 + private String beanClassName;
  8 + private String beanFieldName;
  9 + private String mainPackageInfo;
  10 + private String moduleName;
  11 + private String moduleNameFirstBig;
  12 +
  13 + private ServiceModel(){}
  14 + public static ServiceModel createServiceModel(String poPackageInfo, String beanClassName, String mainPackageInfo, String moduleName){
  15 + ServiceModel model = new ServiceModel();
  16 + model.poPackageInfo = poPackageInfo;
  17 + model.beanClassName = beanClassName;
  18 + model.beanFieldName = Utils.getFirstLetterLower(beanClassName);
  19 + model.mainPackageInfo = mainPackageInfo;
  20 + model.moduleName = moduleName;
  21 + model.moduleNameFirstBig = moduleName.toUpperCase().substring(0, 1)+moduleName.substring(1);
  22 + return model;
  23 + }
  24 + public String getMainPackageInfo() {
  25 + return mainPackageInfo;
  26 + }
  27 + public String getPoPackageInfo() {
  28 + return poPackageInfo;
  29 + }
  30 + public void setPoPackageInfo(String poPackageInfo) {
  31 + this.poPackageInfo = poPackageInfo;
  32 + }
  33 + public String getBeanClassName() {
  34 + return beanClassName;
  35 + }
  36 + public void setBeanClassName(String beanClassName) {
  37 + this.beanClassName = beanClassName;
  38 + }
  39 + public String getBeanFieldName() {
  40 + return beanFieldName;
  41 + }
  42 + public String getModuleName() {
  43 + return moduleName;
  44 + }
  45 + public String getModuleNameFirstBig() {
  46 + return moduleNameFirstBig;
  47 + }
  48 + public void setBeanFieldName(String beanFieldName) {
  49 + this.beanFieldName = beanFieldName;
  50 + }
  51 +
  52 +
  53 +}
... ...
src/com/taover/base/template/model/bussiness/ViewModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/bussiness/ViewModel.java
... ... @@ -0,0 +1,331 @@
  1 +package com.taover.base.template.model.bussiness;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +import java.util.Vector;
  8 +
  9 +import com.taover.db.TableColumn;
  10 +
  11 +public class ViewModel {
  12 + private String webRootPath;
  13 + private String controllerPathMap;
  14 + //map结构如下
  15 + //name:"",easyui:"numberbox|validatebox|datetimebox",required:true|false,precision:0,min:0,max:32767,validType
  16 + private List<Map<String, String>> fields = new ArrayList<Map<String, String>>();
  17 +
  18 + private ViewModel(){}
  19 + public static ViewModel createViewModel(String controllerPathMap, String webRootPath,Vector<TableColumn> tableColumns){
  20 + ViewModel model = new ViewModel();
  21 + model.controllerPathMap = controllerPathMap;
  22 + model.webRootPath = webRootPath;
  23 + for(TableColumn column : tableColumns){
  24 + String fieldName = column.getColumBeanLName();
  25 + String fieldType = column.getJAVADataType();
  26 +
  27 + Map<String, String> columnMap = new HashMap<String, String>();
  28 + columnMap.put("name", fieldName);
  29 + if("Byte|Long|Integer|Short".indexOf(fieldType) != -1){
  30 + columnMap.put("easyui", "numberbox");
  31 + columnMap.put("attr", " precision=\"0\" ");
  32 + }else if("Float|Double".indexOf(fieldType) != -1){
  33 + columnMap.put("easyui", "numberbox");
  34 + columnMap.put("attr", " precision=\"2\" ");
  35 + }else if("java.util.Date|java.sql.Time|java.sql.Timestamp".indexOf(fieldType) != -1){
  36 + columnMap.put("easyui", "datetimebox");
  37 + columnMap.put("attr", "");
  38 + }else{
  39 + columnMap.put("easyui", "validatebox");
  40 + columnMap.put("attr", " validType=\"length[0,"+column.getColumnSize()+"]\"");
  41 + }
  42 + if(!column.isNullable()){
  43 + columnMap.put("required", " required=\"true\" ");
  44 + }
  45 + String remarks = column.getRemarks();
  46 + String splitStr = ":";
  47 + if(remarks.contains(":")){
  48 + splitStr = ":";
  49 + }
  50 + String remarkPart[] = remarks.split(splitStr);
  51 + String cnName = fieldName;
  52 + if(remarkPart.length > 0){
  53 + cnName = remarkPart[0];
  54 + }
  55 + columnMap.put("cnName", cnName);
  56 +
  57 + String easyuiSearchDom = "";
  58 + String layuiSearchDom = "";
  59 + String layuiFormDom = "";
  60 + if(remarkPart.length > 1){
  61 + easyuiSearchDom = ViewModel.parseEasyuiSearchSelect(fieldName, cnName, remarkPart[1]);
  62 + layuiSearchDom = ViewModel.parseLayuiSearchSelect(fieldName, cnName, remarkPart[1]);
  63 + layuiFormDom = ViewModel.parseLayuiFormSelect(fieldName, cnName, remarkPart[1]);
  64 + }else if("java.util.Date|java.sql.Time|java.sql.Timestamp".indexOf(fieldType) != -1){
  65 + easyuiSearchDom = ViewModel.parseEasyuiSearchDatetime(fieldName, cnName);
  66 + layuiSearchDom = ViewModel.parseLayuiSearchDatetime(fieldName, cnName);
  67 + layuiFormDom = ViewModel.parseLayuiFormDatetime(fieldName, cnName);
  68 + }else if("Byte|Long|Integer|Short".indexOf(fieldType) != -1){
  69 + easyuiSearchDom = ViewModel.parseEasyuiSearchNumber(fieldName, cnName);
  70 + layuiSearchDom = ViewModel.parseLayuiSearchNumber(fieldName, cnName);
  71 + layuiFormDom = ViewModel.parseLayuiFormNumber(fieldName, cnName);
  72 + }else{
  73 + easyuiSearchDom = ViewModel.parseEasyuiSearchText(fieldName, cnName);
  74 + layuiSearchDom = ViewModel.parseLayuiSearchText(fieldName, cnName);
  75 + layuiFormDom = ViewModel.parseLayuiFormText(fieldName, cnName);
  76 + }
  77 + //构造easyui筛选栏元素
  78 + columnMap.put("easyui-search-item", easyuiSearchDom);
  79 +
  80 + //构造layui筛选栏元素
  81 + columnMap.put("layui-search-item", layuiSearchDom);
  82 +
  83 + //构造layui表单栏元素
  84 + columnMap.put("layui-form-item", layuiFormDom);
  85 +
  86 + //构造layui表格表头
  87 + columnMap.put("layui-table-item", ViewModel.parseLayuiTableHeader(fieldName, cnName));
  88 +
  89 + model.fields.add(columnMap);
  90 + }
  91 + return model;
  92 + }
  93 +
  94 + public static String parseEasyuiSearchSelect(String name, String cnName, String optionStr){
  95 + String easyuiSearchEle = "<div class=\"toolbar-form-item\">"
  96 + + "<span>"+cnName+"</span>"
  97 + + "<select name=\""+name+"\" class=\"easyui-combobox search_input\">"
  98 + + " <option value=\"\">全部</option> ";
  99 + String[] options = optionStr.split(",");
  100 + List<String> optionsList = new ArrayList<String>();
  101 + for(int i=0; i<options.length; ++i){
  102 + String tempOption = options[i];
  103 + if(tempOption.contains(",")){
  104 + String[] optionsExt = tempOption.split(",");
  105 + if(optionsExt.length > 0){
  106 + for(int j=0; j<optionsExt.length; ++j){
  107 + optionsList.add(optionsExt[j]);
  108 + }
  109 + }
  110 + }else{
  111 + optionsList.add(options[i]);
  112 + }
  113 + }
  114 + for(int i=0; i<optionsList.size(); ++i){
  115 + String optionsItem = optionsList.get(i);
  116 + String[] optionsArr = optionsItem.split("-");
  117 + String optionName = "未知名称";
  118 + if(optionsArr.length > 0){
  119 + optionName = optionsArr[1];
  120 + }
  121 + easyuiSearchEle += " <option value=\""+optionsArr[0]+"\">"+optionName+"</option> ";
  122 + }
  123 +
  124 + easyuiSearchEle += "</select></div>";
  125 + return easyuiSearchEle;
  126 + }
  127 +
  128 + public static String parseEasyuiSearchDatetime(String name, String cnName){
  129 + String dateBoxDom = "<div class=\"toolbar-form-item\">"
  130 + + "<span>"+cnName+"</span>"
  131 + + "<input name=\""+name+"\" type=\"date\" class=\"easyui-datebox\" >"
  132 + + "</div>";
  133 + return dateBoxDom;
  134 + }
  135 +
  136 + public static String parseEasyuiSearchNumber(String name, String cnName){
  137 + String dateBoxDom = "<div class=\"toolbar-form-item\">"
  138 + + "<span>"+cnName+"</span>"
  139 + + "<input name=\""+name+"\" type=\"number\" class=\"easyui-numberbox\" >"
  140 + + "</div>";
  141 + return dateBoxDom;
  142 + }
  143 +
  144 + public static String parseEasyuiSearchText(String name, String cnName){
  145 + String dateBoxDom = "<div class=\"toolbar-form-item\">"
  146 + + "<span>"+cnName+"</span>"
  147 + + "<input name=\""+name+"\" type=\"text\" class=\"easyui-textbox\" >"
  148 + + "</div>";
  149 + return dateBoxDom;
  150 + }
  151 +
  152 + /**
  153 + * <div class="layui-inline">
  154 + <label class="layui-form-label">性别</label>
  155 + <div class="layui-input-block">
  156 + <select name="sex">
  157 + <option value="0">不限</option>
  158 + <option value="1" selected>男</option>
  159 + <option value="2">女</option>
  160 + </select>
  161 + </div>
  162 + </div>
  163 + * @param name
  164 + * @param cnName
  165 + * @param optionStr
  166 + * @return
  167 + */
  168 + public static String parseLayuiSearchSelect(String name, String cnName, String optionStr){
  169 + String LayuiSearchEle = "<div class=\"layui-inline\">"
  170 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  171 + + "<div class=\"layui-input-block\">"
  172 + + "<select name=\""+name+"\" class=\"layui-input\">"
  173 + + " <option value=\"\">全部</option>";
  174 + String[] options = optionStr.split(",");
  175 + List<String> optionsList = new ArrayList<String>();
  176 + for(int i=0; i<options.length; ++i){
  177 + String tempOption = options[i];
  178 + if(tempOption.contains(",")){
  179 + String[] optionsExt = tempOption.split(",");
  180 + if(optionsExt.length > 0){
  181 + for(int j=0; j<optionsExt.length; ++j){
  182 + optionsList.add(optionsExt[j]);
  183 + }
  184 + }
  185 + }else{
  186 + optionsList.add(options[i]);
  187 + }
  188 + }
  189 + for(int i=0; i<optionsList.size(); ++i){
  190 + String optionsItem = optionsList.get(i);
  191 + String[] optionsArr = optionsItem.split("-");
  192 + String optionName = "未知名称";
  193 + if(optionsArr.length > 0){
  194 + optionName = optionsArr[1];
  195 + }
  196 + LayuiSearchEle += " <option value=\""+optionsArr[0]+"\">"+optionName+"</option> ";
  197 + }
  198 +
  199 + LayuiSearchEle += "</select></div></div>";
  200 + return LayuiSearchEle;
  201 + }
  202 +
  203 + /**
  204 + * <div class="layui-inline">
  205 + <label class="layui-form-label">日期范围</label>
  206 + <div class="layui-input-block">
  207 + <input type="text" name="date" placeholder="请输入" class="layui-input me-date-range" >
  208 + </div>
  209 + </div>
  210 + * @param name
  211 + * @param cnName
  212 + * @return
  213 + */
  214 + public static String parseLayuiSearchDatetime(String name, String cnName){
  215 + String dateBoxDom = "<div class=\"layui-inline\">"
  216 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  217 + + "<div class=\"layui-input-block\">"
  218 + +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input me-date-range\" >"
  219 + + "</div></div>";
  220 + return dateBoxDom;
  221 + }
  222 +
  223 + public static String parseLayuiSearchNumber(String name, String cnName){
  224 + String dateBoxDom = "<div class=\"layui-inline\">"
  225 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  226 + + "<div class=\"layui-input-block\">"
  227 + +"<input type=\"number\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input\" >"
  228 + + "</div></div>";
  229 + return dateBoxDom;
  230 + }
  231 +
  232 + public static String parseLayuiSearchText(String name, String cnName){
  233 + String dateBoxDom = "<div class=\"layui-inline\">"
  234 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  235 + + "<div class=\"layui-input-block\">"
  236 + +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input\" >"
  237 + + "</div></div>";
  238 + return dateBoxDom;
  239 + }
  240 +
  241 + public static String parseLayuiFormSelect(String name, String cnName, String optionStr){
  242 + String LayuiFormEle = "<div class=\"layui-form-item\">"
  243 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  244 + + "<div class=\"layui-input-block\">"
  245 + + "<select name=\""+name+"\">"
  246 + + " <option value=\"\">全部</option>";
  247 + String[] options = optionStr.split(",");
  248 + List<String> optionsList = new ArrayList<String>();
  249 + for(int i=0; i<options.length; ++i){
  250 + String tempOption = options[i];
  251 + if(tempOption.contains(",")){
  252 + String[] optionsExt = tempOption.split(",");
  253 + if(optionsExt.length > 0){
  254 + for(int j=0; j<optionsExt.length; ++j){
  255 + optionsList.add(optionsExt[j]);
  256 + }
  257 + }
  258 + }else{
  259 + optionsList.add(options[i]);
  260 + }
  261 + }
  262 + for(int i=0; i<optionsList.size(); ++i){
  263 + String optionsItem = optionsList.get(i);
  264 + String[] optionsArr = optionsItem.split("-");
  265 + String optionName = "未知名称";
  266 + if(optionsArr.length > 0){
  267 + optionName = optionsArr[1];
  268 + }
  269 + LayuiFormEle += " <option value=\""+optionsArr[0]+"\">"+optionName+"</option> ";
  270 + }
  271 +
  272 + LayuiFormEle += "</select></div></div>";
  273 + return LayuiFormEle;
  274 + }
  275 +
  276 + /**
  277 + * <div class="layui-inline">
  278 + <label class="layui-form-label">日期范围</label>
  279 + <div class="layui-input-block">
  280 + <input type="text" name="date" placeholder="请输入" class="layui-input me-date-range" >
  281 + </div>
  282 + </div>
  283 + * @param name
  284 + * @param cnName
  285 + * @return
  286 + */
  287 + public static String parseLayuiFormDatetime(String name, String cnName){
  288 + String dateBoxDom = "<div class=\"layui-form-item\">"
  289 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  290 + + "<div class=\"layui-input-block\">"
  291 + +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input me-date-form\" >"
  292 + + "</div></div>";
  293 + return dateBoxDom;
  294 + }
  295 +
  296 + public static String parseLayuiFormNumber(String name, String cnName){
  297 + String dateBoxDom = "<div class=\"layui-form-item\">"
  298 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  299 + + "<div class=\"layui-input-block\">"
  300 + +"<input type=\"number\" name=\""+name+"\" class=\"layui-input\" >"
  301 + + "</div></div>";
  302 + return dateBoxDom;
  303 + }
  304 +
  305 + public static String parseLayuiFormText(String name, String cnName){
  306 + String dateBoxDom = "<div class=\"layui-form-item\">"
  307 + + "<label class=\"layui-form-label\">"+cnName+"</label>"
  308 + + "<div class=\"layui-input-block\">"
  309 + +"<input type=\"text\" name=\""+name+"\" placeholder=\"请输入\" class=\"layui-input\" >"
  310 + + "</div></div>";
  311 + return dateBoxDom;
  312 + }
  313 +
  314 + public static String parseLayuiTableHeader(String name, String cnName){
  315 + String header = "{title:'"+cnName+"', field:'"+name+"', width:100, sort: true},";
  316 + return header;
  317 + }
  318 +
  319 + public String getControllerPathMap() {
  320 + return controllerPathMap;
  321 + }
  322 + public void setControllerPathMap(String controllerPathMap) {
  323 + this.controllerPathMap = controllerPathMap;
  324 + }
  325 + public List<Map<String, String>> getFields() {
  326 + return fields;
  327 + }
  328 + public void setColumns(List<Map<String, String>> fields) {
  329 + this.fields = fields;
  330 + }
  331 +}
... ...
src/com/taover/base/template/model/createTable/.svn/entries 0 → 100644
  1 +++ a/src/com/taover/base/template/model/createTable/.svn/entries
... ... @@ -0,0 +1,96 @@
  1 +10
  2 +
  3 +dir
  4 +115305
  5 +svn://119.254.17.138/repos/%E6%B2%B1%E6%B2%B1%E7%94%9F%E6%B4%BB%E7%BD%91%E8%B6%85/code/soa.tootoo.cn/trunk/generate-tootoo-dao-po/src/cn/tootoo/base/template/model/createTable
  6 +svn://119.254.17.138/repos
  7 +
  8 +
  9 +
  10 +2014-10-16T09:45:05.710295Z
  11 +76282
  12 +zhuruisong
  13 +
  14 +
  15 +svn:special svn:externals svn:needs-lock
  16 +
  17 +
  18 +
  19 +
  20 +
  21 +
  22 +
  23 +
  24 +
  25 +
  26 +
  27 +5351f05e-98f4-42cc-8e6a-33022518c94f
  28 +
  29 +ColumnModel.java
  30 +file
  31 +
  32 +
  33 +
  34 +
  35 +2015-08-10T05:52:55.776000Z
  36 +fe9f5f043f0f6fa96314ebb9e9d1814a
  37 +2014-10-14T09:23:57.914676Z
  38 +75944
  39 +zhuruisong
  40 +
  41 +
  42 +
  43 +
  44 +
  45 +
  46 +
  47 +
  48 +
  49 +
  50 +
  51 +
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +1421
  62 +
  63 +TableModel.java
  64 +file
  65 +
  66 +
  67 +
  68 +
  69 +2015-08-10T05:52:55.753000Z
  70 +33b80ac378dbdff8b5833ca2b131b529
  71 +2014-10-16T09:45:05.710295Z
  72 +76282
  73 +zhuruisong
  74 +
  75 +
  76 +
  77 +
  78 +
  79 +
  80 +
  81 +
  82 +
  83 +
  84 +
  85 +
  86 +
  87 +
  88 +
  89 +
  90 +
  91 +
  92 +
  93 +
  94 +
  95 +913
  96 +
... ...
src/com/taover/base/template/model/createTable/.svn/text-base/ColumnModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/createTable/.svn/text-base/ColumnModel.java.svn-base
... ... @@ -0,0 +1,64 @@
  1 +package cn.tootoo.base.template.model.createTable;
  2 +
  3 +public class ColumnModel {
  4 + private String columnName;
  5 + private boolean nullable;
  6 + private String columnSQLType;
  7 + private String columnRemarks;
  8 + private String columnSize;
  9 + private String columnDefaults;
  10 +
  11 + public String getColumnName() {
  12 + return columnName;
  13 + }
  14 +
  15 + public void setColumnName(String columnName) {
  16 + this.columnName = columnName;
  17 + }
  18 +
  19 + public boolean isNullable() {
  20 + return nullable;
  21 + }
  22 +
  23 + public void setNullable(boolean nullable) {
  24 + this.nullable = nullable;
  25 + }
  26 +
  27 + public String getColumnSQLType() {
  28 + return columnSQLType;
  29 + }
  30 +
  31 + public void setColumnSQLType(String columnSQLType) {
  32 + this.columnSQLType = columnSQLType;
  33 + }
  34 +
  35 + public String getColumnRemarks() {
  36 + return columnRemarks;
  37 + }
  38 +
  39 + public void setColumnRemarks(String columnRemarks) {
  40 + this.columnRemarks = columnRemarks;
  41 + }
  42 +
  43 +
  44 + public String getColumnSize() {
  45 + return columnSize;
  46 + }
  47 +
  48 +
  49 + public void setColumnSize(String columnSize) {
  50 + this.columnSize = columnSize;
  51 + }
  52 +
  53 +
  54 + public String getColumnDefaults() {
  55 + return columnDefaults;
  56 + }
  57 +
  58 +
  59 + public void setColumnDefaults(String columnDefaults) {
  60 + this.columnDefaults = columnDefaults;
  61 + }
  62 +
  63 +
  64 +}
... ...
src/com/taover/base/template/model/createTable/.svn/text-base/TableModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/createTable/.svn/text-base/TableModel.java.svn-base
... ... @@ -0,0 +1,44 @@
  1 +package cn.tootoo.base.template.model.createTable;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class TableModel {
  6 + private String tableName;
  7 + private String tablePk;
  8 + private String tableRemarks;
  9 + private List<ColumnModel> columnlist;
  10 +
  11 + public String getTablePk() {
  12 + return tablePk;
  13 + }
  14 +
  15 +
  16 + public void setTablePk(String tablePk) {
  17 + this.tablePk = tablePk;
  18 + }
  19 +
  20 + public String getTableName() {
  21 + return tableName;
  22 + }
  23 +
  24 + public void setTableName(String tableName) {
  25 + this.tableName = tableName;
  26 + }
  27 +
  28 + public List<ColumnModel> getColumnlist() {
  29 + return columnlist;
  30 + }
  31 +
  32 + public void setColumnlist(List<ColumnModel> columnlist) {
  33 + this.columnlist = columnlist;
  34 + }
  35 +
  36 + public String getTableRemarks() {
  37 + return tableRemarks;
  38 + }
  39 +
  40 + public void setTableRemarks(String tableRemarks) {
  41 + this.tableRemarks = tableRemarks;
  42 + }
  43 +
  44 +}
... ...
src/com/taover/base/template/model/createTable/ColumnModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/createTable/ColumnModel.java
... ... @@ -0,0 +1,64 @@
  1 +package com.taover.base.template.model.createTable;
  2 +
  3 +public class ColumnModel {
  4 + private String columnName;
  5 + private boolean nullable;
  6 + private String columnSQLType;
  7 + private String columnRemarks;
  8 + private String columnSize;
  9 + private String columnDefaults;
  10 +
  11 + public String getColumnName() {
  12 + return columnName;
  13 + }
  14 +
  15 + public void setColumnName(String columnName) {
  16 + this.columnName = columnName;
  17 + }
  18 +
  19 + public boolean isNullable() {
  20 + return nullable;
  21 + }
  22 +
  23 + public void setNullable(boolean nullable) {
  24 + this.nullable = nullable;
  25 + }
  26 +
  27 + public String getColumnSQLType() {
  28 + return columnSQLType;
  29 + }
  30 +
  31 + public void setColumnSQLType(String columnSQLType) {
  32 + this.columnSQLType = columnSQLType;
  33 + }
  34 +
  35 + public String getColumnRemarks() {
  36 + return columnRemarks;
  37 + }
  38 +
  39 + public void setColumnRemarks(String columnRemarks) {
  40 + this.columnRemarks = columnRemarks;
  41 + }
  42 +
  43 +
  44 + public String getColumnSize() {
  45 + return columnSize;
  46 + }
  47 +
  48 +
  49 + public void setColumnSize(String columnSize) {
  50 + this.columnSize = columnSize;
  51 + }
  52 +
  53 +
  54 + public String getColumnDefaults() {
  55 + return columnDefaults;
  56 + }
  57 +
  58 +
  59 + public void setColumnDefaults(String columnDefaults) {
  60 + this.columnDefaults = columnDefaults;
  61 + }
  62 +
  63 +
  64 +}
... ...
src/com/taover/base/template/model/createTable/TableModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/createTable/TableModel.java
... ... @@ -0,0 +1,44 @@
  1 +package com.taover.base.template.model.createTable;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class TableModel {
  6 + private String tableName;
  7 + private String tablePk;
  8 + private String tableRemarks;
  9 + private List<ColumnModel> columnlist;
  10 +
  11 + public String getTablePk() {
  12 + return tablePk;
  13 + }
  14 +
  15 +
  16 + public void setTablePk(String tablePk) {
  17 + this.tablePk = tablePk;
  18 + }
  19 +
  20 + public String getTableName() {
  21 + return tableName;
  22 + }
  23 +
  24 + public void setTableName(String tableName) {
  25 + this.tableName = tableName;
  26 + }
  27 +
  28 + public List<ColumnModel> getColumnlist() {
  29 + return columnlist;
  30 + }
  31 +
  32 + public void setColumnlist(List<ColumnModel> columnlist) {
  33 + this.columnlist = columnlist;
  34 + }
  35 +
  36 + public String getTableRemarks() {
  37 + return tableRemarks;
  38 + }
  39 +
  40 + public void setTableRemarks(String tableRemarks) {
  41 + this.tableRemarks = tableRemarks;
  42 + }
  43 +
  44 +}
... ...
src/com/taover/base/template/model/dao/.svn/entries 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/.svn/entries
... ... @@ -0,0 +1,130 @@
  1 +10
  2 +
  3 +dir
  4 +115305
  5 +svn://119.254.17.138/repos/%E6%B2%B1%E6%B2%B1%E7%94%9F%E6%B4%BB%E7%BD%91%E8%B6%85/code/soa.tootoo.cn/trunk/generate-tootoo-dao-po/src/cn/tootoo/base/template/model/dao
  6 +svn://119.254.17.138/repos
  7 +
  8 +
  9 +
  10 +2014-06-03T00:22:16.481511Z
  11 +63469
  12 +wangpeng
  13 +
  14 +
  15 +svn:special svn:externals svn:needs-lock
  16 +
  17 +
  18 +
  19 +
  20 +
  21 +
  22 +
  23 +
  24 +
  25 +
  26 +
  27 +5351f05e-98f4-42cc-8e6a-33022518c94f
  28 +
  29 +BaseModel.java
  30 +file
  31 +
  32 +
  33 +
  34 +
  35 +2015-08-10T05:52:55.691000Z
  36 +552925e9c99237e6be4d450a84414d90
  37 +2014-05-23T03:31:02.661296Z
  38 +62995
  39 +wangpeng
  40 +
  41 +
  42 +
  43 +
  44 +
  45 +
  46 +
  47 +
  48 +
  49 +
  50 +
  51 +
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +1065
  62 +
  63 +DaoModel.java
  64 +file
  65 +
  66 +
  67 +
  68 +
  69 +2015-08-10T05:52:55.645000Z
  70 +d34ac2635066f47214bb37fd65b6ec3c
  71 +2014-06-03T00:22:16.481511Z
  72 +63469
  73 +wangpeng
  74 +
  75 +
  76 +
  77 +
  78 +
  79 +
  80 +
  81 +
  82 +
  83 +
  84 +
  85 +
  86 +
  87 +
  88 +
  89 +
  90 +
  91 +
  92 +
  93 +
  94 +
  95 +3009
  96 +
  97 +FunctionModel.java
  98 +file
  99 +
  100 +
  101 +
  102 +
  103 +2015-08-10T05:52:55.667000Z
  104 +5acc3b6225a53209ab1fef0825622349
  105 +2014-05-21T02:30:56.456467Z
  106 +62786
  107 +wangpeng
  108 +
  109 +
  110 +
  111 +
  112 +
  113 +
  114 +
  115 +
  116 +
  117 +
  118 +
  119 +
  120 +
  121 +
  122 +
  123 +
  124 +
  125 +
  126 +
  127 +
  128 +
  129 +2233
  130 +
... ...
src/com/taover/base/template/model/dao/.svn/text-base/BaseModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/.svn/text-base/BaseModel.java.svn-base
... ... @@ -0,0 +1,40 @@
  1 +package cn.tootoo.base.template.model.dao;
  2 +
  3 +public class BaseModel {
  4 + private String beanVarName;
  5 + private String function_return;
  6 + private String function_name;
  7 + private String function_param;
  8 + private String function_body;
  9 +
  10 + public String getBeanVarName() {
  11 + return beanVarName;
  12 + }
  13 + public void setBeanVarName(String beanVarName) {
  14 + this.beanVarName = beanVarName;
  15 + }
  16 + public String getFunction_return() {
  17 + return function_return;
  18 + }
  19 + public void setFunction_return(String function_return) {
  20 + this.function_return = function_return;
  21 + }
  22 + public String getFunction_name() {
  23 + return function_name;
  24 + }
  25 + public void setFunction_name(String function_name) {
  26 + this.function_name = function_name;
  27 + }
  28 + public String getFunction_param() {
  29 + return function_param;
  30 + }
  31 + public void setFunction_param(String function_param) {
  32 + this.function_param = function_param;
  33 + }
  34 + public String getFunction_body() {
  35 + return function_body;
  36 + }
  37 + public void setFunction_body(String function_body) {
  38 + this.function_body = function_body;
  39 + }
  40 +}
... ...
src/com/taover/base/template/model/dao/.svn/text-base/DaoModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/.svn/text-base/DaoModel.java.svn-base
... ... @@ -0,0 +1,116 @@
  1 +package cn.tootoo.base.template.model.dao;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import cn.tootoo.base.template.model.po.ColumnModel;
  7 +
  8 +public class DaoModel {
  9 +
  10 + private String users;
  11 + private String version;
  12 + private String packages;
  13 + private String beanName;
  14 + private String tableName;
  15 + private List<String> imports;
  16 + private List<String> propertys;
  17 + private List<FunctionModel> funlist;
  18 + private Map<String, String> reqParameterToPOMap;
  19 + private List<ColumnModel> columnList;
  20 + private String pkBeanName;
  21 + private String pkColumName;
  22 + private String pkType;
  23 + private String column_list_str;
  24 + private String dbType;
  25 +
  26 + public String getColumn_list_str() {
  27 + return column_list_str;
  28 + }
  29 + public void setColumn_list_str(String column_list_str) {
  30 + this.column_list_str = column_list_str;
  31 + }
  32 + public String getUsers() {
  33 + return users;
  34 + }
  35 + public void setUsers(String users) {
  36 + this.users = users;
  37 + }
  38 + public String getVersion() {
  39 + return version;
  40 + }
  41 + public void setVersion(String version) {
  42 + this.version = version;
  43 + }
  44 + public String getPackages() {
  45 + return packages;
  46 + }
  47 + public void setPackages(String packages) {
  48 + this.packages = packages;
  49 + }
  50 + public String getBeanName() {
  51 + return beanName;
  52 + }
  53 + public void setBeanName(String beanName) {
  54 + this.beanName = beanName;
  55 + }
  56 + public String getTableName() {
  57 + return tableName;
  58 + }
  59 + public void setTableName(String tableName) {
  60 + this.tableName = tableName;
  61 + }
  62 + public List<String> getImports() {
  63 + return imports;
  64 + }
  65 + public void setImports(List<String> imports) {
  66 + this.imports = imports;
  67 + }
  68 + public List<String> getPropertys() {
  69 + return propertys;
  70 + }
  71 + public void setPropertys(List<String> propertys) {
  72 + this.propertys = propertys;
  73 + }
  74 + public List<FunctionModel> getFunlist() {
  75 + return funlist;
  76 + }
  77 + public void setFunlist(List<FunctionModel> funlist) {
  78 + this.funlist = funlist;
  79 + }
  80 + public Map<String, String> getReqParameterToPOMap() {
  81 + return reqParameterToPOMap;
  82 + }
  83 + public void setReqParameterToPOMap(Map<String, String> reqParameterToPOMap) {
  84 + this.reqParameterToPOMap = reqParameterToPOMap;
  85 + }
  86 + public List<ColumnModel> getColumnList() {
  87 + return columnList;
  88 + }
  89 + public void setColumnList(List<ColumnModel> columnList) {
  90 + this.columnList = columnList;
  91 + }
  92 + public String getPkBeanName() {
  93 + return pkBeanName;
  94 + }
  95 + public void setPkBeanName(String pkBeanName) {
  96 + this.pkBeanName = pkBeanName;
  97 + }
  98 + public String getPkColumName() {
  99 + return pkColumName;
  100 + }
  101 + public void setPkColumName(String pkColumName) {
  102 + this.pkColumName = pkColumName;
  103 + }
  104 + public String getPkType() {
  105 + return pkType;
  106 + }
  107 + public void setPkType(String pK_TYPE) {
  108 + pkType = pK_TYPE;
  109 + }
  110 + public String getDbType() {
  111 + return dbType;
  112 + }
  113 + public void setDbType(String dbType) {
  114 + this.dbType = dbType;
  115 + }
  116 +}
... ...
src/com/taover/base/template/model/dao/.svn/text-base/FunctionModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/.svn/text-base/FunctionModel.java.svn-base
... ... @@ -0,0 +1,97 @@
  1 +package cn.tootoo.base.template.model.dao;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class FunctionModel {
  6 + // 方法返回类型
  7 + private String function_return;
  8 + // 方法名
  9 + private String function_name;
  10 + // 方法参数名称
  11 + private List<String> function_param;
  12 + // 形参(类型 名称)
  13 + private String function_params;
  14 + // 方法抛出异常
  15 + private List<String> function_exception;
  16 + // 方法描述
  17 + private String function_description;
  18 + // 异常描述
  19 + private String function_exceptions;
  20 + // 方法体
  21 + private String function_body;
  22 + // 是否是重写方法
  23 + private String over;
  24 +
  25 + public String getFunction_return() {
  26 + return function_return;
  27 + }
  28 +
  29 + public void setFunction_return(String function_return) {
  30 + this.function_return = function_return;
  31 + }
  32 +
  33 + public String getFunction_name() {
  34 + return function_name;
  35 + }
  36 +
  37 + public void setFunction_name(String function_name) {
  38 + this.function_name = function_name;
  39 + }
  40 +
  41 + public List<String> getFunction_param() {
  42 + return function_param;
  43 + }
  44 +
  45 + public void setFunction_param(List<String> function_param) {
  46 + this.function_param = function_param;
  47 + }
  48 +
  49 + public List<String> getFunction_exception() {
  50 + return function_exception;
  51 + }
  52 +
  53 + public void setFunction_exception(List<String> function_exception) {
  54 + this.function_exception = function_exception;
  55 + }
  56 +
  57 + public String getFunction_description() {
  58 + return function_description;
  59 + }
  60 +
  61 + public void setFunction_description(String function_description) {
  62 + this.function_description = function_description;
  63 + }
  64 +
  65 + public String getFunction_params() {
  66 + return function_params;
  67 + }
  68 +
  69 + public void setFunction_params(String function_params) {
  70 + this.function_params = function_params;
  71 + }
  72 +
  73 + public String getFunction_exceptions() {
  74 + return function_exceptions;
  75 + }
  76 +
  77 + public void setFunction_exceptions(String function_exceptions) {
  78 + this.function_exceptions = function_exceptions;
  79 + }
  80 +
  81 + public String getFunction_body() {
  82 + return function_body;
  83 + }
  84 +
  85 + public void setFunction_body(String function_body) {
  86 + this.function_body = function_body;
  87 + }
  88 +
  89 + public String getOver() {
  90 + return over;
  91 + }
  92 +
  93 + public void setOver(String over) {
  94 + this.over = over;
  95 + }
  96 +
  97 +}
... ...
src/com/taover/base/template/model/dao/BaseModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/BaseModel.java
... ... @@ -0,0 +1,40 @@
  1 +package com.taover.base.template.model.dao;
  2 +
  3 +public class BaseModel {
  4 + private String beanVarName;
  5 + private String function_return;
  6 + private String function_name;
  7 + private String function_param;
  8 + private String function_body;
  9 +
  10 + public String getBeanVarName() {
  11 + return beanVarName;
  12 + }
  13 + public void setBeanVarName(String beanVarName) {
  14 + this.beanVarName = beanVarName;
  15 + }
  16 + public String getFunction_return() {
  17 + return function_return;
  18 + }
  19 + public void setFunction_return(String function_return) {
  20 + this.function_return = function_return;
  21 + }
  22 + public String getFunction_name() {
  23 + return function_name;
  24 + }
  25 + public void setFunction_name(String function_name) {
  26 + this.function_name = function_name;
  27 + }
  28 + public String getFunction_param() {
  29 + return function_param;
  30 + }
  31 + public void setFunction_param(String function_param) {
  32 + this.function_param = function_param;
  33 + }
  34 + public String getFunction_body() {
  35 + return function_body;
  36 + }
  37 + public void setFunction_body(String function_body) {
  38 + this.function_body = function_body;
  39 + }
  40 +}
... ...
src/com/taover/base/template/model/dao/DaoModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/DaoModel.java
... ... @@ -0,0 +1,117 @@
  1 +package com.taover.base.template.model.dao;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import com.taover.base.template.model.po.ColumnModel;
  7 +
  8 +
  9 +public class DaoModel {
  10 +
  11 + private String users;
  12 + private String version;
  13 + private String packages;
  14 + private String beanName;
  15 + private String tableName;
  16 + private List<String> imports;
  17 + private List<String> propertys;
  18 + private List<FunctionModel> funlist;
  19 + private Map<String, String> reqParameterToPOMap;
  20 + private List<ColumnModel> columnList;
  21 + private String pkBeanName;
  22 + private String pkColumName;
  23 + private String pkType;
  24 + private String column_list_str;
  25 + private String dbType;
  26 +
  27 + public String getColumn_list_str() {
  28 + return column_list_str;
  29 + }
  30 + public void setColumn_list_str(String column_list_str) {
  31 + this.column_list_str = column_list_str;
  32 + }
  33 + public String getUsers() {
  34 + return users;
  35 + }
  36 + public void setUsers(String users) {
  37 + this.users = users;
  38 + }
  39 + public String getVersion() {
  40 + return version;
  41 + }
  42 + public void setVersion(String version) {
  43 + this.version = version;
  44 + }
  45 + public String getPackages() {
  46 + return packages;
  47 + }
  48 + public void setPackages(String packages) {
  49 + this.packages = packages;
  50 + }
  51 + public String getBeanName() {
  52 + return beanName;
  53 + }
  54 + public void setBeanName(String beanName) {
  55 + this.beanName = beanName;
  56 + }
  57 + public String getTableName() {
  58 + return tableName;
  59 + }
  60 + public void setTableName(String tableName) {
  61 + this.tableName = tableName;
  62 + }
  63 + public List<String> getImports() {
  64 + return imports;
  65 + }
  66 + public void setImports(List<String> imports) {
  67 + this.imports = imports;
  68 + }
  69 + public List<String> getPropertys() {
  70 + return propertys;
  71 + }
  72 + public void setPropertys(List<String> propertys) {
  73 + this.propertys = propertys;
  74 + }
  75 + public List<FunctionModel> getFunlist() {
  76 + return funlist;
  77 + }
  78 + public void setFunlist(List<FunctionModel> funlist) {
  79 + this.funlist = funlist;
  80 + }
  81 + public Map<String, String> getReqParameterToPOMap() {
  82 + return reqParameterToPOMap;
  83 + }
  84 + public void setReqParameterToPOMap(Map<String, String> reqParameterToPOMap) {
  85 + this.reqParameterToPOMap = reqParameterToPOMap;
  86 + }
  87 + public List<ColumnModel> getColumnList() {
  88 + return columnList;
  89 + }
  90 + public void setColumnList(List<ColumnModel> columnList) {
  91 + this.columnList = columnList;
  92 + }
  93 + public String getPkBeanName() {
  94 + return pkBeanName;
  95 + }
  96 + public void setPkBeanName(String pkBeanName) {
  97 + this.pkBeanName = pkBeanName;
  98 + }
  99 + public String getPkColumName() {
  100 + return pkColumName;
  101 + }
  102 + public void setPkColumName(String pkColumName) {
  103 + this.pkColumName = pkColumName;
  104 + }
  105 + public String getPkType() {
  106 + return pkType;
  107 + }
  108 + public void setPkType(String pK_TYPE) {
  109 + pkType = pK_TYPE;
  110 + }
  111 + public String getDbType() {
  112 + return dbType;
  113 + }
  114 + public void setDbType(String dbType) {
  115 + this.dbType = dbType;
  116 + }
  117 +}
... ...
src/com/taover/base/template/model/dao/FunctionModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/dao/FunctionModel.java
... ... @@ -0,0 +1,97 @@
  1 +package com.taover.base.template.model.dao;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class FunctionModel {
  6 + // 方法返回类型
  7 + private String function_return;
  8 + // 方法名
  9 + private String function_name;
  10 + // 方法参数名称
  11 + private List<String> function_param;
  12 + // 形参(类型 名称)
  13 + private String function_params;
  14 + // 方法抛出异常
  15 + private List<String> function_exception;
  16 + // 方法描述
  17 + private String function_description;
  18 + // 异常描述
  19 + private String function_exceptions;
  20 + // 方法体
  21 + private String function_body;
  22 + // 是否是重写方法
  23 + private String over;
  24 +
  25 + public String getFunction_return() {
  26 + return function_return;
  27 + }
  28 +
  29 + public void setFunction_return(String function_return) {
  30 + this.function_return = function_return;
  31 + }
  32 +
  33 + public String getFunction_name() {
  34 + return function_name;
  35 + }
  36 +
  37 + public void setFunction_name(String function_name) {
  38 + this.function_name = function_name;
  39 + }
  40 +
  41 + public List<String> getFunction_param() {
  42 + return function_param;
  43 + }
  44 +
  45 + public void setFunction_param(List<String> function_param) {
  46 + this.function_param = function_param;
  47 + }
  48 +
  49 + public List<String> getFunction_exception() {
  50 + return function_exception;
  51 + }
  52 +
  53 + public void setFunction_exception(List<String> function_exception) {
  54 + this.function_exception = function_exception;
  55 + }
  56 +
  57 + public String getFunction_description() {
  58 + return function_description;
  59 + }
  60 +
  61 + public void setFunction_description(String function_description) {
  62 + this.function_description = function_description;
  63 + }
  64 +
  65 + public String getFunction_params() {
  66 + return function_params;
  67 + }
  68 +
  69 + public void setFunction_params(String function_params) {
  70 + this.function_params = function_params;
  71 + }
  72 +
  73 + public String getFunction_exceptions() {
  74 + return function_exceptions;
  75 + }
  76 +
  77 + public void setFunction_exceptions(String function_exceptions) {
  78 + this.function_exceptions = function_exceptions;
  79 + }
  80 +
  81 + public String getFunction_body() {
  82 + return function_body;
  83 + }
  84 +
  85 + public void setFunction_body(String function_body) {
  86 + this.function_body = function_body;
  87 + }
  88 +
  89 + public String getOver() {
  90 + return over;
  91 + }
  92 +
  93 + public void setOver(String over) {
  94 + this.over = over;
  95 + }
  96 +
  97 +}
... ...
src/com/taover/base/template/model/po/.svn/entries 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/.svn/entries
... ... @@ -0,0 +1,130 @@
  1 +10
  2 +
  3 +dir
  4 +115305
  5 +svn://119.254.17.138/repos/%E6%B2%B1%E6%B2%B1%E7%94%9F%E6%B4%BB%E7%BD%91%E8%B6%85/code/soa.tootoo.cn/trunk/generate-tootoo-dao-po/src/cn/tootoo/base/template/model/po
  6 +svn://119.254.17.138/repos
  7 +
  8 +
  9 +
  10 +2014-05-21T06:48:36.887728Z
  11 +62846
  12 +wangpeng
  13 +
  14 +
  15 +svn:special svn:externals svn:needs-lock
  16 +
  17 +
  18 +
  19 +
  20 +
  21 +
  22 +
  23 +
  24 +
  25 +
  26 +
  27 +5351f05e-98f4-42cc-8e6a-33022518c94f
  28 +
  29 +ColumnModel.java
  30 +file
  31 +
  32 +
  33 +
  34 +
  35 +2015-08-10T05:52:55.898000Z
  36 +b20b551adbb9cf3a5207c168b856d332
  37 +2014-05-21T06:48:36.887728Z
  38 +62846
  39 +wangpeng
  40 +
  41 +
  42 +
  43 +
  44 +
  45 +
  46 +
  47 +
  48 +
  49 +
  50 +
  51 +
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +1507
  62 +
  63 +PoModel.java
  64 +file
  65 +
  66 +
  67 +
  68 +
  69 +2015-08-10T05:52:55.839000Z
  70 +bdbc3709b8452e308f72e6b71c4cc9e2
  71 +2014-05-21T03:24:19.464571Z
  72 +62806
  73 +wangpeng
  74 +
  75 +
  76 +
  77 +
  78 +
  79 +
  80 +
  81 +
  82 +
  83 +
  84 +
  85 +
  86 +
  87 +
  88 +
  89 +
  90 +
  91 +
  92 +
  93 +
  94 +
  95 +1144
  96 +
  97 +TableModel.java
  98 +file
  99 +
  100 +
  101 +
  102 +
  103 +2015-08-10T05:52:55.872000Z
  104 +b95c5663c4c68cf2b4d568d8e43018cd
  105 +2014-05-21T03:24:19.464571Z
  106 +62806
  107 +wangpeng
  108 +
  109 +
  110 +
  111 +
  112 +
  113 +
  114 +
  115 +
  116 +
  117 +
  118 +
  119 +
  120 +
  121 +
  122 +
  123 +
  124 +
  125 +
  126 +
  127 +
  128 +
  129 +487
  130 +
... ...
src/com/taover/base/template/model/po/.svn/text-base/ColumnModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/.svn/text-base/ColumnModel.java.svn-base
... ... @@ -0,0 +1,73 @@
  1 +package cn.tootoo.base.template.model.po;
  2 +
  3 +public class ColumnModel {
  4 + private String columnName;
  5 + private String columnMethodName;
  6 + private String columnUName;
  7 + public String getColumnUName() {
  8 + return columnUName;
  9 + }
  10 +
  11 + public void setColumnUName(String columnUName) {
  12 + this.columnUName = columnUName;
  13 + }
  14 +
  15 + private int columnSQLType;
  16 + private String columnJAVAType;
  17 + private String columnRemarks;
  18 + private String seqName;
  19 + private int column_Scale;
  20 +
  21 + public String getColumnName() {
  22 + return columnName;
  23 + }
  24 +
  25 + public void setColumnName(String columnName) {
  26 + this.columnName = columnName;
  27 + }
  28 +
  29 + public String getColumnMethodName() {
  30 + return columnMethodName;
  31 + }
  32 +
  33 + public void setColumnMethodName(String columnMethodName) {
  34 + this.columnMethodName = columnMethodName;
  35 + }
  36 +
  37 + public int getColumnSQLType() {
  38 + return columnSQLType;
  39 + }
  40 +
  41 + public String getColumnJAVAType() {
  42 + return columnJAVAType;
  43 + }
  44 +
  45 + public void setColumnJAVAType(String columnJAVAType) {
  46 + this.columnJAVAType = columnJAVAType;
  47 + }
  48 +
  49 + public String getColumnRemarks() {
  50 + return columnRemarks;
  51 + }
  52 +
  53 + public void setColumnRemarks(String columnRemarks) {
  54 + this.columnRemarks = columnRemarks;
  55 + }
  56 +
  57 + public int getColumn_Scale() {
  58 + return column_Scale;
  59 + }
  60 +
  61 + public void setColumn_Scale(int column_Scale) {
  62 + this.column_Scale = column_Scale;
  63 + }
  64 +
  65 + public String getSeqName() {
  66 + return seqName;
  67 + }
  68 +
  69 + public void setSeqName(String seqName) {
  70 + this.seqName = seqName;
  71 + }
  72 +
  73 +}
... ...
src/com/taover/base/template/model/po/.svn/text-base/PoModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/.svn/text-base/PoModel.java.svn-base
... ... @@ -0,0 +1,64 @@
  1 +package cn.tootoo.base.template.model.po;
  2 +
  3 +
  4 +public class PoModel {
  5 + // 包名
  6 + private String packages;
  7 + // 作者
  8 + private String users;
  9 + // 版本
  10 + private String version;
  11 +
  12 + private String name;
  13 + private String toStringMethodBody;
  14 + private TableModel tablemodel;
  15 +
  16 + public String getPackages() {
  17 + return packages;
  18 + }
  19 +
  20 + public void setPackages(String packages) {
  21 + this.packages = packages;
  22 + }
  23 +
  24 + public String getUsers() {
  25 + return users;
  26 + }
  27 +
  28 + public void setUsers(String users) {
  29 + this.users = users;
  30 + }
  31 +
  32 + public String getVersion() {
  33 + return version;
  34 + }
  35 +
  36 + public void setVersion(String version) {
  37 + this.version = version;
  38 + }
  39 +
  40 + public String getName() {
  41 + return name;
  42 + }
  43 +
  44 + public void setName(String name) {
  45 + this.name = name;
  46 + }
  47 +
  48 + public TableModel getTablemodel() {
  49 + return tablemodel;
  50 + }
  51 +
  52 + public void setTablemodel(TableModel tablemodel) {
  53 + this.tablemodel = tablemodel;
  54 + }
  55 +
  56 + public String getToStringMethodBody() {
  57 + return toStringMethodBody;
  58 + }
  59 +
  60 + public void setToStringMethodBody(String toStringMethodBody) {
  61 + this.toStringMethodBody = toStringMethodBody;
  62 + }
  63 +
  64 +}
... ...
src/com/taover/base/template/model/po/.svn/text-base/TableModel.java.svn-base 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/.svn/text-base/TableModel.java.svn-base
... ... @@ -0,0 +1,25 @@
  1 +package cn.tootoo.base.template.model.po;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class TableModel {
  6 + private String tableName;
  7 + private List<ColumnModel> columnlist;
  8 +
  9 + public String getTableName() {
  10 + return tableName;
  11 + }
  12 +
  13 + public void setTableName(String tableName) {
  14 + this.tableName = tableName;
  15 + }
  16 +
  17 + public List<ColumnModel> getColumnlist() {
  18 + return columnlist;
  19 + }
  20 +
  21 + public void setColumnlist(List<ColumnModel> columnlist) {
  22 + this.columnlist = columnlist;
  23 + }
  24 +
  25 +}
... ...
src/com/taover/base/template/model/po/ColumnModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/ColumnModel.java
... ... @@ -0,0 +1,73 @@
  1 +package com.taover.base.template.model.po;
  2 +
  3 +public class ColumnModel {
  4 + private String columnName;
  5 + private String columnMethodName;
  6 + private String columnUName;
  7 + public String getColumnUName() {
  8 + return columnUName;
  9 + }
  10 +
  11 + public void setColumnUName(String columnUName) {
  12 + this.columnUName = columnUName;
  13 + }
  14 +
  15 + private int columnSQLType;
  16 + private String columnJAVAType;
  17 + private String columnRemarks;
  18 + private String seqName;
  19 + private int column_Scale;
  20 +
  21 + public String getColumnName() {
  22 + return columnName;
  23 + }
  24 +
  25 + public void setColumnName(String columnName) {
  26 + this.columnName = columnName;
  27 + }
  28 +
  29 + public String getColumnMethodName() {
  30 + return columnMethodName;
  31 + }
  32 +
  33 + public void setColumnMethodName(String columnMethodName) {
  34 + this.columnMethodName = columnMethodName;
  35 + }
  36 +
  37 + public int getColumnSQLType() {
  38 + return columnSQLType;
  39 + }
  40 +
  41 + public String getColumnJAVAType() {
  42 + return columnJAVAType;
  43 + }
  44 +
  45 + public void setColumnJAVAType(String columnJAVAType) {
  46 + this.columnJAVAType = columnJAVAType;
  47 + }
  48 +
  49 + public String getColumnRemarks() {
  50 + return columnRemarks;
  51 + }
  52 +
  53 + public void setColumnRemarks(String columnRemarks) {
  54 + this.columnRemarks = columnRemarks;
  55 + }
  56 +
  57 + public int getColumn_Scale() {
  58 + return column_Scale;
  59 + }
  60 +
  61 + public void setColumn_Scale(int column_Scale) {
  62 + this.column_Scale = column_Scale;
  63 + }
  64 +
  65 + public String getSeqName() {
  66 + return seqName;
  67 + }
  68 +
  69 + public void setSeqName(String seqName) {
  70 + this.seqName = seqName;
  71 + }
  72 +
  73 +}
... ...
src/com/taover/base/template/model/po/PoModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/PoModel.java
... ... @@ -0,0 +1,64 @@
  1 +package com.taover.base.template.model.po;
  2 +
  3 +
  4 +public class PoModel {
  5 + // 包名
  6 + private String packages;
  7 + // 作者
  8 + private String users;
  9 + // 版本
  10 + private String version;
  11 +
  12 + private String name;
  13 + private String toStringMethodBody;
  14 + private TableModel tablemodel;
  15 +
  16 + public String getPackages() {
  17 + return packages;
  18 + }
  19 +
  20 + public void setPackages(String packages) {
  21 + this.packages = packages;
  22 + }
  23 +
  24 + public String getUsers() {
  25 + return users;
  26 + }
  27 +
  28 + public void setUsers(String users) {
  29 + this.users = users;
  30 + }
  31 +
  32 + public String getVersion() {
  33 + return version;
  34 + }
  35 +
  36 + public void setVersion(String version) {
  37 + this.version = version;
  38 + }
  39 +
  40 + public String getName() {
  41 + return name;
  42 + }
  43 +
  44 + public void setName(String name) {
  45 + this.name = name;
  46 + }
  47 +
  48 + public TableModel getTablemodel() {
  49 + return tablemodel;
  50 + }
  51 +
  52 + public void setTablemodel(TableModel tablemodel) {
  53 + this.tablemodel = tablemodel;
  54 + }
  55 +
  56 + public String getToStringMethodBody() {
  57 + return toStringMethodBody;
  58 + }
  59 +
  60 + public void setToStringMethodBody(String toStringMethodBody) {
  61 + this.toStringMethodBody = toStringMethodBody;
  62 + }
  63 +
  64 +}
... ...
src/com/taover/base/template/model/po/TableModel.java 0 → 100644
  1 +++ a/src/com/taover/base/template/model/po/TableModel.java
... ... @@ -0,0 +1,25 @@
  1 +package com.taover.base.template.model.po;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class TableModel {
  6 + private String tableName;
  7 + private List<ColumnModel> columnlist;
  8 +
  9 + public String getTableName() {
  10 + return tableName;
  11 + }
  12 +
  13 + public void setTableName(String tableName) {
  14 + this.tableName = tableName;
  15 + }
  16 +
  17 + public List<ColumnModel> getColumnlist() {
  18 + return columnlist;
  19 + }
  20 +
  21 + public void setColumnlist(List<ColumnModel> columnlist) {
  22 + this.columnlist = columnlist;
  23 + }
  24 +
  25 +}
... ...
src/com/taover/business/Constants.java 0 → 100644
  1 +++ a/src/com/taover/business/Constants.java
... ... @@ -0,0 +1,14 @@
  1 +package com.taover.business;
  2 +
  3 +public class Constants {
  4 + public static String TEMPATE_PATH = "/com/taover/base/template/";
  5 + public static String TEMPATE_CONTROLLERNAME = "ControllerTemplate.ftl";
  6 + public static String TEMPATE_CONTROLLER_EXPORT_NAME = "ControllerExportTemplate.ftl";
  7 + public static String TEMPATE_SERVICEIMPLNAME = "ServiceImplTemplate.ftl";
  8 + public static String TEMPATE_SERVICENAME = "ServiceTemplate.ftl";
  9 + public static String TEMPATE_EXPORT_SERVICENAME = "ServiceExportTemplate.ftl";
  10 + public static String TEMPATE_HTMLNAME = "HtmlTemplate.ftl";
  11 + public static String TEMPATE_HTMLLAYUINAME = "HtmlLayuiTemplate.ftl";
  12 + public static String TEMPATE_JSNAME = "JsTemplate.ftl";
  13 +}
  14 +
... ...
src/com/taover/business/GenerateCS.java 0 → 100644
  1 +++ a/src/com/taover/business/GenerateCS.java
... ... @@ -0,0 +1,96 @@
  1 +package com.taover.business;
  2 +
  3 +import java.sql.Connection;
  4 +import java.sql.ResultSet;
  5 +import java.sql.SQLException;
  6 +import java.util.ArrayList;
  7 +import java.util.List;
  8 +import java.util.Properties;
  9 +import java.util.Vector;
  10 +
  11 +import com.taover.base.template.model.bussiness.EnvironmentModel;
  12 +import com.taover.db.TableColumn;
  13 +import com.taover.db.Tools;
  14 +import com.taover.tools.StringUtil;
  15 +
  16 +public class GenerateCS {
  17 +
  18 + public static void main(String[] args) throws Exception{
  19 + //读取配置文件
  20 + Properties properties = Tools.getProperties();
  21 + //取数据库连接
  22 + Connection conn = Tools.getConnection(properties);
  23 + //初始化要生成的表列表
  24 + List<String> tableNameList = new ArrayList<String>();
  25 +
  26 + String schameName = properties.getProperty("SchameName");
  27 + String createSchame = properties.getProperty("CreateSchame");
  28 + String dbType = properties.getProperty("dbtype");
  29 + String tableName = properties.getProperty("TableName");
  30 + if("mysql".equalsIgnoreCase(dbType)){
  31 + //schameName = schameName.toUpperCase();
  32 + }
  33 +
  34 + if (createSchame.equalsIgnoreCase("true") || "ALL".equalsIgnoreCase(tableName) ) {
  35 +
  36 + String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+schameName+"'";
  37 + ResultSet rs = Tools.executeQuery(Tools.createStmt(conn), sql);
  38 + if (null == rs)
  39 + return ;
  40 + try {
  41 + while (rs.next()) {
  42 + tableNameList.add(rs.getString("Table_name"));
  43 + }
  44 + } catch (SQLException e) {
  45 + e.printStackTrace();
  46 + }
  47 + Tools.close(rs);
  48 + } else {
  49 + if("mysql".equalsIgnoreCase(dbType)){
  50 + tableName = tableName.toUpperCase();
  51 + }
  52 + String[] TableNameArr = tableName.split(",");
  53 + for (int i = 0; i < TableNameArr.length; i++)
  54 + tableNameList.add(TableNameArr[i]);
  55 +
  56 + }
  57 +
  58 + //读取配置文件信息
  59 + String modulePackageInfo = properties.getProperty("modulePackageInfo");
  60 + String moduleFilePath = properties.getProperty("moduleFilePath");
  61 + String dbPackageInfo = properties.getProperty("dbPackageInfo");
  62 + String dbLikeStr = properties.getProperty("DBLikeStr");
  63 +
  64 + //循环遍历各个表名
  65 + for (int i = 0; i < tableNameList.size(); i++) {
  66 + String tableNameCurr = (String) tableNameList.get(i);
  67 +
  68 + // 取得表中所有列
  69 + Vector<TableColumn> columnsInTable = TableColumn.GetTableInfo(conn, schameName, tableNameCurr, dbLikeStr, dbType);
  70 + if (columnsInTable == null || columnsInTable.size() == 0) {
  71 + System.out.println(tableNameCurr + " : 生成失败,得不到表中列明");
  72 + continue;
  73 + }
  74 + TableColumn pkcolum = TableColumn.getPKColum(columnsInTable);
  75 + if (pkcolum == null) {
  76 + System.out.println(tableNameCurr + " : 生成失败,未设置主键");
  77 + continue;
  78 + }
  79 +
  80 + String beanClassName = StringUtil.formatBeanNameFirstUpper(tableNameCurr);
  81 + String poPackageInfo = dbPackageInfo + "." + beanClassName.toLowerCase();
  82 +
  83 + String moduleName = tableNameCurr.split("_")[0];
  84 + EnvironmentModel envir = EnvironmentModel.createEnvironmentModel(modulePackageInfo, moduleFilePath, poPackageInfo, beanClassName, moduleName);
  85 + //生成Controller层
  86 + GenerateController.generateController(envir, false, columnsInTable);
  87 + //生成Service层
  88 + GenerateService.generateService(envir, false);
  89 +
  90 + System.out.println(tableNameCurr + " : 生成结束");
  91 + }
  92 + conn.close();
  93 + System.out.println("全部结束");
  94 +
  95 + }
  96 +}
... ...
src/com/taover/business/GenerateController.java 0 → 100644
  1 +++ a/src/com/taover/business/GenerateController.java
... ... @@ -0,0 +1,48 @@
  1 +package com.taover.business;
  2 +
  3 +import java.io.File;
  4 +import java.io.StringWriter;
  5 +import java.util.Vector;
  6 +
  7 +import com.taover.base.template.model.bussiness.ControllerModel;
  8 +import com.taover.base.template.model.bussiness.EnvironmentModel;
  9 +import com.taover.db.TableColumn;
  10 +import com.taover.db.Tools;
  11 +
  12 +import freemarker.template.Configuration;
  13 +import freemarker.template.Template;
  14 +
  15 +public class GenerateController {
  16 +
  17 + public static void generateController(EnvironmentModel enirModel, boolean coverWhenFileExists, Vector<TableColumn> columnsInTable) {
  18 + try{
  19 + ControllerModel model = ControllerModel.createControllerModel(
  20 + enirModel.getControllerPackageInfo(),
  21 + enirModel.getPoPackageInfo(),
  22 + enirModel.getServicePackageInfo(),
  23 + enirModel.getBeanClassName(),
  24 + enirModel.getMainPackageInfo(),
  25 + enirModel.getSubModuleName(),
  26 + columnsInTable);
  27 +
  28 + File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
  29 + Configuration cfg = new Configuration();
  30 + cfg.setDirectoryForTemplateLoading(f);
  31 +
  32 + StringWriter out = new StringWriter();
  33 + Template template = cfg.getTemplate(Constants.TEMPATE_CONTROLLERNAME, "UTF-8");
  34 + template.process(model, out);
  35 +
  36 + String destFilePath = enirModel.getControllerFilePath() + File.separator + model.getControllerClassName() + ".java";
  37 + File destFile = new File(destFilePath);
  38 + if(coverWhenFileExists || !destFile.exists()){
  39 + Tools.createFile(enirModel.getControllerFilePath(), model.getControllerClassName()+".java", out.toString());
  40 + }else{
  41 + System.out.println("文件生成:"+destFile.getName()+"文件已经存在,未覆盖!");
  42 + }
  43 +
  44 + }catch(Exception e){
  45 + e.printStackTrace();
  46 + }
  47 + }
  48 +}
... ...
src/com/taover/business/GenerateService.java 0 → 100644
  1 +++ a/src/com/taover/business/GenerateService.java
... ... @@ -0,0 +1,57 @@
  1 +package com.taover.business;
  2 +
  3 +import java.io.File;
  4 +import java.io.StringWriter;
  5 +
  6 +import com.taover.base.template.model.bussiness.EnvironmentModel;
  7 +import com.taover.base.template.model.bussiness.ServiceModel;
  8 +import com.taover.db.Tools;
  9 +
  10 +import freemarker.template.Configuration;
  11 +import freemarker.template.Template;
  12 +
  13 +public class GenerateService {
  14 +
  15 + public static void generateService(EnvironmentModel enirModel, boolean coverWhenFileExists) {
  16 + try{
  17 + ServiceModel model = ServiceModel.createServiceModel(
  18 + enirModel.getPoPackageInfo(),
  19 + enirModel.getBeanClassName(),
  20 + enirModel.getMainPackageInfo(),
  21 + enirModel.getSubModuleName());
  22 +
  23 + File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
  24 + Configuration cfg = new Configuration();
  25 + cfg.setDirectoryForTemplateLoading(f);
  26 +
  27 + //service实现文件
  28 + StringWriter outService = new StringWriter();
  29 + Template templateService = cfg.getTemplate(Constants.TEMPATE_SERVICEIMPLNAME, "UTF-8");
  30 + templateService.process(model, outService);
  31 + File destFile = new File(
  32 + enirModel.getServiceFilePath()+File.separator+
  33 + "impl"+File.separator+
  34 + model.getBeanClassName()+"ServiceImpl.java");
  35 + if(coverWhenFileExists || !destFile.exists()){
  36 + Tools.createFile(enirModel.getServiceFilePath()+File.separator+"impl", model.getBeanClassName()+"ServiceImpl.java", outService.toString());
  37 + }else{
  38 + System.out.println("文件生成:"+destFile.getName()+"文件已经存在,未覆盖!");
  39 + }
  40 +
  41 + //service接口文件
  42 + StringWriter outServiceImpl = new StringWriter();
  43 + Template templateServiceImpl = cfg.getTemplate(Constants.TEMPATE_SERVICENAME, "UTF-8");
  44 + templateServiceImpl.process(model, outServiceImpl);
  45 + File destFile2 = new File(
  46 + enirModel.getServiceFilePath()+File.separator+
  47 + model.getBeanClassName()+"Service.java");
  48 + if(coverWhenFileExists || !destFile2.exists()){
  49 + Tools.createFile(enirModel.getServiceFilePath(), model.getBeanClassName()+"Service.java", outServiceImpl.toString());
  50 + }else{
  51 + System.out.println("文件生成:"+destFile2.getName()+"文件已经存在,未覆盖!");
  52 + }
  53 + }catch(Exception e){
  54 + e.printStackTrace();
  55 + }
  56 + }
  57 +}
... ...
src/com/taover/business/GenerateVCSDP.java 0 → 100644
  1 +++ a/src/com/taover/business/GenerateVCSDP.java
... ... @@ -0,0 +1,128 @@
  1 +package com.taover.business;
  2 +
  3 +import java.io.File;
  4 +import java.sql.Connection;
  5 +import java.sql.ResultSet;
  6 +import java.sql.SQLException;
  7 +import java.util.ArrayList;
  8 +import java.util.List;
  9 +import java.util.Properties;
  10 +import java.util.Vector;
  11 +
  12 +import com.taover.base.template.model.bussiness.EnvironmentModel;
  13 +import com.taover.db.GenerateDao;
  14 +import com.taover.db.GeneratePO;
  15 +import com.taover.db.TableColumn;
  16 +import com.taover.db.Tools;
  17 +import com.taover.tools.StringUtil;
  18 +
  19 +public class GenerateVCSDP {
  20 +
  21 + public static void main(String[] args) {
  22 + try {
  23 + generate();
  24 + } catch (Exception e) {
  25 + // TODO Auto-generated catch block
  26 + e.printStackTrace();
  27 + }
  28 + }
  29 +
  30 + public static void generate() throws Exception{
  31 + //读取配置文件
  32 + Properties properties = Tools.getProperties();
  33 + //取数据库连接
  34 + Connection conn = Tools.getConnection(properties);
  35 + //初始化要生成的表列表
  36 + List<String> tableNameList = new ArrayList<String>();
  37 +
  38 + //读取基本信息
  39 + String outputPath = properties.getProperty("OutputPath");
  40 + String schameName = properties.getProperty("SchameName");
  41 + String dbLikeStr = properties.getProperty("DBLikeStr");
  42 + String dbType = properties.getProperty("dbtype");
  43 + String dbPackagePath = properties.getProperty("packageName");
  44 + String tableName = properties.getProperty("TableName");
  45 +
  46 + //读取配置文件信息-Controller、Service层需要
  47 + String modulePackageInfo = properties.getProperty("modulePackageInfo");
  48 + String moduleFilePath = properties.getProperty("moduleFilePath");
  49 + String dbPackageInfo = properties.getProperty("dbPackageInfo");
  50 +
  51 + //如果文件已存在是否覆盖
  52 + boolean coverWhenFileExists = false;
  53 + if(properties.getProperty("coverWhenFileExists") != null){
  54 + coverWhenFileExists = Boolean.valueOf(properties.getProperty("coverWhenFileExists"));
  55 + }
  56 +
  57 + //读取配置文件信息-HTML、JS需要
  58 + String webRootPath = properties.getProperty("WebRootPath");
  59 +
  60 + if("mysql".equalsIgnoreCase(dbType)){
  61 + schameName = schameName.toUpperCase();
  62 + }
  63 +
  64 + if (!dbPackagePath.substring(dbPackagePath.length()-1).equals("."))
  65 + dbPackagePath += ".";
  66 +
  67 + if ("ALL".equalsIgnoreCase(tableName) ) {
  68 +
  69 + String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+schameName+"'";
  70 + ResultSet rs = Tools.executeQuery(Tools.createStmt(conn), sql);
  71 + if (null == rs)
  72 + return ;
  73 + try {
  74 + while (rs.next()) {
  75 + tableNameList.add(rs.getString("Table_name"));
  76 + }
  77 + } catch (SQLException e) {
  78 + e.printStackTrace();
  79 + }
  80 + Tools.close(rs);
  81 + } else {
  82 + if("mysql".equalsIgnoreCase(dbType)){
  83 +// tableName = tableName.toUpperCase();
  84 + }
  85 + String[] TableNameArr = tableName.split(",");
  86 + for (int i = 0; i < TableNameArr.length; i++)
  87 + tableNameList.add(TableNameArr[i]);
  88 + }
  89 +
  90 + for (int i = 0; i < tableNameList.size(); i++) {
  91 +
  92 + String tableNameCurr = (String) tableNameList.get(i);
  93 +
  94 + // 取得表中所有列
  95 + Vector<TableColumn> columnsInTable = TableColumn.GetTableInfo(conn, schameName, tableNameCurr, dbLikeStr, dbType);
  96 + if (columnsInTable == null || columnsInTable.size() == 0) {
  97 + System.out.println(tableNameCurr + " : 生成失败,得不到表中列明");
  98 + continue;
  99 + }
  100 + TableColumn pkcolum = TableColumn.getPKColum(columnsInTable);
  101 + if (pkcolum == null) {
  102 + System.out.println(tableNameCurr + " : 生成失败,未设置主键");
  103 + continue;
  104 + }
  105 +
  106 + // 生成po类
  107 + GeneratePO.generatePO(outputPath, dbPackagePath, columnsInTable);
  108 + // 生成Dao
  109 + GenerateDao.table2dao(outputPath, dbPackagePath, columnsInTable, dbType);
  110 +
  111 + String beanClassName = StringUtil.formatBeanNameFirstUpper(tableNameCurr);
  112 + String poPackageInfo = dbPackageInfo + "." + beanClassName.toLowerCase();
  113 +
  114 + String moduleName = tableNameCurr.split("_")[0];
  115 + EnvironmentModel envir = EnvironmentModel.createEnvironmentModel(modulePackageInfo, moduleFilePath, poPackageInfo, beanClassName, moduleName);
  116 + //生成Controller层
  117 + GenerateController.generateController(envir, coverWhenFileExists, columnsInTable);
  118 + //生成Service层
  119 + GenerateService.generateService(envir, coverWhenFileExists);
  120 + //生成view
  121 + GenerateView.generateView(webRootPath, tableNameCurr, columnsInTable, coverWhenFileExists);
  122 +
  123 + System.out.println(tableNameCurr + " : 生成结束");
  124 + }
  125 + conn.close();
  126 + System.out.println("全部结束");
  127 + }
  128 +}
... ...
src/com/taover/business/GenerateView.java 0 → 100644
  1 +++ a/src/com/taover/business/GenerateView.java
... ... @@ -0,0 +1,140 @@
  1 +package com.taover.business;
  2 +
  3 +import java.io.File;
  4 +import java.io.StringWriter;
  5 +import java.sql.Connection;
  6 +import java.sql.ResultSet;
  7 +import java.sql.SQLException;
  8 +import java.util.ArrayList;
  9 +import java.util.List;
  10 +import java.util.Properties;
  11 +import java.util.Vector;
  12 +
  13 +import com.taover.base.template.model.bussiness.ViewModel;
  14 +import com.taover.db.TableColumn;
  15 +import com.taover.db.Tools;
  16 +import com.taover.tools.StringUtil;
  17 +
  18 +import freemarker.template.Configuration;
  19 +import freemarker.template.Template;
  20 +
  21 +public class GenerateView {
  22 + public static void main(String args[]) throws SQLException{
  23 + //读取配置文件
  24 + Properties properties = Tools.getProperties();
  25 + //取数据库连接
  26 + Connection conn = Tools.getConnection(properties);
  27 + //初始化要生成的表列表
  28 + List<String> tableNameList = new ArrayList<String>();
  29 +
  30 + String outputPath = properties.getProperty("OutputPath");
  31 + String schameName = properties.getProperty("SchameName");
  32 + String createSchame = properties.getProperty("CreateSchame");
  33 + String dbLikeStr = properties.getProperty("DBLikeStr");
  34 + String dbType = properties.getProperty("dbtype");
  35 + String dbPackagePath = properties.getProperty("packageName");
  36 + String tableName = properties.getProperty("TableName");
  37 +
  38 + //WebRootPath读取
  39 + String webRootPath = properties.getProperty("WebRootPath");
  40 +
  41 + if("mysql".equalsIgnoreCase(dbType)){
  42 + //schameName = schameName.toUpperCase();
  43 + }
  44 +
  45 + if ("ALL".equalsIgnoreCase(tableName) ) {
  46 +
  47 + String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+schameName+"'";
  48 + ResultSet rs = Tools.executeQuery(Tools.createStmt(conn), sql);
  49 + if (null == rs)
  50 + return ;
  51 + List<String> result = new ArrayList<String>();
  52 + try {
  53 + while (rs.next()) {
  54 + tableNameList.add(rs.getString("Table_name"));
  55 + }
  56 + } catch (SQLException e) {
  57 + e.printStackTrace();
  58 + result = null;
  59 + }
  60 + Tools.close(rs);
  61 + } else {
  62 + if("mysql".equalsIgnoreCase(dbType)){
  63 + tableName = tableName.toUpperCase();
  64 + }
  65 + String[] TableNameArr = tableName.split(",");
  66 + for (int i = 0; i < TableNameArr.length; i++)
  67 + tableNameList.add(TableNameArr[i]);
  68 +
  69 + }
  70 +
  71 + for (int i = 0; i < tableNameList.size(); i++) {
  72 + String tableNameCurr = (String) tableNameList.get(i);
  73 +
  74 + // 取得表中所有列
  75 + Vector<TableColumn> columnsInTable = TableColumn.GetTableInfo(conn, schameName, tableNameCurr, dbLikeStr, dbType);
  76 + if (columnsInTable == null || columnsInTable.size() == 0) {
  77 + System.out.println(tableNameCurr + " : 生成失败,得不到表中列明");
  78 + continue;
  79 + }
  80 + TableColumn pkcolum = TableColumn.getPKColum(columnsInTable);
  81 + if (pkcolum == null) {
  82 + System.out.println(tableNameCurr + " : 生成失败,未设置主键");
  83 + continue;
  84 + }
  85 +
  86 + //生成view
  87 + generateView(webRootPath, tableNameCurr, columnsInTable, false);
  88 +
  89 + System.out.println(tableNameCurr + " : 生成结束");
  90 + }
  91 + conn.close();
  92 + System.out.println("全部结束");
  93 + }
  94 +
  95 + public static void generateView(String webRootPath, String tableName, Vector<TableColumn> columnsInTable, boolean coverWhenFileExists) {
  96 + try{
  97 + String controllerMapping = StringUtil.formatBeanNameFirstLow(tableName).toLowerCase();
  98 + ViewModel model = ViewModel.createViewModel(controllerMapping, webRootPath, columnsInTable);
  99 +
  100 + File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
  101 + Configuration cfg = new Configuration();
  102 + cfg.setDirectoryForTemplateLoading(f);
  103 +
  104 + StringWriter htmlOut = new StringWriter();
  105 + Template htmlTemplate = cfg.getTemplate(Constants.TEMPATE_HTMLNAME, "UTF-8");
  106 + htmlTemplate.process(model, htmlOut);
  107 + File destFile = new File(
  108 + webRootPath+File.separator+"manage"+File.separator+"html"+File.separator+controllerMapping+".html");
  109 + if(coverWhenFileExists || !destFile.exists()){
  110 + Tools.createFile(webRootPath+File.separator+"manage"+File.separator+"html", controllerMapping+".html", htmlOut.toString());
  111 + }else{
  112 + System.out.println("文件生成:"+destFile.getName()+"文件已经存在,未覆盖!");
  113 + }
  114 +
  115 + StringWriter jsOut = new StringWriter();
  116 + Template jsTemplate = cfg.getTemplate(Constants.TEMPATE_JSNAME, "UTF-8");
  117 + jsTemplate.process(model, jsOut);
  118 + File destFile2 = new File(
  119 + webRootPath+File.separator+"manage"+File.separator+"js"+File.separator+controllerMapping+".js");
  120 + if(coverWhenFileExists || !destFile2.exists()){
  121 + Tools.createFile(webRootPath+File.separator+"manage"+File.separator+"js", controllerMapping+".js", jsOut.toString());
  122 + }else{
  123 + System.out.println("文件生成:"+destFile2.getName()+"文件已经存在,未覆盖!");
  124 + }
  125 +
  126 + StringWriter htmlLayuiOut = new StringWriter();
  127 + Template htmlLayuiTemplate = cfg.getTemplate(Constants.TEMPATE_HTMLLAYUINAME, "UTF-8");
  128 + htmlLayuiTemplate.process(model, htmlLayuiOut);
  129 + File destLayuiFile = new File(
  130 + webRootPath+File.separator+"views"+File.separator+controllerMapping+".html");
  131 + if(coverWhenFileExists || !destLayuiFile.exists()){
  132 + Tools.createFile(webRootPath+File.separator+"views", controllerMapping+".html", htmlLayuiOut.toString());
  133 + }else{
  134 + System.out.println("文件生成:"+destFile.getName()+"文件已经存在,未覆盖!");
  135 + }
  136 + }catch(Exception e){
  137 + e.printStackTrace();
  138 + }
  139 + }
  140 +}
... ...
src/com/taover/business/Utils.java 0 → 100644
  1 +++ a/src/com/taover/business/Utils.java
... ... @@ -0,0 +1,13 @@
  1 +package com.taover.business;
  2 +
  3 +public class Utils {
  4 + public static String getFirstLetterLower(String source){
  5 + String lowerFirstLetter = "";
  6 + if(source.length() > 0){
  7 + lowerFirstLetter = source.substring(0, 1).toLowerCase();
  8 + }else{
  9 + return "";
  10 + }
  11 + return lowerFirstLetter+source.substring(1);
  12 + }
  13 +}
... ...
src/com/taover/business/util/TempVelocity.java 0 → 100644
  1 +++ a/src/com/taover/business/util/TempVelocity.java
... ... @@ -0,0 +1,134 @@
  1 +package com.taover.business.util;
  2 +
  3 +import java.io.File;
  4 +import java.io.StringWriter;
  5 +import java.sql.SQLException;
  6 +import java.util.ArrayList;
  7 +import java.util.HashMap;
  8 +import java.util.List;
  9 +import java.util.Map;
  10 +import java.util.regex.Matcher;
  11 +import java.util.regex.Pattern;
  12 +
  13 +import com.taover.business.Constants;
  14 +import com.taover.db.Tools;
  15 +
  16 +import freemarker.template.Configuration;
  17 +import freemarker.template.Template;
  18 +
  19 +public class TempVelocity {
  20 + public static void main(String args[]) throws SQLException{
  21 + String cnFunc = "代销平台毛利=1-代销平台成本/代销平台报价";
  22 +// String func = "promotProfit=promotPrice-promotAllCost-shareReward*shareRewardRate/100";
  23 + generate(cnFunc);
  24 + }
  25 +
  26 + public static void generate(String cnFunc) {
  27 + try{
  28 + File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
  29 + Configuration cfg = new Configuration();
  30 + cfg.setDirectoryForTemplateLoading(f);
  31 +
  32 + StringWriter htmlOut = new StringWriter();
  33 + Template htmlTemplate = cfg.getTemplate("Temp.ftl", "UTF-8");
  34 + Map<String, Object> data = new HashMap<String, Object>();
  35 + data.put("cnFunc", cnFunc);
  36 + parseData(data);
  37 +
  38 + htmlTemplate.process(data, htmlOut);
  39 + System.out.println(htmlOut.toString());
  40 + htmlOut.close();
  41 + }catch(Exception e){
  42 + e.printStackTrace();
  43 + }
  44 + }
  45 +
  46 + public static void parseData(Map<String, Object> data){
  47 + //propertyList,result
  48 + String cnFunc = (String) data.get("cnFunc");
  49 +
  50 +
  51 + String result = cnFunc.split("=")[0];
  52 + String resultEn = getEnName(result);
  53 +
  54 + String propertyStr = cnFunc.split("=")[1];
  55 + List<String> propertyList = new ArrayList<String>();
  56 +// Pattern pattern = Pattern.compile("[a-zA-Z]+", Pattern.CASE_INSENSITIVE);
  57 + Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+", Pattern.CASE_INSENSITIVE);
  58 + Matcher matcher = pattern.matcher(propertyStr);
  59 + List<String> cnNameList = new ArrayList<String>();
  60 + String enFunc = cnFunc;
  61 + while(matcher.find()){
  62 + String tempGroup = matcher.group();
  63 + cnNameList.add(tempGroup);
  64 + }
  65 + for(String cnName : cnNameList){
  66 + String enName = getEnName(cnName);
  67 + if(enName == null){
  68 + enName = "errorVal";
  69 + }
  70 + propertyList.add(enName);
  71 + enFunc = enFunc.replaceAll(cnName+"\\b", enName);
  72 + }
  73 + enFunc = enFunc.replaceAll(result, resultEn);
  74 +
  75 + data.put("enFunc", enFunc);
  76 + data.put("result", resultEn);
  77 + data.put("propertyList", propertyList);
  78 + }
  79 +
  80 + public static String getEnName(String cnName){
  81 + Map<String, String> keyReflect = new HashMap<String, String>();
  82 + keyReflect.put("供货价格","goodsMoney");
  83 + keyReflect.put("物料成本","materielFee");
  84 + keyReflect.put("运费","freight");
  85 + keyReflect.put("赠品成本","freeGift");
  86 + keyReflect.put("检测成本","detectPer");
  87 + keyReflect.put("预计件数","preNumber");
  88 + keyReflect.put("产品成本","productCost");
  89 + keyReflect.put("分享金","shareReward");
  90 + keyReflect.put("平台售价","platPrice");
  91 + keyReflect.put("平台优惠券","platCoupon");
  92 + keyReflect.put("平台销售成本","platSaleCost");
  93 + keyReflect.put("平台总成本","platAllCost");
  94 + keyReflect.put("平台毛利","platProfit");
  95 + keyReflect.put("平台毛利率","platProfitRate");
  96 + keyReflect.put("初级分享师返利","primaryShareReward");
  97 + keyReflect.put("高级分享师返利","seniorShareReward");
  98 + keyReflect.put("分享后平台最低毛利率","afterSharePlatLowestProfit");
  99 + keyReflect.put("促销价格","promotPrice");
  100 + keyReflect.put("促销产品成本","promotCost");
  101 + keyReflect.put("促销优惠券","promotCoupon");
  102 + keyReflect.put("促销总成本","promotAllCost");
  103 + keyReflect.put("促销毛利","promotProfit");
  104 + keyReflect.put("促销毛利率","promotProfitRate");
  105 + keyReflect.put("促销初级分享师返利","promotPrimaryShareReward");
  106 + keyReflect.put("促销高级分享师返利","promotSeniorShareReward");
  107 + keyReflect.put("促销分享后平台最低毛利","promotAfterShareLowestProfit");
  108 + keyReflect.put("产销联盟报价","psUionPrice");
  109 + keyReflect.put("产销联盟渠道成本","psUnionChannelCost");
  110 + keyReflect.put("联盟毛利率","psUnionProfitRate");
  111 + keyReflect.put("采购渠道报价","channelPrice");
  112 + keyReflect.put("采购渠道成本","purchaseChannelCost");
  113 + keyReflect.put("采购毛利率","purchaseChannelProfitRate");
  114 + keyReflect.put("代销平台报价","agentPrice");
  115 + keyReflect.put("代销平台成本","agentCost");
  116 + keyReflect.put("代销平台毛利","agentProfit");
  117 + keyReflect.put("试吃供货价格","shichiGoodsMoney");
  118 + keyReflect.put("试吃售价","shichiPrice");
  119 + keyReflect.put("试吃份数","shichiNumber");
  120 + keyReflect.put("试吃成本","shichiCost");
  121 + keyReflect.put("试吃利润","shichiProfit");
  122 + keyReflect.put("积分使用率","integralUseRate");
  123 + keyReflect.put("买手提成","ticheng");
  124 + keyReflect.put("运营提点","operateRate");
  125 + keyReflect.put("初级分享师返点","primaryAgentRate");
  126 + keyReflect.put("高级分享师返点","seniorAgentRate");
  127 + keyReflect.put("渠道拓展提点","channelExpRate");
  128 + keyReflect.put("渠道维护提点","channelProRate");
  129 + keyReflect.put("转账费率","transAccountRate");
  130 + keyReflect.put("损耗","lossRate");
  131 + keyReflect.put("分享金比例","shareRewardRate");
  132 + return keyReflect.get(cnName);
  133 + }
  134 +}
... ...
src/com/taover/db/Constants.java 0 → 100644
  1 +++ a/src/com/taover/db/Constants.java
... ... @@ -0,0 +1,20 @@
  1 +package com.taover.db;
  2 +
  3 +public class Constants {
  4 +
  5 + public static final String LINE = "\r\n";
  6 + public static final String TAB = "\t";
  7 + public static final String NUM_TYPE = "NUMBER";
  8 + public static String[] SCOPES = new String[] { "public", "private", "protected" };
  9 + public static String STATIC = new String("static");
  10 + public static String[] FILE_TYPE = new String[] { "class", "interface" };
  11 + public static String[] SUFFIX = new String[] { "PO", "Dao", "Impl", "DaoImpl" };
  12 + public static String SERIAL = "java.io.Serializable";
  13 + public static String SERIAL_NUM = "private static final long serialVersionUID = 1L;";
  14 + public static String[] KEY_WORD = new String[] { "return", "get", "set", "void", "this." };
  15 + public static String TEMPATE_PATH = "/com/taover/base/template/";
  16 + public static String TEMPATE_DAONAME = "DAOTemplate.ftl";
  17 + public static String TEMPATE_PONAME = "POTemplate.ftl";
  18 + public static String TEMPATE_CREAT_ETABLE_NAME = "createTableTemplate.ftl";
  19 + public static String ISNULL = "= null;";
  20 +}
... ...
src/com/taover/db/GenerateDao.java 0 → 100644
  1 +++ a/src/com/taover/db/GenerateDao.java
... ... @@ -0,0 +1,144 @@
  1 +package com.taover.db;
  2 +
  3 +import java.io.File;
  4 +import java.io.StringWriter;
  5 +import java.util.ArrayList;
  6 +import java.util.LinkedHashMap;
  7 +import java.util.List;
  8 +import java.util.Map;
  9 +import java.util.Vector;
  10 +
  11 +import com.taover.base.template.model.dao.DaoModel;
  12 +import com.taover.base.template.model.dao.FunctionModel;
  13 +import com.taover.tools.StringUtil;
  14 +import freemarker.template.Configuration;
  15 +import freemarker.template.Template;
  16 +
  17 +public class GenerateDao {
  18 +
  19 + public static void table2dao(String filePath,String packagePath, Vector<TableColumn> tableColumns, String dbType) throws Exception {
  20 +
  21 + String sTableName = tableColumns.get(0).getTableName();
  22 + String sTableSchema = tableColumns.get(0).getTableSchema();
  23 + String sJavaBeanName = tableColumns.get(0).getTableBeanUName();
  24 + String packageBeanPath = packagePath + sJavaBeanName.toLowerCase() + ";";
  25 + String sFileName = filePath + sJavaBeanName.toLowerCase() + "";
  26 +
  27 +
  28 + // 生成dao的模板
  29 + DaoModel cif = new DaoModel();
  30 + cif.setPackages(packageBeanPath.toLowerCase());
  31 + cif.setUsers("com.taover");
  32 + cif.setVersion("1.0");
  33 + cif.setBeanName(sJavaBeanName);
  34 + cif.setTableName(sTableName);
  35 + cif.setDbType(dbType);
  36 +
  37 + //设置主键信息
  38 + TableColumn pkcolum = TableColumn.getPKColum(tableColumns);
  39 + cif.setPkBeanName(pkcolum.getColumBeanUName());
  40 + cif.setPkColumName(pkcolum.getColumnName());
  41 + cif.setPkType(pkcolum.getJAVADataType());
  42 +
  43 + //insert select 时的字段列表串
  44 + cif.setColumn_list_str(Tools.getColumnListStr(tableColumns, sTableName));
  45 +
  46 + //设置数据库字段
  47 + cif.setColumnList(Tools.getColums(tableColumns));
  48 + //生成requset to po函数需要的字符串Map
  49 + cif.setReqParameterToPOMap(getReqParameterToPOMap(tableColumns));
  50 +
  51 + // 生成引入
  52 + generateImports(cif, packageBeanPath, sJavaBeanName);
  53 +
  54 + // 生成属性以及get,set方法
  55 + //generateGetSetMethod(cif, sTableSchema);
  56 +
  57 + File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
  58 + Configuration cfg = new Configuration();
  59 + cfg.setDirectoryForTemplateLoading(f);
  60 +
  61 + StringWriter out = new StringWriter();
  62 + Template template = cfg.getTemplate(Constants.TEMPATE_DAONAME, "UTF-8");
  63 + template.process(cif, out);
  64 +
  65 + Tools.createFile(sFileName, sJavaBeanName + "Dao.java", out.toString());
  66 +
  67 + }
  68 +
  69 + public static void generateGetSetMethod(DaoModel cif, String sTableSchema) {
  70 + List<String> paramlist = new ArrayList<String>();
  71 +
  72 +
  73 +
  74 + paramlist.add("@Resource");
  75 + paramlist.add("private JdbcTemplate jdbcegroceryRead;");
  76 + paramlist.add("@Resource");
  77 + paramlist.add("private JdbcTemplate jdbcegroceryWrite;");
  78 + paramlist.add("private Logger logger = Logger.getLogger(this.getClass());");
  79 + List<FunctionModel> functionList = generateGetSetFunction(paramlist);
  80 + cif.setFunlist(functionList);
  81 +
  82 + cif.setPropertys(paramlist);
  83 + }
  84 +
  85 + public static void generateImports(DaoModel cif, String packagebeanpath, String javaBeanName) {
  86 + List<String> importlist = new ArrayList<String>();
  87 + importlist.add("import java.util.*;");
  88 + importlist.add("import org.apache.log4j.Logger;");
  89 + importlist.add("import org.springframework.jdbc.core.JdbcTemplate;");
  90 + importlist.add("import org.springframework.stereotype.Repository;");
  91 + importlist.add("import org.apache.commons.logging.LogFactory;");
  92 + importlist.add("import org.apache.commons.logging.Log;");
  93 + importlist.add("import javax.annotation.Resource;");
  94 +
  95 + importlist.add("import com.taover.tools.JdbcUtil;");
  96 + importlist.add("import com.taover.tools.StringUtil;");
  97 + importlist.add("import com.taover.tools.StringUtils;");
  98 + importlist.add("import com.taover.tools.DAORowMapper;");
  99 + importlist.add("import com.taover.tools.LogUtils;");
  100 + cif.setImports(importlist);
  101 + }
  102 +
  103 + public static List<FunctionModel> generateGetSetFunction(List<String> params) {
  104 + List<FunctionModel> functionList = new ArrayList<FunctionModel>();
  105 + for (int i = 0; i < params.size(); i++) {
  106 + FunctionModel getModel = new FunctionModel();
  107 + FunctionModel setModel = new FunctionModel();
  108 + String[] param = params.get(i).split(" ");
  109 + getModel.setFunction_return(param[1]);
  110 + if (param[2].equalsIgnoreCase("isLogInfo")) {
  111 + getModel.setFunction_name("isLogInfo");
  112 + setModel.setFunction_name(Constants.KEY_WORD[2] + "LogInfo");
  113 + } else {
  114 + getModel.setFunction_name(Constants.KEY_WORD[1] + StringUtil.getFunctionName(param[2]));
  115 + setModel.setFunction_name(Constants.KEY_WORD[2] + StringUtil.getFunctionName(param[2]));
  116 + }
  117 + getModel.setFunction_body(Constants.KEY_WORD[0] + " " + param[2] + ";");
  118 + setModel.setFunction_params(param[1] + " " + param[2]);
  119 + setModel.setFunction_return(Constants.KEY_WORD[3]);
  120 + setModel.setFunction_body(Constants.KEY_WORD[4] + param[2] + " = " + param[2] + ";");
  121 + functionList.add(getModel);
  122 + functionList.add(setModel);
  123 + }
  124 + return functionList;
  125 + }
  126 +
  127 + public static Map<String, String> getReqParameterToPOMap(Vector<TableColumn> tableColumns) {
  128 + Map<String, String> reqParameterToPOMap = new LinkedHashMap<String, String>();
  129 + if (tableColumns == null || tableColumns.size() == 0)
  130 + return reqParameterToPOMap;
  131 + for (int i = 0; i < tableColumns.size(); i++) {
  132 + String sInputName = tableColumns.get(i).getColumBeanLName();
  133 + String sColumBeanName = tableColumns.get(i).getColumBeanUName();
  134 + String poLine =null;
  135 + if(tableColumns.get(i).getDecimalDigits()!=0){
  136 + poLine = sColumBeanName + "((" + tableColumns.get(i).getJAVADataType()+ ") StringUtil.StringToObj((String) map.get(\""+ sInputName + "\"), " + 9999 + "))";
  137 + }else{
  138 + poLine = sColumBeanName + "((" + tableColumns.get(i).getJAVADataType()+ ") StringUtil.StringToObj((String) map.get(\""+ sInputName + "\"), " + tableColumns.get(i).getDataType() + "))";
  139 + }
  140 + reqParameterToPOMap.put(sColumBeanName, poLine);
  141 + }
  142 + return reqParameterToPOMap;
  143 + }
  144 +}
... ...
src/com/taover/db/GenerateDaoPO.java 0 → 100644
  1 +++ a/src/com/taover/db/GenerateDaoPO.java
... ... @@ -0,0 +1,103 @@
  1 +package com.taover.db;
  2 +
  3 +import java.sql.Connection;
  4 +import java.sql.ResultSet;
  5 +import java.sql.SQLException;
  6 +import java.util.ArrayList;
  7 +import java.util.List;
  8 +import java.util.Properties;
  9 +import java.util.Vector;
  10 +
  11 +
  12 +
  13 +
  14 +/*
  15 + * 如果列是自增长;在数据库描述中需要进行如下描述seq|属性描述
  16 + * 不支持联合主键
  17 + * 同时如果有自己的sequence 则命名规则如下:
  18 + * "SEQ_" + TableSchema + "_" + TableName + "_" + ColumnName
  19 + * SEQ_schame_tablename(SEQ_EGROCERY_DEVEL_SS_SKU_SKU_ID)
  20 + *
  21 + */
  22 +
  23 +public class GenerateDaoPO {
  24 +
  25 + public static void main(String[] args) throws Exception{
  26 +
  27 + //读取配置文件
  28 + Properties properties = Tools.getProperties();
  29 + //取数据库连接
  30 + Connection conn = Tools.getConnection(properties);
  31 + //初始化要生成的表列表
  32 + List<String> tableNameList = new ArrayList<String>();
  33 +
  34 + String outputPath = properties.getProperty("OutputPath");
  35 + String schameName = properties.getProperty("SchameName");
  36 + String createSchame = properties.getProperty("CreateSchame");
  37 + String dbLikeStr = properties.getProperty("DBLikeStr");
  38 + String dbType = properties.getProperty("dbtype");
  39 + String dbPackagePath = properties.getProperty("packageName");
  40 + String tableName = properties.getProperty("TableName");
  41 + if("mysql".equalsIgnoreCase(dbType)){
  42 + //schameName = schameName.toUpperCase();
  43 +
  44 + }
  45 +
  46 + if (!dbPackagePath.substring(dbPackagePath.length()-1).equals("."))
  47 + dbPackagePath += ".";
  48 +
  49 + if (createSchame.equalsIgnoreCase("true") || "ALL".equalsIgnoreCase(tableName) ) {
  50 +
  51 + String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+schameName+"'";
  52 + ResultSet rs = Tools.executeQuery(Tools.createStmt(conn), sql);
  53 + if (null == rs)
  54 + return ;
  55 + List<String> result = new ArrayList<String>();
  56 + try {
  57 + while (rs.next()) {
  58 + tableNameList.add(rs.getString("Table_name"));
  59 + }
  60 + } catch (SQLException e) {
  61 + e.printStackTrace();
  62 + result = null;
  63 + }
  64 + Tools.close(rs);
  65 + } else {
  66 + if("mysql".equalsIgnoreCase(dbType)){
  67 +// tableName = tableName.toUpperCase();
  68 + }
  69 + String[] TableNameArr = tableName.split(",");
  70 + for (int i = 0; i < TableNameArr.length; i++)
  71 + tableNameList.add(TableNameArr[i]);
  72 +
  73 + }
  74 +
  75 + for (int i = 0; i < tableNameList.size(); i++) {
  76 +
  77 + String tableNameCurr = (String) tableNameList.get(i);
  78 +
  79 +
  80 + // 取得表中所有列
  81 + Vector<TableColumn> columnsInTable = TableColumn.GetTableInfo(conn, schameName, tableNameCurr, dbLikeStr, dbType);
  82 + if (columnsInTable == null || columnsInTable.size() == 0) {
  83 + System.out.println(tableNameCurr + " : 生成失败,得不到表中列明");
  84 + continue;
  85 + }
  86 + TableColumn pkcolum = TableColumn.getPKColum(columnsInTable);
  87 + if (pkcolum == null) {
  88 + System.out.println(tableNameCurr + " : 生成失败,未设置主键");
  89 + continue;
  90 + }
  91 +
  92 +
  93 + // 生成po类
  94 + GeneratePO.generatePO(outputPath, dbPackagePath, columnsInTable);
  95 + // 生成Dao
  96 + GenerateDao.table2dao(outputPath, dbPackagePath, columnsInTable, dbType);
  97 + System.out.println(tableNameCurr + " : 生成结束");
  98 + }
  99 + conn.close();
  100 + System.out.println("全部结束");
  101 +
  102 + }
  103 +}
... ...
src/com/taover/db/GeneratePO.java 0 → 100644
  1 +++ a/src/com/taover/db/GeneratePO.java
... ... @@ -0,0 +1,89 @@
  1 +package com.taover.db;
  2 +
  3 +import java.io.File;
  4 +import java.io.StringWriter;
  5 +import java.sql.SQLException;
  6 +import java.util.ArrayList;
  7 +import java.util.List;
  8 +import java.util.Vector;
  9 +
  10 +import com.taover.base.template.model.po.ColumnModel;
  11 +import com.taover.base.template.model.po.PoModel;
  12 +import com.taover.base.template.model.po.TableModel;
  13 +
  14 +import com.taover.tools.StringUtil;
  15 +import freemarker.template.Configuration;
  16 +import freemarker.template.Template;
  17 +
  18 +public class GeneratePO {
  19 + public static void generatePO(String sOutputPath, String sDBPackagePath, Vector<TableColumn> ColumnsInTable) throws Exception {
  20 +
  21 + String sJavaBeanName = ColumnsInTable.get(0).getTableBeanUName();
  22 + String sTableName = ColumnsInTable.get(0).getTableName();
  23 + String sPackagePath = sDBPackagePath + ColumnsInTable.get(0).getTableBeanLName();
  24 +
  25 + TableModel tm = CreatePoModel(ColumnsInTable);
  26 + StringWriter out = new StringWriter();
  27 +
  28 + PoModel cif = new PoModel();
  29 + cif.setPackages(sPackagePath.toLowerCase() + ";");
  30 + cif.setUsers("taover.com");
  31 + cif.setVersion("1.0");
  32 + cif.setName(sJavaBeanName);
  33 + cif.setToStringMethodBody(getPOToString(ColumnsInTable));
  34 + cif.setTablemodel(tm);
  35 +
  36 + File f = new File(Tools.getPath() + Constants.TEMPATE_PATH);
  37 + Configuration cfg = new Configuration();
  38 + cfg.setDirectoryForTemplateLoading(f);
  39 + Template template = cfg.getTemplate(Constants.TEMPATE_PONAME);
  40 + template.process(cif, out);
  41 + String filePoPath = sOutputPath + StringUtil.formatBeanNameFirstLow(sTableName);
  42 + Tools.createFile(filePoPath.toLowerCase(), sJavaBeanName + "PO.java", out.toString());
  43 + }
  44 + public static TableModel CreatePoModel(Vector<TableColumn> ColumnsInTable) throws Exception {
  45 + TableModel tm = new TableModel();
  46 + List<ColumnModel> clist = new ArrayList<ColumnModel>();
  47 + int len = ColumnsInTable.size();
  48 + for (int i = 0; i < len; i++) {
  49 + TableColumn colum = ColumnsInTable.get(i);
  50 + ColumnModel cm = new ColumnModel();
  51 + String sColumnBeanName = colum.getColumBeanLName();
  52 + String sSetColumnBeanName = colum.getColumBeanUName();
  53 + cm.setColumnName(sColumnBeanName);
  54 + cm.setColumnMethodName(sSetColumnBeanName);
  55 + cm.setColumnRemarks(colum.getRemarks());
  56 + cm.setColumnJAVAType(colum.getJAVADataType());
  57 + clist.add(cm);
  58 + }
  59 + tm.setColumnlist(clist);
  60 + tm.setTableName(ColumnsInTable.get(0).getTableName());
  61 + return tm;
  62 + }
  63 +
  64 + public static String getPOToString(Vector<TableColumn> ColumnsInTable) throws SQLException {
  65 + StringBuffer returnbuffer = new StringBuffer();
  66 + returnbuffer.append("[");
  67 + int iLen = ColumnsInTable.size() - 1;
  68 + for (int i = 0; i <= iLen; i++) {
  69 + TableColumn colum = ColumnsInTable.get(i);
  70 + String tempName = colum.getColumBeanLName();
  71 + if (i == iLen) {
  72 + if (i == 0) {
  73 + returnbuffer.append(tempName).append("=").append("\"").append("+").append(tempName);
  74 + }else{
  75 + returnbuffer.append("\",").append(tempName).append("=").append("\"").append("+").append(tempName);
  76 + }
  77 +
  78 + } else {
  79 + if (i == 0) {
  80 + returnbuffer.append(tempName).append("=").append("\"").append("+").append(tempName).append("+");
  81 + }else{
  82 + returnbuffer.append("\",").append(tempName).append("=").append("\"").append("+").append(tempName).append("+");
  83 + }
  84 + }
  85 + }
  86 + returnbuffer.append("+\"]\"");
  87 + return returnbuffer.toString();
  88 + }
  89 +}
... ...
src/com/taover/db/TableColumn.java 0 → 100644
  1 +++ a/src/com/taover/db/TableColumn.java
... ... @@ -0,0 +1,491 @@
  1 +package com.taover.db;
  2 +
  3 +import java.sql.Connection;
  4 +import java.sql.DatabaseMetaData;
  5 +import java.sql.ResultSet;
  6 +import java.sql.SQLException;
  7 +import java.util.Vector;
  8 +
  9 +
  10 +
  11 +import com.taover.tools.StringUtil;
  12 +
  13 +public class TableColumn {
  14 +
  15 +
  16 + protected String tableCatalog;
  17 + protected String tableSchema;
  18 + protected String tableName;
  19 + protected String columnName;
  20 + protected int dataType;
  21 + protected String typeName;
  22 + protected int columnSize;
  23 + protected int bufferLength;
  24 + protected int decimalDigits;
  25 + protected int numPrecRadix;
  26 + protected boolean nullable;
  27 + protected String remarks;
  28 + protected String columnDefaults;//LONG
  29 + protected int sqlDataType;
  30 + protected int sqlDatatimeSubject;
  31 + protected int charOctetLength;
  32 + protected int ordinalPosition;
  33 + protected String is_nullable;
  34 +
  35 + //for mysql
  36 + protected String scopeCatalog;
  37 + protected String scopeSchema;
  38 + protected String scopeTable;
  39 + protected int sourceDataType;
  40 + protected String isAutoIncrement;
  41 +
  42 + protected String seqName;
  43 + protected boolean primaryKey;
  44 + protected String dic;
  45 +
  46 +
  47 + public String getTableCatalog() {
  48 + return tableCatalog;
  49 + }
  50 + public void setTableCatalog(String tableCatalog) {
  51 + this.tableCatalog = tableCatalog;
  52 + }
  53 + public String getTableSchema() {
  54 + return tableSchema;
  55 + }
  56 + public void setTableSchema(String tableSchema) {
  57 + this.tableSchema = tableSchema;
  58 + }
  59 + public String getTableName() {
  60 + return tableName;
  61 + }
  62 + public void setTableName(String tableName) {
  63 + this.tableName = tableName;
  64 + }
  65 + public String getColumnName() {
  66 + return columnName;
  67 + }
  68 + public void setColumnName(String columnName) {
  69 + this.columnName = columnName;
  70 + }
  71 + public int getDataType() {
  72 + return dataType;
  73 + }
  74 + public String getTypeName() {
  75 + return typeName;
  76 + }
  77 + public void setTypeName(String typeName) {
  78 + this.typeName = typeName;
  79 + }
  80 + public int getColumnSize() {
  81 + return columnSize;
  82 + }
  83 + public void setColumnSize(int columnSize) {
  84 + this.columnSize = columnSize;
  85 + }
  86 + public int getBufferLength() {
  87 + return bufferLength;
  88 + }
  89 + public void setBufferLength(int bufferLength) {
  90 + this.bufferLength = bufferLength;
  91 + }
  92 + public int getDecimalDigits() {
  93 + return decimalDigits;
  94 + }
  95 + public void setDecimalDigits(int decimalDigits) {
  96 + this.decimalDigits = decimalDigits;
  97 + }
  98 + public int getNumPrecRadix() {
  99 + return numPrecRadix;
  100 + }
  101 + public void setNumPrecRadix(int numPrecRadix) {
  102 + this.numPrecRadix = numPrecRadix;
  103 + }
  104 + public boolean isNullable() {
  105 + return nullable;
  106 + }
  107 + public void setNullable(boolean nullable) {
  108 + this.nullable = nullable;
  109 + }
  110 + public String getRemarks() {
  111 + return remarks;
  112 + }
  113 + public void setRemarks(String remarks) {
  114 + if (remarks == null || remarks.isEmpty() || remarks.equalsIgnoreCase("null"))
  115 + this.remarks = "";
  116 + else {
  117 + remarks.trim();
  118 + remarks = remarks.replaceAll("\\r", "");
  119 + remarks = remarks.replaceAll("\\n", "");
  120 + this.remarks = remarks;
  121 + }
  122 + }
  123 + public String getColumnDefaults() {
  124 + return columnDefaults;
  125 + }
  126 + public void setColumnDefaults(String columnDefaults) {
  127 + if (columnDefaults == null || columnDefaults.isEmpty() || columnDefaults.equalsIgnoreCase("null"))
  128 + this.columnDefaults = "";
  129 + else {
  130 + columnDefaults.trim();
  131 + columnDefaults = columnDefaults.replaceAll("\\r", "");
  132 + columnDefaults = columnDefaults.replaceAll("\\n", "");
  133 + this.columnDefaults = columnDefaults;
  134 + }
  135 + }
  136 + public int getSqlDataType() {
  137 + return sqlDataType;
  138 + }
  139 + public void setSqlDataType(int sqlDataType) {
  140 + this.sqlDataType = sqlDataType;
  141 + }
  142 + public int getSqlDatatimeSubject() {
  143 + return sqlDatatimeSubject;
  144 + }
  145 + public void setSqlDatatimeSubject(int sqlDatatimeSubject) {
  146 + this.sqlDatatimeSubject = sqlDatatimeSubject;
  147 + }
  148 + public int getCharOctetLength() {
  149 + return charOctetLength;
  150 + }
  151 + public void setCharOctetLength(int charOctetLength) {
  152 + this.charOctetLength = charOctetLength;
  153 + }
  154 + public int getOrdinalPosition() {
  155 + return ordinalPosition;
  156 + }
  157 + public void setOrdinalPosition(int ordinalPosition) {
  158 + this.ordinalPosition = ordinalPosition;
  159 + }
  160 + public String getIs_nullable() {
  161 + return is_nullable;
  162 + }
  163 + public void setIs_nullable(String is_nullable) {
  164 + this.is_nullable = is_nullable;
  165 + }
  166 + public String getSeqName() {
  167 + return seqName;
  168 + }
  169 + public void setSeqName(String seqName) {
  170 + this.seqName = seqName;
  171 + }
  172 + public boolean isPrimaryKey() {
  173 + return primaryKey;
  174 + }
  175 + public void setPrimaryKey(boolean primaryKey) {
  176 + this.primaryKey = primaryKey;
  177 + }
  178 + public String getDic() {
  179 + return dic;
  180 + }
  181 +
  182 + public void setDic(String dic) {
  183 + this.dic = dic;
  184 + }
  185 +
  186 + public String getScopeCatalog() {
  187 + return scopeCatalog;
  188 + }
  189 + public void setScopeCatalog(String scopeCatalog) {
  190 + this.scopeCatalog = scopeCatalog;
  191 + }
  192 + public String getScopeSchema() {
  193 + return scopeSchema;
  194 + }
  195 + public void setScopeSchema(String scopeSchema) {
  196 + this.scopeSchema = scopeSchema;
  197 + }
  198 + public String getScopeTable() {
  199 + return scopeTable;
  200 + }
  201 + public void setScopeTable(String scopeTable) {
  202 + this.scopeTable = scopeTable;
  203 + }
  204 + public int getSourceDataType() {
  205 + return sourceDataType;
  206 + }
  207 + public void setSourceDataType(int sourceDataType) {
  208 + this.sourceDataType = sourceDataType;
  209 + }
  210 + public String getIsAutoIncrement() {
  211 + return isAutoIncrement;
  212 + }
  213 + public void setIsAutoIncrement(String isAutoIncrement) {
  214 + this.isAutoIncrement = isAutoIncrement;
  215 + }
  216 +
  217 + public void setPrimaryKey(String sPKColumName) throws SQLException {
  218 + if (sPKColumName.equalsIgnoreCase(columnName))
  219 + primaryKey = true;
  220 + }
  221 +
  222 + public void setPrimaryKey(int primarykey) {
  223 + if (primarykey != 0)
  224 + this.primaryKey = true;
  225 + else
  226 + this.primaryKey = false;
  227 + }
  228 +
  229 + public void setPrimaryKey(ResultSet rs) throws SQLException {
  230 + String columnname = rs.getString("COLUMN_NAME").trim();
  231 + if (columnname.equalsIgnoreCase(this.columnName))
  232 + this.primaryKey = true;
  233 + }
  234 +
  235 + public String toString() {
  236 + return "tableCatalog=" + tableCatalog + ","
  237 + + "tableSchema=" + tableSchema + ","
  238 + + "tableName=" + tableName + ","
  239 + + "columnName=" + columnName + ","
  240 + + "dataType=" + dataType + ","
  241 + + "typeName=" + typeName + ";,"
  242 + + "columnSize=" + columnSize + ","
  243 + + "bufferLength=" + bufferLength + ","
  244 + + "decimalDigits=" + decimalDigits + ","
  245 + + "numPrecRadix=" + numPrecRadix + ","
  246 + + "nullable=" + nullable + ","
  247 + + "remarks=" + remarks + ","
  248 + + "columnDefaults=" + columnDefaults + ","
  249 + + "sqlDataType=" + sqlDataType + ","
  250 + + "sqlDatatimeSubject=" + sqlDatatimeSubject + ","
  251 + + "charOctetLength=" + charOctetLength + ","
  252 + + "ordinalPosition=" + ordinalPosition + ","
  253 + + "Is_Nullable=" + is_nullable + ","
  254 + + "seq=" + seqName + ","
  255 + + "PrimaryKey=" + primaryKey + ","
  256 + + "dic=" + dic;
  257 + }
  258 +
  259 + public TableColumn() {
  260 + setTableCatalog("");
  261 + setTableSchema("");
  262 + setTableName("");
  263 + setColumnName("");
  264 + setDataType(0);
  265 + setTypeName("");
  266 + setColumnSize(0);
  267 + setBufferLength(0);
  268 + setDecimalDigits(0);
  269 + setNumPrecRadix(0);
  270 + setNullable(false);
  271 + setColumnDefaults("");
  272 + setSqlDataType(0);
  273 + setSqlDatatimeSubject(0);
  274 + setCharOctetLength(0);
  275 + setOrdinalPosition(0);
  276 + setIs_nullable("");
  277 +
  278 +
  279 + setSeqName("");
  280 + setPrimaryKey(false);
  281 + setDic("");
  282 + }
  283 +
  284 + public TableColumn(ResultSet rs, String dbType) throws SQLException {
  285 +
  286 + setTableCatalog(rs.getString("TABLE_CAT"));
  287 + setTableSchema(rs.getString("TABLE_SCHEM"));
  288 + if (getTableSchema() == null && dbType.equalsIgnoreCase("mysql"))
  289 + setTableSchema(getTableCatalog());
  290 + setTableName(rs.getString("TABLE_NAME").trim());
  291 + setColumnName(rs.getString("COLUMN_NAME").trim());
  292 + //setColumnSize 一定要在DataType之前,否则会影响返回的JAVA类型
  293 + setColumnSize(rs.getInt("COLUMN_SIZE"));
  294 + setTypeName(rs.getString("TYPE_NAME").trim());
  295 + setDecimalDigits(rs.getInt("DECIMAL_DIGITS"));
  296 + setDataType(rs.getInt("DATA_TYPE"));
  297 + setBufferLength(rs.getInt("BUFFER_LENGTH"));
  298 + setNumPrecRadix(rs.getInt("NUM_PREC_RADIX"));
  299 + setNullable(rs.getBoolean("NULLABLE"));
  300 + setColumnDefaults(rs.getString("COLUMN_DEF"));
  301 + setSqlDataType(rs.getInt("SQL_DATA_TYPE"));
  302 + setSqlDatatimeSubject(rs.getInt("SQL_DATETIME_SUB"));
  303 + setCharOctetLength(rs.getInt("CHAR_OCTET_LENGTH"));
  304 + setOrdinalPosition(rs.getInt("ORDINAL_POSITION"));
  305 + setIs_nullable(rs.getString("IS_NULLABLE"));
  306 + setRemarks(rs.getString("REMARKS"));
  307 +
  308 + if (dbType.equalsIgnoreCase("mysql")) {
  309 + setScopeCatalog(rs.getString("SCOPE_CATALOG"));
  310 + setScopeSchema(rs.getString("SCOPE_SCHEMA"));
  311 + setScopeTable(rs.getString("SCOPE_TABLE"));
  312 + setSourceDataType(rs.getInt("SOURCE_DATA_TYPE"));
  313 + setIsAutoIncrement(rs.getString("IS_AUTOINCREMENT"));
  314 + }
  315 + if (null != remarks && !remarks.isEmpty()) {
  316 + int iStartPos = remarks.indexOf("seq");
  317 + int iSplitPos = remarks.indexOf("|");
  318 + // 存在seq 设置
  319 + if (iStartPos >= 0 && iSplitPos >0) {
  320 + String seq_setting = remarks.substring(iStartPos);
  321 + int iEndPos = seq_setting.indexOf("|", iStartPos);
  322 + String rem = remarks.substring(0, iStartPos);
  323 + if (iEndPos >= 0) {
  324 + seq_setting = seq_setting.substring(0, iEndPos);
  325 + rem += remarks.substring(iEndPos + 1);
  326 + }
  327 + //setRemarks(rem);
  328 + String arr[] = seq_setting.split("=");
  329 +
  330 + if (arr.length == 2) {
  331 + setSeqName(arr[1]);
  332 + } else {
  333 + setSeqName("SEQ_" + getTableSchema() + "_" + getTableName() + "_" + getColumnName());
  334 + }
  335 + }
  336 + } else {
  337 + //setRemarks(this.columnName);
  338 + }
  339 + }
  340 +
  341 + public void setDataType(int datatype) {
  342 + this.dataType = datatype;
  343 + //orcale 下, 91同93
  344 +// if ((datatype == 91))
  345 +// this.dataType = 93;
  346 + if ((datatype == 1111) && getTypeName().length()>=9&&(getTypeName().substring(0, 9).equalsIgnoreCase("TIMESTAMP")))
  347 + this.dataType = 93;
  348 +
  349 + if (((datatype == 2) || (datatype == 3)) && (this.decimalDigits == 0)) {
  350 + if (this.columnSize < 3) {
  351 + this.dataType = -6;
  352 + } else if (this.columnSize < 5) {
  353 + this.dataType = 5;
  354 + } else if (this.columnSize < 11)
  355 + this.dataType = 4;
  356 + else
  357 + this.dataType = -5;
  358 + }
  359 + }
  360 +
  361 + public String getJAVADataType() {
  362 + switch (this.dataType) {
  363 + case -101:
  364 + return "oracle.sql.TIMESTAMPTZ";
  365 + case -102:
  366 + return "oracle.sql.TIMESTAMPLTZ";
  367 + case -7:
  368 + return "Boolean";
  369 + case -6:
  370 + return "Byte";
  371 + case -5:
  372 + return "Long";
  373 + case -4:
  374 + case -3:
  375 + case -2:
  376 + return "byte[]";
  377 + case -1:
  378 + return "String";
  379 + case 1:
  380 + return "String";
  381 + case 2:
  382 + case 3:
  383 + if (this.decimalDigits != 0) {
  384 + return "java.math.BigDecimal";
  385 + }
  386 + return "Long";
  387 + case 4:
  388 + return "Integer";
  389 + case 5:
  390 + return "Short";
  391 + case 6:
  392 + return "Float";
  393 + case 7:
  394 + case 8:
  395 + return "Double";
  396 + case 12:
  397 + return "String";
  398 + case 91:
  399 + return "java.util.Date";
  400 + case 92:
  401 + return "java.sql.Time";
  402 + case 93:
  403 + return "java.sql.Timestamp";
  404 + case 1111:
  405 + case 2004:
  406 + case 2005:
  407 + return "String";
  408 + }
  409 + return "";
  410 + }
  411 +
  412 + public String getTableBeanUName() {
  413 + return StringUtil.formatBeanNameFirstUpper(getTableName());
  414 + }
  415 +
  416 + public String getTableBeanLName() {
  417 + return StringUtil.formatBeanNameFirstLow(getTableName());
  418 + }
  419 +
  420 + public String getColumBeanUName() {
  421 + return StringUtil.formatBeanNameFirstUpper(this.columnName);
  422 + }
  423 +
  424 + public String getColumBeanLName() {
  425 + return StringUtil.formatBeanNameFirstLow(this.columnName);
  426 + }
  427 +
  428 + public static Vector<TableColumn> GetTableInfo(Connection Conn, String schameName, String sTableName, String likeStr, String dbType) {
  429 +
  430 + Vector<TableColumn> ColumnsInTable = new Vector<TableColumn>();
  431 + try {
  432 +
  433 + DatabaseMetaData dbmd = Conn.getMetaData();
  434 + ResultSet rs = dbmd.getColumns(null, schameName, sTableName, likeStr);
  435 + if (rs == null) {
  436 + System.out.println("The Result Set is null ");
  437 + return null;
  438 + }
  439 + while (rs.next()) {
  440 + TableColumn tableColumns = new TableColumn(rs, dbType);
  441 + ColumnsInTable.addElement(tableColumns);
  442 + }
  443 + setPrimaryKey(Conn, likeStr, ColumnsInTable);
  444 + rs.close();
  445 + } catch (Exception e) {
  446 + e.printStackTrace();
  447 + }
  448 + return ColumnsInTable;
  449 + }
  450 +
  451 + public static void setPrimaryKey (Connection Conn, String likeStr, Vector<TableColumn> Colums) {
  452 +
  453 + try {
  454 + DatabaseMetaData dbmd = Conn.getMetaData();
  455 + if (Colums == null || Colums.size() < 0)
  456 + return;
  457 + ResultSet rs = dbmd.getPrimaryKeys(Colums.get(0).getTableCatalog(), Colums.get(0).getTableSchema(), Colums.get(0).getTableName());
  458 + while (rs.next()) {
  459 + String sPKColumName = rs.getString("COLUMN_NAME").trim();
  460 + for (int i = 0; i < Colums.size(); i++) {
  461 + TableColumn tc = Colums.get(i);
  462 + tc.setPrimaryKey(sPKColumName);
  463 + }
  464 + }
  465 + rs.close();
  466 + }
  467 + catch (SQLException e) {
  468 + e.printStackTrace();
  469 + }
  470 + return;
  471 + }
  472 +
  473 + public static TableColumn getPKColum(Vector<TableColumn> Colums) {
  474 + if (Colums == null || Colums.size() == 0)
  475 + return null;
  476 + for (int i = 0; i < Colums.size(); i++) {
  477 + if (Colums.get(i).isPrimaryKey()) {
  478 + return Colums.get(i);
  479 + }
  480 + }
  481 + return null;
  482 + }
  483 +
  484 + public static TableColumn getColumFromListByName(Vector<TableColumn> ColumList, String sColumnName) {
  485 + for (int i = 0; ColumList != null && i < ColumList.size(); i++) {
  486 + if (ColumList.get(i).getColumnName().equalsIgnoreCase(sColumnName))
  487 + return ColumList.get(i);
  488 + }
  489 + return null;
  490 + }
  491 +}
0 492 \ No newline at end of file
... ...
src/com/taover/db/Tools.java 0 → 100644
  1 +++ a/src/com/taover/db/Tools.java
... ... @@ -0,0 +1,287 @@
  1 +package com.taover.db;
  2 +
  3 +import java.io.File;
  4 +import java.io.FileInputStream;
  5 +import java.io.FileNotFoundException;
  6 +import java.io.FileOutputStream;
  7 +import java.io.IOException;
  8 +import java.io.InputStream;
  9 +import java.io.PrintStream;
  10 +import java.sql.Connection;
  11 +import java.sql.DriverManager;
  12 +import java.sql.PreparedStatement;
  13 +import java.sql.ResultSet;
  14 +import java.sql.SQLException;
  15 +import java.sql.Statement;
  16 +import java.util.ArrayList;
  17 +import java.util.List;
  18 +import java.util.Properties;
  19 +import java.util.StringTokenizer;
  20 +import java.util.Vector;
  21 +
  22 +import com.taover.db.GenerateDaoPO;
  23 +
  24 +import com.taover.base.template.model.po.ColumnModel;
  25 +import com.taover.tools.StringUtil;
  26 +
  27 +public class Tools {
  28 +
  29 + private static String path = null;
  30 + private static String resourcesPath = null;
  31 +
  32 + public static Connection getConnection(Properties properties) {
  33 + Connection conn = null;
  34 + try {
  35 + Class.forName(properties.getProperty("driver"));
  36 + Properties prop = new Properties();
  37 + prop.setProperty("user", properties.getProperty("User"));
  38 + prop.setProperty("password", properties.getProperty("Password"));
  39 + prop.setProperty("remarks", "true");
  40 + conn = DriverManager.getConnection(properties.getProperty("URL"),
  41 + prop);
  42 + } catch (Exception e) {
  43 + e.printStackTrace();
  44 + }
  45 + return conn;
  46 + }
  47 +
  48 + public static String getPath() {
  49 +
  50 + //兼容传入path使用
  51 + if(path != null){
  52 + return path;
  53 + }
  54 +
  55 + GenerateDaoPO td = null;
  56 + String str = null;
  57 + try {
  58 + td = new GenerateDaoPO();
  59 + str = System.getProperty("user.dir") + File.separator + "bin";
  60 + } catch (Exception e) {
  61 + str = ".";
  62 + e.printStackTrace();
  63 + }
  64 + return str;
  65 +
  66 +
  67 + }
  68 +
  69 + public static String getResourcesPath() {
  70 + return resourcesPath;
  71 +
  72 + }
  73 + public static void setResourcesPath(String resourcesPath) {
  74 + Tools.resourcesPath = resourcesPath;
  75 + }
  76 +
  77 + public static void setPath(String path) {
  78 + Tools.path = path;
  79 + }
  80 +
  81 + public static Properties getProperties(String propertiesName) {
  82 + Properties properties = null;
  83 + try {
  84 + properties = new Properties();
  85 + InputStream inputStream = new FileInputStream(getResourcesPath() +File.separator +propertiesName + ".properties");
  86 + properties.load(inputStream);
  87 + inputStream.close();
  88 + } catch (Exception e) {
  89 + properties = null;
  90 + e.printStackTrace();
  91 + }
  92 + return properties;
  93 + }
  94 +
  95 + public static Properties getProperties() {
  96 + Properties properties = null;
  97 + try {
  98 + properties = new Properties();
  99 + InputStream inputStream = new FileInputStream(getPath() +File.separator
  100 + + "default.properties");
  101 + properties.load(inputStream);
  102 + inputStream.close();
  103 + } catch (Exception e) {
  104 + properties = null;
  105 + e.printStackTrace();
  106 + }
  107 + return properties;
  108 + }
  109 + public static Properties getProductProperties() {
  110 + Properties properties = null;
  111 + try {
  112 + properties = new Properties();
  113 + InputStream inputStream = new FileInputStream(getPath()+File.separator
  114 + + "product.properties");
  115 + properties.load(inputStream);
  116 + inputStream.close();
  117 + } catch (Exception e) {
  118 + properties = null;
  119 + e.printStackTrace();
  120 + }
  121 + return properties;
  122 + }
  123 +
  124 + public static String getColumnListStr(Vector<TableColumn> tableColumns,
  125 + String tableName) throws SQLException {
  126 + StringBuffer sb = new StringBuffer();
  127 + for (int i = 0; i < tableColumns.size(); i++) {
  128 + if (i == tableColumns.size() - 1) {
  129 + sb.append(tableColumns.get(i).getColumnName());
  130 + break;
  131 + }
  132 + if (tableColumns.get(i).getColumnName().equals("check")) {
  133 + sb.append("\\\"" + tableColumns.get(i).getColumnName()
  134 + + "\\\", ");
  135 + } else {
  136 + sb.append(tableColumns.get(i).getColumnName() + ", ");
  137 + }
  138 + }
  139 + return sb.toString();
  140 + }
  141 +
  142 + public static List<ColumnModel> getColums(Vector<TableColumn> tableColumns) {
  143 + if (tableColumns == null || tableColumns.size() == 0)
  144 + return null;
  145 + List<ColumnModel> list = new ArrayList<ColumnModel>();
  146 + for (int i = 0; i < tableColumns.size(); i++) {
  147 + String sColumnDBName = tableColumns.get(i).getColumnName();
  148 + String sColumnBeanName = StringUtil.formatBeanNameFirstLow(sColumnDBName);
  149 + ColumnModel cm = new ColumnModel();
  150 + cm.setColumnName(sColumnDBName);
  151 + cm.setColumnMethodName(sColumnBeanName);
  152 + cm.setColumnRemarks(tableColumns.get(i).getRemarks());
  153 + cm.setColumnUName(StringUtil
  154 + .formatBeanNameFirstUpper(sColumnDBName));
  155 + String seq = tableColumns.get(i).getSeqName();
  156 + if (seq != null && !seq.isEmpty()) {
  157 + cm.setSeqName(seq);
  158 + }
  159 + cm.setColumnJAVAType(tableColumns.get(i).getJAVADataType());
  160 + list.add(cm);
  161 + }
  162 + return list;
  163 + }
  164 +
  165 + public static void createFile(String path, String filename, String incontent)
  166 + throws IOException {
  167 + java.io.File file = new java.io.File(path + File.separator + filename);
  168 + createFile(path);
  169 + if (file.exists() && file.isFile())
  170 + file.delete();
  171 + if (!file.exists())
  172 + file.createNewFile();
  173 +
  174 + try {
  175 + FileOutputStream out = new FileOutputStream(path + File.separator+ filename);
  176 + PrintStream p = new PrintStream(out);
  177 + p.println(incontent);
  178 + out.close();
  179 + p.close();
  180 + } catch (FileNotFoundException e) {
  181 + e.printStackTrace();
  182 + }
  183 +
  184 + }
  185 +
  186 + public static void createFile(String path) {
  187 + File tempFile = new File(path);
  188 + tempFile.mkdirs();
  189 +
  190 +
  191 + /*StringTokenizer st = new StringTokenizer(path, File.separator);
  192 + String path1 = st.nextToken() + File.separator;
  193 + String path2 = path1;
  194 + while (st.hasMoreTokens()) {
  195 + path1 = st.nextToken() + File.separator;
  196 + path2 += path1;
  197 + File inbox = new File(path2);
  198 + if (!inbox.exists())
  199 + inbox.mkdir();
  200 + }*/
  201 + }
  202 +
  203 + public static Statement createStmt(Connection conn) {
  204 + Statement stmt = null;
  205 + try {
  206 + stmt = conn.createStatement();
  207 + } catch (SQLException e) {
  208 + e.printStackTrace();
  209 + }
  210 + return stmt;
  211 + }
  212 +
  213 + public static int executeUpdate(Connection conn, String sql) {
  214 + Statement stmt = null;
  215 + int ret = 0;
  216 + try {
  217 + stmt = conn.createStatement();
  218 + ret = stmt.executeUpdate(sql);
  219 + } catch (SQLException e) {
  220 + e.printStackTrace();
  221 + }
  222 + return ret;
  223 + }
  224 +
  225 + public static PreparedStatement prepareStmt(Connection conn, String sql) {
  226 + PreparedStatement pStmt = null;
  227 + try{
  228 + pStmt = conn.prepareStatement(sql);
  229 + } catch (SQLException e) {
  230 + e.printStackTrace();
  231 + }
  232 + return pStmt;
  233 + }
  234 +
  235 + public static PreparedStatement prepareStmt(Connection conn, String sql, int autoGeneratedKeys) {
  236 + PreparedStatement pStmt = null;
  237 + try{
  238 + pStmt = conn.prepareStatement(sql, autoGeneratedKeys);
  239 + } catch (SQLException e) {
  240 + e.printStackTrace();
  241 + }
  242 + return pStmt;
  243 + }
  244 +
  245 + public static ResultSet executeQuery(Statement stmt, String sql) {
  246 + ResultSet rs = null;
  247 + try {
  248 + rs = stmt.executeQuery(sql);
  249 + } catch (SQLException e) {
  250 + e.printStackTrace();
  251 + }
  252 + return rs;
  253 + }
  254 +
  255 + public static void close(Connection conn) {
  256 + if(conn != null) {
  257 + try {
  258 + conn.close();
  259 + } catch (SQLException e) {
  260 + e.printStackTrace();
  261 + }
  262 + conn = null;
  263 + }
  264 + }
  265 +
  266 + public static void close(Statement stmt) {
  267 + if(stmt != null) {
  268 + try {
  269 + stmt.close();
  270 + } catch (SQLException e) {
  271 + e.printStackTrace();
  272 + }
  273 + stmt = null;
  274 + }
  275 + }
  276 +
  277 + public static void close(ResultSet rs) {
  278 + if(rs != null) {
  279 + try {
  280 + rs.close();
  281 + } catch (SQLException e) {
  282 + e.printStackTrace();
  283 + }
  284 + rs = null;
  285 + }
  286 + }
  287 +}
... ...
src/com/taover/tools/StringUtil.java 0 → 100644
  1 +++ a/src/com/taover/tools/StringUtil.java
... ... @@ -0,0 +1,565 @@
  1 +package com.taover.tools;
  2 +
  3 +import java.io.File;
  4 +import java.lang.reflect.Field;
  5 +import java.lang.reflect.Method;
  6 +import java.math.BigDecimal;
  7 +import java.text.DateFormat;
  8 +import java.text.ParseException;
  9 +import java.text.ParsePosition;
  10 +import java.text.SimpleDateFormat;
  11 +import java.util.ArrayList;
  12 +import java.util.Arrays;
  13 +import java.util.Calendar;
  14 +import java.util.Date;
  15 +import java.util.List;
  16 +import java.util.Locale;
  17 +import java.util.Random;
  18 +import java.util.regex.Matcher;
  19 +import java.util.regex.Pattern;
  20 +
  21 +
  22 +public class StringUtil {
  23 +
  24 + public static int strToInt(String s, int def) {
  25 + try {
  26 + return Integer.parseInt(s);
  27 + } catch (Exception e) {
  28 + return def;
  29 + }
  30 + }
  31 +
  32 + public static String getFunctionName(String paramName) {
  33 + String functionName = null;
  34 +
  35 + if (paramName.length() > 1) {
  36 + functionName = paramName.substring(0, 1).toUpperCase()
  37 + + paramName.substring(1, paramName.length());
  38 + } else {
  39 + functionName = paramName.toUpperCase();
  40 +
  41 + }
  42 + return functionName;
  43 + }
  44 +
  45 + public static Date StringToDate(String sDate, String sFormat) throws ParseException {
  46 + SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
  47 + return sdf.parse(sDate);
  48 + }
  49 +
  50 + public static java.sql.Timestamp StringToTimestamp(String sDate, String sFormat) throws ParseException {
  51 + SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
  52 + Date t = sdf.parse(sDate);
  53 + return new java.sql.Timestamp(t.getTime());
  54 +
  55 + }
  56 +
  57 + public static Object StringToObj(String s, int type) {
  58 + try {
  59 + switch (type) {
  60 + case -7:
  61 + return Boolean.parseBoolean(s);
  62 + case -6:
  63 + return Byte.parseByte(s);
  64 + case 5:
  65 + return Short.parseShort(s);
  66 + case 4:
  67 + return Integer.parseInt(s);
  68 + case -5:
  69 + return Long.parseLong(s);
  70 + case 6:
  71 + return Float.parseFloat(s);
  72 + case 7:
  73 + case 8:
  74 + return Double.parseDouble(s);
  75 + case 2:
  76 + case 3:
  77 + return Integer.parseInt(s);
  78 + case 91:
  79 + return StringToDate(s, "yyyy-MM-dd HH:mm:ss");
  80 + case 92:
  81 + case 93:
  82 + return StringToTimestamp(s, "yyyy-MM-dd HH:mm:ss");
  83 + case 100:
  84 + return StringToTimestamp(s+" 00:00:00", "yyyy-MM-dd HH:mm:ss");
  85 + case 101:
  86 + return StringToTimestamp(s+" 23:59:59", "yyyy-MM-dd HH:mm:ss");
  87 + case 9999:
  88 + return new BigDecimal(s);
  89 + default:
  90 + return s;
  91 + }
  92 +
  93 + } catch (Exception e) {
  94 + return null;
  95 + }
  96 + }
  97 +
  98 + public static String getJavaType(int type, int scale) {
  99 + String javaType = "";
  100 + switch (type) {
  101 + case -7:
  102 + javaType = "Boolean";
  103 + case -6:
  104 + // return "byte";
  105 + javaType = "java.sql.Blob";
  106 + case 5:
  107 + // return "short";
  108 + javaType = "java.math.BigDecimal";
  109 + case 4:
  110 + // return "integer";
  111 + javaType = "Integer";
  112 + case -5:
  113 + // return "long";
  114 + javaType = "Long";
  115 + case 6:
  116 + // return "float";
  117 + javaType = "java.math.BigDecimal";
  118 + case 7:
  119 + case 8:
  120 + // return "double";
  121 + javaType = "java.math.BigDecimal";
  122 + break;
  123 + case 2:
  124 + case 3:
  125 + // if (this.decimalDigits != 0) {
  126 + // return "double";
  127 + // }
  128 + // return "long";
  129 + if (scale != 0) {
  130 + javaType = "java.math.BigDecimal";
  131 + } else {
  132 + javaType = "Integer";
  133 + }
  134 + break;
  135 + case 91:
  136 + case 92:
  137 + case 93:
  138 + // return "date";
  139 + javaType = "java.util.Date";
  140 + break;
  141 + default:
  142 + javaType = "String";
  143 +
  144 + }
  145 + return javaType;
  146 + }
  147 +
  148 + public static Date strToFormatDate(String date, String format) {
  149 + if (date == null) return null;
  150 + SimpleDateFormat sdf = new SimpleDateFormat(format);
  151 + return sdf.parse(date, new ParsePosition(0));
  152 + }
  153 +
  154 + /**
  155 + * 将字符串转换为yyyy-MM-dd格式的日期
  156 + *
  157 + * @param date
  158 + * @return 转换后的日期对象
  159 + */
  160 + public static Date strToDate(String date) {
  161 + return StringUtil.strToFormatDate(date, "yyyy-MM-dd");
  162 + }
  163 +
  164 + /**
  165 + * 将字符串转换为yyyy-MM-dd HH:mm:ss格式的日期
  166 + *
  167 + * @param date
  168 + * @return 转换后的日期对象
  169 + */
  170 + public static Date strToDateTime(String date) {
  171 + return StringUtil.strToFormatDate(date, "yyyy-MM-dd HH:mm:ss");
  172 + }
  173 +
  174 + /**
  175 + * 将date型日期转换成特定格式的时间字符串
  176 + *
  177 + * @param date
  178 + * @param format
  179 + * @return 转换后的日期对象
  180 + */
  181 + public static String dateToFormatStr(Date date, String format) {
  182 + if (date == null) return null;
  183 + SimpleDateFormat sdf = new SimpleDateFormat(format);
  184 + return sdf.format(date);
  185 + }
  186 +
  187 + /**
  188 + * 将date型日期转换成yyyy-MM-dd HH:mm:ss格式的时间字符串
  189 + *
  190 + * @param date
  191 + * 日期
  192 + * @return 返回yyyy-MM-dd HH:mm格式的时间字符串
  193 + */
  194 + public static String dateTimeToStr(Date date) {
  195 + return StringUtil.dateToFormatStr(date, "yyyy-MM-dd HH:mm:ss");
  196 + }
  197 +
  198 + /**
  199 + * 将date型日期转换成yyyy-MM-dd格式的日期字符串
  200 + *
  201 + * @param date
  202 + * 日期
  203 + * @return 返回yyyy-MM-dd格式的日期字符串
  204 + */
  205 + public static String dateToStr(Date date) {
  206 + return StringUtil.dateToFormatStr(date, "yyyy-MM-dd");
  207 + }
  208 +
  209 + /**
  210 + * 计算出date day天之前或之后的日期
  211 + *
  212 + * @param date
  213 + * {@link Date} 日期
  214 + * @param days
  215 + * int 天数,正数为向后几天,负数为向前几天
  216 + * @return 返回Date日期类型
  217 + */
  218 + public static Date getDateBeforeOrAfterDays(Date date, int days) {
  219 + Calendar now = Calendar.getInstance();
  220 + now.setTime(date);
  221 + now.set(Calendar.DATE, now.get(Calendar.DATE) + days);
  222 + return now.getTime();
  223 + }
  224 +
  225 + /**
  226 + * 计算出date monthes月之前或之后的日期
  227 + *
  228 + * @param date
  229 + * 日期
  230 + * @param monthes
  231 + * 月数,正数为向后几天,负数为向前几天
  232 + * @return 返回Date日期类型
  233 + */
  234 + public static Date getDateBeforeOrAfterMonthes(Date date, int monthes) {
  235 + Calendar now = Calendar.getInstance();
  236 + now.setTime(date);
  237 + now.set(Calendar.MONTH, now.get(Calendar.MONTH) + monthes);
  238 + return now.getTime();
  239 + }
  240 +
  241 + /**
  242 + * 计算出date years年之前或之后的日期
  243 + *
  244 + * @param date
  245 + * 日期
  246 + * @param years
  247 + * 年数,正数为向后几年,负数为向前几年
  248 + * @return 返回Date日期类型
  249 + */
  250 + public static Date getDateBeforeOrAfterYears(Date date, int years) {
  251 + Calendar now = Calendar.getInstance();
  252 + now.setTime(date);
  253 + now.set(Calendar.YEAR, now.get(Calendar.YEAR) + years);
  254 + return now.getTime();
  255 + }
  256 +
  257 + /**
  258 + * 计算两个日期之间的天数
  259 + *
  260 + * @param beginDate
  261 + * @param endDate
  262 + * @return 如果beginDate 在 endDate之后返回负数 ,反之返回正数
  263 + */
  264 + public static int daysOfTwoDate(Date beginDate, Date endDate) {
  265 +
  266 + Calendar beginCalendar = Calendar.getInstance();
  267 + Calendar endCalendar = Calendar.getInstance();
  268 +
  269 + beginCalendar.setTime(beginDate);
  270 + endCalendar.setTime(endDate);
  271 +
  272 + return daysOfTwoDate(beginCalendar, endCalendar);
  273 +
  274 + }
  275 +
  276 + /**
  277 + * 计算两个日期之间的天数
  278 + *
  279 + * @param d1
  280 + * @param d2
  281 + * @return 如果d1 在 d2 之后返回负数 ,反之返回正数
  282 + */
  283 + public static int daysOfTwoDate(Calendar d1, Calendar d2) {
  284 + int days = 0;
  285 + int years = d1.get(Calendar.YEAR) - d2.get(Calendar.YEAR);
  286 + if (years == 0) {// 同一年中
  287 + days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
  288 + return days;
  289 + } else if (years > 0) {// 不同一年
  290 + for (int i = 0; i < years; i++) {
  291 + d2.add(Calendar.YEAR, 1);
  292 + days += -d2.getActualMaximum(Calendar.DAY_OF_YEAR);
  293 + if (d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)) {
  294 + days += d2.get(Calendar.DAY_OF_YEAR)
  295 + - d1.get(Calendar.DAY_OF_YEAR);
  296 + return days;
  297 + }
  298 + }
  299 + } else
  300 + for (int i = 0; i < -years; i++) {
  301 + d1.add(Calendar.YEAR, 1);
  302 + days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);
  303 + if (d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)) {
  304 + days += d2.get(Calendar.DAY_OF_YEAR)
  305 + - d1.get(Calendar.DAY_OF_YEAR);
  306 + return days;
  307 + }
  308 + }
  309 + return days;
  310 + }
  311 +
  312 + /**
  313 + * 获得当前时间当天的开始时间,即当前给出的时间那一天的00:00:00的时间
  314 + *
  315 + * @param date
  316 + * 当前给出的时间
  317 + * @return 当前给出的时间那一天的00:00:00的时间的日期对象
  318 + */
  319 + public static Date getDateBegin(Date date) {
  320 + SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
  321 + if (date != null) {
  322 + try {
  323 + return DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.CHINA).parse(ymdFormat.format(date));
  324 + } catch (ParseException e) {
  325 + e.printStackTrace();
  326 + }
  327 + }
  328 +
  329 + return null;
  330 + }
  331 +
  332 + /**
  333 + * 获得当前时间当天的结束时间,即当前给出的时间那一天的23:59:59的时间
  334 + *
  335 + * @param date
  336 + * 当前给出的时间
  337 + * @return 当前给出的时间那一天的23:59:59的时间的日期对象
  338 + */
  339 + public static Date getDateEnd(Date date) {
  340 + SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
  341 + if (date != null) {
  342 + try {
  343 + date = getDateBeforeOrAfterDays(date, 1);
  344 + date = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.CHINA).parse(ymdFormat.format(date));
  345 + Date endDate = new Date();
  346 + endDate.setTime(date.getTime() - 1000);
  347 + return endDate;
  348 + } catch (ParseException e) {
  349 + e.printStackTrace();
  350 + }
  351 + }
  352 + return null;
  353 + }
  354 +
  355 + public static String getTime() {
  356 + Date d = new Date();
  357 + String re = dateToFormatStr(d, "yyyyMMddHHmm");
  358 + return re;
  359 + }
  360 +
  361 + public static String removeLast(String str) {
  362 + str = str.trim();
  363 + return str.substring(0, str.length() - 1);
  364 + }
  365 +
  366 + public static boolean isEmpty(String str) {
  367 + return str == null || str.trim().length() == 0
  368 + || str.trim().equals("null");
  369 + }
  370 +
  371 + public static int getRandom6() {
  372 + Random ran = new Random();
  373 + int r = 0;
  374 + m1 : while (true) {
  375 + int n = ran.nextInt(1000000);
  376 + r = n;
  377 + int[] bs = new int[6];
  378 + for (int i = 0; i < bs.length; i++) {
  379 + bs[i] = n % 10;
  380 + n /= 10;
  381 + }
  382 + Arrays.sort(bs);
  383 + for (int i = 1; i < bs.length; i++) {
  384 + if (bs[i - 1] == bs[i]) {
  385 + continue m1;
  386 + }
  387 + }
  388 + break;
  389 + }
  390 + return r;
  391 + }
  392 +
  393 + public static int getCurrentTimeHashCode() {
  394 + return String.valueOf(System.currentTimeMillis()).hashCode();
  395 + }
  396 +
  397 + public static String randomNumString(int len) {
  398 + final int maxNum = 10;
  399 + char[] str = {'0', '1', '2', '3', '5', '6', '7', '8', '9'};
  400 + StringBuffer randStr = new StringBuffer("");
  401 + Random r = new Random();
  402 + for (int i = 0, count = 0; count < len; i++) {
  403 + i = Math.abs(r.nextInt(maxNum));
  404 + if (i >= 0 && i < str.length) {
  405 + randStr.append(str[i]);
  406 + count++;
  407 + }
  408 + }
  409 + return randStr.toString();
  410 + }
  411 +
  412 + /**
  413 + * 随机生成指定长度的字符串
  414 + */
  415 + public static String randomString(int length) {
  416 + if (length < 1) { return null; }
  417 + String basicchars = "0123456789abcdefghijklmnopqrstuvwxy";
  418 + Random randGen = new Random();
  419 + char[] numbersAndLetters = basicchars.toCharArray();
  420 + char[] randBuffer = new char[length];
  421 + for (int i = 0; i < randBuffer.length; i++) {
  422 + randBuffer[i] = numbersAndLetters[randGen.nextInt(basicchars.length() - 1)];
  423 + }
  424 + return new String(randBuffer);
  425 + }
  426 +
  427 + public static String format(String format, Object... objects) {
  428 + return String.format(format, objects);
  429 + }
  430 +
  431 + public static String Object2params(Object... params) {
  432 + String newLine = "\n";
  433 + if ("\\".equals(File.separator)) {// windows 下 log 换行符
  434 + newLine = "\r\n";
  435 + }
  436 + StringBuffer info = new StringBuffer();
  437 + info.append(newLine);
  438 + int i = 1;
  439 + if (params != null) {
  440 + for (Object param : params) {
  441 + info.append("[参数" + i + ":" + param + "]");
  442 + info.append(newLine);
  443 + i++;
  444 + }
  445 + }
  446 + return info.toString();
  447 + }
  448 +
  449 + public static boolean isAutowired(List<Object[]> condition) {
  450 + return false;
  451 + }
  452 +
  453 + public static boolean isAutowired(String condition) {
  454 + return false;
  455 + }
  456 +
  457 + public static String toUpperCaseFirstOne(String s) {
  458 + if (Character.isUpperCase(s.charAt(0)))
  459 + return s;
  460 + else
  461 + return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
  462 + }
  463 +
  464 + public static String formatBeanNameFirstUpper(String name) {
  465 + if (name == null) return null;
  466 + if (name.length() == 0) return "";
  467 + String sReturn = formatBeanNameFirstLow(name);
  468 + return toUpperCaseFirstOne(sReturn);
  469 + }
  470 +
  471 + public static String formatBeanNameFirstLow(String name) {
  472 + if (name == null) return null;
  473 + if (name.length() == 0) return "";
  474 + byte[] ss = name.toLowerCase().getBytes();
  475 + int len = ss.length;
  476 + byte[] ss1 = new byte[len];
  477 + ss1[0] = ss[0];
  478 + int k = 1;
  479 + for (int i = 1; i < ss.length; i++) {
  480 + if (ss[i] == '_') {
  481 + if (i < ss.length - 1) {
  482 + ss1[k] = (byte)Character.toUpperCase(ss[(i + 1)]);
  483 + i++;
  484 + }
  485 + len--;
  486 + } else {
  487 + ss1[k] = ss[i];
  488 + }
  489 + k++;
  490 + }
  491 + return new String(ss1, 0, len);
  492 + }
  493 +
  494 + public static Object getObjectValue(Field field, Object target) {
  495 + Object result = null;
  496 + try {
  497 + String sMethodName = "get"
  498 + + StringUtil.toUpperCaseFirstOne(field.getName());
  499 + Method method = target.getClass().getMethod(sMethodName, null);
  500 + result = method.invoke(target, null);
  501 + } catch (Exception e) {
  502 + e.printStackTrace();
  503 + }
  504 + return result;
  505 + }
  506 +
  507 + @SuppressWarnings("unchecked")
  508 + public static String getValueFromObjectByName(Object obj, String fiedName) {
  509 + if(!StringUtil.isEmpty(fiedName)){
  510 + try {
  511 + String sMethodName = "get"
  512 +// + StringUtil.toUpperCaseFirstOne(fiedName);
  513 + + StringUtil.formatBeanNameFirstUpper(fiedName);//例:FIR_NAME 改成 FirName
  514 + Method method = obj.getClass().getMethod(sMethodName, null);
  515 + Object t = method.invoke(obj, null);
  516 + if(t != null)
  517 + return t.toString();
  518 + } catch (Exception e) {
  519 + e.printStackTrace();
  520 + }
  521 +
  522 + }
  523 + return null;
  524 + }
  525 +
  526 + @SuppressWarnings("unchecked")
  527 + public static Object[] getListByObject(Object obj) {
  528 + ArrayList list = new ArrayList();
  529 + for (Field field : obj.getClass().getDeclaredFields()) {
  530 + Object result = getObjectValue(field, obj);
  531 + list.add(field.getName() + " 值: " + result);
  532 + }
  533 + return list.toArray();
  534 + }
  535 +
  536 +
  537 + public static String replaceBlank(String str) {
  538 + String dest = "";
  539 + if (str != null) {
  540 + Pattern p = Pattern.compile("\\s*|\t|\r|\n");
  541 + Matcher m = p.matcher(str);
  542 + dest = m.replaceAll("");
  543 + }
  544 + return dest;
  545 + }
  546 +
  547 +
  548 + public static String transferObjectList(List<Object[]> obj){
  549 +
  550 + if(obj == null){
  551 + return "";
  552 + }
  553 + StringBuffer returnStr = new StringBuffer("[");
  554 + for(Object[] o : obj){
  555 + returnStr.append(Arrays.toString(o));
  556 + returnStr.append(",");
  557 + }
  558 + returnStr.append("]");
  559 +
  560 + return returnStr.toString();
  561 +
  562 +
  563 + }
  564 +
  565 +}
... ...