diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b60bb04492e29189cf5ffb414daeaf10fa116406 --- /dev/null +++ b/pom.xml @@ -0,0 +1,143 @@ + + + 4.0.0 + + com.es + disped + 1.0.0-SNAPSHOT + + disped-common + disped-common + http://maven.apache.org + + + + commons-io + commons-io + 2.6 + + + commons-fileupload + commons-fileupload + 1.3.3 + + + commons-io + commons-io + + + + + org.apache.commons + commons-lang3 + 3.7 + + + commons-logging + commons-logging + 1.2 + + + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-aspects + ${spring.version} + + + aspectjweaver + org.aspectj + + + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-jms + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + + org.aspectj + aspectjweaver + ${aspectj.version} + + + org.aspectj + aspectjrt + ${aspectj.version} + + + + com.alibaba + fastjson + 1.2.47 + + + + org.mybatis + mybatis + 3.4.5 + + + org.mybatis + mybatis-spring + 1.3.1 + + + + com.github.pagehelper + pagehelper + 5.1.2 + + + + com.aliyun + aliyun-java-sdk-core + 4.1.1 + + + + org.apache.httpcomponents + httpclient + 4.3.6 + + + + dom4j + dom4j + 1.6.1 + + + com.thoughtworks.xstream + xstream + 1.3.1 + + + diff --git a/src/main/java/com/es/disped/common/annotation/DynamicDataSource.java b/src/main/java/com/es/disped/common/annotation/DynamicDataSource.java new file mode 100644 index 0000000000000000000000000000000000000000..647ea13d567c16ea9912cb458b7c7a6f8f5f1174 --- /dev/null +++ b/src/main/java/com/es/disped/common/annotation/DynamicDataSource.java @@ -0,0 +1,29 @@ +package com.es.disped.common.annotation; + +import java.lang.annotation.*; + + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午4:16:08
+ * + * 名称:DynamicDataSource
+ *

+ * 描述:动态数据源切换注解(默认切换扩展数据源)
+ */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface DynamicDataSource { + + /** + * 需要切换的数据源名称
+ * + * @return DataSourceName + */ + String value() default "extendDataSource"; +} diff --git a/src/main/java/com/es/disped/common/aspect/DataSourceAspect.java b/src/main/java/com/es/disped/common/aspect/DataSourceAspect.java new file mode 100644 index 0000000000000000000000000000000000000000..50af6d648718a22b82b41a378c48f1af59170888 --- /dev/null +++ b/src/main/java/com/es/disped/common/aspect/DataSourceAspect.java @@ -0,0 +1,55 @@ +package com.es.disped.common.aspect; + +import com.es.disped.common.annotation.DynamicDataSource; +import com.es.disped.common.spring.DataSourceContextHolder; + +import java.lang.reflect.Method; + +import org.springframework.aop.AfterReturningAdvice; +import org.springframework.aop.MethodBeforeAdvice; + + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午4:16:42
+ * 名称:DataSourceAspect
+ *

+ * 描述:切换数据源 aop 切面(order=1 优先级最高)
+ */ +public class DataSourceAspect implements MethodBeforeAdvice, AfterReturningAdvice { + + + /** + * 前置通知(用于在事物开启之前切换数据源)
+ * + * @see MethodBeforeAdvice#before(Method, Object[], Object) + */ + public void before(Method method, Object[] args, Object target) throws Throwable { + if (method.isAnnotationPresent(DynamicDataSource.class)) { + DynamicDataSource dataSource = method.getAnnotation(DynamicDataSource.class); + if (dataSource.value() != "defaultDataSource") { + DataSourceContextHolder.setDataSource(dataSource.value()); + System.out.println(">>>>>>>>>>>>>>>>>>>>>>切换数据源:"+dataSource.value()); + } + } + } + + /** + * 后置通知(用于清理切换过的数据源,还原默认数据源)
+ * + * @see AfterReturningAdvice#afterReturning(Object, Method, Object[], Object) + */ + public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { + if (method.isAnnotationPresent(DynamicDataSource.class)) { + DynamicDataSource dataSource = method.getAnnotation(DynamicDataSource.class); + if (dataSource.value() != "defaultDataSource") { + DataSourceContextHolder.clearDataSource(); + } + } + } + +} diff --git a/src/main/java/com/es/disped/common/constant/AliSms.java b/src/main/java/com/es/disped/common/constant/AliSms.java new file mode 100644 index 0000000000000000000000000000000000000000..30d671f5f81769d1a271aa258c89606b874fa91d --- /dev/null +++ b/src/main/java/com/es/disped/common/constant/AliSms.java @@ -0,0 +1,93 @@ +/** + * + */ +package com.es.disped.common.constant; + +import java.io.Serializable; + +import com.es.disped.common.support.BaseSupport; + +/** + * @author Anson
+ * + * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 下午1:44:56
+ * + * 名称:SmsConstants.java
+ * + * 描述:阿里云短信常量
+ */ +public class AliSms extends BaseSupport implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1528222552685097162L; + public static String ALI_MESSAGE_REGIION_ID = "cn-hangzhou"; + protected static String ALI_ACCESS_KEY_ID="LTAIwKpMxSL7O2Uc"; + protected static String ALI_ACCESS_SECRET="CzNIMsO5UFRMgOvUXpl3ZjJNGTikAb"; + + public enum ALI_MESSAGE_SIGN_NAME + { + ES_TECH(1,"易享科技"); + + private int name; + private String value; + + private ALI_MESSAGE_SIGN_NAME(int name, String value) { + this.setName(name); + this.setValue(value); + } + + public int getName() { + return name; + } + + public void setName(int name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public enum ALI_MESSAGE_TEMPLATE_CODE + { + VERTIFY_CODE(1,"SMS_165678220"), + PASSWORD_RESET(2,"SMS_166095362"), + ACCOUNT_VERTIFY(3,"SMS_166095366"), + ORDINARY_NOTICE(4,"SMS_166665311"); + + private int name; + private String value; + + private ALI_MESSAGE_TEMPLATE_CODE(int name, String value) { + this.setName(name); + this.setValue(value); + } + + public int getName() { + return name; + } + + public void setName(int name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/src/main/java/com/es/disped/common/constant/DataSourceName.java b/src/main/java/com/es/disped/common/constant/DataSourceName.java new file mode 100644 index 0000000000000000000000000000000000000000..6f85a019825fb44e3efd189ad7b0d16dbfc2ad30 --- /dev/null +++ b/src/main/java/com/es/disped/common/constant/DataSourceName.java @@ -0,0 +1,50 @@ +package com.es.disped.common.constant; + + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午4:16:26
+ * 名称:DataSourceName
+ *

+ * 描述:常量定义,枚举类型多数据源名称
+ */ +public enum DataSourceName { + + /** + * 默认数据源
+ */ + DEFAULT("defaultDataSource"), + + /** + * 扩展数据源
+ */ + EXTEND("extendDataSource"); + + /** + * 数据源名称
+ */ + private String name; + + /** + * 构造方法
+ * + * @param name 数据源名称 + */ + DataSourceName(String name) { + this.name = name; + } + + /** + * 获取名称的 get 方法
+ * + * @return String 数据源真实名称 + */ + public String getName() { + return name; + } + +} diff --git a/src/main/java/com/es/disped/common/constant/RecordStatus.java b/src/main/java/com/es/disped/common/constant/RecordStatus.java new file mode 100644 index 0000000000000000000000000000000000000000..1aaef30546967276a15ecb64ca123b3084852388 --- /dev/null +++ b/src/main/java/com/es/disped/common/constant/RecordStatus.java @@ -0,0 +1,54 @@ +package com.es.disped.common.constant; + +/** + * @Author Anson
+ * + * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年4月27日
+ * + * @名称: DataStatusModel.java
+ *

+ * @描述: 数据状态枚举模型
+ */ +public enum RecordStatus { + + VERTIFY("审核中",1),USEAGE("使用中",2),DELETE("已删除",3),FREEZE("冻结",4); + + private String name; + private int value; + + private RecordStatus(String name,int value) + { + this.setName(name); + this.setValue(value); + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public static String getName(int value) + { + for(int i=0;i + * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月19日 下午8:47:30
+ * 微信消息类型 + */ + public enum MessageType + { + TEXT("本文消息","text"),IMAGE("图片消息","image"),VOICE("语音消息","voice"),VIDEO("视频消息","video"), + LINK("链接消息","link"),LOCATION("位置消息","location"),EVENT("事件消息","event"),EVENT_SUBSCRIBE("关注","subscribe"), + EVENT_UNSUBSCRIBE("取消关注","unsubscribe"),CLICK("点击菜单","CLICK"),VIEW("视图菜单","view"); + + String name; + String value; + + private MessageType(String name, String value) { + this.setName(name); + this.setValue(value); + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + } + + /** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月17日 下午1:15:36
+ * 微信模板信息 + */ + public enum TemplateMessage + { + COURSE_RESERVATION_SUCCESS("课程预约成功通知","PDI8SwmeInfh5YHDTivjemste1V-kUcNnoJ6D7uSe0g"), + COURSE_NOTICE("上课提醒","9IkiqzdU8LkpdjaGKaTS2XBbH2dOhb1JHj0u5Hqm8P0"); + + String name; + String value; + + private TemplateMessage(String name, String value) { + this.setName(name); + this.setValue(value); + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + } + + public static String getAccessTokenUrl() + { + return accessTokenUrl; + } + + public static String getTemplateMessageUrl(String accessToken) { + setTemplateMessageUrl(accessToken); + return templateMessageUrl; + } + + private static void setTemplateMessageUrl(String accessToken) { + WeChat.templateMessageUrl=WeChat.templateMessageUrl.replace("ACCESS_TOKEN_VAL", accessToken); + } + + public static void setAccessTokenUrl(String accessTokenUrl) { + WeChat.accessTokenUrl = accessTokenUrl; + } + + public static String getTemplateMessageDetailUrl() { + return TemplateMessageDetailUrl; + } + + public static void setTemplateMessageDetailUrl(String templateMessageDetailUrl) { + TemplateMessageDetailUrl = templateMessageDetailUrl; + } + +} diff --git a/src/main/java/com/es/disped/common/model/MsgModel.java b/src/main/java/com/es/disped/common/model/MsgModel.java new file mode 100644 index 0000000000000000000000000000000000000000..702d290f9cdc4d40d551561dce7658e92101cbbd --- /dev/null +++ b/src/main/java/com/es/disped/common/model/MsgModel.java @@ -0,0 +1,147 @@ +package com.es.disped.common.model; + +import java.io.Serializable; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午1:01:00
+ * + * 名称:MsgModel
+ *

+ * 描述:消息模型
+ * + */ +public class MsgModel implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 状态值
+ */ + private Integer status; + + /** + * 消息
+ */ + private String msg; + + /** + * 返回对象
+ */ + private Object res; + + /** + * 获取状态值
+ * + * @return Integer 状态值 + */ + public Integer getStatus() { + return status; + } + + /** + * 设置状态值
+ * + * @param status 状态值 + */ + public void setStatus(Integer status) { + this.status = status; + } + + /** + * 获取消息
+ * + * @return String 消息内容 + */ + public String getMsg() { + return msg; + } + + /** + * 设置消息
+ * + * @param msg 消息内容 + */ + public void setMsg(String msg) { + this.msg = msg; + } + + /** + * 获取结果对象
+ * + * @return Object 结果对象 + */ + public Object getRes() { + return res; + } + + /** + * 设置结果对象
+ * + * @param res 结果对象 + */ + public void setRes(Object res) { + this.res = res; + } + + /** + * 无参构造方法,构建 MsgModel 对象
+ */ + public MsgModel() { + super(); + } + + /** + * 代参构造方法,构建 MsgModel 对象
+ * + * @param status 状态值 + * @param msg 消息内容 + * @param res 结果对象 + */ + public MsgModel(Integer status, String msg, Object res) { + super(); + this.status = status; + this.msg = msg; + this.res = res; + } + + /** + * 代参构造方法,构建 MsgModel 对象
+ * + * @param status 状态值 + * @param msg 消息内容 + * @param res 结果对象 + */ + public MsgModel(Integer status, Object res) { + super(); + this.status = status; + this.res = res; + } + + /** + * 代参构造方法,构建 MsgModel 对象
+ * + * @param status 状态值 + * @param msg 消息内容 + */ + public MsgModel(Integer status, String msg) { + super(); + this.status = status; + this.msg = msg; + } + + /** + * 代参构造方法,构建 MsgModel 对象
+ * + * @param msg 消息内容 + */ + public MsgModel(String msg) { + super(); + this.msg = msg; + } + +} \ No newline at end of file diff --git a/src/main/java/com/es/disped/common/model/PageModel.java b/src/main/java/com/es/disped/common/model/PageModel.java new file mode 100644 index 0000000000000000000000000000000000000000..e0eddd8d23996b0d2292568d4ba373b0428b883a --- /dev/null +++ b/src/main/java/com/es/disped/common/model/PageModel.java @@ -0,0 +1,195 @@ +package com.es.disped.common.model; + +import com.github.pagehelper.Page; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午1:01:40
+ * + * 名称:PageModel
+ *

+ * 描述:分页Page对象,与页面 boostrapTable 插件交互使用
+ */ +public class PageModel implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 总记录数
+ */ + private long total; + + /** + * 结果集
+ */ + private List rows; + + /** + * 页码值
+ */ + private int pageNum; + + /** + * 每页记录数
+ */ + private int pageSize; + + /** + * 总页数
+ */ + private int pages; + + /** + * 当前页的数量 <= pageSize,该属性来自ArrayList的size属性
+ */ + private int size; + + /** + * 无参构造方法,构建 PageModel 对象
+ */ + public PageModel() { + super(); + } + + /** + * 构造方法(根据参数 List 创建 PageModel)
+ * + * @param list 分页查询出的 Page 集合 + */ + public PageModel(List list) { + if (list instanceof Page) { + Page page = (Page) list; + this.pageNum = page.getPageNum(); + this.pageSize = page.getPageSize(); + this.total = page.getTotal(); + this.pages = page.getPages(); + List customList = new ArrayList(); + for (T t : list) { + customList.add(t); + } + this.rows = customList; + this.size = page.size(); + } + } + + /** + * 获取总记录数
+ * + * @return long 总记录数 + */ + public long getTotal() { + return total; + } + + /** + * 设置总记录数
+ * + * @param total 总记录数 + */ + public void setTotal(long total) { + this.total = total; + } + + /** + * 获取数据集合
+ * + * @return List 结果数据集合 + */ + public List getRows() { + return rows; + } + + /** + * 设置数据结合(使用 forEach 遍历集合转换对象)
+ * + * @param rows 结果对象集合 + */ + public void setRows(List rows) { + List list = new ArrayList(); + for (T t : rows) { + list.add(t); + } + this.rows = list; + } + + /** + * 获取当前页码值
+ * + * @return int 当前页码值 + */ + public int getPageNum() { + return pageNum; + } + + /** + * 设置当前页码值
+ * + * @param pageNum 当前页码值 + */ + public void setPageNum(int pageNum) { + this.pageNum = pageNum; + } + + /** + * 获取每页记录数
+ * + * @return int 每页记录数 + */ + public int getPageSize() { + return pageSize; + } + + /** + * 设置每页记录数
+ * + * @param pageSize 每页记录数 + */ + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + /** + * 获取总页数
+ * + * @return int 总页数 + */ + public int getPages() { + return pages; + } + + /** + * 设置总页数
+ * + * @param pages 总页数 + */ + public void setPages(int pages) { + this.pages = pages; + } + + /** + * 获取当前页数量
+ * + * @return int 当前页条数 + */ + public int getSize() { + return size; + } + + /** + * 设置当前页数量
+ * + * @param size 当前页条数 + */ + public void setSize(int size) { + this.size = size; + } + +} \ No newline at end of file diff --git a/src/main/java/com/es/disped/common/service/BaseService.java b/src/main/java/com/es/disped/common/service/BaseService.java new file mode 100644 index 0000000000000000000000000000000000000000..efb6dc30a4a6da611b99defa36787e5160e0e87e --- /dev/null +++ b/src/main/java/com/es/disped/common/service/BaseService.java @@ -0,0 +1,200 @@ +package com.es.disped.common.service; + +import org.apache.ibatis.annotations.Param; + +import com.es.disped.common.model.PageModel; + +import java.util.List; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午1:02:09
+ * + * 描述:通用base接口,封装CRUD操作
+ */ +public interface BaseService { + + /** + * 根据条件查询记录数量 + * + * @param example + * @return + */ + int countByExample(Example example); + + /** + * 根据条件删除记录 + * + * @param example + * @return + */ + int deleteByExample(Example example); + + /** + * 根据主键删除记录 + * + * @param id + * @return + */ + int deleteByPrimaryKey(Object id); + + /** + * 插入记录 + * + * @param record + * @return + */ + int insert(Record record); + + /** + * 插入记录有效字段 + * + * @param record + * @return + */ + int insertSelective(Record record); + + /** + * 根据条件查询记录,附带BLOB字段 + * + * @param example + * @return + */ + List selectByExampleWithBLOBs(Example example); + + /** + * 根据条件查询记录 + * + * @param example + * @return + */ + List selectByExample(Example example); + + /** + * 根据条件查询记录并按页码分页,附带BLOB字段 + * + * @param example 条件 + * @param pageNum 页数 + * @param pageSize 每页记录数 + * @return + */ + PageModel selectByExampleWithBLOBsForStartPage(Example example, Integer pageNum, Integer pageSize); + + /** + * 根据条件查询记录并按页码分页 + * + * @param example 条件 + * @param pageNum 页数 + * @param pageSize 每页记录数 + * @return + */ + PageModel selectByExampleForStartPage(Example example, Integer pageNum, Integer pageSize); + + /** + * 根据条件查询记录并按最后记录数分页,附带BLOB字段 + * + * @param example 条件 + * @param offset 跳过数量 + * @param limit 查询数量 + * @return + */ + PageModel selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit); + + /** + * 根据条件查询记录并按最后记录数分页 + * + * @param example 条件 + * @param offset 跳过数量 + * @param limit 查询数量 + * @return + */ + PageModel selectByExampleForOffsetPage(Example example, Integer offset, Integer limit); + + /** + * 根据条件查询第一条记录 + * + * @param example + * @return + */ + Record selectFirstByExample(Example example); + + /** + * 根据条件查询第一条记录,附带BLOB字段 + * + * @param example + * @return + */ + Record selectFirstByExampleWithBLOBs(Example example); + + /** + * 根据主键查询记录 + * + * @param id + * @return + */ + Record selectByPrimaryKey(Object id); + + /** + * 根据条件更新有效字段 + * + * @param record + * @param example + * @return + */ + int updateByExampleSelective(@Param("record") Record record, @Param("example") Example example); + + /** + * 根据条件更新记录有效字段,附带BLOB字段 + * + * @param record + * @param example + * @return + */ + int updateByExampleWithBLOBs(@Param("record") Record record, @Param("example") Example example); + + /** + * 根据条件更新记录 + * + * @param record + * @param example + * @return + */ + int updateByExample(@Param("record") Record record, @Param("example") Example example); + + /** + * 根据主键更新记录有效字段 + * + * @param record + * @return + */ + int updateByPrimaryKeySelective(Record record); + + /** + * 根据主键更新记录,附带BLOB字段 + * + * @param record + * @return + */ + int updateByPrimaryKeyWithBLOBs(Record record); + + /** + * 根据主键更新记录 + * + * @param record + * @return + */ + int updateByPrimaryKey(Record record); + + /** + * 根据主键批量删除记录 + * + * @param ids + * @return + */ + int deleteByPrimaryKeys(Object...ids); + +} diff --git a/src/main/java/com/es/disped/common/service/impl/BaseServiceImpl.java b/src/main/java/com/es/disped/common/service/impl/BaseServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..563e8119af90b1b41d93c49dd2348b359e4a3aab --- /dev/null +++ b/src/main/java/com/es/disped/common/service/impl/BaseServiceImpl.java @@ -0,0 +1,379 @@ +package com.es.disped.common.service.impl; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.ObjectUtils; + +import com.es.disped.common.model.PageModel; +import com.es.disped.common.service.BaseService; +import com.github.pagehelper.PageHelper; + + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午1:02:24
+ * + * 描述:基本base接口,CRUD泛型接口实现类,抽象类只能被继承
+ */ +@SuppressWarnings("unchecked") +public abstract class BaseServiceImpl implements BaseService { + + @Autowired + private Mapper mapper; + + public int countByExample(Example example) { + int res = 0; + try { + Method countByExample = mapper.getClass().getDeclaredMethod("countByExample", example.getClass()); + Object result = countByExample.invoke(mapper, example); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int deleteByExample(Example example) { + int res = 0; + try { + Method deleteByExample = mapper.getClass().getDeclaredMethod("deleteByExample", example.getClass()); + Object result = deleteByExample.invoke(mapper, example); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int deleteByPrimaryKey(Object id) { + int res = 0; + try { + Method deleteByPrimaryKey = mapper.getClass().getDeclaredMethod("deleteByPrimaryKey", id.getClass()); + Object result = deleteByPrimaryKey.invoke(mapper, id); + return Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int insert(Record record) { + int res = 0; + try { + Method insert = mapper.getClass().getDeclaredMethod("insert", record.getClass()); + Object result = insert.invoke(mapper, record); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int insertSelective(Record record) { + int res = 0; + try { + Method insertSelective = mapper.getClass().getDeclaredMethod("insertSelective", record.getClass()); + Object result = insertSelective.invoke(mapper, record); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public List selectByExampleWithBLOBs(Example example) { + List list = null; + try { + Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass()); + Object result = selectByExampleWithBLOBs.invoke(mapper, example); + list = (List) result; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return list; + } + + public List selectByExample(Example example) { + List list = null; + try { + Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass()); + Object result = selectByExample.invoke(mapper, example); + list = (List) result; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return list; + } + + public PageModel selectByExampleWithBLOBsForStartPage(Example example, Integer pageNum, Integer pageSize) { + PageModel pageModel = null; + try { + Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass()); + PageHelper.startPage(pageNum, pageSize); + Object result = selectByExampleWithBLOBs.invoke(mapper, example); + pageModel = new PageModel((List) result); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return pageModel; + } + + public PageModel selectByExampleForStartPage(Example example, Integer pageNum, Integer pageSize) { + PageModel pageModel = null; + try { + Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass()); + PageHelper.startPage(pageNum, pageSize); + Object result = selectByExample.invoke(mapper, example); + pageModel = new PageModel((List) result); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return pageModel; + } + + public PageModel selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit) { + PageModel pageModel = null; + try { + Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass()); + PageHelper.offsetPage(offset, limit); + Object result = selectByExampleWithBLOBs.invoke(mapper, example); + pageModel = new PageModel((List) result); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return pageModel; + } + + public PageModel selectByExampleForOffsetPage(Example example, Integer offset, Integer limit) { + PageModel pageModel = null; + try { + Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass()); + PageHelper.offsetPage(offset, limit); + Object result = selectByExample.invoke(mapper, example); + pageModel = new PageModel((List) result); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return pageModel; + } + + public Record selectFirstByExample(Example example) { + Record res = null; + try { + Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass()); + List result = (List) selectByExample.invoke(mapper, example); + if (null != result && result.size() > 0) { + res = result.get(0); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public Record selectFirstByExampleWithBLOBs(Example example) { + Record res = null; + try { + Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass()); + List result = (List) selectByExampleWithBLOBs.invoke(mapper, example); + if (null != result && result.size() > 0) { + res = result.get(0); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public Record selectByPrimaryKey(Object id) { + Record res = null; + try { + Method selectByPrimaryKey = mapper.getClass().getDeclaredMethod("selectByPrimaryKey", id.getClass()); + Object result = selectByPrimaryKey.invoke(mapper, id); + res = (Record) result; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int updateByExampleSelective(@Param("record") Record record, @Param("example") Example example) { + int res = 0; + try { + Method updateByExampleSelective = mapper.getClass().getDeclaredMethod("updateByExampleSelective", record.getClass(), example.getClass()); + Object result = updateByExampleSelective.invoke(mapper, record, example); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int updateByExampleWithBLOBs(@Param("record") Record record, @Param("example") Example example) { + int res = 0; + try { + Method updateByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("updateByExampleWithBLOBs", record.getClass(), example.getClass()); + Object result = updateByExampleWithBLOBs.invoke(mapper, record, example); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int updateByExample(@Param("record") Record record, @Param("example") Example example) { + int res = 0; + try { + Method updateByExample = mapper.getClass().getDeclaredMethod("updateByExample", record.getClass(), example.getClass()); + Object result = updateByExample.invoke(mapper, record, example); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int updateByPrimaryKeySelective(Record record) { + int res = 0; + try { + Method updateByPrimaryKeySelective = mapper.getClass().getDeclaredMethod("updateByPrimaryKeySelective", record.getClass()); + Object result = updateByPrimaryKeySelective.invoke(mapper, record); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int updateByPrimaryKeyWithBLOBs(Record record) { + int res = 0; + try { + Method updateByPrimaryKeyWithBLOBs = mapper.getClass().getDeclaredMethod("updateByPrimaryKeyWithBLOBs", record.getClass()); + Object result = updateByPrimaryKeyWithBLOBs.invoke(mapper, record); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int updateByPrimaryKey(Record record) { + int res = 0; + try { + Method updateByPrimaryKey = mapper.getClass().getDeclaredMethod("updateByPrimaryKey", record.getClass()); + Object result = updateByPrimaryKey.invoke(mapper, record); + res = Integer.parseInt(String.valueOf(result)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return res; + } + + public int deleteByPrimaryKeys(Object...ids) { + int count = 0; + try { + if(!ObjectUtils.isEmpty(ids)){ + for(Object id:ids){ + Method deleteByPrimaryKey = mapper.getClass().getDeclaredMethod("deleteByPrimaryKey", id.getClass()); + Object result = deleteByPrimaryKey.invoke(mapper, id); + count += Integer.parseInt(String.valueOf(result)); + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return count; + } +} diff --git a/src/main/java/com/es/disped/common/sms/AliMsg.java b/src/main/java/com/es/disped/common/sms/AliMsg.java new file mode 100644 index 0000000000000000000000000000000000000000..3f156818d6094b91180d9c4b9bf58efbb6a9f969 --- /dev/null +++ b/src/main/java/com/es/disped/common/sms/AliMsg.java @@ -0,0 +1,241 @@ +/** + * + */ +package com.es.disped.common.sms; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * @author Anson
+ * + * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 上午11:50:31
+ * + * 名称:AliMsg.java
+ * + * 描述:阿里云短信客户端返回信息
+ */ +public class AliMsg implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -8926141311343135404L; + private String Message=null; + private String RequestId=null; + private String BizId=null; + private String Code=null; + private int TotalCount; + private List SmsSendDetailDTOs=null; + /** + * + */ + public AliMsg() { + this.SmsSendDetailDTOs=new ArrayList(); + } + /** + * + * @author Anson
+ * + * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 下午9:14:34
+ * + * 名称:AliQueryMsg.java
+ * + * 描述:短信查询结果
+ */ + class SmsSendDetailDTO + { + private String SendDate=null; + private String OutId=null; + private int SendStatus; + private String ReceiveDate=null; + private String ErrCode=null; + private String TemplateCode=null; + private String Content=null; + private String PhoneNum=null; + /** + * + */ + public SmsSendDetailDTO() { + + } + /** + * @return the sendDate + */ + public String getSendDate() { + return SendDate; + } + /** + * @param sendDate the sendDate to set + */ + public void setSendDate(String sendDate) { + SendDate = sendDate; + } + /** + * @return the outId + */ + public String getOutId() { + return OutId; + } + /** + * @param outId the outId to set + */ + public void setOutId(String outId) { + OutId = outId; + } + /** + * @return the sendStatus + */ + public int getSendStatus() { + return SendStatus; + } + /** + * @param sendStatus the sendStatus to set + */ + public void setSendStatus(int sendStatus) { + SendStatus = sendStatus; + } + /** + * @return the receiveDate + */ + public String getReceiveDate() { + return ReceiveDate; + } + /** + * @param receiveDate the receiveDate to set + */ + public void setReceiveDate(String receiveDate) { + ReceiveDate = receiveDate; + } + /** + * @return the errCode + */ + public String getErrCode() { + return ErrCode; + } + /** + * @param errCode the errCode to set + */ + public void setErrCode(String errCode) { + ErrCode = errCode; + } + /** + * @return the templateCode + */ + public String getTemplateCode() { + return TemplateCode; + } + /** + * @param templateCode the templateCode to set + */ + public void setTemplateCode(String templateCode) { + TemplateCode = templateCode; + } + /** + * @return the content + */ + public String getContent() { + return Content; + } + /** + * @param content the content to set + */ + public void setContent(String content) { + Content = content; + } + /** + * @return the phoneNum + */ + public String getPhoneNum() { + return PhoneNum; + } + /** + * @param phoneNum the phoneNum to set + */ + public void setPhoneNum(String phoneNum) { + PhoneNum = phoneNum; + } + } + /** + * @return the message + */ + public String getMessage() { + return Message; + } + /** + * @param message the message to set + */ + public void setMessage(String message) { + Message = message; + } + /** + * @return the requestId + */ + public String getRequestId() { + return RequestId; + } + /** + * @param requestId the requestId to set + */ + public void setRequestId(String requestId) { + RequestId = requestId; + } + /** + * @return the bizId + */ + public String getBizId() { + return BizId; + } + /** + * @param bizId the bizId to set + */ + public void setBizId(String bizId) { + BizId = bizId; + } + /** + * @return the code + */ + public String getCode() { + return Code; + } + /** + * @param code the code to set + */ + public void setCode(String code) { + Code = code; + } + /** + * @return the totalCount + */ + public int getTotalCount() { + return TotalCount; + } + /** + * @param totalCount the totalCount to set + */ + public void setTotalCount(int totalCount) { + TotalCount = totalCount; + } + /** + * @return the smsSendDetailDTOs + */ + public List getSmsSendDetailDTOs() { + return SmsSendDetailDTOs; + } + /** + * @param smsSendDetailDTOs the smsSendDetailDTOs to set + */ + public void setSmsSendDetailDTOs(List smsSendDetailDTOs) { + SmsSendDetailDTOs = smsSendDetailDTOs; + } +} diff --git a/src/main/java/com/es/disped/common/sms/SmsClient.java b/src/main/java/com/es/disped/common/sms/SmsClient.java new file mode 100644 index 0000000000000000000000000000000000000000..e8394e3895ef2a58a8f5c09762b700ff27125b4c --- /dev/null +++ b/src/main/java/com/es/disped/common/sms/SmsClient.java @@ -0,0 +1,120 @@ +/** + * + */ +package com.es.disped.common.sms; + +import com.aliyuncs.CommonRequest; +import com.aliyuncs.CommonResponse; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.profile.DefaultProfile; +import com.es.disped.common.constant.AliSms; +/** + * @author Anson
+ * + * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 下午1:11:04
+ * + * 名称:SmsClient.java
+ * + * 描述:提供阿里云短信客户端
+ */ +public class SmsClient extends AliSms{ + + /** + * + */ + private static final long serialVersionUID = 1630607837618861484L; + private IAcsClient client=null; + private CommonRequest request=null; + private CommonResponse response=null; + private int status; + private AliMsg aliMsg=null; + + public SmsClient() { + this.request=new CommonRequest(); + this.client = new DefaultAcsClient(DefaultProfile.getProfile( + ALI_MESSAGE_REGIION_ID, ALI_ACCESS_KEY_ID, ALI_ACCESS_SECRET)); + } + + /** + * @return the client + */ + public IAcsClient getClient() { + return client; + } + + /** + * @param client the client to set + */ + public void setClient(IAcsClient client) { + this.client = client; + } + + /** + * @return the request + */ + public CommonRequest getRequest() { + return request; + } + + /** + * @param request the request to set + */ + public void setRequest(CommonRequest request) { + this.request = request; + } + + /** + * @return the response + */ + public CommonResponse getResponse() { + return response; + } + + /** + * @param response the response to set + */ + public void setResponse(CommonResponse response) { + this.response = response; + } + + /** + * @return the status + */ + public int getStatus() { + if(!this.isNull(getResponse())) + { + setStatus(this.getResponse().getHttpStatus()); + } + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(int status) { + this.status = status; + } + + /** + * @return the aliMsg + */ + public AliMsg getAliMsg() { + if(!this.isNull(getResponse())) + { + aliMsg=this.fromJson(this.getResponse().getData(), AliMsg.class); + } + return aliMsg; + } + + /** + * @param aliMsg the aliMsg to set + */ + public void setAliMsg(AliMsg aliMsg) { + this.aliMsg = aliMsg; + } +} diff --git a/src/main/java/com/es/disped/common/spring/CustomSqlSessionTemplate.java b/src/main/java/com/es/disped/common/spring/CustomSqlSessionTemplate.java new file mode 100644 index 0000000000000000000000000000000000000000..f61bbffc1dd65d98507844b1f17d044ad953036e --- /dev/null +++ b/src/main/java/com/es/disped/common/spring/CustomSqlSessionTemplate.java @@ -0,0 +1,318 @@ +//package com.es.disped.common.spring; +// +//import static java.lang.reflect.Proxy.newProxyInstance; +//import static org.apache.ibatis.reflection.ExceptionUtil.unwrapThrowable; +//import static org.mybatis.spring.SqlSessionUtils.closeSqlSession; +//import static org.mybatis.spring.SqlSessionUtils.getSqlSession; +//import static org.mybatis.spring.SqlSessionUtils.isSqlSessionTransactional; +// +//import java.lang.reflect.InvocationHandler; +//import java.lang.reflect.Method; +//import java.sql.Connection; +//import java.util.List; +//import java.util.Map; +// +//import org.apache.ibatis.exceptions.PersistenceException; +//import org.apache.ibatis.executor.BatchResult; +//import org.apache.ibatis.session.Configuration; +//import org.apache.ibatis.session.ExecutorType; +//import org.apache.ibatis.session.ResultHandler; +//import org.apache.ibatis.session.RowBounds; +//import org.apache.ibatis.session.SqlSession; +//import org.apache.ibatis.session.SqlSessionFactory; +//import org.mybatis.spring.MyBatisExceptionTranslator; +//import org.mybatis.spring.SqlSessionTemplate; +//import org.springframework.dao.support.PersistenceExceptionTranslator; +//import org.springframework.util.Assert; +// +// +//public class CustomSqlSessionTemplate extends SqlSessionTemplate { +// +// private final SqlSessionFactory sqlSessionFactory; +// private final ExecutorType executorType; +// private final SqlSession sqlSessionProxy; +// private final PersistenceExceptionTranslator exceptionTranslator; +// +// private Map targetSqlSessionFactorys; +// private SqlSessionFactory defaultTargetSqlSessionFactory; +// +// public void setTargetSqlSessionFactorys(Map targetSqlSessionFactorys) { +// this.targetSqlSessionFactorys = targetSqlSessionFactorys; +// } +// +// public void setDefaultTargetSqlSessionFactory(SqlSessionFactory defaultTargetSqlSessionFactory) { +// this.defaultTargetSqlSessionFactory = defaultTargetSqlSessionFactory; +// } +// +// public CustomSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { +// this(sqlSessionFactory, sqlSessionFactory.getConfiguration().getDefaultExecutorType()); +// } +// +// public CustomSqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType) { +// this(sqlSessionFactory, executorType, new MyBatisExceptionTranslator(sqlSessionFactory.getConfiguration() +// .getEnvironment().getDataSource(), true)); +// } +// +// public CustomSqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType, +// PersistenceExceptionTranslator exceptionTranslator) { +// +// super(sqlSessionFactory, executorType, exceptionTranslator); +// +// this.sqlSessionFactory = sqlSessionFactory; +// this.executorType = executorType; +// this.exceptionTranslator = exceptionTranslator; +// +// this.sqlSessionProxy = (SqlSession) newProxyInstance( +// SqlSessionFactory.class.getClassLoader(), +// new Class[] { SqlSession.class }, +// new SqlSessionInterceptor()); +// +// this.defaultTargetSqlSessionFactory = sqlSessionFactory; +// } +// +// @Override +// public SqlSessionFactory getSqlSessionFactory() { +// +// SqlSessionFactory targetSqlSessionFactory = targetSqlSessionFactorys.get(DataSourceContextHolder.getDataSource()); +// if (targetSqlSessionFactory != null) { +// return targetSqlSessionFactory; +// } else if (defaultTargetSqlSessionFactory != null) { +// return defaultTargetSqlSessionFactory; +// } else { +// Assert.notNull(targetSqlSessionFactorys, "Property 'targetSqlSessionFactorys' or 'defaultTargetSqlSessionFactory' are required"); +// Assert.notNull(defaultTargetSqlSessionFactory, "Property 'defaultTargetSqlSessionFactory' or 'targetSqlSessionFactorys' are required"); +// } +// return this.sqlSessionFactory; +// } +// +// @Override +// public Configuration getConfiguration() { +// return this.getSqlSessionFactory().getConfiguration(); +// } +// +// public ExecutorType getExecutorType() { +// return this.executorType; +// } +// +// public PersistenceExceptionTranslator getPersistenceExceptionTranslator() { +// return this.exceptionTranslator; +// } +// +// /** +// * {@inheritDoc} +// */ +// public T selectOne(String statement) { +// return this.sqlSessionProxy. selectOne(statement); +// } +// +// /** +// * {@inheritDoc} +// */ +// public T selectOne(String statement, Object parameter) { +// return this.sqlSessionProxy. selectOne(statement, parameter); +// } +// +// /** +// * {@inheritDoc} +// */ +// public Map selectMap(String statement, String mapKey) { +// return this.sqlSessionProxy. selectMap(statement, mapKey); +// } +// +// /** +// * {@inheritDoc} +// */ +// public Map selectMap(String statement, Object parameter, String mapKey) { +// return this.sqlSessionProxy. selectMap(statement, parameter, mapKey); +// } +// +// /** +// * {@inheritDoc} +// */ +// public Map selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) { +// return this.sqlSessionProxy. selectMap(statement, parameter, mapKey, rowBounds); +// } +// +// /** +// * {@inheritDoc} +// */ +// public List selectList(String statement) { +// return this.sqlSessionProxy. selectList(statement); +// } +// +// /** +// * {@inheritDoc} +// */ +// public List selectList(String statement, Object parameter) { +// return this.sqlSessionProxy. selectList(statement, parameter); +// } +// +// /** +// * {@inheritDoc} +// */ +// public List selectList(String statement, Object parameter, RowBounds rowBounds) { +// return this.sqlSessionProxy. selectList(statement, parameter, rowBounds); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void select(String statement, ResultHandler handler) { +// this.sqlSessionProxy.select(statement, handler); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void select(String statement, Object parameter, ResultHandler handler) { +// this.sqlSessionProxy.select(statement, parameter, handler); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) { +// this.sqlSessionProxy.select(statement, parameter, rowBounds, handler); +// } +// +// /** +// * {@inheritDoc} +// */ +// public int insert(String statement) { +// return this.sqlSessionProxy.insert(statement); +// } +// +// /** +// * {@inheritDoc} +// */ +// public int insert(String statement, Object parameter) { +// return this.sqlSessionProxy.insert(statement, parameter); +// } +// +// /** +// * {@inheritDoc} +// */ +// public int update(String statement) { +// return this.sqlSessionProxy.update(statement); +// } +// +// /** +// * {@inheritDoc} +// */ +// public int update(String statement, Object parameter) { +// return this.sqlSessionProxy.update(statement, parameter); +// } +// +// /** +// * {@inheritDoc} +// */ +// public int delete(String statement) { +// return this.sqlSessionProxy.delete(statement); +// } +// +// /** +// * {@inheritDoc} +// */ +// public int delete(String statement, Object parameter) { +// return this.sqlSessionProxy.delete(statement, parameter); +// } +// +// /** +// * {@inheritDoc} +// */ +// public T getMapper(Class type) { +// return getConfiguration().getMapper(type, this); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void commit() { +// throw new UnsupportedOperationException("Manual commit is not allowed over a Spring managed SqlSession"); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void commit(boolean force) { +// throw new UnsupportedOperationException("Manual commit is not allowed over a Spring managed SqlSession"); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void rollback() { +// throw new UnsupportedOperationException("Manual rollback is not allowed over a Spring managed SqlSession"); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void rollback(boolean force) { +// throw new UnsupportedOperationException("Manual rollback is not allowed over a Spring managed SqlSession"); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void close() { +// throw new UnsupportedOperationException("Manual close is not allowed over a Spring managed SqlSession"); +// } +// +// /** +// * {@inheritDoc} +// */ +// public void clearCache() { +// this.sqlSessionProxy.clearCache(); +// } +// +// /** +// * {@inheritDoc} +// */ +// public Connection getConnection() { +// return this.sqlSessionProxy.getConnection(); +// } +// +// /** +// * {@inheritDoc} +// * @since 1.0.2 +// */ +// public List flushStatements() { +// return this.sqlSessionProxy.flushStatements(); +// } +// +// /** +// * Proxy needed to route MyBatis method calls to the proper SqlSession got from Spring's Transaction Manager It also +// * unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to pass a {@code PersistenceException} to +// * the {@code PersistenceExceptionTranslator}. +// */ +// private class SqlSessionInterceptor implements InvocationHandler { +// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { +// final SqlSession sqlSession = getSqlSession( +// CustomSqlSessionTemplate.this.getSqlSessionFactory(), +// CustomSqlSessionTemplate.this.executorType, +// CustomSqlSessionTemplate.this.exceptionTranslator); +// try { +// Object result = method.invoke(sqlSession, args); +// if (!isSqlSessionTransactional(sqlSession, CustomSqlSessionTemplate.this.getSqlSessionFactory())) { +// // force commit even on non-dirty sessions because some databases require +// // a commit/rollback before calling close() +// sqlSession.commit(true); +// } +// return result; +// } catch (Throwable t) { +// Throwable unwrapped = unwrapThrowable(t); +// if (CustomSqlSessionTemplate.this.exceptionTranslator != null && unwrapped instanceof PersistenceException) { +// Throwable translated = CustomSqlSessionTemplate.this.exceptionTranslator +// .translateExceptionIfPossible((PersistenceException) unwrapped); +// if (translated != null) { +// unwrapped = translated; +// } +// } +// throw unwrapped; +// } finally { +// closeSqlSession(sqlSession, CustomSqlSessionTemplate.this.getSqlSessionFactory()); +// } +// } +// } +//} \ No newline at end of file diff --git a/src/main/java/com/es/disped/common/spring/DataSourceContextHolder.java b/src/main/java/com/es/disped/common/spring/DataSourceContextHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..c25a68fee3d504847032cf94ce1ea47a9bc05442 --- /dev/null +++ b/src/main/java/com/es/disped/common/spring/DataSourceContextHolder.java @@ -0,0 +1,56 @@ +package com.es.disped.common.spring; + +import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; + + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午4:16:58
+ * 名称:DataSourceContextHolder
+ * + * 描述:动态切换数据源支持器
+ */ +public class DataSourceContextHolder extends AbstractRoutingDataSource { + + private static final ThreadLocal contextHolder = new ThreadLocal(); + + /** + * 抽象方法查找数据源标示
+ * + * @see AbstractRoutingDataSource#determineCurrentLookupKey() + */ + @Override + protected Object determineCurrentLookupKey() { + return getDataSource(); + } + + /** + * 设置数据源名称
+ * + * @param dataSource 数据源名称 + */ + public static void setDataSource(String dataSource) { + contextHolder.set(dataSource); + } + + /** + * 获取数据源
+ * + * @return String 数据源名称 + */ + public static String getDataSource() { + return ((String) contextHolder.get()); + } + + /** + * 清理数据源(恢复默认数据源)
+ */ + public static void clearDataSource() { + contextHolder.remove(); + } + +} diff --git a/src/main/java/com/es/disped/common/support/BaseSupport.java b/src/main/java/com/es/disped/common/support/BaseSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..77e359a43127b1e08e50a9fcb7e97050d9d8fcda --- /dev/null +++ b/src/main/java/com/es/disped/common/support/BaseSupport.java @@ -0,0 +1,323 @@ +package com.es.disped.common.support; + +import java.io.*; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +import com.alibaba.fastjson.JSONObject; + + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年3月29日 下午1:02:42
+ * + * 名称:BaseSupport
+ *

+ * 描述:基本的通用的工具支持类,包括一系列常用方法的封装,为子类提供便捷的调用方式
+ */ +public abstract class BaseSupport { + + /** + * 判断对象是否为null,或空
+ * + * @param obj 需要进行判断的对象 + * @return boolean 为null或空返回 true,否则返回 false + */ + public boolean isNull(Object obj) { + if (null == obj) + return true; + if (obj instanceof List) { + List list = (List) obj; + return list.isEmpty() ? true : false; + } + if (obj instanceof Map) { + Map map = (Map) obj; + return map.isEmpty() ? true : false; + } + if (obj instanceof Set) { + Set set = (Set) obj; + return set.isEmpty() ? true : false; + } + if (obj instanceof String) { + String str = (String) obj; + return str.isEmpty() ? true : false; + } + return false; + } + + /** + * Json字符串转换为Java类对象
+ * + * @param json + * 需要转换的json字符串
+ * @param classOfT + * json字符串对应的类类型
+ * @return + * 类对象 + */ + public T fromJson(String json, Class classOfT) + { + if(this.isNull(json)) + { + return null; + }else + { + return JSONObject.parseObject(json, classOfT); + } + } + + + /** + * Json字符串转换为Java类对象
+ * + * @param json + * 需要转换的json字符串
+ * @param classOfT + * json字符串对应的类类型
+ * @return + * 类对象 + */ + public String toJson(T obj) + { + return JSONObject.toJSONString(obj); + } + + /** + * 对象转换为 String,通常用于获取 Map 集合中的对象时使用
+ * + * @param obj 需要转换的对象 + * @return String 对象的值(为null则返回"") + */ + public String obj2Str(Object obj) { + return null == obj ? "" : obj.toString(); + } + + /** + * 生成 uuid 主键,长度为32位,且为大写模式
+ * + * @return String 32位主键字符串 + */ + public String getUUID() { + return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(); + } + + /** + * 对字符串进行 base64 编码
+ * + * @param str 需要进行编码的字符串 + * @return String 进行编码后的结果字符串 + */ + public String base64Encoder(String str) { + if (this.isNull(str)) + return null; + return Base64.getUrlEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)); + } + + /** + * 对字符串进行 base64 解码
+ * + * @param str 已进行 base64 编码的编码字符串 + * @return String 解码后的原字符串 + */ + public String base64Decoder(String str) { + if (this.isNull(str)) + return null; + return new String(Base64.getUrlDecoder().decode(str), StandardCharsets.UTF_8); + } + + /** + * 对字符串进行 md5 加密算法
+ * + * @param str 需要进行 md5 加密的字符串 + * @return String 加密后的结果 + */ + public String md5(String str) { + if (this.isNull(str)) + return null; + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(str.getBytes()); + return new BigInteger(1, md.digest()).toString(16).toUpperCase(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 获取系统当前时间
+ * + * @param pattern 获取系统时间的格式,如:yyyy-MM-dd HH:mm:ss + * @return String 返回格式化后的当前时间 + */ + public String currentDate(String pattern) { + if (this.isNull(pattern)) + return null; + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + return sdf.format(new Date()); + } + + /** + * 时间戳转换成日期
+ * + * @param timestamp 需要进行转换的时间戳 + * @param pattern 转换后的格式 + * @return String 格式化后的日期 + */ + public String timeStamp2Date(String timestamp, String pattern) { + if (this.isNull(timestamp) || this.isNull(pattern)) + return null; + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + return sdf.format(new Date(Long.valueOf(timestamp))); + } + + /** + * 日期转换为时间戳
+ * + * @param dateStr 需要进行转换的日期字符串 + * @param pattern 日期的格式 + * @return String 转换后的时间戳 + */ + public String date2TimeStamp(String dateStr, String pattern) { + if (this.isNull(dateStr) || this.isNull(pattern)) + return null; + try { + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + return String.valueOf(sdf.parse(dateStr).getTime()); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 从指定文件中读取文件内容
+ * + * @param filePath 文件路径(绝对路径) + * @return String 读取的文件内容 + */ + public String readFromFile(String filePath) { + if (this.isNull(filePath)) + return null; + try { + StringBuffer stringBuffer = new StringBuffer(); + File file = new File(filePath);// 指定要读取的文件 + FileReader reader = new FileReader(file);// 获取该文件的输入流 + char[] bb = new char[1024];// 用来保存每次读取到的字符 + int n;// 每次读取到的字符长度 + while ((n = reader.read(bb)) != -1) { + stringBuffer.append(new String(bb, 0, n)); + } + reader.close();// 关闭输入流,释放连接 + return stringBuffer.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 将内容写入到指定文件中(写入会覆盖文件原有内容,建议先读取,再写入,将读取的内容与需要写入的内容并在一起进行写入)
+ * + * @param content 需要写入文件中的内容 + * @param filePath 文件路径(绝对路径) + */ + public void writeToFile(String content, String filePath) { + if (!this.isNull(content) && !this.isNull(filePath)) { + try { + generateFile(filePath); + File file = new File(filePath);// 要写入的文本文件 + FileWriter writer = new FileWriter(file);// 获取该文件的输出流 + writer.write(content);// 写内容 + writer.flush();// 清空缓冲区,立即将输出流里的内容写到文件里 + writer.close();// 关闭输出流,施放资源 + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 生成指定路径文件夹,先进行判断文件夹是否存在,若不存在则创建对应目录的文件夹,若存在则不进行任何操作
+ * + * @param path 文件夹路径(绝对路径) + */ + public void generatePath(String path) { + if (!this.isNull(path)) { + File file = new File(path); + if (!file.exists() && !file.isDirectory()) { + file.mkdirs(); + } + } + } + + /** + * 生成指定路径的文件,先进行判断文件是否存在,若不存在则进行创建文件,若存在则不进行任何操作
+ * + * @param path 文件路径(绝对路径) + */ + public void generateFile(String path) { + if (!this.isNull(path)) { + File file = new File(path); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 读取配置 properties 文件中的值,读取 classpath 下 /properties/setting.properties 配置文件
+ * + * @param key 资源文件中的 key 值 + * @return String 读取到的 key 对应的 value 值 + */ + public String propertiesValue(String key) { + if (this.isNull(key)) + return null; + try { + // 获取需要读取的properties文件路径 + Properties prop = new Properties(); + InputStream inputStream = this.getClass().getResourceAsStream("/properties/setting.properties"); + prop.load(inputStream); + return prop.getProperty(key); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 读取指定路径 properties 文件中的值,会从 classpath 路径下进行查找资源文件
+ * + * @param resource 资源文件路径(对应 classpath 中的路径) + * @param key 资源文件中的 key 值 + * @return String 读取到的 key 对应的 value 值 + */ + public String propertiesValue(String resource, String key) { + if (this.isNull(resource) || this.isNull(key)) + return null; + try { + // 获取需要读取的properties文件路径 + Properties prop = new Properties(); + InputStream inputStream = this.getClass().getResourceAsStream(resource); + prop.load(inputStream); + return prop.getProperty(key); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/HttpClient.java b/src/main/java/com/es/disped/common/wechat/http/HttpClient.java new file mode 100644 index 0000000000000000000000000000000000000000..570774a49c8dbf99abc87807b8349556e6a36190 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/HttpClient.java @@ -0,0 +1,82 @@ +package com.es.disped.common.wechat.http; + +import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.es.disped.common.wechat.http.config.HttpConfig; + + +@Configuration +public class HttpClient { + +// @Autowired +// private HttpConfig httpConfig=new HttpConfig(); + + /** + * 实例化一个连接管理器,设置最大连接数、并发数 + * @return httpClientConnectionManager + */ + @Bean(name = "httpClientConnectionManager") + public PoolingHttpClientConnectionManager getHttpClientConnectionManager() { + PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(); + // 最大连接数 + httpClientConnectionManager.setMaxTotal(HttpConfig.getMaxTotal()); + // 并发数 + httpClientConnectionManager.setDefaultMaxPerRoute(HttpConfig.getDefaultMaxPerRoute()); + return httpClientConnectionManager; + } + + /** + * 实例化连接池,设置连接池管理器 + * @param poolingHttpClientConnectionManager + * @return httpClientBuilder + */ + @Bean(name = "httpClientBuilder") + public HttpClientBuilder getHttpClientBuilder(@Qualifier("httpClientConnectionManager") + PoolingHttpClientConnectionManager poolingHttpClientConnectionManager) { + // HttpClientBuilder构造方法被保护了 + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + httpClientBuilder.setConnectionManager(poolingHttpClientConnectionManager); + return httpClientBuilder; + } + + /** + * 注入连接池,用于获取httpClient + * @param httpClientBuilder + * @return + */ + @Bean + public CloseableHttpClient getCloseableHttpClient(@Qualifier("httpClientBuilder")HttpClientBuilder httpClientBuilder) { + return httpClientBuilder.build(); + } + + /** + * Builder是RequestConfig的一个内部类 通过RequestConfig的custom方法来获取到一个Builder对象 + * 设置builder的连接信息 这里还可以设置proxy,cookieSpec等属性。有需要的话可以在此设置 + * + * @return + */ + @Bean(name = "builder") + public RequestConfig.Builder getBuilder() { + RequestConfig.Builder builder = RequestConfig.custom(); + return builder.setConnectTimeout(HttpConfig.getConnectTimeout()) + .setConnectionRequestTimeout(HttpConfig.getConnectionRequestTimeout()) + .setSocketTimeout(HttpConfig.getSocketTimeout()) + .setStaleConnectionCheckEnabled(HttpConfig.isStaleConnectionCheckEnabled()); + } + + /** + * 使用builder构建 RequestConfig + * @param builder + * @return + */ + @Bean + public RequestConfig getRequestConfig(@Qualifier("builder") RequestConfig.Builder builder) { + return builder.build(); + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/config/HttpConfig.java b/src/main/java/com/es/disped/common/wechat/http/config/HttpConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..09f40486d9da808c6f1785b1143fcff6dd5d72a7 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/config/HttpConfig.java @@ -0,0 +1,105 @@ +package com.es.disped.common.wechat.http.config; + +public class HttpConfig{ + + //private final String resource="/properties/http.properties"; + /** + * 最大连接数 + */ + private static int maxTotal=100; + /** + * 并发数 + */ + private static int defaultMaxPerRoute=20; + /** + * 创建连接的最长时间 + */ + private static int connectTimeout=1000; + /** + * 从连接池获取连接的最长时间 + */ + private static int connectionRequestTimeout=500; + /** + * 数据传输最长时间 + */ + private static int socketTimeout=10000; + /** + * 提交请求之前测试连接是否可用 + */ + private static boolean staleConnectionCheckEnabled=true; + +// public HttpConfig() { +// this.maxTotal=Integer.valueOf( +// this.propertiesValue(resource, "client.http.maxTotal")); +// this.defaultMaxPerRoute=Integer.valueOf( +// this.propertiesValue(resource, "client.http.defaultMaxPerRoute")); +// this.connectTimeout=Integer.valueOf( +// this.propertiesValue(resource, "client.http.connectTimeout")); +// this.connectionRequestTimeout=Integer.valueOf( +// this.propertiesValue(resource, "client.http.connectionRequestTimeout")); +// this.socketTimeout=Integer.valueOf( +// this.propertiesValue(resource, "client.http.socketTimeout")); +// this.staleConnectionCheckEnabled=Boolean.valueOf( +// this.propertiesValue(resource, "client.http.staleConnectionCheckEnabled")); +// } + + public static int getMaxTotal() { + return maxTotal; + } + + public static void setMaxTotal(int maxTotal) { + HttpConfig.maxTotal = maxTotal; + } + + public static int getDefaultMaxPerRoute() { + return defaultMaxPerRoute; + } + + public static void setDefaultMaxPerRoute(int defaultMaxPerRoute) { + HttpConfig.defaultMaxPerRoute = defaultMaxPerRoute; + } + + public static int getConnectTimeout() { + return connectTimeout; + } + + public static void setConnectTimeout(int connectTimeout) { + HttpConfig.connectTimeout = connectTimeout; + } + + public static int getConnectionRequestTimeout() { + return connectionRequestTimeout; + } + + public static void setConnectionRequestTimeout(int connectionRequestTimeout) { + HttpConfig.connectionRequestTimeout = connectionRequestTimeout; + } + + public static int getSocketTimeout() { + return socketTimeout; + } + + public static void setSocketTimeout(int socketTimeout) { + HttpConfig.socketTimeout = socketTimeout; + } + + public static boolean isStaleConnectionCheckEnabled() { + return staleConnectionCheckEnabled; + } + + public static void setStaleConnectionCheckEnabled(boolean staleConnectionCheckEnabled) { + HttpConfig.staleConnectionCheckEnabled = staleConnectionCheckEnabled; + } + + @Override + public String toString() { + return "HttpConfig{" + + "maxTotal=" + maxTotal + + ", defaultMaxPerRoute=" + defaultMaxPerRoute + + ", connectTimeout=" + connectTimeout + + ", connectionRequestTimeout=" + connectionRequestTimeout + + ", socketTimeout=" + socketTimeout + + ", staleConnectionCheckEnabled=" + staleConnectionCheckEnabled + + '}'; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/config/WeChatConfig.java b/src/main/java/com/es/disped/common/wechat/http/config/WeChatConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..a585fe71c5c1475447c5106f716f031f209d66ea --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/config/WeChatConfig.java @@ -0,0 +1,50 @@ +package com.es.disped.common.wechat.http.config; + +public class WeChatConfig{ + + /** + * 公众号id + */ + private static String appId="wx97af5889a44dfe99"; + /** + * appsecret + */ + private static String appsecret="6e169c3c95924e1d2a96cec6ca7c0a45"; + /** + * token + */ + private static String token="eshedu"; + + public static String getAppId() { + return appId; + } + + public static void setAppId(String appId) { + WeChatConfig.appId = appId; + } + + public static String getAppsecret() { + return appsecret; + } + + public static void setAppsecret(String appsecret) { + WeChatConfig.appsecret = appsecret; + } + + public static String getToken() { + return token; + } + + public static void setToken(String token) { + WeChatConfig.token = token; + } + + @Override + public String toString() { + return "WeChatConfig{" + + "appId='" + appId + '\'' + + ", appsecret='" + appsecret + '\'' + + ", token='" + token + '\'' + + '}'; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/request/AccessRequest.java b/src/main/java/com/es/disped/common/wechat/http/request/AccessRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..ca939fd346c2587379db37fad85df60e4526a7c3 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/request/AccessRequest.java @@ -0,0 +1,69 @@ +package com.es.disped.common.wechat.http.request; + +import java.io.Serializable; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月15日 下午4:07:37
+ * 获取access_token请求参数 + */ +public class AccessRequest implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 1401666627114595048L; + /** + * 获取access_token填写client_credential + */ + private String grant_type = "client_credential"; + /** + * 第三方用户唯一凭证 + */ + private String appid; + /** + * 第三方用户唯一凭证密钥,即appsecret + */ + private String secret; + + public AccessRequest(String appid, String secret) { + this.appid = appid; + this.secret = secret; + } + + public String getGrant_type() { + return grant_type; + } + + public void setGrant_type(String grant_type) { + this.grant_type = grant_type; + } + + public String getAppid() { + return appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } + + @Override + public String toString() { + return "AccessRequest{" + + "grant_type='" + grant_type + '\'' + + ", appid='" + appid + '\'' + + ", secret='" + secret + '\'' + + '}'; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/request/WeChatRequest.java b/src/main/java/com/es/disped/common/wechat/http/request/WeChatRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..3a7f6d1e231afacc58f2340ad2a12422f2f30e97 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/request/WeChatRequest.java @@ -0,0 +1,77 @@ +package com.es.disped.common.wechat.http.request; + +import java.io.Serializable; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月15日 下午4:09:48
+ * 微信接入请求数据 + */ +public class WeChatRequest implements Serializable{ + /** + * + */ + private static final long serialVersionUID = -3730919637726564153L; + /** + * 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。 + */ + private String signature; + /** + * 时间戳 + */ + private String timestamp; + /** + * 随机次数 + */ + private String nonce; + /** + * 随机字符串 + */ + private String echostr; + + public String getSignature() { + return signature; + } + + public void setSignature(String signature) { + this.signature = signature; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getNonce() { + return nonce; + } + + public void setNonce(String nonce) { + this.nonce = nonce; + } + + public String getEchostr() { + return echostr; + } + + public void setEchostr(String echostr) { + this.echostr = echostr; + } + + @Override + public String toString() { + return "WeChatRequest{" + + "signature='" + signature + '\'' + + ", timestamp=" + timestamp + + ", nonce='" + nonce + '\'' + + ", echostr='" + echostr + '\'' + + '}'; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/response/AccessResponse.java b/src/main/java/com/es/disped/common/wechat/http/response/AccessResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..3940dd0b7f8d2b90c7c2e59a75bcba03d1df4781 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/response/AccessResponse.java @@ -0,0 +1,78 @@ +package com.es.disped.common.wechat.http.response; + +import java.io.Serializable; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月15日 下午4:11:04
+ * 获取access_tokn返回数据 + */ +public class AccessResponse implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 8806962081799199526L; + /** + * 获取到的凭证 + */ + private String access_token; + /** + * access_token接口调用凭证超时时间,单位(秒) + */ + private String expires_in; + /** + * 错误码 + */ + private String errorcode; + /** + * 错误信息 + */ + private String errmsg; + + public String getAccess_token() { + return access_token; + } + + public void setAccess_token(String access_token) { + this.access_token = access_token; + } + + public String getExpires_in() { + return expires_in; + } + + public void setExpires_in(String expires_in) { + this.expires_in = expires_in; + } + + public String getErrorcode() { + return errorcode; + } + + public void setErrorcode(String errorcode) { + this.errorcode = errorcode; + } + + public String getErrmsg() { + return errmsg; + } + + public void setErrmsg(String errmsg) { + this.errmsg = errmsg; + } + + @Override + public String toString() { + return "AccessResponse{" + + "access_token='" + access_token + '\'' + + ", expires_in='" + expires_in + '\'' + + ", errorcode='" + errorcode + '\'' + + ", errmsg='" + errmsg + '\'' + + '}'; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/response/TemplateMsgResponse.java b/src/main/java/com/es/disped/common/wechat/http/response/TemplateMsgResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..6b4dd1af0a7a1d304cfc8977937bd4e94a8b58c7 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/response/TemplateMsgResponse.java @@ -0,0 +1,30 @@ +package com.es.disped.common.wechat.http.response; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月15日 下午4:13:41
+ * 模板推送返回数据 + */ +public class TemplateMsgResponse extends WeChatBaseResponse{ + + /** + * + */ + private static final long serialVersionUID = -2725247356146955923L; + /** + * 消息id + */ + private String msgid; + + public String getMsgid() { + return msgid; + } + + public void setMsgid(String msgid) { + this.msgid = msgid; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/http/response/WeChatBaseResponse.java b/src/main/java/com/es/disped/common/wechat/http/response/WeChatBaseResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..fa93c2bfc17f99978ee53e6daf7e04f54bfb12b7 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/http/response/WeChatBaseResponse.java @@ -0,0 +1,44 @@ +package com.es.disped.common.wechat.http.response; + +import java.io.Serializable; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月15日 下午4:11:55
+ * 通用返回信息 + */ +public class WeChatBaseResponse implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 5113562347332678571L; + /** + * 错误码 + */ + private int errcode; + /** + * 错误信息 + */ + private String errmsg; + + public int getErrcode() { + return errcode; + } + + public void setErrcode(int errcode) { + this.errcode = errcode; + } + + public String getErrmsg() { + return errmsg; + } + + public void setErrmsg(String errmsg) { + this.errmsg = errmsg; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/model/TemplateMsg.java b/src/main/java/com/es/disped/common/wechat/model/TemplateMsg.java new file mode 100644 index 0000000000000000000000000000000000000000..0731c7feb5361c9fad91ccebf4f7299e0eb20409 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/model/TemplateMsg.java @@ -0,0 +1,75 @@ +package com.es.disped.common.wechat.model; + +import java.io.Serializable; +import java.util.TreeMap; + +public class TemplateMsg implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 1791348941122590620L; + /** + * 接收者openid + */ + private String touser; + /** + * 模板ID + */ + private String template_id; + /** + * 模板跳转链接 + */ + private String url; + // "miniprogram":{ 未加入 + // "appid":"xiaochengxuappid12345", + // "pagepath":"index?foo=bar" + // }, + /** + * data数据 + */ + private TreeMap> data; + + /** + * 构造模板参数 + * + * @param value + * @param color 可不填 + * @return + */ + public static TreeMap item(String value, String color) { + TreeMap params = new TreeMap(); + params.put("value", value); + params.put("color", color); + return params; + } + + public String getTouser() { + return touser; + } + public void setTouser(String touser) { + this.touser = touser; + } + public String getTemplate_id() { + return template_id; + } + public void setTemplate_id(String template_id) { + this.template_id = template_id; + } + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + public TreeMap> getData() { + return data; + } + public void setData(TreeMap> data) { + this.data = data; + } + @Override + public String toString() { + return "WechatTemplateMsg [touser=" + touser + ", template_id=" + template_id + ", url=" + url + ", data=" + + data + "]"; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/model/TextMsg.java b/src/main/java/com/es/disped/common/wechat/model/TextMsg.java new file mode 100644 index 0000000000000000000000000000000000000000..2e1438b853d8b5e3cc179b9359e30f9e6a302f19 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/model/TextMsg.java @@ -0,0 +1,102 @@ +package com.es.disped.common.wechat.model; + +import java.io.Serializable; + +/** + * @author Anson
+ * Copyright by EasyShare 2019
+ * + * All right reserved
+ * + * Created on 2019年6月19日 下午12:18:50
+ * 本文消息对象 + */ +public class TextMsg implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -8834128628762432276L; + /** + * 开发者微信号 + */ + private String ToUserName; + /** + * 发送方帐号(一个OpenID) + */ + private String FromUserName; + /** + * 消息创建时间 + */ + private String CreateTime; + /** + * 消息类型,文本为text + */ + private String MsgType; + /** + * 文本消息内容 + */ + private String Content; + /** + * 消息id,64位 + */ + private String MsgId; + + public TextMsg() { + + } + + public String getToUserName() { + return ToUserName; + } + + public void setToUserName(String toUserName) { + ToUserName = toUserName; + } + + public String getFromUserName() { + return FromUserName; + } + + public void setFromUserName(String fromUserName) { + FromUserName = fromUserName; + } + + public String getCreateTime() { + return CreateTime; + } + + public void setCreateTime(String createTime) { + CreateTime = createTime; + } + + public String getMsgType() { + return MsgType; + } + + public void setMsgType(String msgType) { + MsgType = msgType; + } + + public String getContent() { + return Content; + } + + public void setContent(String content) { + Content = content; + } + + public String getMsgId() { + return MsgId; + } + + public void setMsgId(String msgId) { + MsgId = msgId; + } + + @Override + public String toString() { + return "TextMessage [ToUserName=" + ToUserName + ", FromUserName=" + FromUserName + ", CreateTime=" + CreateTime + + ", MsgType=" + MsgType + ", Content=" + Content + ", MsgId=" + MsgId + "]"; + } +} diff --git a/src/main/java/com/es/disped/common/wechat/signature/WeChatSignature.java b/src/main/java/com/es/disped/common/wechat/signature/WeChatSignature.java new file mode 100644 index 0000000000000000000000000000000000000000..0b0edc6234b589aa7d2f649cbb9f713a5fc52550 --- /dev/null +++ b/src/main/java/com/es/disped/common/wechat/signature/WeChatSignature.java @@ -0,0 +1,63 @@ +package com.es.disped.common.wechat.signature; + +import java.security.MessageDigest; +import java.util.Arrays; + +import com.es.disped.common.wechat.http.config.WeChatConfig; +import com.es.disped.common.wechat.http.request.WeChatRequest; + +//@Service("weChatSignature") +public class WeChatSignature extends WeChatConfig{ + +// @Autowired + //private WeChatConfig config=new WeChatConfig(); + + /** + * 加密校验 signature + * @param request 微信请求参数 + * @return + */ + public static boolean checkSignature(WeChatRequest request) { + String[] arr = new String[]{WeChatConfig.getToken(), request.getTimestamp(), request.getNonce()}; + //排序 + Arrays.sort(arr); + //生成字符串 + StringBuffer content = new StringBuffer(); + for (int i = 0; i < arr.length; i++) { + content.append(arr[i]); + } + //sha1加密 + String temp = getSha1(content.toString()); + return temp.equals(request.getSignature()); + } + + /** + * Sha1加密方法 + * + * @param str + * @return + */ + public static String getSha1(String str) { + if (str == null || str.length() == 0) { + return null; + } + char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f'}; + try { + MessageDigest mdTemp = MessageDigest.getInstance("SHA1"); + mdTemp.update(str.getBytes("UTF-8")); + byte[] md = mdTemp.digest(); + int j = md.length; + char buf[] = new char[j * 2]; + int k = 0; + for (int i = 0; i < j; i++) { + byte byte0 = md[i]; + buf[k++] = hexDigits[byte0 >>> 4 & 0xf]; + buf[k++] = hexDigits[byte0 & 0xf]; + } + return new String(buf); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/resources/properties/http.properties b/src/main/resources/properties/http.properties new file mode 100644 index 0000000000000000000000000000000000000000..059e8d2733f4118a508536031b016813d66747a7 --- /dev/null +++ b/src/main/resources/properties/http.properties @@ -0,0 +1,6 @@ +client.http.maxTotal=100 +client.http.defaultMaxPerRoute=20 +client.http.connectTimeout=1000 +client.http.connectionRequestTimeout=500 +client.http.socketTimeout=10000 +client.http.staleConnectionCheckEnabled=true \ No newline at end of file diff --git a/src/main/resources/properties/wechat.properties b/src/main/resources/properties/wechat.properties new file mode 100644 index 0000000000000000000000000000000000000000..779dfe53922f3d0adc3fa3402305df2b9c2535db --- /dev/null +++ b/src/main/resources/properties/wechat.properties @@ -0,0 +1,3 @@ +wx.account.appId=wx97af5889a44dfe99 +wx.account.appsecret=6e169c3c95924e1d2a96cec6ca7c0a45 +wx.account.token=eshedu \ No newline at end of file diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..6b880bd961d3cc1bb82147d57434d8a424f872db --- /dev/null +++ b/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: Administrator +Build-Jdk: 1.8.0_66 +Created-By: Maven Integration for Eclipse + diff --git a/target/classes/META-INF/maven/com.es/disped-common/pom.properties b/target/classes/META-INF/maven/com.es/disped-common/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..074a253b0bad6de9a045ee13d3b63d1013561297 --- /dev/null +++ b/target/classes/META-INF/maven/com.es/disped-common/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Tue Jul 23 13:42:27 CST 2019 +version=1.0.0-SNAPSHOT +groupId=com.es +m2e.projectName=disped-common +m2e.projectLocation=E\:\\Java\\JavaWeb\\JavaDynamicWeb\\disped\\disped-common +artifactId=disped-common diff --git a/target/classes/META-INF/maven/com.es/disped-common/pom.xml b/target/classes/META-INF/maven/com.es/disped-common/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b60bb04492e29189cf5ffb414daeaf10fa116406 --- /dev/null +++ b/target/classes/META-INF/maven/com.es/disped-common/pom.xml @@ -0,0 +1,143 @@ + + + 4.0.0 + + com.es + disped + 1.0.0-SNAPSHOT + + disped-common + disped-common + http://maven.apache.org + + + + commons-io + commons-io + 2.6 + + + commons-fileupload + commons-fileupload + 1.3.3 + + + commons-io + commons-io + + + + + org.apache.commons + commons-lang3 + 3.7 + + + commons-logging + commons-logging + 1.2 + + + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-aspects + ${spring.version} + + + aspectjweaver + org.aspectj + + + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-jms + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + + org.aspectj + aspectjweaver + ${aspectj.version} + + + org.aspectj + aspectjrt + ${aspectj.version} + + + + com.alibaba + fastjson + 1.2.47 + + + + org.mybatis + mybatis + 3.4.5 + + + org.mybatis + mybatis-spring + 1.3.1 + + + + com.github.pagehelper + pagehelper + 5.1.2 + + + + com.aliyun + aliyun-java-sdk-core + 4.1.1 + + + + org.apache.httpcomponents + httpclient + 4.3.6 + + + + dom4j + dom4j + 1.6.1 + + + com.thoughtworks.xstream + xstream + 1.3.1 + + + diff --git a/target/classes/properties/http.properties b/target/classes/properties/http.properties new file mode 100644 index 0000000000000000000000000000000000000000..059e8d2733f4118a508536031b016813d66747a7 --- /dev/null +++ b/target/classes/properties/http.properties @@ -0,0 +1,6 @@ +client.http.maxTotal=100 +client.http.defaultMaxPerRoute=20 +client.http.connectTimeout=1000 +client.http.connectionRequestTimeout=500 +client.http.socketTimeout=10000 +client.http.staleConnectionCheckEnabled=true \ No newline at end of file diff --git a/target/classes/properties/wechat.properties b/target/classes/properties/wechat.properties new file mode 100644 index 0000000000000000000000000000000000000000..779dfe53922f3d0adc3fa3402305df2b9c2535db --- /dev/null +++ b/target/classes/properties/wechat.properties @@ -0,0 +1,3 @@ +wx.account.appId=wx97af5889a44dfe99 +wx.account.appsecret=6e169c3c95924e1d2a96cec6ca7c0a45 +wx.account.token=eshedu \ No newline at end of file diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..14ade72af14d5c05cd3d81969e18b054a083b0cf --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Mar 29 13:05:26 CST 2019 +version=1.0.0-SNAPSHOT +groupId=com.es +artifactId=disped-common diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..49d9d16513d043e6502a7cc83f8f828153dcf323 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,25 @@ +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\signature\WeChatSignature.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\aspect\DataSourceAspect.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\config\HttpConfig.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\service\impl\BaseServiceImpl.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\config\WeChatConfig.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\service\BaseService.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\annotation\DynamicDataSource.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\response\WeChatBaseResponse.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\request\AccessRequest.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\constant\RecordStatus.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\model\TemplateMsg.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\constant\WeChat.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\model\PageModel.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\sms\AliMsg.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\model\MsgModel.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\HttpClient.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\support\BaseSupport.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\sms\SmsClient.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\model\TextMsg.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\response\TemplateMsgResponse.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\constant\AliSms.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\constant\DataSourceName.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\response\AccessResponse.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\spring\DataSourceContextHolder.java +E:\Java\JavaWeb\JavaDynamicWeb\disped\disped-common\src\main\java\com\es\disped\common\wechat\http\request\WeChatRequest.java diff --git a/target/surefire-reports/TEST-com.es.disped.common.AppTest.xml b/target/surefire-reports/TEST-com.es.disped.common.AppTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..156fc399ea54a273ae7deaccc5dff22990d720d5 --- /dev/null +++ b/target/surefire-reports/TEST-com.es.disped.common.AppTest.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.es.disped.common.AppTest.txt b/target/surefire-reports/com.es.disped.common.AppTest.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed4d8449aafc534379f376c64f5202ba375a9f33 --- /dev/null +++ b/target/surefire-reports/com.es.disped.common.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.es.disped.common.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.09 sec