Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

zdm 6 years ago
parent
commit
5c12ade4ca
55 changed files with 3307 additions and 181 deletions
  1. 70 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/notice/NoticeDO.java
  2. 28 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/notice/UserNoticeDO.java
  3. 36 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxGraphicSceneDO.java
  4. 37 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxWechatSaasDO.java
  5. 31 0
      common/common-exception/src/main/java/com/yihu/jw/exception/code/BaseErrorCode.java
  6. 45 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java
  7. 13 6
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/module/InterfaceErrorCodeVO.java
  8. 24 12
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/module/InterfaceParamVO.java
  9. 2 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/notice/NoticeVO.java
  10. 2 10
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/notice/UserNoticeVO.java
  11. 39 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxComboVO.java
  12. 40 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxGraphicSceneVO.java
  13. 79 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxReplySceneVO.java
  14. 263 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxTemplateConfigVO.java
  15. 51 60
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxTemplateVO.java
  16. 4 1
      common/common-util/pom.xml
  17. 15 0
      common/common-util/src/main/java/com/yihu/jw/util/http/AllowAllHostnameVerifier.java
  18. 100 0
      common/common-util/src/main/java/com/yihu/jw/util/http/CustomTrustClientClientImpl.java
  19. 336 0
      common/common-util/src/main/java/com/yihu/jw/util/http/DefaultClientImpl.java
  20. 54 0
      common/common-util/src/main/java/com/yihu/jw/util/http/HTTPClient.java
  21. 23 0
      common/common-util/src/main/java/com/yihu/jw/util/http/HTTPResponse.java
  22. 155 0
      common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientKit.java
  23. 3 1
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/notice/NoticeDao.java
  24. 4 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/user/UserDao.java
  25. 11 14
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxGraphicMessageDao.java
  26. 11 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxGraphicSceneDao.java
  27. 20 20
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxTemplateDao.java
  28. 14 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxWechatSaasDao.java
  29. 165 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/FileUploadController.java
  30. 123 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/notice/NoticeEndPoint.java
  31. 54 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/notice/UserNoticeEndpoint.java
  32. 196 5
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WechatController.java
  33. 5 0
      svr/svr-base/src/main/java/com/yihu/jw/base/listener/ApplicationReadyListener.java
  34. 168 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/notice/NoticeService.java
  35. 62 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/notice/UserNoticeService.java
  36. 355 5
      svr/svr-base/src/main/java/com/yihu/jw/base/service/wx/WechatService.java
  37. 1 1
      svr/svr-base/src/main/java/com/yihu/jw/base/util/ErrorCodeUtil.java
  38. 79 0
      svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/DelayService.java
  39. 53 0
      svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/Notice.java
  40. 12 0
      svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/OnDelayedListener.java
  41. 196 0
      svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/RedisLock.java
  42. 59 0
      svr/svr-base/src/main/java/com/yihu/jw/base/util/threadPool/ThreadPool.java
  43. 32 0
      svr/svr-base/src/main/java/com/yihu/jw/base/util/threadPool/ThreadPoolUtil.java
  44. 2 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/constant/LoginInfo.java
  45. 35 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/LoginController.java
  46. 2 1
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/facilities/FacilitiesController.java
  47. 3 1
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/FacilityUsedRecordController.java
  48. 6 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/facility/FacilityServerDao.java
  49. 32 20
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/interceptor/ActivatedInterceptor.java
  50. 2 2
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/job/ActivatedUserUpdateTask.java
  51. 19 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/facility/FacilityServerService.java
  52. 61 21
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/facility/FacilityService.java
  53. 65 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/LoginService.java
  54. 4 1
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/UserService.java
  55. 6 0
      wlyy-parent-pom/pom.xml

+ 70 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/notice/NoticeDO.java

@ -1,5 +1,6 @@
package com.yihu.jw.entity.base.notice;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
@ -15,6 +16,62 @@ import java.util.Date;
@Table(name = "base_notice")
public class NoticeDO extends UuidIdentityEntityWithOperator{
    public enum Status{
        wait("待发布",1),
        released("已发布",2);
        private String name;
        private Integer value;
        Status(String name, Integer value) {
            this.name = name;
            this.value = value;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Integer getValue() {
            return value;
        }
        public void setValue(Integer value) {
            this.value = value;
        }
    }
    public enum SendType{
        manual_release("手动发布",1),
        automatic_release("自动发布",2);
        private String name;
        private Integer value;
        SendType(String name, Integer value) {
            this.name = name;
            this.value = value;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Integer getValue() {
            return value;
        }
        public void setValue(Integer value) {
            this.value = value;
        }
    }
    private String title;//公告标题
    private Integer status;//状态(1待发布,2已发布)
    private Date sendTime;//发布时间
@ -50,6 +107,7 @@ public class NoticeDO extends UuidIdentityEntityWithOperator{
    }
    @Column(name = "send_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getSendTime() {
        return sendTime;
    }
@ -75,4 +133,16 @@ public class NoticeDO extends UuidIdentityEntityWithOperator{
    public void setDel(Integer del) {
        this.del = del;
    }
    @Override
    public String toString() {
        return "NoticeDO{" +
                "title='" + title + '\'' +
                ", status=" + status +
                ", sendTime=" + sendTime +
                ", content='" + content + '\'' +
                ", sendType=" + sendType +
                ", del=" + del +
                '}';
    }
}

+ 28 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/notice/UserNoticeDO.java

@ -14,6 +14,34 @@ import javax.persistence.Table;
@Table(name = "base_user_notice")
public class UserNoticeDO extends UuidIdentityEntity{
    public enum Read{
        unRead("未读",0),
        read("已读",1);
        private String name;
        private Integer value;
        Read(String name, Integer value) {
            this.name = name;
            this.value = value;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Integer getValue() {
            return value;
        }
        public void setValue(Integer value) {
            this.value = value;
        }
    }
    private String noticeId;//公告id
    private String userId;//用户id
    private Integer isRead;//是否已读(1已读,0未读)

+ 36 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxGraphicSceneDO.java

@ -0,0 +1,36 @@
package com.yihu.jw.entity.base.wx;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Administrator on 2018/10/9.
 */@Entity
@Table(name = "wx_graphic_scene")
public class WxGraphicSceneDO extends UuidIdentityEntity implements java.io.Serializable{
    private String wechatId;//所属微信
    private String scene;//场景值
    @Column(name = "wechat_id")
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    @Column(name="scene")
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
}

+ 37 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxWechatSaasDO.java

@ -0,0 +1,37 @@
package com.yihu.jw.entity.base.wx;
import com.yihu.jw.entity.UuidIdentityEntity;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Administrator on 2018/10/8.
 */
@Entity
@Table(name = "wx_wechat_saas")
public class WxWechatSaasDO extends UuidIdentityEntity implements java.io.Serializable {
    private String wechatId;
    private String saasId;
    @Column(name="wechat_id")
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    @Column(name="saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
}

+ 31 - 0
common/common-exception/src/main/java/com/yihu/jw/exception/code/BaseErrorCode.java

@ -63,6 +63,18 @@ public class BaseErrorCode {
     */
    public static class Notice{
        public static final String FINDDICTBYCODE = "-105000";
        /**
         * 请输入50个字以内的公告标题
         */
        public static final String LIMIT_TITLE = "-105001";
        /**
         * 已经发布,请不要重复发布
         */
        public static final String HAD_RELEASE = "-105002";
        /**
         * 自动发布,不允许手动发布
         */
        public static final String AUTO_RELEASE = "-105003";
    }
    /**
@ -72,6 +84,25 @@ public class BaseErrorCode {
        public static final String FINDDICTBYCODE = "-106000";
    }
    /**
     * 通知公告模块
     */
    public static class FileUpload{
        /**
         * 文件格式错误
         */
        public static final String FAIL_UPLOAD_FORMAT = "-107000";
        /**
         * 文件大小不超过{}M
         */
        public static final String FAIL_FILE_SIZE = "-107001";
        /**
         * 上传内容为空
         */
        public static final String FILE_NULL = "-107002";
    }
    /**
     * 微信模块
     */

+ 45 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -162,6 +162,32 @@ public class BaseRequestMapping {
        public static final String PREFIX  = "/error";
    }
    /**
     * 通知公告
     */
    public static class Notice extends Basic {
        public static final String PREFIX  = "/notice";
        public static final String RELEASE  = "/release";
    }
    /**
     * 用户通知公告
     */
    public static class UserNotice extends Basic {
        public static final String PREFIX  = "/userNotice";
    }
    /**
     * 文件上传
     */
    public static class FileUpload extends Basic {
        public static final String PREFIX  = "/fileUpload";
        public static final String UPLOAD_STREAM_IMG  = "/upload_stream_img";
        public static final String UPLOAD_STREAM  = "/upload_stream";
        public static final String UPLOAD_STRING  = "/upload_string";
        public static final String UPLOAD_STREAM_ATTACHMENT  = "/upload_stream_attachment";
    }
    /**
     * 角色权限
     */
@ -176,7 +202,26 @@ public class BaseRequestMapping {
        public static final String PREFIX  = "/wechat";
        public static final String wechat_base ="/wechatBase";
        public static final String api_success ="success";
        public static final String getWechatInfos ="/getWechatInfos";
        public static final String saveWxAndSaas ="/saveWxAndSaas";
        public static final String updateWxAndSaas ="/updateWxAndSaas";
        public static final String findWechatCombo ="/findWechatCombo";
        public static final String findWechatImgGroup ="/findWechatImgGroup";
        public static final String createImgGroup ="/createImgGroup";
        public static final String updateImgGroup ="/updateImgGroup";
        public static final String deleteImgGroup ="/deleteImgGroup";
        public static final String saveImg ="/saveImg";
        public static final String findImg ="/findImg";
        public static final String saveImgGroup ="/saveImgGroup";
        public static final String saveWxReplyScene ="/saveWxReplyScene";
        public static final String findWxReplyScene ="/findWxReplyScene";
        public static final String saveWxTemp ="/saveWxTemp";
        public static final String saveWxTempConfig ="/saveWxTempConfig";
        public static final String findWxTempConfigList ="/findWxTempConfigList";
        public static final String findWxTemplateConfig ="/findWxTemplateConfig";
    }
    /**

+ 13 - 6
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/module/InterfaceErrorCodeVO.java

@ -2,6 +2,7 @@ package com.yihu.jw.restmodel.base.module;
import com.yihu.jw.restmodel.UuidIdentityVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * @author yeshijie on 2018/9/28.
@ -9,12 +10,18 @@ import io.swagger.annotations.ApiModel;
@ApiModel(value = "InterfaceErrorCodeVO", description = "接口错误说明")
public class InterfaceErrorCodeVO extends UuidIdentityVO {
    private String interfaceId;//接口id
    private String name;//错误码名称
    private String description;//错误码描述
    private String solution;//解决方案
    private Integer sort;//排序
    private Integer del;//删除标志
    @ApiModelProperty(value = "接口id", example = "接口id")
    private String interfaceId;
    @ApiModelProperty(value = "错误码名称", example = "错误码名称")
    private String name;
    @ApiModelProperty(value = "错误码描述", example = "错误码描述")
    private String description;
    @ApiModelProperty(value = "解决方案", example = "解决方案")
    private String solution;
    @ApiModelProperty(value = "排序", example = "1")
    private Integer sort;
    @ApiModelProperty(value = "删除标志", example = "1")
    private Integer del;
    public String getInterfaceId() {
        return interfaceId;

+ 24 - 12
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/module/InterfaceParamVO.java

@ -2,24 +2,36 @@ package com.yihu.jw.restmodel.base.module;
import com.yihu.jw.restmodel.UuidIdentityVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * @author yeshijie on 2018/9/28.
 */
@ApiModel(value = "InterfaceParamVO", description = "接口入参出参")
public class InterfaceParamVO extends UuidIdentityVO {
    
    private String interfaceId;//接口id
    private String name;//参数名
    private Integer paramType;//参数类型
    private Integer dataType;//数据类型
    private Integer isRequire;//是否必填(1是,0否)
    private Integer maxLength;//最大长度
    private String description;//描述
    private String example;//示例
    private Integer type;//类型(1入参,2出参)
    private Integer sort;//排序
    private Integer del;//删除标志
    @ApiModelProperty(value = "接口id", example = "接口id")
    private String interfaceId;
    @ApiModelProperty(value = "参数名", example = "user")
    private String name;
    @ApiModelProperty(value = "参数类型", example = "HEADER")
    private Integer paramType;
    @ApiModelProperty(value = "数据类型", example = "VERCHAR")
    private Integer dataType;
    @ApiModelProperty(value = "是否必填(1是,0否)", example = "1")
    private Integer isRequire;
    @ApiModelProperty(value = "最大长度", example = "1")
    private Integer maxLength;
    @ApiModelProperty(value = "描述", example = "")
    private String description;
    @ApiModelProperty(value = "示例", example = "")
    private String example;
    @ApiModelProperty(value = "类型(1入参,2出参)", example = "1")
    private Integer type;
    @ApiModelProperty(value = "排序", example = "1")
    private Integer sort;
    @ApiModelProperty(value = "删除标志", example = "1")
    private Integer del;
    public String getInterfaceId() {
        return interfaceId;

+ 2 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/notice/NoticeVO.java

@ -1,5 +1,6 @@
package com.yihu.jw.restmodel.base.notice;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.restmodel.UuidIdentityVOWithOperator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -18,6 +19,7 @@ public class NoticeVO extends UuidIdentityVOWithOperator {
    @ApiModelProperty(value = "状态(1待发布,2已发布)", example = "1")
    private Integer status;
    @ApiModelProperty(value = "发布时间", example = "2019-01-01 12:20:59")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date sendTime;
    @ApiModelProperty(value = "公告内容", example = "内容")
    private String content;

+ 2 - 10
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/notice/UserNoticeVO.java

@ -1,5 +1,6 @@
package com.yihu.jw.restmodel.base.notice;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.UuidIdentityEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -24,9 +25,8 @@ public class UserNoticeVO extends UuidIdentityEntity{
    @ApiModelProperty(value = "公告标题", example = "标题")
    private String title;
    @ApiModelProperty(value = "发布时间", example = "2019-01-01 12:20:59")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date sendTime;
    @ApiModelProperty(value = "公告内容", example = "内容")
    private String content;
    public String getNoticeId() {
        return noticeId;
@ -75,12 +75,4 @@ public class UserNoticeVO extends UuidIdentityEntity{
    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
}

+ 39 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxComboVO.java

@ -0,0 +1,39 @@
package com.yihu.jw.restmodel.base.wx;
import io.swagger.annotations.ApiModelProperty;
/**
 * Created by Administrator on 2018/10/9.
 */
public class WxComboVO {
    @ApiModelProperty(value = "微信id")
    private String id;
    @ApiModelProperty(value = "微信公众号")
    private String name;
    @ApiModelProperty(value = "原始id")
    private String appOriginId;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAppOriginId() {
        return appOriginId;
    }
    public void setAppOriginId(String appOriginId) {
        this.appOriginId = appOriginId;
    }
}

+ 40 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxGraphicSceneVO.java

@ -0,0 +1,40 @@
package com.yihu.jw.restmodel.base.wx;
import io.swagger.annotations.ApiModelProperty;
/**
 * Created by Administrator on 2018/10/9.
 */
public class WxGraphicSceneVO {
    @ApiModelProperty(value = "id")
    private String id;
    @ApiModelProperty(value = "所属微信")
    private String wechatId;//所属微信
    @ApiModelProperty(value = "场景值")
    private String scene;//场景值
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
}

+ 79 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxReplySceneVO.java

@ -0,0 +1,79 @@
package com.yihu.jw.restmodel.base.wx;
import io.swagger.annotations.ApiModelProperty;
/**
 * Created by Administrator on 2018/10/9.
 */
public class WxReplySceneVO {
    @ApiModelProperty(value = "微信id(唯一)")
    private String wechatId;//微信id(唯一)
    @ApiModelProperty(value = "原始ID(唯一)")
    private String appOriginId;//原始ID(唯一)
    @ApiModelProperty(value = "微信消息类型:text,event,image,voice,video,shortvideo,location,link")
    private String msgType;//微信消息类型:text,event,image,voice,video,shortvideo,location,link
    @ApiModelProperty(value = "微信事件类型:SCAN,LOCATION,CLICK,subscribe,unsubscribe")
    private String event;//微信事件类型:SCAN,LOCATION,CLICK,subscribe,unsubscribe
    @ApiModelProperty(value = "图文消息/自定义消息,分组场景,微信的eventKey")
    private String scene;//图文消息/自定义消息,分组场景,微信的eventKey
    @ApiModelProperty(value = "居民回复内容,消息字段")
    private String content;//居民回复内容,消息字段
    @ApiModelProperty(value = "状态(-1删除 0 冻结 1可用")
    private Integer status;//状态(-1删除 0 冻结 1可用
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    public String getAppOriginId() {
        return appOriginId;
    }
    public void setAppOriginId(String appOriginId) {
        this.appOriginId = appOriginId;
    }
    public String getMsgType() {
        return msgType;
    }
    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }
    public String getEvent() {
        return event;
    }
    public void setEvent(String event) {
        this.event = event;
    }
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 263 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxTemplateConfigVO.java

@ -0,0 +1,263 @@
package com.yihu.jw.restmodel.base.wx;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
/**
 * Created by Administrator on 2018/10/10.
 */
public class WxTemplateConfigVO {
    @ApiModelProperty(value = "id")
    private String id;
    @ApiModelProperty(value = "微信id")
    private String wechatId;//微信id
    @ApiModelProperty(value = "微信模板id")
    private String templateId;//微信模板id
    @ApiModelProperty(value = "自定义模板名称")
    private String templateName;//自定义模板名称
    @ApiModelProperty(value = "使用场景值")
    private String scene;//使用场景值
    @ApiModelProperty(value = "使用场景描述")
    private String sceneDescription;//使用场景描述
    @ApiModelProperty(value = "头部")
    private String first;//头部,
    @ApiModelProperty(value = "跳转链接")
    private String url;//跳转链接
    @ApiModelProperty(value = "备注")
    private String remark;//备注
    @ApiModelProperty(value = "项目")
    private String keyword1;//项目
    @ApiModelProperty(value = "项目")
    private String keyword2;//项目
    @ApiModelProperty(value = "项目")
    private String keyword3;//项目
    @ApiModelProperty(value = "项目")
    private String keyword4;//项目
    @ApiModelProperty(value = "项目")
    private String keyword5;//项目
    @ApiModelProperty(value = "项目")
    private String keyword6;//项目
    @ApiModelProperty(value = "项目")
    private String keyword7;//项目
    @ApiModelProperty(value = "跳转小程序的appid")
    private String appid;//跳转小程序的appid
    @ApiModelProperty(value = "跳转小程序路径")
    private String pagepath;//跳转小程序路径
    @ApiModelProperty(value = "状态 -1删除 0 冻结 1可用")
    private Integer status;  //状态 -1删除 0 冻结 1可用
    @ApiModelProperty(value = "创建人")
    private String createUser;//创建人
    @ApiModelProperty(value = "创建人名")
    private String createUserName;//创建人名
    @ApiModelProperty(value = "创建时间")
    private Date createTime;//创建时间
    @ApiModelProperty(value = "修改人")
    private String updateUser;//修改人
    @ApiModelProperty(value = "修改人名称")
    private String updateUserName;//修改人名称
    @ApiModelProperty(value = "修改时间")
    private Date updateTime;//修改时间
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    public String getTemplateId() {
        return templateId;
    }
    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    public String getSceneDescription() {
        return sceneDescription;
    }
    public void setSceneDescription(String sceneDescription) {
        this.sceneDescription = sceneDescription;
    }
    public String getFirst() {
        return first;
    }
    public void setFirst(String first) {
        this.first = first;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public String getKeyword1() {
        return keyword1;
    }
    public void setKeyword1(String keyword1) {
        this.keyword1 = keyword1;
    }
    public String getKeyword2() {
        return keyword2;
    }
    public void setKeyword2(String keyword2) {
        this.keyword2 = keyword2;
    }
    public String getKeyword3() {
        return keyword3;
    }
    public void setKeyword3(String keyword3) {
        this.keyword3 = keyword3;
    }
    public String getKeyword4() {
        return keyword4;
    }
    public void setKeyword4(String keyword4) {
        this.keyword4 = keyword4;
    }
    public String getKeyword5() {
        return keyword5;
    }
    public void setKeyword5(String keyword5) {
        this.keyword5 = keyword5;
    }
    public String getKeyword6() {
        return keyword6;
    }
    public void setKeyword6(String keyword6) {
        this.keyword6 = keyword6;
    }
    public String getKeyword7() {
        return keyword7;
    }
    public void setKeyword7(String keyword7) {
        this.keyword7 = keyword7;
    }
    public String getAppid() {
        return appid;
    }
    public void setAppid(String appid) {
        this.appid = appid;
    }
    public String getPagepath() {
        return pagepath;
    }
    public void setPagepath(String pagepath) {
        this.pagepath = pagepath;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    public String getCreateUserName() {
        return createUserName;
    }
    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
    public String getUpdateUserName() {
        return updateUserName;
    }
    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

+ 51 - 60
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxTemplateVO.java

@ -1,5 +1,8 @@
package com.yihu.jw.restmodel.base.wx;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -9,23 +12,36 @@ import java.util.Map;
 * Created by Administrator on 2017/5/20 0020.
 */
public class WxTemplateVO {
    @ApiModelProperty(value = "id")
    private String id;
    @ApiModelProperty(value = "模板标题")
    private String title;//模板标题
    private String name;//用于模板列表渲染
    private String wechatCode;//关联的微信code 关联表 Wx_Wechat
    private String wechatName;//关联的微信名
    @ApiModelProperty(value = "关联的微信code 关联表 Wx_Wechat")
    private String wechatId;//关联的微信code 关联表 Wx_Wechat
    @ApiModelProperty(value = "微信模板id")
    private String templateId;//微信模板id
    @ApiModelProperty(value = "模板名称(模板检索名称)")
    private String templateName;//模板名称(模板检索名称)
    @ApiModelProperty(value = "模板内容")
    private String content;//模板内容
    @ApiModelProperty(value = "remark")
    private String remark;
    @ApiModelProperty(value = "状态 -1删除 0 冻结 1可用")
    private Integer status;  //状态 -1删除 0 冻结 1可用
    @ApiModelProperty(value = "创建人")
    private String createUser;//创建人
    @ApiModelProperty(value = "创建人名")
    private String createUserName;//创建人名
    @ApiModelProperty(value = "创建时间")
    private Date createTime;//创建时间
    @ApiModelProperty(value = "修改人")
    private String updateUser;//修改人
    @ApiModelProperty(value = "修改人名称")
    private String updateUserName;//修改人名称
    @ApiModelProperty(value = "修改时间")
    private Date updateTime;//修改时间
    private String remark;
    private List<Map<String,Object>> children = new ArrayList<>();
    private String state;
    private Integer status;  //状态 -1删除 0 冻结 1可用
    public String getId() {
        return id;
@ -35,23 +51,6 @@ public class WxTemplateVO {
        this.id = id;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getTitle() {
        return title;
    }
@ -60,20 +59,12 @@ public class WxTemplateVO {
        this.title = title;
    }
    public String getWechatCode() {
        return wechatCode;
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatCode(String wechatCode) {
        this.wechatCode = wechatCode;
    }
    public String getWechatName() {
        return wechatName;
    }
    public void setWechatName(String wechatName) {
        this.wechatName = wechatName;
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    public String getTemplateId() {
@ -84,6 +75,14 @@ public class WxTemplateVO {
        this.templateId = templateId;
    }
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    public String getContent() {
        return content;
    }
@ -92,6 +91,22 @@ public class WxTemplateVO {
        this.content = content;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getCreateUser() {
        return createUser;
    }
@ -139,28 +154,4 @@ public class WxTemplateVO {
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getName() {
        return title;
    }
    public void setName(String name) {
        this.name = name;
    }
    public List<Map<String, Object>> getChildren() {
        return children;
    }
    public void setChildren(List<Map<String, Object>> children) {
        this.children = children;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
}

+ 4 - 1
common/common-util/pom.xml

@ -61,6 +61,9 @@
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
        </dependency>
    </dependencies>
</project>

+ 15 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/AllowAllHostnameVerifier.java

@ -0,0 +1,15 @@
package com.yihu.jw.util.http;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
/**
 * @author Air
 * @version 1.0
 * @created 2015.07.02 15:48
 */
public class AllowAllHostnameVerifier implements HostnameVerifier {
    public boolean verify(String hostname, SSLSession session) {
        return true;
    }
}

+ 100 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/CustomTrustClientClientImpl.java

@ -0,0 +1,100 @@
package com.yihu.jw.util.http;
import okhttp3.OkHttpClient;
import javax.net.ssl.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collection;
/**
 * 用于非受信证书的HTTPS访问
 *
 * @created Airhead 2016/8/24.
 */
class CustomTrustClientClientImpl extends DefaultClientImpl {
    CustomTrustClientClientImpl() {
        try {
            final TrustManager[] trustManagers = new TrustManager[]{
                    new X509TrustManager() {
                        @Override
                        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
                        }
                        @Override
                        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
                        }
                        @Override
                        public X509Certificate[] getAcceptedIssuers() {
                            return new X509Certificate[0];
                        }
                    }
            };
            final SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, trustManagers, new SecureRandom());
            SSLSocketFactory socketFactory = sslContext.getSocketFactory();
            OkHttpClient httpClient = new OkHttpClient.Builder()
                    .sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0])
                    .hostnameVerifier(new AllowAllHostnameVerifier()).build();
            setHttpClient(httpClient);
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            e.printStackTrace();
        }
    }
    CustomTrustClientClientImpl(String path, String password) {
        try {
            InputStream inputStream = new FileInputStream(new File(path));
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(inputStream);
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            InputStream in = null;
            keyStore.load(in, password.toCharArray());
            int index = 0;
            for (Certificate certificate : certificates) {
                String certificateAlias = Integer.toString(index++);
                keyStore.setCertificateEntry(certificateAlias, certificate);
            }
            KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(keyStore, password.toCharArray());
            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(inputStream, password.toCharArray());
            trustManagerFactory.init(trustStore);
            TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
            if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509KeyManager)) {
                throw new IllegalStateException("Unexpectd default trust managers:" + Arrays.toString(trustManagers));
            }
            SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustManagers, new SecureRandom());
            SSLSocketFactory socketFactory = sslContext.getSocketFactory();
            OkHttpClient httpClient = new OkHttpClient.Builder()
                    .sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0])
                    .hostnameVerifier(new AllowAllHostnameVerifier()).build();
            setHttpClient(httpClient);
        } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException | KeyManagementException | UnrecoverableKeyException e) {
            e.printStackTrace();
        }
    }
}

+ 336 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/DefaultClientImpl.java

@ -0,0 +1,336 @@
package com.yihu.jw.util.http;
import okhttp3.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
 * @author Airhead
 * @since 2016/8/24.
 */
class DefaultClientImpl implements HTTPClient {
    private static final Log log = LogFactory.getLog(DefaultClientImpl.class);
    private OkHttpClient httpClient;
    DefaultClientImpl() {
        this.httpClient = new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS).build();
    }
    public HTTPResponse get(String url) {
        return get(url, null);
    }
    public HTTPResponse get(String url, Map<String, String> params) {
        return get(url, params, null);
    }
    public HTTPResponse get(String url, Map<String, String> params, Map<String, String> headers) {
        try {
            Request.Builder builder = new Request.Builder();
            if (headers != null) {
                builder.headers(Headers.of(headers));
            }
            Request request = builder
                    .url(formatURL(url, params))
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            // ?? 怎么把异常处理了??  应该交由调用者处理
            ex.printStackTrace();
            log.error(ex.getMessage());
            return new HTTPResponse(417,ex.getMessage());
        }
    }
    public HTTPResponse post(String url) {
        return post(url, (Map<String, String>) null);
    }
    public HTTPResponse post(String url, Map<String, String> params) {
        return post(url, params, null);
    }
    public HTTPResponse post(String url, Map<String, String> params, Map<String, String> headers) {
        try {
            FormBody.Builder fromBodyBuilder = new FormBody.Builder();
            if (params != null) {
                params.forEach(fromBodyBuilder::add);
            }
            RequestBody requestBody = fromBodyBuilder
                    .build();
            Request.Builder builder = new Request.Builder();
            if (headers != null) {
                builder.headers(Headers.of(headers));
            }
            Request request = builder
                    .url(url)
                    .post(requestBody)
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            //讲异常信息返回,交由调用者处理
            log.error(ex.getMessage());
            return new HTTPResponse(417,ex.getMessage());
        }
    }
    @Override
    public HTTPResponse post(String url, String json, Map<String, String> headers) {
        try {
            Request.Builder builder = new Request.Builder();
            if (headers != null) {
                builder.headers(Headers.of(headers));
            }
            final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            RequestBody body = RequestBody.create(JSON, json);
            Request request = builder
                    .url(url)
                    .post(body)
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    public HTTPResponse postFile(String url, String path) {
        return postFile(url, path, null);
    }
    public HTTPResponse postFile(String url, String path, Map<String, String> params) {
        return postFile(url, path, params, null);
    }
    public HTTPResponse postFile(String url, String path, Map<String, String> params, Map<String, String> headers) {
        try {
            File file = new File(path);
            final MediaType type = MediaType.parse("application/zip");
            Request.Builder requestBuilder = new Request.Builder();
            if (headers != null) {
                requestBuilder.headers(Headers.of(headers));
            }
            MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
            multipartBuilder.setType(MultipartBody.FORM)
                    .addFormDataPart("pack", file.getName(), RequestBody.create(type, file));
            for (String key : params.keySet()) {
                multipartBuilder.addFormDataPart(key, params.get(key));
            }
            Request request = requestBuilder
                    .url(url)
                    .post(multipartBuilder.build())
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    @Override
    public HTTPResponse postFile(String url, String key, String path, String contentType) {
        try {
            File file = new File(path);
            final MediaType type = MediaType.parse(contentType);
            Request.Builder requestBuilder = new Request.Builder();
            MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
            multipartBuilder.setType(MultipartBody.FORM)
                    .addFormDataPart(key, file.getName(), RequestBody.create(type, file));
            Request request = requestBuilder
                    .url(url)
                    .post(multipartBuilder.build())
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    public HTTPResponse put(String url) {
        return put(url, (Map<String, String>) null);
    }
    public HTTPResponse put(String url, Map<String, String> params) {
        return put(url, params, null);
    }
    @Override
    public HTTPResponse put(String url, String json) {
        try {
            final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            RequestBody body = RequestBody.create(JSON, json);
            Request request = new Request.Builder()
                    .url(url)
                    .put(body)
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            ex.printStackTrace();
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    public HTTPResponse put(String url, Map<String, String> params, Map<String, String> headers) {
        try {
            FormBody.Builder fromBodyBuilder = new FormBody.Builder();
            if (params != null) {
                params.forEach(fromBodyBuilder::add);
            }
            RequestBody requestBody = fromBodyBuilder
                    .build();
            Request.Builder builder = new Request.Builder();
            if (headers != null) {
                builder.headers(Headers.of(headers));
            }
            Request request = builder
                    .url(url)
                    .put(requestBody)
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    public HTTPResponse delete(String url) {
        return delete(url, (Map<String, String>) null);
    }
    public HTTPResponse delete(String url, Map<String, String> params) {
        return delete(url, params, null);
    }
    @Override
    public HTTPResponse delete(String url, String json) {
        try {
            final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            RequestBody body = RequestBody.create(JSON, json);
            Request request = new Request.Builder()
                    .url(url)
                    .delete(body)
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    public HTTPResponse delete(String url, Map<String, String> params, Map<String, String> headers) {
        try {
            FormBody.Builder fromBodyBuilder = new FormBody.Builder();
            if (params != null) {
                params.forEach(fromBodyBuilder::add);
            }
            RequestBody requestBody = fromBodyBuilder
                    .build();
            Request.Builder builder = new Request.Builder();
            if (headers != null) {
                builder.headers(Headers.of(headers));
            }
            Request request = builder
                    .url(url)
                    .delete(requestBody)
                    .build();
            Response response = httpClient.newCall(request).execute();
            return new HTTPResponse(response.code(), response.body().string());
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return new HTTPResponse(417, ex.getMessage());
        }
    }
    public HTTPResponse request(String method, String url, Map<String, String> params, Map<String, String> headers) {
        if (method.equals(POST)) {
            return post(url, params, headers);
        }
        if (method.equals(GET)) {
            return get(url, params, headers);
        }
        if (method.equals(PUT)) {
            return put(url, params, headers);
        }
        if (method.equals(DELETE)) {
            return delete(url, params, headers);
        }
        return get(url, params, headers);
    }
    protected void setHttpClient(OkHttpClient okHttpClient) {
        this.httpClient = okHttpClient;
    }
    private String formatURL(String url, Map<String, String> params) {
        if (params == null) {
            return url;
        }
        final String[] query = {""};
        params.forEach((name, value) -> {
            try {
                query[0] += "&" + name + "=" + URLEncoder.encode(value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("encode url ");
            }
        });
        if (url.contains("?")) {
            return url + query[0];
        }
        return url + "?" + query[0].substring(1);
    }
}

+ 54 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/HTTPClient.java

@ -0,0 +1,54 @@
package com.yihu.jw.util.http;
import java.util.Map;
/**
 * @created Airhead 2016/8/24.
 */
public interface HTTPClient {
    //主要的几种方法,其他的暂时未使用
    String GET = "GET";
    String POST = "POST";
    String PUT = "PUT";
    String DELETE = "DELETE";
    HTTPResponse get(String url);
    HTTPResponse get(String url, Map<String, String> params);
    HTTPResponse get(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse post(String url);
    HTTPResponse post(String url, Map<String, String> params);
    HTTPResponse post(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse post(String url, String json, Map<String, String> headers);
    HTTPResponse postFile(String url, String path);
    HTTPResponse postFile(String url, String path, Map<String, String> params);
    HTTPResponse postFile(String url, String path, Map<String, String> params, Map<String, String> headers);
    HTTPResponse postFile(String url, String key, String path, String contentType);
    HTTPResponse put(String url);
    HTTPResponse put(String url, Map<String, String> params);
    HTTPResponse put(String url, String json);
    HTTPResponse put(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse delete(String url);
    HTTPResponse delete(String url, Map<String, String> params);
    HTTPResponse delete(String url, String json);
    HTTPResponse delete(String url, Map<String, String> params, Map<String, String> headers);
    HTTPResponse request(String method, String url, Map<String, String> params, Map<String, String> headers);
}

+ 23 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/HTTPResponse.java

@ -0,0 +1,23 @@
package com.yihu.jw.util.http;
/**
 * @created Airhead 2016/8/24.
 */
public class HTTPResponse {
    private final int statusCode;// e.g. 200
    private final String body;
    public HTTPResponse(int statusCode, String body) {
        this.statusCode = statusCode;
        this.body = body;
    }
    public int getStatusCode() {
        return statusCode;
    }
    public String getBody() {
        return body;
    }
}

+ 155 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientKit.java

@ -0,0 +1,155 @@
package com.yihu.jw.util.http;
import javafx.util.Pair;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import java.util.HashMap;
import java.util.Map;
/**
 * @created Airhead 2016/8/24.
 */
public class HttpClientKit {
    private static Map<String, Pair<String, String>> keyStoreMap = new HashMap<>();
    private static Map<String, SSLConnectionSocketFactory> keyStoreSSLMap = new HashMap<>();
    /**
     * 用于HTTP和受信HTTPS
     *
     * @return
     */
    public static HTTPClient use() {
        return new DefaultClientImpl();
    }
    /**
     * 用于非受信HTTPS
     *
     * @param host host正常情况是不需要包含端口号的。
     *             但在非域名(或开发)时,不同的端口会使用不同证书,
     *             在添加host时,可以增加端口号
     *             格式:
     *             1.ip:port
     *             2.domain
     * @return
     */
    public static HTTPClient custom(String host) {
        if (host != null) {
            Pair<String, String> keyStore = keyStoreMap.get(host);
            if (keyStore != null) {
                return new CustomTrustClientClientImpl(keyStore.getKey(), keyStore.getValue());
            }
        }
        return new CustomTrustClientClientImpl();
    }
    public static void addKeyStore(String host, String file, String password) throws Exception {
        keyStoreMap.put(host, new Pair<>(file, password));
    }
    public static void addKeyStoreSSL(String host, SSLConnectionSocketFactory sslConnectionSocketFactory) throws Exception {
        keyStoreSSLMap.put(host, sslConnectionSocketFactory);
    }
    public static HTTPResponse get(String url) {
        return use().get(url);
    }
    public static HTTPResponse get(String url, Map<String, String> params) {
        return use().get(url, params);
    }
    public static HTTPResponse get(String url, Map<String, String> params, Map<String, String> headers) {
        return use().get(url, params, headers);
    }
    public static HTTPResponse post(String url) {
        return use().post(url);
    }
    public static HTTPResponse post(String url, Map<String, String> params) {
        return use().post(url, params);
    }
    public static HTTPResponse post(String url, String json) {
        return use().post(url, json, null);
    }
    public static HTTPResponse post(String url, String json, Map<String, String> headers) {
        return use().post(url, json, headers);
    }
    public static HTTPResponse post(String url, Map<String, String> params, Map<String, String> headers) {
        return use().post(url, params, headers);
    }
    public static HTTPResponse postFile(String url, String path) {
        return use().postFile(url, path);
    }
    public static HTTPResponse postFile(String url, String path, Map<String, String> params) {
        if (url.startsWith("https")) {
            return custom(url).postFile(url, path, params);
        } else {
            return use().postFile(url, path, params);
        }
    }
    public static HTTPResponse postFile(String url, String key, String path, String contentType) {
        if (url.startsWith("https")) {
            return custom(url).postFile(url, key, path, contentType);
        } else {
            return use().postFile(url, key, path, contentType);
        }
    }
    public static HTTPResponse postFile(String url, String path, Map<String, String> params, Map<String, String> headers) {
        if (url.startsWith("https")) {
            return custom(url).postFile(url, path, params, headers);
        } else {
            return use().postFile(url, path, params, headers);
        }
    }
    public static HTTPResponse put(String url) {
        return use().put(url);
    }
    public static HTTPResponse put(String url, Map<String, String> params) {
        return use().put(url, params);
    }
    public static HTTPResponse put(String url, String json) {
        return use().put(url, json);
    }
    public static HTTPResponse put(String url, Map<String, String> params, Map<String, String> headers) {
        return use().put(url, params, headers);
    }
    public static HTTPResponse delete(String url) {
        return use().delete(url);
    }
    public static HTTPResponse delete(String url, Map<String, String> params) {
        return use().delete(url, params);
    }
    public static HTTPResponse delete(String url, String json) {
        return use().delete(url, json);
    }
    public static HTTPResponse delete(String url, Map<String, String> params, Map<String, String> headers) {
        return use().delete(url, params, headers);
    }
    public static HTTPResponse request(String method, String url, Map<String, String> params, Map<String, String> headers) {
        if (url.startsWith("https")) {
            return custom(url).request(method, url, params, headers);
        } else {
            return use().request(method, url, params, headers);
        }
    }
}

+ 3 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/dao/notice/NoticeDao.java

@ -4,11 +4,13 @@ import com.yihu.jw.entity.base.notice.NoticeDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 公告通知
 * @author yeshijie on 2018/9/30.
 */
public interface NoticeDao extends PagingAndSortingRepository<NoticeDO, String>, JpaSpecificationExecutor<NoticeDO> {
    List<NoticeDO> findByStatusAndSendType(Integer status,Integer sendType);
}

+ 4 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/user/UserDao.java

@ -4,9 +4,13 @@ import com.yihu.jw.entity.base.user.UserDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Dao - 后台管理员
 * Created by progr1mmer on 2018/8/20.
 */
public interface UserDao extends PagingAndSortingRepository<UserDO, String>, JpaSpecificationExecutor<UserDO> {
    List<UserDO> findByEnabled(boolean enabled);
}

+ 11 - 14
svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxGraphicMessageDao.java

@ -1,15 +1,12 @@
package com.yihu.jw.base.dao.wx;//package com.yihu.jw.business.wx.dao;
//
//import com.yihu.jw.base.wx.WxGraphicMessageDO;
//import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
//import org.springframework.data.jpa.repository.Query;
//import org.springframework.data.repository.PagingAndSortingRepository;
//
///**
// * Created by Administrator on 2017/5/20 0020.
// */
//public interface WxGraphicMessageDao extends PagingAndSortingRepository<WxGraphicMessageDO, String>, JpaSpecificationExecutor<WxGraphicMessageDO> {
//
//    @Query("from WxGraphicMessageDO w where w.id =?1 and w.status!=-1")
//    WxGraphicMessageDO findById(String id);
//}
import com.yihu.jw.entity.base.wx.WxGraphicMessageDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Administrator on 2017/5/20 0020.
 */
public interface WxGraphicMessageDao extends PagingAndSortingRepository<WxGraphicMessageDO, String>, JpaSpecificationExecutor<WxGraphicMessageDO> {
}

+ 11 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxGraphicSceneDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.base.dao.wx;
import com.yihu.jw.entity.base.wx.WxGraphicSceneDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Administrator on 2018/10/9.
 */
public interface WxGraphicSceneDao extends PagingAndSortingRepository<WxGraphicSceneDO, String>, JpaSpecificationExecutor<WxGraphicSceneDO> {
}

+ 20 - 20
svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxTemplateDao.java

@ -1,21 +1,21 @@
package com.yihu.jw.base.dao.wx;//package com.yihu.jw.business.wx.dao;
//
//import com.yihu.jw.base.wx.WxTemplateDO;
//import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
//import org.springframework.data.jpa.repository.Query;
//import org.springframework.data.repository.PagingAndSortingRepository;
//
//import java.util.List;
//
///**
// * Created by Administrator on 2017/5/20 0020.
// */
//public interface WxTemplateDao extends PagingAndSortingRepository<WxTemplateDO, String>, JpaSpecificationExecutor<WxTemplateDO> {
//
//
//    @Query("from WxTemplateDO w where w.id = ?1 and w.status =1")
//    WxTemplateDO findById(String id);
//
//    @Query("from WxTemplateDO w where w.wechatId = ?1 and w.status =1")
//    List<WxTemplateDO> findByWxId(String wechatId);
//}
import com.yihu.jw.entity.base.wx.WxTemplateDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Administrator on 2017/5/20 0020.
 */
public interface WxTemplateDao extends PagingAndSortingRepository<WxTemplateDO, String>, JpaSpecificationExecutor<WxTemplateDO> {
    @Query("from WxTemplateDO w where w.id = ?1 and w.status =1")
    WxTemplateDO findById(String id);
    @Query("from WxTemplateDO w where w.wechatId = ?1 and w.status =1")
    List<WxTemplateDO> findByWxId(String wechatId);
}

+ 14 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxWechatSaasDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.base.dao.wx;
import com.yihu.jw.entity.base.wx.WxWechatSaasDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Administrator on 2018/10/8.
 */
public interface WxWechatSaasDao  extends PagingAndSortingRepository<WxWechatSaasDO, String>, JpaSpecificationExecutor<WxWechatSaasDO> {
    List<WxWechatSaasDO> findByWechatId(String wechatId);
}

+ 165 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/FileUploadController.java

@ -0,0 +1,165 @@
package com.yihu.jw.base.endpoint.common;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.base.util.ErrorCodeUtil;
import com.yihu.jw.exception.code.BaseErrorCode;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLDecoder;
import java.util.Base64;
/**
 * 文件上传不在微服务中处理
 * @author yeshijie on 2017/12/7.
 */
@RestController
@RequestMapping(BaseRequestMapping.FileUpload.PREFIX)
@Api(tags = "文件上传相关操作", description = "文件上传相关操作")
public class FileUploadController extends EnvelopRestEndpoint {
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Autowired
    private ErrorCodeUtil errorCodeUtil;
    @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM_IMG)
    @ApiOperation(value = "文件流上传图片", notes = "文件流上传图片")
    public ObjEnvelop<UploadVO> uploadImg(@ApiParam(value = "文件", required = true)
                                       @RequestParam(value = "file", required = true) MultipartFile file) throws Exception{
        // 得到文件的完整名称  xxx.txt
        String fullName = file.getOriginalFilename();
        if(StringUtils.isBlank(fullName)){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.FileUpload.FAIL_UPLOAD_FORMAT), ObjEnvelop.class);
        }
        //得到文件类型
        String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
        if(StringUtils.isBlank(fileType)||!"jpg,jpeg,png".contains(fileType)){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.FileUpload.FAIL_UPLOAD_FORMAT), ObjEnvelop.class);
        }
        long size = file.getSize();
        long max = 5*1024*1024;
        if(size>max){
            String msg = String.format(BaseErrorCode.FileUpload.FAIL_FILE_SIZE, 5);
            return failed(msg, ObjEnvelop.class);
        }
        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(fileName);
        uploadVO.setFileType(fileType);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        return success("上传成功", uploadVO);
    }
    @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM_ATTACHMENT)
    @ApiOperation(value = "文件流上传附件", notes = "文件流上传附件")
    public ObjEnvelop<UploadVO> uploadAttachment(@ApiParam(value = "文件", required = true)
                                       @RequestParam(value = "file", required = true) MultipartFile file) throws Exception{
        // 得到文件的完整名称  xxx.txt
        String fullName = file.getOriginalFilename();
        if(StringUtils.isBlank(fullName)){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.FileUpload.FAIL_UPLOAD_FORMAT), ObjEnvelop.class);
        }
        //得到文件类型
        String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
        if(StringUtils.isBlank(fileType)||!"doc、docx、pdf、xls、xlsx、jpg、jpeg、png".contains(fileType)){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.FileUpload.FAIL_UPLOAD_FORMAT), ObjEnvelop.class);
        }
        long size = file.getSize();
        long max = 5*1024*1024;
        if(size>max){
            String msg = String.format(BaseErrorCode.FileUpload.FAIL_FILE_SIZE, 5);
            return failed(msg, ObjEnvelop.class);
        }
        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(fileName);
        uploadVO.setFileType(fileType);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        return success("上传成功", uploadVO);
    }
    @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM)
    @ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
    public ObjEnvelop<UploadVO> uploadStream(@ApiParam(value = "文件", required = true)
        @RequestParam(value = "file", required = true) MultipartFile file) throws Exception{
        // 得到文件的完整名称  xxx.txt
        String fullName = file.getOriginalFilename();
        //得到文件类型
        String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(fileName);
        uploadVO.setFileType(fileType);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        return success("上传成功", uploadVO);
    }
    @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STRING)
    @ApiOperation(value = "base64上传图片",notes = "base64上传图片")
    public ObjEnvelop<UploadVO> uploadImages(@ApiParam(name = "jsonData", value = "头像转化后的输入流")
                                                 @RequestBody String jsonData) throws Exception {
        if(jsonData == null){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.FileUpload.FILE_NULL), ObjEnvelop.class);
        }
        String date = URLDecoder.decode(jsonData,"UTF-8");
        String[] fileStreams = date.split(",");
        String is = URLDecoder.decode(fileStreams[1],"UTF-8").replace(" ","+");
        byte[] in = Base64.getDecoder().decode(is);
        String pictureName = fileStreams[0].substring(0,fileStreams[0].length()-1);
        String fileExtension = pictureName.substring(pictureName.lastIndexOf(".") + 1).toLowerCase();
        String description = null;
        if ((pictureName != null) && (pictureName.length() > 0)) {
            int dot = pictureName.lastIndexOf('.');
            if ((dot > -1) && (dot < (pictureName.length()))) {
                description = pictureName.substring(0, dot);
            }
        }
        InputStream inputStream = new ByteArrayInputStream(in);
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, "png", "");
        String groupName = objectNode.get("groupName").toString();
        String remoteFileName = objectNode.get("remoteFileName").toString();
        //解析返回的objectNode
        UploadVO uploadVO = new UploadVO();
        uploadVO.setFileName(remoteFileName);
        uploadVO.setFileType(groupName);
        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", ""));
        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", ""));
        //返回文件路径
        return success("上传成功", uploadVO);
    }
}

+ 123 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/notice/NoticeEndPoint.java

@ -0,0 +1,123 @@
package com.yihu.jw.base.endpoint.notice;
import com.yihu.jw.base.service.notice.NoticeService;
import com.yihu.jw.base.util.ErrorCodeUtil;
import com.yihu.jw.entity.base.notice.NoticeDO;
import com.yihu.jw.exception.code.BaseErrorCode;
import com.yihu.jw.restmodel.base.notice.NoticeVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 公告通知
 * @author yeshijie on 2018/10/9.
 */
@RestController
@RequestMapping(value = BaseRequestMapping.Notice.PREFIX)
@Api(value = "公告通知管理", description = "公告通知管理服务接口", tags = {"基础服务 - 公告通知管理服务接口"})
public class NoticeEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private NoticeService noticeService;
    @Autowired
    private ErrorCodeUtil errorCodeUtil;
    @PostMapping(value = BaseRequestMapping.Notice.CREATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建")
    public ObjEnvelop<NoticeVO> create (
            @ApiParam(name = "json_data", value = "Json数据", required = true)
            @RequestBody String jsonData) throws Exception {
        NoticeDO noticeDO = toEntity(jsonData, NoticeDO.class);
        if(StringUtils.isBlank(noticeDO.getTitle())||noticeDO.getTitle().length()>50){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Notice.LIMIT_TITLE), ObjEnvelop.class);
        }
        noticeDO = noticeService.addNotice(noticeDO);
        return success(noticeDO, NoticeVO.class);
    }
    @PostMapping(value = BaseRequestMapping.Notice.DELETE)
    @ApiOperation(value = "删除")
    public Envelop delete(
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id) {
        noticeService.deleteNotice(id);
        return success("删除成功");
    }
    @PostMapping(value = BaseRequestMapping.Notice.RELEASE)
    @ApiOperation(value = "发布")
    public Envelop release(
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id) {
        NoticeDO noticeDO = noticeService.findById(id);
        if (NoticeDO.Status.released.getValue().equals(noticeDO.getStatus())){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Notice.HAD_RELEASE), Envelop.class);
        }
        if (NoticeDO.SendType.automatic_release.getValue().equals(noticeDO.getSendType())){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Notice.AUTO_RELEASE), Envelop.class);
        }
        noticeService.release(noticeDO);
        return success("发布成功");
    }
    @PostMapping(value = BaseRequestMapping.Notice.UPDATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新")
    public ObjEnvelop<NoticeVO> update (
            @ApiParam(name = "json_data", value = "Json数据", required = true)
            @RequestBody String jsonData) throws Exception {
        NoticeDO noticeDO = toEntity(jsonData, NoticeDO.class);
        if (null == noticeDO.getId()) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Common.ID_IS_NULL), ObjEnvelop.class);
        }
        if(StringUtils.isBlank(noticeDO.getTitle())||noticeDO.getTitle().length()>50){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Notice.LIMIT_TITLE), ObjEnvelop.class);
        }
        noticeDO = noticeService.updateNotice(noticeDO);
        return success(noticeDO, NoticeVO.class);
    }
    @GetMapping(value = BaseRequestMapping.Notice.PAGE)
    @ApiOperation(value = "获取分页")
    public PageEnvelop<NoticeVO> page (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<NoticeDO> noticeDOs = noticeService.search(fields, filters, sorts, page, size);
        int count = (int)noticeService.getCount(filters);
        return success(noticeDOs, count, page, size, NoticeVO.class);
    }
    @GetMapping(value = BaseRequestMapping.Notice.LIST)
    @ApiOperation(value = "获取列表")
    public ListEnvelop<NoticeVO> list (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        List<NoticeDO> noticeDOs = noticeService.search(fields, filters, sorts);
        return success(noticeDOs, NoticeVO.class);
    }
}

+ 54 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/notice/UserNoticeEndpoint.java

@ -0,0 +1,54 @@
package com.yihu.jw.base.endpoint.notice;
import com.yihu.jw.base.service.notice.UserNoticeService;
import com.yihu.jw.entity.base.notice.NoticeDO;
import com.yihu.jw.restmodel.base.notice.NoticeVO;
import com.yihu.jw.restmodel.base.notice.UserNoticeVO;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 *
 * @author yeshijie on 2018/10/9.
 */
@RestController
@RequestMapping(value = BaseRequestMapping.UserNotice.PREFIX)
@Api(value = "用户公告通知管理", description = "用户公告通知管理服务接口", tags = {"基础服务 - 用户公告通知管理服务接口"})
public class UserNoticeEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private UserNoticeService userNoticeService;
    @GetMapping(value = BaseRequestMapping.Module.FINDBYID)
    @ApiOperation(value = "查看文章详情")
    public ObjEnvelop<NoticeVO> findById(
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id) {
        NoticeDO noticeDO = userNoticeService.findNoticeDetail(id);
        return success(noticeDO, NoticeVO.class);
    }
    @GetMapping(value = BaseRequestMapping.Module.PAGE)
    @ApiOperation(value = "获取分页")
    public PageEnvelop<UserNoticeVO> page (
            @ApiParam(name = "userId", value = "用户id")
            @RequestParam(value = "userId", required = true) String userId,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        return userNoticeService.queryPage(page,size,userId);
    }
}

+ 196 - 5
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WechatController.java

@ -1,18 +1,22 @@
package com.yihu.jw.base.endpoint.wx;
import com.alibaba.fastjson.JSONArray;
import com.yihu.jw.base.service.wx.WechatService;
import com.yihu.jw.entity.base.wx.*;
import com.yihu.jw.restmodel.base.wx.WxReplySceneVO;
import com.yihu.jw.restmodel.base.wx.WxTemplateConfigVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by Trick on 2018/9/26.
@ -25,6 +29,8 @@ public class WechatController extends EnvelopRestEndpoint {
    @Autowired
    private WechatService wechatService;
    //====================微信与租户管理=======================
    @GetMapping(value = BaseRequestMapping.WeChat.getWechatInfos)
    @ApiOperation(value = "获取微信基本信息列表", notes = "获取微信基本信息列表")
    public MixEnvelop getWxWechatList(@ApiParam(name = "name", value = "微信名称")
@ -41,4 +47,189 @@ public class WechatController extends EnvelopRestEndpoint {
                                      @RequestParam(value = "size", required = true) Integer size) {
        return wechatService.getWxWechatList(name, saasName, status, publicType, page, size);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.saveWxAndSaas)
    @ApiOperation(value = "保存微信信息", notes = "保存微信信息")
    public Envelop saveWxAndSaas(@ApiParam(name = "wxWechatJson", value = "微信基本信息")
                                 @RequestParam(value = "wxWechatJson", required = true)String wxWechatJson,
                                 @ApiParam(name = "wxWechatSaasDOs", value = "微信租户关联")
                                 @RequestParam(value = "wxWechatSaasDOs", required = false)String wxWechatSaasDOs)throws Exception{
        WxWechatDO wxWechatDO = toEntity(wxWechatJson, WxWechatDO.class);
        List<WxWechatSaasDO> list = (List<WxWechatSaasDO>) JSONArray.parseArray(wxWechatSaasDOs, WxWechatSaasDO.class);
        return wechatService.saveWxAndSaas(wxWechatDO,list);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.updateWxAndSaas)
    @ApiOperation(value = "修改微信信息", notes = "修改微信信息")
    public Envelop updateWxAndSaas(@ApiParam(name = "wxWechatJson", value = "微信基本信息")
                                   @RequestParam(value = "wxWechatJson", required = true)String wxWechatJson,
                                   @ApiParam(name = "wxWechatSaasDOs", value = "微信租户关联")
                                   @RequestParam(value = "wxWechatSaasDOs", required = false)String wxWechatSaasDOs)throws Exception {
        WxWechatDO wxWechat = toEntity(wxWechatJson, WxWechatDO.class);
        List<WxWechatSaasDO> list = (List<WxWechatSaasDO>) JSONArray.parseArray(wxWechatSaasDOs, WxWechatSaasDO.class);
        return wechatService.updateWxAndSaas(wxWechat,list);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWechatCombo)
    @ApiOperation(value = "微信信息下拉框", notes = "微信信息下拉框")
    public MixEnvelop findWechatCombo() {
        return wechatService.findWechatCombo();
    }
    //====================微信与租户管理end=======================
    //====================图文素材管理============================
    @GetMapping(value = BaseRequestMapping.WeChat.findWechatImgGroup)
    @ApiOperation(value = "获取图文素材分组", notes = "获取图文素材分组")
    public MixEnvelop findWechatImgGroup(@ApiParam(name = "wechatId", value = "微信ID")
                                         @RequestParam(value = "wechatId", required = true)String wechatId,
                                         @ApiParam(name = "page", value = "第几页")
                                         @RequestParam(value = "page", required = false)Integer page,
                                         @ApiParam(name = "size", value = "每页条数")
                                         @RequestParam(value = "size", required = false)Integer size) {
        return wechatService.findWechatImgGroup(wechatId,page,size);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.createImgGroup)
    @ApiOperation(value = "创建图文素材分组", notes = "创建图文素材分组")
    public Envelop createImgGroup(@ApiParam(name = "wxGraphicSceneJson", value = "图文分组JSON")
                                  @RequestParam(value = "wxGraphicSceneJson", required = true)String wxGraphicSceneJson)throws Exception {
        WxGraphicSceneDO wxWechatScene = toEntity(wxGraphicSceneJson, WxGraphicSceneDO.class);
        return wechatService.createImgGroup(wxWechatScene);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.updateImgGroup)
    @ApiOperation(value = "修改图文素材分组", notes = "修改图文素材分组")
    public Envelop updateImgGroup(@ApiParam(name = "id", value = "id")
                                  @RequestParam(value = "id", required = true)String id,
                                  @ApiParam(name = "scene", value = "分组名称(场景值)")
                                  @RequestParam(value = "scene", required = true)String scene) {
        return wechatService.updateImgGroup(id,scene);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.deleteImgGroup)
    @ApiOperation(value = "删除图文素材分组", notes = "删除图文素材分组")
    public Envelop deleteImgGroup(@ApiParam(name = "id", value = "id")
                                  @RequestParam(value = "id", required = true)String id) {
        return wechatService.deleteImgGroup(id);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.saveImg)
    @ApiOperation(value = "保存图文素材", notes = "保存图文素材")
    public Envelop saveImg(@ApiParam(name = "id", value = "id")
                           @RequestParam(value = "id", required = true)String wxGraphicMessageJson)throws Exception {
        WxGraphicMessageDO WxGraphicMessage = toEntity(wxGraphicMessageJson, WxGraphicMessageDO.class);
        return wechatService.saveImg(WxGraphicMessage);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findImg)
    @ApiOperation(value = "获取图文素材", notes = "获取图文素材")
    public MixEnvelop findImg(@ApiParam(name = "wechatId", value = "微信id")
                              @RequestParam(value = "wechatId", required = true)String wechatId,
                              @ApiParam(name = "title", value = "素材标题")
                              @RequestParam(value = "title", required = false)String title,
                              @ApiParam(name = "scene", value = "场景值")
                              @RequestParam(value = "scene", required = false)String scene,
                              @ApiParam(name = "page", value = "第几页")
                              @RequestParam(value = "page", required = true)Integer page,
                              @ApiParam(name = "size", value = "每页几条")
                              @RequestParam(value = "size", required = true)Integer size) {
        return wechatService.findImg(wechatId, title, scene, page, size);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.saveImgGroup)
    @ApiOperation(value = "分组图文素材", notes = "分组图文素材")
    public Envelop saveImgGroup(@ApiParam(name = "groups", value = "微信id")
                                @RequestParam(value = "groups", required = true)String groups) {
        List<WxGraphicSceneGroupDO> list = (List<WxGraphicSceneGroupDO>) JSONArray.parseArray(groups, WxGraphicSceneGroupDO.class);
        return wechatService.saveImgGroup(list);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.saveWxReplyScene)
    @ApiOperation(value = "事件配置场景", notes = "事件配置场景")
    public Envelop saveWxReplyScene(@ApiParam(name = "wxReplySceneJson", value = "事件配置json")
                                    @RequestParam(value = "wxReplySceneJson", required = true)String wxReplySceneJson) throws Exception{
        WxReplySceneDO wxReplyScene = toEntity(wxReplySceneJson, WxReplySceneDO.class);
        return wechatService.saveWxReplyScene(wxReplyScene);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWxReplyScene)
    @ApiOperation(value = "获取消息配置场景", notes = "获取消息配置场景")
    public MixEnvelop<WxReplySceneVO,WxReplySceneVO> findWxReplyScene(@ApiParam(name = "wechatId", value = "微信id")
                                       @RequestParam(value = "wechatId", required = true)String wechatId,
                                                       @ApiParam(name = "msgType", value = "消息类型")
                                       @RequestParam(value = "msgType", required = false)String msgType,
                                                       @ApiParam(name = "event", value = "事件类型")
                                       @RequestParam(value = "event", required = false)String event,
                                                       @ApiParam(name = "content", value = "回复内容")
                                       @RequestParam(value = "content", required = false)String content,
                                                       @ApiParam(name = "page", value = "页数")
                                       @RequestParam(value = "page", required = true)Integer page,
                                                       @ApiParam(name = "size", value = "每页大小")
                                       @RequestParam(value = "size", required = true)Integer size) {
        return wechatService.findWxReplyScene(wechatId, msgType, event, content, page, size);
    }
    //====================图文素材管理end============================
    //===================模板消息==========================================
    @PostMapping(value = BaseRequestMapping.WeChat.saveWxTemp)
    @ApiOperation(value = "保存微信模板消息基础信息", notes = "保存微信模板消息基础信息")
    public Envelop saveWxTemp(@ApiParam(name = "wxTemplateJson", value = "微信模板消息基础信息json")
                              @RequestParam(value = "wxTemplateJson", required = true)String wxTemplateJson)throws Exception {
        WxTemplateDO wxTemplate = toEntity(wxTemplateJson, WxTemplateDO.class);
        return wechatService.saveWxTemp(wxTemplate);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.saveWxTemp)
    @ApiOperation(value = "获取微信模板消息基础信息(列表)", notes = "获取微信模板消息基础信息(列表)")
    public MixEnvelop findWxtemp(@ApiParam(name = "wechatId", value = "微信id")
                                 @RequestParam(value = "wechatId", required = true)String wechatId,
                                 @ApiParam(name = "status", value = "状态")
                                 @RequestParam(value = "status", required = true)Integer status,
                                 @ApiParam(name = "name", value = "微信模板名称")
                                 @RequestParam(value = "name", required = true)String name,
                                 @ApiParam(name = "key", value = "模板id或标题模糊匹配")
                                 @RequestParam(value = "key", required = true)String key,
                                 @ApiParam(name = "page", value = "页码")
                                 @RequestParam(value = "page", required = true)Integer page,
                                 @ApiParam(name = "size", value = "分页大小")
                                 @RequestParam(value = "size", required = true)Integer size) {
        return wechatService.findWxtemp(wechatId, status, name, key, page, size);
    }
    @PostMapping(value = BaseRequestMapping.WeChat.saveWxTempConfig)
    @ApiOperation(value = "保存微信模板消息信息", notes = "保存微信模板消息信息")
    public Envelop saveWxTempConfig(@ApiParam(name = "wxTemplateConfigJosn", value = "微信模板消息信息json")
                                    @RequestParam(value = "wxTemplateConfigJosn", required = true)String wxTemplateConfigJosn)throws Exception {
        WxTemplateConfigDO WxTemplateConfig = toEntity(wxTemplateConfigJosn, WxTemplateConfigDO.class);
        return wechatService.saveWxTempConfig(WxTemplateConfig);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWxTempConfigList)
    @ApiOperation(value = "获取微信模板列表", notes = "获取微信模板列表")
    public MixEnvelop<WxTemplateConfigVO,WxTemplateConfigVO> findWxTempConfigList(@ApiParam(name = "wechatId", value = "微信id")
                                           @RequestParam(value = "wechatId", required = true)String wechatId,
                                           @ApiParam(name = "scene", value = "微信场景值")
                                           @RequestParam(value = "scene", required = true)String scene,
                                           @ApiParam(name = "page", value = "第几页")
                                           @RequestParam(value = "page", required = true)Integer page,
                                           @ApiParam(name = "size", value = "分页大小")
                                           @RequestParam(value = "size", required = true)Integer size) {
        return wechatService.findWxTempConfigList(wechatId, scene, page, size);
    }
    @GetMapping(value = BaseRequestMapping.WeChat.findWxTemplateConfig)
    @ApiOperation(value = "获取微信模板列表(单条)", notes = "获取微信模板列表(单条)")
    public ObjEnvelop<WxTemplateConfigVO>  findWxTemplateConfig(@ApiParam(name = "wechatId", value = "微信id")
                                                   @RequestParam(value = "wechatId", required = true)String wechatId,
                                                                          @ApiParam(name = "name", value = "模板名称")
                                                   @RequestParam(value = "name", required = true)String name,
                                                                          @ApiParam(name = "scene", value = "场景值")
                                                   @RequestParam(value = "scene", required = true)String scene) {
        return success(wechatService.findWxTemplateConfig(wechatId,name,scene), WxTemplateConfigVO.class);
    }
    //===================模板消息end==========================================
}

+ 5 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/listener/ApplicationReadyListener.java

@ -2,6 +2,7 @@ package com.yihu.jw.base.listener;
import com.yihu.jw.base.activemq.MessageManager;
import com.yihu.jw.base.service.errorCode.ErrorCodeService;
import com.yihu.jw.base.service.notice.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
@ -18,6 +19,8 @@ public class ApplicationReadyListener implements ApplicationListener<Application
    private MessageManager messageManager;
    @Autowired
    private ErrorCodeService errorCodeService;
    @Autowired
    private NoticeService noticeService;
    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
@ -25,6 +28,8 @@ public class ApplicationReadyListener implements ApplicationListener<Application
        messageManager.initConsumer();
        //初始化错误码
        errorCodeService.initErrorCode();
        //初始化延迟队列
        noticeService.initDelayNotice();
    }
}

+ 168 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/notice/NoticeService.java

@ -1,9 +1,27 @@
package com.yihu.jw.base.service.notice;
import com.yihu.jw.base.dao.notice.NoticeDao;
import com.yihu.jw.base.dao.notice.UserNoticeDao;
import com.yihu.jw.base.dao.user.UserDao;
import com.yihu.jw.base.util.threadPool.ThreadPoolUtil;
import com.yihu.jw.base.util.delay.DelayService;
import com.yihu.jw.base.util.delay.Notice;
import com.yihu.jw.base.util.delay.OnDelayedListener;
import com.yihu.jw.base.util.delay.RedisLock;
import com.yihu.jw.entity.base.notice.NoticeDO;
import com.yihu.jw.entity.base.notice.UserNoticeDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.yihu.jw.entity.base.notice.NoticeDO.Status.released;
/**
 * 公告通知
@ -12,5 +30,155 @@ import org.springframework.stereotype.Service;
@Service
public class NoticeService extends BaseJpaService<NoticeDO, NoticeDao> {
    @Autowired
    private NoticeDao noticeDao;
    @Autowired
    private UserNoticeDao userNoticeDao;
    @Autowired
    private DelayService delayService;
    @Autowired
    private UserDao userDao;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private ThreadPoolUtil threadPoolUtil;
    /**
     * redis锁的key
     */
    private final String rediskey = "notice:";
    /**
     * 发布公告
     * @param noticeDO
     */
    @Transactional(rollbackFor = Exception.class)
    public void release(NoticeDO noticeDO){
        noticeDO.setStatus(NoticeDO.Status.released.getValue());
        noticeDO.setSendTime(new Date());
        List<UserDO> userDOList = userDao.findByEnabled(true);
        List<UserNoticeDO> userNoticeDOs = new ArrayList<>(userDOList.size());
        userDOList.forEach(userDO -> {
            UserNoticeDO userNoticeDO = new UserNoticeDO();
            userNoticeDO.setDel(1);
            userNoticeDO.setIsRead(UserNoticeDO.Read.unRead.getValue());
            userNoticeDO.setNoticeId(noticeDO.getId());
            userNoticeDO.setUserId(userDO.getId());
            userNoticeDOs.add(userNoticeDO);
        });
        userNoticeDao.save(userNoticeDOs);
        noticeDao.save(noticeDO);
    }
    /**
     * 按id查找
     * @param id
     * @return
     */
    public NoticeDO findById(String id){
        return noticeDao.findOne(id);
    }
    /**
     * 新增消息公告
     * @param noticeDO
     * @return
     */
    public NoticeDO addNotice(NoticeDO noticeDO){
        noticeDO.setDel(1);
        noticeDO.setStatus(NoticeDO.Status.wait.getValue());
        noticeDao.save(noticeDO);
        //自动发布
        if(NoticeDO.SendType.automatic_release.getValue().equals(noticeDO.getSendType())){
            Notice notice = new Notice(noticeDO.getId(), noticeDO.getSendTime().getTime());
            delayService.add(notice);
        }
        return noticeDO;
    }
    /**
     * 修改公告
     * @param noticeDO
     * @return
     */
    public NoticeDO updateNotice(NoticeDO noticeDO){
        NoticeDO noticeOld = noticeDao.findOne(noticeDO.getId());
        if(released.getValue().equals(noticeDO.getStatus())){
            //已发布的不能修改
            return noticeDO;
        }
        if(!noticeOld.getSendType().equals(noticeDO.getSendType())){
            if(NoticeDO.SendType.automatic_release.getValue().equals(noticeDO.getSendType())){
                //自动发布
                Notice notice = new Notice(noticeDO.getId(), noticeDO.getSendTime().getTime());
                delayService.add(notice);
            }else {
                //手动发布
                delayService.remove(noticeDO.getId());
            }
        }
        noticeOld.setContent(noticeDO.getContent());
        noticeOld.setTitle(noticeDO.getTitle());
        noticeOld.setSendTime(noticeDO.getSendTime());
        noticeOld.setSendType(noticeDO.getSendType());
        noticeDao.save(noticeOld);
        return noticeDO;
    }
    /**
     * 删除
     * @param noticeId
     */
    public void deleteNotice(String noticeId){
        NoticeDO noticeDO = noticeDao.findOne(noticeId);
        noticeDO.setDel(0);
        noticeDao.save(noticeDO);
    }
    /**
     * 初始化延迟队列,项目启动的时候吧数据库的数据重新加入到队列中
     */
    public void initDelayNotice(){
        //启动监听
        delayService.start(new OnDelayedListener() {
            @Override
            public void onDelayedArrived(final Notice notice) {
                //异步来做
                threadPoolUtil.execute(new Runnable() {
                    @Override
                    public void run() {
                        String noticeId = notice.getNoticeId();
                        //分布式事务锁,防止代码在多台机器上执行
                        RedisLock lock = new RedisLock(redisTemplate, rediskey+noticeId, 10000, 20000);
                        try {
                            if(lock.lock()) {
                                //需要加锁的代码
                                NoticeDO noticeDO = noticeDao.findOne(noticeId);
                                if (NoticeDO.Status.wait.getValue().equals(noticeDO.getStatus())
                                        &&NoticeDO.SendType.automatic_release.getValue().equals(noticeDO.getSendType())){
                                    release(noticeDO);
                                }
                            }
                        } catch (InterruptedException e){
                            e.printStackTrace();
                        } finally {
                            lock.unlock();
                        }
                    }
                });
            }
        });
        //查找需要加入队列的数据
        List<NoticeDO> noticeDOList = noticeDao.findByStatusAndSendType(NoticeDO.Status.wait.getValue(),
                NoticeDO.SendType.automatic_release.getValue());
        noticeDOList.forEach(noticeDO -> {
            Notice notice = new Notice(noticeDO.getId(), noticeDO.getSendTime().getTime());
            delayService.add(notice);
        });
    }
}

+ 62 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/notice/UserNoticeService.java

@ -1,10 +1,22 @@
package com.yihu.jw.base.service.notice;
import com.yihu.jw.base.dao.notice.NoticeDao;
import com.yihu.jw.base.dao.notice.UserNoticeDao;
import com.yihu.jw.entity.base.notice.NoticeDO;
import com.yihu.jw.entity.base.notice.UserNoticeDO;
import com.yihu.jw.restmodel.base.notice.UserNoticeVO;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 用户公告通知
 * @author yeshijie on 2018/9/30.
@ -12,5 +24,55 @@ import org.springframework.stereotype.Service;
@Service
public class UserNoticeService extends BaseJpaService<UserNoticeDO, UserNoticeDao> {
    @Autowired
    private UserNoticeDao userNoticeDao;
    @Autowired
    private NoticeDao noticeDao;
    @Autowired
    private JdbcTemplate jdbcTempalte;
    /**
     * 查看文章详情
     * @param id
     * @return
     */
    public NoticeDO findNoticeDetail(String id){
        UserNoticeDO userNoticeDO = userNoticeDao.findOne(id);
        if(UserNoticeDO.Read.unRead.getValue().equals(userNoticeDO.getIsRead())){
            userNoticeDO.setIsRead(UserNoticeDO.Read.read.getValue());
            userNoticeDao.save(userNoticeDO);
        }
        NoticeDO noticeDO = noticeDao.findOne(userNoticeDO.getNoticeId());
        return noticeDO;
    }
    /**
     * 按类型分页查找
     * @param page
     * @param size
     * @param userId
     * @return
     */
    public PageEnvelop<UserNoticeVO> queryPage(Integer page, Integer size, String userId){
        StringBuffer sql = new StringBuffer("SELECT n.id noticeId,n.title,n.send_time sendTime,u.id,u.is_read isRead,u.user_id userId from base_notice n , base_user_notice u WHERE n.del = '1' ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(*) count from base_notice n , base_user_notice u WHERE n.del = '1' ");
        List<Object> args = new ArrayList<>();
        if(StringUtils.isNotBlank(userId)){
            sql.append(" and u.user_id=? ");
            sqlCount.append(" and u.user_id='").append(userId).append("' ");
            args.add(userId);
        }
        sql.append(" and u.notice_id = n.id and u.del = '1' ");
        sqlCount.append(" and u.notice_id = n.id and u.del = '1'");
        sql.append(" ORDER BY n.send_time desc limit ").append((page-1)*size).append(",").append(size);
        List<UserNoticeVO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(UserNoticeVO.class));
        List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
        long count = Long.valueOf(countList.get(0).get("count").toString());
        return PageEnvelop.getSuccessListWithPage("查找成功",list, page, size,count);
    }
}

+ 355 - 5
svr/svr-base/src/main/java/com/yihu/jw/base/service/wx/WechatService.java

@ -1,12 +1,12 @@
package com.yihu.jw.base.service.wx;
import com.yihu.jw.restmodel.base.saas.SaasVO;
import com.yihu.jw.restmodel.base.wx.WxSaasVO;
import com.yihu.jw.restmodel.base.wx.WxWechatVO;
import com.yihu.jw.base.dao.wx.*;
import com.yihu.jw.entity.base.wx.*;
import com.yihu.jw.restmodel.base.wx.*;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.rm.base.BaseRequestMapping;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * Created by trick on 2017/5/20 0020.
@ -26,6 +27,24 @@ public class WechatService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private WechatDao wechatDao;
    @Autowired
    private WxWechatSaasDao wxWechatSaasDao;
    @Autowired
    private WxGraphicSceneDao wxGraphicSceneDao;
    @Autowired
    private WxGraphicSceneGroupDao wxGraphicSceneGroupDao;
    @Autowired
    private WxGraphicMessageDao wxGraphicMessageDao;
    @Autowired
    private WxReplySceneDao wxReplySceneDao;
    @Autowired
    private WxTemplateDao wxTemplateDao;
    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    //====================微信与租户管理=======================
    public MixEnvelop getWxWechatList(String name,String saasName,Integer status,Integer publicType,Integer page,Integer size){
@ -91,7 +110,7 @@ public class WechatService {
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success, list, page, size, count);
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
    }
    public List<WxSaasVO> getWxSaasVOs(String id){
@ -106,4 +125,335 @@ public class WechatService {
        List<WxSaasVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxSaasVO.class));
        return list;
    }
    public Envelop saveWxAndSaas(WxWechatDO wxWechatDO, List<WxWechatSaasDO> wxWechatSaasDOs){
        String uuid = UUID.randomUUID().toString();
        wxWechatDO.setId(uuid);
        wechatDao.save(wxWechatDO);
        if(wxWechatSaasDOs!=null&&wxWechatSaasDOs.size()>0){
            for(WxWechatSaasDO wxs:wxWechatSaasDOs){
                wxs.setWechatId(uuid);
            }
            wxWechatSaasDao.save(wxWechatSaasDOs);
        }
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public Envelop updateWxAndSaas(WxWechatDO wxWechatDO, List<WxWechatSaasDO> wxWechatSaasDOs) {
        wechatDao.save(wxWechatDO);
        List<WxWechatSaasDO> ws = wxWechatSaasDao.findByWechatId(wxWechatDO.getId());
        wxWechatSaasDao.delete(ws);
        if(wxWechatSaasDOs!=null&&wxWechatSaasDOs.size()>0){
            for(WxWechatSaasDO wxs:wxWechatSaasDOs){
                wxs.setWechatId(wxWechatDO.getId());
            }
            wxWechatSaasDao.save(wxWechatSaasDOs);
        }
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    //====================微信与租户管理end=======================
    //====================图文素材管理============================
    public MixEnvelop findWechatCombo(){
        String sql ="SELECT t.id,t.`name`,t.app_origin_id AS appOriginId from wx_wechat t";
        List<WxComboVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxComboVO.class));
        return MixEnvelop.getSuccessList(BaseRequestMapping.WeChat.api_success,list);
    }
    public MixEnvelop findWechatImgGroup(String wechatId,Integer page,Integer size){
        String totalSql ="SELECT COUNT(1) AS total from wx_graphic_scene g WHERE g.wechat_id ='"+wechatId+"'";
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
                " g.id,g.wechat_id AS wechatId,g.scene " +
                " FROM " +
                " wx_graphic_scene g " +
                " WHERE " +
                " g.wechat_id = '"+wechatId+"' " +
                " LIMIT  " + (page - 1) * size + "," + size + "";
        List<WxGraphicSceneVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxGraphicSceneVO.class));
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
    }
    public Envelop createImgGroup(WxGraphicSceneDO wxGraphicSceneDO){
        wxGraphicSceneDao.save(wxGraphicSceneDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public Envelop updateImgGroup(String id,String scene){
        WxGraphicSceneDO wxGraphicSceneDO = wxGraphicSceneDao.findOne(id);
        List<WxGraphicSceneGroupDO> list = wxGraphicSceneGroupDao.findByWechatIdAndScene(wxGraphicSceneDO.getWechatId(),wxGraphicSceneDO.getScene());
        if(list!=null&&list.size()>0){
            for(WxGraphicSceneGroupDO group:list){
                group.setScene(scene);
            }
            wxGraphicSceneGroupDao.save(list);
        }
        wxGraphicSceneDO.setScene(scene);
        wxGraphicSceneDao.save(wxGraphicSceneDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public Envelop deleteImgGroup(String id){
        WxGraphicSceneDO wxGraphicSceneDO = wxGraphicSceneDao.findOne(id);
        List<WxGraphicSceneGroupDO> list = wxGraphicSceneGroupDao.findByWechatIdAndScene(wxGraphicSceneDO.getWechatId(),wxGraphicSceneDO.getScene());
        if(list!=null&&list.size()>0){
            wxGraphicSceneGroupDao.delete(list);
        }
        wxGraphicSceneDao.delete(wxGraphicSceneDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public Envelop saveImg(WxGraphicMessageDO wxGraphicMessageDO){
        wxGraphicMessageDao.save(wxGraphicMessageDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public MixEnvelop findImg(String wechatId,String title,String scene,Integer page,Integer size){
        String sqlTotal = "SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wx_graphic_message m ";
                if(StringUtils.isNotBlank(scene)){
                    sqlTotal+= " JOIN wx_graphic_scene_group g ON g.graphic_id = m.id ";
                }
        sqlTotal+= " WHERE " +
                " m.wechat_id = '"+wechatId+"' " +
                " m.status =1" ;
                if(StringUtils.isNotBlank(title)){
                    sqlTotal += " AND m.title LIKE '%"+title+"%' " ;
                }
                if(StringUtils.isNotBlank(scene)){
                    sqlTotal+= "AND g.scene = '"+scene+"'";
                }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(sqlTotal);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
                " m.id, " +
                " m.wechat_id AS wechatId, " +
                " m.`code` AS code, " +
                " m.title, " +
                " m.description, " +
                " m.url, " +
                " m.pic_url AS picUrl, " +
                " m.remark, " +
                " m.`status` " +
                " FROM " +
                " wx_graphic_message m ";
        if(StringUtils.isNotBlank(scene)){
            sql+= " JOIN wx_graphic_scene_group g ON g.graphic_id = m.id ";
        }
        sql+=" WHERE m.wechat_id = '"+wechatId+"' " +
                " m.status =1" ;
        if(StringUtils.isNotBlank(title)){
            sql += " AND m.title LIKE '%"+title+"%' " ;
        }
        if(StringUtils.isNotBlank(scene)){
            sql+= "AND g.scene = '"+scene+"'";
        }
        sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
        List<WxGraphicMessageVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxGraphicMessageVO.class));
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
    }
    public Envelop saveImgGroup(List<WxGraphicSceneGroupDO> groups){
        List<WxGraphicSceneGroupDO> gs = wxGraphicSceneGroupDao.findByWechatIdAndScene(groups.get(0).getWechatId(),groups.get(0).getScene());
        if(gs!=null&&gs.size()>0){
            wxGraphicSceneGroupDao.delete(gs);
        }
        wxGraphicSceneGroupDao.save(groups);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public Envelop saveWxReplyScene(WxReplySceneDO wxReplySceneDO){
        wxReplySceneDao.save(wxReplySceneDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public MixEnvelop findWxReplyScene(String wechatId,String msgType,String event,String content,Integer page,Integer size){
        String totalSql = "SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wx_reply_scene s " +
                " WHERE " +
                " s.wechat_id = '"+wechatId+"'";
        if(StringUtils.isNotBlank(msgType)){
            totalSql += " AND s.msg_type ='"+msgType+"'";
        }
        if(StringUtils.isNotBlank(event)){
            totalSql += " AND s.event ='"+event+"'";
        }
        if(StringUtils.isNotBlank(content)){
            totalSql += " AND s.content like '%"+content+"%'";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
                " s.wechat_id AS wechatId," +
                " s.scene, " +
                " s.`status`, " +
                " s.id, " +
                " s.content, " +
                " s.app_origin_id AS appOriginId, " +
                " s.`event`, " +
                " s.msg_type AS msgType" +
                " FROM " +
                " wx_reply_scene s " +
                " WHERE " +
                " s.wechat_id = '"+wechatId+"'";
        if(StringUtils.isNotBlank(msgType)){
            sql += " AND s.msg_type ='"+msgType+"'";
        }
        if(StringUtils.isNotBlank(event)){
            sql += " AND s.event ='"+event+"'";
        }
        if(StringUtils.isNotBlank(content)){
            sql += " AND s.content like '%"+content+"%'";
        }
        sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
        List<WxReplySceneVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxReplySceneVO.class));
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
    }
    //===================图文素材管理end====================================
    //===================模板消息==========================================
    public Envelop saveWxTemp(WxTemplateDO wxTemplateDO){
        wxTemplateDao.save(wxTemplateDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public MixEnvelop findWxtemp(String wechatId,Integer status,String name,String key,Integer page,Integer size){
        String totalSql = "SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wx_template t" +
                " WHERE t.wechat_id= '"+wechatId+"' ";
        if(status!=null){
            totalSql+= " AND t.status = "+ status;
        }
        if(StringUtils.isNotBlank(name)){
            totalSql+= " AND t.template_name ='"+name+"'";
        }
        if(StringUtils.isNotBlank(key)){
            totalSql+= " AND (t.template_id ='"+key+"' OR t.title like'%"+key+"%')";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
                " t.id, " +
                " t.title, " +
                " t.wechat_id AS wechatId, " +
                " t.template_id AS templateId, " +
                " t.template_name AS templateName, " +
                " t.content, " +
                " t.`status` " +
                " FROM " +
                " wx_template t" +
                " WHERE t.wechat_id= '"+wechatId+"' ";
        if(status!=null){
            sql+= " AND t.status = "+ status;
        }
        if(StringUtils.isNotBlank(name)){
            sql+= " AND t.template_name ='"+name+"'";
        }
        if(StringUtils.isNotBlank(key)){
            sql+= " AND (t.template_id ='"+key+"' OR t.title like'%"+key+"%')";
        }
        sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
        List<WxTemplateVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxTemplateVO.class));
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
    }
    public Envelop saveWxTempConfig(WxTemplateConfigDO wxTemplateConfigDO){
        wxTemplateConfigDao.save(wxTemplateConfigDO);
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public MixEnvelop findWxTempConfigList(String wechatId,String scene,Integer page,Integer size){
        String totalSql ="SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wx_template_config g " +
                " WHERE " +
                " g.wechat_id ='"+wechatId+"'";
        if(StringUtils.isNotBlank(scene)){
            totalSql += " AND g.scene = '"+scene+"'";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql ="SELECT " +
                " g.id, " +
                " g.wechat_id AS wechatId, " +
                " g.template_id AS templateId, " +
                " g.template_name AS template_name, " +
                " g.scene, " +
                " g.scene_description AS sceneDescription, " +
                " g.`first`, " +
                " g.url, " +
                " g.remark, " +
                " g.keyword1, " +
                " g.keyword2, " +
                " g.keyword3, " +
                " g.keyword4, " +
                " g.keyword5, " +
                " g.keyword6, " +
                " g.keyword7, " +
                " g.create_time AS createTime, " +
                " g.create_user AS createUser, " +
                " g.create_user_name AS createUserName, " +
                " g.update_time AS updateTime, " +
                " g.update_user AS updateUser, " +
                " g.update_user_name AS updateUserName " +
                " FROM " +
                " wx_template_config g " +
                " WHERE " +
                " g.wechat_id ='"+wechatId+"'";
        if(StringUtils.isNotBlank(scene)){
            sql += " AND g.scene = '"+scene+"'";
        }
        sql+=" LIMIT  " + (page - 1) * size + "," + size + "";
        List<WxTemplateConfigVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WxTemplateConfigVO.class));
        return MixEnvelop.getSuccessListWithPage(BaseRequestMapping.WeChat.api_success, list, page, size, count);
    }
    public WxTemplateConfigDO findWxTemplateConfig(String wechatId,String name,String scene){
        WxTemplateConfigDO wxTemplateConfigDO =  wxTemplateConfigDao.findByWechatIdAndTemplateNameAndScene(wechatId,name,scene);
        return wxTemplateConfigDO;
    }
    //===================模板消息end=======================================
}

+ 1 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/util/ErrorCodeUtil.java

@ -21,6 +21,6 @@ public class ErrorCodeUtil {
     * @return
     */
    public String getErrorMsg(String errorCode){
        return redisTemplate.opsForValue().get(BaseErrorCode.PREFIX+errorCode);
        return redisTemplate.opsForValue().get(BaseErrorCode.PREFIX + errorCode);
    }
}

+ 79 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/DelayService.java

@ -0,0 +1,79 @@
package com.yihu.jw.base.util.delay;
import com.yihu.jw.base.util.threadPool.ThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.DelayQueue;
/**
 * @author yeshijie on 2018/9/29.
 */
@Component
public class DelayService {
    private final Logger log = LoggerFactory.getLogger(DelayService.class);
    @Autowired
    private ThreadPoolUtil threadPoolUtil;
    private boolean start;
    private OnDelayedListener listener;
    public DelayQueue<Notice> delayQueue = new DelayQueue<Notice>();
    public void start(OnDelayedListener listener) {
        if (start) {
            return;
        }
        log.info("DelayService 启动");
        start = true;
        this.listener = listener;
        threadPoolUtil.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    while (true) {
                        Notice notice = delayQueue.take();
                        if (DelayService.this.listener != null) {
                            DelayService.this.listener.onDelayedArrived(notice);
                        }
                        log.info("执行任务+"+notice.getNoticeId()+","+notice.getStartTime());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    public void add(Notice notice) {
        delayQueue.put(notice);
    }
    public boolean remove(Notice notice) {
        return delayQueue.remove(notice);
    }
    public void add(String noticeId,long startTime) {
        delayQueue.put(new Notice(noticeId, startTime));
    }
    public void remove(String noticeId) {
        Notice[] array = delayQueue.toArray(new Notice[]{});
        if (array == null || array.length <= 0) {
            return;
        }
        Notice target = null;
        for (Notice notice : array) {
            if (notice.getNoticeId().equals(noticeId)) {
                target = notice;
                break;
            }
        }
        if (target != null) {
            delayQueue.remove(target);
        }
    }
}

+ 53 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/Notice.java

@ -0,0 +1,53 @@
package com.yihu.jw.base.util.delay;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
/**
 * 消息公告的延迟队列
 * @author yeshijie on 2018/10/9.
 */
public class Notice implements Delayed {
    private String noticeId;
    private long startTime;
    public Notice(String noticeId, long timeout){
        this.noticeId = noticeId;
        this.startTime = timeout;
    }
    @Override
    public int compareTo(Delayed other) {
        if (other == this) {
            return 0;
        }
        if (other instanceof Notice) {
            Notice otherRequest = (Notice) other;
            long otherStartTime = otherRequest.getStartTime();
            return (int) (this.startTime - otherStartTime);
        }
        return 0;
    }
    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(startTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }
    public String getNoticeId() {
        return noticeId;
    }
    public void setNoticeId(String noticeId) {
        this.noticeId = noticeId;
    }
    public long getStartTime() {
        return startTime;
    }
    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }
}

+ 12 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/OnDelayedListener.java

@ -0,0 +1,12 @@
package com.yihu.jw.base.util.delay;
/**
 * @author yeshijie on 2018/10/9.
 */
public interface OnDelayedListener {
    /**
     * 延迟时间到了,执行处理订单
     * @param notice
     */
    void onDelayedArrived(Notice notice);
}

+ 196 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/util/delay/RedisLock.java

@ -0,0 +1,196 @@
package com.yihu.jw.base.util.delay;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.util.concurrent.TimeUnit;
/**
 * @author yeshijie on 2018/10/9.
 */
public class RedisLock {
    private static Logger logger = LoggerFactory.getLogger(RedisLock.class);
    private RedisTemplate redisTemplate;
    private static final int DEFAULT_ACQUIRY_RESOLUTION_MILLIS = 100;
    /**
     * Lock key path.
     */
    private String lockKey;
    /**
     * 锁超时时间,防止线程在入锁以后,无限的执行等待
     */
    private int expireMsecs = 60 * 1000;
    /**
     * 锁等待时间,防止线程饥饿
     */
    private int timeoutMsecs = 10 * 1000;
    private volatile boolean locked = false;
    /**
     * Detailed constructor with default acquire timeout 10000 msecs and lock expiration of 60000 msecs.
     *
     * @param lockKey lock key (ex. account:1, ...)
     */
    public RedisLock(RedisTemplate redisTemplate, String lockKey) {
        this.redisTemplate = redisTemplate;
        this.lockKey = lockKey + "_lock";
    }
    /**
     * Detailed constructor with default lock expiration of 60000 msecs.
     *
     */
    public RedisLock(RedisTemplate redisTemplate, String lockKey, int timeoutMsecs) {
        this(redisTemplate, lockKey);
        this.timeoutMsecs = timeoutMsecs;
    }
    /**
     * Detailed constructor.
     *
     */
    public RedisLock(RedisTemplate redisTemplate, String lockKey, int timeoutMsecs, int expireMsecs) {
        this(redisTemplate, lockKey, timeoutMsecs);
        this.expireMsecs = expireMsecs;
    }
    /**
     * @return lock key
     */
    public String getLockKey() {
        return lockKey;
    }
    private String get(final String key) {
        Object obj = null;
        try {
            obj = redisTemplate.execute(new RedisCallback<Object>() {
                @Override
                public Object doInRedis(RedisConnection connection) throws DataAccessException {
                    StringRedisSerializer serializer = new StringRedisSerializer();
                    byte[] data = connection.get(serializer.serialize(key));
                    connection.close();
                    if (data == null) {
                        return null;
                    }
                    return serializer.deserialize(data);
                }
            });
        } catch (Exception e) {
            logger.error("get redis error, key : {}", key);
        }
        return obj != null ? obj.toString() : null;
    }
    private boolean setNX(final String key, final String value) {
        Object obj = null;
        try {
            obj = redisTemplate.execute(new RedisCallback<Object>() {
                @Override
                public Object doInRedis(RedisConnection connection) throws DataAccessException {
                    StringRedisSerializer serializer = new StringRedisSerializer();
                    Boolean success = connection.setNX(serializer.serialize(key), serializer.serialize(value));
                    connection.close();
                    return success;
                }
            });
        } catch (Exception e) {
            logger.error("setNX redis error, key : {}", key);
        }
        return obj != null ? (Boolean) obj : false;
    }
    private String getSet(final String key, final String value) {
        Object obj = null;
        try {
            obj = redisTemplate.execute(new RedisCallback<Object>() {
                @Override
                public Object doInRedis(RedisConnection connection) throws DataAccessException {
                    StringRedisSerializer serializer = new StringRedisSerializer();
                    byte[] ret = connection.getSet(serializer.serialize(key), serializer.serialize(value));
                    connection.close();
                    return serializer.deserialize(ret);
                }
            });
        } catch (Exception e) {
            logger.error("setNX redis error, key : {}", key);
        }
        return obj != null ? (String) obj : null;
    }
    /**
     * 获得 lock.
     * 实现思路: 主要是使用了redis 的setnx命令,缓存了锁.
     * reids缓存的key是锁的key,所有的共享, value是锁的到期时间(注意:这里把过期时间放在value了,没有时间上设置其超时时间)
     * 执行过程:
     * 1.通过setnx尝试设置某个key的值,成功(当前没有这个锁)则返回,成功获得锁
     * 2.锁已经存在则获取锁的到期时间,和当前时间比较,超时的话,则设置新的值
     *
     * @return true if lock is acquired, false acquire timeouted
     * @throws InterruptedException in case of thread interruption
     */
    public synchronized boolean lock() throws InterruptedException {
        int timeout = timeoutMsecs;
        while (timeout >= 0) {
            long expires = System.currentTimeMillis() + expireMsecs + 1;
            //锁到期时间
            String expiresStr = String.valueOf(expires);
            if (this.setNX(lockKey, expiresStr)) {
                // lock acquired
                locked = true;
                return true;
            }
            //redis里的时间
            String currentValueStr = this.get(lockKey);
            if (currentValueStr != null && Long.parseLong(currentValueStr) < System.currentTimeMillis()) {
                //判断是否为空,不为空的情况下,如果被其他线程设置了值,则第二个条件判断是过不去的
                // lock is expired
                String oldValueStr = this.getSet(lockKey, expiresStr);
                //获取上一个锁到期时间,并设置现在的锁到期时间,
                //只有一个线程才能获取上一个线上的设置时间,因为jedis.getSet是同步的
                if (oldValueStr != null && oldValueStr.equals(currentValueStr)) {
                    //防止误删(覆盖,因为key是相同的)了他人的锁——这里达不到效果,这里值会被覆盖,但是因为什么相差了很少的时间,所以可以接受
                    //[分布式的情况下]:如过这个时候,多个线程恰好都到了这里,但是只有一个线程的设置值和当前值相同,他才有权利获取锁
                    // lock acquired
                    locked = true;
                    return true;
                }
            }
            timeout -= DEFAULT_ACQUIRY_RESOLUTION_MILLIS;
            /*
                延迟100 毫秒,  这里使用随机时间可能会好一点,可以防止饥饿进程的出现,即,当同时到达多个进程,
                只会有一个进程获得锁,其他的都用同样的频率进行尝试,后面有来了一些进行,也以同样的频率申请锁,这将可能导致前面来的锁得不到满足.
                使用随机的等待时间可以一定程度上保证公平性
             */
            TimeUnit.MILLISECONDS.sleep(DEFAULT_ACQUIRY_RESOLUTION_MILLIS);
        }
        return false;
    }
    /**
     * Acqurired lock release.
     */
    public synchronized void unlock() {
        if (locked) {
            redisTemplate.delete(lockKey);
            locked = false;
        }
    }
}

+ 59 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/util/threadPool/ThreadPool.java

@ -0,0 +1,59 @@
package com.yihu.jw.base.util.threadPool;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
 * @author yeshijie on 2018/10/10.
 */
@Configuration
public class ThreadPool {
    /**
     * 线程池核心线程数
     */
    private int CORE_POOL_SIZE = 5;
    /**
     * 线程池最大线程数
     */
    private int MAX_POOL_SIZE = 100;
    /**
     * 额外线程空状态生存时间
     */
    private int KEEP_ALIVE_TIME = 10000;
    /**
     * 额外线程空状态生存时间单位秒
     */
    private TimeUnit unit = TimeUnit.SECONDS;
    /**
     * 阻塞队列。当核心线程都被占用,且阻塞队列已满的情况下,才会开启额外线程。
     */
    private BlockingQueue workQueue = new ArrayBlockingQueue(10);
    /**
     * 线程池对拒绝任务(无线程可用)的处理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,调用者的线程会执行该任务,如果执行器已关闭,则丢弃.
     */
    private RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.AbortPolicy();
    /**
     * 线程工厂
     */
    private ThreadFactory threadFactory = new ThreadFactory() {
        private final AtomicInteger integer = new AtomicInteger();
        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "myThreadPool thread:" + integer.getAndIncrement());
        }
    };
    @Bean
    ThreadPoolUtil threadPoolUtil(){
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME,
                unit, workQueue, threadFactory ,rejectedExecutionHandler);
        ThreadPoolUtil threadPoolUtil = new ThreadPoolUtil(threadPool);
        return threadPoolUtil;
    }
}

+ 32 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/util/threadPool/ThreadPoolUtil.java

@ -0,0 +1,32 @@
package com.yihu.jw.base.util.threadPool;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
/**
 * @author yeshijie on 2018/9/30.
 */
public class ThreadPoolUtil {
    /**
     * 线程池
     */
    private ThreadPoolExecutor threadPool;
    public ThreadPoolUtil(ThreadPoolExecutor threadPool) {
        this.threadPool = threadPool;
    }
    public void execute(Runnable runnable) {
        threadPool.execute(runnable);
    }
    public void execute(FutureTask futureTask) {
        threadPool.execute(futureTask);
    }
    public void cancel(FutureTask futureTask) {
        futureTask.cancel(true);
    }
}

+ 2 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/constant/LoginInfo.java

@ -17,6 +17,8 @@ public class LoginInfo {
    //用户创建
    public static final String SAVE_TYPE_IJK = "ijkLogin";  //i健康登录注册
    public static final String SAVE_TYPE_PHONE = "phoneLogin";//手机登录注册
    public static final String SAVE_TYPE_IDCARDNO= "idCardNoLogin";  //身份证登录注册
    //用户类型
    public static final String USER_TYPE_PATIENT = "patient";//居民

+ 35 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/LoginController.java

@ -127,6 +127,41 @@ public class LoginController extends EnvelopRestEndpoint {
        }
    }
    @PostMapping("/idCard/register")
    @ApiOperation(value = "【普通用户】-身份证认证注册")
    public Envelop idCardNoRegister(
            HttpServletRequest request,
            @ApiParam(name = "name", value = "用户姓名", required = true) @RequestParam(required = true, name = "name") String name,
            @ApiParam(name = "idCardNo", value = "身份证号码", required = true) @RequestParam(required = true, name = "idCardNo") String idCardNo) {
        try {
            loginService.idCardRegister(request,name, idCardNo);
        } catch (ManageException e) {
            return failed(e.getMessage());
        }
        return success("用户认证完成!");
    }
    @PostMapping("/idCard/login")
    @ApiOperation(value = "【普通用户】-身份证登录")
    public Envelop idCardLogin(
            HttpServletRequest request,
            @ApiParam(name = "username", value = "账号", required = true) @RequestParam(required = true, name = "username") String username,
            @ApiParam(name = "password", value = "密码", required = true) @RequestParam(required = true, name = "password") String password) {
        User user = null;
        try {
            user = loginService.idCardlogin(request, username, password);
        } catch (ManageException e) {
            failed(e.getMessage());
        }
        if (user != null) {
            return success("登录成功", user);
        } else {
            return failed("登录失败");
        }
    }
    @PostMapping("/loginout")
    @ApiOperation(value = "登出")
    public Envelop loginout(

+ 2 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/facilities/FacilitiesController.java

@ -462,7 +462,7 @@ public class FacilitiesController extends EnvelopRestEndpoint {
    @PostMapping(value = "/demoImport")
    @ApiOperation(value = "模拟导入设施")
    @ApiOperation(value = "导入设施列表临时接口")
    public Envelop demoImport(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestPart(value = "file") MultipartFile file,
@ -474,6 +474,7 @@ public class FacilitiesController extends EnvelopRestEndpoint {
            List<Map<String,String>> dataList = excelReader.getCorrectLs();
            if (dataList.size() > 0) {
                //TODO 导入
                facilityService.batchInsertDemo(dataList);
                System.out.println(dataList);
                return success("导入成功!");
            }

+ 3 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/FacilityUsedRecordController.java

@ -229,7 +229,9 @@ public class FacilityUsedRecordController extends EnvelopRestEndpoint {
            }
            //根据设施编码获取 设施状态
            Facility facility = facilityService.findByCode(facilityCode);
            record.setFacilitieStatus(facility.getStatus());
            if (facility!=null) {
                record.setFacilitieStatus(facility.getStatus());
            }
        }
        int count = (int) facilityUsedRecordService.getCount(filters);
        return success(facilityUsedRecordList, count, page, size);

+ 6 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/facility/FacilityServerDao.java

@ -3,6 +3,8 @@ package com.yihu.jw.healthyhouse.dao.facility;
import com.yihu.jw.healthyhouse.model.facility.FacilityServer;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
 * 设施服务dao
 * @author zdm
@ -12,5 +14,9 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface FacilityServerDao extends JpaRepository<FacilityServer, Long> {
    FacilityServer findById(String id);
    FacilityServer findByCode(String code);
    List<FacilityServer> findByNameIn(List<String> name);
}

+ 32 - 20
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/interceptor/ActivatedInterceptor.java

@ -37,13 +37,14 @@ import java.util.HashMap;
import java.util.Map;
/**
 *  用户在线状态验证拦截器
 * 用户在线状态验证拦截器
 *
 * @author HZY
 * @created 2018/10/9 9:19
 */
//@Aspect
//@Component
public class ActivatedInterceptor  {
@Aspect
@Component
public class ActivatedInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(ActivatedInterceptor.class);
@ -87,34 +88,45 @@ public class ActivatedInterceptor  {
    @Around("execution(* com.yihu.jw.healthyhouse.controller..*.*(..))")
    public Object activatedAround(ProceedingJoinPoint  joinPoint) throws Throwable{
    public Object activatedAround(ProceedingJoinPoint joinPoint) throws Throwable {
        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes sra = (ServletRequestAttributes) ra;
        HttpServletRequest request = sra.getRequest();
        HttpServletResponse response = sra.getResponse();
        String requestUri = request.getRequestURI();
        String contextPath = request.getContextPath();
        if (requestUri.indexOf("/login") != -1
                || requestUri.indexOf("/register") != -1
                || requestUri.indexOf("/loginout") != -1
                || requestUri.indexOf("/getRandomImageCode") != -1
                || requestUri.indexOf("/checkRandomImageCode") != -1
                || requestUri.indexOf("/captcha") != -1
                || requestUri.indexOf("swagger") != -1
                || requestUri.indexOf(contextPath + "/v2/api-docs") != -1) {
            return joinPoint.proceed();
        }
        HttpSession session = request.getSession();
        Object userId = session.getAttribute(LoginInfo.USER_ID);
        if (userId == null ){
        String userId = request.getHeader("userId");
        System.out.println(userId);
        if (userId == null) {
            response.setStatus(402);
            return  joinPoint.proceed();
            return joinPoint.proceed();
//            return failed("用户未登录,请登录!",-10000);
        }
        User user = userService.findById(userId.toString());
        if (user == null ){
        User user = userService.findById(userId);
        if (user == null) {
            response.setStatus(402);
            return  joinPoint.proceed();
            return joinPoint.proceed();
//            return failed("用户不存在,请重新登录!",-10000);
        }else if (HouseUserContant.activated_lock.equals(user.getActivated())){
            response.setStatus(402);
        } else if (HouseUserContant.activated_lock.equals(user.getActivated())) {
            response.setStatus(103);
//           return failed("用户已被冻结,请联系管理员!",-10000);
        }else if (HouseUserContant.activated_offline.equals(user.getActivated())){
        } else if (HouseUserContant.activated_offline.equals(user.getActivated())) {
            response.setStatus(402);
//            return failed("用户已离线,请重新登录!",-10000);
        }else {
//            return  joinPoint.proceed();
        }
        return  joinPoint.proceed();
        return joinPoint.proceed();
    }
@ -144,8 +156,7 @@ public class ActivatedInterceptor  {
    }
    protected Envelop failed (String message, int status) {
    protected Envelop failed(String message, int status) {
        Envelop envelop = new Envelop();
        envelop.setMessage(message);
        envelop.setStatus(status);
@ -154,4 +165,5 @@ public class ActivatedInterceptor  {
}

+ 2 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/job/ActivatedUserUpdateTask.java

@ -21,7 +21,7 @@ import java.util.*;
 * Task - 定时检查集群状态,提高解析任务容错率
 * Created by progr1mmer on 2017/12/15.
 */
//@Component
@Component
public class ActivatedUserUpdateTask {
    @Autowired
@ -29,7 +29,7 @@ public class ActivatedUserUpdateTask {
    @Autowired
    private UserService userService;
    @Scheduled(cron = "0/40 * * * * ?")
    @Scheduled(cron = "0/30 * * * * ?")
    private void startTask() {
        List<String> keys = new ArrayList<>();
        String pattern = "healthyHouse:*:activated";

+ 19 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/facility/FacilityServerService.java

@ -31,5 +31,24 @@ public class FacilityServerService extends BaseJpaService<FacilityServer, Facili
        return  facilityServerDao.findById(id);
    }
    public List<FacilityServer> findByNameIn (List<String> names) {
       return facilityServerDao.findByNameIn(names);
    }
    /**
     * 设施服务编码生成
     *
     * @return
     */
    public String genFacilityServerCode() {
        String code = "HFHS" + randomString(5);
        FacilityServer facility = facilityServerDao.findByCode(code);
        while (facility != null) {
            code = "HFHS" + randomString(5);
            facility = facilityServerDao.findByCode(code);
        }
        return code;
    }
}

+ 61 - 21
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/facility/FacilityService.java

@ -1,15 +1,19 @@
package com.yihu.jw.healthyhouse.service.facility;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.healthyhouse.dao.facility.FacilityDao;
import com.yihu.jw.healthyhouse.dao.facility.FacilityServerRelationDao;
import com.yihu.jw.healthyhouse.model.facility.Facility;
import com.yihu.jw.healthyhouse.model.facility.FacilityServer;
import com.yihu.jw.healthyhouse.model.facility.FacilityServerRelation;
import com.yihu.jw.healthyhouse.service.area.BaseCityService;
import com.yihu.jw.healthyhouse.service.area.BaseTownService;
import com.yihu.jw.healthyhouse.service.dict.SystemDictEntryService;
import com.yihu.jw.healthyhouse.util.RestTemplateUtil;
import com.yihu.jw.healthyhouse.util.facility.msg.FacilityMsg;
import com.yihu.jw.healthyhouse.util.poi.ExcelUtils;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.util.http.HTTPResponse;
import com.yihu.jw.util.http.HttpClientKit;
import com.yihu.mysql.query.BaseJpaService;
import jxl.write.Colour;
import jxl.write.WritableCellFormat;
@ -19,20 +23,15 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * 设施管理器.
@ -53,6 +52,10 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
    private BaseTownService baseTownService;
    @Autowired
    private SystemDictEntryService systemDictEntryService;
    @Autowired
    private FacilityServerService facilityServerService;
    @Autowired
    private FacilityServerRelationDao facilityServerRelationDao;
@ -110,10 +113,6 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
            response.setHeader("Content-Disposition", "attachment; filename="
                    + new String(fileName.getBytes("gb2312"), "ISO8859-1") + ".xlsx");
            OutputStream os = response.getOutputStream();
            //获取导出数据集
            JSONObject order = new JSONObject();
            order.put("id", "asc");
            //写excel
            Workbook workbook = new XSSFWorkbook();
            int k = 0;
@ -285,11 +284,12 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
    /**
     *  //TODO 临时方法
     * 批量导入设施的集合
     *
     * @param facilities 设施列表
     */
    public Map<String, Object> batchInsertDemo(List<Map<String,String> > facilities) throws ManageException {
    public Map<String, Object> batchInsertDemo(List<Map<String,String> > facilities) throws ManageException, IOException {
        Map<String, Object> result = new HashMap<>();
        //批量存储的集合
        int correctCount = 0;
@ -316,8 +316,33 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
                facility.setAddress(facilityMsg.get("address"));
            }
            facility.setStatus("0");
            facility.setDeleteFlag("0");
            getLatAndlon(facility);//获取经纬度
            //已添加过的经纬度不再次导入
            if (isHasFacility(facility.getLongitude(), facility.getLatitude())) {
                errors.add(facility);
            } else {
                //获取设施服务
                String servies = facilityMsg.get("service");
                String[] serviceArr= servies.split("、");
                List<FacilityServer> facilityServers = facilityServerService.findByNameIn(Arrays.asList(serviceArr));
                if (facilities!=null ){
                    List<FacilityServerRelation> relations = new ArrayList<>();
                    for (FacilityServer facilityServer : facilityServers) {
                        //遍历添加设施项目
                        FacilityServerRelation relation = new FacilityServerRelation();
                        relation.setFacilitieCode(facility.getCode());
                        relation.setFacilitieName(facility.getName());
                        relation.setServiceCode(facilityServer.getCode());
                        relation.setServiceName(facilityServer.getName());
                        relation.setServiceName(facilityServer.getName());
                        relations.add(relation);
                    }
                    facilityServerRelationDao.save(relations);
                }
                corrects.add(facility);
            }
            if (corrects.size() > 100) {
                facilityDao.save(corrects);
@ -335,12 +360,27 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
        return result;
    }
    public Envelop getLatAndlon(String address) {
        Map<String ,String> map = new HashMap<>();
        String url = "http://api.map.baidu.com/geocoder/v2/?address="+ address + "&output=json&ak=465443b4e84fb6823359e5921915e8dc&callback=showLocation";
        RestTemplateUtil restTemplateUtil = new RestTemplateUtil(url,null);
        Envelop envelop = restTemplateUtil.exchange(url, HttpMethod.GET, Envelop.class,map);
        return envelop;
    /**
     *  //TODO  临时方法
     * 获取经纬度
     * @param facility
     * @throws IOException
     */
    public void getLatAndlon(Facility facility) throws IOException {
        String url = "http://api.map.baidu.com/geocoder/v2/?address="+ facility.getAddress() + "&output=json&ak=465443b4e84fb6823359e5921915e8dc";
        HTTPResponse httpResponse = HttpClientKit.get(url);
        if (httpResponse.getStatusCode() == 200) {
            String result = httpResponse.getBody();
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String,Object> map = objectMapper.readValue(result,Map.class);
            Map result1 = (Map) map.get("result");
            Map<String,Double> location = (Map<String, Double>) result1.get("location");
            facility.setLatitude(location.get("lat"));
            facility.setLongitude(location.get("lng"));
            System.out.println(result);
        }
    }
}

+ 65 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/LoginService.java

@ -8,6 +8,7 @@ import com.yihu.jw.healthyhouse.constant.LoginInfo;
import com.yihu.jw.healthyhouse.constant.UserConstant;
import com.yihu.jw.healthyhouse.model.user.User;
import com.yihu.jw.restmodel.wlyy.HouseUserContant;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.security.MD5;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
@ -328,4 +329,68 @@ public class LoginService  extends BaseJpaService {
    }
    /**
     *  //TODO 体验版本方法,后续可能删除
     * 身份证登录
     *
     * @param loginCode
     * @param password
     * @return
     * @throws Exception
     */
    @Transactional(noRollbackForClassName = "ManageException")
    public User idCardlogin(HttpServletRequest request, String loginCode, String password) throws ManageException {
        //判断登陆信息是否正确
        User user = userService.findByCode(loginCode);
        if (user == null) {
            String message = "账号不存在";
            throw new ManageException(message);
        }
        if (!user.getPassword().equals(MD5.GetMD5Code(password + user.getSalt()))) {
            String message = "密码错误";
            throw new ManageException(message);
        }
        request.getSession().setAttribute(LoginInfo.IS_LOGIN, true);
        request.getSession().setAttribute(LoginInfo.TOKEN, ""); //TODO token是否添加
        request.getSession().setAttribute(LoginInfo.LOGIN_NAME, user.getName());
        request.getSession().setAttribute(LoginInfo.USER_ID, user.getId());
        user.setActivated(HouseUserContant.activated_active);
        user.setLastLoginTime(new Date());
        user= userService.saveOrUpdate(user, LoginInfo.SAVE_TYPE_IDCARDNO);
        return user;
    }
    @Transactional(noRollbackForClassName = "ManageException")
    public User idCardRegister(HttpServletRequest request, String name, String idCardNo) throws ManageException {
        if(!IdCardUtil.cardCodeVerifySimple(idCardNo)){
            throw new ManageException("身份证号格式有误");
        }
        User user = userService.findByLoginCodeAndUserType(idCardNo,LoginInfo.USER_TYPE_PATIENT);
        if (user==null) {
            //新增账号
            user = new User();
            String password = idCardNo.substring(idCardNo.length()-6,idCardNo.length());
            user.setPassword(password);
            user.setLoginCode(idCardNo);
            user.setName(name);
            user.setIdCardNo(idCardNo);
            user.setUserType(LoginInfo.USER_TYPE_PATIENT);
        }
        // 更新身份证验证字段
        user.setRealnameAuthentication(UserConstant.AUTHORIZED);
        user.setName(name);
        request.getSession().setAttribute(LoginInfo.IS_LOGIN, true);
        request.getSession().setAttribute(LoginInfo.TOKEN, ""); //TODO token是否添加
        request.getSession().setAttribute(LoginInfo.LOGIN_NAME, user.getName());
        request.getSession().setAttribute(LoginInfo.USER_ID, user.getId());
        user.setActivated(HouseUserContant.activated_active);
        user.setLastLoginTime(new Date());
        user= userService.saveOrUpdate(user, LoginInfo.SAVE_TYPE_IDCARDNO);
        return user;
    }
}

+ 4 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/UserService.java

@ -195,6 +195,7 @@ public class UserService extends BaseJpaService<User, UserDao> {
     * @return
     * @throws ManageException
     */
    @Transactional
    public User saveOrUpdate(User user, String userCode) throws ManageException {
        User loginUser = userDao.findByLoginCode(userCode);
        if (user.getId() == null) {//保存
@ -463,7 +464,9 @@ public class UserService extends BaseJpaService<User, UserDao> {
     */
    @Transactional
    public void updateUserOffLine(List<Serializable> ids) throws ManageException {
        userDao.updateUserOnLine(ids);//更新在线
        if (ids!=null) {
            userDao.updateUserOnLine(ids);//更新在线
        }
        userDao.updateUserOffLine(ids);//更新离线
    }

+ 6 - 0
wlyy-parent-pom/pom.xml

@ -97,6 +97,7 @@
        <version.fastdfs>1.25</version.fastdfs>
        <version.poi>3.17</version.poi>
        <version.jxl>2.6.10</version.jxl>
        <version.okhttp>3.4.1</version.okhttp>
        <!-- Version end -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -298,6 +299,11 @@
                <artifactId>jxl</artifactId>
                <version>${version.jxl}</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>${version.okhttp}</version>
            </dependency>
            <!--   poi xml导入导出工具 end -->
            <!-- Zipkin 日志追踪 -->