作者 钟来

初始提交

@@ -77,6 +77,29 @@ @@ -77,6 +77,29 @@
77 <groupId>net.jodah</groupId> 77 <groupId>net.jodah</groupId>
78 <artifactId>expiringmap</artifactId> 78 <artifactId>expiringmap</artifactId>
79 </dependency> 79 </dependency>
  80 +
  81 +
  82 + <!-- 数据库 -->
  83 + <dependency>
  84 + <groupId>commons-dbcp</groupId>
  85 + <artifactId>commons-dbcp</artifactId>
  86 + <version>1.4</version>
  87 + </dependency>
  88 + <dependency>
  89 + <groupId>commons-dbutils</groupId>
  90 + <artifactId>commons-dbutils</artifactId>
  91 + <version>1.6</version>
  92 + </dependency>
  93 + <dependency>
  94 + <groupId>commons-pool</groupId>
  95 + <artifactId>commons-pool</artifactId>
  96 + <version>1.6</version>
  97 + </dependency>
  98 + <dependency>
  99 + <groupId>mysql</groupId>
  100 + <artifactId>mysql-connector-java</artifactId>
  101 + <version>8.0.17</version>
  102 + </dependency>
80 </dependencies> 103 </dependencies>
81 104
82 <build> 105 <build>
  1 +package com.zhonglai.luhui.mqtt.comm.dao;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import org.apache.commons.dbutils.*;
  5 +import org.apache.commons.dbutils.handlers.BeanHandler;
  6 +import org.apache.commons.dbutils.handlers.BeanListHandler;
  7 +import org.apache.commons.dbutils.handlers.MapListHandler;
  8 +import org.apache.commons.dbutils.handlers.ScalarHandler;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +
  11 +import java.lang.reflect.Field;
  12 +import java.lang.reflect.InvocationTargetException;
  13 +import java.lang.reflect.Method;
  14 +import java.sql.SQLException;
  15 +import java.util.ArrayList;
  16 +import java.util.List;
  17 +import java.util.Map;
  18 +
  19 +/**
  20 + * 数据库操作
  21 + * Created by zhonglai on 2016/12/15.
  22 + */
  23 +public class BaseDao {
  24 +
  25 + private DBFactory dBFactory = new DBFactoryImp();
  26 +
  27 + public BaseDao(DBFactory dBFactory)
  28 + {
  29 + this.dBFactory = dBFactory;
  30 + }
  31 +
  32 + public BaseDao()
  33 + {
  34 +
  35 + }
  36 +
  37 + /**
  38 + * 指定表名插入对象
  39 + * @param object 传值对象
  40 + */
  41 + public void insert(Object object )
  42 + {
  43 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  44 + String sql = "insert into ";
  45 + sql += changTableNameFromObject(object) + "(";
  46 + Field[] fields = object.getClass().getDeclaredFields( );
  47 + String values = "(";
  48 + List<Object> valueList = new ArrayList<Object>();
  49 + for(Field field:fields)
  50 + {//
  51 + Method method;
  52 + try {
  53 + method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName()));
  54 + Object value = method.invoke(object);
  55 + if(null != value)
  56 + {
  57 + if(!"(".equals(values) )
  58 + {
  59 + sql += ",";
  60 + values += ",";
  61 + }
  62 + sql += "`"+changTableNameFromObject(field.getName())+"`";
  63 + values += "?";
  64 + valueList.add(value);
  65 + }
  66 + } catch (NoSuchMethodException e) {
  67 + // TODO Auto-generated catch block
  68 + e.printStackTrace();
  69 + } catch (SecurityException e) {
  70 + // TODO Auto-generated catch block
  71 + e.printStackTrace();
  72 + } catch (IllegalAccessException e) {
  73 + // TODO Auto-generated catch block
  74 + e.printStackTrace();
  75 + } catch (IllegalArgumentException e) {
  76 + // TODO Auto-generated catch block
  77 + e.printStackTrace();
  78 + } catch (InvocationTargetException e) {
  79 + // TODO Auto-generated catch block
  80 + e.printStackTrace();
  81 + }
  82 +
  83 + }
  84 + sql += ")";
  85 + values += ")";
  86 + sql = sql+" values "+values;
  87 +
  88 + try {
  89 + // 创建一个BeanProcessor对象
  90 + // GenerousBeanProcessor 仅仅重写了父类BeanProcessor的mapColumnsToProperties方法
  91 + BeanProcessor bean = new GenerousBeanProcessor();
  92 + // 将GenerousBeanProcessor对象传递给BasicRowProcessor
  93 + RowProcessor processor = new BasicRowProcessor(bean);
  94 + object = runner.insert(sql,new BeanHandler<Object>(Object.class,processor),valueList.toArray());
  95 + } catch (SQLException e) {
  96 + e.printStackTrace();
  97 + }
  98 + }
  99 +
  100 + /**
  101 + * 插入对象集合
  102 + * @param objectList
  103 + */
  104 + public void insertList(List<Object> objectList)
  105 + {
  106 + insertList(objectList,null);
  107 + }
  108 +
  109 + /**
  110 + * 指定表名插入对象集合
  111 + * @param objectList
  112 + */
  113 + public void insertList(List<?> objectList ,String tableName)
  114 + {
  115 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  116 +
  117 + Object object = objectList.get(0);
  118 +
  119 + String sql = "insert into ";
  120 + if(StringUtils.isBlank(tableName))
  121 + {
  122 + tableName = changTableNameFromObject(object.getClass().getSimpleName());
  123 + }
  124 +
  125 + List<Object> valueList = new ArrayList<Object>();
  126 + sql += tableName + msaicAttribute(object) + " values " +msaicValues(objectList,valueList);
  127 +
  128 + try {
  129 + runner.update(sql,valueList.toArray());
  130 + } catch (SQLException e) {
  131 + e.printStackTrace();
  132 + }
  133 + }
  134 +
  135 + /**
  136 + * 拼接属性条件
  137 + * @param object
  138 + * @return
  139 + */
  140 + private String msaicAttribute(Object object)
  141 + {
  142 + Field[] fields = object.getClass().getDeclaredFields( );
  143 + String attributeStr = "(";
  144 + List<Object> valueList = new ArrayList<Object>();
  145 + for(Field field:fields)
  146 + {//
  147 + if(!"(".equals(attributeStr) )
  148 + {
  149 + attributeStr += ",";
  150 + }
  151 + attributeStr += "`"+changTableNameFromObject(field.getName())+"`";
  152 + }
  153 + attributeStr += ")";
  154 + return attributeStr;
  155 + }
  156 +
  157 + private String msaicValues(List<?> objectList,List<Object> valueList)
  158 + {
  159 + StringBuffer returnValues = new StringBuffer();
  160 + for(Object object:objectList)
  161 + {
  162 + Field[] fields = object.getClass().getDeclaredFields( );
  163 + String values = "(";
  164 + for(Field field:fields)
  165 + {//
  166 + Method method;
  167 + try {
  168 + method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName()));
  169 + Object value = method.invoke(object);
  170 + if(!"(".equals(values) )
  171 + {
  172 + values += ",";
  173 + }
  174 + values += "?";
  175 + valueList.add(value);
  176 + } catch (NoSuchMethodException e) {
  177 + // TODO Auto-generated catch block
  178 + e.printStackTrace();
  179 + } catch (SecurityException e) {
  180 + // TODO Auto-generated catch block
  181 + e.printStackTrace();
  182 + } catch (IllegalAccessException e) {
  183 + // TODO Auto-generated catch block
  184 + e.printStackTrace();
  185 + } catch (IllegalArgumentException e) {
  186 + // TODO Auto-generated catch block
  187 + e.printStackTrace();
  188 + } catch (InvocationTargetException e) {
  189 + // TODO Auto-generated catch block
  190 + e.printStackTrace();
  191 + }
  192 +
  193 + }
  194 + values += ")";
  195 + if(returnValues.length()!=0)
  196 + {
  197 + returnValues.append(",");
  198 + }
  199 + returnValues.append(values);
  200 + }
  201 + return returnValues.toString();
  202 + }
  203 +
  204 +
  205 + /**
  206 + * 以主键id更新对象
  207 + * @param object
  208 + */
  209 + public void update(Object object)
  210 + {
  211 + update(object,null);
  212 + }
  213 +
  214 + /**
  215 + * 根据条件更新对象
  216 + * @param object 传值对象
  217 + * @param whereFieldNames 条件(多个用,分割)
  218 + */
  219 + public void update(Object object,String whereFieldNames)
  220 + {
  221 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  222 +
  223 + String sql = "update ";
  224 + sql += changTableNameFromObject(object);
  225 + Field[] fields = object.getClass().getDeclaredFields();
  226 + List<Object> valueList = new ArrayList<Object>();
  227 +
  228 + if(null != fields && fields.length !=0 )
  229 + {
  230 + sql += " set ";
  231 + int j = 0;
  232 + for(int i=0;i<fields.length;i++)
  233 + {
  234 + Field field = fields[i];
  235 + try {
  236 + Method method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName()));
  237 + Object value = method.invoke(object);
  238 + if(null != value)
  239 + {
  240 + if(j!=0)
  241 + {
  242 + sql += ",";
  243 + }
  244 + sql += "`"+changTableNameFromObject(field.getName())+"`"+"=?";
  245 + j++;
  246 + valueList.add(value);
  247 + }
  248 + } catch (NoSuchMethodException e) {
  249 +
  250 + e.printStackTrace();
  251 + } catch (SecurityException e) {
  252 + // TODO Auto-generated catch block
  253 + e.printStackTrace();
  254 + } catch (IllegalAccessException e) {
  255 + // TODO Auto-generated catch block
  256 + e.printStackTrace();
  257 + } catch (IllegalArgumentException e) {
  258 + // TODO Auto-generated catch block
  259 + e.printStackTrace();
  260 + } catch (InvocationTargetException e) {
  261 + // TODO Auto-generated catch block
  262 + e.printStackTrace();
  263 + }
  264 +
  265 + }
  266 +
  267 + sql += " where 1=1 ";
  268 + if(StringUtils.isNoneBlank(whereFieldNames))
  269 + {
  270 + String[] wheres = whereFieldNames.split(",");
  271 + if(StringUtils.isNotBlank(whereFieldNames))
  272 + {
  273 + for(int i =0;i<wheres.length;i++)
  274 + {
  275 + try {
  276 + Method method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(wheres[i]));
  277 + Object value = method.invoke(object);
  278 + sql += " and ";
  279 + sql += changTableNameFromObject(wheres[i]) + "=?";
  280 + valueList.add(value);
  281 + } catch (IllegalAccessException e) {
  282 + // TODO Auto-generated catch block
  283 + e.printStackTrace();
  284 + } catch (IllegalArgumentException e) {
  285 + // TODO Auto-generated catch block
  286 + e.printStackTrace();
  287 + } catch (InvocationTargetException e) {
  288 + // TODO Auto-generated catch block
  289 + e.printStackTrace();
  290 + } catch (NoSuchMethodException e) {
  291 + // TODO Auto-generated catch block
  292 + e.printStackTrace();
  293 + } catch (SecurityException e) {
  294 + // TODO Auto-generated catch block
  295 + e.printStackTrace();
  296 + }
  297 +
  298 + }
  299 + }
  300 + }else{
  301 + Method method = null;
  302 + try {
  303 + method = object.getClass().getMethod("get"+ com.ruoyi.common.utils.StringUtils.getName("id"));
  304 + Object value = method.invoke(object);
  305 + sql += " and ";
  306 + sql += "id=?";
  307 + valueList.add(value);
  308 + } catch (NoSuchMethodException e) {
  309 + e.printStackTrace();
  310 + } catch (InvocationTargetException e) {
  311 + e.printStackTrace();
  312 + } catch (IllegalAccessException e) {
  313 + e.printStackTrace();
  314 + }
  315 +
  316 + }
  317 + }
  318 +
  319 + try {
  320 + runner.update(sql,valueList.toArray());
  321 + } catch (SQLException e) {
  322 + e.printStackTrace();
  323 + }
  324 + }
  325 +
  326 + /**
  327 + * 根据条件获取对象
  328 + * @param clas 对象
  329 + * @param where 条件
  330 + * @param <T>
  331 + * @return
  332 + */
  333 + public <T> Object get(Class<T> clas,Map<String,Object> where)
  334 + {
  335 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  336 +
  337 + String tableName = changTableNameFromObject(clas.getSimpleName());
  338 +
  339 + String sql = "select * from "+tableName+" where 1=1 ";
  340 + try {
  341 + List<Object> valueList = new ArrayList<Object>();
  342 + sql += getCountFrommapWhere(where,valueList);
  343 + return runner.query(sql, new BeanHandler<T>(clas, getRowProcessor()),valueList.toArray());
  344 + } catch (SQLException e) {
  345 + e.printStackTrace();
  346 + }
  347 + return null;
  348 + }
  349 +
  350 + /**
  351 + * 根据条件获取对象
  352 + * @param clas 对象
  353 + * @param where 条件
  354 + * @param <T>
  355 + * @return
  356 + */
  357 + public <T> Object get(Class<T> clas,String where,String tableName)
  358 + {
  359 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  360 +
  361 + String sql = "select * from "+tableName+" where 1=1 ";
  362 + try {
  363 + List<Object> valueList = new ArrayList<Object>();
  364 + sql += "and "+where;
  365 + return runner.query(sql, new BeanHandler<T>(clas, getRowProcessor()));
  366 + } catch (SQLException e) {
  367 + e.printStackTrace();
  368 + }
  369 + return null;
  370 + }
  371 +
  372 + /**
  373 + * 根据id获取对象
  374 + * @param clas 对象
  375 + * @param id 主键id
  376 + * @param <T>
  377 + * @return
  378 + */
  379 + public <T> Object get(Class<T> clas,Object id)
  380 + {
  381 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  382 +
  383 + String tableName = changTableNameFromObject(clas.getSimpleName());
  384 +
  385 + String sql = "select * from "+tableName+" where 1=1 ";
  386 +
  387 + try {
  388 + sql += " and id=?";
  389 + Object[] params = {id};
  390 + return runner.query(sql, new BeanHandler<T>(clas, getRowProcessor()),params);
  391 + } catch (SQLException e) {
  392 + e.printStackTrace();
  393 + }
  394 + return null;
  395 + }
  396 +
  397 + /**
  398 + * 根据条件删除对象
  399 + * @param clas 对象
  400 + * @param where 条件
  401 + * @return
  402 + */
  403 + public int delete(Class<?> clas, Map<String,Object> where)
  404 + {
  405 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  406 +
  407 + String tableName = changTableNameFromObject(clas.getSimpleName());
  408 + String sql = "DELETE FROM "+tableName+" WHERE 1=1 ";
  409 + try {
  410 + List<Object> valueList = new ArrayList<Object>();
  411 + sql += getCountFrommapWhere(where,valueList);
  412 + return runner.update(sql,valueList.toArray());
  413 + } catch (SQLException e) {
  414 + e.printStackTrace();
  415 + }
  416 + return 0;
  417 + }
  418 +
  419 + /**
  420 + * 根据id删除对象
  421 + * @param clas 对象
  422 + * @param id 主键id
  423 + */
  424 + public int delete(Class<?> clas,Object id)
  425 + {
  426 + return delete(clas,id,null);
  427 + }
  428 +
  429 + /**
  430 + * 根据id删除对象
  431 + * @param clas 对象
  432 + * @param id 主键id
  433 + */
  434 + public int delete(Class<?> clas,Object id,String tableName)
  435 + {
  436 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  437 +
  438 + if(StringUtils.isBlank(tableName))
  439 + {
  440 + tableName = changTableNameFromObject(clas.getSimpleName());
  441 + }
  442 + String sql = "DELETE FROM "+tableName+" WHERE 1=1 ";
  443 + try {
  444 + sql += " and id=?";
  445 + Object[] params = {id};
  446 + return runner.update(sql,params);
  447 + } catch (SQLException e) {
  448 + e.printStackTrace();
  449 + }
  450 + return 0;
  451 + }
  452 +
  453 + /**
  454 + * 对象条件获取对象列表
  455 + * @param object 对象条件
  456 + * @param <T>
  457 + * @return
  458 + */
  459 + public <T> T find(Object object)
  460 + {
  461 + return find(object,"*");
  462 + }
  463 +
  464 + /**
  465 + * 对象条件获取对象指定属性值列表
  466 + * @param object 对象条件
  467 + * @param selectStr 指定属性值(用数据库表字段多个,分割)
  468 + * @param <T>
  469 + * @return
  470 + */
  471 + public <T> T find(Object object,String selectStr)
  472 + {
  473 + return find(object,selectStr,null);
  474 + }
  475 +
  476 + /**
  477 + * 对象条件的条件获取对象列表
  478 + * @param object 对象条件
  479 + * @param selectStr 指定属性值(用数据库表字段多个,分割)
  480 + * @param whereMap 对象条件的条件
  481 + * @param <T>
  482 + * @return
  483 + */
  484 + public <T> T find(Object object,String selectStr,Map<String,String> whereMap)
  485 + {
  486 + return find(object,selectStr,whereMap,null);
  487 + }
  488 +
  489 + /**
  490 + * 对象条件的条件按一定排序获取对象列表
  491 + * @param object 对象条件
  492 + * @param selectStr 指定属性值(用数据库表字段多个,分割)
  493 + * @param whereMap 对象条件的条件
  494 + * @param order 排序条件
  495 + * @param <T>
  496 + * @return
  497 + */
  498 + public <T> T find(Object object,String selectStr,Map<String,String> whereMap,String order)
  499 + {
  500 + return find(object,selectStr,whereMap,order,0,0);
  501 + }
  502 +
  503 +
  504 + /**
  505 + * 对象条件获取对象列表
  506 + * @param object 对象条件
  507 + * @param selectStr 指定属性值(用数据库表字段多个,分割)
  508 + * @param whereMap 对象条件的条件
  509 + * @param order 排序条件
  510 + * @param pageSize 页面大小
  511 + * @param pageNo 页码
  512 + * @param <T>
  513 + * @return
  514 + */
  515 + public <T> T find(Object object,String selectStr,Map<String,String> whereMap,String order,Integer pageSize,Integer pageNo )
  516 + {
  517 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  518 +
  519 + if(StringUtils.isBlank(order))
  520 + {
  521 + order = "";
  522 + }
  523 + if(null == pageSize)
  524 + {
  525 + pageSize = 0;
  526 + }
  527 + if(null == pageNo)
  528 + {
  529 + pageNo = 0;
  530 + }
  531 + if(StringUtils.isBlank("selectStr"))
  532 + {
  533 + selectStr = "*";
  534 + }
  535 +
  536 + List<Object> valueList = new ArrayList<Object>();
  537 + String sql = getFindSql(object,selectStr,whereMap,valueList);
  538 +
  539 + if(StringUtils.isNotBlank(order))
  540 + {
  541 + sql += " order by "+order;
  542 + }
  543 + if(0 != pageSize && 0 != pageNo)
  544 + {
  545 + sql += " limit "+((pageNo-1)*pageSize)+","+pageSize;
  546 + }
  547 + try {
  548 + return (T) runner.
  549 + query(sql,new BeanListHandler(object.getClass(),getRowProcessor()),valueList.toArray());
  550 + } catch (SQLException e) {
  551 + e.printStackTrace();
  552 + }
  553 + return null;
  554 + }
  555 +
  556 + /**
  557 + * sql执行查询
  558 + * @param sql
  559 + * @return
  560 + */
  561 + public <T> T findBysql(String sql,Class type,Object... params)
  562 + {
  563 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  564 +
  565 + try {
  566 + return (T) runner.
  567 + query(sql,new BeanListHandler(type,getRowProcessor()),params);
  568 + } catch (SQLException e) {
  569 + e.printStackTrace();
  570 + }
  571 + return null;
  572 + }
  573 +
  574 + /**
  575 + * 对象条件获取总数
  576 + * @param object 对象条件
  577 + * @return
  578 + */
  579 + public Long getTotle(Object object )
  580 + {
  581 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  582 +
  583 + List<Object> valueList = new ArrayList<Object>();
  584 + String sql = getFindSql(object,"count(*)",null,valueList);
  585 + try {
  586 + return runner.query(sql,new ScalarHandler<Long>(),valueList.toArray());
  587 + } catch (SQLException e) {
  588 + e.printStackTrace();
  589 + }
  590 + return 0l;
  591 + }
  592 +
  593 + /**
  594 + * 对象条件的条件获取总数
  595 + * @param object 对象条件
  596 + * @param whereMap 对象条件的条件
  597 + * @return
  598 + */
  599 + public Long getTotle(Object object,Map<String,String> whereMap)
  600 + {
  601 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  602 + List<Object> valueList = new ArrayList<Object>();
  603 + String sql = getFindSql(object,"count(*)",whereMap,valueList);
  604 + try {
  605 + return runner.query(sql,new ScalarHandler<Long>(),valueList.toArray());
  606 + } catch (SQLException e) {
  607 + e.printStackTrace();
  608 + }
  609 + return 0l;
  610 + }
  611 +
  612 + /**
  613 + * sql执行查询
  614 + * @param sql
  615 + * @return
  616 + */
  617 + public List findListBysql(String sql)
  618 + {
  619 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  620 +
  621 + List list = null;
  622 + try {
  623 + list = runner.query(sql,new MapListHandler());
  624 + } catch (SQLException e) {
  625 + e.printStackTrace();
  626 + }
  627 + return list;
  628 + }
  629 +
  630 + /**
  631 + * sql执行查询
  632 + * @param sql
  633 + * @return
  634 + */
  635 + public JSONArray findBysql(String sql)
  636 + {
  637 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  638 +
  639 + List list = null;
  640 + try {
  641 + list = runner.query(sql,new MapListHandler());
  642 + } catch (SQLException e) {
  643 + e.printStackTrace();
  644 + }
  645 + if(null != list)
  646 + {
  647 + return JSONArray.parseArray(JSONArray.toJSONString(list));
  648 + }
  649 + return null;
  650 + }
  651 +
  652 + /**
  653 + * sql执行更新
  654 + * @param sql
  655 + * @param params
  656 + * @return
  657 + */
  658 + public int updateBySql(String sql,Object... params)
  659 + {
  660 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  661 + try {
  662 + return runner.update(sql,params);
  663 + } catch (SQLException e) {
  664 + e.printStackTrace();
  665 + }
  666 + return 0;
  667 + }
  668 +
  669 + /**
  670 + * 生成查询条件
  671 + * @param object
  672 + * @param selectStr
  673 + * @param whereMap
  674 + * @param valueList
  675 + * @return
  676 + */
  677 + private String getFindSql(Object object,String selectStr,Map<String,String> whereMap,List<Object> valueList )
  678 + {
  679 +
  680 + String sql = null;
  681 + sql = "select "+selectStr+" from "+ changTableNameFromObject(object);
  682 + String where = " where 1=1 ";
  683 + String like = "";
  684 + Field[] fields = object.getClass().getDeclaredFields();
  685 +
  686 + if(null != fields && fields.length !=0 )
  687 + {
  688 + for(int i=0;i<fields.length;i++)
  689 + {
  690 + Field field = fields[i];
  691 + try {
  692 + Method method;
  693 + method = object.getClass().getMethod("get"+ com.ruoyi.common.utils.StringUtils.getName(field.getName()));
  694 + Object value = method.invoke(object);
  695 + if(!(null == value))
  696 + {
  697 + String orther = "";
  698 + String s = "=";
  699 + if(!(null == whereMap || null == whereMap.get(field.getName())))
  700 + {
  701 + s = whereMap.get(field.getName());
  702 + if("like".equals(s))
  703 + {
  704 + value = "%"+value+"%";
  705 + like += " or " + "`"+changTableNameFromObject(field.getName())+"`"+s+" ?"+orther ;
  706 + valueList.add(value);
  707 + continue;
  708 + }
  709 + if("time".equals(s))
  710 + {
  711 + s = ">";
  712 + orther = " and `"+changTableNameFromObject(field.getName())+"`< '"+whereMap.get("end_"+field.getName())+"'";
  713 + }
  714 + }
  715 + where += " and `"+changTableNameFromObject(field.getName())+"`"+s+" ?"+orther;
  716 + valueList.add(value);
  717 + }
  718 + } catch (NoSuchMethodException e) {
  719 + e.printStackTrace();
  720 + } catch (SecurityException e) {
  721 + // TODO Auto-generated catch block
  722 + e.printStackTrace();
  723 + } catch (IllegalAccessException e) {
  724 + // TODO Auto-generated catch block
  725 + e.printStackTrace();
  726 + } catch (IllegalArgumentException e) {
  727 + // TODO Auto-generated catch block
  728 + e.printStackTrace();
  729 + } catch (InvocationTargetException e) {
  730 + // TODO Auto-generated catch block
  731 + e.printStackTrace();
  732 + }
  733 +
  734 + }
  735 + }
  736 + sql += where;
  737 + if(StringUtils.isNoneBlank(like))
  738 + {
  739 + sql += "and (1=2 "+like+")";
  740 + }
  741 + return sql;
  742 + }
  743 +
  744 + /**
  745 + * 添加或更新对象
  746 + * INSERT INTO test(`in1`,`str1`) VALUES ('1','1');
  747 + * @param object 对象
  748 + * @return
  749 + */
  750 + public void saveOrUpdateObject(Object object)
  751 + {
  752 + String sql = "insert into ";
  753 +
  754 + sql += changTableNameFromObject(object) + "(";
  755 + Field[] fields = object.getClass().getDeclaredFields( );
  756 + String values = "(";
  757 + String update = "";
  758 + for(Field field:fields)
  759 + {//
  760 + Method method;
  761 + try {
  762 + method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName()));
  763 + Object value = method.invoke(object);
  764 + if(null != value)
  765 + {
  766 + if(!"(".equals(values) )
  767 + {
  768 + sql += ",";
  769 + values += ",";
  770 + update += ",";
  771 + }
  772 + sql += "`"+changTableNameFromObject(field.getName())+"`";
  773 + values += "'"+ value+"'";
  774 + update += "`"+changTableNameFromObject(field.getName())+"`"+"=VALUES("+"`"+changTableNameFromObject(field.getName())+"`)";
  775 + }
  776 + } catch (NoSuchMethodException e) {
  777 + // TODO Auto-generated catch block
  778 + e.printStackTrace();
  779 + } catch (SecurityException e) {
  780 + // TODO Auto-generated catch block
  781 + e.printStackTrace();
  782 + } catch (IllegalAccessException e) {
  783 + // TODO Auto-generated catch block
  784 + e.printStackTrace();
  785 + } catch (IllegalArgumentException e) {
  786 + // TODO Auto-generated catch block
  787 + e.printStackTrace();
  788 + } catch (InvocationTargetException e) {
  789 + // TODO Auto-generated catch block
  790 + e.printStackTrace();
  791 + }
  792 +
  793 +
  794 + }
  795 + sql += ")";
  796 + values += ")";
  797 + try {
  798 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  799 + runner.update(sql+" values "+values+" ON DUPLICATE KEY UPDATE "+update);
  800 + } catch (SQLException e) {
  801 + e.printStackTrace();
  802 + }
  803 + }
  804 +
  805 + /**
  806 + * 添加或更新对象列表
  807 + * INSERT INTO `test` (`in1`,`str1`)VALUES ('1','2'),('2','2') ON DUPLICATE KEY UPDATE `in1`=VALUES(`in1`),`str1`=VALUES(`str1`);
  808 + * @param objectlist 对象列表
  809 + * @return
  810 + */
  811 + public void saveOrUpdateObjectList(List<Object> objectlist)
  812 + {
  813 + StringBuffer sb =new StringBuffer();
  814 + String update = "";
  815 + for(int i = 0; i<objectlist.size();i++)
  816 + {
  817 + Object object = objectlist.get(i);
  818 +
  819 + Field[] fields = object.getClass().getDeclaredFields( );
  820 + if(i==0)
  821 + {
  822 + sb.append("INSERT INTO `"+changTableNameFromObject(object)+"` ");
  823 + sb.append("(");
  824 + for(Field field:fields)
  825 + {
  826 + if(!"".equals(update) )
  827 + {
  828 + sb.append(",");
  829 + update += ",";
  830 + }
  831 + sb.append("`"+changTableNameFromObject(field.getName())+"`");
  832 + update += "`"+changTableNameFromObject(field.getName())+"`"+"=VALUES("+"`"+changTableNameFromObject(field.getName())+"`)";
  833 + }
  834 + sb.append(")");
  835 + sb.append("VALUES ");
  836 + }else{
  837 + sb.append(",");
  838 + }
  839 + for(int j=0;j<fields.length;j++)
  840 + {
  841 + Field field = fields[j];
  842 + Method method;
  843 + try {
  844 + method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName()));
  845 + Object value = method.invoke(object);
  846 + if(null == value)
  847 + {
  848 + value = "";
  849 + }
  850 + if(j!=0)
  851 + {
  852 + sb.append(",");
  853 + }else{
  854 + sb.append("(");
  855 + }
  856 + sb.append("'"+ value+"'");
  857 + if(j==fields.length-1)
  858 + {
  859 + sb.append(")");
  860 + }
  861 + } catch (NoSuchMethodException e) {
  862 + // TODO Auto-generated catch block
  863 + e.printStackTrace();
  864 + } catch (SecurityException e) {
  865 + // TODO Auto-generated catch block
  866 + e.printStackTrace();
  867 + } catch (IllegalAccessException e) {
  868 + // TODO Auto-generated catch block
  869 + e.printStackTrace();
  870 + } catch (IllegalArgumentException e) {
  871 + // TODO Auto-generated catch block
  872 + e.printStackTrace();
  873 + } catch (InvocationTargetException e) {
  874 + // TODO Auto-generated catch block
  875 + e.printStackTrace();
  876 + }
  877 +
  878 + }
  879 + }
  880 + sb.append(" ON DUPLICATE KEY UPDATE ");
  881 + sb.append(update);
  882 + try {
  883 + QueryRunner runner = new QueryRunner(dBFactory.getDataSource());
  884 + runner.update(sb.toString());
  885 + } catch (SQLException e) {
  886 + e.printStackTrace();
  887 + }
  888 + }
  889 +
  890 + /**
  891 + * 将map条件转换成sql条件
  892 + * @param mapwhere map条件
  893 + * @param valueList sql条件参数
  894 + * @return
  895 + */
  896 + private String getCountFrommapWhere(Map<String,Object> mapwhere,List<Object> valueList)
  897 + {
  898 + String where = "";
  899 + for(String key:mapwhere.keySet())
  900 + {
  901 + Object value = mapwhere.get(key);
  902 + where += " and ";
  903 + where += changTableNameFromObject(key) + "=?";
  904 + valueList.add(value);
  905 + }
  906 + return where;
  907 + }
  908 +
  909 + /**
  910 + * 获取一个驼峰过滤规则类
  911 + * @return
  912 + */
  913 + private RowProcessor getRowProcessor()
  914 + {
  915 + // 创建一个BeanProcessor对象
  916 + // GenerousBeanProcessor 仅仅重写了父类BeanProcessor的mapColumnsToProperties方法
  917 + BeanProcessor bean = new GenerousBeanProcessor();
  918 + // 将GenerousBeanProcessor对象传递给BasicRowProcessor
  919 + return new BasicRowProcessor(bean);
  920 + }
  921 +
  922 + /**
  923 + * 对象转变数据库名
  924 + * @param object 对象
  925 + * @return
  926 + */
  927 + public static String changTableNameFromObject(Object object) {
  928 + Class clas = object.getClass();
  929 +
  930 + String tableNmae = clas.getSimpleName();
  931 +
  932 + Method method = null; // 父类对象调用子类方法(反射原理)
  933 + try {
  934 + method = clas.getMethod("getTableName");
  935 + Object tObject = method.invoke(object);
  936 + if(null != tObject)
  937 + {
  938 + tableNmae = (String) tObject;
  939 + }
  940 + } catch (NoSuchMethodException e) {
  941 + e.printStackTrace();
  942 + } catch (IllegalAccessException e) {
  943 + e.printStackTrace();
  944 + } catch (InvocationTargetException e) {
  945 + e.printStackTrace();
  946 + }
  947 +
  948 + return com.ruoyi.common.utils.StringUtils.toUnderScoreCase(tableNmae);
  949 + }
  950 +}
  1 +/**
  2 + * @version 0.1
  3 + * @describe 数据库链接工厂
  4 + * @author yushigui
  5 + * @date 2014-1-19
  6 + */
  7 +package com.zhonglai.luhui.mqtt.comm.dao;
  8 +
  9 +import javax.sql.DataSource;
  10 +
  11 +public interface DBFactory {
  12 + public DataSource getDataSource();
  13 +}
  1 +/**
  2 + * @version 0.1
  3 + * @describe 数据库链接工厂
  4 + * @author yushigui
  5 + * @date 2014-1-19
  6 + */
  7 +package com.zhonglai.luhui.mqtt.comm.dao;
  8 +
  9 +import org.apache.commons.dbcp.BasicDataSourceFactory;
  10 +
  11 +import javax.sql.DataSource;
  12 +import java.io.File;
  13 +import java.io.FileInputStream;
  14 +import java.sql.Connection;
  15 +import java.sql.SQLException;
  16 +import java.util.Properties;
  17 +
  18 +public class DBFactoryImp implements DBFactory{
  19 + private static DataSource ds = null;
  20 + static {
  21 + try {
  22 + if(null==ds )
  23 + {
  24 + String path = System.getProperty("user.dir")+"/configs/";
  25 + Properties p = new Properties();
  26 + p.load(new FileInputStream(new File(path+"dbcpconfig.properties")));
  27 +// p.load(DBFactory.class
  28 +// .getClassLoader().getResourceAsStream("configs/dbcpconfig.properties"));
  29 + ds = BasicDataSourceFactory.createDataSource(p);
  30 + }
  31 + } catch (Exception e) {
  32 + e.printStackTrace();
  33 + }
  34 + }
  35 +
  36 + public static Connection getConnection() {
  37 + try {
  38 + return ds.getConnection();
  39 + } catch (SQLException e) {
  40 + e.printStackTrace();
  41 + return null;
  42 + }
  43 + }
  44 +
  45 + public DataSource getDataSource(){
  46 + return ds;
  47 + }
  48 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto;
  2 +
  3 +
  4 +
  5 +/**
  6 + * 告警信息
  7 + * @author Administrator
  8 + *
  9 + */
  10 +public class DeviceAlarmInfo {
  11 +
  12 + private String deviceInfoId; //设备id
  13 + private String alarmCode; //告警代码
  14 + private Integer alarmTime; //告警时间
  15 + private Integer isSendNumber; //发送次数
  16 + private Integer alarmState; //告警状态(1发生告警,0结束告警)
  17 +
  18 + public String getDeviceInfoId() {
  19 + return deviceInfoId;
  20 + }
  21 + public void setDeviceInfoId(String deviceInfoId) {
  22 + this.deviceInfoId = deviceInfoId;
  23 + }
  24 + public String getAlarmCode() {
  25 + return alarmCode;
  26 + }
  27 + public void setAlarmCode(String alarmCode) {
  28 + this.alarmCode = alarmCode;
  29 + }
  30 + public Integer getAlarmTime() {
  31 + return alarmTime;
  32 + }
  33 + public void setAlarmTime(Integer alarmTime) {
  34 + this.alarmTime = alarmTime;
  35 + }
  36 + public Integer getIsSendNumber() {
  37 + return isSendNumber;
  38 + }
  39 + public void setIsSendNumber(Integer isSendNumber) {
  40 + this.isSendNumber = isSendNumber;
  41 + }
  42 + public Integer getAlarmState() {
  43 + return alarmState;
  44 + }
  45 + public void setAlarmState(Integer alarmState) {
  46 + this.alarmState = alarmState;
  47 + }
  48 +
  49 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto;
  2 +
  3 +import com.luhui.domain.log.LogDeviceOperation;
  4 +
  5 +/**
  6 + * 设备操作类型
  7 + */
  8 +public enum DeviceOperationTypeEnum {
  9 + CUSTOM(-1,"自定义"),
  10 + DeviceUpgrade(0,"设备远程升级"),
  11 + DeviceReset(1,"设备远程复位"),
  12 + ControllerRemoteManualOpen(2,"远程手动开"),
  13 + ControllerRemoteManualClose(3,"远程手动关"),
  14 + ControllerRemoteAutomaticOpen(4,"远程自动开"),
  15 + ControllerRemoteAutomaticClose(5,"远程自动关"),
  16 + ControllerLocalManualOpen(6,"本地手动开"),
  17 + ControllerLocalManualClose(7,"本地手动关"),
  18 + ControllerLocalAutomaticOpen(8,"本地自动开"),
  19 + ControllerLocalAutomaticClose(9,"本地自动关"),
  20 + OnekeyAutomatic(10,"一键自动"),
  21 + ControllerAllOpen(11,"控制器全开"),
  22 + ControllerAllClose(12,"控制器全关"),
  23 + ControllerTimeSlotLocal(13,"控制器时间段本地设置"),
  24 + ControllerTimeSlotRemote(14,"控制器时间段远程设置"),
  25 + ControllerTimeIntervalLocal(15,"控制器时间间隔本地设置"),
  26 + ControllerTimeIntervalRemote(16,"控制器时间间隔远程设置"),
  27 + DeviceSensorRelationLocal(17,"传感器和控制器关系本地设置"),
  28 + DeviceSensorRelationRemote(18,"传感器和控制器关系远程设置"),
  29 + NoonOxygenRemote(19,"午间增氧时间远程设置"),
  30 + NoonOxygenLocal(20,"午间增氧时间本地设置"),
  31 + CODRemote(21,"COD远程设置"),
  32 + CODLocal(22,"COD本地设置"),
  33 + AmmoniaNitrogenRemote(23,"氨氮远程设置"),
  34 + AmmoniaNitrogenLocal(24,"氨氮本地设置"),
  35 + PHRemote(25,"PH远程设置"),
  36 + PHLocal(26,"PH本地设置"),
  37 + NitriteRemote(27,"亚硝酸盐远程设置"),
  38 + NitriteLocal(28,"亚硝酸盐本地设置"),
  39 + AlgaeRemote(29,"藻类远程设置"),
  40 + AlgaeLocal(30,"藻类本地设置"),
  41 + PipePressureRemote(31,"管道压力远程设置"),
  42 + PipePressureLocal(32,"管道压力本地设置"),
  43 + CurrentSpeedRemote(33,"流速远程设置"),
  44 + CurrentSpeedLocal(34,"流速本地设置"),
  45 + WaterLevelRemote(35,"水位远程设置"),
  46 + WaterLevelLocal(36,"水位本地设置"),
  47 + OxygenMeltingThresholdSettingRemote(37,"溶氧门限远程设置"),
  48 + OxygenMeltingThresholdSettingLocal(38,"溶氧门限本地设置"),
  49 + NightOxygenRemote(39,"夜间增氧时间远程设置"),
  50 + NightOxygenLocal(40,"夜间增氧时间本地设置"),
  51 + ContrastTimeRemote(41,"对表时间远程设置"),
  52 + ContrastTimeLocal(42,"对表时间本地设置"),
  53 + SalinityRemote(43,"盐度远程设置"),
  54 + SalinityLocal(44,"盐度本地设置"),
  55 + KBRemote(45,"KB值远程设置"),
  56 + KBLocal(46,"KB值本地设置"),
  57 + WaterTemperatureRemote(47,"水体温度门限远程设置"),
  58 + WaterTemperatureLocal(48,"水体温度门限本地设置"),
  59 + Device301SetWorkConfig(49,"301工作参数一建设置"),
  60 + Device301ReadWorkConfig(50,"301工作参数读取"),
  61 + DeviceSensorCalibrationLocal(51,"传感器本地校准"),
  62 + DeviceSensorCalibrationRemote(52,"传感器远程校准"),
  63 + DeviceTimeToTime(53,"主机对表"),
  64 + PLCWaterPushTimeSlotLocal(54,"PLC推水时段本地设置"),
  65 + PLCWaterPushTimeSlotRemote(55,"PLC推水时段远程设置"),
  66 + PLCFoulingTimeLocal(56,"PLC吸污时间段本地设置"),
  67 + PLCFoulingTimeRemote(57,"PLC吸污时间段远程设置"),
  68 + PLCOxygenIncreasingTimeLocal(58,"PLC增氧时间段本地设置"),
  69 + PLCOxygenIncreasingTimeRemote(59,"PLC增氧时间段远程设置"),
  70 + PLCFeedingTimeLocal(60,"PLC投饵时间段本地设置"),
  71 + PLCFeedingTimeRemote(61,"PLC投饵时间段远程设置"),
  72 + PLCSpareTimeLocal(62,"PLC备用时间段本地设置"),
  73 + PLCSpareTimeRemote(63,"PLC备用时间段远程设置"),
  74 + DeviceSensorchange(64,"传感器切换"),
  75 + DeviceHaveUpdatedVersion(65,"有更新版本"),
  76 + DeviceForcedUpdatesRequired(66,"需要强制更新版本"),
  77 + ControllerTypeLocal(67,"控制器类型本地设置"),
  78 + ControllerTypeRemote(68,"控制器类型远程设置"),
  79 + UnknownOperation(69,"未知操作"),
  80 + Voltage(70,"电压设置"),
  81 + LeakageCurrent(71,"漏电流设置"),
  82 + Power(72,"功率设置"),
  83 + AirTemperature(73,"气温设置"),
  84 + TemperatureStep(74,"温度步长设置"),
  85 + Current(75,"电流限制设置"),
  86 + LeakageDetectionTime(76,"漏电检测时间设置"),
  87 + LeakageDetectionInterval(77,"漏电检测间隔设置"),
  88 + PowerLimits(78,"功率限制设置"),
  89 + LeakageTest(79,"漏电测试"),
  90 + LedTest(80,"LED测试"),
  91 + ControllerTimeSlotRemoteGET(81,"控制器时间段远程获取"),
  92 + ManDunControllerSceneTime(82,"控制器场景时间段远程设置"),
  93 + ManDunControllerSceneTimeEXE(83,"执行场景预定义的开关控制序列"),
  94 + ManDunControllerRestartCommunication(84,"重启通讯模块"),
  95 + ManDunControllerDelTime(85,"删除定时操作"),
  96 + ManDunModifyLineName(86,"修改线路名称"),
  97 + ManDunModifyLeakageSelfTestTime(87,"修改漏电自检时间"),
  98 + ManDunSwitchRemoteControlBit(88,"开关远程控制位"),
  99 + ManDunModifySwitchDisplayBit(89,"修改开关显示位"),
  100 + ManDunModifySwitchWiringMode(90,"修改开关接线方式"),
  101 + ManDunModifyPowerLimit(91,"修改功率限额"),
  102 + ManDunModifyVoltageLimit(92,"修改电压限额"),
  103 + ManDunModifyCurrentLimit(93,"修改电流限额"),
  104 + ManDunModifyLeakageCurrentLimit(94,"修改漏电流限额"),
  105 + ManDunModifyTemperatureLimit(95,"修改温度限额"),
  106 + ManDunModifyElectricalAppliances(96,"修改电器"),
  107 + ManDunModifyRealTimeDataUploadInterval(97,"修改实时数据上传间隔 RTVI"),
  108 + ManDunModifyWiFiParameters(98,"修改开关显示位"),
  109 + ManDunModifyTimeZone(99,"修改时区"),
  110 + ManDunModifyDevicePassword(100,"修改开关显示位"),
  111 + ManDunModifyRealTimeDataUploadIntervalTemp(101,"临时修改实时数据间隔 RTVI(掉电不保存)"),
  112 + ManDunModifyServerPoint(102,"修改服务器指向"),
  113 + ManDunModifyNetworkAddress(103,"修改网络地址"),
  114 + ManDunModifyCurrentCalibrationFactor(104,"修改电流校准系数(仅 E9支持)"),
  115 + ManDunModifyServerPointDomain (105,"修改服务器指向(支持域名)"),
  116 + UP_CHANGE_ADDRESS(106,"修改编号"),
  117 + ControllerOperation(107,"远程操作开关"),
  118 +
  119 + UP_R1(108,"修改节能模式的转速"),
  120 + UP_R2(109,"修改对流模式的转速"),
  121 + UP_R3(110,"修改增强模式的转速"),
  122 + UP_IS(111,"修改设置启停电流"),
  123 + UP_RP(112,"修改设置最大转速值"),
  124 + UP_FB(113,"修改使能异常检测及正反转"),
  125 + UP_RMR(114,"修改设置开机默认挡位"),
  126 + UP_RM(115,"修改开关模式挡位"),
  127 +
  128 + QiYaRemote(116,"气压远程设置"),
  129 +
  130 + CLOS(117,"链接关闭"),
  131 + ControllerTimeModeRemote(118,"控制器时间模式远程设置"),
  132 +
  133 + ;
  134 +
  135 + public Integer type; //类型
  136 + public String name; //名称
  137 +
  138 + DeviceOperationTypeEnum(Integer type, String name)
  139 + {
  140 + this.type = type;
  141 + this.name = name;
  142 + }
  143 +
  144 + public void setDeviceOperationLog(LogDeviceOperation logDeviceOperation)
  145 + {
  146 + logDeviceOperation.setDeviceOperationType(type);
  147 + logDeviceOperation.setOperationDescribe(name);
  148 + }
  149 +
  150 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class LogDeviceOperation {
  7 + private Integer deviceOperationId; //设备操作日志id
  8 + private String deviceInfoId; //设备信息id
  9 + private Integer deviceOperationTime; //设备操作时间
  10 + private String operationInstruction; //设备操作指令
  11 + private String operationDescribe; //设备操作描述
  12 + private String deviceOldState; //设备操作前状态
  13 + private String deviceNewState; //设备操作后的状态
  14 + private Integer deviceOperationType; //设备操作类型
  15 + private String sensorOrController; //传感器或控制器编号(控制器以00_开头)
  16 + private Integer isStateChange; //是否有状态改变(0否,1是)
  17 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto;
  2 +
  3 +import com.luhui.ly.service.comm.nio.util.TableUtil;
  4 +
  5 +import java.util.Date;
  6 +
  7 +public enum TableGenerateSqlEnum {
  8 +
  9 + //设备传感器数据
  10 + DeviceSensorData("设备传感器数据数据库","ly_sensor_data",
  11 + "device_sensor_data",
  12 + 3,
  13 + "CREATE TABLE IF NOT EXISTS `device_sensor_data` ("+
  14 + "`device_info_id` varchar(50) NOT NULL COMMENT '设备信息id',"+
  15 + "`data_type` varchar(50) NOT NULL COMMENT '数据类型',"+
  16 + "`data_value` varchar(50) NOT NULL COMMENT '数据值',"+
  17 + "`creat_time` int(11) NOT NULL COMMENT '创建时间',"+
  18 + "`device_model` varchar(10) DEFAULT NULL COMMENT '设备型号,(3,5,6,6_P)',"+
  19 + "KEY `device_info_id` (`device_info_id`,`data_type`,`creat_time`)"+
  20 + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"
  21 + ),
  22 + //管理员操作日志
  23 + LogSysUserOperation("管理员操作日志数据库","ly_sys_user_operation",
  24 + "log_sys_user_operation",
  25 + 2,
  26 + "CREATE TABLE IF NOT EXISTS `log_sys_user_operation` (" +
  27 + " `operation_name` varchar(50) NOT NULL COMMENT '操作名称'," +
  28 + " `operation_ip` varchar(50) DEFAULT NULL COMMENT '操作ip'," +
  29 + " `operation_url` varchar(200) DEFAULT NULL COMMENT '操作连接'," +
  30 + " `operation_value` text COMMENT '操作值'," +
  31 + " `user_id` int(11) DEFAULT NULL COMMENT '用户id'," +
  32 + " `user_login_name` varchar(50) DEFAULT NULL COMMENT '用户名称'," +
  33 + " `user_nickname` varchar(50) DEFAULT NULL COMMENT '用户昵称'," +
  34 + " `create_time` int(11) NOT NULL COMMENT '创建时间'," +
  35 + " `module` varchar(50) DEFAULT NULL COMMENT '操作模块'" +
  36 + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"
  37 + ),
  38 + //设备操作日志
  39 + LogDeviceOperation("设备操作日志数据库","ly_log_device_operation",
  40 + "log_device_operation",
  41 + 3,
  42 + "CREATE TABLE IF NOT EXISTS `log_device_operation` (" +
  43 + " `device_operation_id` int(11) NOT NULL AUTO_INCREMENT," +
  44 + " `device_info_id` varchar(50) NOT NULL COMMENT '设备id'," +
  45 + " `device_operation_time` int(11) NOT NULL COMMENT '设备操作时间'," +
  46 + " `operation_instruction` text COMMENT '设备操作指令'," +
  47 + " `operation_describe` varchar(50) DEFAULT NULL COMMENT '设备操作描述'," +
  48 + " `device_old_state` text COMMENT '设备操作前状态'," +
  49 + " `device_new_state` text COMMENT '设备操作后的状态'," +
  50 + " `device_operation_type` varchar(11) DEFAULT NULL COMMENT '设备操作类型'," +
  51 + " `sensor_or_controller` varchar(50) DEFAULT '00' COMMENT '传感器或控制器编号(控制器以00_开头)'," +
  52 + " `is_state_change` int(11) DEFAULT '0' COMMENT '是否有状态改变(0否,1是)'," +
  53 + " PRIMARY KEY (`device_operation_id`)" +
  54 + ") ENGINE=InnoDB AUTO_INCREMENT=3677 DEFAULT CHARSET=utf8"
  55 + ),
  56 + //用户登录日志
  57 + UserLoginLog("用户登录日志数据库","ly_user_login",
  58 + "user_login_log",
  59 + 2,
  60 + "CREATE TABLE IF NOT EXISTS `user_login_log` (" +
  61 + " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  62 + " `user_id` int(11) NOT NULL COMMENT '用户id'," +
  63 + " `user_login_name` varchar(50) NOT NULL COMMENT '用户登录名'," +
  64 + " `user_nickname` varchar(50) NOT NULL COMMENT '用户姓名'," +
  65 + " `user_type` int(11) NOT NULL DEFAULT '0' COMMENT '用户类型,默认0-普通用户,1-管理员,2客服'," +
  66 + " `login_province_id` varchar(50) DEFAULT NULL COMMENT '登录省份id'," +
  67 + " `login_city_id` varchar(50) DEFAULT NULL COMMENT '登录城市id'," +
  68 + " `login_province_name` varchar(50) DEFAULT NULL COMMENT '登录省份名'," +
  69 + " `login_city_name` varchar(50) DEFAULT NULL COMMENT '登录城市名'," +
  70 + " `login_address` varchar(50) DEFAULT NULL COMMENT '登陆地址'," +
  71 + " `login_ip` varchar(50) DEFAULT NULL COMMENT '登录ip'," +
  72 + " `create_time` int(11) NOT NULL COMMENT '登陆时间'," +
  73 + " PRIMARY KEY (`id`)" +
  74 + ") ENGINE=InnoDB AUTO_INCREMENT=916 DEFAULT CHARSET=utf8"
  75 + ),
  76 + //管理员登录日志
  77 + SysUserLoginLog("管理员登录日志数据库","ly_sys_user_login",
  78 + "sys_user_login_log",
  79 + 1,
  80 + "CREATE TABLE IF NOT EXISTS `sys_user_login_log` (" +
  81 + " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  82 + " `user_login_name` varchar(50) NOT NULL COMMENT '用户登录名'," +
  83 + " `user_phone` varchar(50) NOT NULL COMMENT '用户电话'," +
  84 + " `login_province_id` varchar(50) DEFAULT NULL COMMENT '登录省份id'," +
  85 + " `login_city_id` varchar(50) DEFAULT NULL COMMENT '登录城市id'," +
  86 + " `login_province_name` varchar(50) DEFAULT NULL COMMENT '登录省份名'," +
  87 + " `login_city_name` varchar(50) DEFAULT NULL COMMENT '登录城市名'," +
  88 + " `login_address` varchar(50) DEFAULT NULL COMMENT '登陆地址'," +
  89 + " `login_ip` varchar(50) DEFAULT NULL COMMENT '登录ip'," +
  90 + " `create_time` int(11) NOT NULL COMMENT '登陆时间'," +
  91 + " PRIMARY KEY (`id`)" +
  92 + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"
  93 + ),
  94 + //用户操作日志
  95 + LogUserOperation("用户操作日志数据库","ly_user_operation",
  96 + "log_user_operation",
  97 + 3,
  98 + "CREATE TABLE IF NOT EXISTS `log_user_operation` (" +
  99 + " `operation_name` varchar(50) NOT NULL COMMENT '操作名称'," +
  100 + " `operation_ip` varchar(50) DEFAULT NULL COMMENT '操作ip'," +
  101 + " `operation_url` varchar(200) DEFAULT NULL COMMENT '操作连接'," +
  102 + " `operation_value` text COMMENT '操作值'," +
  103 + " `user_id` int(11) DEFAULT NULL COMMENT '用户id'," +
  104 + " `user_login_name` varchar(50) DEFAULT NULL COMMENT '用户名称'," +
  105 + " `user_nickname` varchar(50) DEFAULT NULL COMMENT '用户昵称'," +
  106 + " `create_time` int(11) NOT NULL COMMENT '创建时间'," +
  107 + " `module` varchar(50) DEFAULT NULL COMMENT '操作模块'," +
  108 + " `my_user_id` varchar(45) DEFAULT NULL COMMENT '我的用户id'," +
  109 + " `my_user_login_name` varchar(45) DEFAULT NULL COMMENT '我的用户名称'," +
  110 + " `my_user_nickname` varchar(45) DEFAULT NULL COMMENT '我的用户昵称'" +
  111 + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"
  112 + ),
  113 + //用户积分信息记录
  114 + UserIntegral("用户积分信息记录数据库","ly_user_integral",
  115 + "user_integral",
  116 + 2,
  117 + "CREATE TABLE IF NOT EXISTS `user_integral` (" +
  118 + " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  119 + " `user_id` int(11) DEFAULT NULL COMMENT '用户id'," +
  120 + " `integral_before` int(11) DEFAULT NULL COMMENT '操作前积分数'," +
  121 + " `integral_end` int(11) DEFAULT NULL COMMENT '操作后积分数'," +
  122 + " `integral_number` int(11) DEFAULT NULL COMMENT '积分数量'," +
  123 + " `integral_type` int(11) DEFAULT NULL COMMENT '积分类型'," +
  124 + " `integral_type_name` varchar(50) DEFAULT NULL COMMENT '积分信息'," +
  125 + " `create_time` int(11) DEFAULT NULL COMMENT '创建时间'," +
  126 + " `remark` varchar(50) DEFAULT NULL COMMENT '备注'," +
  127 + " PRIMARY KEY (`id`)" +
  128 + ") ENGINE=InnoDB AUTO_INCREMENT=4559 DEFAULT CHARSET=utf8"
  129 + ),
  130 + //告警信息
  131 + DeviceAlarmInfo("告警信息数据库","ly_device_alarm_info",
  132 + "device_alarm_info",
  133 + 3,
  134 + "CREATE TABLE IF NOT EXISTS `device_alarm_info` (" +
  135 + " `alarm_info_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  136 + " `device_info_id` varchar(50) NOT NULL COMMENT '设备id'," +
  137 + " `alarm_code` varchar(50) NOT NULL COMMENT '告警代码'," +
  138 + " `alarm_time` int(11) DEFAULT NULL COMMENT '告警时间'," +
  139 + " `is_send_number` int(11) DEFAULT '0' COMMENT '发送次数'," +
  140 + " `alarm_state` int(11) DEFAULT '0' COMMENT '告警状态(1发生告警,0结束告警)'," +
  141 + " PRIMARY KEY (`alarm_info_id`)" +
  142 + ") ENGINE=InnoDB AUTO_INCREMENT=399144 DEFAULT CHARSET=utf8"
  143 + ),
  144 + //用户分享
  145 + UserShare("用户分享数据库","ly_user_share",
  146 + "user_share",
  147 + 2,
  148 + "CREATE TABLE IF NOT EXISTS `user_share` (" +
  149 + " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  150 + " `user_id` int(11) NOT NULL COMMENT '用户id'," +
  151 + " `user_login_name` varchar(50) NOT NULL COMMENT '用户登录名称'," +
  152 + " `share_content` text COMMENT '分享内容'," +
  153 + " `share_time` int(11) NOT NULL COMMENT '分享时间'," +
  154 + " `share_type` int(11) NOT NULL COMMENT '分享类型(注:1-首页分享,2-曲线分享,3-病害报表分享,4-多天曲线分享)'," +
  155 + " `random_number` int(11) DEFAULT NULL COMMENT '随机数'," +
  156 + " PRIMARY KEY (`id`)" +
  157 + ") ENGINE=InnoDB AUTO_INCREMENT=1301 DEFAULT CHARSET=utf8"
  158 + ),
  159 + //用户等级记录
  160 + UserLevel("用户等级记录","ly_user_level",
  161 + "log_user_level",
  162 + 2,
  163 + "CREATE TABLE IF NOT EXISTS `log_user_level` (" +
  164 + " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  165 + " `user_id` int(11) NOT NULL COMMENT '用户id'," +
  166 + " `user_login_name` varchar(50) NOT NULL COMMENT '用户登录名称'," +
  167 + " `operation` varchar(50) NOT NULL COMMENT '操作描述'," +
  168 + " `create_time` int(11) NOT NULL COMMENT '创建时间'," +
  169 + " `level` int(11) NOT NULL COMMENT '积分(可以为负数)'," +
  170 + " `use_type` int(11) NOT NULL COMMENT '使用类型'," +
  171 + " `order_id` int(11) NOT NULL COMMENT '关联支付表id'," +
  172 +
  173 + " PRIMARY KEY (`id`)" +
  174 + ") ENGINE=InnoDB AUTO_INCREMENT=1301 DEFAULT CHARSET=utf8"
  175 + ),
  176 + //用户货币记录
  177 + UserCurrency("用户货币记录","ly_user_currency",
  178 + "log_user_currency",
  179 + 2,
  180 + "CREATE TABLE IF NOT EXISTS `log_user_currency` (" +
  181 + " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id'," +
  182 + " `user_id` int(11) NOT NULL COMMENT '用户id'," +
  183 + " `user_login_name` varchar(50) NOT NULL COMMENT '用户登录名称'," +
  184 + " `operation` varchar(50) NOT NULL COMMENT '操作描述'," +
  185 + " `create_time` int(11) NOT NULL COMMENT '创建时间'," +
  186 + " `currency` int(11) NOT NULL COMMENT '货币数(可以为负数)'," +
  187 + " `use_type` int(11) NOT NULL COMMENT '使用类型'," +
  188 + " `order_id` int(11) NOT NULL COMMENT '关联支付表id'," +
  189 + " PRIMARY KEY (`id`)" +
  190 + ") ENGINE=InnoDB AUTO_INCREMENT=1301 DEFAULT CHARSET=utf8"
  191 + ),
  192 + Device301Sensitivity("301传感器灵敏度数据","ly_device301_sensitivity","device301_sensitivity",
  193 + 2,
  194 + "CREATE TABLE IF NOT EXISTS `device301_sensitivity` (" +
  195 + " `device_info_id` varchar(50) NOT NULL COMMENT '设备信息表id'," +
  196 + " `pump_current` varchar(10) DEFAULT NULL COMMENT '水泵电流'," +
  197 + " `leakage_current` varchar(10) DEFAULT NULL COMMENT '泄露电流'," +
  198 + " `magnification` varchar(10) DEFAULT NULL COMMENT '放大倍数'," +
  199 + " `sensor_sensitivity` varchar(10) DEFAULT NULL COMMENT '传感器灵敏度'," +
  200 + " `sensor_accuracy` varchar(10) DEFAULT NULL COMMENT '传感器准确度'," +
  201 + " `create_time` int(11) NOT NULL COMMENT '添加时间'" +
  202 + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8"),
  203 + LogSyswebErr("系统运行错误日志","ly_sysweb_err","log_sysweb_err",2,
  204 + "CREATE TABLE IF NOT EXISTS `log_sysweb_err` (" +
  205 + " `create_time` int(11) DEFAULT NULL COMMENT '创建时间'," +
  206 + " `url` varchar(200) DEFAULT NULL COMMENT '请求链接'," +
  207 + " `parameter_value` text COMMENT '参数'," +
  208 + " `err_message` text COMMENT '错误信息'" +
  209 + ") ENGINE=InnoDB DEFAULT CHARSET=utf8")
  210 + ;
  211 +
  212 + public String alias; //别名
  213 + public String dateBaseName; //数据库名称
  214 + public String tableName; //表名
  215 + public String generateSql; //创建sql
  216 + public int accuracy; //表类型(1年表,2月表,3日表)
  217 +
  218 + TableGenerateSqlEnum(String alias, String dateBaseName, String tableName, int accuracy, String generateSql)
  219 + {
  220 + this.alias = alias;
  221 + this.dateBaseName = dateBaseName;
  222 + this.tableName = tableName;
  223 + this.accuracy = accuracy;
  224 + this.generateSql = generateSql;
  225 + }
  226 +
  227 + public String getTableName(Date date)
  228 + {
  229 + return TableUtil.getTableName(date, dateBaseName, tableName,accuracy);
  230 + }
  231 +
  232 + public String getNowTableName()
  233 + {
  234 + return TableUtil.getNowTableName( dateBaseName, tableName,accuracy);
  235 + }
  236 + public String getTableName(String date)
  237 + {
  238 + return TableUtil.getTableName( date,dateBaseName, tableName,accuracy);
  239 + }
  240 +
  241 + public String getTableName(Integer date)
  242 + {
  243 + return getTableName(new Date(date*1000l));
  244 + }
  245 +}
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
  3 +import com.ruoyi.common.utils.DateUtils;
  4 +import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
  5 +import com.zhonglai.luhui.mqtt.comm.dto.*;
  6 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  7 +import com.zhonglai.luhui.mqtt.comm.util.TableUtil;
3 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
4 9
5 import java.util.ArrayList; 10 import java.util.ArrayList;
@@ -31,7 +36,7 @@ public abstract class DataPersistenceService { @@ -31,7 +36,7 @@ public abstract class DataPersistenceService {
31 operateHis.setDeviceNewState(deviceNewState); 36 operateHis.setDeviceNewState(deviceNewState);
32 } 37 }
33 operateHis.setIsStateChange(1); 38 operateHis.setIsStateChange(1);
34 - operateHis.setDeviceOperationTime(CommonUtil.getNowTimeMilly()); 39 + operateHis.setDeviceOperationTime(DateUtils.getNowTimeMilly());
35 40
36 operateHisList.add(operateHis); 41 operateHisList.add(operateHis);
37 baseDao.insertList(operateHisList, TableGenerateSqlEnum.LogDeviceOperation.getNowTableName()); 42 baseDao.insertList(operateHisList, TableGenerateSqlEnum.LogDeviceOperation.getNowTableName());
@@ -66,7 +71,7 @@ public abstract class DataPersistenceService { @@ -66,7 +71,7 @@ public abstract class DataPersistenceService {
66 { 71 {
67 DeviceAlarmInfo deviceAlarmInfo = new DeviceAlarmInfo(); 72 DeviceAlarmInfo deviceAlarmInfo = new DeviceAlarmInfo();
68 deviceAlarmInfo.setDeviceInfoId(deviceInfoId); 73 deviceAlarmInfo.setDeviceInfoId(deviceInfoId);
69 - deviceAlarmInfo.setAlarmTime(CommonUtil.getNowTimeMilly()); 74 + deviceAlarmInfo.setAlarmTime(DateUtils.getNowTimeMilly());
70 deviceAlarmInfo.setAlarmState(1); 75 deviceAlarmInfo.setAlarmState(1);
71 deviceAlarmInfo.setAlarmCode("09"); 76 deviceAlarmInfo.setAlarmCode("09");
72 deviceAlarmInfo.setIsSendNumber(0); 77 deviceAlarmInfo.setIsSendNumber(0);
1 package com.zhonglai.luhui.mqtt.comm.util; 1 package com.zhonglai.luhui.mqtt.comm.util;
2 2
3 -import com.google.gson.JsonObject; 3 +import com.alibaba.fastjson.JSONObject;
4 import org.apache.commons.lang3.StringUtils; 4 import org.apache.commons.lang3.StringUtils;
5 5
6 public class ChangUtil { 6 public class ChangUtil {
7 - public static boolean changString(JsonObject oldData, String strName, String strValue) 7 + public static boolean changString(JSONObject oldData, String strName, String strValue)
8 { 8 {
9 if(StringUtils.isNoneBlank(strValue)) 9 if(StringUtils.isNoneBlank(strValue))
10 { 10 {
11 - if(!oldData.has(strName) || !strValue.equals(oldData.get(strName).getAsString())) 11 + if(!oldData.containsKey(strName) || !strValue.equals(oldData.getString(strName)))
12 { 12 {
13 - oldData.addProperty(strName,strValue); 13 + oldData.put(strName,strValue);
14 return true; 14 return true;
15 } 15 }
16 } 16 }
17 return false; 17 return false;
18 } 18 }
19 19
20 - public static boolean changInt(JsonObject oldData, String intName, Integer intValue) 20 + public static boolean changInt(JSONObject oldData, String intName, Integer intValue)
21 { 21 {
22 if(null != intValue) 22 if(null != intValue)
23 { 23 {
24 - if(!oldData.has(intName) || intValue -oldData.get(intName).getAsInt() != 0 ) 24 + if(!oldData.containsKey(intName) || intValue -oldData.getInteger(intName) != 0 )
25 { 25 {
26 - oldData.addProperty(intName,intValue); 26 + oldData.put(intName,intValue);
27 return true; 27 return true;
28 } 28 }
29 } 29 }
30 return false; 30 return false;
31 } 31 }
32 32
33 - public static boolean changFloat(JsonObject oldData, String intName, Float intValue) 33 + public static boolean changFloat(JSONObject oldData, String intName, Float intValue)
34 { 34 {
35 if(null != intValue) 35 if(null != intValue)
36 { 36 {
37 - if(!oldData.has(intName) || intValue -oldData.get(intName).getAsFloat() != 0 ) 37 + if(!oldData.containsKey(intName) || intValue -oldData.getFloat(intName) != 0 )
38 { 38 {
39 - oldData.addProperty(intName,intValue); 39 + oldData.put(intName,intValue);
40 return true; 40 return true;
41 } 41 }
42 } 42 }
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +
  4 +import com.ruoyi.common.utils.DateUtils;
  5 +
  6 +import java.util.Date;
  7 +
  8 +public class TableUtil {
  9 + public TableUtil() {
  10 + }
  11 +
  12 + public static String getNowTableName(String dateBase, String tableName, int accuracy) {
  13 + return getTableName(getTimeToString(), dateBase, tableName, accuracy);
  14 + }
  15 +
  16 + public static String getTableName(Date date, String dateBase, String tableName, int accuracy) {
  17 + return getTableName(getTimeToString(date), dateBase, tableName, accuracy);
  18 + }
  19 +
  20 + public static String getTableName(String date, String dateBase, String tableName, int accuracy) {
  21 + String[] datas = date.split("-");
  22 + dateBase = dateBase + "_" + datas[0];
  23 + if (0 == accuracy) {
  24 + tableName = tableName + "";
  25 + } else if (1 == accuracy) {
  26 + tableName = tableName + "_" + datas[0];
  27 + } else if (2 == accuracy) {
  28 + tableName = tableName + "_" + datas[0] + datas[1];
  29 + } else if (3 == accuracy) {
  30 + tableName = tableName + "_" + datas[0] + datas[1] + datas[2];
  31 + } else {
  32 + tableName = tableName + "_" + datas[0] + datas[1] + datas[2];
  33 + }
  34 +
  35 + return dateBase + "." + tableName;
  36 + }
  37 +
  38 + public static String getTimeToString(long dateValue) {
  39 + return DateUtils.parseDateToStr( "yyyy-MM-dd",new Date(dateValue));
  40 + }
  41 +
  42 + public static String getTimeToString(int dateValue) {
  43 + return DateUtils.parseDateToStr("yyyy-MM-dd",new Date((long)dateValue * 1000L));
  44 + }
  45 +
  46 + public static String getTimeToString(Date dateValue) {
  47 + return DateUtils.parseDateToStr("yyyy-MM-dd",dateValue);
  48 + }
  49 +
  50 + public static String getTimeToString() {
  51 + return DateUtils.parseDateToStr("yyyy-MM-dd",new Date());
  52 + }
  53 +}
1 package com.zhonglai.luhui.mqtt.service; 1 package com.zhonglai.luhui.mqtt.service;
2 2
3 -import com.luhui.ly.device.mqtt.comm.dto.ServerDto;  
4 -import com.luhui.ly.device.mqtt.comm.factory.Topic;  
5 -import com.luhui.ly.device.mqtt.comm.service.CacheService; 3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  5 +import com.zhonglai.luhui.mqtt.comm.service.CacheService;
6 import com.zhonglai.luhui.mqtt.dto.PutReqDto; 6 import com.zhonglai.luhui.mqtt.dto.PutReqDto;
7 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
8 8
1 package com.zhonglai.luhui.mqtt.service; 1 package com.zhonglai.luhui.mqtt.service;
2 2
3 -import com.luhui.ly.device.mqtt.comm.dto.ServerDto;  
4 -import com.luhui.ly.device.mqtt.comm.factory.Topic;  
5 -import com.luhui.ly.device.mqtt.comm.service.DataPersistenceService; 3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  5 +import com.zhonglai.luhui.mqtt.comm.service.DataPersistenceService;
6 import org.slf4j.Logger; 6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 7 import org.slf4j.LoggerFactory;
8 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
1 package com.zhonglai.luhui.mqtt.service; 1 package com.zhonglai.luhui.mqtt.service;
2 2
3 -import com.luhui.ly.device.mqtt.comm.service.TopicsService; 3 +import com.zhonglai.luhui.mqtt.comm.service.TopicsService;
4 import org.springframework.stereotype.Service; 4 import org.springframework.stereotype.Service;
5 5
6 @Service 6 @Service
@@ -576,4 +576,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils @@ -576,4 +576,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
576 } 576 }
577 return sb.toString(); 577 return sb.toString();
578 } 578 }
  579 +
  580 + /**
  581 + * [简要描述]:首字母大写
  582 + *
  583 + * @author com.zhonglai
  584 + * @param str
  585 + * @return
  586 + */
  587 + public static String getName(String str) {
  588 + char ch = str.toCharArray()[0];
  589 + ch = (char) ((ch - 97) + 'A');
  590 + str = ch + str.substring(1);
  591 + return str;
  592 + }
579 } 593 }