Commit 2bacdb7f by Hayreal

sop触达中心-执行sop企微任务

1 parent 3220cd3d
Showing 38 changed files with 1653 additions and 16 deletions
package cn.com.glsx.execute.modules.constant;
import lombok.Data;
public class DracConstant {
public static class WelcomeActivity {
public static final Integer COUPON = 1;
public static final Integer EQUITY = 2;
public static final Integer SERVICE_PACKAGE = 3;
public static final Integer QY_CODE = 4;
}
public static class MassSenderStatus {
public static final Integer UN_SENDER = 0;
public static final Integer SENDER = 1;
public static final Integer FAILURE_SENDER = 2;
public static final Integer FAILURE_RECIVER = 3;
}
public static class MassStatus {
public static final Byte FAILURE = -1;
public static final Byte SUCCESS = 0;
public static final Byte SENDER = 1;
public static final Byte SEND_FAILURE = 2;
public static final Byte UNSEND = 3;
}
public static class WelcomeDesc {
public static final String ONEGROUP = "ONE_GROUP";
public static final String MASS = "MASS_GROUP";
public static final String CODE = "CODE_GROUP";
public static final String DRAC = "DRAC";
public static final String MOMENT = "MOMENT";
public static final String OPERATION = "OPERATION";
public static final String ACTIVITY = "ACTIVITY";
public static final String RESCUE = "RESCUE";
public static final String OUTBOUND = "OUT_BOUND";
public static final String BUSINESS_CARD = "BUSINESS_CARD";
public static final String BATCH_MOMENT = "BATCH_MOMENT";
public static final String BATCH_MESSAGING = "BATCH_MESSAGING";
public static final String CHAT_GROUP_WELCOME_MESSAGE = "CHAT_GROUP_WELCOME_MESSAGE";
}
public static class TemplateStatus {
public static final Byte OK = 1;
public static final Byte FORBIDDEN = 2;
}
public static class DelFlag {
public static final Byte OK = 0;
public static final Byte DEL = -1;
}
public static class QyAttType {
public static final String TEXT = "text";
public static final String IMAGE = "image";
public static final String VEDIO = "video";
public static final String URI = "link";
public static final String MINIPROGRAM = "miniprogram";
public static final String FILE = "file";
public static final String ACTIVITY = "activity";
}
public static class AttType {
public static final int TEXT = 1;
public static final int IMAGE = 2;
public static final int VEDIO = 3;
public static final int MINIPROGRAM = 4;
public static final int FILE = 5;
public static final int URI = 6;
}
public static class DracMiniProgram{
public static final String miniprogram_appid_key = "appId";
public static final String miniprogram_title_key = "title";
public static final String miniprogram_page_key = "page";
public static final String miniprogram_mediaid_key = "mediaId";
}
public static class DracLink{
public static final String link_title_key = "title";
public static final String link_desc_key = "desc";
public static final String link_picurl_key = "picurl";
public static final String link_url_key = "url";
}
}
package cn.com.glsx.execute.modules.enums.exception;
public enum ResultEnum {
CHAT_TYPE_EMPTY(40000001,"群发任务类型chatType不能为空!"),
ATT_TYPE_ERROR(40000002,"不支持的群发任务类型!"),
;
private int code;
private String message;
ResultEnum(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}
......@@ -17,6 +17,8 @@ public enum MethodEnum {
CUSTOMER_CALL_DETAIL("marketing.api.ai.outbound.call.customer.detail", "客户通话详情"),
BATCH_MESSAGE_CREATE("entmicro.api.wechatcloudcontrol.nosession.batchmessaging.create", "企微高级群发任务创建"),
WECHAT_USERINFO_BY_UNIONID("scrm.api.wechat.auth.userProfile.getUserInfo.byUnionId", "获取的用户信息"),
ADD_MESSAGE_TEMPLATE("scrm.api.work.wechat.external.contact.msg.add", "创建企业群发"),
UPLOAD_MEDIA("scrm.api.work.wechat.external.contact.upload.media", "上传素材"),
;
private String method;
private String describe;
......
package cn.com.glsx.execute.modules.enums.wechat;
import cn.com.glsx.framework.core.enums.BaseEnum;
import java.util.HashMap;
import java.util.Map;
/**
* @Title: WorkWechatMediaTypeEnum.java
* @Description: 媒体文件类型枚举
* @author Alvin
* @date 2021年9月12日 下午9:23:46
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
public enum WorkWechatMediaTypeEnum implements BaseEnum<WorkWechatMediaTypeEnum, String>{
/**
* 图片
*/
IMAGE("image", "图片"),
/**
* 语音
*/
VOICE("voice", "语音"),
/**
* 视频
*/
VIDEO("video", "视频"),
/**
* 普通文件
*/
FILE("file", "普通文件"),
;
private String value;
private String displayName;
private static Map<String, WorkWechatMediaTypeEnum> map;
private WorkWechatMediaTypeEnum(String value, String displayName){
this.value = value;
this.displayName = displayName;
put();
}
@Override
public String getValue() {
return value;
}
@Override
public String getDisplayName() {
return displayName;
}
private void put(){
if(map == null){
map = new HashMap<String, WorkWechatMediaTypeEnum>();
}
map.put(value, this);
}
public static WorkWechatMediaTypeEnum get(String value){
return map.get(value);
}
@Override
public String toString() {
return this.name().concat("[value:").concat(getValue().toString()).concat(", displayName:").concat(getDisplayName()).concat("]");
}
}
package cn.com.glsx.execute.modules.model.sopTask;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
@Data
public class AttContent implements Serializable {
@JsonProperty("mediaId")
@Schema(name = "mediaId", description = "企微素材ID(不用传,用于保存企微返回数据)")
private String mediaId;
@JsonProperty("attType")
@Schema(name = "attType", description = "文本类型:1.文本 2.图片 3.视频 4.小程序 5.文件 6.URI")
private Integer attType;
@JsonProperty("attContent")
@Schema(name = "attContent", description = "文本内容 attType=4时传小程序参数")
private String attContent;
}
package cn.com.glsx.execute.modules.model.sopTask;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
import java.util.List;
@Data
public class ExecuteSopTaskResponse implements Serializable {
@Schema(name = "failList",description = "无效或无法发送的external_userid列表")
@JsonProperty("failList")
private List<String> failList;
@JsonProperty("msgId")
@Schema(name = "msgId",description = "企业群发消息的id,可用于获取群发消息发送结果")
private String msgId;
}
package cn.com.glsx.execute.modules.model.sopTask;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class SopTaskExecuteStaffRequest implements Serializable {
@JsonProperty("sendUserId")
@Schema(name = "sendUserId", description = "发送员工")
private String sendUserId;
@JsonProperty("sendExternalUserId")
@Schema(name = "sendExternalUserId", description = "发送客户")
private List<String> sendExternalUserId;
}
package cn.com.glsx.execute.modules.model.sopTask;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
@Data
public class SopTaskToCustomerExecuteRequest implements Serializable {
@NotNull
@JsonProperty("sendType")
@Schema(name = "sendType", description = "发送任务类型:1.短信发送 2.企微群发 3.企微朋友圈")
private Integer sendType;
@NotNull
@JsonProperty("merchantId")
@Schema(name = "merchantId", description = "商户号")
private Integer merchantId;
@JsonProperty("sendPhoneList")
@Schema(name = "sendPhoneList", description = " 发送手机号 sendType为1时候必传")
private List<String> sendPhoneList;
@JsonProperty("chatType")
@Schema(name = "chatType", description = "群发任务的类型 sendType为2时候必传,默认为single,表示发送给客户,group表示发送给客户群", allowableValues = {"single", "group"})
private String chatType;
@JsonProperty("executeStaffRequestList")
@Schema(name = "executeStaffRequestList", description = "发送员工及客户")
private List<SopTaskExecuteStaffRequest> executeStaffRequestList;
@JsonProperty("contentList")
@Schema(name = "contentList", description = "发送内容")
private List<AttContent> contentList;
// @JsonProperty("appConfigDTO")
// @Schema(name = "appConfigDTO", description = "小程序参数:发送内容包含小程序时必传")
// private WechatAppConfigDTO appConfigDTO;
}
package cn.com.glsx.execute.modules.model.sopTask;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
@Data
public class SopTaskToStaffExecuteRequest implements Serializable {
@JsonProperty("userId")
@Schema(name = "userId",description = "员工userId")
private String userId;
@JsonProperty("content")
@Schema(name = "content",description = "消息内容")
private String content;
@JsonProperty("merchantId")
@Schema(name = "merchantId",description = "商户号")
private Integer merchantId;
@JsonProperty("title")
@Schema(name = "title",description = "内容标题")
private String title;
@JsonProperty("type")
@Schema(name = "type",description = "1:text 2:image 3:voice 4:video 5:file 6:textCard 7:news 8:mpnews 9:markdown 10:miniprogram_notice")
private String type;
@JsonProperty("url")
@Schema(name = "url",description = "点击后跳转的链接")
private String url;
@JsonProperty("mediaId")
@Schema(name = "mediaId",description = "企微mediaId")
private String mediaId;
@JsonProperty("picurl")
@Schema(name = "picurl",description = "图片地址")
private String picurl;
@JsonProperty("btnTxt")
@Schema(name = "btnTxt",description = "按钮文字。 默认为“详情”, 不超过4个文字")
private String btnTxt;
}
package cn.com.glsx.execute.modules.model.wechat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@Data
public class WechatAppConfigDTO implements Serializable {
@NotNull
@JsonProperty("appId")
@Schema(name = "appId", description = "小程序appId")
private Integer appId;
@NotNull
@JsonProperty("page")
@Schema(name = "page", description = "小程序page参数")
private String page;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateRequestDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class AddWorkWechatExternalContactMsgTemplateRequestDTO extends WorkWechatBaseRequestDTO {
private static final long serialVersionUID = 6804160537709365796L;
/**
* 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
* @link WorkWechatChatTypeEnum
*/
@JsonProperty("chat_type")
@Schema(name = "chatType", description = "群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群")
private String chatType;
/**
* 客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户
*/
@JsonProperty("external_userid")
@Schema(name = "externalUserIdList", description = "客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户")
private List<String> externalUserIdList;
/**
* 发送企业群发消息的成员userid,当类型为发送给客户群时必填
*/
@JsonProperty("sender")
@Schema(name = "sender", description = "发送企业群发消息的成员userid,当类型为发送给客户群时必填")
private String sender;
/**
* 消息文本内容,最多4000个字节
*/
@JsonProperty("text")
@Schema(name = "text", description = "消息文本内容,最多4000个字节")
private WorkWechatExternalContactMsgTextDTO text;
/**
* 附件,最多支持添加9个附件
*/
@JsonProperty("attachments")
@Schema(name = "attachments", description = "附件,最多支持添加9个附件")
private List<WorkWechatExternalContactMsgAttachmentDTO> attachments;
}
package cn.com.glsx.execute.modules.model.workWechat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateResponseDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午4:03:44
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class AddWorkWechatExternalContactMsgTemplateResponseDTO extends BaseResponseDTO {
private static final long serialVersionUID = 592595894342894177L;
/**
* 无效或无法发送的external_userid列表
*/
@JsonProperty("fail_list")
private List<String> failList;
/**
* 企业群发消息的id,可用于获取群发消息发送结果
*/
@JsonProperty("msgid")
private String msgId;
}
package cn.com.glsx.execute.modules.model.workWechat;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: BaseResponseDTO.java
* @Description:
* @author Alvin
* @date 2019年3月23日 下午4:47:17
* @version V1.0
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2018
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class BaseResponseDTO implements Serializable{
private static final long serialVersionUID = 1L;
@JsonProperty("errcode")
private Integer errCode;
@JsonProperty("errmsg")
private String errMsg;
public Integer getErrCode() {
return errCode;
}
public void setErrCode(Integer errCode) {
this.errCode = errCode;
}
public String getErrMsg() {
if(errCode != null){
errMsg = WechatErrcodeConfig.getErrMsg(String.valueOf(errCode), errMsg);
}
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public boolean isSuccess(){
return errCode == null || 0 == errCode;
}
public static BaseResponseDTO error(Integer errCode, String errMsg){
BaseResponseDTO response = new BaseResponseDTO();
response.setErrCode(errCode);
response.setErrMsg(errMsg);
return response;
}
@Override
public String toString() {
return "BaseResponseDTO [errCode=" + errCode + ", errMsg=" + getErrMsg()
+ "]";
}
}
package cn.com.glsx.execute.modules.model.workWechat;
import lombok.Data;
import java.io.Serializable;
@Data
public class UpLoadMediaToWorkWechatRequestDTO implements Serializable {
private String content;
private Integer attType;
private Integer merchantId;
}
package cn.com.glsx.execute.modules.model.workWechat;
import cn.com.glsx.execute.modules.enums.wechat.WorkWechatMediaTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* @Title: UploadWorkWechatMediaRequestDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午7:10:09
* @version V1.0
*/
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class UploadWorkWechatMediaRequestDTO extends WorkWechatBaseRequestDTO {
private static final long serialVersionUID = 5965689134793447641L;
/**
* 媒体文件内容
*/
@NotNull(message = "媒体文件内容不能为空")
@Schema(name = "data", description = "媒体文件内容", required = true)
private String data;
/**
* 媒体文件名
*/
@NotEmpty(message = "媒体文件名不能为空")
@Schema(name = "fileName", description = "媒体文件名", required = true)
private String fileName;
/**
* 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
*/
// @NotNull(message = "媒体文件类型不能为空")
// @Schema(name = "mediaType", description = "图片内容字节数组", required = true)
// private WorkWechatMediaTypeEnum mediaType;
private Integer mediaType;
}
package cn.com.glsx.execute.modules.model.workWechat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
/**
* @Title: UploadWorkWechatMediaResponseDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午7:16:07
* @version V1.0
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class UploadWorkWechatMediaResponseDTO extends BaseResponseDTO {
private static final long serialVersionUID = -3849867089877210048L;
@JsonProperty("type")
private String type;
@JsonProperty("media_id")
private String mediaId;
@JsonProperty("created_at")
private String createdAt;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
/**
* @Title: BaseRequestDTO.java
* @Description:
* @author Alvin
* @date 2021年9月15日 下午5:34:44
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@NoArgsConstructor
public class WorkWechatBaseRequestDTO implements Serializable{
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
private static final long serialVersionUID = -8748996888906556828L;
/**
* 商户号
*/
@NotNull(message = "商户号不能为空")
@JsonIgnore
@Schema(name = "merchantId", description = "授权企微商户号", required = true)
private Integer merchantId;
/**
* 授权令牌(消费方不用传)
*/
@Null(message = "授权令牌需为空")
@JsonIgnore
@Schema(name = "accessToken", description = "授权令牌(消费方不用传)")
private String accessToken;
public WorkWechatBaseRequestDTO(
@NotNull(message = "商户号不能为空") Integer merchantId) {
this.merchantId = merchantId;
}
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateAttachFileDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgAttachFileDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
/**
* 文件的media_id
*/
@JsonProperty("media_id")
@Schema(name = "mediaId", description = "文件素材ID")
private String mediaId;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateAttachImageDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgAttachImageDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
/**
* 图片的media_id
*/
@JsonProperty("media_id")
@Schema(name = "mediaId", description = "图片的素材ID")
private String mediaId;
/**
* 图片的链接
*/
@JsonProperty("pic_url")
@Schema(name = "picUrl", description = "图片的链接")
private String picUrl;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateAttachLinkDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgAttachLinkDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
/**
* 图文消息标题,最长128个字节
*/
@JsonProperty("title")
@Schema(name = "title", description = "图文消息标题,最长128个字节")
private String title;
/**
* 图文消息封面的url,最长2048个字节
*/
@JsonProperty("picurl")
@Schema(name = "picUrl", description = "图文消息封面的url,最长2048个字节")
private String picUrl;
/**
* 图文消息的描述,最多512个字节
*/
@JsonProperty("desc")
@Schema(name = "desc", description = "图文消息的描述,最多512个字节")
private String desc;
/**
* 图文消息的链接,最长2048个字节
*/
@JsonProperty("url")
@Schema(name = "url", description = "图文消息的链接,最长2048个字节")
private String url;
}
package cn.com.glsx.execute.modules.model.workWechat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import io.swagger.v3.oas.annotations.media.Schema;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateAttachMiniprogramDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgAttachMiniprogramDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
/**
* 小程序消息标题,最多64个字节
*/
@JsonProperty("title")
@Schema(name = "title", description = "小程序消息标题,最多64个字节")
private String title;
/**
* 小程序消息封面的mediaid,封面图建议尺寸为520*416
*/
@JsonProperty("pic_media_id")
@Schema(name = "picMediaId", description = "小程序消息封面的mediaid,封面图建议尺寸为520*416")
private String picMediaId;
/**
* 小程序appid(可以在微信公众平台上查询),必须是关联到企业的小程序应用
*/
@JsonProperty("appid")
@Schema(name = "appId", description = "小程序appid(可以在微信公众平台上查询),必须是关联到企业的小程序应用")
private String appId;
/**
* 小程序page路径
*/
@JsonProperty("page")
@Schema(name = "page", description = "小程序page路径")
private String page;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateAttachVideoDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgAttachVideoDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
/**
* 视频的media_id
*/
@JsonProperty("media_id")
@Schema(name = "mediaId", description = "视频素材ID")
private String mediaId;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: WorkWechatExternalContactMsgAttachmentDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgAttachmentDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
/**
* 附件类型,可选image、link、miniprogram或者video
* @link WorkWechatMsgTypeEnum
*/
@JsonProperty("msgtype")
@Schema(name = "msgType", description = "附件类型,可选image、link、miniprogram或者video")
private String msgType;
@JsonProperty("image")
@Schema(name = "image", description = "图片附件")
private WorkWechatExternalContactMsgAttachImageDTO image;
@JsonProperty("link")
@Schema(name = "link", description = "图文消息附件")
private WorkWechatExternalContactMsgAttachLinkDTO link;
@JsonProperty("miniprogram")
@Schema(name = "miniprogram", description = "小程序消息附件")
private WorkWechatExternalContactMsgAttachMiniprogramDTO miniprogram;
@JsonProperty("video")
@Schema(name = "video", description = "视频附件")
private WorkWechatExternalContactMsgAttachVideoDTO video;
@JsonProperty("file")
@Schema(name = "file", description = "文件附件")
private WorkWechatExternalContactMsgAttachFileDTO file;
}
package cn.com.glsx.execute.modules.model.workWechat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonMethod;
import org.codehaus.jackson.annotate.JsonProperty;
import java.io.Serializable;
/**
* @Title: AddWorkWechatExternalContactMsgTemplateTextDTO.java
* @Description:
* @author Alvin
* @date 2021年10月27日 下午3:13:47
* @version V1.0
*/
@JsonAutoDetect(JsonMethod.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@ToString(includeFieldNames = true, callSuper = true)
public class WorkWechatExternalContactMsgTextDTO implements Serializable {
private static final long serialVersionUID = -1130690409738473507L;
@JsonProperty("content")
@Schema(name = "content", description = "消息内容")
private String content;
}
......@@ -3,7 +3,7 @@
<parent>
<groupId>cn.com.glsx</groupId>
<artifactId>platform-execute-server</artifactId>
<version>1.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
......@@ -71,11 +71,6 @@
<!-- local api -->
<dependency>
<groupId>cn.com.glsx</groupId>
<artifactId>rpc-scrm-wechat-api</artifactId>
<version>3.15.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.com.glsx</groupId>
<artifactId>platform-execute-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
......@@ -90,12 +85,6 @@
<artifactId>rest-service-echocenter-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<!-- dubbo api -->
<dependency>
<groupId>cn.com.glsx.scrm</groupId>
<artifactId>rpc-scrm-proxy-api</artifactId>
<version>3.7.0-SNAPSHOT</version>
</dependency>
<!--rabbitmq-->
<dependency>
......
package cn.com.glsx.execute.common.exception;
import cn.com.glsx.execute.modules.enums.exception.ResultEnum;
import com.glsx.plat.exception.SystemMessage;
import lombok.Getter;
import lombok.Setter;
/**
* @author payu
*/
@Setter
@Getter
public class AdminException extends RuntimeException {
private int errorCode;
private String message;
public AdminException() {
}
public AdminException(String message) {
super(message);
this.errorCode = SystemMessage.FAILURE.getCode();
this.message = message;
}
public AdminException(int errorCode, String message) {
super(message);
this.errorCode = errorCode;
this.message = message;
}
public AdminException(ResultEnum resultEnum) {
this.errorCode = resultEnum.getCode();
this.message = resultEnum.getMessage();
}
public AdminException(Throwable cause) {
super(cause);
}
public AdminException(String message, Throwable cause) {
super(message, cause);
}
}
package cn.com.glsx.execute.common.exception;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.glsx.plat.core.web.R;
import com.glsx.plat.exception.ExceptionLevel;
import com.glsx.plat.exception.GlobalRExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.BindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局异常处理
*
* @author payu
*/
@Slf4j
@RestControllerAdvice
public class AdminExceptionHandler extends GlobalRExceptionHandler {
@ExceptionHandler(AdminException.class)
public R handleAdminException(AdminException e) {
return R.error(e.getErrorCode(),e.getMessage());
}
/**
* Mybatis BindingException
*
* @param e
* @return
*/
@ExceptionHandler(BindingException.class)
public R handleBindingException(BindingException e) {
return R.error(e.getMessage());
}
@ExceptionHandler(ExcelDataConvertException.class)
public R handleExcelDataConvertException(ExcelDataConvertException e) {
return R.error(e.getMessage());
}
@Override
protected void saveException(Exception e, ExceptionLevel level) {
super.saveException(e, level);
}
}
package cn.com.glsx.execute.modules.controller.task;
import cn.com.glsx.execute.modules.model.sopTask.ExecuteSopTaskResponse;
import cn.com.glsx.execute.modules.model.sopTask.SopTaskToCustomerExecuteRequest;
import cn.com.glsx.execute.modules.model.sopTask.SopTaskToStaffExecuteRequest;
import cn.com.glsx.execute.modules.service.sopTask.ExecuteTaskService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Tag(name = "sop执行任务接口")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/sop/api/execute")
public class SopTaskExecuteController {
@Autowired
private ExecuteTaskService executeTaskService;
@PostMapping("/sendCustomer")
public ExecuteSopTaskResponse executeCustomer(SopTaskToCustomerExecuteRequest request){
return null;
}
@PostMapping("/sendStaff")
public ExecuteSopTaskResponse executeStaff(SopTaskToStaffExecuteRequest request){
return null;
}
}
......@@ -9,12 +9,17 @@ import cn.com.glsx.execute.modules.model.oneVone.BatchMessagingCrowConditionDTO;
import cn.com.glsx.execute.modules.model.oneVone.LabelRequestDTO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;
import org.bouncycastle.util.encoders.Hex;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
......@@ -194,6 +199,17 @@ public class RopRequestConveter {
Field[] declaredFields = clazz.getDeclaredFields();
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(request));
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
// 获取父类的属性字段
Class superclass = clazz.getSuperclass();
if (superclass != null) {
Field[] superclassDeclaredFields = superclass.getDeclaredFields();
extracted(superclassDeclaredFields, jsonObject, paramsMap);
}
extracted(declaredFields, jsonObject, paramsMap);
return paramsMap;
}
private static void extracted(Field[] declaredFields, JSONObject jsonObject, MultiValueMap<String, String> paramsMap) {
for (Field field : declaredFields) {
Object o = jsonObject.get(field.getName());
if (o == null) continue;
......@@ -203,6 +219,5 @@ public class RopRequestConveter {
paramsMap.add(field.getName(), o.toString());
}
}
return paramsMap;
}
}
package cn.com.glsx.execute.modules.converter.workWechat;
import cn.com.glsx.execute.modules.constant.DracConstant;
import cn.com.glsx.execute.modules.model.sopTask.AttContent;
import cn.com.glsx.execute.modules.model.workWechat.*;
import com.alibaba.fastjson.JSONObject;
import static cn.com.glsx.execute.modules.constant.DracConstant.AttType.*;
import static cn.com.glsx.execute.modules.constant.DracConstant.DracLink.*;
import static cn.com.glsx.execute.modules.constant.DracConstant.DracMiniProgram.*;
public class WorkWechatDTOConvert {
public static WorkWechatExternalContactMsgAttachmentDTO convertAttachment(AttContent dracWelcomeConfig) {
WorkWechatExternalContactMsgAttachmentDTO attachmentDTO = null;
switch (dracWelcomeConfig.getAttType()) {
case VEDIO:
attachmentDTO = convertVedioAttachment(dracWelcomeConfig);
break;
case URI:
attachmentDTO = convertUriAttachment(dracWelcomeConfig);
break;
case MINIPROGRAM:
attachmentDTO = convertMiniprogramAttachment(dracWelcomeConfig);
break;
case FILE:
attachmentDTO = convertFileAttachment(dracWelcomeConfig);
break;
default:
break;
}
return attachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertImageAttachment(AttContent content) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachImageDTO imageAtt = new WorkWechatExternalContactMsgAttachImageDTO();
imageAtt.setMediaId(content.getMediaId());
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.IMAGE);
workWechatExternalContactMsgAttachmentDTO.setImage(imageAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertVedioAttachment(AttContent content) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachVideoDTO vedioAtt = new WorkWechatExternalContactMsgAttachVideoDTO();
vedioAtt.setMediaId(content.getMediaId());
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.VEDIO);
workWechatExternalContactMsgAttachmentDTO.setVideo(vedioAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertUriAttachment(AttContent content) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachLinkDTO linkAtt = new WorkWechatExternalContactMsgAttachLinkDTO();
JSONObject contentJson = JSONObject.parseObject(content.getAttContent());
// {"title":"头号新闻","url":"http://xxxxx/yy/xx"}
linkAtt.setTitle(contentJson.getString(link_title_key));
linkAtt.setUrl(contentJson.getString(link_url_key));
linkAtt.setDesc(contentJson.getString(link_desc_key));
linkAtt.setPicUrl(contentJson.getString(link_picurl_key));
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.URI);
workWechatExternalContactMsgAttachmentDTO.setLink(linkAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertMiniprogramAttachment(AttContent content) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachMiniprogramDTO miniprogramAtt = new WorkWechatExternalContactMsgAttachMiniprogramDTO();
JSONObject contentJson = JSONObject.parseObject(content.getAttContent());
// {"appId":"","title":"头号新闻","page":"http://xxxxx/yy/xx","pic_url":"http://xxxxx/yy/xx","mediaId":""}
miniprogramAtt.setAppId(contentJson.getString(miniprogram_appid_key));
miniprogramAtt.setTitle(contentJson.getString(miniprogram_title_key));
miniprogramAtt.setPage(contentJson.getString(miniprogram_page_key));
miniprogramAtt.setPicMediaId(contentJson.getString(miniprogram_mediaid_key));
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.MINIPROGRAM);
workWechatExternalContactMsgAttachmentDTO.setMiniprogram(miniprogramAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
private static WorkWechatExternalContactMsgAttachmentDTO convertFileAttachment(AttContent content) {
WorkWechatExternalContactMsgAttachmentDTO workWechatExternalContactMsgAttachmentDTO = new WorkWechatExternalContactMsgAttachmentDTO();
WorkWechatExternalContactMsgAttachFileDTO fileAtt = new WorkWechatExternalContactMsgAttachFileDTO();
fileAtt.setMediaId(content.getMediaId());
workWechatExternalContactMsgAttachmentDTO.setMsgType(DracConstant.QyAttType.FILE);
workWechatExternalContactMsgAttachmentDTO.setFile(fileAtt);
return workWechatExternalContactMsgAttachmentDTO;
}
/**
* 转换文本内容资源
* @param content
* @return
*/
public static WorkWechatExternalContactMsgTextDTO convertTextAttachment(AttContent content) {
WorkWechatExternalContactMsgTextDTO workWechatExternalContactMsgTextDTO = new WorkWechatExternalContactMsgTextDTO();
workWechatExternalContactMsgTextDTO.setContent(content.getAttContent());
return workWechatExternalContactMsgTextDTO;
}
}
package cn.com.glsx.execute.modules.service.proxy;
import cn.com.glsx.execute.modules.constant.DracConstant;
import cn.com.glsx.execute.modules.converter.rop.RopRequestConveter;
import cn.com.glsx.execute.modules.enums.rop.MethodEnum;
import cn.com.glsx.execute.modules.enums.rop.ModelBaseUrlEnum;
import cn.com.glsx.execute.modules.enums.wechat.WorkWechatMediaTypeEnum;
import cn.com.glsx.execute.modules.model.rop.RopResponseDTO;
import cn.com.glsx.execute.modules.model.wechat.GetUserInfoRequest;
import cn.com.glsx.execute.modules.model.wechat.GetUserInfoResponse;
import cn.com.glsx.execute.modules.model.workWechat.*;
import cn.com.glsx.execute.utils.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class WorkWechatService {
@Autowired
private Environment environment;
public void executeGroupMessage(AddWorkWechatExternalContactMsgTemplateRequestDTO sendWorkDTO) {
}
public String uploadMediaGetMediaId(UpLoadMediaToWorkWechatRequestDTO requestDTO) {
Integer attType = requestDTO.getAttType();
String attContent = requestDTO.getContent();
Integer merchantId = requestDTO.getMerchantId();
String fileName = "default-";
//附件文件解析
if (attType.equals(DracConstant.AttType.FILE)) {
// workWechatMediaTypeEnum = WorkWechatMediaTypeEnum.FILE;
String ecodingName = null;
try {
//从json格式中提取pdf文件路径
//去除转义符
String unescapeJava = StringEscapeUtils.unescapeJava(attContent);
JSONObject jsonObject = JSONObject.parseObject(unescapeJava);
Map map = jsonObject;
attContent = String.valueOf(map.get("url"));
String name = String.valueOf(map.get("fileName"));
ecodingName = new String(name.getBytes("utf-8"), "UTF-8");
} catch (UnsupportedEncodingException e) {
log.info("欢迎语附件名称转码异常:{}", e);
}
//获取文件扩展名
String fileType = FileUtils.getFileType(attContent);
fileName = "file-" + ecodingName + fileType;
}
if (attType.equals(DracConstant.AttType.IMAGE)) {
fileName = "image-" + UUIDUtils.getUUID();
} else if (attType.equals(DracConstant.AttType.VEDIO)) {
fileName = "vedio-" + UUIDUtils.getUUID();
} else if (attType.equals(DracConstant.AttType.URI)) {
fileName = "uri-" + UUIDUtils.getUUID();
}
UploadWorkWechatMediaRequestDTO dto = new UploadWorkWechatMediaRequestDTO();
dto.setFileName(fileName);
dto.setData(attContent);
dto.setMediaType(attType);
dto.setMerchantId(merchantId);
try {
RopResponseDTO<UploadWorkWechatMediaResponseDTO> remoteResponse = doUploadMediaToWorkWechat(dto);
if (remoteResponse.getCode().equals("200")) {
return remoteResponse.getData().getMediaId();
}
}catch (Exception e){
log.error("上传素材到企微失败:{}",e.getMessage());
return StringUtil.EMPTY_STRING;
}
return StringUtil.EMPTY_STRING;
}
public RopResponseDTO<UploadWorkWechatMediaResponseDTO> doUploadMediaToWorkWechat(UploadWorkWechatMediaRequestDTO requestDTO) throws Exception{
String url = environment.getProperty(ModelBaseUrlEnum.ROP_SCRM_WECHAT.getBaseUrlConfig(),"");
MultiValueMap<String, String> paramsMap = RopRequestConveter.toMultiValueMap(requestDTO, UploadWorkWechatMediaRequestDTO.class);
log.info("WorkWechatService.doUploadMediaToWorkWechat 请求参数:{}",paramsMap);
String post = RopHttpUtil.post(paramsMap, String.class, url, MethodEnum.UPLOAD_MEDIA.getMethod(), null);
log.info("WorkWechatService.doUploadMediaToWorkWechat 请求结果:{}", JSON.toJSONString(post));
return JacksonUtils.X.parse(post, new TypeReference<RopResponseDTO<UploadWorkWechatMediaResponseDTO>>(){});
}
public RopResponseDTO<AddWorkWechatExternalContactMsgTemplateResponseDTO> addMsgTemplate(AddWorkWechatExternalContactMsgTemplateRequestDTO sendWorkDTO) throws Exception {
String url = environment.getProperty(ModelBaseUrlEnum.ROP_SCRM_WECHAT.getBaseUrlConfig(),"");
MultiValueMap<String, String> paramsMap = RopRequestConveter.toMultiValueMap(sendWorkDTO, AddWorkWechatExternalContactMsgTemplateResponseDTO.class);
log.info("WorkWechatService.addMsgTemplate 请求参数:{}",paramsMap);
String post = RopHttpUtil.post(paramsMap, String.class, url, MethodEnum.ADD_MESSAGE_TEMPLATE.getMethod(), null);
log.info("WorkWechatService.addMsgTemplate 请求结果:{}", JSON.toJSONString(post));
return JacksonUtils.X.parse(post, new TypeReference<RopResponseDTO<AddWorkWechatExternalContactMsgTemplateResponseDTO>>(){});
}
}
package cn.com.glsx.execute.modules.service.sopTask;
import cn.com.glsx.entmicro.constants.DracConstant;
import cn.com.glsx.execute.common.exception.AdminException;
import cn.com.glsx.execute.modules.converter.workWechat.WorkWechatDTOConvert;
import cn.com.glsx.execute.modules.enums.exception.ResultEnum;
import cn.com.glsx.execute.modules.model.rop.RopResponseDTO;
import cn.com.glsx.execute.modules.model.shorturl.GenerateUrlRequest;
import cn.com.glsx.execute.modules.model.sopTask.AttContent;
import cn.com.glsx.execute.modules.model.sopTask.SopTaskToCustomerExecuteRequest;
import cn.com.glsx.execute.modules.model.sopTask.SopTaskExecuteStaffRequest;
import cn.com.glsx.execute.modules.model.workWechat.AddWorkWechatExternalContactMsgTemplateRequestDTO;
import cn.com.glsx.execute.modules.model.workWechat.AddWorkWechatExternalContactMsgTemplateResponseDTO;
import cn.com.glsx.execute.modules.model.workWechat.UpLoadMediaToWorkWechatRequestDTO;
import cn.com.glsx.execute.modules.model.workWechat.WorkWechatExternalContactMsgAttachmentDTO;
import cn.com.glsx.execute.modules.service.proxy.WorkWechatService;
import cn.com.glsx.execute.modules.service.shorturl.ShortUrlService;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import static cn.com.glsx.execute.modules.constant.DracConstant.AttType.*;
/**
* sop任务执行服务
*/
@Slf4j
@Service
public class ExecuteTaskService {
// 1文本,2图片,3视频,4小程序
private static final String uploadQyMediaType = "2,3";
@Autowired
private WorkWechatService workWechatService;
@Autowired
private ShortUrlService shortUrlService;
/**
* 企微群发
*
* @return
*/
public String sendGroupMessage(SopTaskToCustomerExecuteRequest request) {
// 1、构建企微群发api参数
AddWorkWechatExternalContactMsgTemplateRequestDTO sendWorkDTO = buildGroupMessageParam(request);
// 2、发送群发
for (SopTaskExecuteStaffRequest executeStaff : request.getExecuteStaffRequestList()) {
// 发送人
sendWorkDTO.setSender(executeStaff.getSendUserId());
// 发送客户
sendWorkDTO.setExternalUserIdList(executeStaff.getSendExternalUserId());
// 授权商户号
sendWorkDTO.setMerchantId(request.getMerchantId());
try {
log.info("群发参数详情:{}", JSONObject.toJSONString(sendWorkDTO));
RopResponseDTO<AddWorkWechatExternalContactMsgTemplateResponseDTO> sendResponse = workWechatService.addMsgTemplate(sendWorkDTO);
log.info("send qy wechatmessage staffid:{}, sendResult:{}", JSONObject.toJSONString(executeStaff.getSendUserId()), JSONObject.toJSONString(sendResponse));
if (sendResponse.getCode().equals("200")) {
return sendResponse.getData().getMsgId();
}
} catch (Exception e) {
log.error("群发失败:{}", e.getMessage());
}
}
return null;
}
/**
* 构建企微群发参数
*
* @param request
* @return
*/
public AddWorkWechatExternalContactMsgTemplateRequestDTO buildGroupMessageParam(SopTaskToCustomerExecuteRequest request) {
AddWorkWechatExternalContactMsgTemplateRequestDTO sendWorkDTO = new AddWorkWechatExternalContactMsgTemplateRequestDTO();
// 1、chatType
String chatType = request.getChatType();
if (StringUtils.isEmpty(chatType)) {
//
throw new AdminException(ResultEnum.CHAT_TYPE_EMPTY);
}
sendWorkDTO.setChatType(chatType);
// 2、附件数据封装
List<AttContent> contentList = request.getContentList();
if (!CollectionUtils.isEmpty(contentList)) {
// 上传素材
uploadMediaToQy(contentList, request.getMerchantId());
List<WorkWechatExternalContactMsgAttachmentDTO> attachmentDTOList = new ArrayList<>();
for (AttContent content : contentList) {
if (content.getAttType().equals(DracConstant.AttType.TEXT)) {
sendWorkDTO.setText(WorkWechatDTOConvert.convertTextAttachment(content));
} else {
attachmentDTOList.add(WorkWechatDTOConvert.convertAttachment(content));
}
}
sendWorkDTO.setAttachments(attachmentDTOList);
}
return sendWorkDTO;
}
/**
* 上传素材到企微
*
* @param contentList
* @return
*/
private List<AttContent> uploadMediaToQy(List<AttContent> contentList, Integer merchantId) {
for (AttContent attContent : contentList) {
UpLoadMediaToWorkWechatRequestDTO workWechatDTO = new UpLoadMediaToWorkWechatRequestDTO();
Integer attType = attContent.getAttType();
if (attType.equals(TEXT)) {
workWechatDTO.setContent(attContent.getAttContent());
continue;
} else if (attType.equals(URI)) {
// 构建短链
workWechatDTO.setContent(buildShortURL(attContent.getAttContent()));
continue;
} else {
JSONObject attContentJSON = JSONObject.parseObject(attContent.getAttContent());
workWechatDTO.setContent(attContentJSON.get("pic_url").toString());
}
workWechatDTO.setMerchantId(merchantId);
workWechatDTO.setAttType(attType);
String mediaId = workWechatService.uploadMediaGetMediaId(workWechatDTO);
attContent.setMediaId(mediaId);
}
return contentList;
}
/**
* 构建短链
* @param attContent
* @return
*/
public String buildShortURL(String attContent) {
GenerateUrlRequest request = new GenerateUrlRequest();
request.setUrl(JSONObject.parseObject(attContent).get("url").toString());
return shortUrlService.generate(request);
}
/**
* 发送朋友圈
*
* @return
*/
public Boolean sendMoment() {
return false;
}
/**
* 发送企微通知
*
* @return
*/
public Boolean sendNotice() {
return false;
}
/**
* 发送短信
*
* @return
*/
public Boolean sendMessage() {
return false;
}
}
package cn.com.glsx.execute.utils;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author zhouhaibao
* @version 1.0
* @description: 读取文件流
* @date 2021/11/12 10:41
*/
public class FileUtils {
/**
* 根据url下载文件流
*
* @param urlStr
* @return
*/
public static InputStream getInputStreamFromUrl(String urlStr) {
InputStream inputStream = null;
try {
//url解码
URL url = new URL(java.net.URLDecoder.decode(urlStr, "UTF-8"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3 * 1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//得到输入流
inputStream = conn.getInputStream();
} catch (IOException e) {
e.getStackTrace();
}
return inputStream;
}
/**
* 获取文件扩展名
*
* @return
*/
public static String getFileType(String filePath) {
if(filePath.lastIndexOf(".") != -1 && filePath.lastIndexOf(".") != 0){
return filePath.substring(filePath.lastIndexOf("."));
}
return "";
}
}
package cn.com.glsx.execute.utils;
import java.util.UUID;
/**
* @author zhouhaibao
* @version 1.0
* @description: UUID工具类
* @date 2021/11/10 12:48
*/
public class UUIDUtils {
public static String getUUID() {
return UUID.randomUUID().toString().replace("-", "");
}
}
package cn.com.glsx.cn.com.glsx.sopTask;
import cn.com.glsx.cn.com.glsx.BaseTest;
import cn.com.glsx.execute.modules.constant.DracConstant;
import cn.com.glsx.execute.modules.model.sopTask.AttContent;
import cn.com.glsx.execute.modules.model.sopTask.SopTaskToCustomerExecuteRequest;
import cn.com.glsx.execute.modules.model.sopTask.SopTaskExecuteStaffRequest;
import cn.com.glsx.execute.modules.service.sopTask.ExecuteTaskService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
public class ExecuteTaskServiceTest extends BaseTest {
@Autowired
private ExecuteTaskService executeTaskService;
@Test
public void sendGroupMessage(){
SopTaskToCustomerExecuteRequest request = new SopTaskToCustomerExecuteRequest();
List<AttContent> list = new ArrayList<>();
AttContent content = new AttContent();
content.setAttContent("{ \"pic_url\": \"https://wx.glsx.com.cn/upload/biz/9e913dc8-92d6-44d8-96e5-7af16d78f999.jpg\" }");
content.setAttType(DracConstant.AttType.IMAGE);
list.add(content);
List<SopTaskExecuteStaffRequest> executeStaffRequestList = new ArrayList<>();
SopTaskExecuteStaffRequest staffRequest = new SopTaskExecuteStaffRequest();
staffRequest.setSendUserId("wo-ZewEAAAuEZrLUMtmMbvLVAb61FQBw");
executeStaffRequestList.add(staffRequest);
request.setContentList(list);
request.setMerchantId(44211227);
request.setSendType(2);
request.setChatType("single");
request.setExecuteStaffRequestList(executeStaffRequestList);
String string = executeTaskService.sendGroupMessage(request);
System.out.println(string);
}
}
......@@ -7,8 +7,8 @@ import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-10-15T17:20:19+0800",
comments = "version: 1.5.2.Final, compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)"
date = "2023-12-20T11:19:39+0800",
comments = "version: 1.5.2.Final, compiler: javac, environment: Java 1.8.0_331 (Oracle Corporation)"
)
public class UserConverterImpl implements UserConverter {
......
......@@ -8,7 +8,7 @@
<groupId>cn.com.glsx</groupId>
<artifactId>platform-execute-server</artifactId>
<version>1.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<description>Microservice Scaffolding project for Spring Boot</description>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!