- 添加短信服务 admin api

This commit is contained in:
sin-ning@aliyun.com 2019-05-27 00:24:14 +08:00
parent 5c68383abb
commit d1a793729a
8 changed files with 91 additions and 26 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.mall.admin.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.admin.api.SmsService;
import cn.iocoder.mall.admin.api.bo.sms.PageSmsTemplateBO;
import cn.iocoder.mall.admin.api.dto.sms.PageQuerySmsSignDTO;
@ -9,10 +10,7 @@ import cn.iocoder.mall.admin.application.po.sms.SmsTemplateUpdatePO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* 短信服务
@ -21,33 +19,34 @@ import org.springframework.web.bind.annotation.RestController;
* @time 2019/5/26 12:26 PM
*/
@RestController
@RequestMapping("sms/template")
@RequestMapping("admins/sms/template")
@Api("短信服务(短信模板)")
public class SmsTemplateController {
@Autowired
private SmsService smsService;
@PostMapping("page")
@GetMapping("page")
@ApiOperation("短信模板-page")
public PageSmsTemplateBO pageSign(PageQuerySmsTemplateDTO pageQuerySmsTemplateDTO) {
return smsService.pageSmsTemplate(pageQuerySmsTemplateDTO);
public CommonResult<PageSmsTemplateBO> pageSign(PageQuerySmsTemplateDTO pageQuerySmsTemplateDTO) {
return CommonResult.success(smsService.pageSmsTemplate(pageQuerySmsTemplateDTO));
}
@PostMapping("add")
@ApiOperation("短信模板-添加")
public void addSign(SmsTemplateAddPO smsTemplateAddPO) {
public CommonResult addSign(SmsTemplateAddPO smsTemplateAddPO) {
smsService.addTemplate(
smsTemplateAddPO.getSmsSignId(),
smsTemplateAddPO.getTemplateCode(),
smsTemplateAddPO.getTemplate(),
smsTemplateAddPO.getPlatform(),
smsTemplateAddPO.getSmsType());
return CommonResult.success(null);
}
@PostMapping("update")
@PutMapping("update")
@ApiOperation("短信模板-更新")
public void updateSign(SmsTemplateUpdatePO smsTemplateUpdatePO) {
public CommonResult updateSign(SmsTemplateUpdatePO smsTemplateUpdatePO) {
smsService.updateTemplate(
smsTemplateUpdatePO.getId(),
smsTemplateUpdatePO.getSmsSignId(),
@ -55,11 +54,13 @@ public class SmsTemplateController {
smsTemplateUpdatePO.getTemplate(),
smsTemplateUpdatePO.getPlatform(),
smsTemplateUpdatePO.getSmsType());
return CommonResult.success(null);
}
@PostMapping("deleted")
@DeleteMapping("deleted")
@ApiOperation("短信模板-删除")
public void deletedSign(@RequestParam("id") Integer id) {
public CommonResult deletedSign(@RequestParam("id") Integer id) {
smsService.deleteTemplate(id);
return CommonResult.success(null);
}
}

View File

@ -1,11 +1,8 @@
package cn.iocoder.mall.admin.api.bo.sms;
import cn.iocoder.common.framework.jsonField.DateFieldSerializer;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;

View File

@ -1,8 +1,11 @@
package cn.iocoder.mall.admin.api.bo.sms;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
/**
@ -37,11 +40,19 @@ public class PageSmsTemplateBO {
/**
* 短信签名 id
*/
private String platformId;
private String platform;
/**
* 短信模板 Code
*/
private String templateCode;
/**
* 短信模板
*/
private String template;
/**
* 短信类型
*/
private Integer smsType;
/**
* 审核状态
*
@ -54,6 +65,16 @@ public class PageSmsTemplateBO {
* 审核信息
*/
private String applyMessage;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
///
/// 关联字段
@ -62,11 +83,12 @@ public class PageSmsTemplateBO {
* 签名信息
*/
private Sign sign;
}
@Data
@Accessors(chain = true)
public class Sign {
public static class Sign {
/**
* 编号
*/

View File

@ -13,8 +13,8 @@ import java.util.Arrays;
public enum SmsTypeEnum implements IntArrayValuable {
VERIFICATION_CODE(1, "验证码"),
NOTICE(1, "通知"),
MARKETING(2, "营销"),
NOTICE(2, "通知"),
MARKETING(3, "营销"),
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsTypeEnum::getValue).toArray();

View File

@ -3,6 +3,7 @@ package cn.iocoder.mall.admin.api.dto.sms;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
@ -15,16 +16,21 @@ import java.io.Serializable;
@Accessors(chain = true)
public class PageQuerySmsTemplateDTO implements Serializable {
@NotNull
private Long current;
@NotNull
private Long size;
@NotNull
private String id;
@NotNull
private Integer smsSignId;
@NotNull
private String template;
@NotNull
private String applyStatus;
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.admin.convert;
import cn.iocoder.mall.admin.api.bo.sms.PageSmsSignBO;
import cn.iocoder.mall.admin.api.bo.sms.PageSmsTemplateBO;
import cn.iocoder.mall.admin.api.bo.sms.SmsSignBO;
import cn.iocoder.mall.admin.dataobject.SmsSignDO;
import org.mapstruct.Mapper;
@ -25,4 +26,5 @@ public interface SmsSignConvert {
@Mappings({})
List<PageSmsSignBO.Sign> convert(List<SmsSignDO> smsSignDOList);
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.mall.admin.convert;
import cn.iocoder.mall.admin.api.bo.sms.PageSmsTemplateBO;
import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO;
import cn.iocoder.mall.admin.dataobject.SmsSignDO;
import cn.iocoder.mall.admin.dataobject.SmsTemplateDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
@ -24,5 +25,8 @@ public interface SmsTemplateConvert {
SmsTemplateBO convert(SmsTemplateDO smsTemplateDO);
@Mappings({})
List<PageSmsTemplateBO.Template> convert(List<SmsTemplateDO> smsTemplateDO);
List<PageSmsTemplateBO.Template> convert(List<SmsTemplateDO> smsTemplateDOList);
@Mappings({})
List<PageSmsTemplateBO.Sign> convertTemplateSign(List<SmsSignDO> smsSignDOList);
}

View File

@ -27,11 +27,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* 短信
@ -95,6 +95,9 @@ public class SmsServiceImpl implements SmsService {
if (!StringUtils.isEmpty(queryDTO.getTemplate())) {
queryWrapper.like("template", queryDTO.getTemplate());
}
if (!StringUtils.isEmpty(queryDTO.getId())) {
queryWrapper.eq("id", queryDTO.getId());
}
Page<SmsTemplateDO> page = new Page<SmsTemplateDO>()
.setSize(queryDTO.getSize())
@ -102,9 +105,39 @@ public class SmsServiceImpl implements SmsService {
.setDesc("create_time");
IPage<SmsTemplateDO> signPage = smsTemplateMapper.selectPage(page, queryWrapper);
List<PageSmsTemplateBO.Template> templateList
= SmsTemplateConvert.INSTANCE.convert(signPage.getRecords());
if (CollectionUtils.isEmpty(templateList)) {
return new PageSmsTemplateBO()
.setData(Collections.EMPTY_LIST)
.setCurrent(signPage.getCurrent())
.setSize(signPage.getSize())
.setTotal(signPage.getTotal());
}
// 获取 sign
Set<Integer> smsSignIds = templateList.stream().map(
PageSmsTemplateBO.Template::getSmsSignId).collect(Collectors.toSet());
List<SmsSignDO> smsSignDOList = smsSignMapper.selectList(
new QueryWrapper<SmsSignDO>().in("id", smsSignIds));
List<PageSmsTemplateBO.Sign> signList = SmsTemplateConvert.INSTANCE.convertTemplateSign(smsSignDOList);
Map<Integer, PageSmsTemplateBO.Sign> smsSignDOMap = signList
.stream().collect(Collectors.toMap(PageSmsTemplateBO.Sign::getId, o -> o));
// 设置 sign
templateList.forEach(template -> {
if (smsSignDOMap.containsKey(template.getSmsSignId())) {
template.setSign(smsSignDOMap.get(template.getSmsSignId()));
}
});
return new PageSmsTemplateBO()
.setData(templateList)
.setCurrent(signPage.getCurrent())
@ -121,7 +154,7 @@ public class SmsServiceImpl implements SmsService {
new QueryWrapper<SmsSignDO>()
.eq("platform", platform)
.eq("sign", sign)
);
);
if (smsSignDO != null) {
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(),