Bläddra i källkod

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

huangzhiyong 6 år sedan
förälder
incheckning
77cb1dc52b
16 ändrade filer med 1366 tillägg och 104 borttagningar
  1. 36 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxGraphicSceneDO.java
  2. 37 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxWechatSaasDO.java
  3. 19 0
      common/common-exception/src/main/java/com/yihu/jw/exception/code/BaseErrorCode.java
  4. 30 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java
  5. 39 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxComboVO.java
  6. 40 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxGraphicSceneVO.java
  7. 79 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxReplySceneVO.java
  8. 263 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxTemplateConfigVO.java
  9. 51 60
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/wx/WxTemplateVO.java
  10. 11 14
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxGraphicMessageDao.java
  11. 11 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxGraphicSceneDao.java
  12. 20 20
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxTemplateDao.java
  13. 14 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/wx/WxWechatSaasDao.java
  14. 165 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/FileUploadController.java
  15. 196 5
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WechatController.java
  16. 355 5
      svr/svr-base/src/main/java/com/yihu/jw/base/service/wx/WechatService.java

+ 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;
    }
}

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

@ -84,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";
    }
    /**
     * 微信模块
     */

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

@ -170,6 +170,17 @@ public class BaseRequestMapping {
        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";
    }
    /**
     * 角色权限
     */
@ -184,7 +195,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";
    }
    /**

+ 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;
    }
}

+ 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);
    }
}

+ 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==========================================
}

+ 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=======================================
}