Commit aa98c6e0 authored by lifei's avatar lifei

提交临时代码

parent 0d86f6fc
......@@ -14,4 +14,5 @@ api/null/*
job/null/*
logs
*/null
*/logs
\ No newline at end of file
*/logs
/.metadata/
......@@ -383,7 +383,7 @@ public class GroupController {
public List<GroupSimpleVo> myManage(@RequestHeader("passport") String passport,
@RequestParam(value = "offset", defaultValue = "0") Integer offset,
@RequestParam(value = "size", defaultValue = "20") Integer size,
@RequestParam(value = "type", defaultValue = "1") Integer type) {
@RequestParam(value = "type", defaultValue = "1") String type) {
return groupService.listMyManageGroups(passport, offset, size, type);
}
......
package mobi.mixiong.camp.controller.group.api.v1;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import mobi.mixiong.camp.CommonResponse;
......@@ -8,10 +9,7 @@ import mobi.mixiong.camp.PageBean;
import mobi.mixiong.camp.enums.GroupMsgSendType;
import mobi.mixiong.camp.exception.ServerException;
import mobi.mixiong.camp.service.group.GroupMsgService;
import mobi.mixiong.camp.service.group.vo.GroupMsgHistoryItemVo;
import mobi.mixiong.camp.service.group.vo.GroupMsgItemVo;
import mobi.mixiong.camp.service.group.vo.GroupMsgParam;
import mobi.mixiong.camp.service.group.vo.GroupMsgVo;
import mobi.mixiong.camp.service.group.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -94,4 +92,18 @@ public class GroupMsgController {
public GroupMsgHistoryItemVo getGroupMsgHistoryItemVo(@RequestParam("history_id")Long historyId, @RequestHeader("passport") String passport){
return groupMsgService.getHistoryVo(historyId,false);
}
@GetMapping("/sms_template_list")
public PageBean<JSONObject> smsTemplateList(@RequestParam(value = "offset",defaultValue = "0") Integer offset,
@RequestParam(value = "size",defaultValue = "10") Integer size) {
return groupMsgService.listAliYunSMSTemplate(offset, size);
}
@PostMapping("/asyncAliyunSmsTemplate2redis")
public CommonResponse asyncAliyunSmsTemplate2redis() {
groupMsgService.asyncAliyunSmsTemplate2redis();
return CommonResponse.DEFAULT_SUCCESS;
}
}
......@@ -6,7 +6,8 @@ import java.util.stream.Collectors;
public enum GroupMsgDetailType {
IMAGE(1,"图片"),
TEXT(2,"文字");
TEXT(2,"文字"),
SMS(3, "短信");
private final int value;
private final String desc;
......
package mobi.mixiong.camp.cache.sms;
import mobi.mixiong.camp.cache.CacheUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class SmsTemplateCache {
@Resource(name = "stringRedisTemplate")
private RedisTemplate<String, String> smsTemplateTemplate;
// 阿里云短信模板Code,英文逗号隔开
private final String TEMPLATE_CODE_KEY = "mx:AliYunSmsTemplateCode";
private final String SMS_TEMPLATE_PREFIX = "mx:AliYunSmsTemplate:";
public String getTemplateCodes() {
return CacheUtil.val().get(smsTemplateTemplate, TEMPLATE_CODE_KEY);
}
public void setSmsTemplate(String templateCode, String value) {
CacheUtil.val().set(smsTemplateTemplate, SMS_TEMPLATE_PREFIX + templateCode, value);
}
public String getSmsTemplate(String templateCode) {
return CacheUtil.val().get(smsTemplateTemplate, SMS_TEMPLATE_PREFIX + templateCode);
}
}
......@@ -68,6 +68,10 @@ public interface GroupDao extends CustomizedMapper<Group> {
@Lang(SimpleSelectInExtendedLanguageDriver.class)
List<GroupSearchDto> listMyCreateGroups(String passport, @Param("list") List<Long> programIds, @Param("stage_idx") Integer stageIdx, @Param("group_idx") Integer groupIdx, Integer offset, Integer size);
@Select("select * from `group` where passport = #{passport} and status =1 and type = #{type} order by create_time desc limit #{offset}, #{size}")
List<Group> listMyManageGroups(String passport, Integer offset, Integer size,Integer type);
@Select("<script>" +
"select * from `group` where passport = #{passport} and status =1"
+ "<if test='list != null and list.size > 0'> and type in <foreach collection='list' item='item' open='(' separator=',' close=')'> #{item} </foreach></if>"
+ "order by create_time desc limit #{offset}, #{size}"
+ "</script>")
List<Group> listMyManageGroups(String passport, Integer offset, Integer size, @Param("list") List<String> type);
}
......@@ -42,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service("groupDs")
@EnableAspectJAutoProxy(exposeProxy = true)
......@@ -420,8 +421,9 @@ public class GroupDs {
return GroupDto.from(groupCo, count);
}
public List<Group> listMyManageGroups(String passport, Integer offset, Integer size, Integer type) {
return groupDao.listMyManageGroups(passport, offset, size, type);
public List<Group> listMyManageGroups(String passport, Integer offset, Integer size, String type) {
List<String> types = Stream.of(type.split(",")).collect(Collectors.toList());
return groupDao.listMyManageGroups(passport, offset, size, types);
}
public List<Long> listGroupsByProgram(Long programId) {
......
......@@ -108,8 +108,13 @@ public class GroupMsgJob implements Job {
.otherParam(ImOtherParam.builder().role(GroupMemberRole.MANAGER.role()).build()).build();
break;
}
case SMS: {
}
default:
break;
}
if(param != null){
if (param != null) {
msgSendASyncService.sendIMGroupMsg(param);
}
}
......
......@@ -26,6 +26,11 @@
<artifactId>aliyun-java-sdk-sts</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package mobi.mixiong.camp.service.group;
import com.alibaba.fastjson.JSONObject;
import mobi.mixiong.camp.PageBean;
import mobi.mixiong.camp.service.group.vo.GroupMsgHistoryItemVo;
import mobi.mixiong.camp.service.group.vo.GroupMsgItemVo;
import mobi.mixiong.camp.service.group.vo.GroupMsgParam;
import mobi.mixiong.camp.service.group.vo.GroupMsgVo;
import mobi.mixiong.camp.service.group.vo.*;
import java.util.List;
......@@ -25,4 +23,8 @@ public interface GroupMsgService {
PageBean<GroupMsgHistoryItemVo> listMyMsgSendHistory(String passport, Integer status, Integer offset, Integer size);
GroupMsgHistoryItemVo getHistoryVo(Long historyId, boolean needOneDetails);
PageBean<JSONObject> listAliYunSMSTemplate(Integer offset, Integer size);
void asyncAliyunSmsTemplate2redis();
}
......@@ -81,7 +81,7 @@ public interface GroupService {
*/
List<GroupMemberVo> listGroupManagerVo(Long groupId);
List<GroupSimpleVo> listMyManageGroups(String passport, Integer offset, Integer size,Integer type);
List<GroupSimpleVo> listMyManageGroups(String passport, Integer offset, Integer size, String type);
List<GroupListItemVo> list(List<GroupMemberCo> members);
......
package mobi.mixiong.camp.service.group.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.cyril.event.channel.EventChannel;
import com.cyril.event.exception.PublishEventException;
import com.github.pagehelper.PageHelper;
......@@ -10,6 +18,7 @@ import com.google.common.collect.Lists;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import mobi.mixiong.camp.PageBean;
import mobi.mixiong.camp.cache.sms.SmsTemplateCache;
import mobi.mixiong.camp.constant.OnsEventType;
import mobi.mixiong.camp.ds.group.GroupDs;
import mobi.mixiong.camp.ds.group.GroupMemberDs;
......@@ -33,6 +42,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -40,6 +51,11 @@ import java.util.stream.Collectors;
@Slf4j
public class GroupMsgServiceImpl implements GroupMsgService {
// 当前类使用的阿里云Sdk短信调用参数,目前只有"cn-hangzhou"这个region可用, 不要使用填写其他region的值
public static final String REGION_CN_HANGZHOU = "cn-hangzhou";
private String accessKeyId = "LTAI4Fzc8WyCFUMomrDYC6zo";
private String accessKeySecret = "ORgAqrZ64EtOfYUuFigFqAVZfFl1uv";
@Autowired
private GroupMsgDs groupMsgDs;
......@@ -52,6 +68,9 @@ public class GroupMsgServiceImpl implements GroupMsgService {
@Autowired
private EventChannel eventChannel;
@Autowired
private SmsTemplateCache smsTemplateCache;
@Override
@Transactional(transactionManager = "transactionManager", rollbackFor = Exception.class)
@SneakyThrows
......@@ -209,6 +228,34 @@ public class GroupMsgServiceImpl implements GroupMsgService {
return getHistoryVo(history, needOneDetails);
}
/**
* 查询阿里云短信模板
* @return
*/
@Override
public PageBean<JSONObject> listAliYunSMSTemplate(Integer offset, Integer size) {
String templateCodes = smsTemplateCache.getTemplateCodes();
if (StringUtils.isEmpty(templateCodes)) {
throw new ServerException("系统中暂时还没有短信模板Code, 请联系系统人员添加");
}
List<String> list = Arrays.asList(templateCodes.split(","));
int totalSize = list.size();
int totalPage = (totalSize % size) == 0 ? totalSize / size : totalSize / size + 1;
int currentPage = offset / size;
List<String> subList = list.subList(offset, list.size() >= offset + size ? offset + size : list.size());
List<JSONObject> returnList = new ArrayList<>();
for (String code : subList) {
String content = smsTemplateCache.getSmsTemplate(code);
returnList.add(JSON.parseObject(content));
}
return new PageBean<>(totalPage, totalSize, currentPage, returnList);
}
@Override
public void asyncAliyunSmsTemplate2redis() {
queryAliyunSmsTemplateList();
}
private GroupMsgHistoryItemVo getHistoryVo(GroupMsgHistory history, boolean needOneDetails) {
if (history == null) {
throw new ServerException("id 不正确");
......@@ -241,4 +288,37 @@ public class GroupMsgServiceImpl implements GroupMsgService {
return null;
}
/**
* 查询阿里云的短信模板,并存入本地Redis中
*/
private void queryAliyunSmsTemplateList() {
String templateCodes = smsTemplateCache.getTemplateCodes();
String[] split = templateCodes.split(",");
// 参照阿里云sdk demo例子
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("dysmsapi.aliyuncs.com");
// 这个值是阿里云写死的值,换成别的或者不传,则版本号错误,需要确认接口的版本号,如云通信短信、语音、流量服务的Version=2017-05-25。阿里云文档写挺坑的
request.setSysVersion("2017-05-25");
request.setSysAction("QuerySmsTemplate");
request.putQueryParameter("RegionId", "cn-hangzhou");
// 通过Code 去查阿里云的模板内容
for (String templateCode : split) {
try {
request.putQueryParameter("TemplateCode", templateCode);
CommonResponse response = client.getCommonResponse(request);
// add to redis
smsTemplateCache.setSmsTemplate(templateCode, response.getData());
} catch (ServerException e) {
log.error("listAliYunSMSTemplate method ServerException :", e);
} catch (ClientException e) {
log.error("listAliYunSMSTemplate method ClientException e", e);
}
}
}
}
......@@ -231,7 +231,7 @@ public class GroupServiceImpl implements GroupService {
}
@Override
public List<GroupSimpleVo> listMyManageGroups(String passport, Integer offset, Integer size, Integer type) {
public List<GroupSimpleVo> listMyManageGroups(String passport, Integer offset, Integer size, String type) {
List<Group> groups = groupDs.listMyManageGroups(passport, offset, size, type);
return groups.stream().map(GroupSimpleVo::from).collect(Collectors.toList());
......
package mobi.mixiong.camp.service.group.vo;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class AliYunSMSTemplateVo {
private String templateCode;
private String templateContent;
private String templateName;
private String templateStatus;
private Integer templateType;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment