mirror of https://github.com/ZhongFuCheng3y/austin
commit
595b561497
@ -0,0 +1,33 @@
|
||||
package com.java3y.austin.common.enums;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
public enum FileType {
|
||||
IMAGE("10", "image"),
|
||||
VOICE("20", "voice"),
|
||||
COMMON_FILE("30", "file"),
|
||||
VIDEO("40", "video"),
|
||||
;
|
||||
private String code;
|
||||
private String dingDingName;
|
||||
|
||||
public static String dingDingNameByCode(String code) {
|
||||
for (FileType fileType : FileType.values()) {
|
||||
if (fileType.getCode().equals(code)) {
|
||||
return fileType.getDingDingName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.java3y.austin.handler.receipt;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMessageCorpconversationGetsendresultRequest;
|
||||
import com.dingtalk.api.response.OapiMessageCorpconversationGetsendresultResponse;
|
||||
import com.java3y.austin.common.constant.SendAccountConstant;
|
||||
import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount;
|
||||
import com.java3y.austin.support.utils.AccountUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 拉取钉钉工作消息回执信息
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DingDingWorkReceipt {
|
||||
|
||||
private static final String URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult";
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private AccountUtils accountUtils;
|
||||
public void pull() {
|
||||
// try {
|
||||
// for (int index = SendAccountConstant.START; true; index = index + SendAccountConstant.STEP) {
|
||||
// DingDingWorkNoticeAccount account = accountUtils.getAccount(index, SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class);
|
||||
// if (account == null) {
|
||||
// break;
|
||||
// }
|
||||
// String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + index);
|
||||
// DingTalkClient client = new DefaultDingTalkClient(URL);
|
||||
// OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest();
|
||||
// req.setAgentId(Long.valueOf(account.getAgentId()));
|
||||
// req.setTaskId(456L);
|
||||
// OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, accessToken);
|
||||
// System.out.println(rsp.getBody());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("DingDingWorkReceipt#pull");
|
||||
// }
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.java3y.austin.service.api.impl.service;
|
||||
|
||||
import com.java3y.austin.common.vo.BasicResultVO;
|
||||
import com.java3y.austin.service.api.domain.SendRequest;
|
||||
import com.java3y.austin.service.api.domain.SendResponse;
|
||||
import com.java3y.austin.service.api.impl.domain.SendTaskModel;
|
||||
import com.java3y.austin.service.api.service.RecallService;
|
||||
import com.java3y.austin.support.pipeline.ProcessContext;
|
||||
import com.java3y.austin.support.pipeline.ProcessController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* 撤回接口
|
||||
* @author 3y
|
||||
*/
|
||||
@Service
|
||||
public class RecallServiceImpl implements RecallService {
|
||||
|
||||
@Autowired
|
||||
private ProcessController processController;
|
||||
|
||||
@Override
|
||||
public SendResponse recall(SendRequest sendRequest) {
|
||||
SendTaskModel sendTaskModel = SendTaskModel.builder()
|
||||
.messageTemplateId(sendRequest.getMessageTemplateId())
|
||||
.build();
|
||||
ProcessContext context = ProcessContext.builder()
|
||||
.code(sendRequest.getCode())
|
||||
.processModel(sendTaskModel)
|
||||
.needBreak(false)
|
||||
.response(BasicResultVO.success()).build();
|
||||
ProcessContext process = processController.process(context);
|
||||
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg());
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.java3y.austin.service.api.service;
|
||||
|
||||
import com.java3y.austin.service.api.domain.BatchSendRequest;
|
||||
import com.java3y.austin.service.api.domain.SendRequest;
|
||||
import com.java3y.austin.service.api.domain.SendResponse;
|
||||
|
||||
/**
|
||||
* 撤回接口
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
public interface RecallService {
|
||||
|
||||
|
||||
/**
|
||||
* 根据模板ID撤回消息
|
||||
*
|
||||
* @param sendRequest
|
||||
* @return
|
||||
*/
|
||||
SendResponse recall(SendRequest sendRequest);
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.java3y.austin.web.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMediaUploadRequest;
|
||||
import com.dingtalk.api.response.OapiMediaUploadResponse;
|
||||
import com.java3y.austin.common.constant.SendAccountConstant;
|
||||
import com.java3y.austin.common.enums.ChannelType;
|
||||
import com.java3y.austin.common.enums.FileType;
|
||||
import com.java3y.austin.common.vo.BasicResultVO;
|
||||
import com.java3y.austin.web.service.MaterialService;
|
||||
import com.java3y.austin.web.vo.DataParam;
|
||||
import com.java3y.austin.web.vo.amis.UserTimeLineVo;
|
||||
import com.taobao.api.FileItem;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
/**
|
||||
* 素材管理接口
|
||||
* @author 3y
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/material")
|
||||
@Api("素材管理接口")
|
||||
@CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true", allowedHeaders = "*")
|
||||
public class MaterialController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MaterialService materialService;
|
||||
|
||||
|
||||
/**
|
||||
* 素材上传接口
|
||||
*
|
||||
* @param file 文件内容
|
||||
* @param sendAccount 发送账号
|
||||
* @param sendChannel 发送渠道
|
||||
* @param fileType 文件类型
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("/素材上传接口")
|
||||
public BasicResultVO uploadMaterial(@RequestParam("file") MultipartFile file, String sendAccount, Integer sendChannel, String fileType) {
|
||||
if (ChannelType.DING_DING_WORK_NOTICE.getCode().equals(sendChannel)) {
|
||||
return materialService.dingDingMaterialUpload(file, sendAccount, fileType);
|
||||
}
|
||||
return BasicResultVO.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.java3y.austin.web.service;
|
||||
|
||||
|
||||
import com.java3y.austin.common.vo.BasicResultVO;
|
||||
import com.java3y.austin.support.domain.MessageTemplate;
|
||||
import com.java3y.austin.web.vo.MessageTemplateParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 素材接口
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
public interface MaterialService {
|
||||
|
||||
|
||||
/**
|
||||
* 钉钉素材上传
|
||||
* @param file
|
||||
* @param sendAccount
|
||||
* @param fileType
|
||||
* @return
|
||||
*/
|
||||
BasicResultVO dingDingMaterialUpload(MultipartFile file, String sendAccount, String fileType);
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.java3y.austin.web.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMediaUploadRequest;
|
||||
import com.dingtalk.api.response.OapiMediaUploadResponse;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.java3y.austin.common.constant.SendAccountConstant;
|
||||
import com.java3y.austin.common.enums.FileType;
|
||||
import com.java3y.austin.common.enums.RespStatusEnum;
|
||||
import com.java3y.austin.common.vo.BasicResultVO;
|
||||
import com.java3y.austin.web.service.MaterialService;
|
||||
import com.java3y.austin.web.vo.UploadResponseVo;
|
||||
import com.taobao.api.FileItem;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
/**
|
||||
* @author 3y
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MaterialServiceImpl implements MaterialService {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
private static final String DING_DING_URL = "https://oapi.dingtalk.com/media/upload";
|
||||
|
||||
@Override
|
||||
public BasicResultVO dingDingMaterialUpload(MultipartFile file, String sendAccount, String fileType) {
|
||||
OapiMediaUploadResponse rsp;
|
||||
try {
|
||||
String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + sendAccount);
|
||||
DingTalkClient client = new DefaultDingTalkClient(DING_DING_URL);
|
||||
OapiMediaUploadRequest req = new OapiMediaUploadRequest();
|
||||
FileItem item = new FileItem(new StringBuilder().append(IdUtil.fastSimpleUUID()).append(file.getOriginalFilename()).toString(),
|
||||
file.getInputStream());
|
||||
req.setMedia(item);
|
||||
req.setType(FileType.dingDingNameByCode(fileType));
|
||||
rsp = client.execute(req, accessToken);
|
||||
if (rsp.getErrcode() == 0L) {
|
||||
return new BasicResultVO(RespStatusEnum.SUCCESS, UploadResponseVo.builder().id(rsp.getMediaId()).build());
|
||||
}
|
||||
log.error("MaterialService#dingDingMaterialUpload fail:{}", rsp.getErrmsg());
|
||||
} catch (Exception e) {
|
||||
log.error("MaterialService#dingDingMaterialUpload fail:{}", Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
return BasicResultVO.fail("未知错误,联系管理员");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.java3y.austin.web.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* 上传后成功返回素材的Id
|
||||
*/
|
||||
@Builder
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UploadResponseVo {
|
||||
private String id;
|
||||
}
|
Loading…
Reference in new issue