瀏覽代碼

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

# Conflicts:
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/ModuleController.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/SaasController.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/service/FunctionService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/service/ModuleFunService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/service/ModuleService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SaasService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SystemDictListService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SystemDictService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/sms/dao/SmsDao.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/sms/service/SmsService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/BaseRoleController.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/EmployController.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/BaseRoleDao.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/EmployDao.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/user/service/BaseRoleService.java
#	svr/svr-base/src/main/java/com/yihu/jw/business/user/service/EmployService.java
Progr1mmer 6 年之前
父節點
當前提交
c55e386a2a
共有 48 個文件被更改,包括 3141 次插入1748 次删除
  1. 56 0
      common/common-entity/src/main/java/com/yihu/jw/base/wx/WxGraphicSceneGroupDO.java
  2. 46 0
      common/common-entity/src/main/java/com/yihu/jw/base/wx/WxMenuJsonDO.java
  3. 86 0
      common/common-entity/src/main/java/com/yihu/jw/base/wx/WxReplySceneDO.java
  4. 7 26
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxGraphicMessageDO.java
  5. 10 1
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxTemplateDO.java
  6. 9 29
      common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxWechatDO.java
  7. 97 0
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/PatientRehabilitationPlanDO.java
  8. 118 0
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationDetailDO.java
  9. 66 0
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationPlanTemplateDO.java
  10. 47 0
      common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationTemplateDetailDO.java
  11. 48 0
      common/common-util/src/main/java/com/yihu/jw/util/wechat/WeiXinMessageReplyUtils.java
  12. 54 0
      common/common-util/src/main/java/com/yihu/jw/util/wechat/WeiXinMessageUtils.java
  13. 3 3
      svr/svr-base/src/main/java/com/yihu/jw/base/config/HibernateProperties.java
  14. 163 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/ModuleController.java
  15. 39 39
      svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/ModuleFunController.java
  16. 128 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/SaasController.java
  17. 6 6
      svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/SystemController.java
  18. 152 18
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/FunctionService.java
  19. 80 80
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/ModuleFunService.java
  20. 141 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/ModuleService.java
  21. 72 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SaasService.java
  22. 11 11
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SystemDictListService.java
  23. 11 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SystemDictService.java
  24. 32 32
      svr/svr-base/src/main/java/com/yihu/jw/business/demo/DemoController.java
  25. 18 18
      svr/svr-base/src/main/java/com/yihu/jw/business/sms/dao/SmsDao.java
  26. 178 170
      svr/svr-base/src/main/java/com/yihu/jw/business/sms/service/SmsService.java
  27. 49 49
      svr/svr-base/src/main/java/com/yihu/jw/business/sms/vo/SMSHttpVo.java
  28. 6 2
      svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/BaseRoleController.java
  29. 180 176
      svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/EmployController.java
  30. 11 11
      svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/BaseRoleDao.java
  31. 27 27
      svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/EmployDao.java
  32. 182 179
      svr/svr-base/src/main/java/com/yihu/jw/business/user/service/BaseRoleService.java
  33. 153 147
      svr/svr-base/src/main/java/com/yihu/jw/business/user/service/EmployService.java
  34. 183 0
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WechatCoreController.java
  35. 47 59
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WxMenuController.java
  36. 29 27
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WechatDao.java
  37. 17 17
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxAccessTokenDao.java
  38. 15 0
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxGraphicSceneGroupDao.java
  39. 20 47
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxMenuDao.java
  40. 13 0
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxMenuJsonDao.java
  41. 18 0
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxReplySceneDao.java
  42. 288 0
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WechatCoreService.java
  43. 13 114
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WechatService.java
  44. 151 96
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxAccessTokenService.java
  45. 50 357
      svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxMenuService.java
  46. 0 1
      svr/svr-base/src/main/resources/application.yml
  47. 5 0
      svr/svr-wlyy-specialist/pom.xml
  48. 6 6
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistService.java

+ 56 - 0
common/common-entity/src/main/java/com/yihu/jw/base/wx/WxGraphicSceneGroupDO.java

@ -0,0 +1,56 @@
package com.yihu.jw.base.wx;
import com.yihu.jw.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Trick on 2018/8/15.
 */
@Entity
@Table(name = "wx_graphic_scene_group")
public class WxGraphicSceneGroupDO extends IdEntity implements java.io.Serializable{
    private String wechatId;//微信Id
    private String scene;//场景值(根据场景值组装图文消息)
    private String graphicId;//场景关联微信图文素材id
    private Integer sort; //排序字段
    @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;
    }
    @Column(name = "graphic_id")
    public String getGraphicId() {
        return graphicId;
    }
    public void setGraphicId(String graphicId) {
        this.graphicId = graphicId;
    }
    @Column(name = "sort")
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
}

+ 46 - 0
common/common-entity/src/main/java/com/yihu/jw/base/wx/WxMenuJsonDO.java

@ -0,0 +1,46 @@
package com.yihu.jw.base.wx;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Trick on 2018/8/13.
 */
@Entity
@Table(name = "wx_menu_json")
public class WxMenuJsonDO extends IdEntityWithOperation implements java.io.Serializable{
    private String wechatId;//微信Id
    private String content;//'微信模板内容',
    private Integer status;//-1删除 0 冻结 1可用',
    @Column(name = "wechat_id")
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 86 - 0
common/common-entity/src/main/java/com/yihu/jw/base/wx/WxReplySceneDO.java

@ -0,0 +1,86 @@
package com.yihu.jw.base.wx;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Trick on 2018/8/15.
 */
@Entity
@Table(name = "wx_reply_scene")
public class WxReplySceneDO extends IdEntityWithOperation implements java.io.Serializable{
    private String wechatId;//微信id(唯一)
    private String appOriginId;//原始ID(唯一)
    private String msgType;//微信消息类型:text,event,image,voice,video,shortvideo,location,link
    private String event;//微信事件类型:SCAN,LOCATION,CLICK,subscribe,unsubscribe
    private String scene;//图文消息/自定义消息,分组场景
    private String content;//居民回复内容,消息字段
    private Integer status;//状态(-1删除 0 冻结 1可用
    @Column(name = "wechat_id")
    public String getWechatId() {
        return wechatId;
    }
    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }
    @Column(name = "app_origin_id")
    public String getAppOriginId() {
        return appOriginId;
    }
    public void setAppOriginId(String appOriginId) {
        this.appOriginId = appOriginId;
    }
    @Column(name = "msg_type")
    public String getMsgType() {
        return msgType;
    }
    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }
    @Column(name = "event")
    public String getEvent() {
        return event;
    }
    public void setEvent(String event) {
        this.event = event;
    }
    @Column(name = "scene")
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 7 - 26
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxGraphicMessageDO.java

@ -15,7 +15,7 @@ import java.util.Date;
@Table(name = "wx_graphic_message")
public class WxGraphicMessageDO extends UuidIdentityEntityWithOperator implements java.io.Serializable {
    private String saasId;
    private String code;
    private String title;//标题
    private String description;//描述
    private String url;//图文消息url值
@ -23,25 +23,6 @@ public class WxGraphicMessageDO extends UuidIdentityEntityWithOperator implement
    private String remark;//备注
    private Integer status;  //状态 -1删除 0 冻结 1可用
    public WxGraphicMessageDO() {
    }
    public WxGraphicMessageDO(String code, String title, String description, String url, String picUrl, String createUser, String createUserName, Date createTime, String updateUser, String updateUserName, Date updateTime, String remark, Integer status) {
        this.title = title;
        this.description = description;
        this.url = url;
        this.picUrl = picUrl;
        this.createUser = createUser;
        this.createUserName = createUserName;
        this.createTime = createTime;
        this.updateUser = updateUser;
        this.updateUserName = updateUserName;
        this.updateTime = updateTime;
        this.remark = remark;
        this.status = status;
    }
    @Column(name = "title", length = 200)
    public String getTitle() {
        return title;
@ -101,12 +82,12 @@ public class WxGraphicMessageDO extends UuidIdentityEntityWithOperator implement
        this.status = status;
    }
    @Column(name = "saas_id", length = 50)
    public String getSaasId() {
        return saasId;
    @Column(name = "code", length = 50)
    public String getCode() {
        return code;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    @Column(name = "code", length = 50)
    public void setCode(String code) {
        this.code = code;
    }
}

+ 10 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxTemplateDO.java

@ -20,6 +20,7 @@ public class WxTemplateDO extends UuidIdentityEntityWithOperator implements java
    @Transient
    private String wechatName;
    private String templateId;//微信模板id
    private String templateName;//模板名称(模板检索名称)
    private String content;//模板内容
    private String remark;
    private Integer status;  //状态 -1删除 0 冻结 1可用
@ -57,8 +58,16 @@ public class WxTemplateDO extends UuidIdentityEntityWithOperator implements java
        this.templateId = templateId;
    }
    @Column(name="content")
    @Column(name="template_name")
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    @Column(name="content")
    public String getContent() {
        return content;
    }

+ 9 - 29
common/common-entity/src/main/java/com/yihu/jw/entity/base/wx/WxWechatDO.java

@ -19,7 +19,6 @@ import java.util.Map;
public class WxWechatDO extends UuidIdentityEntityWithOperator implements java.io.Serializable {
    // Fields
    private String saasId;//'saas配置id'
    private String name;//名称
    private String token;//token
    private String encodingAesKey;//加密密钥
@ -28,6 +27,7 @@ public class WxWechatDO extends UuidIdentityEntityWithOperator implements java.i
    private String type;//'1:服务号 2 订阅号
    private String appId;//'微信app_id'
    private String appSecret;//'微信app_secret'
    private String appOriginId;//原始ID
    private String baseUrl;//'微信base_url'
    private String remark;//'备注'
@ -37,25 +37,6 @@ public class WxWechatDO extends UuidIdentityEntityWithOperator implements java.i
    @Transient
    private String state;
    public WxWechatDO(String code, String saasId, String name, String token, String encodingAesKey, Integer encType, Integer status, String type, String appId, String appSecret, String baseUrl, String createUser, String createUserName, Date createTime, String updateUser, String updateUserName, Date updateTime, String remark) {
        this.saasId = saasId;
        this.name = name;
        this.token = token;
        this.encodingAesKey = encodingAesKey;
        this.encType = encType;
        this.status = status;
        this.type = type;
        this.appId = appId;
        this.appSecret = appSecret;
        this.baseUrl = baseUrl;
        this.createUser = createUser;
        this.createUserName = createUserName;
        this.createTime = createTime;
        this.updateUser = updateUser;
        this.updateUserName = updateUserName;
        this.updateTime = updateTime;
        this.remark = remark;
    }
    /**
     * default constructor
     */
@ -98,15 +79,6 @@ public class WxWechatDO extends UuidIdentityEntityWithOperator implements java.i
        this.encodingAesKey = encodingAesKey;
    }
    @Column(name = "saas_id", length = 50)
    public String getSaasId() {
        return this.saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "name", length = 200)
    public String getName() {
        return this.name;
@ -152,6 +124,14 @@ public class WxWechatDO extends UuidIdentityEntityWithOperator implements java.i
        this.appSecret = appSecret;
    }
    @Column(name = "app_origin_id", length = 200)
    public String getAppOriginId() {
        return appOriginId;
    }
    public void setAppOriginId(String appOriginId) {
        this.appOriginId = appOriginId;
    }
    @Column(name = "base_url", length = 200)
    public String getBaseUrl() {
        return this.baseUrl;

+ 97 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/PatientRehabilitationPlanDO.java

@ -0,0 +1,97 @@
package com.yihu.jw.entity.specialist.rehabilitation;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by humingfen on 2018/8/10.
 */
@Entity
@Table(name = "wlyy_patient_rehabilitation_plan")
public class PatientRehabilitationPlanDO extends IdEntityWithOperation implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "patient")
    private String patient;//患者标识
    @Column(name = "name")
    private String name;//患者姓名
    @Column(name = "title")
    private String title;//康复服务套餐名称
    @Column(name = "payment")
    private Integer payment;//支付方式(1立即支付,2按服务支付)
    @Column(name = "total_expense")
    private Float totalExpense;//套餐总金额
    @Column(name = "plan_type")
    private Integer planType;//安排类型(1康复计划,2转社区医院,3转家庭病床)
    @Column(name = "service_package_id")
    private String servicePackageId;//服务包id
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public Integer getPayment() {
        return payment;
    }
    public void setPayment(Integer payment) {
        this.payment = payment;
    }
    public Float getTotalExpense() {
        return totalExpense;
    }
    public void setTotalExpense(Float totalExpense) {
        this.totalExpense = totalExpense;
    }
    public Integer getPlanType() {
        return planType;
    }
    public void setPlanType(Integer planType) {
        this.planType = planType;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getServicePackageId() {
        return servicePackageId;
    }
    public void setServicePackageId(String servicePackageId) {
        this.servicePackageId = servicePackageId;
    }
}

+ 118 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationDetailDO.java

@ -0,0 +1,118 @@
package com.yihu.jw.entity.specialist.rehabilitation;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * Created by humingfen on 2018/8/15.
 */
@Entity
@Table(name = "wlyy_rehabilitation_detail")
public class RehabilitationDetailDO extends IdEntityWithOperation implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "program_id")
    private String programId;//居民康复套餐code
    @Column(name = "service_item_id")
    private String serviceItemId;//服务项目id
    @Column(name = "hospital")
    private String hospital;//医院code
    @Column(name = "hospital_name")
    private String hospitalName;//医院名称
    @Column(name = "type")
    private Integer type;//执行者类型(1家医,2行政团队)
    @Column(name = "doctor")
    private String doctor;//计划完成者标识
    @Column(name = "doctor_name")
    private String doctorName;//计划完成者标识
    @Column(name = "execute_time")
    private String executeTime;//服务项目执行时间
    @Column(name = "status")
    private Integer status;//状态(0未开始,1进行中,2已完成)
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getProgramId() {
        return programId;
    }
    public void setProgramId(String programId) {
        this.programId = programId;
    }
    public String getServiceItemId() {
        return serviceItemId;
    }
    public void setServiceItemId(String serviceItemId) {
        this.serviceItemId = serviceItemId;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getExecuteTime() {
        return executeTime;
    }
    public void setExecuteTime(String executeTime) {
        this.executeTime = executeTime;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
}

+ 66 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationPlanTemplateDO.java

@ -0,0 +1,66 @@
package com.yihu.jw.entity.specialist.rehabilitation;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by humingfen on 2018/8/15.
 */
@Entity
@Table(name = "wlyy_rehabilitation_plan_template")
public class RehabilitationPlanTemplateDO extends IdEntityWithOperation implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "title")
    private String title;//模板名称
    @Column(name = "hospital")
    private String hospital;//医院标识
    @Column(name = "hospital_name")
    private String hospitalName;//医院名称
    @Column(name = "admin_team_code")
    private Integer adminTeamCode;//行政团队id
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public Integer getAdminTeamCode() {
        return adminTeamCode;
    }
    public void setAdminTeamCode(Integer adminTeamCode) {
        this.adminTeamCode = adminTeamCode;
    }
}

+ 47 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationTemplateDetailDO.java

@ -0,0 +1,47 @@
package com.yihu.jw.entity.specialist.rehabilitation;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * Created by humingfen on 2018/8/15.
 */
@Entity
@Table(name = "wlyy_rehabilitation_template_detail")
public class RehabilitationTemplateDetailDO extends IdEntityWithOperation implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "template_id")
    private String templateId;//康复套餐模板id
    @Column(name = "service_item_id")
    private String serviceId;//服务项目id
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getTemplateId() {
        return templateId;
    }
    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }
    public String getServiceId() {
        return serviceId;
    }
    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }
}

+ 48 - 0
common/common-util/src/main/java/com/yihu/jw/util/wechat/WeiXinMessageReplyUtils.java

@ -0,0 +1,48 @@
package com.yihu.jw.util.wechat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by Trick on 2018/8/16.
 */
public class WeiXinMessageReplyUtils {
    /**
     * 回复图文消息
     *
     * @param toUser
     * @param fromUser
     * @param articles
     * @return
     * @throws Exception
     */
    public static String replyNewsMessage(String toUser,String fromUser,List<Map<String,String>> articles) throws Exception {
        if(articles == null || articles.size() < 1){
            throw new Exception("图文信息不能为空!");
        }
        StringBuilder result = new StringBuilder();
        result.append("<xml>");
        result.append("<ToUserName>" + toUser + "</ToUserName>");
        result.append("<FromUserName>" + fromUser + "</FromUserName>");
        result.append("<CreateTime>" + new Date().getTime() + "</CreateTime>");
        result.append("<MsgType>news</MsgType>");
        result.append("<ArticleCount>" + articles.size() + "</ArticleCount>");
        result.append("<Articles>");
        for(Map<String,String>  article : articles){
            result.append("<item>");
            result.append("<Title>" +  article.get("Title") +"</Title>");
            result.append("<Description>" + article.get("Description") + "</Description>");
            result.append("<PicUrl>" + article.get("PicUrl") + "</PicUrl>");
            result.append("<Url>" + article.get("Url") + "</Url>");
            result.append("</item>");
        }
        result.append("</Articles>");
        result.append("</xml>");
        return result.toString();
    }
}

+ 54 - 0
common/common-util/src/main/java/com/yihu/jw/util/wechat/WeiXinMessageUtils.java

@ -0,0 +1,54 @@
package com.yihu.jw.util.wechat;
/**
 * Created by Trick on 2018/8/16.
 */
public class WeiXinMessageUtils {
    // 请求消息类型:文本
    public static final String REQ_MESSAGE_TYPE_TEXT = "text";
    // 请求消息类型:图片
    public static final String REQ_MESSAGE_TYPE_IMAGE = "image";
    // 请求消息类型:语音
    public static final String REQ_MESSAGE_TYPE_VOICE = "voice";
    // 请求消息类型:视频
    public static final String REQ_MESSAGE_TYPE_VIDEO = "video";
    // 请求消息类型:小视频
    public static final String REQ_MESSAGE_TYPE_SHORTVIDEO = "shortvideo";
    // 请求消息类型:地理位置
    public static final String REQ_MESSAGE_TYPE_LOCATION = "location";
    // 请求消息类型:链接
    public static final String REQ_MESSAGE_TYPE_LINK = "link";
    // 请求消息类型:事件推送
    public static final String REQ_MESSAGE_TYPE_EVENT = "event";
    // 事件类型:subscribe(订阅)
    public static final String EVENT_TYPE_SUBSCRIBE = "subscribe";
    // 事件类型:unsubscribe(取消订阅)
    public static final String EVENT_TYPE_UNSUBSCRIBE = "unsubscribe";
    // 事件类型:scan(用户已关注时的扫描带参数二维码)
    public static final String EVENT_TYPE_SCAN = "SCAN";
    // 事件类型:LOCATION(上报地理位置)
    public static final String EVENT_TYPE_LOCATION = "LOCATION";
    // 事件类型:CLICK(自定义菜单)
    public static final String EVENT_TYPE_CLICK = "CLICK";
    // 响应消息类型:文本
    public static final String RESP_MESSAGE_TYPE_TEXT = "text";
    // 响应消息类型:图片
    public static final String RESP_MESSAGE_TYPE_IMAGE = "image";
    // 响应消息类型:语音
    public static final String RESP_MESSAGE_TYPE_VOICE = "voice";
    // 响应消息类型:视频
    public static final String RESP_MESSAGE_TYPE_VIDEO = "video";
    // 响应消息类型:音乐
    public static final String RESP_MESSAGE_TYPE_MUSIC = "music";
    // 响应消息类型:图文
    public static final String RESP_MESSAGE_TYPE_NEWS = "news";
//    public static BaseMessage messageProcess(){
//        BaseMessage message = null;
//
//        return message;
//    }
}

+ 3 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/config/HibernateProperties.java

@ -28,8 +28,8 @@
//    private String physical_naming_strategy;
//    @Value("${hibernate.implicit_naming_strategy}")
//    private String implicit_naming_strategy;
//    @Autowired
//    private List<Interceptor> interceptors;
////    @Autowired
////    private List<Interceptor> interceptors;
//
//    public Properties hibProperties() {
//        Properties properties = new Properties();
@ -37,7 +37,7 @@
//        properties.put("hibernate.show_sql", show_sql);
//        properties.put("hibernate.physical_naming_strategy", physical_naming_strategy);
//        properties.put("hibernate.implicit_naming_strategy", implicit_naming_strategy);
//        properties.put("hibernate.ejb.interceptor", interceptors.get(0));
//        //properties.put("hibernate.ejb.interceptor", interceptors.get(0));
//        return properties;
//    }
//}

+ 163 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/ModuleController.java

@ -0,0 +1,163 @@
//package com.yihu.jw.business.base.controller;
//
//import com.yihu.jw.base.base.ModuleDO;
//import com.yihu.jw.business.base.service.ModuleService;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.restmodel.base.base.ModuleVO;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//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.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/19.
// */
//@RestController
//@RequestMapping(BaseRequestMapping.api_base_common)
//@Api(value = "模块模块", description = "模块接口管理")
//public class ModuleController extends EnvelopRestController {
//    @Autowired
//    private ModuleService moduleService;
//
////    @PostMapping(value = BaseRequestMapping.Module.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
////    @ApiOperation(value = "创建模块", notes = "创建单个模块")
////    public Envelop createModule(
////            @ApiParam(name = "json_data", value = "", defaultValue = "")
////            @RequestBody String jsonData) {
////        try {
////            ModuleDO module = toEntity(jsonData, ModuleDO.class);
////            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_create, moduleService.createModule(module));
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
////    @PutMapping(value = BaseRequestMapping.Module.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
////    @ApiOperation(value = "修改模块", notes = "修改模块")
////    public Envelop updateModule(
////            @ApiParam(name = "json_data", value = "", defaultValue = "")
////            @RequestBody String jsonData) {
////        try {
////            ModuleDO module = toEntity(jsonData, ModuleDO.class);
////            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_update, moduleService.updateModule(module));
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
//    @DeleteMapping(value = BaseRequestMapping.Module.api_delete)
//    @ApiOperation(value = "删除模块", notes = "删除模块")
//    public Envelop deleteModule(
//            @ApiParam(name = "codes", value = "codes")
//            @PathVariable(value = "codes", required = true) String codes) {
//        try {
//            moduleService.deleteModule(codes);
//            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_delete );
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//    @GetMapping(value = BaseRequestMapping.Module.api_getById)
//    @ApiOperation(value = "根据code查找模块", notes = "根据code查找模块")
//    public Envelop findByCode(
//            @ApiParam(name = "id", value = "id")
//            @PathVariable(value = "id", required = true) String id
//    ) {
//        try {
//            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_find, moduleService.findById(id));
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//
//    @RequestMapping(value = BaseRequestMapping.Module.api_getList, method = RequestMethod.GET)
//    @ApiOperation(value = "获取父模块列表(分页)")
//    public Envelop getModules(
//            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
//            @RequestParam(value = "fields", required = false) String fields,
//            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
//            //code like 1,name大于aa ,code 等于1 , defaultValue = "code?1;name>aa;code=1"
//            @RequestParam(value = "filters", required = false) String filters,
//            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
//            @RequestParam(value = "sorts", required = false) String sorts,
//            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
//            @RequestParam(value = "size", required = false) int size,
//            @ApiParam(name = "page", value = "页码", defaultValue = "1")
//            @RequestParam(value = "page", required = false) int page,
//            HttpServletRequest request,
//            HttpServletResponse response) throws Exception {
//        if(StringUtils.isBlank(sorts)){
//            sorts = "-updateTime";
//        }
//        if(StringUtils.isBlank(filters)){
//            filters = "parentCode=0;";
//        }else{
//            filters="parentCode=0;"+filters;
//        }
//
//        //得到list数据
//        List<ModuleDO> list = moduleService.search(fields, filters, sorts, page, size);
//
//        if(list!=null){
//            for(ModuleDO module:list){//循环遍历,设置是否有子节点
//                List<ModuleDO> children = moduleService.getChildren(module.getId());
//                //children长度为0时    state  “open”表示是子节点,“closed”表示为父节点;
//                // children长度>0时,  state   “open,closed”表示是节点的打开关闭
//                if (children.size()>0){
//                    module.setState("closed");
//                }else{
//                    module.setState("open");
//                }
//            }
//        }
//
//        //获取总数
//        long count=moduleService.getCount(filters);
//        //封装头信息
//        pagedResponse(request, response, count, page, size);
//        //封装返回格式
//        List<ModuleVO> ModuleVOs = convertToModels(list, new ArrayList<>(list.size()), ModuleVO.class, fields);
//
//        return Envelop.getSuccessListWithPage(BaseRequestMapping.Module.message_success_find_Modules,ModuleVOs, page, size,count);
//    }
//
//
//    @GetMapping(value = BaseRequestMapping.Module.api_getListNoPage)
//    @ApiOperation(value = "获取模块列表,不分页")
//    public Envelop getListNoPage(
//            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
//            @RequestParam(value = "fields", required = false) String fields,
//            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
//            @RequestParam(value = "filters", required = false) String filters,
//            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
//            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
//        //得到list数据
//        List<ModuleDO> list = moduleService.search(filters, sorts);
//        //封装返回格式
//        List<ModuleVO> ModuleVOs = convertToModels(list, new ArrayList<>(list.size()), ModuleVO.class, fields);
//        return Envelop.getSuccessList(BaseRequestMapping.Module.message_success_find_Modules,ModuleVOs);
//    }
//
//
//    @GetMapping(value =BaseRequestMapping.Module.api_getChildren )
//    @ApiOperation(value="查找子节点")
//    public Envelop getChildren(@PathVariable String code){
//        List<ModuleDO> children = moduleService.getChildren(code);
//        return Envelop.getSuccess("查询成功",children);
//    }
//
//
//}

+ 39 - 39
svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/ModuleFunController.java

@ -1,39 +1,39 @@
package com.yihu.jw.business.base.controller;
import com.yihu.jw.business.base.service.ModuleFunService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
@RestController
@RequestMapping(BaseRequestMapping.api_base_common)
@Api(value = "模块功能模块", description = "模块功能模块")
public class ModuleFunController extends EnvelopRestController {
    @Autowired
    private ModuleFunService moduleFunService;
    @GetMapping(value = BaseRequestMapping.ModuleFun.api_getExistFun)
    @ApiOperation(value="查找已存在的功能")
    public Envelop getExistFunc(@PathVariable String id){
        List<String> funcs = moduleFunService.getExistFun(id);
        return Envelop.getSuccess("查询成功",funcs);
    }
    @PutMapping(value =  BaseRequestMapping.ModuleFun.api_changeFun,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "模块更新功能")
    public Envelop changeFun (@RequestBody String jsonData) throws JSONException {
        moduleFunService.changeFun(jsonData);
        return Envelop.getSuccess("更新成功",null);
    }
}
//package com.yihu.jw.business.base.controller;
//
//import com.yihu.jw.business.base.service.ModuleFunService;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//import com.yihu.jw.rm.base.BaseRequestMapping;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.json.JSONException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/19.
// */
//@RestController
//@RequestMapping(BaseRequestMapping.api_base_common)
//@Api(value = "模块功能模块", description = "模块功能模块")
//public class ModuleFunController extends EnvelopRestController {
//    @Autowired
//    private ModuleFunService moduleFunService;
//
//    @GetMapping(value = BaseRequestMapping.ModuleFun.api_getExistFun)
//    @ApiOperation(value="查找已存在的功能")
//    public Envelop getExistFunc(@PathVariable String id){
//        List<String> funcs = moduleFunService.getExistFun(id);
//        return Envelop.getSuccess("查询成功",funcs);
//    }
//
//    @PutMapping(value =  BaseRequestMapping.ModuleFun.api_changeFun,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "模块更新功能")
//    public Envelop changeFun (@RequestBody String jsonData) throws JSONException {
//        moduleFunService.changeFun(jsonData);
//        return Envelop.getSuccess("更新成功",null);
//    }
//}

+ 128 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/SaasController.java

@ -0,0 +1,128 @@
//package com.yihu.jw.business.base.controller;
//
//import com.yihu.jw.base.base.SaasDO;
//import com.yihu.jw.business.base.service.SaasService;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//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.*;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/19.
// */
//@RestController
//@RequestMapping(BaseRequestMapping.api_base_common)
//@Api(value = "Saas配置模块", description = "Saas配置模块接口管理")
//public class SaasController extends EnvelopRestController {
//    @Autowired
//    private SaasService saasService;
//
////    @PostMapping(value = BaseRequestMapping.Saas.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
////    @ApiOperation(value = "创建Saas配置", notes = "创建单个Saas配置")
////    public Envelop createSaas(
////            @ApiParam(name = "json_data", value = "", defaultValue = "")
////            @RequestBody String jsonData) {
////        try {
////            SaasDO saas = toEntity(jsonData, SaasDO.class);
////            return Envelop.getSuccess(BaseRequestMapping.Saas.message_success_create, saasService.createSaas(saas));
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
////    @PutMapping(value = BaseRequestMapping.Saas.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
////    @ApiOperation(value = "修改Saas配置", notes = "修改Saas配置")
////    public Envelop updateSaas(
////            @ApiParam(name = "json_data", value = "", defaultValue = "")
////            @RequestBody String jsonData) {
////        try {
////            SaasDO saas = toEntity(jsonData, SaasDO.class);
////            return Envelop.getSuccess(BaseRequestMapping.Saas.message_success_update, saasService.updateSaas(saas));
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
//    @DeleteMapping(value = BaseRequestMapping.Saas.api_delete, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "删除Saas配置", notes = "删除Saas配置")
//    public Envelop deleteSaas(
//            @ApiParam(name = "id", value = "id")
//            @RequestParam(value = "id", required = true) String id) {
//        try {
//            saasService.deleteSaas(id);
//            return Envelop.getSuccess(BaseRequestMapping.Saas.message_success_delete);
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//    @GetMapping(value = BaseRequestMapping.Saas.api_getById, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "根据code查找Saas配置", notes = "根据code查找Saas配置")
//    public Envelop findByCode(
//            @ApiParam(name = "id", value = "id")
//            @RequestParam(value = "id", required = true) String id
//    ) {
//        try {
//            return Envelop.getSuccess(BaseRequestMapping.Saas.message_success_find, saasService.findById(id));
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//
//    @RequestMapping(value = BaseRequestMapping.Saas.api_getSaass, method = RequestMethod.GET)
//    @ApiOperation(value = "获取Saas配置列表(分页)")
//    public Envelop getSaass(
//            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
//            @RequestParam(value = "fields", required = false) String fields,
//            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
//            //code like 1,name大于aa ,code 等于1 , defaultValue = "code?1;name>aa;code=1"
//            @RequestParam(value = "filters", required = false) String filters,
//            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
//            @RequestParam(value = "sorts", required = false) String sorts,
//            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
//            @RequestParam(value = "size", required = false) int size,
//            @ApiParam(name = "page", value = "页码", defaultValue = "1")
//            @RequestParam(value = "page", required = false) int page,
//            HttpServletRequest request,
//            HttpServletResponse response) throws Exception {
//        //得到list数据
//        List<SaasDO> list = saasService.search(fields, filters, sorts, page, size);
//        //获取总数
//        long count = saasService.getCount(filters);
//        //封装头信息
//        pagedResponse(request, response, count, page, size);
//        //封装返回格式
//        List<SaasDO> mSaass = convertToModels(list, new ArrayList<>(list.size()), SaasDO.class, fields);
//
//        return Envelop.getSuccessListWithPage(BaseRequestMapping.Saas.message_success_find_saass, mSaass, page, size, count);
//    }
//
//
//    @GetMapping(value = BaseRequestMapping.Saas.api_getSaassNoPage)
//    @ApiOperation(value = "获取Saas配置列表,不分页")
//    public Envelop getAppsNoPage(
//            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,id,remark")
//            @RequestParam(value = "fields", required = false) String fields,
//            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
//            @RequestParam(value = "filters", required = false) String filters,
//            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
//            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
//        //得到list数据
//        List<SaasDO> list = saasService.search(filters, sorts);
//        //封装返回格式
//        List<SaasDO> mSaass = convertToModels(list, new ArrayList<>(list.size()), SaasDO.class, fields);
//        return Envelop.getSuccessList(BaseRequestMapping.Saas.message_success_find_saass, mSaass);
//    }
//}

+ 6 - 6
svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/SystemController.java

@ -1,6 +1,6 @@
package com.yihu.jw.business.base.controller;
/**
 * Created by LiTaohong on 2017/11/30.
 */
public class SystemController {
}
//package com.yihu.jw.business.base.controller;
///**
// * Created by LiTaohong on 2017/11/30.
// */
//public class SystemController {
//}

+ 152 - 18
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/FunctionService.java

@ -1,18 +1,152 @@
package com.yihu.jw.business.base.service;
import com.yihu.jw.business.base.dao.FunctionDao;
import com.yihu.jw.entity.base.function.FunctionDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by chenweida on 2017/5/19.
 */
@Service
public class FunctionService extends BaseJpaService<FunctionDO, FunctionDao> {
    @Autowired
    private FunctionDao functionDao;
}
//package com.yihu.jw.business.base.service;
//
//import com.yihu.jw.base.base.ModuleFunctionDO;
//import com.yihu.jw.business.base.dao.FunctionDao;
//import com.yihu.jw.business.base.dao.ModuleFunctionDao;
//import com.yihu.jw.base.base.FunctionDO;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.restmodel.base.base.FunctionVO;
//import com.yihu.jw.rm.base.BaseRequestMapping;
//import com.yihu.mysql.query.BaseJpaService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.StringUtils;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by chenweida on 2017/5/19.
// */
//@Service
//public class FunctionService extends BaseJpaService<FunctionDO, FunctionDao> {
//    @Autowired
//    private FunctionDao functionDao;
//    @Autowired
//    private ModuleFunctionDao moduleFunctionDao;
//    @Autowired
//    private ModuleFunService moduleFunService;
//    @Autowired
//    private JdbcTemplate jdbcTemplate;
//
//    @Transactional
//    public FunctionDO createFunction(FunctionDO function) throws ApiException {
//        if (StringUtils.isEmpty(function.getId())) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(function.getName())) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        FunctionDO functionTmp = functionDao.findByName(function.getName());
//        if (functionTmp != null) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_name_exist, ExceptionCode.common_error_params_code);
//        }
//        return functionDao.save(function);
//    }
//
//    @Transactional
//    public FunctionDO updateFunction(FunctionDO function) {
//        if (StringUtils.isEmpty(function.getName())) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(function.getId())) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        FunctionDO functionTmp = functionDao.findByNameExcludeId(function.getName(), function.getId());
//        if (functionTmp != null) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_name_exist, ExceptionCode.common_error_params_code);
//        }
//        return functionDao.save(function);
//    }
//
//    public FunctionDO findById(String id) {
//        FunctionDO function = functionDao.findById(id);
//        if (function == null) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
//        }
//        return function;
//    }
//
//    @Transactional
//    public void deleteFunction(String id) {
//        FunctionDO function = functionDao.findById(id);
//        if (function == null) {
//            throw new ApiException(BaseRequestMapping.Function.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
//        }
//        function.setStatus(-1);
//        functionDao.save(function);
//    }
//    @Transactional
//    public void assignFunction(String moduleId, String functionIds) {
//        //先删除原来已经分配好的功能
//        moduleFunctionDao.deleteByModuleId(moduleId);
//        //分配新的功能
//        String [] functionCodeArr=functionIds.split(",");
//        List<ModuleFunctionDO> saasModuleList=new ArrayList<>();
//        for(String functionId:functionCodeArr){
//            ModuleFunctionDO saasModule=new ModuleFunctionDO();
//            saasModule.setModuleId(moduleId);
//            saasModule.setFunctionId(functionId);
//            saasModuleList.add(saasModule);
//        }
//        moduleFunctionDao.save(saasModuleList);
//    }
//
//    public List<FunctionVO> getModuleFunctions(String saasId) {
//        String sql=" select m.code,m.parent_code,m.name from base_function f,base_module_function mf where f.code=mf.function_id and f.status=1 and mf.module_id=?";
//        return jdbcTemplate.queryForList(sql,FunctionVO.class,saasId);
//    }
//
//    /**
//     * 根据code获得子节点,并判断是否子节点是否还有孙节点 (treegrid点击查询子节点 用到)
//     * @param code
//     * @return
//     */
//    public List<FunctionDO> getChildren(String code){
//        List<FunctionDO> childrens = functionDao.getChildren(code);
//        for(FunctionDO children:childrens){
//            List<FunctionDO> children1 = functionDao.getChildren(children.getId());//判断子节点是否有孙节点
//            children.setChildren(children1);
//        }
//        return childrens;
//    }
//
//    public List<FunctionDO> findAll(){
//        return functionDao.findAll();
//    }
//
//    /**
//     * key为code ,value为功能名称
//     * @return
//     */
//    public Map<String,String> getName(){
//        List<FunctionDO> functions = findAll();
//        Map<String, String> map = new HashMap<>();
//        if(null!=functions){
//            for(FunctionDO function: functions){
//                map.put(function.getId(),function.getName());
//            }
//        }
//        return map;
//    }
//
//    /**
//     * 根据code获取所有子节点(包括孙节点,曾孙节点....)
//     * @param id
//     * @return
//     */
//    public FunctionDO getAllChildren(String id){
//        FunctionDO function = functionDao.findById(id);
//        List<FunctionDO> childrens = functionDao.getChildren(id);
//        for(FunctionDO children:childrens){
//            getAllChildren(children.getId());
//        }
//        function.setChildren(childrens);
//        return function;
//    }
//}

+ 80 - 80
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/ModuleFunService.java

@ -1,80 +1,80 @@
package com.yihu.jw.business.base.service;
import com.yihu.jw.entity.base.module.ModuleFunctionDO;
import com.yihu.jw.business.base.dao.ModuleFunctionDao;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
@Service
public class ModuleFunService extends BaseJpaService<ModuleFunctionDO, ModuleFunctionDao> {
    @Autowired
    private ModuleFunctionDao moduleFunctionDao;
    /**
     * 根据模块code,获取已存在的功能code
     * @param id
     * @return
     */
    public List<String> getExistFun(String id) {
        List<ModuleFunctionDO> moduleFuns = moduleFunctionDao.findByModuleId(id);
        List<String> list = new ArrayList<>();
        for(ModuleFunctionDO moduleFun:moduleFuns){
            list.add(moduleFun.getFunctionId());
        }
        return list;
    }
    /**
     * 更改模块关联的功能
     * @param jsonData
     */
    public void changeFun(String jsonData) throws JSONException {
        JSONObject jsonObject =  new JSONObject(jsonData);
        if(!jsonObject.has("moduleCode")){
            throw new ApiException(BaseRequestMapping.ModuleFun.moduleId_is_null, ExceptionCode.common_error_params_code);
            //filterStr+="saasId="+jsonObject.get("saasId")+";";
        }
        if(!jsonObject.has("funCodes")){
            throw new ApiException(BaseRequestMapping.ModuleFun.funIds_is_null, ExceptionCode.common_error_params_code);
        }
        String moduleCode = jsonObject.get("moduleCode").toString();//模块code
        String funCodes = jsonObject.get("funCodes").toString();//功能code,多个code  ","  分隔
        List<String> existFun = getExistFun(moduleCode);
        List<String> newFunCodes = new ArrayList<String>(Arrays.asList(funCodes.split(",")));//目前的功能code
        List<String> oldFunCodes = new ArrayList<String>(existFun);//构建existFun的副本
        oldFunCodes.removeAll(newFunCodes);// 去除相同元素--->>需要删除的功能code
        newFunCodes.removeAll(existFun);// 去除相同元素---->>需要添加的功能code
        //先删除权限在添加...
        for(String delCode: oldFunCodes){
            moduleFunctionDao.delete(delCode, moduleCode);
        }
        for(String addCode:newFunCodes){
            ModuleFunctionDO moduleFunction = new ModuleFunctionDO();
            moduleFunction.setFunctionId(addCode);
            moduleFunction.setModuleId(moduleCode);
            moduleFunctionDao.save(moduleFunction);
        }
    }
}
//package com.yihu.jw.business.base.service;
//
//import com.yihu.jw.base.base.ModuleFunctionDO;
//import com.yihu.jw.business.base.dao.ModuleFunctionDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.rm.base.BaseRequestMapping;
//import com.yihu.mysql.query.BaseJpaService;
//import org.json.JSONException;
//import org.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/19.
// */
//@Service
//public class ModuleFunService extends BaseJpaService<ModuleFunctionDO, ModuleFunctionDao> {
//
//    @Autowired
//    private ModuleFunctionDao moduleFunctionDao;
//
//    /**
//     * 根据模块code,获取已存在的功能code
//     * @param id
//     * @return
//     */
//    public List<String> getExistFun(String id) {
//        List<ModuleFunctionDO> moduleFuns = moduleFunctionDao.findByModuleId(id);
//        List<String> list = new ArrayList<>();
//        for(ModuleFunctionDO moduleFun:moduleFuns){
//            list.add(moduleFun.getFunctionId());
//        }
//        return list;
//    }
//
//
//
//    /**
//     * 更改模块关联的功能
//     * @param jsonData
//     */
//    public void changeFun(String jsonData) throws JSONException {
//        JSONObject jsonObject =  new JSONObject(jsonData);
//        if(!jsonObject.has("moduleCode")){
//            throw new ApiException(BaseRequestMapping.ModuleFun.moduleId_is_null, ExceptionCode.common_error_params_code);
//            //filterStr+="saasId="+jsonObject.get("saasId")+";";
//        }
//        if(!jsonObject.has("funCodes")){
//            throw new ApiException(BaseRequestMapping.ModuleFun.funIds_is_null, ExceptionCode.common_error_params_code);
//        }
//        String moduleCode = jsonObject.get("moduleCode").toString();//模块code
//        String funCodes = jsonObject.get("funCodes").toString();//功能code,多个code  ","  分隔
//
//        List<String> existFun = getExistFun(moduleCode);
//
//        List<String> newFunCodes = new ArrayList<String>(Arrays.asList(funCodes.split(",")));//目前的功能code
//
//        List<String> oldFunCodes = new ArrayList<String>(existFun);//构建existFun的副本
//        oldFunCodes.removeAll(newFunCodes);// 去除相同元素--->>需要删除的功能code
//
//        newFunCodes.removeAll(existFun);// 去除相同元素---->>需要添加的功能code
//
//        //先删除权限在添加...
//        for(String delCode: oldFunCodes){
//            moduleFunctionDao.delete(delCode, moduleCode);
//        }
//        for(String addCode:newFunCodes){
//            ModuleFunctionDO moduleFunction = new ModuleFunctionDO();
//            moduleFunction.setFunctionId(addCode);
//            moduleFunction.setModuleId(moduleCode);
//            moduleFunctionDao.save(moduleFunction);
//        }
//
//    }
//}

+ 141 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/ModuleService.java

@ -0,0 +1,141 @@
//package com.yihu.jw.business.base.service;
//
//import com.yihu.jw.base.base.ModuleDO;
//import com.yihu.jw.base.base.SaasModuleDO;
//import com.yihu.jw.business.base.dao.ModuleDao;
//import com.yihu.jw.business.base.dao.SaasModuleDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.restmodel.base.base.ModuleVO;
//import com.yihu.jw.rm.base.BaseRequestMapping;
//import com.yihu.mysql.query.BaseJpaService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.StringUtils;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by chenweida on 2017/5/19.
// */
//@Service
//public class ModuleService extends BaseJpaService<ModuleDO, ModuleDao> {
//    @Autowired
//    private ModuleDao moduleDao;
//    @Autowired
//    private SaasModuleDao saasModuleDao;
//    @Autowired
//    private JdbcTemplate jdbcTemplate;
//
//
//    @Transactional
//    public ModuleDO createModule(ModuleDO module) throws ApiException {
//        if (StringUtils.isEmpty(module.getId())) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(module.getName())) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(module.getSaasId())) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        ModuleDO moduleTmp = moduleDao.findByName(module.getName());
//        if (moduleTmp != null) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_name_exist, ExceptionCode.common_error_params_code);
//        }
//        return moduleDao.save(module);
//    }
//
//    @Transactional
//    public ModuleDO updateModule(ModuleDO module) {
//        if (StringUtils.isEmpty(module.getName())) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(module.getId())) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        ModuleDO moduleTmp = moduleDao.findByNameExcludeId(module.getName(), module.getId());
//        if (moduleTmp != null) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_name_exist, ExceptionCode.common_error_params_code);
//        }
//        return moduleDao.save(module);
//    }
//
//    public ModuleDO findById(String Id) {
//        ModuleDO module = moduleDao.findById(Id);
//        if (module == null) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
//        }
//        return module;
//    }
//
//    @Transactional
//    public void deleteModule(String Id) {
//        ModuleDO module = moduleDao.findById(Id);
//        if (module == null) {
//            throw new ApiException(BaseRequestMapping.Module.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
//        }
//        module.setStatus(-1);
//    }
//
//    @Transactional
//    public void assignModule(String saasCode, String moduleCodes) {
//        //先删除原来已经分配好的模块
//        saasModuleDao.deleteBySaasCode(saasCode);
//        //分配新的模块
//        String [] moduleCodeArr=moduleCodes.split(",");
//        List<SaasModuleDO> saasModuleList=new ArrayList<>();
//        for(String moduleCode:moduleCodeArr){
//            SaasModuleDO saasModule=new SaasModuleDO();
//            saasModule.setModuleId(moduleCode);
//            saasModule.setSaasId(saasCode);
//            saasModuleList.add(saasModule);
//        }
//        saasModuleDao.save(saasModuleList);
//    }
//
//    public List<ModuleVO> getSaasModules(String saasCode) {
//        String sql=" select m.code,m.parent_code,m.name from base_module m,base_saas_module sm where m.code=sm.module_id and m.status=1 and sm.saas_id=?";
//       return jdbcTemplate.queryForList(sql,ModuleVO.class,saasCode);
//    }
//
//    public List<ModuleDO> getChildren(String code){
//        List<ModuleDO> childrens = moduleDao.getChildren(code);
//        for(ModuleDO children:childrens){
//            List<ModuleDO> children1 = moduleDao.getChildren(children.getId());//判断子节点是否有孙节点
//            //没有children    state
//            //“open”表示是子节点,“closed”表示为父节点;
//            if (children1.size()>0){
//                children.setState("closed");
//            }else{
//                children.setState("open");
//            }
//        }
//        return childrens;
//    }
//
//    public List<ModuleDO> findAll(){
//        return moduleDao.findAll();
//    }
//
//    /**
//     * key为code ,value为模块名称
//     * @return
//     */
//    public Map<String,String> getName(){
//        List<ModuleDO> modules = findAll();
//        Map<String, String> map = new HashMap<>();
//        if(null!=modules){
//            for(ModuleDO module: modules){
//                map.put(module.getId(),module.getName());
//            }
//        }
//        return map;
//    }
//
//}

+ 72 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SaasService.java

@ -0,0 +1,72 @@
package com.yihu.jw.business.base.service;
import com.yihu.jw.base.base.SaasDO;
import com.yihu.jw.business.base.dao.SaasDao;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
/**
 * Created by chenweida on 2017/5/19.
 */
@Service
public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
    @Autowired
    private SaasDao saasDao;
    @Transactional
    public SaasDO createSaas(SaasDO saas) throws ApiException {
        if (StringUtils.isEmpty(saas.getId())) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(saas.getName())) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_name_is_null, ExceptionCode.common_error_params_code);
        }
        SaasDO saasTmp = saasDao.findByName(saas.getName());
        if (saasTmp != null) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_name_exist, ExceptionCode.common_error_params_code);
        }
        return saasDao.save(saas);
    }
    @Transactional
    public SaasDO updateSaas(SaasDO saas) {
        if (StringUtils.isEmpty(saas.getName())) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_name_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(saas.getId())) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        SaasDO saasTmp = saasDao.findByNameExcludeId(saas.getName(), saas.getId());
        if (saasTmp != null) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_name_exist, ExceptionCode.common_error_params_code);
        }
        return saasDao.save(saas);
    }
    public SaasDO findById(String id) {
        SaasDO saas = saasDao.findById(id);
        if (saas == null) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
        }
        return saas;
    }
    @Transactional
    public void deleteSaas(String id) {
        SaasDO saas = saasDao.findById(id);
        if (saas == null) {
            throw new ApiException(BaseRequestMapping.Saas.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
        }
        saas.setStatus(-1);
    }
    public SaasDO findByName(String cityName) {
        return saasDao.findByName(cityName);
    }
}

+ 11 - 11
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SystemDictListService.java

@ -1,11 +1,11 @@
package com.yihu.jw.business.base.service;
import com.yihu.jw.entity.base.system.SystemDictEntryDO;
import com.yihu.jw.business.base.dao.SystemDictListDao;
import com.yihu.mysql.query.BaseJpaService;
/**
 * Created by LiTaohong on 2017/12/01.
 */
public class SystemDictListService extends BaseJpaService<SystemDictEntryDO, SystemDictListDao> {
}
//package com.yihu.jw.business.base.service;
//
//import com.yihu.jw.base.base.SystemDictListDO;
//import com.yihu.jw.business.base.dao.SystemDictListDao;
//import com.yihu.mysql.query.BaseJpaService;
//
///**
// * Created by LiTaohong on 2017/12/01.
// */
//public class SystemDictListService extends BaseJpaService<SystemDictListDO, SystemDictListDao> {
//}

+ 11 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/SystemDictService.java

@ -0,0 +1,11 @@
//package com.yihu.jw.business.base.service;
//
//import com.yihu.jw.base.base.SystemDictDO;
//import com.yihu.jw.business.base.dao.SystemDictDao;
//import com.yihu.mysql.query.BaseJpaService;
//
///**
// * Created by LiTaohong on 2017/12/01.
// */
//public class SystemDictService extends BaseJpaService<SystemDictDO, SystemDictDao> {
//}

+ 32 - 32
svr/svr-base/src/main/java/com/yihu/jw/business/demo/DemoController.java

@ -1,32 +1,32 @@
package com.yihu.jw.business.demo;
import com.yihu.jw.business.user.dao.BaseRoleDao;
import com.yihu.jw.restmodel.common.Envelop;
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.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
/**
 * Created by chenweida on 2017/5/10.
 */
@RestController
@RequestMapping("/demo")
@Api(description = "demo例子")
@RefreshScope
public class DemoController {
    @Autowired
    private BaseRoleDao baseRoleDao;
    @ApiOperation(value = "根据code查找患者")
    @GetMapping(value = "findByCode")
    public Envelop findByCode(
            @ApiParam(name = "code", value = "患者code", required = false) @RequestParam(value = "code", required = false) String code) {
        baseRoleDao.findAllByName("管理员");
        return  Envelop.getSuccess("成功");
    }
}
//package com.yihu.jw.business.demo;
//
//import com.yihu.jw.business.user.dao.BaseRoleDao;
//import com.yihu.jw.restmodel.common.Envelop;
//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.cloud.context.config.annotation.RefreshScope;
//import org.springframework.web.bind.annotation.*;
//
//
///**
// * Created by chenweida on 2017/5/10.
// */
//@RestController
//@RequestMapping("/demo")
//@Api(description = "demo例子")
//@RefreshScope
//public class DemoController {
//    @Autowired
//    private BaseRoleDao baseRoleDao;
//
//    @ApiOperation(value = "根据code查找患者")
//    @GetMapping(value = "findByCode")
//    public Envelop findByCode(
//            @ApiParam(name = "code", value = "患者code", required = false) @RequestParam(value = "code", required = false) String code) {
//        baseRoleDao.findAllByName("管理员");
//        return  Envelop.getSuccess("成功");
//    }
//
//}

+ 18 - 18
svr/svr-base/src/main/java/com/yihu/jw/business/sms/dao/SmsDao.java

@ -1,18 +1,18 @@
package com.yihu.jw.business.sms.dao;
import com.yihu.jw.entity.base.sms.BaseSmsDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
public interface SmsDao extends PagingAndSortingRepository<BaseSmsDO, String>, JpaSpecificationExecutor<BaseSmsDO> {
    @Query("select count(a.id) from BaseSmsDO a where a.mobile = ?1 and a.createTime  between ?2 and ?3 ")
    int countByMobile(String mobile,Date begin, Date end);
    @Query("select a from BaseSmsDO a where a.mobile = ?1 and a.type = ?2 and a.saasId= ?3 order by a.createTime desc")
    List<BaseSmsDO> findByMobileType(String mobile, int type,String saasId);
}
//package com.yihu.jw.business.sms.dao;
//
//import com.yihu.jw.base.sms.BaseSmsDO;
//import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
//import org.springframework.data.jpa.repository.Query;
//import org.springframework.data.repository.PagingAndSortingRepository;
//
//import java.util.Date;
//import java.util.List;
//
//public interface SmsDao extends PagingAndSortingRepository<BaseSmsDO, String>, JpaSpecificationExecutor<BaseSmsDO> {
//
//    @Query("select count(a.id) from BaseSmsDO a where a.mobile = ?1 and a.createTime  between ?2 and ?3 ")
//    int countByMobile(String mobile,Date begin, Date end);
//
//    @Query("select a from BaseSmsDO a where a.mobile = ?1 and a.type = ?2 and a.saasId= ?3 order by a.createTime desc")
//    List<BaseSmsDO> findByMobileType(String mobile, int type,String saasId);
//}

+ 178 - 170
svr/svr-base/src/main/java/com/yihu/jw/business/sms/service/SmsService.java

@ -1,180 +1,188 @@
package com.yihu.jw.business.sms.service;
import com.yihu.jw.entity.base.sms.BaseSmsDO;
import com.yihu.jw.business.sms.dao.SmsDao;
import com.yihu.jw.business.sms.vo.SMSHttpVo;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.base.BaseEnvelop;
import com.yihu.jw.util.common.SmsValidateCodeUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.vo.ValidateCode;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * Created by chenweida on 2017/5/22.
 */
@Service
public class SmsService  extends BaseJpaService<BaseSmsDO, SmsDao> {
    @Autowired
    private SmsDao smsDao;
    @Autowired
    private SMSHttpVo smsHttpVo;
//package com.yihu.jw.business.sms.service;
//
//import com.yihu.jw.base.sms.BaseSmsDO;
//import com.yihu.jw.business.sms.dao.SmsDao;
//import com.yihu.jw.business.sms.vo.SMSHttpVo;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.base.BaseEnvelop;
//import com.yihu.jw.util.common.SmsValidateCodeUtils;
//import com.yihu.jw.util.date.DateUtil;
//import com.yihu.jw.vo.ValidateCode;
//import com.yihu.mysql.query.BaseJpaService;
//import org.apache.http.NameValuePair;
//import org.apache.http.message.BasicNameValuePair;
//import org.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.domain.Sort;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.util.MultiValueMap;
//import org.springframework.web.client.RestTemplate;
//
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.time.LocalDateTime;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/22.
// */
//@Service
//public class SmsService  extends BaseJpaService<BaseSmsDO, SmsDao> {
//    @Autowired
//    private SmsDao smsDao;
//    @Autowired
//    private SMSHttpVo smsHttpVo;
//
//
////    @Transactional
////    public BaseSmsDO createSms(BaseSmsDO sms) throws ApiException {
////
////        return smsDao.save(sms);
////    }
////
////    @Transactional
////    public BaseSmsDO updateSms(BaseSmsDO sms) {
////        return smsDao.save(sms);
////    }
//
//
//    /**
//     * 发送验证码(不走权限判断,包括:注册、找回密码)
//     * @param mobile
//     * @param ip
//     * @param type
//     * @return
//     * @throws Exception
//     */
//    @Transactional
//    public BaseSmsDO createSms(BaseSmsDO sms) throws ApiException {
//    public BaseEnvelop send(String mobile, String ip, int type,String saasId) throws Exception {
//        // 1、同一手机一天不允许超过5条短信
//        //1.1获取一天的开始和结束时间
//        String today = DateUtil.getStringDateShort();
//        Date begin = DateUtil.strToDate(today + " 00:00:00", DateUtil.YYYY_MM_DD_HH_MM_SS);
//        Date end = DateUtil.strToDate(today + " 23:59:59", DateUtil.YYYY_MM_DD_HH_MM_SS);
//        int smsCount = smsDao.countByMobile(mobile,begin,end);
//        if(smsCount>=5){
//            return Envelop.getError("您的验证码次数已用完,请明天再尝试!",-1);
//        }
//        // 2、60秒之内不允许重复发送
////        PageRequest pageRequest = new PageRequest(0, 1, new Sort(Sort.Direction.DESC, "id"));
//        List<BaseSmsDO> page = smsDao.findByMobileType(mobile,type,saasId);
//        if (page.size()>0) {
////            for (BaseSmsDO sms : page) {
////                if (sms == null) {
////                    continue;
////                }
//                // 计算间隔时间
//                Date temp = DateUtil.getNextMin(page.get(0).getCreateTime(), 1);
//                long leftTime = (temp.getTime() - System.currentTimeMillis()) / 1000;
//                if (leftTime > 0) {
//                    return BaseEnvelop.getError("发送短信验证码间隔时间为:60秒!");
//                }
////            }
//        }
//        //3、生成验证码
//        ValidateCode vc = SmsValidateCodeUtils.generate(6,1);
//
//        return smsDao.save(sms);
//        //4、保存验证码(1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录)
//        BaseSmsDO sms = new BaseSmsDO();
//        sms.setMobile(mobile);
//        sms.setIp(ip);
//        sms.setType(type);
//        sms.setCaptcha(vc.getCode());
//        switch (type){
//            case 1:sms.setContent("您的注册验证码为:"+vc.getCode());break;
//            case 2:sms.setContent("您找回密码验证码为:"+vc.getCode());break;
//            case 3:sms.setContent("您找回密码验证码为:"+vc.getCode());break;
//        }
//        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
//        sms.setDeadline(s.parse(vc.getCreateTimeString()));
//        sms.setStatus(1);
//        sms.setSaasId(saasId);
//        //5、 调用发送信息的接口
////        String result = httpClientUtil.post(smsHttpVo.getUrl(), buildSmsParams(sms.getContent(), mobile), "GBK");
////        JSONObject json = toJson(result);
////        if (json == null) {
////            // 发送失败
////            return BaseEnvelop.getError("短信接口请求失败!");
////        } else if (json.getInt("result") != 0) {
////            return BaseEnvelop.getError(json.getString("description"));
////        } else {
////            //发送成功,保存到数据库
////        }
//        smsDao.save(sms);
//        if(smsCount>=2&&smsCount<=5){
//           return  BaseEnvelop.getSuccess("今日可重发验证码剩余"+(5-smsCount)+"次,请尽快完成验证。!");
//        }
//        return BaseEnvelop.getSuccess("验证码发送成功!");
//    }
//
//    @Transactional
//    public BaseSmsDO updateSms(BaseSmsDO sms) {
//        return smsDao.save(sms);
//    //封装发送短信的参数
//    public  List<NameValuePair> buildSmsParams(String content, String mobile) {
//        List<NameValuePair> params = new ArrayList<NameValuePair>();
//        params.add(new BasicNameValuePair("SpCode", smsHttpVo.getCode()));
//        params.add(new BasicNameValuePair("LoginName", smsHttpVo.getName()));
//        params.add(new BasicNameValuePair("Password", smsHttpVo.getPassword()));
//        params.add(new BasicNameValuePair("MessageContent", content));
//        params.add(new BasicNameValuePair("UserNumber", mobile));
//        params.add(new BasicNameValuePair("SerialNumber", String.valueOf(System.currentTimeMillis())));
//        params.add(new BasicNameValuePair("ScheduleTime", ""));
//        params.add(new BasicNameValuePair("f", "1"));
//        return params;
//    }
    /**
     * 发送验证码(不走权限判断,包括:注册、找回密码)
     * @param mobile
     * @param ip
     * @param type
     * @return
     * @throws Exception
     */
    @Transactional
    public BaseEnvelop send(String mobile, String ip, int type,String saasId) throws Exception {
        // 1、同一手机一天不允许超过5条短信
        //1.1获取一天的开始和结束时间
        String today = DateUtil.getStringDateShort();
        Date begin = DateUtil.strToDate(today + " 00:00:00", DateUtil.YYYY_MM_DD_HH_MM_SS);
        Date end = DateUtil.strToDate(today + " 23:59:59", DateUtil.YYYY_MM_DD_HH_MM_SS);
        int smsCount = smsDao.countByMobile(mobile,begin,end);
        if(smsCount>=5){
            return Envelop.getError("您的验证码次数已用完,请明天再尝试!",-1);
        }
        // 2、60秒之内不允许重复发送
//
//    //校验验证码是否正确
//    public Envelop checkSms(String mobile,String saasId,int type,String captcha){
//        PageRequest pageRequest = new PageRequest(0, 1, new Sort(Sort.Direction.DESC, "id"));
        List<BaseSmsDO> page = smsDao.findByMobileType(mobile,type,saasId);
        if (page.size()>0) {
//            for (BaseSmsDO sms : page) {
//                if (sms == null) {
//        List<BaseSmsDO> page = smsDao.findByMobileType(mobile,type,saasId);
////        if (page != null) {
////            for (BaseSmsDO sms : page) {
//                BaseSmsDO sms = page.get(0);
//                String toCaptcha = sms.getCaptcha();
//                Date deadline = sms.getDeadline();
//                if(new Date().before(deadline)){
//                    //对比校验码是否正确
//                    if(captcha.equals(toCaptcha)){
//                        Envelop.getSuccess("验证码校验成功!");
//                    }else{
//                        return Envelop.getError("验证码错误!");
//                    }
//                }else{
//                    //过期
//                    return Envelop.getError("验证码过期!");
//                }
//
////            }
////        }
//        return Envelop.getError("未发送验证码!");
//    }
//
//    //解析短信返回的json数据
//    public JSONObject toJson(String result) {
//        JSONObject json = new JSONObject();
//        try {
//            String[] temps = result.split("&");
//            for (String temp : temps) {
//                if (temp.split("=").length != 2) {
//                    continue;
//                }
                // 计算间隔时间
                Date temp = DateUtil.getNextMin(page.get(0).getCreateTime(), 1);
                long leftTime = (temp.getTime() - System.currentTimeMillis()) / 1000;
                if (leftTime > 0) {
                    return BaseEnvelop.getError("发送短信验证码间隔时间为:60秒!");
                }
//                String key = temp.split("=")[0];
//                String value = temp.split("=")[1];
//                json.put(key, value);
//            }
        }
        //3、生成验证码
        ValidateCode vc = SmsValidateCodeUtils.generate(6,1);
        //4、保存验证码(1微信端注册,2微信端找回密码,3医生端找回密码,4患者登录,5医生登录)
        BaseSmsDO sms = new BaseSmsDO();
        sms.setMobile(mobile);
        sms.setIp(ip);
        sms.setType(type);
        sms.setCaptcha(vc.getCode());
        switch (type){
            case 1:sms.setContent("您的注册验证码为:"+vc.getCode());break;
            case 2:sms.setContent("您找回密码验证码为:"+vc.getCode());break;
            case 3:sms.setContent("您找回密码验证码为:"+vc.getCode());break;
        }
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        sms.setDeadline(s.parse(vc.getCreateTimeString()));
        sms.setStatus(1);
        sms.setSaasId(saasId);
        //5、 调用发送信息的接口
//        String result = httpClientUtil.post(smsHttpVo.getUrl(), buildSmsParams(sms.getContent(), mobile), "GBK");
//        JSONObject json = toJson(result);
//        if (json == null) {
//            // 发送失败
//            return BaseEnvelop.getError("短信接口请求失败!");
//        } else if (json.getInt("result") != 0) {
//            return BaseEnvelop.getError(json.getString("description"));
//        } else {
//            //发送成功,保存到数据库
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        smsDao.save(sms);
        if(smsCount>=2&&smsCount<=5){
           return  BaseEnvelop.getSuccess("今日可重发验证码剩余"+(5-smsCount)+"次,请尽快完成验证。!");
        }
        return BaseEnvelop.getSuccess("验证码发送成功!");
    }
    //封装发送短信的参数
    public  List<NameValuePair> buildSmsParams(String content, String mobile) {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("SpCode", smsHttpVo.getCode()));
        params.add(new BasicNameValuePair("LoginName", smsHttpVo.getName()));
        params.add(new BasicNameValuePair("Password", smsHttpVo.getPassword()));
        params.add(new BasicNameValuePair("MessageContent", content));
        params.add(new BasicNameValuePair("UserNumber", mobile));
        params.add(new BasicNameValuePair("SerialNumber", String.valueOf(System.currentTimeMillis())));
        params.add(new BasicNameValuePair("ScheduleTime", ""));
        params.add(new BasicNameValuePair("f", "1"));
        return params;
    }
    //校验验证码是否正确
    public Envelop checkSms(String mobile,String saasId,int type,String captcha){
        PageRequest pageRequest = new PageRequest(0, 1, new Sort(Sort.Direction.DESC, "id"));
        List<BaseSmsDO> page = smsDao.findByMobileType(mobile,type,saasId);
//        if (page != null) {
//            for (BaseSmsDO sms : page) {
                BaseSmsDO sms = page.get(0);
                String toCaptcha = sms.getCaptcha();
                Date deadline = sms.getDeadline();
                if(new Date().before(deadline)){
                    //对比校验码是否正确
                    if(captcha.equals(toCaptcha)){
                        Envelop.getSuccess("验证码校验成功!");
                    }else{
                        return Envelop.getError("验证码错误!");
                    }
                }else{
                    //过期
                    return Envelop.getError("验证码过期!");
                }
//            }
//        }
        return Envelop.getError("未发送验证码!");
    }
    //解析短信返回的json数据
    public JSONObject toJson(String result) {
        JSONObject json = new JSONObject();
        try {
            String[] temps = result.split("&");
            for (String temp : temps) {
                if (temp.split("=").length != 2) {
                    continue;
                }
                String key = temp.split("=")[0];
                String value = temp.split("=")[1];
                json.put(key, value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}
//        return json;
//    }
//
//
//}

+ 49 - 49
svr/svr-base/src/main/java/com/yihu/jw/business/sms/vo/SMSHttpVo.java

@ -1,49 +1,49 @@
package com.yihu.jw.business.sms.vo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
 * Created by 刘文彬 on 2018/4/13.
 */
@Component
@ConfigurationProperties(prefix = "jw.sms")
public class SMSHttpVo {
    private String url;
    private String code;
    private String name;
    private String password;
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}
//package com.yihu.jw.business.sms.vo;
//
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.stereotype.Component;
//
///**
// * Created by 刘文彬 on 2018/4/13.
// */
//@Component
//@ConfigurationProperties(prefix = "jw.sms")
//public class SMSHttpVo {
//
//    private String url;
//    private String code;
//    private String name;
//    private String password;
//
//    public String getUrl() {
//        return url;
//    }
//
//    public void setUrl(String url) {
//        this.url = url;
//    }
//
//    public String getCode() {
//        return code;
//    }
//
//    public void setCode(String code) {
//        this.code = code;
//    }
//
//    public String getName() {
//        return name;
//    }
//
//    public void setName(String name) {
//        this.name = name;
//    }
//
//    public String getPassword() {
//        return password;
//    }
//
//    public void setPassword(String password) {
//        this.password = password;
//    }
//}

+ 6 - 2
svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/BaseRoleController.java

@ -1,9 +1,13 @@
package com.yihu.jw.business.user.contorller;
import com.yihu.jw.entity.base.user.RoleDO;
import com.yihu.jw.base.user.BaseEmployRoleDO;
import com.yihu.jw.base.user.BaseMenuDO;
import com.yihu.jw.base.user.BaseRoleDO;
import com.yihu.jw.base.user.BaseRoleMenuDO;
import com.yihu.jw.business.user.service.BaseRoleService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.restmodel.base.user.BaseEmployVO;
import com.yihu.jw.restmodel.base.user.BaseRoleVO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
@ -151,7 +155,7 @@ public class BaseRoleController extends EnvelopRestController {
    public Envelop getPhoneAndSaasId(@ApiParam(name = "phone", value = "电话号码(账号)") @RequestParam(value = "phone", required = true) String phone,
                                     @ApiParam(name = "saasId", value = "saasId") @RequestParam(value = "saasId", required = true) String saasId){
        try{
            List<RoleDO> result = baseRoleService.findByPhoneAndSaasId(phone,saasId);
            List<BaseRoleDO> result = baseRoleService.findByPhoneAndSaasId(phone,saasId);
            return Envelop.getSuccess("获取数据成功!",result);
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());

+ 180 - 176
svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/EmployController.java

@ -1,195 +1,199 @@
package com.yihu.jw.business.user.contorller;
import com.yihu.jw.entity.base.user.EmployDO;
import com.yihu.jw.business.user.service.EmployService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.restmodel.base.user.BaseEmployVO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.base.BaseUserRequestMapping;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by chenweida on 2017/5/11.
 */
@RestController
@RequestMapping(BaseUserRequestMapping.api_user_common)
@Api(description = "医生,行政人员等非患者用户(基础用户)")
public class EmployController extends EnvelopRestController {
    @Autowired
    private EmployService employService;
    @PostMapping(value = BaseUserRequestMapping.BaseEmploy.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建用户", notes = "创建单个用户")
    public Envelop createBaseEmployDO(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            EmployDO baseEmployDO = toEntity(jsonData,EmployDO.class);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_create,employService.createBaseEmployDO(baseEmployDO));
        } catch (Exception e){
            return Envelop.getError(e.getMessage());
        }
    }
//    @PostMapping(value = BaseUserRequestMapping.BaseEmploy.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "修改用户", notes = "修改用户")
//    public Envelop updateBaseEmployDO(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
//package com.yihu.jw.business.user.contorller;
//
//import com.yihu.jw.base.base.FunctionDO;
//import com.yihu.jw.base.user.BaseEmployDO;
//import com.yihu.jw.base.user.BaseEmployRoleDO;
//import com.yihu.jw.business.user.service.EmployService;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.restmodel.base.base.FunctionVO;
//import com.yihu.jw.restmodel.base.user.BaseEmployVO;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//import com.yihu.jw.rm.base.BaseRequestMapping;
//import com.yihu.jw.rm.base.BaseUserRequestMapping;
//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.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.text.ParseException;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/11.
// */
//@RestController
//@RequestMapping(BaseUserRequestMapping.api_user_common)
//@Api(description = "医生,行政人员等非患者用户(基础用户)")
//public class EmployController extends EnvelopRestController {
//    @Autowired
//    private EmployService employService;
//
//    @PostMapping(value = BaseUserRequestMapping.BaseEmploy.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "创建用户", notes = "创建单个用户")
//    public Envelop createBaseEmployDO(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
//        try{
//            BaseEmployDO baseEmployDO = toEntity(jsonData,BaseEmployDO.class);
//            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_update,employService.updateBaseEmployDO(baseEmployDO));
//            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_create,employService.createBaseEmployDO(baseEmployDO));
//        } catch (Exception e){
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
////    @PostMapping(value = BaseUserRequestMapping.BaseEmploy.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
////    @ApiOperation(value = "修改用户", notes = "修改用户")
////    public Envelop updateBaseEmployDO(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
////        try{
////            BaseEmployDO baseEmployDO = toEntity(jsonData,BaseEmployDO.class);
////            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_update,employService.updateBaseEmployDO(baseEmployDO));
////        } catch (ApiException e){
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
//    @ApiOperation(value = "根据id查找用户")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getById)
//    public Envelop getEmployeeById(@ApiParam(name = "id", value = "id", required = true) @RequestParam(value = "id", required = true) String id) {
//        try{
//            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find,this.employService.findById(id));
//        } catch (ApiException e){
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
    @ApiOperation(value = "根据id查找用户")
    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getById)
    public Envelop getEmployeeById(@ApiParam(name = "id", value = "id", required = true) @RequestParam(value = "id", required = true) String id) {
        try{
            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find,this.employService.findById(id));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @ApiOperation(value = "根据saasId查找所有用户")
    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getListBySaasId)
    public Envelop getAllEmployeeBySaasId(@ApiParam(name = "saasId", value = "saasId", required = true) @RequestParam(value = "saasId", required = true) String saasId) {
        try{
            return Envelop.getSuccessList(BaseUserRequestMapping.BaseEmploy.message_success_find,this.employService.findAllBySaasId(saasId));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @ApiOperation(value = "根据手机号和saasId查找用户")
    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getByPhone)
    public Envelop getEmployeeByPhoneAndSaasId(@ApiParam(name = "phone", value = "phone", required = true) @RequestParam(value = "phone", required = true) String phone,
                                               @ApiParam(name = "saasId", value = "saasId", required = true) @RequestParam(value = "saasId", required = true) String saasId) {
        try {
            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find, this.employService.findByPhoneAndSaasId(phone,saasId));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @ApiOperation(value = "根据name模糊查询某saasId平台下的所有用户")
    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getListByName)
    public Envelop getListByNameAndSaasId(@ApiParam(name = "saasId", value = "saasId", required = true) @RequestParam(value = "saasId", required = true) String saasId,
                                          @ApiParam(name = "name", value = "name", required = true) @RequestParam(value = "name", required = true) String name) {
        try{
            return Envelop.getSuccessList(BaseUserRequestMapping.BaseEmploy.message_success_find,this.employService.findAllByNameAndSaasId(name,saasId));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @ApiOperation(value = "根据指定条件查询用户列表,分页")
    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getListNoPage)
    public Envelop getListPageByNameAndSaasId(@ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,name,sex,photo,skill,email,phone,family_tel,introduction,jxzc,lczc,xlzc,xzzc") @RequestParam(value = "fields", required = false) String fields,
                                              @ApiParam(name = "filters", value = "过滤器,为空检索所有条件") @RequestParam(value = "filters", required = false) String filters,
                                              @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime") @RequestParam(value = "sorts", required = false) String sorts,
                                              @ApiParam(name = "size", value = "分页大小", defaultValue = "15") @RequestParam(value = "size", required = false) int size,
                                              @ApiParam(name = "page", value = "页码", defaultValue = "1") @RequestParam(value = "page", required = false) int page,
                                              HttpServletRequest request, HttpServletResponse response) throws ParseException {
        if (StringUtils.isBlank(filters)) {
            return Envelop.getError(BaseUserRequestMapping.BaseEmploy.message_fail_params_not_present, ExceptionCode.common_error_params_code);
        } else {
            filters = "status<>-1;" + filters;
        }
        if (StringUtils.isBlank(sorts)) {
            sorts = "-updateTime";
        }
        //得到list数据
        List<BaseEmployVO> list = employService.search(fields, filters, sorts, page, size);
        //获取总数
        long count = employService.getCount(filters);
        //封装头信息
        pagedResponse(request, response, count, page, size);
        //封装返回格式
        List<BaseEmployVO> mFunctions = convertToModels(list, new ArrayList<>(list.size()), BaseEmployVO.class, fields);
        return Envelop.getSuccessListWithPage(BaseUserRequestMapping.BaseEmploy.message_success_find, mFunctions, page, size, count);
    }
//    @ApiOperation(value = "给某一用户新增角色")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_create)
//    public Envelop createEmployRoles(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String employId,
//                                     @ApiParam(name = "roleIds", value = "roleIds", required = true) @RequestParam(value = "roleIds", required = true) String roleIds) {
//        try {
//            String[] roleIdArray = roleIds.split(",");
//            List<BaseEmployRoleDO> list = new ArrayList<>();
//            for (String roleId : roleIdArray) {
//                BaseEmployRoleDO baseEmployRoleDO = new BaseEmployRoleDO();
//                baseEmployRoleDO.setEmployId(employId);
//                baseEmployRoleDO.setRoleId(roleId);
//                list.add(baseEmployRoleDO);
//            }
//            if (roleIdArray.length < 1) {
//                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find, this.employRoleService.createBaseEmployRoleDO(list.get(0)));
//            }else{
//                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find, this.employRoleService.createBatchBaseEmployRoleDO(list));
//            }
//        } catch (ApiException e) {
//
//    @ApiOperation(value = "根据saasId查找所有用户")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getListBySaasId)
//    public Envelop getAllEmployeeBySaasId(@ApiParam(name = "saasId", value = "saasId", required = true) @RequestParam(value = "saasId", required = true) String saasId) {
//        try{
//            return Envelop.getSuccessList(BaseUserRequestMapping.BaseEmploy.message_success_find,this.employService.findAllBySaasId(saasId));
//        } catch (ApiException e){
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//    @ApiOperation(value = "修改用户角色")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_update)
//    public Envelop updateEmployRole(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String id,
//                                    @ApiParam(name = "roleId", value = "roleId", required = true) @RequestParam(value = "roleId", required = true) String newRoleId) {
//
//
//    @ApiOperation(value = "根据手机号和saasId查找用户")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getByPhone)
//    public Envelop getEmployeeByPhoneAndSaasId(@ApiParam(name = "phone", value = "phone", required = true) @RequestParam(value = "phone", required = true) String phone,
//                                               @ApiParam(name = "saasId", value = "saasId", required = true) @RequestParam(value = "saasId", required = true) String saasId) {
//        try {
//            BaseEmployRoleDO baseEmployRoleDO = new BaseEmployRoleDO();
//            baseEmployRoleDO.setId(id);
//            baseEmployRoleDO.setRoleId(newRoleId);
//            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_delete, this.employRoleService.updateBaseEmployRoleDO(baseEmployRoleDO));
//            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find, this.employService.findByPhoneAndSaasId(phone,saasId));
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//    @ApiOperation(value = "查看用户角色列表,不分页")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_getListNoPage)
//    public Envelop findEmployRoleList(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String employId) {
//        try {
//            return Envelop.getSuccessList(BaseUserRequestMapping.BaseEmploy.message_success_delete, this.employRoleService.findAllByEmployId(employId));
//        } catch (ApiException e) {
//
//    @ApiOperation(value = "根据name模糊查询某saasId平台下的所有用户")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getListByName)
//    public Envelop getListByNameAndSaasId(@ApiParam(name = "saasId", value = "saasId", required = true) @RequestParam(value = "saasId", required = true) String saasId,
//                                          @ApiParam(name = "name", value = "name", required = true) @RequestParam(value = "name", required = true) String name) {
//        try{
//            return Envelop.getSuccessList(BaseUserRequestMapping.BaseEmploy.message_success_find,this.employService.findAllByNameAndSaasId(name,saasId));
//        } catch (ApiException e){
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//    @ApiOperation(value = "删除用户角色")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_delete)
//    public Envelop deleteEmployRoles(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String employId,
//                                     @ApiParam(name = "roleIds", value = "roleIds", required = true) @RequestParam(value = "roleIds", required = true) String roleIds) {
//        try {
//            String[] idArray = roleIds.split(",");
//            if (idArray.length < 1) {
//                this.employRoleService.deleteBaseEmployRoleDO(employId,roleIds);
//                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_delete,"删除单个角色");
//            }else{
//                this.employRoleService.deleteBatchBaseEmployRoleDO(employId,roleIds);
//                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_delete, "删除多个角色");
//            }
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//
//    @ApiOperation(value = "根据指定条件查询用户列表,分页")
//    @GetMapping(value = BaseUserRequestMapping.BaseEmploy.api_getListNoPage)
//    public Envelop getListPageByNameAndSaasId(@ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,name,sex,photo,skill,email,phone,family_tel,introduction,jxzc,lczc,xlzc,xzzc") @RequestParam(value = "fields", required = false) String fields,
//                                              @ApiParam(name = "filters", value = "过滤器,为空检索所有条件") @RequestParam(value = "filters", required = false) String filters,
//                                              @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime") @RequestParam(value = "sorts", required = false) String sorts,
//                                              @ApiParam(name = "size", value = "分页大小", defaultValue = "15") @RequestParam(value = "size", required = false) int size,
//                                              @ApiParam(name = "page", value = "页码", defaultValue = "1") @RequestParam(value = "page", required = false) int page,
//                                              HttpServletRequest request, HttpServletResponse response) throws ParseException {
//        if (StringUtils.isBlank(filters)) {
//            return Envelop.getError(BaseUserRequestMapping.BaseEmploy.message_fail_params_not_present, ExceptionCode.common_error_params_code);
//        } else {
//            filters = "status<>-1;" + filters;
//        }
//        if (StringUtils.isBlank(sorts)) {
//            sorts = "-updateTime";
//        }
//
//        //得到list数据
//        List<BaseEmployVO> list = employService.search(fields, filters, sorts, page, size);
//
//        //获取总数
//        long count = employService.getCount(filters);
//        //封装头信息
//        pagedResponse(request, response, count, page, size);
//        //封装返回格式
//        List<BaseEmployVO> mFunctions = convertToModels(list, new ArrayList<>(list.size()), BaseEmployVO.class, fields);
//
//        return Envelop.getSuccessListWithPage(BaseUserRequestMapping.BaseEmploy.message_success_find, mFunctions, page, size, count);
//    }
}
//
//
////    @ApiOperation(value = "给某一用户新增角色")
////    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_create)
////    public Envelop createEmployRoles(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String employId,
////                                     @ApiParam(name = "roleIds", value = "roleIds", required = true) @RequestParam(value = "roleIds", required = true) String roleIds) {
////        try {
////            String[] roleIdArray = roleIds.split(",");
////            List<BaseEmployRoleDO> list = new ArrayList<>();
////            for (String roleId : roleIdArray) {
////                BaseEmployRoleDO baseEmployRoleDO = new BaseEmployRoleDO();
////                baseEmployRoleDO.setEmployId(employId);
////                baseEmployRoleDO.setRoleId(roleId);
////                list.add(baseEmployRoleDO);
////            }
////            if (roleIdArray.length < 1) {
////                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find, this.employRoleService.createBaseEmployRoleDO(list.get(0)));
////            }else{
////                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_find, this.employRoleService.createBatchBaseEmployRoleDO(list));
////            }
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
////    @ApiOperation(value = "修改用户角色")
////    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_update)
////    public Envelop updateEmployRole(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String id,
////                                    @ApiParam(name = "roleId", value = "roleId", required = true) @RequestParam(value = "roleId", required = true) String newRoleId) {
////        try {
////            BaseEmployRoleDO baseEmployRoleDO = new BaseEmployRoleDO();
////            baseEmployRoleDO.setId(id);
////            baseEmployRoleDO.setRoleId(newRoleId);
////            return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_delete, this.employRoleService.updateBaseEmployRoleDO(baseEmployRoleDO));
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
////    @ApiOperation(value = "查看用户角色列表,不分页")
////    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_getListNoPage)
////    public Envelop findEmployRoleList(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String employId) {
////        try {
////            return Envelop.getSuccessList(BaseUserRequestMapping.BaseEmploy.message_success_delete, this.employRoleService.findAllByEmployId(employId));
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//
////    @ApiOperation(value = "删除用户角色")
////    @GetMapping(value = BaseUserRequestMapping.BaseEmployRole.api_delete)
////    public Envelop deleteEmployRoles(@ApiParam(name = "employId", value = "employId", required = true) @RequestParam(value = "employId", required = true) String employId,
////                                     @ApiParam(name = "roleIds", value = "roleIds", required = true) @RequestParam(value = "roleIds", required = true) String roleIds) {
////        try {
////            String[] idArray = roleIds.split(",");
////            if (idArray.length < 1) {
////                this.employRoleService.deleteBaseEmployRoleDO(employId,roleIds);
////                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_delete,"删除单个角色");
////            }else{
////                this.employRoleService.deleteBatchBaseEmployRoleDO(employId,roleIds);
////                return Envelop.getSuccess(BaseUserRequestMapping.BaseEmploy.message_success_delete, "删除多个角色");
////            }
////        } catch (ApiException e) {
////            return Envelop.getError(e.getMessage(), e.getErrorCode());
////        }
////    }
//}

+ 11 - 11
svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/BaseRoleDao.java

@ -1,6 +1,6 @@
package com.yihu.jw.business.user.dao;
import com.yihu.jw.entity.base.user.RoleDO;
import com.yihu.jw.base.user.BaseRoleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -10,22 +10,22 @@ import java.util.List;
/**
 * Created by LiTaohong on 2017/11/28.
 */
public interface BaseRoleDao extends PagingAndSortingRepository<RoleDO, String>, JpaSpecificationExecutor<RoleDO> {
public interface BaseRoleDao extends PagingAndSortingRepository<BaseRoleDO, String>, JpaSpecificationExecutor<BaseRoleDO> {
    @Query("from RoleDO b where b.id = ?1")
    RoleDO findOneById(String id);
    @Query("from BaseRoleDO b where b.id = ?1")
    BaseRoleDO findOneById(String id);
    //角色与saasId为一对多关系
    @Query("from RoleDO b where b.saasId = ?1")
    List<RoleDO> findAllBySaasId(String saasId);
    @Query("from BaseRoleDO b where b.saasId = ?1")
    List<BaseRoleDO> findAllBySaasId(String saasId);
    @Query("from RoleDO b where b.saasId = ?1 and b.name = ?2")
    RoleDO findOneBySaasIdAndName(String saasId, String name);
    @Query("from BaseRoleDO b where b.saasId = ?1 and b.name = ?2")
    BaseRoleDO findOneBySaasIdAndName(String saasId,String name);
    @Query("from RoleDO b where b.name like %?1%")
    List<RoleDO> findAllByName(String name);
    @Query("from BaseRoleDO b where b.name like %?1%")
    List<BaseRoleDO> findAllByName(String name);
    @Query(value="select b.* from base_role b,base_employ e,base_employ_role r where r.role_id=b.id and r.employ_id=e.id and e.phone= ?1 and e.saas_id= ?2",nativeQuery = true)
    List<RoleDO> findByPhoneAndSaasId(String phone, String saasId);
    List<BaseRoleDO> findByPhoneAndSaasId(String phone,String saasId);
}

+ 27 - 27
svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/EmployDao.java

@ -1,27 +1,27 @@
package com.yihu.jw.business.user.dao;
import com.yihu.jw.entity.base.user.EmployDO;
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 chenweida on 2017/11/28.
 */
/**
 * 基础用户类接口
 */
public interface EmployDao extends PagingAndSortingRepository<EmployDO, String>, JpaSpecificationExecutor<EmployDO> {
    @Query("from EmployDO ba where ba.saasId = ?1")
    List<EmployDO> findAllBySaasId(String saasId);
    @Query("from EmployDO ba where ba.name like ?1 and ba.saasId = ?2")
    List<EmployDO> findAllByNameAndSaasId(String name, String saasId);
    @Query("from EmployDO ba where ba.phone = ?1 and ba.saasId = ?2")
    EmployDO findByPhoneAndSaasId(String phone, String saasId);
}
//package com.yihu.jw.business.user.dao;
//
//import com.yihu.jw.base.user.BaseEmployDO;
//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 chenweida on 2017/11/28.
// */
//
///**
// * 基础用户类接口
// */
//public interface EmployDao extends PagingAndSortingRepository<BaseEmployDO, String>, JpaSpecificationExecutor<BaseEmployDO> {
//
//    @Query("from BaseEmployDO ba where ba.saasId = ?1")
//    List<BaseEmployDO> findAllBySaasId(String saasId);
//
//    @Query("from BaseEmployDO ba where ba.name like ?1 and ba.saasId = ?2")
//    List<BaseEmployDO> findAllByNameAndSaasId(String name,String saasId);
//
//    @Query("from BaseEmployDO ba where ba.phone = ?1 and ba.saasId = ?2")
//    BaseEmployDO findByPhoneAndSaasId(String phone,String saasId);
//}

+ 182 - 179
svr/svr-base/src/main/java/com/yihu/jw/business/user/service/BaseRoleService.java

@ -1,179 +1,182 @@
package com.yihu.jw.business.user.service;
import com.yihu.jw.entity.base.user.RoleDO;
import com.yihu.jw.business.user.dao.BaseRoleDao;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.rm.base.BaseUserRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
/**
 * Created by LiTaohong on 2017/11/28.
 * 基础角色功能
 */
@Service
public class BaseRoleService extends BaseJpaService<RoleDO,BaseRoleDao> {
    @Autowired
    private BaseRoleDao baseRoleDao;
    /**
     * 创建role
     * @param baseRoleDO
     * @return
     */
    @Transactional
    public RoleDO createBaseRole(RoleDO baseRoleDO){
        if (StringUtils.isEmpty(baseRoleDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getName())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_name_is_null, ExceptionCode.common_error_params_code);
        }
        return this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 更新role
     * @param baseRoleDO
     * @return
     */
    @Transactional
    public RoleDO updateBaseRole(RoleDO baseRoleDO){
        if (StringUtils.isEmpty(baseRoleDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        return this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 根据roleId查询role
     * @param id
     * @return
     */
    public RoleDO findById(String id){
        if (StringUtils.isEmpty(id)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null,ExceptionCode.common_error_params_code);
        }
        RoleDO baseRoleDO = this.baseRoleDao.findOneById(id);
        if (null == baseRoleDO) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_no_exist,ExceptionCode.common_error_params_code);
        }
        return baseRoleDO;
    }
    /**
     * 查询某要saasId平台下的所有role
     * @param saasId
     * @return
     */
    public List<RoleDO> findAllBySaasId(String saasId){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
        }
        List<RoleDO> list = this.baseRoleDao.findAllBySaasId(saasId);
        if (null == list || list.size() == 0) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
        }
        return list;
    }
    /**
     * 查找某一平台下某一个role
     * @param saasId
     * @param name
     * @return
     */
    public RoleDO findBySaasIdAndName(String saasId, String name){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(name)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_name_is_null,ExceptionCode.common_error_params_code);
        }
        RoleDO baseRoleDO = this.baseRoleDao.findOneBySaasIdAndName(name,saasId);
        if (null == baseRoleDO) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_role_no_exist,ExceptionCode.common_error_params_code);
        }
        return baseRoleDO;
    }
    /**
     * 根据name查询所有的role,包括不同平台saasid的
     * @param name
     * @return
     */
    public List<RoleDO> getRoleListByName(String name){
        if (StringUtils.isEmpty(name)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_name_is_null,ExceptionCode.common_error_params_code);
        }
        List<RoleDO> list = this.baseRoleDao.findAllByName(name);
        if (null == list || list.size() == 0) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_role_no_exist,ExceptionCode.common_error_params_code);
        }
        return list;
    }
    /**
     * 根据roleId删除role
     * @param baseRoleDO
     */
    @Transactional
    public void deleteBaseRole(RoleDO baseRoleDO){
        if (StringUtils.isEmpty(baseRoleDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 删除某一saasId相关的所有role
     * @param saasId
     */
    @Transactional
    public void deleteBaseRolesBySaasId(String saasId){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        List<RoleDO> list = this.baseRoleDao.findAllBySaasId(saasId);
        for(RoleDO baseRoleDO:list){
        }
        this.baseRoleDao.save(list);
    }
    /**
     * 根据saasId和name删除角色
     * @param saasId
     * @param name
     */
    @Transactional
    public void deleteBaseRoleByNameAndSaasId(String saasId,String name){
        RoleDO baseRoleDO = this.findBySaasIdAndName(saasId,name);
        this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 根据phone(账号)和saasId查询角色列表
     * @param phone
     * @param saasId
     * @return
     */
    public List<RoleDO> findByPhoneAndSaasId(String phone, String saasId){
        return this.baseRoleDao.findByPhoneAndSaasId(phone,saasId);
    }
}
//package com.yihu.jw.business.user.service;
//
//import com.yihu.jw.base.user.BaseRoleDO;
//import com.yihu.jw.business.user.dao.BaseRoleDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.rm.base.BaseUserRequestMapping;
//import com.yihu.mysql.query.BaseJpaService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.StringUtils;
//
//import java.util.List;
//
///**
// * Created by LiTaohong on 2017/11/28.
// * 基础角色功能
// */
//@Service
//public class BaseRoleService extends BaseJpaService<BaseRoleDO,BaseRoleDao> {
//    @Autowired
//    private BaseRoleDao baseRoleDao;
//
//    /**
//     * 创建role
//     * @param baseRoleDO
//     * @return
//     */
//    @Transactional
//    public BaseRoleDO createBaseRole(BaseRoleDO baseRoleDO){
//        if (StringUtils.isEmpty(baseRoleDO.getId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(baseRoleDO.getName())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        return this.baseRoleDao.save(baseRoleDO);
//    }
//
//    /**
//     * 更新role
//     * @param baseRoleDO
//     * @return
//     */
//    @Transactional
//    public BaseRoleDO updateBaseRole(BaseRoleDO baseRoleDO){
//        if (StringUtils.isEmpty(baseRoleDO.getId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        return this.baseRoleDao.save(baseRoleDO);
//    }
//
//    /**
//     * 根据roleId查询role
//     * @param id
//     * @return
//     */
//    public BaseRoleDO findById(String id){
//        if (StringUtils.isEmpty(id)) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null,ExceptionCode.common_error_params_code);
//        }
//        BaseRoleDO baseRoleDO = this.baseRoleDao.findOneById(id);
//        if (null == baseRoleDO) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return baseRoleDO;
//    }
//
//    /**
//     * 查询某要saasId平台下的所有role
//     * @param saasId
//     * @return
//     */
//    public List<BaseRoleDO> findAllBySaasId(String saasId){
//        if (StringUtils.isEmpty(saasId)) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
//        }
//        List<BaseRoleDO> list = this.baseRoleDao.findAllBySaasId(saasId);
//        if (null == list || list.size() == 0) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return list;
//    }
//
//    /**
//     * 查找某一平台下某一个role
//     * @param saasId
//     * @param name
//     * @return
//     */
//    public BaseRoleDO findBySaasIdAndName(String saasId,String name){
//        if (StringUtils.isEmpty(saasId)) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(name)) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_name_is_null,ExceptionCode.common_error_params_code);
//        }
//        BaseRoleDO baseRoleDO = this.baseRoleDao.findOneBySaasIdAndName(name,saasId);
//        if (null == baseRoleDO) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_role_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return baseRoleDO;
//    }
//
//    /**
//     * 根据name查询所有的role,包括不同平台saasid的
//     * @param name
//     * @return
//     */
//    public List<BaseRoleDO> getRoleListByName(String name){
//        if (StringUtils.isEmpty(name)) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_name_is_null,ExceptionCode.common_error_params_code);
//        }
//        List<BaseRoleDO> list = this.baseRoleDao.findAllByName(name);
//        if (null == list || list.size() == 0) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_role_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return list;
//    }
//
//
//    /**
//     * 根据roleId删除role
//     * @param baseRoleDO
//     */
//    @Transactional
//    public void deleteBaseRole(BaseRoleDO baseRoleDO){
//        if (StringUtils.isEmpty(baseRoleDO.getId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        baseRoleDO.setStatus(-1);
//        this.baseRoleDao.save(baseRoleDO);
//    }
//
//    /**
//     * 删除某一saasId相关的所有role
//     * @param saasId
//     */
//    @Transactional
//    public void deleteBaseRolesBySaasId(String saasId){
//        if (StringUtils.isEmpty(saasId)) {
//            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        List<BaseRoleDO> list = this.baseRoleDao.findAllBySaasId(saasId);
//        for(BaseRoleDO baseRoleDO:list){
//            baseRoleDO.setStatus(-1);
//        }
//        this.baseRoleDao.save(list);
//    }
//
//    /**
//     * 根据saasId和name删除角色
//     * @param saasId
//     * @param name
//     */
//    @Transactional
//    public void deleteBaseRoleByNameAndSaasId(String saasId,String name){
//        BaseRoleDO baseRoleDO = this.findBySaasIdAndName(saasId,name);
//        baseRoleDO.setStatus(-1);
//        this.baseRoleDao.save(baseRoleDO);
//    }
//
//    /**
//     * 根据phone(账号)和saasId查询角色列表
//     * @param phone
//     * @param saasId
//     * @return
//     */
//    public List<BaseRoleDO> findByPhoneAndSaasId(String phone,String saasId){
//        return this.baseRoleDao.findByPhoneAndSaasId(phone,saasId);
//    }
//}

+ 153 - 147
svr/svr-base/src/main/java/com/yihu/jw/business/user/service/EmployService.java

@ -1,148 +1,154 @@
package com.yihu.jw.business.user.service;
import com.yihu.jw.entity.base.user.EmployDO;
import com.yihu.jw.business.user.dao.EmployDao;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.restmodel.common.base.BaseEnvelopStatus;
import com.yihu.jw.rm.base.BaseUserRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
/**
 * Created by chenweida on 2017/5/11.
 * 用户信息功能
 */
@Service
@EnableCaching
@CacheConfig(cacheNames = "employ")
public class EmployService extends BaseJpaService<EmployDO,EmployDao> {
    @Autowired
    private EmployDao employDao;
    /**
     * 创建用户
     * @param employeeDO
     * @return
     */
    @Cacheable(value = "employ#600#300")
    @Transactional
    public EmployDO createBaseEmployDO(EmployDO employeeDO){
        if (StringUtils.isEmpty(employeeDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(employeeDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        return this.employDao.save(employeeDO);
    }
    /**
     * 更新用户
     * @param employeeDO
     * @return
     */
    @CachePut(value = "employ#600#300",key = "#employeeDO.id")
    @Transactional
    public EmployDO updateBaseEmployDO(EmployDO employeeDO){
        if (StringUtils.isEmpty(employeeDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(employeeDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        return this.employDao.save(employeeDO);
    }
    /**
     * 根据Id查询用户
     * @param id
     * @return
     */
//package com.yihu.jw.business.user.service;
//
//import com.yihu.jw.base.user.BaseEmployDO;
//import com.yihu.jw.base.user.BaseRoleDO;
//import com.yihu.jw.business.user.dao.EmployDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.restmodel.common.base.BaseEnvelopStatus;
//import com.yihu.jw.rm.base.BaseUserRequestMapping;
//import com.yihu.mysql.query.BaseJpaService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cache.annotation.*;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.util.MultiValueMap;
//import org.springframework.util.StringUtils;
//
//import javax.servlet.Servlet;
//import java.util.List;
//
///**
// * Created by chenweida on 2017/5/11.
// * 用户信息功能
// */
//
//@Service
//@EnableCaching
//@CacheConfig(cacheNames = "employ")
//public class EmployService extends BaseJpaService<BaseEmployDO,EmployDao> {
//    @Autowired
//    private EmployDao employDao;
//
//    /**
//     * 创建用户
//     * @param employeeDO
//     * @return
//     */
//    @Cacheable(value = "employ#600#300")
//    @Transactional
//    public BaseEmployDO createBaseEmployDO(BaseEmployDO employeeDO){
//        if (StringUtils.isEmpty(employeeDO.getId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(employeeDO.getSaasId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        return this.employDao.save(employeeDO);
//    }
//
//    /**
//     * 更新用户
//     * @param employeeDO
//     * @return
//     */
//    @CachePut(value = "employ#600#300",key = "#employeeDO.id")
//    @Transactional
//    public BaseEmployDO updateBaseEmployDO(BaseEmployDO employeeDO){
//        if (StringUtils.isEmpty(employeeDO.getId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(employeeDO.getSaasId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        return this.employDao.save(employeeDO);
//    }
//
//    /**
//     * 根据Id查询用户
//     * @param id
//     * @return
//     */
////    @Cacheable(value = "employ#600#300",key = "#employeeDO.id")
//    public BaseEmployDO findById(String id){
//        if (StringUtils.isEmpty(id)) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null,ExceptionCode.common_error_params_code);
//        }
//        BaseEmployDO BaseEmployDO = this.employDao.findOne(id);
//        if (null == BaseEmployDO) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return BaseEmployDO;
//    }
//
//
//    /**
//     * 根据手机号和saasId查询用户,一个用户可能注册多个saas平台,所以根据手机号查找要限定saasId
//     * @param phone
//     * @param saasId
//     * @return
//     */
//    public BaseEmployDO findByPhoneAndSaasId(String phone,String saasId) throws ApiException{
//        BaseEmployDO BaseEmployDO = this.employDao.findByPhoneAndSaasId(phone,saasId);
//        if (null == BaseEmployDO) {
//            throw new ApiException(BaseEnvelopStatus.status_10100.getName(), BaseEnvelopStatus.status_10100.getCode());
//        }
//        return BaseEmployDO;
//    }
//
//    /**
//     * 查询某saasId平台下的所有用户
//     * @param saasId
//     * @return
//     */
//    @Cacheable(value = "employ#600#300",key = "#employeeDO.id")
    public EmployDO findById(String id){
        if (StringUtils.isEmpty(id)) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null,ExceptionCode.common_error_params_code);
        }
        EmployDO BaseEmployDO = this.employDao.findOne(id);
        if (null == BaseEmployDO) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_no_exist,ExceptionCode.common_error_params_code);
        }
        return BaseEmployDO;
    }
    /**
     * 根据手机号和saasId查询用户,一个用户可能注册多个saas平台,所以根据手机号查找要限定saasId
     * @param phone
     * @param saasId
     * @return
     */
    public EmployDO findByPhoneAndSaasId(String phone, String saasId) throws ApiException{
        EmployDO BaseEmployDO = this.employDao.findByPhoneAndSaasId(phone,saasId);
        if (null == BaseEmployDO) {
            throw new ApiException(BaseEnvelopStatus.status_10100.getName(), BaseEnvelopStatus.status_10100.getCode());
        }
        return BaseEmployDO;
    }
    /**
     * 查询某saasId平台下的所有用户
     * @param saasId
     * @return
     */
    @Cacheable(value = "employ#600#300",key = "#employeeDO.id")
    public List<EmployDO> findAllBySaasId(String saasId){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
        }
        List<EmployDO> list = this.employDao.findAllBySaasId(saasId);
        if (null == list || list.size() == 0) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
        }
        return list;
    }
    /**
     * 查询name模糊查询某saasId平台下的所有用户
     * @param saasId
     * @return
     */
    @Cacheable(value = "employ#600#300",key = "#employeeDO.id")
    public List<EmployDO> findAllByNameAndSaasId(String name, String saasId){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
        }
        List<EmployDO> list = this.employDao.findAllByNameAndSaasId(name,saasId);
        if (null == list || list.size() == 0) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
        }
        return list;
    }
    /**
     * 根据Id删除用户
     * @param employDO
     */
    @CacheEvict(key = "#employDO.id")
    @Transactional
    public void deleteBaseEmploy(EmployDO employDO){
        if (StringUtils.isEmpty(employDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(employDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        employDO.setStatus(-1);
        this.employDao.save(employDO);
    }
}
//    public List<BaseEmployDO> findAllBySaasId(String saasId){
//        if (StringUtils.isEmpty(saasId)) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
//        }
//        List<BaseEmployDO> list = this.employDao.findAllBySaasId(saasId);
//        if (null == list || list.size() == 0) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return list;
//    }
//
//    /**
//     * 查询name模糊查询某saasId平台下的所有用户
//     * @param saasId
//     * @return
//     */
//    @Cacheable(value = "employ#600#300",key = "#employeeDO.id")
//    public List<BaseEmployDO> findAllByNameAndSaasId(String name,String saasId){
//        if (StringUtils.isEmpty(saasId)) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
//        }
//        List<BaseEmployDO> list = this.employDao.findAllByNameAndSaasId(name,saasId);
//        if (null == list || list.size() == 0) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
//        }
//        return list;
//    }
//
//
//    /**
//     * 根据Id删除用户
//     * @param employDO
//     */
//    @CacheEvict(key = "#employDO.id")
//    @Transactional
//    public void deleteBaseEmploy(BaseEmployDO employDO){
//        if (StringUtils.isEmpty(employDO.getId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(employDO.getSaasId())) {
//            throw new ApiException(BaseUserRequestMapping.BaseEmploy.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
//        }
//        employDO.setStatus(-1);
//        this.employDao.save(employDO);
//    }
//
//}

+ 183 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WechatCoreController.java

@ -0,0 +1,183 @@
package com.yihu.jw.business.wx.controller;
import com.yihu.jw.base.wx.WxWechatDO;
import com.yihu.jw.business.wx.service.WechatCoreService;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.base.WechatRequestMapping;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;
/**
 * Created by Trick on 2018/8/16.
 */
@RestController
@RequestMapping(WechatRequestMapping.api_common)
@Api(value = "微信回调及事件处理", description = "微信回调及事件处理")
public class WechatCoreController extends EnvelopRestController {
    private Logger logger = LoggerFactory.getLogger(WechatCoreController.class);
    @Autowired
    private WechatCoreService wechatCoreService;
    /**
     * 微信接口验证
     *
     * @param request
     * @param response
     */
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public void checkSignature(HttpServletRequest request, HttpServletResponse response) {
        try {
            String signature = request.getParameter("signature").toString();
            String timestamp = request.getParameter("timestamp").toString();
            String nonce = request.getParameter("nonce").toString();
            String echostr = request.getParameter("echostr").toString();
            if (validate(signature, timestamp, nonce)) {
                // 验证成功,返回验证码
                response.getWriter().print(echostr);
            } else {
                // 验证失败
                response.setStatus(401);
            }
        } catch (Exception e) {
            // 服务器错误
            response.setStatus(500);
        }
    }
    /**
     * 接收居民微信回复的消息
     *
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public void receiveMessages(HttpServletRequest request, HttpServletResponse response) {
        try {
            String signature = request.getParameter("signature").toString();
            String timestamp = request.getParameter("timestamp").toString();
            String nonce = request.getParameter("nonce").toString();
            if (validate(signature, timestamp, nonce)) {
                String xmlStr = wechatCoreService.messageProcess(request);
                // 判断返回值是xml、json格式(取关是空串)
                Boolean flag = wechatCoreService.isXML(xmlStr);
                if (xmlStr == "error") {
                    // 服务器错误
                    response.setStatus(500);
                } else if (!flag && StringUtils.isNotEmpty(xmlStr)) {
                    JSONObject json = new JSONObject(xmlStr);
//                    if (json.has("openId")) {
//                        if (StringUtils.isNotEmpty(json.getString("openId")) && !("undefined".equals(json.getString("openId")))) {
//                            pushMsgTask.putWxMsg(getAccessToken(), json.getInt("type"), json.getString("openId"), null, json);
//                        }
//                    }
                } else {
                    // 返回消息(图文消息)
                    response.setHeader("Content-type", "text/html;charset=UTF-8");
                    //这句话的意思,是告诉servlet用UTF-8转码,而不是用默认的ISO8859
                    response.setCharacterEncoding("UTF-8");
                    logger.info(xmlStr);
                    response.getWriter().print(xmlStr);
                }
            } else {
                // 验证失败
                response.setStatus(401);
            }
        } catch (Exception e) {
            e.printStackTrace();
            // 服务器错误
            response.setStatus(500);
        }
    }
    /**
     * 微信推送消息验证
     *
     * @param signature
     * @param timestamp
     * @param nonce
     * @return
     * @throws NoSuchAlgorithmException
     */
    private boolean validate(String signature, String timestamp, String nonce) throws NoSuchAlgorithmException {
        //查询平台所有微信token
        List<WxWechatDO> wxs =  wechatCoreService.findAll();
        if(wxs!=null&&wxs.size()>0){
            for(WxWechatDO wx :wxs){
                String token = wx.getToken();
                // 字典序排序
                String[] array = new String[]{token, timestamp, nonce};
                Arrays.sort(array);
                //连接字典序排序后字符串
                String content = "";
                for (String str : array) {
                    content += str;
                }
                // 解析
                MessageDigest md = MessageDigest.getInstance("SHA-1");
                String decodeStr = "";
                byte[] bytes = md.digest(content.getBytes());
                decodeStr = byteToStr(bytes);
                //验证
                if (StringUtils.isNotEmpty(decodeStr) && decodeStr.equals(signature.toUpperCase())) {
                    return true;
                }
            }
        }
        return false;
    }
    /**
     * 将字节转换为字符
     *
     * @param mByte
     * @return
     */
    private static String byteToHexStr(byte mByte) {
        char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        char[] tempArr = new char[2];
        tempArr[0] = Digit[(mByte >>> 4) & 0X0F];
        tempArr[1] = Digit[mByte & 0X0F];
        String s = new String(tempArr);
        return s;
    }
    /**
     * 将字节数组转换为字符串
     *
     * @param byteArray
     * @return
     */
    private static String byteToStr(byte[] byteArray) {
        String strDigest = "";
        for (int i = 0; i < byteArray.length; i++) {
            strDigest += byteToHexStr(byteArray[i]);
        }
        return strDigest;
    }
}

+ 47 - 59
svr/svr-base/src/main/java/com/yihu/jw/business/wx/controller/WxMenuController.java

@ -1,58 +1,46 @@
//package com.yihu.jw.business.wx.controller;
//
//import com.yihu.jw.base.wx.WxMenuDO;
//import com.yihu.jw.base.wx.WxWechatDO;
//import com.yihu.jw.business.wx.WechatResponse;
//import com.yihu.jw.business.wx.service.WechatService;
//import com.yihu.jw.business.wx.service.WxMenuService;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//import com.yihu.jw.restmodel.base.wx.WxMenuVO;
//import com.yihu.jw.restmodel.base.wx.WxWechatVO;
//import com.yihu.jw.rm.base.WechatRequestMapping;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.apache.commons.lang.StringUtils;
//import org.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by Administrator on 2017/5/19 0019.
// */
//@RestController
//@RequestMapping(WechatRequestMapping.api_common)
//@Api(value = "微信菜单相关操作", description = "微信菜单相关操作")
//public class WxMenuController extends EnvelopRestController {
//
//    @Autowired
//    private WxMenuService wxMenuService;
//
//    @Autowired
//    private WechatService wechatService;
//
//    @PostMapping(value = WechatRequestMapping.WxMenu.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "添加微信菜单", notes = "添加微信菜单")
//    public Envelop createWxMenu(
//            @ApiParam(name = "json_data", value = "", defaultValue = "")
//            @RequestBody String jsonData) {
//        try {
//            WxMenuDO wxMenu = toEntity(jsonData, WxMenuDO.class);
//            return Envelop.getSuccess(WechatRequestMapping.WxMenu.message_success_create, wxMenuService.createWxMenu(wxMenu));
//        } catch (ApiException e) {
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
package com.yihu.jw.business.wx.controller;
import com.yihu.jw.business.wx.service.WechatService;
import com.yihu.jw.business.wx.service.WxMenuService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.base.WechatRequestMapping;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
@RestController
@RequestMapping(WechatRequestMapping.api_common)
@Api(value = "微信菜单相关操作", description = "微信菜单相关操作")
public class WxMenuController extends EnvelopRestController {
    @Autowired
    private WxMenuService wxMenuService;
    @Autowired
    private WechatService wechatService;
    @PostMapping(value = WechatRequestMapping.WxMenu.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "添加微信菜单", notes = "添加微信菜单")
    public Envelop createWxMenu(@ApiParam(name = "wxId", value = "微信id")
                                    @RequestParam(value = "wxId", required = false)String wxId) {
        try {
            return wxMenuService.createWxMenu(wxId);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
//    @PutMapping(value = WechatRequestMapping.WxMenu.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    @ApiOperation(value = "修改微信菜单", notes = "修改微信菜单")
//    public Envelop updateWxMenu(
@ -65,8 +53,8 @@
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//
//    @DeleteMapping(value = WechatRequestMapping.WxMenu.api_delete)
//    @ApiOperation(value = "删除微信菜单", notes = "删除微信菜单")
//    public Envelop deleteWxMenu(
@ -232,5 +220,5 @@
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//}
}

+ 29 - 27
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WechatDao.java

@ -1,27 +1,29 @@
//package com.yihu.jw.business.wx.dao;
//
//import com.yihu.jw.base.wx.WxWechatDO;
//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 WechatDao extends PagingAndSortingRepository<WxWechatDO, String>, JpaSpecificationExecutor<WxWechatDO> {
//
//    @Query("from WxWechatDO w where w.appId = ?1 and w.status!=-1")
//    WxWechatDO findByAppId(String appId);
//
//
//    @Query("from WxWechatDO w where w.appId = ?1 and w.id!= ?2 and w.status!=-1")
//    WxWechatDO findByAppIdExcludeId(String appId, String id);
//
//    @Query("from WxWechatDO w where w.id = ?1 and w.status!=-1")
//    WxWechatDO findById(String id);
//
//    @Query("from WxWechatDO w where w.status!=-1")
//    List<WxWechatDO> findAll();
//}
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.base.wx.WxWechatDO;
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 WechatDao extends PagingAndSortingRepository<WxWechatDO, String>, JpaSpecificationExecutor<WxWechatDO> {
    @Query("from WxWechatDO w where w.appId = ?1 and w.status!=-1")
    WxWechatDO findByAppId(String appId);
    @Query("from WxWechatDO w where w.appId = ?1 and w.id!= ?2 and w.status!=-1")
    WxWechatDO findByAppIdExcludeId(String appId, String id);
    @Query("from WxWechatDO w where w.id = ?1 and w.status!=-1")
    WxWechatDO findById(String id);
    @Query("from WxWechatDO w where w.status!=-1")
    List<WxWechatDO> findAll();
    @Query("from WxWechatDO w where w.appOriginId = ?1 and w.status!=-1")
    WxWechatDO findByAppOriginId(String appOriginId);
}

+ 17 - 17
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxAccessTokenDao.java

@ -1,17 +1,17 @@
//package com.yihu.jw.business.wx.dao;
//
//import com.yihu.jw.base.wx.WxAccessTokenDO;
//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/18 0018.
// */
//public interface WxAccessTokenDao extends PagingAndSortingRepository<WxAccessTokenDO, String>, JpaSpecificationExecutor<WxAccessTokenDO> {
//
//    @Query("from WxAccessTokenDO w where w.wechatId =?1 order by w.addTimestamp desc")
//    List<WxAccessTokenDO> getWxAccessTokenById(String wechatId);
//}
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.base.wx.WxAccessTokenDO;
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/18 0018.
 */
public interface WxAccessTokenDao extends PagingAndSortingRepository<WxAccessTokenDO, String>, JpaSpecificationExecutor<WxAccessTokenDO> {
    @Query("from WxAccessTokenDO w where w.wechatId =?1 order by w.addTimestamp desc")
    List<WxAccessTokenDO> getWxAccessTokenById(String wechatId);
}

+ 15 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxGraphicSceneGroupDao.java

@ -0,0 +1,15 @@
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.base.wx.WxGraphicSceneGroupDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2018/8/16.
 */
public interface WxGraphicSceneGroupDao extends PagingAndSortingRepository<WxGraphicSceneGroupDO, String>, JpaSpecificationExecutor<WxGraphicSceneGroupDO> {
    List<WxGraphicSceneGroupDO> findByWechatIdAndScene(String wechatId,String scene);
}

+ 20 - 47
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxMenuDao.java

@ -1,47 +1,20 @@
//package com.yihu.jw.business.wx.dao;
//
//import com.yihu.jw.base.wx.WxMenuDO;
//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/19 0019.
// */
//public interface WxMenuDao  extends PagingAndSortingRepository<WxMenuDO, String>, JpaSpecificationExecutor<WxMenuDO> {
//
//
//    @Query("from WxMenuDO m where m.id = ?1 and m.status = 1")
//    WxMenuDO findById(String id);
//
//    @Query("from WxMenuDO m where m.wechatId =?1 and m.status = 1 order  by m.supMenuid ,m.sort")
//    List<WxMenuDO> findByWechatId(String wechatId);
//
//    @Query("from WxMenuDO m where m.wechatId = ?1 and  m.supMenuid= ?2 and m.status =1 order by m.sort")
//    List<WxMenuDO> findChildMenus(String wechatId, String supMenuid);
//
//    @Query("from WxMenuDO m where  m.supMenuid= ?1 and m.status =1 order by m.sort")
//    List<WxMenuDO> findChildMenus( String supMenuid);
//
//    /**
//     * 根据wechatId判断父菜单的sort是否重复
//     * @param wechatId
//     * @param sort
//     */
//    @Query("from WxMenuDO m where m.wechatId = ?1 and m.status =1 and m.sort =?2 and m.supMenuid ='0' and m.id != ?3")
//    WxMenuDO findByWechatIdExcludeSortFromParent(String wechatId, Integer sort,String id);
//
//    /**
//     * 根据wechatId,supMenucode判断子菜单的sort是否重复
//     * @param wechatId
//     * @param sort
//     */
//    @Query("from WxMenuDO m where m.wechatId = ?1 and m.status =1 and m.sort =?2 and m.supMenuid =?3 and m.id != ?4")
//    WxMenuDO findByWechatIdExcludeSortFromChild(String wechatId, Integer sort,String supMenuid,String id);
//
//    @Query("from WxMenuDO m where m.wechatId =?1 and m.status = 1 and  m.supMenuid = '0' order by m.supMenuid ,m.sort")
//    List<WxMenuDO> findParentMenuByWechatId(String wechatId);
//
//}
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.base.wx.WxMenuDO;
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/19 0019.
 */
public interface WxMenuDao  extends PagingAndSortingRepository<WxMenuDO, String>, JpaSpecificationExecutor<WxMenuDO> {
    @Query("FROM WxMenuDO w WHERE w.wechatId =?1 AND w.status ='1' AND w.supMenuid IS NULL ORDER BY w.sort ASC")
    List<WxMenuDO> findParentRootByWechatId(String wechatId);
    @Query("FROM WxMenuDO w WHERE w.wechatId =?1 AND w.status ='1' AND w.supMenuid IS NOT NULL ORDER BY w.sort ASC")
    List<WxMenuDO> findChilrenByWechatId(String wechatId);
}

+ 13 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxMenuJsonDao.java

@ -0,0 +1,13 @@
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.base.wx.WxMenuJsonDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/8/13.
 */
public interface WxMenuJsonDao extends PagingAndSortingRepository<WxMenuJsonDO, String>, JpaSpecificationExecutor<WxMenuJsonDO> {
    WxMenuJsonDO findByWechatIdAndStatus(String wechatId,Integer status);
}

+ 18 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/wx/dao/WxReplySceneDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.business.wx.dao;
import com.yihu.jw.base.wx.WxReplySceneDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2018/8/16.
 */
public interface WxReplySceneDao extends PagingAndSortingRepository<WxReplySceneDO, String>, JpaSpecificationExecutor<WxReplySceneDO> {
    List<WxReplySceneDO> findByAppOriginIdAndMsgTypeAndStatus(String appOriginId,String msgType,Integer status);
    List<WxReplySceneDO> findByAppOriginIdAndMsgTypeAndEventAndStatus(String appOriginId,String msgType,String event,Integer status);
}

+ 288 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WechatCoreService.java

@ -0,0 +1,288 @@
package com.yihu.jw.business.wx.service;
import com.yihu.jw.base.wx.WxReplySceneDO;
import com.yihu.jw.base.wx.WxWechatDO;
import com.yihu.jw.business.wx.controller.WechatCoreController;
import com.yihu.jw.business.wx.dao.WechatDao;
import com.yihu.jw.business.wx.dao.WxReplySceneDao;
import com.yihu.jw.util.wechat.WeiXinMessageReplyUtils;
import com.yihu.jw.util.wechat.WeiXinMessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by Trick on 2018/8/16.
 */
@Service
public class WechatCoreService {
    private Logger logger = LoggerFactory.getLogger(WechatCoreService.class);
    @Autowired
    private WechatDao wechatDao;
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    @Autowired
    private WxReplySceneDao wxReplySceneDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 微信推送消息处理
     *
     * @param request
     */
    public String messageProcess(HttpServletRequest request) {
        try {
            String returnStr = "";
            // 将解析结果存储在HashMap中
            Map<String, String> message = new HashMap();
            // 从request中取得输入流
            InputStream inputStream = request.getInputStream();
            // 读取输入流
            SAXReader reader = new SAXReader();
            Document document = reader.read(inputStream);
            // 得到xml根元素
            Element root = document.getRootElement();
            // 得到根元素的所有子节点
            List elementList = root.elements();
            // 遍历所有子节点
            for (Object e : elementList) {
                Element ele = (Element) e;
                message.put(ele.getName(), ele.getText());
            }
            logger.info("weixin  event:" + message.toString());
            // 释放资源
            inputStream.close();
            // 消息处理
            returnStr = messageProcess(message);
            return returnStr;
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
    /**
     * 对接收到的消息进行处理
     *
     * @param message
     * @return
     */
    private String messageProcess(Map<String, String> message) throws Exception {
        String msgType = message.get("MsgType");
        String result = "";
        switch (msgType) {
            case WeiXinMessageUtils.REQ_MESSAGE_TYPE_EVENT:  // 事件消息
                result = eventProcess(message);
                break;
            case WeiXinMessageUtils.RESP_MESSAGE_TYPE_TEXT:  // 回复文本消息
                //回复文本消息 处理
                result = textProcess(message);
                break;
            default:
                break;
        }
        return result;
    }
    /**
     * 事件细分处理:
     * 1.扫描二维码事件
     * 2.订阅事件
     * 3.取消订阅事件
     * 4.菜单点击
     * @param message
     * @return
     */
    public String eventProcess(Map<String, String> message) throws Exception{
        String result = "";
        String event = message.get("Event");
        switch (event) {
            case WeiXinMessageUtils.EVENT_TYPE_SCAN: // 扫描二维码事件
                result = scanEventProcess(message);
                break;
            case WeiXinMessageUtils.EVENT_TYPE_SUBSCRIBE: // 订阅事件
                if (message.containsKey("EventKey") && StringUtils.isNotEmpty(message.get("EventKey")) && message.containsKey("Ticket")
                        && StringUtils.isNotEmpty(message.get("Ticket"))) {
                    result = scanEventProcess(message);
                } else {
                    result = subscribeEventProcess(message);
                }
                break;
            case WeiXinMessageUtils.EVENT_TYPE_UNSUBSCRIBE: // 取消订阅事件
                result = unsubscribeEventProcess(message);
                break;
            case WeiXinMessageUtils.EVENT_TYPE_CLICK: //菜单点击
                result = this.clickProcess(message);
            default:
                break;
        }
        return result;
    }
    public String scanEventProcess(Map<String, String> message){
        return "";
    }
    /**
     * 搜索关注事件
     * @param message
     * @return
     */
    public String subscribeEventProcess(Map<String, String> message) throws Exception{
        String toUserName = message.get("ToUserName");
        List<WxReplySceneDO> scenes = wxReplySceneDao.findByAppOriginIdAndMsgTypeAndEventAndStatus(toUserName,WeiXinMessageUtils.RESP_MESSAGE_TYPE_TEXT,WeiXinMessageUtils.EVENT_TYPE_SUBSCRIBE,1);
        if(scenes!=null&&scenes.size()>0){
            WxReplySceneDO scene = scenes.get(0);
            if(StringUtils.isNotBlank(scene.getScene())){
                return getGraphicXMl(scene.getScene(),scene.getWechatId(),message);
            }
        }
        return "";
    }
    public String unsubscribeEventProcess(Map<String, String> message){
        return "";
    }
    public String clickProcess(Map<String, String> message){
        return "";
    }
    /**
     * 文本消息动态生成图文消息
     * @param message
     * @return
     * @throws Exception
     */
    public String  textProcess(Map<String, String> message) throws Exception{
        String toUserName = message.get("ToUserName");
        String content = message.get("Content");
        List<WxReplySceneDO> scenes = wxReplySceneDao.findByAppOriginIdAndMsgTypeAndStatus(toUserName,WeiXinMessageUtils.RESP_MESSAGE_TYPE_TEXT,1);
        if(scenes!=null&&scenes.size()>0){
            for(WxReplySceneDO scene:scenes){
                if(StringUtils.isNotBlank(scene.getContent())
                        &&content.equals(scene.getContent())
                        &&StringUtils.isNotBlank(scene.getScene())){
                    //根据场景值,动态生成图文消息回复文斌
                    return getGraphicXMl(scene.getScene(),scene.getWechatId(),message);
                }
            }
        }
        return null;
    }
    /**
     * 构造图文消息XML
     * @param secene
     * @param wxId
     * @param message
     * @return
     * @throws Exception
     */
    public String getGraphicXMl(String secene,String wxId,Map<String, String> message)throws Exception{
        List<Map<String,Object>> group = getGraphicGroupByScene(secene,wxId);
        String result = "";
        if(group!=null&&group.size()>0){
            List<Map<String, String>> articles = new ArrayList<>();
            for(Map<String,Object> graphic : group){
                // 图文信息
                Map<String, String> article = new HashMap<>();
                String url = (String)graphic.get("url");
                String baseUrl = (String)graphic.get("baseUrl");
                String appId = (String)graphic.get("appId");
                String title = (String)graphic.get("title");
                String description = (String)graphic.get("description");
                String picUrl = (String)graphic.get("picUrl");
                url = url.replace("{server}",baseUrl).replace("{appId}",appId);
                article.put("Url", url);
                article.put("Title", title);
                article.put("Description", description);
                article.put("PicUrl", picUrl);
            }
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        }
        return result;
    }
    /**
     * 获取指定场景下所有图文消息分组
     * @param secene
     * @param wxId
     * @return
     */
    public List<Map<String,Object>> getGraphicGroupByScene(String secene,String wxId) {
        String sql = "SELECT " +
                " m.title, " +
                " m.description, " +
                " m.url, " +
                " m.pic_url AS picUrl," +
                " w.app_id AS appId," +
                " w.base_url AS baseUrl" +
                " FROM " +
                " wx_graphic_scene_group g " +
                " JOIN wx_graphic_message m ON g.graphic_id = m.id " +
                " JOIN wx_wechat w ON w.id = g.wechat_id" +
                " WHERE " +
                " m.wechat_id = '"+wxId+"' " +
                " AND g.wechat_id = '"+wxId+"' " +
                " AND g.scene = '"+secene+"' " +
                " AND m.`status` = 1 " +
                " ORDER BY m.sort ASC";
        List<Map<String,Object>> group = jdbcTemplate.queryForList(sql);
        return group;
    }
    /**
     * 判断是否是xml结构
     */
    public boolean isXML(String value) {
        try {
            DocumentHelper.parseText(value);
        } catch (DocumentException e) {
            return false;
        }
        return true;
    }
    public List<WxWechatDO> findAll(){
        return wechatDao.findAll();
    }
}

+ 13 - 114
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WechatService.java

@ -1,114 +1,13 @@
//package com.yihu.jw.business.wx.service;
//
//import com.yihu.jw.base.wx.WxWechatDO;
//import com.yihu.jw.business.wx.dao.WechatDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.base.mysql.query.BaseJpaService;
//import com.yihu.jw.rm.base.WechatRequestMapping;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//
//import javax.persistence.Transient;
//import java.util.*;
//
///**
// * Created by Administrator on 2017/5/20 0020.
// */
//@Service
//public class WechatService extends BaseJpaService<WxWechatDO, WechatDao> {
//
//    @Autowired
//    private WechatDao wechatDao;
//
//    @Transient
//    public WxWechatDO createWechat(WxWechatDO wechat) {
//        String code = UUID.randomUUID().toString().replaceAll("-", "");
//        wechat.setId(code);
//        if (StringUtils.isEmpty(wechat.getSaasId())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_saasId_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wechat.getStatus())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_status_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wechat.getType())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_type_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wechat.getName())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        WxWechatDO wechatTem = wechatDao.findByAppId(wechat.getAppId());
//        if (wechatTem != null) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_exist, ExceptionCode.common_error_params_code);
//        }
//        return wechatDao.save(wechat);
//    }
//
//    @Transient
//    public WxWechatDO updateWxchat(WxWechatDO wechat) {
//        if (StringUtils.isEmpty(wechat.getSaasId())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_saasId_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wechat.getStatus())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_status_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wechat.getType())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_type_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wechat.getName())) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        WxWechatDO wechat1 = findById(wechat.getId());
//        if (wechat1 == null) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
//        }
//        WxWechatDO wechatTem = wechatDao.findByAppIdExcludeId(wechat.getAppId(), wechat.getId());
//        if (wechatTem != null) {
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_exist, ExceptionCode.common_error_params_code);
//        }
//        return wechatDao.save(wechat);
//    }
//
//
//    public WxWechatDO findById(String id) {
//        return wechatDao.findById(id);
//    }
//
//    @Transient
//    public void deleteWechat(String ids, String userId, String userName) {
//        if (!StringUtils.isEmpty(ids)) {
//            String[] codeArray = ids.split(",");
//            for (String code : codeArray) {
//                WxWechatDO wxWechat = wechatDao.findById(code);
//                if (wxWechat == null) {
//                    throw new ApiException(WechatRequestMapping.WxConfig.message_fail_id_no_exist, ExceptionCode.common_error_params_code);
//                }
//                wxWechat.setStatus(-1);
//                wxWechat.setUpdateUser(userId);
//                wxWechat.setUpdateUserName(userName);
//                wechatDao.save(wxWechat);
//            }
//        }
//    }
//
//    public List<WxWechatDO> findAll() {
//        return wechatDao.findAll();
//    }
//
//    /**
//     * key为code ,value为微信名字
//     *
//     * @return
//     */
//    public Map<String, String> getAllWechatConfig() {
//        List<WxWechatDO> wechats = findAll();
//        Map<String, String> map = new HashMap<>();
//        if (null != wechats) {
//            for (WxWechatDO wx : wechats) {
//                map.put(wx.getId(), wx.getName());
//            }
//        }
//        return map;
//    }
//}
package com.yihu.jw.business.wx.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * Created by Administrator on 2017/5/20 0020.
 */
@Service
@Transactional
public class WechatService {
}

+ 151 - 96
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxAccessTokenService.java

@ -1,96 +1,151 @@
//package com.yihu.jw.business.wx.service;
//
//import com.yihu.jw.base.wx.WxAccessTokenDO;
//import com.yihu.jw.base.wx.WxWechatDO;
//import com.yihu.jw.business.wx.dao.WechatDao;
//import com.yihu.jw.business.wx.dao.WxAccessTokenDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.base.mysql.query.BaseJpaService;
//import com.yihu.jw.rm.base.WechatRequestMapping;
//import com.yihu.jw.util.HttpUtil;
//import org.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//
//import java.util.Date;
//import java.util.List;
//import java.util.UUID;
//
///**
// * Created by Administrator on 2017/5/18 0018.
// */
//@Service
//public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAccessTokenDao> {
//
//
//    private Logger logger= LoggerFactory.getLogger(WxAccessTokenService.class);
//
//    @Autowired
//    private WxAccessTokenDao wxAccessTokenDao;
//
//    @Autowired
//    private WechatDao wechatDao;
//
//    /**
//     * 根据wechatCode查找最新一条
//     * @param wechatId
//     * @return
//     */
//    public WxAccessTokenDO getWxAccessTokenById(String wechatId) {
//        try {
//            //根据wechatCode查找出appid和appSecret
//            WxWechatDO wxWechat = wechatDao.findById(wechatId);
//            if(wxWechat==null){
//                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
//            }
//            List<WxAccessTokenDO> wxAccessTokens =  wxAccessTokenDao.getWxAccessTokenById(wechatId);
//            if(wxAccessTokens!=null&&wxAccessTokens.size()>0){
//                for (WxAccessTokenDO accessToken : wxAccessTokens) {
//                    if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 1000)) {
//                        return accessToken;
//                    } else {
//                        wxAccessTokenDao.delete(accessToken);
//                        break;
//                    }
//                }
//            }
//            String token_url = "https://api.weixin.qq.com/cgi-bin/token";
//            String appId="";
//            String appSecret="";
//            appId = wxWechat.getAppId();
//            appSecret = wxWechat.getAppSecret();
//            if (StringUtils.isEmpty(appId)){
//                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code);
//            }
//            if (StringUtils.isEmpty(appSecret)){
//                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code);
//            }
//            String params = "grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
//            String result = HttpUtil.sendGet(token_url, params);
//            logger.info("--------------微信返回结果:"+result+"---------------");
//            JSONObject json = new JSONObject(result);
//            if (json.has("access_token")) {
//                String token = json.get("access_token").toString();
//                String expires_in = json.get("expires_in").toString();
//                WxAccessTokenDO newaccessToken = new WxAccessTokenDO();
//                newaccessToken.setAccessToken(token);
//                newaccessToken.setExpiresIn(Long.parseLong(expires_in));
//                newaccessToken.setAddTimestamp(System.currentTimeMillis());
//                newaccessToken.setCzrq(new Date());
//                newaccessToken.setCode(UUID.randomUUID().toString().replace("-",""));
//                newaccessToken.setWechatId(wechatId);
//                wxAccessTokenDao.save(newaccessToken);
//                return newaccessToken;
//            } else {
//                return null;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
//}
package com.yihu.jw.business.wx.service;
import com.yihu.jw.base.wx.WxAccessTokenDO;
import com.yihu.jw.base.wx.WxWechatDO;
import com.yihu.jw.business.wx.dao.WechatDao;
import com.yihu.jw.business.wx.dao.WxAccessTokenDao;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.rm.base.WechatRequestMapping;
import com.yihu.jw.util.HttpUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
 * Created by Administrator on 2017/5/18 0018.
 */
@Service
public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAccessTokenDao> {
    private Logger logger= LoggerFactory.getLogger(WxAccessTokenService.class);
    @Autowired
    private WxAccessTokenDao wxAccessTokenDao;
    @Autowired
    private WechatDao wechatDao;
    /**
     * 根据原始id查找
     * @param appOriginId
     * @return
     */
    public WxAccessTokenDO getWxAccessTokenByOriginId(String appOriginId) {
        try {
            //根据wechatCode查找出appid和appSecret
            WxWechatDO wxWechat = wechatDao.findByAppOriginId(appOriginId);
            if(wxWechat==null){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
            }
            List<WxAccessTokenDO> wxAccessTokens =  wxAccessTokenDao.getWxAccessTokenById(wxWechat.getId());
            if(wxAccessTokens!=null&&wxAccessTokens.size()>0){
                for (WxAccessTokenDO accessToken : wxAccessTokens) {
                    if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 500)) {
                        return accessToken;
                    } else {
                        wxAccessTokenDao.delete(accessToken);
                        break;
                    }
                }
            }
            String token_url = "https://api.weixin.qq.com/cgi-bin/token";
            String appId="";
            String appSecret="";
            appId = wxWechat.getAppId();
            appSecret = wxWechat.getAppSecret();
            if (StringUtils.isEmpty(appId)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code);
            }
            if (StringUtils.isEmpty(appSecret)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code);
            }
            String params = "grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
            String result = HttpUtil.sendGet(token_url, params);
            logger.info("--------------微信返回结果:"+result+"---------------");
            JSONObject json = new JSONObject(result);
                if (json.has("access_token")) {
                String token = json.get("access_token").toString();
                String expires_in = json.get("expires_in").toString();
                WxAccessTokenDO newaccessToken = new WxAccessTokenDO();
                newaccessToken.setAccessToken(token);
                newaccessToken.setExpiresIn(Long.parseLong(expires_in));
                newaccessToken.setAddTimestamp(System.currentTimeMillis());
                newaccessToken.setCzrq(new Date());
                newaccessToken.setCode(UUID.randomUUID().toString().replace("-",""));
                newaccessToken.setWechatId(wxWechat.getId());
                wxAccessTokenDao.save(newaccessToken);
                return newaccessToken;
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public WxAccessTokenDO getWxAccessTokenById(String wechatId) {
        try {
            //根据wechatCode查找出appid和appSecret
            WxWechatDO wxWechat = wechatDao.findById(wechatId);
            if(wxWechat==null){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
            }
            List<WxAccessTokenDO> wxAccessTokens =  wxAccessTokenDao.getWxAccessTokenById(wechatId);
            if(wxAccessTokens!=null&&wxAccessTokens.size()>0){
                for (WxAccessTokenDO accessToken : wxAccessTokens) {
                    if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 500)) {
                        return accessToken;
                    } else {
                        wxAccessTokenDao.delete(accessToken);
                        break;
                    }
                }
            }
            String token_url = "https://api.weixin.qq.com/cgi-bin/token";
            String appId="";
            String appSecret="";
            appId = wxWechat.getAppId();
            appSecret = wxWechat.getAppSecret();
            if (StringUtils.isEmpty(appId)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code);
            }
            if (StringUtils.isEmpty(appSecret)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code);
            }
            String params = "grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
            String result = HttpUtil.sendGet(token_url, params);
            logger.info("--------------微信返回结果:"+result+"---------------");
            JSONObject json = new JSONObject(result);
            if (json.has("access_token")) {
                String token = json.get("access_token").toString();
                String expires_in = json.get("expires_in").toString();
                WxAccessTokenDO newaccessToken = new WxAccessTokenDO();
                newaccessToken.setAccessToken(token);
                newaccessToken.setExpiresIn(Long.parseLong(expires_in));
                newaccessToken.setAddTimestamp(System.currentTimeMillis());
                newaccessToken.setCzrq(new Date());
                newaccessToken.setCode(UUID.randomUUID().toString().replace("-",""));
                newaccessToken.setWechatId(wechatId);
                wxAccessTokenDao.save(newaccessToken);
                return newaccessToken;
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

+ 50 - 357
svr/svr-base/src/main/java/com/yihu/jw/business/wx/service/WxMenuService.java

@ -1,357 +1,50 @@
//package com.yihu.jw.business.wx.service;
//
//import com.yihu.jw.base.wx.WxAccessTokenDO;
//import com.yihu.jw.base.wx.WxMenuDO;
//import com.yihu.jw.base.wx.WxWechatDO;
//import com.yihu.jw.business.wx.dao.WxMenuDao;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.base.mysql.query.BaseJpaService;
//import com.yihu.jw.rm.base.WechatRequestMapping;
//import com.yihu.jw.util.HttpUtil;
//import org.json.JSONException;
//import org.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//
//import javax.persistence.Transient;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.UUID;
//
///**
// * Created by Administrator on 2017/5/19 0019.
// */
//@Service
//public class WxMenuService extends BaseJpaService<WxMenuDO, WxMenuDao> {
//
//    private Logger logger= LoggerFactory.getLogger(WxMenuService.class);
//
//    @Autowired
//    private WxMenuDao wxMenuDao;
//
//    @Autowired
//    private WechatService wechatService;
//
//    @Autowired
//    private WxAccessTokenService wxAccessTokenService;
//
//    /**
//     * 将菜单保存至数据库
//     * @param wxMenu
//     * @return
//     */
//    public WxMenuDO createWxMenu(WxMenuDO wxMenu) {
//        String code = UUID.randomUUID().toString().replaceAll("-", "");
//        wxMenu.setId(code);
//        if(canSaveOrUpata(wxMenu)){
//            return wxMenuDao.save(wxMenu);
//        }
//        return null;
//    }
//
//    @Transient
//    public WxMenuDO updateWxMenu(WxMenuDO wxMenu) {
//        if (StringUtils.isEmpty(wxMenu.getId())) {
//            throw new ApiException(WechatRequestMapping.WxMenu.message_fail_id_is_null, ExceptionCode.common_error_params_code);
//        }
//        if(canSaveOrUpata(wxMenu)){
//            WxMenuDO wxMenu1 = findById(wxMenu.getId());
//            if(wxMenu1==null){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_WxMenu_is_no_exist, ExceptionCode.common_error_params_code);
//            }
//            return wxMenuDao.save(wxMenu);
//        }
//        return null;
//    }
//
//    @Transient
//    public void deleteWxMenu(String ids, String userId, String userName) {
//        if(!StringUtils.isEmpty(ids)) {
//            String[] codeArray = ids.split(",");
//            for (String code : codeArray) {
//                WxMenuDO wxMenu = wxMenuDao.findById(code);
//                if (wxMenu == null) {
//                    continue;
//                }
//                String supMenucode = wxMenu.getSupMenuid();
//                if (StringUtils.isEmpty(supMenucode)) {//如果是空,则为父菜单
//                    List<WxMenuDO> childMenus = findChildMenus(wxMenu.getWechatId(), wxMenu.getId());
//                    if (childMenus != null) {
//                        for (WxMenuDO wxmenu : childMenus) {
//                            wxmenu.setStatus(-1);
//                            wxmenu.setUpdateUser(userId);
//                            wxmenu.setUpdateUserName(userName);
//                            wxMenuDao.save(wxmenu);
//                        }
//                    }
//                }
//                wxMenu.setStatus(-1);
//                wxMenu.setUpdateUser(userId);
//                wxMenu.setUpdateUserName(userName);
//                wxMenuDao.save(wxMenu);
//            }
//        }
//    }
//
//    @Transient
//    public void delete(String codes,String userCode) {
//        if(!StringUtils.isEmpty(codes)) {
//            String[] codeArray = codes.split(",");
//            for (String code : codeArray) {
//                WxMenuDO wxMenu = wxMenuDao.findById(code);
//                if (wxMenu == null) {
//                    continue;
//                }
//                String supMenucode = wxMenu.getSupMenuid();
//                if (StringUtils.isEmpty(supMenucode)) {//如果是空,则为父菜单
//                    List<WxMenuDO> childMenus = findChildMenus(wxMenu.getWechatId(), wxMenu.getId());
//                    if (childMenus != null) {
//                        for (WxMenuDO wxmenu : childMenus) {
//                            wxmenu.setStatus(-1);
//                            wxmenu.setUpdateUser(userCode);
//                            wxMenuDao.save(wxmenu);
//                        }
//                    }
//                }
//                wxMenu.setStatus(-1);
//                wxMenu.setUpdateUser(userCode);
//                wxMenuDao.save(wxMenu);
//            }
//        }
//    }
//
//    public WxMenuDO findById(String id) {
//        return wxMenuDao.findById(id);
//    }
//    /**
//     * 根据wechatCode查找所有父菜单
//     * @param wechatCode
//     * @return
//     */
//    public List<WxMenuDO> findParentMenuByWechatCode(String wechatCode){
//        List<WxMenuDO> parentMenus = wxMenuDao.findParentMenuByWechatId(wechatCode);
//        return parentMenus;
//    }
//
//    /**
//     * 根据wechatCode在微信公众号创建菜单
//     * @param wechatId
//     * @return JSONObject
//     */
//    public JSONObject createWechatMenu(String wechatId) throws JSONException {
//        WxWechatDO wechat = wechatService.findById(wechatId);
//        if(wechat==null){
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
//        }
//        //首先根据wechatCode获取菜单,然后封装成json字符串
//        List<WxMenuDO> menus = wxMenuDao.findByWechatId(wechatId);
//        if(menus==null){
//            throw new ApiException(WechatRequestMapping.WxMenu.message_fail_WxMenu_is_no_exist, ExceptionCode.common_error_params_code);
//        }
//        String menuJsonString = getMenuToString(menus, wechatId);
//        logger.info("-----------------微信菜单json字符串:"+ menuJsonString+"--------------------");
//        WxAccessTokenDO wxAccessTokenByCode = wxAccessTokenService.getWxAccessTokenById(wechatId);
//        String token = wxAccessTokenByCode.getAccessToken();
//        // 请求微信接口创建菜单
//        String url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + token;
//        String jsonStr = HttpUtil.sendPost(url, menuJsonString);
//        logger.info("------------------创建微信菜单,微信返回结果:"+jsonStr+"---------------------");
//        JSONObject result = new JSONObject(jsonStr);
//        return result;
//    }
//
//    private String getMenuToString(List<WxMenuDO> menus,String wechatCode){
//        String menuJsonStr = "";
//        List<WxMenuDO> parentMenus = new ArrayList<WxMenuDO>();//存储父菜单
//        if(menus!=null){
//            menuJsonStr = "{\"button\":[{";
//            for(WxMenuDO wxMenu:menus){
//                if(StringUtils.isEmpty(wxMenu.getSupMenuid())){//说明是父菜单
//                    parentMenus.add(wxMenu);
//                }
//            }
//        }
//        int j = 0;
//        for(WxMenuDO menu:parentMenus){//遍历父菜单
//            if(j==0){
//                j++;
//            }else{
//                menuJsonStr += ",{";
//            }
//            menuJsonStr = getString(menuJsonStr, menu);
//            //查找是否有子菜单
//            List<WxMenuDO> childMenus = findChildMenus(wechatCode, menu.getId());
//            if(childMenus!=null){
//                int i =0;
//                menuJsonStr += ",\"sub_button\":[{";
//                for(WxMenuDO childMenu:childMenus){
//                    if(i==0){
//                        i++;
//                    }else{
//                        menuJsonStr += ",{";
//                    }
//                    menuJsonStr = getString(menuJsonStr, childMenu);
//                    menuJsonStr += "}";
//                }
//                menuJsonStr += "]}";
//            }
//        }
//        menuJsonStr += "]}";
//        return menuJsonStr;
//    }
//
//    private String getString(String menuJsonStr, WxMenuDO menu) {
//        menuJsonStr += "\"name\":\""+ menu.getName()+"\"";
//        if(!StringUtils.isEmpty(menu.getType())){
//            menuJsonStr += ",\"type\":\"" + menu.getType()+"\"";
//        }
//        if(!StringUtils.isEmpty(menu.getMenuKey())){
//            menuJsonStr += ",\"key\":\"" + menu.getMenuKey()+"\"";
//        }
//        if(!StringUtils.isEmpty(menu.getUrl())){
//            menuJsonStr += ",\"url\":\"" + menu.getUrl()+"\"";
//        }
//        if(!StringUtils.isEmpty(menu.getMediaId())){
//            menuJsonStr += ",\"media_id\":\"" + menu.getMediaId()+"\"";
//        }
//        if(!StringUtils.isEmpty(menu.getAppid())){
//            menuJsonStr += ",\"appid\":\"" + menu.getAppid()+"\"";
//        }
//        if(!StringUtils.isEmpty(menu.getPagepath())){
//            menuJsonStr += ",\"pagepath\":\"" + menu.getPagepath()+"\"";
//        }
//        return menuJsonStr;
//    }
//
//    /**
//     * 查找子菜单
//     * @param wechatCode
//     * @param sup_menucode
//     * @return
//     */
//    public List<WxMenuDO> findChildMenus(String wechatCode,String sup_menucode ){
//        return wxMenuDao.findChildMenus(wechatCode,sup_menucode);
//    }
//
//    public List<WxMenuDO> findChildMenus(String parentCode ){
//        return wxMenuDao.findChildMenus(parentCode);
//    }
//
//    private boolean canSaveOrUpata(WxMenuDO wxMenu){
//        String wechatCode = wxMenu.getWechatId();
//        String supMenucode = wxMenu.getSupMenuid();
//        if(StringUtils.isEmpty(wechatCode)){
//            WxMenuDO parentMenuCode = findById(supMenucode);
//            wechatCode = parentMenuCode.getWechatId();
//            wxMenu.setWechatId(wechatCode);
//        }
//        String name = wxMenu.getName();
//        if (StringUtils.isEmpty(name)) {
//            throw new ApiException(WechatRequestMapping.WxMenu.message_fail_name_is_null, ExceptionCode.common_error_params_code);
//        }
//        if (StringUtils.isEmpty(wxMenu.getStatus())) {
//            throw new ApiException(WechatRequestMapping.WxMenu.message_fail_status_is_null, ExceptionCode.common_error_params_code);
//        }
//        if(StringUtils.isEmpty(wxMenu.getSort())){
//            throw new ApiException(WechatRequestMapping.WxMenu.message_fail_sort_is_null, ExceptionCode.common_error_params_code);
//        }
//        //根据wechatCode查找是否存在微信配置
//        WxWechatDO wxWechat = wechatService.findById(wechatCode);
//        if(wxWechat==null){
//            throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
//        }
//        if (!"0".equals(supMenucode)) {//不为0,说明是子菜单,判断父菜单是否存在
//            //说明是子菜单
//            //判断父菜单是否存在
//            WxMenuDO parentMenuCode = findById(supMenucode);
//            if(parentMenuCode==null){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_supMenuId_is_no_exist, ExceptionCode.common_error_params_code);
//            }
//
//            //查询已经存在的子菜单条数
//            List<WxMenuDO> childMenus = findChildMenus(wechatCode, supMenucode);
//            if(childMenus.size()==5){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_childMenu_is_to_much, ExceptionCode.common_error_params_code);
//            }
//            if(name.getBytes().length>60){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_name_is_to_long, ExceptionCode.common_error_params_code);
//            }
//            if(StringUtils.isEmpty(wxMenu.getType())){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_type_is_null, ExceptionCode.common_error_params_code);
//            }
//        }else{
//            //查找父菜单
//            List<WxMenuDO> parentMenus = findParentMenuByWechatCode(wechatCode);
//            if(parentMenus!=null){
//                if(parentMenus.size()==3){
//                    throw new ApiException(WechatRequestMapping.WxMenu.message_fail_parentMenu_is_to_much, ExceptionCode.common_error_params_code);
//                }
//            }
//
//            //说明是父菜单
//            if(name.getBytes().length>16){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_name_is_to_long, ExceptionCode.common_error_params_code);
//            }
//
//        }
//        String type1=wxMenu.getType();
//        if(type1==null){
//            type1="";
//        }
//        String type = type1.toUpperCase();
//        if("click".equals(type)){
//            String key = wxMenu.getMenuKey();
//            if(StringUtils.isEmpty(key)){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_key_is_null, ExceptionCode.common_error_params_code);
//            }
//            if(key.getBytes().length>128){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_key_is_toLong, ExceptionCode.common_error_params_code);
//            }
//        }
//        String url = wxMenu.getUrl();
//        if("view".equals(type)){
//            if(StringUtils.isEmpty(url)){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_url_is_null, ExceptionCode.common_error_params_code);
//            }
//            if(url.getBytes().length>128){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_url_is_toLong, ExceptionCode.common_error_params_code);
//            }
//        }
//        if("miniprogram".equals(type)){
//            if(StringUtils.isEmpty(url)){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_url_is_null, ExceptionCode.common_error_params_code);
//            }
//            if(url.getBytes().length>128){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_url_is_toLong, ExceptionCode.common_error_params_code);
//            }
//            if(StringUtils.isEmpty(wxMenu.getAppid())){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_appid_is_null, ExceptionCode.common_error_params_code);
//            }
//            if(StringUtils.isEmpty(wxMenu.getPagepath())){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_pagepath_is_null, ExceptionCode.common_error_params_code);
//            }
//        }
//        if("media_id".equals(type)||"view_limited".equals(type)){
//            if(StringUtils.isEmpty(wxMenu.getMediaId())){
//                throw new ApiException(WechatRequestMapping.WxMenu.message_fail_mediaId_is_null, ExceptionCode.common_error_params_code);
//            }
//        }
//        WxMenuDO wxMenuTemp = null;
//        if(StringUtils.isEmpty(wxMenu.getSupMenuid())){//如果是空,则为父菜单
//            //判断sort是否重复
//            wxMenuTemp = wxMenuDao.findByWechatIdExcludeSortFromParent(wxMenu.getWechatId(), wxMenu.getSort(),wxMenu.getId());
//        }else{//子菜单
//            wxMenuTemp = wxMenuDao.findByWechatIdExcludeSortFromChild(wxMenu.getWechatId(), wxMenu.getSort(), wxMenu.getSupMenuid(), wxMenu.getId());
//        }
//        if(null!=wxMenuTemp){
//            throw new ApiException(WechatRequestMapping.WxMenu.message_fail_sort_is_repeat, ExceptionCode.common_error_params_code);
//        }
//        wxMenu.setUpdateTime(new Date());
//        return true;
//    }
//}
package com.yihu.jw.business.wx.service;
import com.yihu.jw.base.wx.WxMenuDO;
import com.yihu.jw.base.wx.WxMenuJsonDO;
import com.yihu.jw.base.wx.WxWechatDO;
import com.yihu.jw.business.wx.dao.WechatDao;
import com.yihu.jw.business.wx.dao.WxMenuDao;
import com.yihu.jw.business.wx.dao.WxMenuJsonDao;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.rm.base.WechatRequestMapping;
import com.yihu.jw.util.HttpUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
@Service
public class WxMenuService extends BaseJpaService<WxMenuDO, WxMenuDao>{
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    @Autowired
    private WxMenuJsonDao wxMenuJsonDao;
    @Autowired
    private WechatDao wechatDao;
    public Envelop createWxMenu(String wxId){
//        String url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=" ;
        String url ="https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+ wxAccessTokenService.getWxAccessTokenById(wxId).getAccessToken();
        WxMenuJsonDO wxMenuJsonDO = wxMenuJsonDao.findByWechatIdAndStatus(wxId,1);
        String params = wxMenuJsonDO.getContent();
        WxWechatDO wechatDO =  wechatDao.findById(wxId);
        // 替换服务器地址、APPID
        params = params.replaceAll("server_url", wechatDO.getBaseUrl());
        params = params.replaceAll("appId", wechatDO.getAppId());
        String jsonStr = HttpUtil.sendPost(url, params);
        JSONObject result = new JSONObject(jsonStr);
        if (result != null && result.get("errcode").toString().equals("0") && result.getString("errmsg").equals("ok")) {
            Envelop.getSuccess(WechatRequestMapping.WxMenu.message_success_update);
        }
        return Envelop.getError(result.toString());
    }
}

+ 0 - 1
svr/svr-base/src/main/resources/application.yml

@ -26,7 +26,6 @@ spring:
hibernate:
  dialect: org.hibernate.dialect.MySQL5Dialect
  show_sql: true
#  ejb:
#    naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy #springJPA使用驼峰式(hibernate4以下使用)
  physical_naming_strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy #springJPA使用驼峰式(hibernate5以上使用)
  implicit_naming_strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl

+ 5 - 0
svr/svr-wlyy-specialist/pom.xml

@ -102,6 +102,11 @@
            <groupId>com.yihu</groupId>
            <artifactId>mysql-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr.ehr</groupId>
            <artifactId>commons-util</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>
    <build>

+ 6 - 6
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistService.java

@ -124,7 +124,7 @@ public class SpecialistService{
                "  SELECT " +
                "   i.patient " +
                "  FROM " +
                "   wlyy.wlyy_sign_patient_label_info i " +
                "   "+basedb+".wlyy_sign_patient_label_info i " +
                "  WHERE " +
                "   i.label_type = '7' AND " +
                "   i.status = 1 " +
@ -515,9 +515,9 @@ public class SpecialistService{
                " md.name AS doctorName" +
                " FROM " +
                " wlyy_specialist_patient_relation r  " +
                " JOIN wlyy.wlyy_admin_team t ON t.id = r.team_code " +
                " JOIN wlyy.wlyy_doctor d ON t.leader_code = d.`code` " +
                " JOIN wlyy.wlyy_doctor md ON md.code = r.doctor " +
                " JOIN "+basedb+".wlyy_admin_team t ON t.id = r.team_code " +
                " JOIN "+basedb+".wlyy_doctor d ON t.leader_code = d.`code` " +
                " JOIN "+basedb+".wlyy_doctor md ON md.code = r.doctor " +
                " WHERE " +
                " r.patient = '"+patient+"' " +
                " AND r.`status` >=0  " +
@ -557,7 +557,7 @@ public class SpecialistService{
                " d.`level` " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN wlyy.wlyy_doctor d ON r.doctor = d.`code` " +
                " JOIN "+basedb+".wlyy_doctor d ON r.doctor = d.`code` " +
                " WHERE  " +
                " r.patient ='"+patient+"' " +
                " AND r.`status`>=0 " +
@ -585,7 +585,7 @@ public class SpecialistService{
                " d.`level` " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN wlyy.wlyy_doctor d ON r.doctor = d.`code` " +
                " JOIN "+basedb+".wlyy_doctor d ON r.doctor = d.`code` " +
                " WHERE  " +
                " r.patient ='"+patient+"' " +
                " AND r.doctor ='"+doctor+"' " +