currentModelClass();
+
+ /**
+ *
+ * 插入一条记录(选择字段,策略插入)
+ *
+ *
+ * @param entity 实体对象
+ */
+ boolean insert(T entity);
+
+ /**
+ *
+ * 插入(批量),该方法不支持 Oracle、SQL Server
+ *
+ *
+ * @param entityList 实体对象集合
+ */
+ boolean insertBatch(Collection entityList);
+
+ /**
+ *
+ * 插入(批量),该方法不支持 Oracle、SQL Server
+ *
+ *
+ * @param entityList 实体对象集合
+ * @param batchSize 插入批次数量
+ */
+ boolean insertBatch(Collection entityList, int batchSize);
+
+ /**
+ *
+ * 根据 ID 选择修改
+ *
+ *
+ * @param entity 实体对象
+ */
+ boolean updateById(T entity);
+
+ /**
+ *
+ * 根据 whereEntity 条件,更新记录
+ *
+ *
+ * @param entity 实体对象
+ * @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper}
+ */
+ boolean update(T entity, Wrapper updateWrapper);
+
+ /**
+ *
+ * 根据ID 批量更新
+ *
+ *
+ * @param entityList 实体对象集合
+ */
+ boolean updateBatchById(Collection entityList);
+
+ /**
+ *
+ * 根据ID 批量更新
+ *
+ *
+ * @param entityList 实体对象集合
+ * @param batchSize 更新批次数量
+ */
+ boolean updateBatchById(Collection entityList, int batchSize);
+
+ /**
+ *
+ * 根据 ID 查询
+ *
+ *
+ * @param id 主键ID
+ */
+ T selectById(Serializable id);
+
+ /**
+ *
+ * 根据 ID 删除
+ *
+ *
+ * @param id 主键ID
+ */
+ boolean deleteById(Serializable id);
+
+ /**
+ *
+ * 删除(根据ID 批量删除)
+ *
+ *
+ * @param idList 主键ID列表
+ */
+ boolean deleteBatchIds(Collection extends Serializable> idList);
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/service/CrudService.java b/zhongyun-common/src/main/java/com/zhongyun/common/service/CrudService.java
new file mode 100644
index 0000000..9fa1617
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/service/CrudService.java
@@ -0,0 +1,28 @@
+package com.zhongyun.common.service;
+
+
+import com.zhongyun.common.page.PageData;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * CRUD基础服务接口
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ */
+public interface CrudService extends BaseService {
+
+ PageData page(Map params);
+
+ List list(Map params);
+
+ D get(Long id);
+
+ void save(D dto);
+
+ void update(D dto);
+
+ void delete(Long[] ids);
+
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/service/impl/BaseServiceImpl.java b/zhongyun-common/src/main/java/com/zhongyun/common/service/impl/BaseServiceImpl.java
new file mode 100644
index 0000000..8311ea8
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/service/impl/BaseServiceImpl.java
@@ -0,0 +1,213 @@
+
+
+package com.zhongyun.common.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
+import com.zhongyun.common.constant.Constant;
+import com.zhongyun.common.page.PageData;
+import com.zhongyun.common.service.BaseService;
+import com.zhongyun.common.utils.ConvertUtils;
+import org.apache.ibatis.binding.MapperMethod;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
+import org.apache.ibatis.session.SqlSession;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+
+/**
+ * 基础服务类,所有Service都要继承
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ */
+public abstract class BaseServiceImpl, T> implements BaseService {
+ @Autowired
+ protected M baseDao;
+ protected Log log = LogFactory.getLog(getClass());
+
+ /**
+ * 获取分页对象
+ * @param params 分页查询参数
+ * @param defaultOrderField 默认排序字段
+ * @param isAsc 排序方式
+ */
+ protected IPage getPage(Map params, String defaultOrderField, boolean isAsc) {
+ //分页参数
+ long curPage = 1;
+ long limit = 10;
+
+ if(params.get(Constant.PAGE) != null){
+ curPage = Long.parseLong((String)params.get(Constant.PAGE));
+ }
+ if(params.get(Constant.LIMIT) != null){
+ limit = Long.parseLong((String)params.get(Constant.LIMIT));
+ }
+
+ //分页对象
+ Page page = new Page<>(curPage, limit);
+
+ //分页参数
+ params.put(Constant.PAGE, page);
+
+ //排序字段
+ String orderField = (String)params.get(Constant.ORDER_FIELD);
+ String order = (String)params.get(Constant.ORDER);
+
+ //前端字段排序
+ if(StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)){
+ if(Constant.ASC.equalsIgnoreCase(order)) {
+ return page.addOrder(OrderItem.asc(orderField));
+ }else {
+ return page.addOrder(OrderItem.desc(orderField));
+ }
+ }
+
+ //没有排序字段,则不排序
+ if(StringUtils.isBlank(defaultOrderField)){
+ return page;
+ }
+
+ //默认排序
+ if(isAsc) {
+ page.addOrder(OrderItem.asc(defaultOrderField));
+ }else {
+ page.addOrder(OrderItem.desc(defaultOrderField));
+ }
+
+ return page;
+ }
+
+ protected PageData getPageData(List> list, long total, Class target){
+ List targetList = ConvertUtils.sourceToTarget(list, target);
+
+ return new PageData<>(targetList, total);
+ }
+
+ protected PageData getPageData(IPage page, Class target){
+ return getPageData(page.getRecords(), page.getTotal(), target);
+ }
+
+ protected void paramsToLike(Map params, String... likes){
+ for (String like : likes){
+ String val = (String)params.get(like);
+ if (StringUtils.isNotBlank(val)){
+ params.put(like, "%" + val + "%");
+ }else {
+ params.put(like, null);
+ }
+ }
+ }
+
+ /**
+ *
+ * 判断数据库操作是否成功
+ *
+ *
+ * 注意!! 该方法为 Integer 判断,不可传入 int 基本类型
+ *
+ *
+ * @param result 数据库操作返回影响条数
+ * @return boolean
+ */
+ protected static boolean retBool(Integer result) {
+ return SqlHelper.retBool(result);
+ }
+
+ protected Class currentMapperClass() {
+ return (Class) ReflectionKit.getSuperClassGenericType(getClass(), 0);
+ }
+
+ @Override
+ public Class currentModelClass() {
+ return (Class)ReflectionKit.getSuperClassGenericType(getClass(), 1);
+ }
+
+ protected String getSqlStatement(SqlMethod sqlMethod) {
+ return SqlHelper.getSqlStatement(this.currentMapperClass(), sqlMethod);
+ }
+
+ @Override
+ public boolean insert(T entity) {
+ return BaseServiceImpl.retBool(baseDao.insert(entity));
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean insertBatch(Collection entityList) {
+ return insertBatch(entityList, 100);
+ }
+
+ /**
+ * 批量插入
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean insertBatch(Collection entityList, int batchSize) {
+ String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE);
+ return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
+ }
+
+ /**
+ * 执行批量操作
+ */
+ protected boolean executeBatch(Collection list, int batchSize, BiConsumer consumer) {
+ return SqlHelper.executeBatch(this.currentModelClass(), this.log, list, batchSize, consumer);
+ }
+
+
+ @Override
+ public boolean updateById(T entity) {
+ return BaseServiceImpl.retBool(baseDao.updateById(entity));
+ }
+
+ @Override
+ public boolean update(T entity, Wrapper updateWrapper) {
+ return BaseServiceImpl.retBool(baseDao.update(entity, updateWrapper));
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean updateBatchById(Collection entityList) {
+ return updateBatchById(entityList, 30);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean updateBatchById(Collection entityList, int batchSize) {
+ String sqlStatement = getSqlStatement(SqlMethod.UPDATE_BY_ID);
+ return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
+ MapperMethod.ParamMap param = new MapperMethod.ParamMap<>();
+ param.put(Constants.ENTITY, entity);
+ sqlSession.update(sqlStatement, param);
+ });
+ }
+
+ @Override
+ public T selectById(Serializable id) {
+ return baseDao.selectById(id);
+ }
+
+ @Override
+ public boolean deleteById(Serializable id) {
+ return SqlHelper.retBool(baseDao.deleteById(id));
+ }
+
+ @Override
+ public boolean deleteBatchIds(Collection extends Serializable> idList) {
+ return SqlHelper.retBool(baseDao.deleteBatchIds(idList));
+ }
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/service/impl/CrudServiceImpl.java b/zhongyun-common/src/main/java/com/zhongyun/common/service/impl/CrudServiceImpl.java
new file mode 100644
index 0000000..b3b20ca
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/service/impl/CrudServiceImpl.java
@@ -0,0 +1,72 @@
+package com.zhongyun.common.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
+import com.zhongyun.common.page.PageData;
+import com.zhongyun.common.service.CrudService;
+import com.zhongyun.common.utils.ConvertUtils;
+import org.springframework.beans.BeanUtils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * CRUD基础服务类
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ */
+public abstract class CrudServiceImpl, T, D> extends BaseServiceImpl implements CrudService {
+
+ protected Class currentDtoClass() {
+ return (Class)ReflectionKit.getSuperClassGenericType(getClass(), 2);
+ }
+
+ @Override
+ public PageData page(Map params) {
+ IPage page = baseDao.selectPage(
+ getPage(params, null, false),
+ getWrapper(params)
+ );
+
+ return getPageData(page, currentDtoClass());
+ }
+
+ @Override
+ public List list(Map params) {
+ List entityList = baseDao.selectList(getWrapper(params));
+
+ return ConvertUtils.sourceToTarget(entityList, currentDtoClass());
+ }
+
+ public abstract QueryWrapper getWrapper(Map params);
+
+ @Override
+ public D get(Long id) {
+ T entity = baseDao.selectById(id);
+
+ return ConvertUtils.sourceToTarget(entity, currentDtoClass());
+ }
+
+ @Override
+ public void save(D dto) {
+ T entity = ConvertUtils.sourceToTarget(dto, currentModelClass());
+ insert(entity);
+
+ //copy主键值到dto
+ BeanUtils.copyProperties(entity, dto);
+ }
+
+ @Override
+ public void update(D dto) {
+ T entity = ConvertUtils.sourceToTarget(dto, currentModelClass());
+ updateById(entity);
+ }
+
+ @Override
+ public void delete(Long[] ids) {
+ baseDao.deleteBatchIds(Arrays.asList(ids));
+ }
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/utils/ConvertUtils.java b/zhongyun-common/src/main/java/com/zhongyun/common/utils/ConvertUtils.java
new file mode 100644
index 0000000..7a3d393
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/utils/ConvertUtils.java
@@ -0,0 +1,54 @@
+
+
+package com.zhongyun.common.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 转换工具类
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ */
+public class ConvertUtils {
+ private static Logger logger = LoggerFactory.getLogger(ConvertUtils.class);
+
+ public static T sourceToTarget(Object source, Class target){
+ if(source == null){
+ return null;
+ }
+ T targetObject = null;
+ try {
+ targetObject = target.newInstance();
+ BeanUtils.copyProperties(source, targetObject);
+ } catch (Exception e) {
+ logger.error("convert error ", e);
+ }
+
+ return targetObject;
+ }
+
+ public static List sourceToTarget(Collection> sourceList, Class target){
+ if(sourceList == null){
+ return null;
+ }
+
+ List targetList = new ArrayList<>(sourceList.size());
+ try {
+ for(Object source : sourceList){
+ T targetObject = target.newInstance();
+ BeanUtils.copyProperties(source, targetObject);
+ targetList.add(targetObject);
+ }
+ }catch (Exception e){
+ logger.error("convert error ", e);
+ }
+
+ return targetList;
+ }
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/utils/DateUtils.java b/zhongyun-common/src/main/java/com/zhongyun/common/utils/DateUtils.java
new file mode 100644
index 0000000..9eacf9b
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/utils/DateUtils.java
@@ -0,0 +1,176 @@
+
+
+package com.zhongyun.common.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
+import org.joda.time.LocalDate;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 日期处理
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ */
+public class DateUtils {
+ /** 时间格式(yyyy-MM-dd) */
+ public final static String DATE_PATTERN = "yyyy-MM-dd";
+ /** 时间格式(yyyy-MM-dd HH:mm:ss) */
+ public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ /**
+ * 日期格式化 日期格式为:yyyy-MM-dd
+ * @param date 日期
+ * @return 返回yyyy-MM-dd格式日期
+ */
+ public static String format(Date date) {
+ return format(date, DATE_PATTERN);
+ }
+
+ /**
+ * 日期格式化 日期格式为:yyyy-MM-dd
+ * @param date 日期
+ * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN
+ * @return 返回yyyy-MM-dd格式日期
+ */
+ public static String format(Date date, String pattern) {
+ if(date != null){
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
+ return df.format(date);
+ }
+ return null;
+ }
+
+ /**
+ * 日期解析
+ * @param date 日期
+ * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN
+ * @return 返回Date
+ */
+ public static Date parse(String date, String pattern) {
+ try {
+ return new SimpleDateFormat(pattern).parse(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 字符串转换成日期
+ * @param strDate 日期字符串
+ * @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN
+ */
+ public static Date stringToDate(String strDate, String pattern) {
+ if (StringUtils.isBlank(strDate)){
+ return null;
+ }
+
+ DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
+ return fmt.parseLocalDateTime(strDate).toDate();
+ }
+
+ /**
+ * 根据周数,获取开始日期、结束日期
+ * @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周
+ * @return 返回date[0]开始日期、date[1]结束日期
+ */
+ public static Date[] getWeekStartAndEnd(int week) {
+ DateTime dateTime = new DateTime();
+ LocalDate date = new LocalDate(dateTime.plusWeeks(week));
+
+ date = date.dayOfWeek().withMinimumValue();
+ Date beginDate = date.toDate();
+ Date endDate = date.plusDays(6).toDate();
+ return new Date[]{beginDate, endDate};
+ }
+
+ /**
+ * 对日期的【秒】进行加/减
+ *
+ * @param date 日期
+ * @param seconds 秒数,负数为减
+ * @return 加/减几秒后的日期
+ */
+ public static Date addDateSeconds(Date date, int seconds) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusSeconds(seconds).toDate();
+ }
+
+ /**
+ * 对日期的【分钟】进行加/减
+ *
+ * @param date 日期
+ * @param minutes 分钟数,负数为减
+ * @return 加/减几分钟后的日期
+ */
+ public static Date addDateMinutes(Date date, int minutes) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusMinutes(minutes).toDate();
+ }
+
+ /**
+ * 对日期的【小时】进行加/减
+ *
+ * @param date 日期
+ * @param hours 小时数,负数为减
+ * @return 加/减几小时后的日期
+ */
+ public static Date addDateHours(Date date, int hours) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusHours(hours).toDate();
+ }
+
+ /**
+ * 对日期的【天】进行加/减
+ *
+ * @param date 日期
+ * @param days 天数,负数为减
+ * @return 加/减几天后的日期
+ */
+ public static Date addDateDays(Date date, int days) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusDays(days).toDate();
+ }
+
+ /**
+ * 对日期的【周】进行加/减
+ *
+ * @param date 日期
+ * @param weeks 周数,负数为减
+ * @return 加/减几周后的日期
+ */
+ public static Date addDateWeeks(Date date, int weeks) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusWeeks(weeks).toDate();
+ }
+
+ /**
+ * 对日期的【月】进行加/减
+ *
+ * @param date 日期
+ * @param months 月数,负数为减
+ * @return 加/减几月后的日期
+ */
+ public static Date addDateMonths(Date date, int months) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusMonths(months).toDate();
+ }
+
+ /**
+ * 对日期的【年】进行加/减
+ *
+ * @param date 日期
+ * @param years 年数,负数为减
+ * @return 加/减几年后的日期
+ */
+ public static Date addDateYears(Date date, int years) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusYears(years).toDate();
+ }
+}
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/utils/MessageUtils.java b/zhongyun-common/src/main/java/com/zhongyun/common/utils/MessageUtils.java
new file mode 100644
index 0000000..742761b
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/utils/MessageUtils.java
@@ -0,0 +1,27 @@
+
+
+package com.zhongyun.common.utils;
+
+import org.springframework.context.MessageSource;
+import org.springframework.context.i18n.LocaleContextHolder;
+
+/**
+ * 国际化
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ * @since 1.0.0
+ */
+public class MessageUtils {
+ private static MessageSource messageSource;
+ static {
+ messageSource = (MessageSource)SpringContextUtils.getBean("messageSource");
+ }
+
+ public static String getMessage(int code){
+ return getMessage(code, new String[0]);
+ }
+
+ public static String getMessage(int code, String... params){
+ return messageSource.getMessage(code+"", params, LocaleContextHolder.getLocale());
+ }
+}
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/utils/Result.java b/zhongyun-common/src/main/java/com/zhongyun/common/utils/Result.java
new file mode 100644
index 0000000..06786ed
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/utils/Result.java
@@ -0,0 +1,92 @@
+
+
+package com.zhongyun.common.utils;
+
+import com.zhongyun.common.exception.ErrorCode;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * 响应数据
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ * @since 1.0.0
+ */
+@ApiModel(value = "响应")
+public class Result implements Serializable {
+ private static final long serialVersionUID = 1L;
+ /**
+ * 编码:0表示成功,其他值表示失败
+ */
+ @ApiModelProperty(value = "编码:0表示成功,其他值表示失败")
+ private int code = 0;
+ /**
+ * 消息内容
+ */
+ @ApiModelProperty(value = "消息内容")
+ private String msg = "success";
+ /**
+ * 响应数据
+ */
+ @ApiModelProperty(value = "响应数据")
+ private T data;
+
+ public Result ok(T data) {
+ this.setData(data);
+ return this;
+ }
+
+ public boolean success(){
+ return code == 0 ? true : false;
+ }
+
+ public Result error() {
+ this.code = ErrorCode.INTERNAL_SERVER_ERROR;
+ this.msg = MessageUtils.getMessage(this.code);
+ return this;
+ }
+
+ public Result error(int code) {
+ this.code = code;
+ this.msg = MessageUtils.getMessage(this.code);
+ return this;
+ }
+
+ public Result error(int code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ return this;
+ }
+
+ public Result error(String msg) {
+ this.code = ErrorCode.INTERNAL_SERVER_ERROR;
+ this.msg = msg;
+ return this;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T data) {
+ this.data = data;
+ }
+}
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/utils/SpringContextUtils.java b/zhongyun-common/src/main/java/com/zhongyun/common/utils/SpringContextUtils.java
new file mode 100644
index 0000000..03359ec
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/utils/SpringContextUtils.java
@@ -0,0 +1,49 @@
+
+
+package com.zhongyun.common.utils;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * Spring Context 工具类
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ */
+@Component
+public class SpringContextUtils implements ApplicationContextAware {
+ public static ApplicationContext applicationContext;
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ SpringContextUtils.applicationContext = applicationContext;
+ }
+
+ public static Object getBean(String name) {
+ return applicationContext.getBean(name);
+ }
+
+ public static T getBean(Class requiredType) {
+ return applicationContext.getBean(requiredType);
+ }
+
+ public static T getBean(String name, Class requiredType) {
+ return applicationContext.getBean(name, requiredType);
+ }
+
+ public static boolean containsBean(String name) {
+ return applicationContext.containsBean(name);
+ }
+
+ public static boolean isSingleton(String name) {
+ return applicationContext.isSingleton(name);
+ }
+
+ public static Class extends Object> getType(String name) {
+ return applicationContext.getType(name);
+ }
+
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/validator/AssertUtils.java b/zhongyun-common/src/main/java/com/zhongyun/common/validator/AssertUtils.java
new file mode 100644
index 0000000..895db10
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/validator/AssertUtils.java
@@ -0,0 +1,92 @@
+
+
+package com.zhongyun.common.validator;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.ArrayUtil;
+import com.zhongyun.common.exception.ErrorCode;
+import com.zhongyun.common.exception.RenException;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 校验工具类
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ * @since 1.0.0
+ */
+public class AssertUtils {
+
+ public static void isBlank(String str, String... params) {
+ isBlank(str, ErrorCode.NOT_NULL, params);
+ }
+
+ public static void isBlank(String str, Integer code, String... params) {
+ if(code == null){
+ throw new RenException(ErrorCode.NOT_NULL, "code");
+ }
+
+ if (StringUtils.isBlank(str)) {
+ throw new RenException(code, params);
+ }
+ }
+
+ public static void isNull(Object object, String... params) {
+ isNull(object, ErrorCode.NOT_NULL, params);
+ }
+
+ public static void isNull(Object object, Integer code, String... params) {
+ if(code == null){
+ throw new RenException(ErrorCode.NOT_NULL, "code");
+ }
+
+ if (object == null) {
+ throw new RenException(code, params);
+ }
+ }
+
+ public static void isArrayEmpty(Object[] array, String... params) {
+ isArrayEmpty(array, ErrorCode.NOT_NULL, params);
+ }
+
+ public static void isArrayEmpty(Object[] array, Integer code, String... params) {
+ if(code == null){
+ throw new RenException(ErrorCode.NOT_NULL, "code");
+ }
+
+ if(ArrayUtil.isEmpty(array)){
+ throw new RenException(code, params);
+ }
+ }
+
+ public static void isListEmpty(List> list, String... params) {
+ isListEmpty(list, ErrorCode.NOT_NULL, params);
+ }
+
+ public static void isListEmpty(List> list, Integer code, String... params) {
+ if(code == null){
+ throw new RenException(ErrorCode.NOT_NULL, "code");
+ }
+
+ if(CollUtil.isEmpty(list)){
+ throw new RenException(code, params);
+ }
+ }
+
+ public static void isMapEmpty(Map map, String... params) {
+ isMapEmpty(map, ErrorCode.NOT_NULL, params);
+ }
+
+ public static void isMapEmpty(Map map, Integer code, String... params) {
+ if(code == null){
+ throw new RenException(ErrorCode.NOT_NULL, "code");
+ }
+
+ if(MapUtil.isEmpty(map)){
+ throw new RenException(code, params);
+ }
+ }
+}
\ No newline at end of file
diff --git a/zhongyun-common/src/main/java/com/zhongyun/common/validator/ValidatorUtils.java b/zhongyun-common/src/main/java/com/zhongyun/common/validator/ValidatorUtils.java
new file mode 100644
index 0000000..c0d1828
--- /dev/null
+++ b/zhongyun-common/src/main/java/com/zhongyun/common/validator/ValidatorUtils.java
@@ -0,0 +1,51 @@
+
+
+package com.zhongyun.common.validator;
+
+import com.zhongyun.common.exception.RenException;
+import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.context.support.ResourceBundleMessageSource;
+import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * hibernate-validator校验工具类
+ * 参考文档:http://docs.jboss.org/hibernate/validator/6.0/reference/en-US/html_single/
+ *
+ * @author Gaoming fangaoming0208@aliyun.com
+ * @since 1.0.0
+ */
+public class ValidatorUtils {
+
+ private static ResourceBundleMessageSource getMessageSource() {
+ ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
+ bundleMessageSource.setDefaultEncoding("UTF-8");
+ bundleMessageSource.setBasenames("i18n/validation");
+ return bundleMessageSource;
+ }
+
+ /**
+ * 校验对象
+ * @param object 待校验对象
+ * @param groups 待校验的组
+ */
+ public static void validateEntity(Object object, Class>... groups)
+ throws RenException {
+ Locale.setDefault(LocaleContextHolder.getLocale());
+ Validator validator = Validation.byDefaultProvider().configure().messageInterpolator(
+ new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource())))
+ .buildValidatorFactory().getValidator();
+
+ Set> constraintViolations = validator.validate(object, groups);
+ if (!constraintViolations.isEmpty()) {
+ ConstraintViolation