Commit 0dd1527b by songxiang

模板消息发送增加来源分类和类型

parent 8b4e8aee
package com.pcloud.common.core.dao; package com.pcloud.common.core.dao;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.SqlSessionTemplate;
import com.pcloud.common.page.PageBean; import com.pcloud.common.page.PageBean;
import com.pcloud.common.page.PageBeanNew; import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam; import com.pcloud.common.page.PageParam;
/** /**
* @描述:数据访问层基础支撑接口. @作者:DiSeng.H * @描述:数据访问层基础支撑接口. @作者:DiSeng.H
* @创建时间:2016年3月11日,下午4:02:32 @版本:1.0 * @创建时间:2016年3月11日,下午4:02:32 @版本:1.0
*/ */
public interface BaseDao<T> { public interface BaseDao<T> {
/** /**
* 根据实体对象新增记录. * 根据实体对象新增记录.
* *
* @param entity * @param entity .
* . * @return id .
* @return id . */
*/ long insert(T entity);
long insert(T entity);
/**
/** * 批量保存对象.
* 批量保存对象. *
* * @param entity .
* @param entity * @return id .
* . */
* @return id . long insert(List<T> list);
*/
long insert(List<T> list); /**
* 更新实体对应的记录.
/** *
* 更新实体对应的记录. * @param entity .
* * @return
* @param entity */
* . long update(T entity);
* @return
*/ /**
long update(T entity); * 更新实体对应的记录.
*
/** * @param entity
* 更新实体对应的记录. * @param sqlId
* * @return
* @param entity */
* @param sqlId long update(T entity, String sqlId);
* @return
*/ /**
long update(T entity, String sqlId); * 更新实体对应的记录.
*
/** * @param entity
* 批量更新对象. * @param sqlId
* * @param errorMessage 错误消息
* @param entity * @return
* . */
* @return int . long update(T entity, String sqlId, String errorMessage);
*/
long update(List<T> list); /**
* 批量更新对象.
/** *
* 根据ID查找记录. * @param entity .
* * @return int .
* @param id */
* . long update(List<T> list);
* @return entity .
*/ /**
T getById(long id); * 根据ID查找记录.
*
/** * @param id .
* 根据ID删除记录. * @return entity .
* */
* @param id T getById(long id);
* .
* @return /**
*/ * 根据ID删除记录.
long deleteById(long id); *
* @param id .
/** * @return
* 分页查询 . */
* long deleteById(long id);
* @param pageParam
* 分页参数. /**
* @param paramMap * 分页查询 .
* 业务条件查询参数. *
* @return * @param pageParam 分页参数.
*/ * @param paramMap 业务条件查询参数.
PageBean listPage(PageParam pageParam, Map<String, Object> paramMap); * @return
*/
PageBean listSimplePage(PageParam pageParam, Map<String, Object> paramMap, String sqlId); PageBean listPage(PageParam pageParam, Map<String, Object> paramMap);
PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId); PageBean listSimplePage(PageParam pageParam, Map<String, Object> paramMap, String sqlId);
<C> PageBeanNew<C> listPageNew(PageParam pageParam, Map<String, Object> paramMap, String sqlId); PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId);
PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId, String countSqlId); <C> PageBeanNew<C> listPageNew(PageParam pageParam, Map<String, Object> paramMap, String sqlId);
/** PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId, String countSqlId);
* 根据条件查询 listBy: <br/>
* /**
* @param paramMap * 根据条件查询 listBy: <br/>
* @return 返回集合 *
*/ * @param paramMap
List<T> listBy(Map<String, Object> paramMap); * @return 返回集合
*/
List<Object> listBy(Map<String, Object> paramMap, String sqlId); List<T> listBy(Map<String, Object> paramMap);
/** List<Object> listBy(Map<String, Object> paramMap, String sqlId);
* 根据条件查询 listBy: <br/>
* /**
* @param paramMap * 根据条件查询 listBy: <br/>
* @return 返回实体 *
*/ * @param paramMap
T getBy(Map<String, Object> paramMap); * @return 返回实体
*/
Object getBy(Map<String, Object> paramMap, String sqlId); T getBy(Map<String, Object> paramMap);
/** Object getBy(Map<String, Object> paramMap, String sqlId);
* 根据序列名称获取下一个值
* /**
* @return * 根据序列名称获取下一个值
*/ *
String getSeqNextValue(String seqName); * @return
*/
SqlSessionTemplate getSessionTemplate(); String getSeqNextValue(String seqName);
SqlSession getSqlSession(); SqlSessionTemplate getSessionTemplate();
}
SqlSession getSqlSession();
}
package com.pcloud.common.core.dao; package com.pcloud.common.core.dao;
import java.sql.Connection; import java.sql.Connection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.ibatis.jdbc.SqlRunner; import com.pcloud.common.utils.string.StringUtil;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.jdbc.SqlRunner;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate; import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger; import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.LoggerFactory; import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.druid.pool.DruidDataSource;
import com.pcloud.common.core.mybatis.interceptor.ExecutorInterceptor; import com.alibaba.druid.pool.DruidDataSource;
import com.pcloud.common.entity.BaseEntity; import com.pcloud.common.core.mybatis.interceptor.ExecutorInterceptor;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.entity.BaseEntity;
import com.pcloud.common.page.PageBean; import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew; import com.pcloud.common.page.PageBean;
import com.pcloud.common.page.PageParam; import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
/**
* @描述:数据访问层基础支撑类. @作者:DiSeng.H /**
* @创建时间:2016年3月11日,下午4:03:36 @版本:1.0 * @描述:数据访问层基础支撑类. @作者:DiSeng.H
*/ * @创建时间:2016年3月11日,下午4:03:36 @版本:1.0
public abstract class BaseDaoImpl<T extends BaseEntity> implements BaseDao<T> { */
public abstract class BaseDaoImpl<T extends BaseEntity> implements BaseDao<T> {
protected static final Logger logger = LoggerFactory.getLogger(BaseDaoImpl.class);
protected static final Logger logger = LoggerFactory.getLogger(BaseDaoImpl.class);
public static final String SQL_INSERT = "insert";
public static final String SQL_BATCH_INSERT = "batchInsert"; public static final String SQL_INSERT = "insert";
public static final String SQL_UPDATE = "update"; public static final String SQL_BATCH_INSERT = "batchInsert";
public static final String SQL_GET_BY_ID = "getById"; public static final String SQL_UPDATE = "update";
public static final String SQL_DELETE_BY_ID = "deleteById"; public static final String SQL_GET_BY_ID = "getById";
public static final String SQL_LIST_PAGE = "listPage"; public static final String SQL_DELETE_BY_ID = "deleteById";
public static final String SQL_LIST_BY = "listBy"; public static final String SQL_LIST_PAGE = "listPage";
public static final String SQL_COUNT_BY_PAGE_PARAM = "countByPageParam"; // 根据当前分页参数进行统计 public static final String SQL_LIST_BY = "listBy";
public static final String SQL_COUNT_BY_PAGE_PARAM = "countByPageParam"; // 根据当前分页参数进行统计
/**
* 注入SqlSessionTemplate实例(要求Spring中进行SqlSessionTemplate的配置).<br/> /**
* 可以调用sessionTemplate完成数据库操作. * 注入SqlSessionTemplate实例(要求Spring中进行SqlSessionTemplate的配置).<br/>
*/ * 可以调用sessionTemplate完成数据库操作.
@Autowired */
protected SqlSessionTemplate sqlSessionTemplate; @Autowired
protected SqlSessionTemplate sqlSessionTemplate;
@Autowired
protected SqlSessionFactory sqlSessionFactory; @Autowired
protected SqlSessionFactory sqlSessionFactory;
@Autowired
private DruidDataSource druidDataSource; @Autowired
private DruidDataSource druidDataSource;
public SqlSessionTemplate getSessionTemplate() {
return sqlSessionTemplate; public SqlSessionTemplate getSessionTemplate() {
} return sqlSessionTemplate;
}
public SqlSession getSqlSession() {
return sqlSessionTemplate; public SqlSession getSqlSession() {
} return sqlSessionTemplate;
}
public long insert(T t) {
public long insert(T t) {
if (t == null)
throw new RuntimeException("T is null"); if (t == null)
throw new RuntimeException("T is null");
int result = sqlSessionTemplate.insert(getStatement(SQL_INSERT), t);
int result = sqlSessionTemplate.insert(getStatement(SQL_INSERT), t);
if (result <= 0)
throw BizException.DB_INSERT_RESULT_0; if (result <= 0)
throw BizException.DB_INSERT_RESULT_0;
if (t != null && t.getId() != null && result > 0)
return t.getId(); if (t != null && t.getId() != null && result > 0)
return t.getId();
return result;
} return result;
}
public long insert(List<T> list) {
public long insert(List<T> list) {
if (list == null || list.size() <= 0)
return 0; if (list == null || list.size() <= 0)
return 0;
int result = sqlSessionTemplate.insert(getStatement(SQL_BATCH_INSERT), list);
int result = sqlSessionTemplate.insert(getStatement(SQL_BATCH_INSERT), list);
if (result <= 0)
throw BizException.DB_INSERT_RESULT_0; if (result <= 0)
throw BizException.DB_INSERT_RESULT_0;
return result;
} return result;
}
public long update(T t) {
if (t == null) public long update(T t) {
throw new RuntimeException("T is null"); if (t == null)
throw new RuntimeException("T is null");
int result = sqlSessionTemplate.update(getStatement(SQL_UPDATE), t);
int result = sqlSessionTemplate.update(getStatement(SQL_UPDATE), t);
if (result <= 0)
throw BizException.DB_UPDATE_RESULT_0; if (result <= 0)
throw BizException.DB_UPDATE_RESULT_0;
return result;
} return result;
}
public long update(T t, String sqlId) {
if (t == null) public long update(T t, String sqlId) {
throw new RuntimeException("T is null"); if (t == null)
throw new RuntimeException("T is null");
int result = 0;
try { int result = 0;
result = sqlSessionTemplate.update(getStatement(sqlId), t); try {
} catch (Exception e) { result = sqlSessionTemplate.update(getStatement(sqlId), t);
logger.error("update fail[" + sqlId + "]:" + e.getMessage(), e); } catch (Exception e) {
throw BizException.DB_DML_FAIL; logger.error("update fail[" + sqlId + "]:" + e.getMessage(), e);
} throw BizException.DB_DML_FAIL;
if (result <= 0) }
throw BizException.DB_UPDATE_RESULT_0; if (result <= 0)
throw BizException.DB_UPDATE_RESULT_0;
return result;
} return result;
}
public long update(List<T> list) {
public long update(T t, String sqlId, String errorMessage) {
if (list == null || list.size() <= 0) if (t == null)
return 0; throw new RuntimeException("T is null");
int result = 0; int result = 0;
try {
for (int i = 0; i < list.size(); i++) { result = sqlSessionTemplate.update(getStatement(sqlId), t);
this.update(list.get(i)); } catch (Exception e) {
result += 1; logger.error("update fail[" + sqlId + "]:" + e.getMessage(), e);
} throw BizException.DB_DML_FAIL;
}
if (result <= 0) if (result <= 0) {
throw BizException.DB_UPDATE_RESULT_0; if (StringUtil.isEmpty(errorMessage))
throw BizException.DB_UPDATE_RESULT_0;
return result; else
} throw new BizException(10000, errorMessage);
}
public T getById(long id) {
return sqlSessionTemplate.selectOne(getStatement(SQL_GET_BY_ID), id); return result;
} }
public long deleteById(long id) { public long update(List<T> list) {
return (long) sqlSessionTemplate.delete(getStatement(SQL_DELETE_BY_ID), id);
} if (list == null || list.size() <= 0)
return 0;
public PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId) {
int result = 0;
if (paramMap == null)
paramMap = new HashMap<String, Object>(); for (int i = 0; i < list.size(); i++) {
this.update(list.get(i));
// 获取分页数据集 , 注切勿换成 sessionTemplate 对象 result += 1;
List<Object> list = getSqlSession().selectList(getStatement(sqlId), paramMap, }
new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage()));
if (result <= 0)
// 统计总记录数 throw BizException.DB_UPDATE_RESULT_0;
Object countObject = (Object) getSqlSession().selectOne(getStatement(sqlId),
new ExecutorInterceptor.CountParameter(paramMap)); return result;
Long count = Long.valueOf(countObject.toString()); }
return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list); public T getById(long id) {
} return sqlSessionTemplate.selectOne(getStatement(SQL_GET_BY_ID), id);
}
public <C> PageBeanNew<C> listPageNew(PageParam pageParam, Map<String, Object> paramMap, String sqlId) {
if (paramMap == null) public long deleteById(long id) {
paramMap = new HashMap<String, Object>(); return (long) sqlSessionTemplate.delete(getStatement(SQL_DELETE_BY_ID), id);
}
// 获取分页数据集 , 注切勿换成 sessionTemplate 对象
List<C> list = getSqlSession().selectList(getStatement(sqlId), paramMap, public PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId) {
new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage()));
if (paramMap == null)
// 统计总记录数 paramMap = new HashMap<String, Object>();
Integer count = getSqlSession().selectOne(getStatement(sqlId),
new ExecutorInterceptor.CountParameter(paramMap)); // 获取分页数据集 , 注切勿换成 sessionTemplate 对象
List<Object> list = getSqlSession().selectList(getStatement(sqlId), paramMap,
return new PageBeanNew<C>(pageParam.getPageNum(), pageParam.getNumPerPage(), count, list); new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage()));
}
// 统计总记录数
public PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId, String countSqlId) { Object countObject = (Object) getSqlSession().selectOne(getStatement(sqlId),
new ExecutorInterceptor.CountParameter(paramMap));
if (paramMap == null) Long count = Long.valueOf(countObject.toString());
paramMap = new HashMap<String, Object>();
return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list);
// 获取分页数据集 , 注切勿换成 sessionTemplate 对象 }
List<Object> list = getSqlSession().selectList(getStatement(sqlId), paramMap,
new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage())); public <C> PageBeanNew<C> listPageNew(PageParam pageParam, Map<String, Object> paramMap, String sqlId) {
if (paramMap == null)
// 统计总记录数 paramMap = new HashMap<String, Object>();
Object countObject = getSqlSession().selectOne(getStatement(countSqlId), paramMap);
Long count = Long.valueOf(countObject.toString()); // 获取分页数据集 , 注切勿换成 sessionTemplate 对象
List<C> list = getSqlSession().selectList(getStatement(sqlId), paramMap,
return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list); new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage()));
}
// 统计总记录数
public PageBean listSimplePage(PageParam pageParam, Map<String, Object> paramMap, String sqlId) { Integer count = getSqlSession().selectOne(getStatement(sqlId),
new ExecutorInterceptor.CountParameter(paramMap));
if (paramMap == null)
paramMap = new HashMap<String, Object>(); return new PageBeanNew<C>(pageParam.getPageNum(), pageParam.getNumPerPage(), count, list);
}
// 获取分页数据集 , 注切勿换成 sessionTemplate 对象
List<Object> list = getSqlSession().selectList(getStatement(sqlId), paramMap, public PageBean listPage(PageParam pageParam, Map<String, Object> paramMap, String sqlId, String countSqlId) {
new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage() + 1));
if (paramMap == null)
return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), list); paramMap = new HashMap<String, Object>();
}
// 获取分页数据集 , 注切勿换成 sessionTemplate 对象
public PageBean listPage(PageParam pageParam, Map<String, Object> paramMap) { List<Object> list = getSqlSession().selectList(getStatement(sqlId), paramMap,
new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage()));
if (paramMap == null)
paramMap = new HashMap<String, Object>(); // 统计总记录数
Object countObject = getSqlSession().selectOne(getStatement(countSqlId), paramMap);
// 获取分页数据集 , 注切勿换成 sessionTemplate 对象 Long count = Long.valueOf(countObject.toString());
List<Object> list = getSqlSession().selectList(getStatement(SQL_LIST_PAGE), paramMap,
new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage())); return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list);
}
// 统计总记录数
Object countObject = (Object) getSqlSession().selectOne(getStatement(SQL_LIST_PAGE), public PageBean listSimplePage(PageParam pageParam, Map<String, Object> paramMap, String sqlId) {
new ExecutorInterceptor.CountParameter(paramMap));
Long count = Long.valueOf(countObject.toString()); if (paramMap == null)
paramMap = new HashMap<String, Object>();
// 是否统计当前分页条件下的数据:1:是,其他为否
Object isCount = paramMap.get("isCount"); // 获取分页数据集 , 注切勿换成 sessionTemplate 对象
if (isCount != null && "1".equals(isCount.toString())) { List<Object> list = getSqlSession().selectList(getStatement(sqlId), paramMap,
Map<String, Object> countResultMap = sqlSessionTemplate.selectOne(getStatement(SQL_COUNT_BY_PAGE_PARAM), new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage() + 1));
paramMap);
return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list, return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), list);
countResultMap); }
} else {
return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list); public PageBean listPage(PageParam pageParam, Map<String, Object> paramMap) {
}
} if (paramMap == null)
paramMap = new HashMap<String, Object>();
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<T> listBy(Map<String, Object> paramMap) { // 获取分页数据集 , 注切勿换成 sessionTemplate 对象
return (List) this.listBy(paramMap, SQL_LIST_BY); List<Object> list = getSqlSession().selectList(getStatement(SQL_LIST_PAGE), paramMap,
} new RowBounds(pageParam.getPageNum() * pageParam.getNumPerPage(), pageParam.getNumPerPage()));
public List<Object> listBy(Map<String, Object> paramMap, String sqlId) { // 统计总记录数
if (paramMap == null) Object countObject = (Object) getSqlSession().selectOne(getStatement(SQL_LIST_PAGE),
paramMap = new HashMap<String, Object>(); new ExecutorInterceptor.CountParameter(paramMap));
Long count = Long.valueOf(countObject.toString());
return sqlSessionTemplate.selectList(getStatement(sqlId), paramMap);
} // 是否统计当前分页条件下的数据:1:是,其他为否
Object isCount = paramMap.get("isCount");
@SuppressWarnings("unchecked") if (isCount != null && "1".equals(isCount.toString())) {
public T getBy(Map<String, Object> paramMap) { Map<String, Object> countResultMap = sqlSessionTemplate.selectOne(getStatement(SQL_COUNT_BY_PAGE_PARAM),
return (T) this.getBy(paramMap, SQL_LIST_BY); paramMap);
} return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list,
countResultMap);
public Object getBy(Map<String, Object> paramMap, String sqlId) { } else {
if (paramMap == null || paramMap.isEmpty()) return new PageBean(pageParam.getPageNum(), pageParam.getNumPerPage(), count.intValue(), list);
return null; }
return this.getSqlSession().selectOne(getStatement(sqlId), paramMap); }
}
@SuppressWarnings({"rawtypes", "unchecked"})
public String getStatement(String sqlId) { public List<T> listBy(Map<String, Object> paramMap) {
return (List) this.listBy(paramMap, SQL_LIST_BY);
String name = this.getClass().getName(); }
StringBuffer sb = new StringBuffer().append(name).append(".").append(sqlId); public List<Object> listBy(Map<String, Object> paramMap, String sqlId) {
if (paramMap == null)
return sb.toString(); paramMap = new HashMap<String, Object>();
}
return sqlSessionTemplate.selectList(getStatement(sqlId), paramMap);
/** }
* 根据序列名称,获取序列值
*/ @SuppressWarnings("unchecked")
public String getSeqNextValue(String seqName) { public T getBy(Map<String, Object> paramMap) {
boolean isClosedConn = false; return (T) this.getBy(paramMap, SQL_LIST_BY);
// 获取当前线程的连接 }
Connection connection = this.sqlSessionTemplate.getConnection();
// 获取Mybatis的SQLRunner类 public Object getBy(Map<String, Object> paramMap, String sqlId) {
SqlRunner sqlRunner = null; if (paramMap == null || paramMap.isEmpty())
try { return null;
// 要执行的SQL return this.getSqlSession().selectOne(getStatement(sqlId), paramMap);
String sql = ""; }
// 数据库驱动类
String driverClass = druidDataSource.getDriver().getClass().getName(); public String getStatement(String sqlId) {
// 不同的数据库,拼接SQL语句
if (driverClass.equals("com.ibm.db2.jcc.DB2Driver")) { String name = this.getClass().getName();
sql = " VALUES " + seqName.toUpperCase() + ".NEXTVAL";
} StringBuffer sb = new StringBuffer().append(name).append(".").append(sqlId);
if (driverClass.equals("oracle.jdbc.OracleDriver")) {
sql = "SELECT " + seqName.toUpperCase() + ".NEXTVAL FROM DUAL"; return sb.toString();
} }
if (driverClass.equals("com.mysql.jdbc.Driver")) {
sql = "SELECT FUN_SEQ('" + seqName.toUpperCase() + "')"; /**
} * 根据序列名称,获取序列值
// 如果状态为关闭,则需要从新打开一个连接 */
if (connection.isClosed()) { public String getSeqNextValue(String seqName) {
connection = sqlSessionFactory.openSession().getConnection(); boolean isClosedConn = false;
isClosedConn = true; // 获取当前线程的连接
} Connection connection = this.sqlSessionTemplate.getConnection();
sqlRunner = new SqlRunner(connection); // 获取Mybatis的SQLRunner类
Object[] args = {}; SqlRunner sqlRunner = null;
// 执行SQL语句 try {
Map<String, Object> params = sqlRunner.selectOne(sql, args); // 要执行的SQL
for (Object o : params.values()) { String sql = "";
return o.toString(); // 数据库驱动类
} String driverClass = druidDataSource.getDriver().getClass().getName();
return null; // 不同的数据库,拼接SQL语句
} catch (Exception e) { if (driverClass.equals("com.ibm.db2.jcc.DB2Driver")) {
throw BizException.DB_GET_SEQ_NEXT_VALUE_ERROR.newInstance("获取序列出现错误!序列名称:{%s}", seqName); sql = " VALUES " + seqName.toUpperCase() + ".NEXTVAL";
} finally { }
if (isClosedConn) { if (driverClass.equals("oracle.jdbc.OracleDriver")) {
sqlRunner.closeConnection(); sql = "SELECT " + seqName.toUpperCase() + ".NEXTVAL FROM DUAL";
} }
} if (driverClass.equals("com.mysql.jdbc.Driver")) {
} sql = "SELECT FUN_SEQ('" + seqName.toUpperCase() + "')";
} }
// 如果状态为关闭,则需要从新打开一个连接
if (connection.isClosed()) {
connection = sqlSessionFactory.openSession().getConnection();
isClosedConn = true;
}
sqlRunner = new SqlRunner(connection);
Object[] args = {};
// 执行SQL语句
Map<String, Object> params = sqlRunner.selectOne(sql, args);
for (Object o : params.values()) {
return o.toString();
}
return null;
} catch (Exception e) {
throw BizException.DB_GET_SEQ_NEXT_VALUE_ERROR.newInstance("获取序列出现错误!序列名称:{%s}", seqName);
} finally {
if (isClosedConn) {
sqlRunner.closeConnection();
}
}
}
}
package com.pcloud.common.core.dto; package com.pcloud.common.core.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* 模板消息dto * 模板消息dto
* @author 作者 : lili *
* @date 创建时间:2016年11月17日 下午12:03:48 * @author 作者 : lili
* @version 1.0 * @version 1.0
* @return * @date 创建时间:2016年11月17日 下午12:03:48
*/ * @return
public class TemplateMessageDto implements Serializable { */
public class TemplateMessageDto implements Serializable {
/**
* /**
*/ *
private static final long serialVersionUID = -4132417523244980195L; */
private static final long serialVersionUID = -4132417523244980195L;
/**
* 场景编码值 /**
*/ * 场景编码值
private String sceneCode; */
private String sceneCode;
/**
* 接收消息的当事人ID /**
*/ * 接收消息的当事人ID
private Long receivePartyId; */
private Long receivePartyId;
/**
* 成员账号接收人 /**
*/ * 成员账号接收人
private List<Long> receiveMemberPartyIds; */
private List<Long> receiveMemberPartyIds;
/**
* 接收消息角色(CHANNEL/AGENT/MERCHANT/ADVISER) /**
*/ * 接收消息角色(CHANNEL/AGENT/MERCHANT/ADVISER)
private String receivePartyRole; */
private String receivePartyRole;
/**
* 公众号所属当事人ID /**
*/ * 公众号所属当事人ID
private Long sendPartyId; */
private Long sendPartyId;
/**
* 公众号所属当事人角色(CHANNEL/AGENT) /**
*/ * 公众号所属当事人角色(CHANNEL/AGENT)
private String sendPartyRole; */
private String sendPartyRole;
/**
* 微信用户 /**
*/ * 微信用户
private Long wechatUserId; */
private Long wechatUserId;
/**
* openId /**
*/ * openId
private String openId; */
private String openId;
/**
* 昵称 /**
*/ * 昵称
private String nickName; */
private String nickName;
/**
* url /**
*/ * url
private String url; */
private String url;
/**
* 参数 /**
*/ * 参数
private Map<String, String> temParam; */
private Map<String, String> temParam;
/**
* 发送类型(0: 通过wechatUserId 1 :通过openId 及昵称 2.通过当事人标识) /**
*/ * 发送类型(0: 通过wechatUserId 1 :通过openId 及昵称 2.通过当事人标识)
private String sendType; */
private String sendType;
/**
* 公众号标识 /**
*/ * 公众号标识
private Long accountSettingId; */
private Long accountSettingId;
/**
* 是否为应用 /**
*/ * 是否为应用
private Boolean isApp; */
private Boolean isApp;
/**
* 应用类型 /**
*/ * 应用类型
private String appType; */
private String appType;
public Long getAccountSettingId() { /**
return accountSettingId; * 消息来源分类
} */
private String fromCategory;
public void setAccountSettingId(Long accountSettingId) {
this.accountSettingId = accountSettingId; public String getFromCategory() {
} return fromCategory;
}
public String getSceneCode() {
return sceneCode; public void setFromCategory(String fromCategory) {
} this.fromCategory = fromCategory;
}
public void setSceneCode(String sceneCode) {
this.sceneCode = sceneCode; public Long getAccountSettingId() {
} return accountSettingId;
}
public Long getWechatUserId() {
return wechatUserId; public void setAccountSettingId(Long accountSettingId) {
} this.accountSettingId = accountSettingId;
}
public void setWechatUserId(Long wechatUserId) {
this.wechatUserId = wechatUserId; public String getSceneCode() {
} return sceneCode;
}
public String getUrl() {
return url; public void setSceneCode(String sceneCode) {
} this.sceneCode = sceneCode;
}
public void setUrl(String url) {
this.url = url; public Long getWechatUserId() {
} return wechatUserId;
}
public Map<String, String> getTemParam() {
return temParam; public void setWechatUserId(Long wechatUserId) {
} this.wechatUserId = wechatUserId;
}
public void setTemParam(Map<String, String> temParam) {
this.temParam = temParam; public String getUrl() {
} return url;
}
public String getOpenId() {
return openId; public void setUrl(String url) {
} this.url = url;
}
public void setOpenId(String openId) {
this.openId = openId; public Map<String, String> getTemParam() {
} return temParam;
}
public String getSendType() {
return sendType; public void setTemParam(Map<String, String> temParam) {
} this.temParam = temParam;
}
public void setSendType(String sendType) {
this.sendType = sendType; public String getOpenId() {
} return openId;
}
public Long getReceivePartyId() {
return receivePartyId; public void setOpenId(String openId) {
} this.openId = openId;
}
public void setReceivePartyId(Long receivePartyId) {
this.receivePartyId = receivePartyId; public String getSendType() {
} return sendType;
}
public String getReceivePartyRole() {
return receivePartyRole; public void setSendType(String sendType) {
} this.sendType = sendType;
}
public void setReceivePartyRole(String receivePartyRole) {
this.receivePartyRole = receivePartyRole; public Long getReceivePartyId() {
} return receivePartyId;
}
public Long getSendPartyId() {
return sendPartyId; public void setReceivePartyId(Long receivePartyId) {
} this.receivePartyId = receivePartyId;
}
public void setSendPartyId(Long sendPartyId) {
this.sendPartyId = sendPartyId; public String getReceivePartyRole() {
} return receivePartyRole;
}
public String getSendPartyRole() {
return sendPartyRole; public void setReceivePartyRole(String receivePartyRole) {
} this.receivePartyRole = receivePartyRole;
}
public void setSendPartyRole(String sendPartyRole) {
this.sendPartyRole = sendPartyRole; public Long getSendPartyId() {
} return sendPartyId;
}
public String getNickName() {
return nickName; public void setSendPartyId(Long sendPartyId) {
} this.sendPartyId = sendPartyId;
}
public void setNickName(String nickName) {
this.nickName = nickName; public String getSendPartyRole() {
} return sendPartyRole;
}
public Boolean getIsApp() {
return isApp; public void setSendPartyRole(String sendPartyRole) {
} this.sendPartyRole = sendPartyRole;
}
public void setIsApp(Boolean isApp) {
this.isApp = isApp; public String getNickName() {
} return nickName;
}
public String getAppType() {
return appType; public void setNickName(String nickName) {
} this.nickName = nickName;
}
public void setAppType(String appType) {
this.appType = appType; public Boolean getIsApp() {
} return isApp;
}
public List<Long> getReceiveMemberPartyIds() {
return receiveMemberPartyIds; public void setIsApp(Boolean isApp) {
} this.isApp = isApp;
}
public void setReceiveMemberPartyIds(List<Long> receiveMemberPartyIds) {
this.receiveMemberPartyIds = receiveMemberPartyIds; public String getAppType() {
} return appType;
}
@Override
public String toString() { public void setAppType(String appType) {
return "TemplateMessageDto [sceneCode=" + sceneCode + ", receivePartyId=" + receivePartyId this.appType = appType;
+ ", receiveMemberPartyIds=" + receiveMemberPartyIds + ", receivePartyRole=" + receivePartyRole }
+ ", sendPartyId=" + sendPartyId + ", sendPartyRole=" + sendPartyRole + ", wechatUserId=" + wechatUserId
+ ", openId=" + openId + ", nickName=" + nickName + ", url=" + url + ", temParam=" + temParam public List<Long> getReceiveMemberPartyIds() {
+ ", sendType=" + sendType + ", accountSettingId=" + accountSettingId + ", isApp=" + isApp return receiveMemberPartyIds;
+ ", appType=" + appType + "]"; }
}
public void setReceiveMemberPartyIds(List<Long> receiveMemberPartyIds) {
} this.receiveMemberPartyIds = receiveMemberPartyIds;
}
@Override
public String toString() {
return "TemplateMessageDto [sceneCode=" + sceneCode + ", receivePartyId=" + receivePartyId
+ ", receiveMemberPartyIds=" + receiveMemberPartyIds + ", receivePartyRole=" + receivePartyRole
+ ", sendPartyId=" + sendPartyId + ", sendPartyRole=" + sendPartyRole + ", wechatUserId=" + wechatUserId
+ ", openId=" + openId + ", nickName=" + nickName + ", url=" + url + ", temParam=" + temParam
+ ", sendType=" + sendType + ", accountSettingId=" + accountSettingId + ", isApp=" + isApp
+ ", appType=" + appType + "]";
}
}
...@@ -2,6 +2,7 @@ package com.pcloud.common.utils; ...@@ -2,6 +2,7 @@ package com.pcloud.common.utils;
import java.util.List; import java.util.List;
import com.pcloud.common.page.PageBeanNew;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -9,56 +10,78 @@ import org.springframework.beans.BeanUtils; ...@@ -9,56 +10,78 @@ import org.springframework.beans.BeanUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
/** /**
*
*
* @author:songx * @author:songx
* @date:2018年8月24日,下午2:18:40 * @date:2018年8月24日,下午2:18:40
*/ */
public class BeanNewUtils { public class BeanNewUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(BeanNewUtils.class); private static final Logger LOGGER = LoggerFactory.getLogger(BeanNewUtils.class);
/** /**
* 实体类之间的转换 * 实体类之间的转换
* *
* @param source * @param source 来源
* 来源 * @param clazz 目标对象
* @param clazz * @return
* 目标对象 */
* @return public static <T> T copyProperties(Object source, Class<T> clazz) {
*/ if (source == null) {
public static <T> T copyProperties(Object source, Class<T> clazz) { return null;
if (source == null) { }
return null; T t = null;
} try {
T t = null; t = clazz.newInstance();
try { } catch (Exception e) {
t = clazz.newInstance(); LOGGER.error("clazz newInstance is error:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.error("clazz newInstance is error:" + e.getMessage(), e); BeanUtils.copyProperties(source, t);
} return t;
BeanUtils.copyProperties(source, t); }
return t;
}
/** /**
* 实体类之间的转换 * 实体类之间的转换
* *
* @param sources * @param sources 来源
* 来源 * @param clazz 目标对象
* @param clazz * @return
* 目标对象 */
* @return public static <T> List<T> copyProperties(List<?> sources, Class<T> clazz) {
*/ if (ListUtils.isEmpty(sources)) {
public static <T> List<T> copyProperties(List<?> sources, Class<T> clazz) { return null;
if (ListUtils.isEmpty(sources)) { }
return null; List<T> results = Lists.newArrayList();
} for (Object source : sources) {
List<T> results = Lists.newArrayList(); results.add(copyProperties(source, clazz));
for (Object source : sources) { }
results.add(copyProperties(source, clazz)); return results;
} }
return results;
} /**
* 分页结果的实体类之间的转换
*
* @param source
* @param clazz
* @param <T>
* @return
*/
public static <T> PageBeanNew<T> copyProperties(PageBeanNew<?> source, Class<T> clazz) {
if (source == null) {
return null;
}
List<?> recordList = source.getRecordList();
PageBeanNew<T> result = new PageBeanNew<T>();
result.setCurrentPage(source.getCurrentPage());
result.setNumPerPage(source.getNumPerPage());
result.setPageCount(source.getPageCount());
result.setTotalCount(source.getTotalCount());
source.setBeginPageIndex(source.getBeginPageIndex());
source.setEndPageIndex(source.getEndPageIndex());
if (ListUtils.isEmpty(recordList)) {
result.setRecordList(Lists.newArrayList());
return result;
}
result.setRecordList(copyProperties(recordList, clazz));
return result;
}
} }
...@@ -20,13 +20,38 @@ import com.pcloud.common.utils.string.StringUtil; ...@@ -20,13 +20,38 @@ import com.pcloud.common.utils.string.StringUtil;
*/ */
public class LocalDateUtils { public class LocalDateUtils {
private static final DateTimeFormatter TIME = DateTimeFormatter.ofPattern("HHmmss");
private static final DateTimeFormatter SHORT_MILLISECOND = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
private static final DateTimeFormatter SHORT_DATETIME = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
private static final DateTimeFormatter DATETIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter SHORT_DATE = DateTimeFormatter.ofPattern("yyyyMMdd");
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/** /**
* 获取当前的日期字符串(yyyy-MM-dd) * 获取当前的日期字符串(yyyy-MM-dd)
* *
* @return * @return
*/ */
public static String getDateNow() { public static String getDateNow() {
return LocalDate.now().toString(); return LocalDate.now().format(DATE);
}
/**
* 获取当前的日期字符串(yyyyMMdd)
*
* @return
*/
public static String getShortDateNow() {
return LocalDate.now().format(SHORT_DATE);
}
/**
* 获取当前的时间字符串(HHmmss)
*
* @return
*/
public static String getShortTimeNow() {
return LocalDateTime.now().format(TIME);
} }
/** /**
...@@ -35,7 +60,16 @@ public class LocalDateUtils { ...@@ -35,7 +60,16 @@ public class LocalDateUtils {
* @return * @return
*/ */
public static String getDateTimeNow() { public static String getDateTimeNow() {
return LocalDateTime.now().withNano(0).toString().replace("T", " "); return LocalDateTime.now().format(DATETIME);
}
/**
* 获取当前的日期字符串(yyyyMMddHHmmss)
*
* @return
*/
public static String getShortDateTimeNow() {
return LocalDateTime.now().format(SHORT_DATETIME);
} }
/** /**
...@@ -44,8 +78,7 @@ public class LocalDateUtils { ...@@ -44,8 +78,7 @@ public class LocalDateUtils {
* @return * @return
*/ */
public static String getYmdhmss() { public static String getYmdhmss() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"); return LocalDateTime.now().format(SHORT_MILLISECOND);
return LocalDateTime.now().format(formatter);
} }
/** /**
...@@ -65,7 +98,10 @@ public class LocalDateUtils { ...@@ -65,7 +98,10 @@ public class LocalDateUtils {
* @return * @return
*/ */
public static String convertToString(LocalDateTime localDateTime) { public static String convertToString(LocalDateTime localDateTime) {
return localDateTime.withNano(0).toString().replace("T", " "); if (localDateTime == null) {
return null;
}
return localDateTime.format(DATETIME);
} }
/** /**
......
package com.pcloud.common.utils; package com.pcloud.common.utils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.pcloud.common.page.PageBeanNew; import com.pcloud.common.page.PageBeanNew;
/** /**
* 返回结果工具类 * 返回结果工具类
* *
* @author:songx * @author:songx
* @date:2018年8月8日,下午2:09:16 * @date:2018年8月8日,下午2:09:16
*/ */
public class ResultUtils { public class ResultUtils {
/** /**
* 集合查询结果判断 * 集合查询结果判断
* *
* @param lists * @param lists
* @return * @return
*/ */
public static <T> List<T> list(List<T> lists) { public static <T> List<T> list(List<T> lists) {
if (!ListUtils.isEmpty(lists)) { if (!ListUtils.isEmpty(lists)) {
return lists; return lists;
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
/** /**
* map查询结果判断 * map查询结果判断
* *
* @param lists * @param lists
* @return * @return
*/ */
public static <K, V> Map<K, V> map(Map<K, V> map) { public static <K, V> Map<K, V> map(Map<K, V> map) {
if (!MapUtils.isEmpty(map)) { if (!MapUtils.isEmpty(map)) {
return map; return map;
} }
return Maps.newHashMap(); return Maps.newHashMap();
} }
/** /**
* 分页查询结果判断 * 分页查询结果判断
* *
* @param pageBeanNew * @param pageBeanNew
* @return * @return
*/ */
public static <T> PageBeanNew<T> pageBeanNew(PageBeanNew<T> pageBeanNew, Integer currentPage, Integer numPerPage) { public static <T> PageBeanNew<T> pageBeanNew(PageBeanNew<T> pageBeanNew, Integer currentPage, Integer numPerPage) {
if (pageBeanNew != null) { if (pageBeanNew != null) {
return pageBeanNew; return pageBeanNew;
} }
return new PageBeanNew<T>(currentPage, numPerPage, 0, Lists.newArrayList()); return new PageBeanNew<T>(currentPage, numPerPage, 0, Lists.newArrayList());
} }
} }
package com.pcloud.common.utils.string; package com.pcloud.common.utils.string;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.exceptions.BizException;
/** /**
* @描述:字符串工具类 * @描述:字符串工具类
* @作者:DiSeng.H * @作者:DiSeng.H
* @创建时间:2016年3月10日,上午11:49:07 @版本:1.0 * @创建时间:2016年3月10日,上午11:49:07 @版本:1.0
*/ */
public class StringUtil extends StringUtilParent { public class StringUtil extends StringUtilParent {
/**
* 判断字符串是否为空 /**
* * 判断字符串是否为空
* @param str *
* @return * @param str
*/ * @return
public static boolean isNotNull(String str) { */
if (str != null && !"".equals(str.trim())) { public static boolean isNotNull(String str) {
return true; if (str != null && !"".equals(str.trim())) {
} else { return true;
return false; } else {
} return false;
} }
}
/**
* 判断对象是否为空 /**
* * 判断对象是否为空
* @param str *
* @return * @param str
*/ * @return
public static boolean isNotNull(Object obj) { */
if (obj != null && obj.toString() != null && !"".equals(obj.toString().trim())) { public static boolean isNotNull(Object obj) {
return true; if (obj != null && obj.toString() != null && !"".equals(obj.toString().trim())) {
} else { return true;
return false; } else {
} return false;
} }
}
/**
* 判断字符串是否为空(自动截取首尾空白) /**
* * 判断字符串是否为空(自动截取首尾空白)
* @param str *
* 源字符串 * @param str 源字符串
* @return * @return
*/ */
public static boolean isEmpty(String str) { public static boolean isEmpty(String str) {
return isEmpty(str, true); return isEmpty(str, true);
} }
/** /**
* 判断字符串是否为空 * 判断字符串是否为空
* *
* @param str * @param str 源字符串
* 源字符串 * @param trim 是否截取首尾空白
* @param trim * @return
* 是否截取首尾空白 */
* @return public static boolean isEmpty(String str, boolean trim) {
*/ return str == null ? true : ("".equals(str.trim()) || "null".equals(str.trim()));
public static boolean isEmpty(String str, boolean trim) { }
return str == null ? true : ("".equals(str.trim()) || "null".equals(str.trim()));
} /**
* 判断数组是否为空
/** *
* 判断数组是否为空 * @param str
* * @return
* @param str */
* @return public static boolean isEmpty(String[] strs) {
*/ return strs == null ? true : strs.length == 0;
public static boolean isEmpty(String[] strs) { }
return strs == null ? true : strs.length == 0;
} /**
* @param str the string need to be parsed
/** * @param delim the delimiter to seperate created by zqf at 6/1/2013
* @param str */
* the string need to be parsed @SuppressWarnings({"rawtypes", "unchecked"})
* @param delim public static String[] parseToArray(String str, String delim) {
* the delimiter to seperate created by zqf at 6/1/2013 ArrayList arr = new ArrayList();
*/ StringTokenizer st = new StringTokenizer(str, delim);
@SuppressWarnings({ "rawtypes", "unchecked" }) while (st.hasMoreTokens()) {
public static String[] parseToArray(String str, String delim) { arr.add(st.nextToken());
ArrayList arr = new ArrayList(); }
StringTokenizer st = new StringTokenizer(str, delim); String[] ret = new String[arr.size()];
while (st.hasMoreTokens()) { for (int i = 0; i < arr.size(); i++) {
arr.add(st.nextToken()); ret[i] = (String) arr.get(i);
} }
String[] ret = new String[arr.size()]; return ret;
for (int i = 0; i < arr.size(); i++) { }
ret[i] = (String) arr.get(i);
} /**
return ret; * replace a old substring with rep in str
} *
* @param str the string need to be replaced
/** * @param old the string need to be removed
* replace a old substring with rep in str * @param rep the string to be inserted
* * @return string replaced
* @param str */
* the string need to be replaced public static String replace(String str, String old, String rep) {
* @param old if ((str == null) || (old == null) || (rep == null)) {// if one is null
* the string need to be removed // return ""
* @param rep return "";
* the string to be inserted }
* @return string replaced int index = str.indexOf(old);
*/ if ((index < 0) || "".equals(old)) { // if no old string found or
public static String replace(String str, String old, String rep) { // nothing to replace,return the
if ((str == null) || (old == null) || (rep == null)) {// if one is null // origin
// return "" return str;
return ""; }
} StringBuffer strBuf = new StringBuffer(str);
int index = str.indexOf(old); while (index >= 0) { // found old part
if ((index < 0) || "".equals(old)) { // if no old string found or strBuf.delete(index, index + old.length());
// nothing to replace,return the strBuf.insert(index, rep);
// origin index = strBuf.toString().indexOf(old);
return str; }
} return strBuf.toString();
StringBuffer strBuf = new StringBuffer(str); }
while (index >= 0) { // found old part
strBuf.delete(index, index + old.length()); /**
strBuf.insert(index, rep); * 带逗号分隔的数字转换为NUMBER类型
index = strBuf.toString().indexOf(old); *
} * @param str
return strBuf.toString(); * @return
} * @throws ParseException
*/
/** public static Number stringToNumber(String str) throws ParseException {
* 带逗号分隔的数字转换为NUMBER类型 if (str == null || "".equals(str)) {
* return null;
* @param str }
* @return DecimalFormatSymbols dfs = new DecimalFormatSymbols();
* @throws ParseException dfs.setDecimalSeparator('.');
*/ dfs.setGroupingSeparator(',');
public static Number stringToNumber(String str) throws ParseException { dfs.setMonetaryDecimalSeparator('.');
if (str == null || "".equals(str)) { DecimalFormat df = new DecimalFormat("###,###,###,###.##", dfs);
return null; return df.parse(str);
} }
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.'); public static String getExtensionName(String filename) {
dfs.setGroupingSeparator(','); if ((filename != null) && (filename.length() > 0)) {
dfs.setMonetaryDecimalSeparator('.'); int dot = filename.lastIndexOf('.');
DecimalFormat df = new DecimalFormat("###,###,###,###.##", dfs); if ((dot > -1) && (dot < (filename.length() - 1))) {
return df.parse(str); return filename.substring(dot + 1);
} }
}
public static String getExtensionName(String filename) { return filename;
if ((filename != null) && (filename.length() > 0)) { }
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length() - 1))) { /**
return filename.substring(dot + 1); * 用于字符串替换
} *
} * @param target 目标对象 需要替换的字符串
return filename; * @param replacement 要替换的字符串
} * @param value 替换的值
* @return
/** */
* 用于字符串替换 public static String replacement(String target, String replacement, String value) {
* if (target != null)
* @param target return target.replace(replacement, value);
* 目标对象 需要替换的字符串 return null;
* @param replacement }
* 要替换的字符串
* @param value /**
* 替换的值 * 判断字符串是否为数字
* @return *
*/ * @param str
public static String replacement(String target, String replacement, String value) { * @return
if (target != null) */
return target.replace(replacement, value); public static boolean isNumeric(String str) {
return null; if (str == null || str.length() == 0) {
} return false;
}
/** for (int i = 0; i < str.length(); i++) {
* 判断字符串是否为数字 if (!Character.isDigit(str.charAt(i))) {
* return false;
* @param str }
* @return }
*/ return true;
public static boolean isNumeric(String str) { }
if (str == null || str.length() == 0) {
return false; /**
} * 计算指定时间与当前时间的差
for (int i = 0; i < str.length(); i++) { *
if (!Character.isDigit(str.charAt(i))) { * @param date
return false; * @return
} */
} public static String convDateToString(Date date) {
return true; Long time = new Date().getTime() - date.getTime();
} Long min = time / 1000 / 60;
if (min < 5) {
/** return "刚刚";
* 计算指定时间与当前时间的差 } else if (min >= 5 && min < 60) {
* return min + "分钟之前";
* @param date } else if (min >= 60 && min < 1440) {
* @return return min / 60 + "小时之前";
*/ } else if (min >= 1440 && min < 10080) {
public static String convDateToString(Date date) { return min / 60 / 24 + "天之前";
Long time = new Date().getTime() - date.getTime(); } else if (min >= 10080 && min < 40320) {
Long min = time / 1000 / 60; return min / 60 / 24 / 7 + "周之前";
if (min < 5) { } else if (min >= 40320 && min < 525600) {
return "刚刚"; return min / 60 / 24 / 7 / 4 + "月之前";
} else if (min >= 5 && min < 60) { } else if (min >= 525600) {
return min + "分钟之前"; return min / 60 / 24 / 365 + "年之前";
} else if (min >= 60 && min < 1440) { }
return min / 60 + "小时之前"; return null;
} else if (min >= 1440 && min < 10080) { }
return min / 60 / 24 + "天之前";
} else if (min >= 10080 && min < 40320) { /**
return min / 60 / 24 / 7 + "周之前"; * @return
} else if (min >= 40320 && min < 525600) { * @description 获取当前服务器日期
return min / 60 / 24 / 7 / 4 + "月之前"; */
} else if (min >= 525600) { public static String getCurrdate(String formatStr) {
return min / 60 / 24 / 365 + "年之前"; Calendar cal = Calendar.getInstance();
} SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
return null; String mDateTime = formatter.format(cal.getTime());
} return mDateTime;
}
/**
* @description 获取当前服务器日期 /**
* @return * 将Object值转换成Double类型
*/ *
public static String getCurrdate(String formatStr) { * @param value
Calendar cal = Calendar.getInstance(); * @return
SimpleDateFormat formatter = new SimpleDateFormat(formatStr); */
String mDateTime = formatter.format(cal.getTime()); public static double getDoubleByObj(Object value) {
return mDateTime; if (value == null) {
} return 0;
}
/** return Double.valueOf(String.valueOf(value));
* 将Object值转换成Double类型 }
*
* @param value /**
* @return * 将Object值转换成Float类型
*/ *
public static double getDoubleByObj(Object value) { * @param value
if (value == null) { * @return
return 0; */
} public static float getFloatByObj(Object value) {
return Double.valueOf(String.valueOf(value)); if (value == null) {
} return 0;
}
/** return Float.valueOf(String.valueOf(value));
* 将Object值转换成Float类型 }
*
* @param value /**
* @return * 将Object值转换成Integer类型
*/ *
public static float getFloatByObj(Object value) { * @param value
if (value == null) { * @return
return 0; */
} public static Integer getIntegerByObj(Object value) {
return Float.valueOf(String.valueOf(value)); if (value == null) {
} return 0;
}
/** return Integer.valueOf(String.valueOf(value));
* 将Object值转换成Integer类型 }
*
* @param value
* @return /**
*/ * 将Object值转换成String类型
public static Integer getIntegerByObj(Object value) { *
if (value == null) { * @param value
return 0; * @return
} */
return Integer.valueOf(String.valueOf(value)); public static String getByObj(Object value) {
} if (value == null) {
return null;
/** }
* 解析字符串 ---> 去掉字符串中回车、换行、空格 return value.toString();
* }
* @param str
* 被解析字符串 /**
* @return String 解析后的字符串 * 解析字符串 ---> 去掉字符串中回车、换行、空格
*/ *
public static String parse(String str) { * @param str 被解析字符串
return str.replaceAll("\n", "").replaceAll("chr(13)", "").replaceAll(" ", ""); * @return String 解析后的字符串
} */
public static String parse(String str) {
public static Integer[] Str2Integers(String value) { return str.replaceAll("\n", "").replaceAll("chr(13)", "").replaceAll(" ", "");
if (null == value || !org.springframework.util.StringUtils.hasText(value)) { }
return null;
} public static Integer[] Str2Integers(String value) {
String[] values = value.split(","); if (null == value || !org.springframework.util.StringUtils.hasText(value)) {
Integer[] v = new Integer[values.length]; return null;
for (int i = 0; i < values.length; i++) { }
v[i] = Integer.parseInt(values[i]); String[] values = value.split(",");
} Integer[] v = new Integer[values.length];
return v; for (int i = 0; i < values.length; i++) {
} v[i] = Integer.parseInt(values[i]);
}
public static String[] Str2Strings(String value) { return v;
if (null == value || !org.springframework.util.StringUtils.hasText(value)) { }
return null;
} public static String[] Str2Strings(String value) {
String[] values = value.split(","); if (null == value || !org.springframework.util.StringUtils.hasText(value)) {
String[] v = new String[values.length]; return null;
for (int i = 0; i < values.length; i++) { }
v[i] = values[i]; String[] values = value.split(",");
} String[] v = new String[values.length];
return v; for (int i = 0; i < values.length; i++) {
} v[i] = values[i];
}
public static int strFormateInt(Object obj) { return v;
if (isNotNull(obj)) { }
return "是".equals(obj) ? 1 : 0;
} else { public static int strFormateInt(Object obj) {
return 0; if (isNotNull(obj)) {
} return "是".equals(obj) ? 1 : 0;
} } else {
return 0;
/** }
* 获取UUID }
*
* @return UUID /**
*/ * 获取UUID
public static String getUUID() { *
* @return UUID
return (UUID.randomUUID() + "").replaceAll("-", ""); */
} public static String getUUID() {
/** return (UUID.randomUUID() + "").replaceAll("-", "");
* 将字符串转移为ASCII码 }
*
* @param cnStr /**
* @return * 将字符串转移为ASCII码
*/ *
public static String getCnASCII(String cnStr) { * @param cnStr
StringBuffer strBuf = new StringBuffer(); * @return
byte[] bGBK = cnStr.getBytes(); */
for (int i = 0; i < bGBK.length; i++) { public static String getCnASCII(String cnStr) {
// System.out.println(Integer.toHexString(bGBK[i]&0xff)); StringBuffer strBuf = new StringBuffer();
strBuf.append(Integer.toHexString(bGBK[i] & 0xff)); byte[] bGBK = cnStr.getBytes();
} for (int i = 0; i < bGBK.length; i++) {
return strBuf.toString(); // System.out.println(Integer.toHexString(bGBK[i]&0xff));
} strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
}
/** return strBuf.toString();
* }
* @param initCode
* 初始化编码 /**
* @param length * @param initCode 初始化编码
* 需要生成编码长度 * @param length 需要生成编码长度
* @param ind * @param ind 地增量
* 地增量 * @return 递增后的编码
* @return 递增后的编码 */
*/ public static String getNextCode(String initCode, int length, int ind) {
public static String getNextCode(String initCode, int length, int ind) { Integer temp = Integer.parseInt(initCode);
Integer temp = Integer.parseInt(initCode); temp = temp + ind;
temp = temp + ind; String tempCode = temp.toString();
String tempCode = temp.toString(); int tempLen = 0;
int tempLen = 0; if (tempCode.length() < length) {
if (tempCode.length() < length) { tempLen = length - tempCode.length();
tempLen = length - tempCode.length(); }
} for (int i = 0; i < tempLen; i++) {
for (int i = 0; i < tempLen; i++) { tempCode = "0" + tempCode;
tempCode = "0" + tempCode; }
} return tempCode;
return tempCode; }
}
public static int switchNumber(String str) {
public static int switchNumber(String str) { char c = str.charAt(0);
char c = str.charAt(0); int temp = 0;
int temp = 0; switch (c) {
switch (c) { // 数值
// 数值 case '〇':
case '〇': case '零':
case '零': temp = 0;
temp = 0; break;
break; case '一':
case '一': temp = 1;
temp = 1; break;
break; case '二':
case '二': temp = 2;
temp = 2; break;
break; case '三':
case '三': temp = 3;
temp = 3; break;
break; case '四':
case '四': temp = 4;
temp = 4; break;
break; case '五':
case '五': temp = 5;
temp = 5; break;
break; case '六':
case '六': temp = 6;
temp = 6; break;
break; case '七':
case '七': temp = 7;
temp = 7; break;
break; case '八':
case '八': temp = 8;
temp = 8; break;
break; case '九':
case '九': temp = 9;
temp = 9; break;
break; // 单位,前缀是单数字
// 单位,前缀是单数字 case '十':
case '十': temp = 10;
temp = 10; break;
break; }
} return temp;
return temp; }
}
/**
/** * 中文数字转换为阿拉伯数
* 中文数字转换为阿拉伯数 *
* * @param String s
* @param String */
* s public static int cnNumToInt(String s) {
*/ int result = 0;
public static int cnNumToInt(String s) { int yi = 1;// 记录高级单位
int result = 0; int wan = 1;// 记录高级单位
int yi = 1;// 记录高级单位 int ge = 1;// 记录单位
int wan = 1;// 记录高级单位 char c = s.charAt(0);
int ge = 1;// 记录单位 int temp = 0;// 记录数值
char c = s.charAt(0); switch (c) {
int temp = 0;// 记录数值 // 数值
switch (c) { case '〇':
// 数值 case '零':
case '〇': temp = 0;
case '零': break;
temp = 0; case '一':
break; temp = 1 * ge * wan * yi;
case '一': ge = 1;
temp = 1 * ge * wan * yi; break;
ge = 1; case '二':
break; temp = 2 * ge * wan * yi;
case '二': ge = 1;
temp = 2 * ge * wan * yi; break;
ge = 1; case '三':
break; temp = 3 * ge * wan * yi;
case '三': ge = 1;
temp = 3 * ge * wan * yi; break;
ge = 1; case '四':
break; temp = 4 * ge * wan * yi;
case '四': ge = 1;
temp = 4 * ge * wan * yi; break;
ge = 1; case '五':
break; temp = 5 * ge * wan * yi;
case '五': ge = 1;
temp = 5 * ge * wan * yi; break;
ge = 1; case '六':
break; temp = 6 * ge * wan * yi;
case '六': ge = 1;
temp = 6 * ge * wan * yi; break;
ge = 1; case '七':
break; temp = 7 * ge * wan * yi;
case '七': ge = 1;
temp = 7 * ge * wan * yi; break;
ge = 1; case '八':
break; temp = 8 * ge * wan * yi;
case '八': ge = 1;
temp = 8 * ge * wan * yi; break;
ge = 1; case '九':
break; temp = 9 * ge * wan * yi;
case '九': ge = 1;
temp = 9 * ge * wan * yi; break;
ge = 1; // 单位,前缀是单数字
break; case '十':
// 单位,前缀是单数字 ge = 10;
case '十': break;
ge = 10; case '百':
break; ge = 100;
case '百': break;
ge = 100; case '千':
break; ge = 1000;
case '千': break;
ge = 1000; // 高级单位,前缀可以是多个数字
break; case '万':
// 高级单位,前缀可以是多个数字 wan = 10000;
case '万': ge = 1;
wan = 10000; break;
ge = 1; case '亿':
break; yi = 100000000;
case '亿': wan = 1;
yi = 100000000; ge = 1;
wan = 1; break;
ge = 1; default:
break; return -1;
default: }
return -1; result += temp;
} if (ge > 1) {
result += temp; result += 1 * ge * wan * yi;
if (ge > 1) { }
result += 1 * ge * wan * yi; return result;
} }
return result;
} public static String geneStrAry(String str, String splits) {
if (StringUtil.isEmpty(str))
public static String geneStrAry(String str, String splits) { return "";
if (StringUtil.isEmpty(str)) String[] ary = str.split(splits);
return ""; StringBuffer sb = new StringBuffer("");
String[] ary = str.split(splits); for (int i = 0; i < ary.length; i++) {
StringBuffer sb = new StringBuffer(""); sb.append("'");
for (int i = 0; i < ary.length; i++) { sb.append(ary[i]);
sb.append("'"); sb.append("'");
sb.append(ary[i]); if (i < ary.length - 1)
sb.append("'"); sb.append(",");
if (i < ary.length - 1) }
sb.append(","); return sb.toString();
} }
return sb.toString();
} public static boolean equals(String str1, String str2) {
return str1 == null ? false : str2 == null ? true : str1.equals(str2);
public static boolean equals(String str1, String str2) { }
return str1 == null ? false : str2 == null ? true : str1.equals(str2);
} public static boolean equalsIgnoreCase(String str1, String str2) {
return str1 == null ? false : str2 == null ? true : str1.equalsIgnoreCase(str2);
public static boolean equalsIgnoreCase(String str1, String str2) { }
return str1 == null ? false : str2 == null ? true : str1.equalsIgnoreCase(str2);
} /**
* @param obj 传数值类型的obj
/** * @param format
* * @return
* @param obj */
* 传数值类型的obj public static String decimalFormat(Object obj) {
* @param format if (null == obj)
* @return return "";
*/ DecimalFormat df = new DecimalFormat("0.00");
public static String decimalFormat(Object obj) { return df.format(obj);
if (null == obj) }
return "";
DecimalFormat df = new DecimalFormat("0.00"); /**
return df.format(obj); * @param obj 传数值类型的obj
} * @param format
* @return
/** */
* public static String decimalFormat(Object obj, String format) {
* @param obj if (null == obj)
* 传数值类型的obj return "";
* @param format DecimalFormat df = new DecimalFormat(format);
* @return return df.format(obj);
*/ }
public static String decimalFormat(Object obj, String format) {
if (null == obj) /**
return ""; * 字符串两端增加书名号
DecimalFormat df = new DecimalFormat(format); *
return df.format(obj); * @param str
} * @return
*/
/** public static String addBracket(String str) {
* 字符串两端增加书名号 if (null == str)
* return "";
* @param str if (!str.startsWith("《") || !str.endsWith("》")) {
* @return str = "《" + str + "》";
*/ }
public static String addBracket(String str) { return str;
if (null == str) }
return "";
if (!str.startsWith("《") || !str.endsWith("》")) { /**
str = "《" + str + "》"; * 字符串两端增加书名号,且名称控制在30个字符之内
} *
return str; * @param str
} * @return
*/
/** public static String addBracket2Short(String str) {
* 字符串两端增加书名号,且名称控制在30个字符之内 if (null == str)
* return "";
* @param str if (!str.startsWith("《") || !str.endsWith("》")) {
* @return str = "《" + (str.length() > 30 ? str.substring(0, 10) + "..." + str.substring(str.length() - 10) : str)
*/ + "》";
public static String addBracket2Short(String str) { }
if (null == str) return str;
return ""; }
if (!str.startsWith("《") || !str.endsWith("》")) {
str = "《" + (str.length() > 30 ? str.substring(0, 10) + "..." + str.substring(str.length() - 10) : str) /**
+ "》"; * 校验特殊字符
} *
return str; * @param productId
} * @throws BizException
*/
/** public static boolean checkCharacter(String str) throws BizException {
* 校验特殊字符 if (StringUtil.isEmpty(str)) {
* return false;
* @param productId }
* @throws BizException String regEx = "[\\\\\"%/]";
*/ Pattern p = Pattern.compile(regEx);
public static boolean checkCharacter(String str) throws BizException { Matcher m = p.matcher(str);
if (StringUtil.isEmpty(str)) { if (m.find()) {
return false; return true;
} }
String regEx = "[\\\\\"%/]"; return false;
Pattern p = Pattern.compile(regEx); }
Matcher m = p.matcher(str);
if (m.find()) { }
return true;
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment