- 添加短信服务 admin api
This commit is contained in:
parent
5c68383abb
commit
d1a793729a
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.mall.admin.application.controller.admins;
|
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.SmsService;
|
||||||
import cn.iocoder.mall.admin.api.bo.sms.PageSmsTemplateBO;
|
import cn.iocoder.mall.admin.api.bo.sms.PageSmsTemplateBO;
|
||||||
import cn.iocoder.mall.admin.api.dto.sms.PageQuerySmsSignDTO;
|
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.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信服务
|
* 短信服务
|
||||||
@ -21,33 +19,34 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
* @time 2019/5/26 12:26 PM
|
* @time 2019/5/26 12:26 PM
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("sms/template")
|
@RequestMapping("admins/sms/template")
|
||||||
@Api("短信服务(短信模板)")
|
@Api("短信服务(短信模板)")
|
||||||
public class SmsTemplateController {
|
public class SmsTemplateController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SmsService smsService;
|
private SmsService smsService;
|
||||||
|
|
||||||
@PostMapping("page")
|
@GetMapping("page")
|
||||||
@ApiOperation("短信模板-page")
|
@ApiOperation("短信模板-page")
|
||||||
public PageSmsTemplateBO pageSign(PageQuerySmsTemplateDTO pageQuerySmsTemplateDTO) {
|
public CommonResult<PageSmsTemplateBO> pageSign(PageQuerySmsTemplateDTO pageQuerySmsTemplateDTO) {
|
||||||
return smsService.pageSmsTemplate(pageQuerySmsTemplateDTO);
|
return CommonResult.success(smsService.pageSmsTemplate(pageQuerySmsTemplateDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("add")
|
@PostMapping("add")
|
||||||
@ApiOperation("短信模板-添加")
|
@ApiOperation("短信模板-添加")
|
||||||
public void addSign(SmsTemplateAddPO smsTemplateAddPO) {
|
public CommonResult addSign(SmsTemplateAddPO smsTemplateAddPO) {
|
||||||
smsService.addTemplate(
|
smsService.addTemplate(
|
||||||
smsTemplateAddPO.getSmsSignId(),
|
smsTemplateAddPO.getSmsSignId(),
|
||||||
smsTemplateAddPO.getTemplateCode(),
|
smsTemplateAddPO.getTemplateCode(),
|
||||||
smsTemplateAddPO.getTemplate(),
|
smsTemplateAddPO.getTemplate(),
|
||||||
smsTemplateAddPO.getPlatform(),
|
smsTemplateAddPO.getPlatform(),
|
||||||
smsTemplateAddPO.getSmsType());
|
smsTemplateAddPO.getSmsType());
|
||||||
|
return CommonResult.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("update")
|
@PutMapping("update")
|
||||||
@ApiOperation("短信模板-更新")
|
@ApiOperation("短信模板-更新")
|
||||||
public void updateSign(SmsTemplateUpdatePO smsTemplateUpdatePO) {
|
public CommonResult updateSign(SmsTemplateUpdatePO smsTemplateUpdatePO) {
|
||||||
smsService.updateTemplate(
|
smsService.updateTemplate(
|
||||||
smsTemplateUpdatePO.getId(),
|
smsTemplateUpdatePO.getId(),
|
||||||
smsTemplateUpdatePO.getSmsSignId(),
|
smsTemplateUpdatePO.getSmsSignId(),
|
||||||
@ -55,11 +54,13 @@ public class SmsTemplateController {
|
|||||||
smsTemplateUpdatePO.getTemplate(),
|
smsTemplateUpdatePO.getTemplate(),
|
||||||
smsTemplateUpdatePO.getPlatform(),
|
smsTemplateUpdatePO.getPlatform(),
|
||||||
smsTemplateUpdatePO.getSmsType());
|
smsTemplateUpdatePO.getSmsType());
|
||||||
|
return CommonResult.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("deleted")
|
@DeleteMapping("deleted")
|
||||||
@ApiOperation("短信模板-删除")
|
@ApiOperation("短信模板-删除")
|
||||||
public void deletedSign(@RequestParam("id") Integer id) {
|
public CommonResult deletedSign(@RequestParam("id") Integer id) {
|
||||||
smsService.deleteTemplate(id);
|
smsService.deleteTemplate(id);
|
||||||
|
return CommonResult.success(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package cn.iocoder.mall.admin.api.bo.sms;
|
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 com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package cn.iocoder.mall.admin.api.bo.sms;
|
package cn.iocoder.mall.admin.api.bo.sms;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,11 +40,19 @@ public class PageSmsTemplateBO {
|
|||||||
/**
|
/**
|
||||||
* 短信签名 id
|
* 短信签名 id
|
||||||
*/
|
*/
|
||||||
private String platformId;
|
private String platform;
|
||||||
|
/**
|
||||||
|
* 短信模板 Code
|
||||||
|
*/
|
||||||
|
private String templateCode;
|
||||||
/**
|
/**
|
||||||
* 短信模板
|
* 短信模板
|
||||||
*/
|
*/
|
||||||
private String template;
|
private String template;
|
||||||
|
/**
|
||||||
|
* 短信类型
|
||||||
|
*/
|
||||||
|
private Integer smsType;
|
||||||
/**
|
/**
|
||||||
* 审核状态
|
* 审核状态
|
||||||
*
|
*
|
||||||
@ -54,6 +65,16 @@ public class PageSmsTemplateBO {
|
|||||||
* 审核信息
|
* 审核信息
|
||||||
*/
|
*/
|
||||||
private String applyMessage;
|
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;
|
private Sign sign;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class Sign {
|
public static class Sign {
|
||||||
/**
|
/**
|
||||||
* 编号
|
* 编号
|
||||||
*/
|
*/
|
||||||
|
@ -13,8 +13,8 @@ import java.util.Arrays;
|
|||||||
public enum SmsTypeEnum implements IntArrayValuable {
|
public enum SmsTypeEnum implements IntArrayValuable {
|
||||||
|
|
||||||
VERIFICATION_CODE(1, "验证码"),
|
VERIFICATION_CODE(1, "验证码"),
|
||||||
NOTICE(1, "通知"),
|
NOTICE(2, "通知"),
|
||||||
MARKETING(2, "营销"),
|
MARKETING(3, "营销"),
|
||||||
;
|
;
|
||||||
|
|
||||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsTypeEnum::getValue).toArray();
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsTypeEnum::getValue).toArray();
|
||||||
|
@ -3,6 +3,7 @@ package cn.iocoder.mall.admin.api.dto.sms;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,16 +16,21 @@ import java.io.Serializable;
|
|||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class PageQuerySmsTemplateDTO implements Serializable {
|
public class PageQuerySmsTemplateDTO implements Serializable {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private Long current;
|
private Long current;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private Long size;
|
private Long size;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private Integer smsSignId;
|
private Integer smsSignId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private String template;
|
private String template;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private String applyStatus;
|
private String applyStatus;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.mall.admin.convert;
|
package cn.iocoder.mall.admin.convert;
|
||||||
|
|
||||||
import cn.iocoder.mall.admin.api.bo.sms.PageSmsSignBO;
|
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.api.bo.sms.SmsSignBO;
|
||||||
import cn.iocoder.mall.admin.dataobject.SmsSignDO;
|
import cn.iocoder.mall.admin.dataobject.SmsSignDO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
@ -25,4 +26,5 @@ public interface SmsSignConvert {
|
|||||||
|
|
||||||
@Mappings({})
|
@Mappings({})
|
||||||
List<PageSmsSignBO.Sign> convert(List<SmsSignDO> smsSignDOList);
|
List<PageSmsSignBO.Sign> convert(List<SmsSignDO> smsSignDOList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.PageSmsTemplateBO;
|
||||||
import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO;
|
import cn.iocoder.mall.admin.api.bo.sms.SmsTemplateBO;
|
||||||
|
import cn.iocoder.mall.admin.dataobject.SmsSignDO;
|
||||||
import cn.iocoder.mall.admin.dataobject.SmsTemplateDO;
|
import cn.iocoder.mall.admin.dataobject.SmsTemplateDO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mappings;
|
import org.mapstruct.Mappings;
|
||||||
@ -24,5 +25,8 @@ public interface SmsTemplateConvert {
|
|||||||
SmsTemplateBO convert(SmsTemplateDO smsTemplateDO);
|
SmsTemplateBO convert(SmsTemplateDO smsTemplateDO);
|
||||||
|
|
||||||
@Mappings({})
|
@Mappings({})
|
||||||
List<PageSmsTemplateBO.Template> convert(List<SmsTemplateDO> smsTemplateDO);
|
List<PageSmsTemplateBO.Template> convert(List<SmsTemplateDO> smsTemplateDOList);
|
||||||
|
|
||||||
|
@Mappings({})
|
||||||
|
List<PageSmsTemplateBO.Sign> convertTemplateSign(List<SmsSignDO> smsSignDOList);
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信
|
* 短信
|
||||||
@ -95,6 +95,9 @@ public class SmsServiceImpl implements SmsService {
|
|||||||
if (!StringUtils.isEmpty(queryDTO.getTemplate())) {
|
if (!StringUtils.isEmpty(queryDTO.getTemplate())) {
|
||||||
queryWrapper.like("template", queryDTO.getTemplate());
|
queryWrapper.like("template", queryDTO.getTemplate());
|
||||||
}
|
}
|
||||||
|
if (!StringUtils.isEmpty(queryDTO.getId())) {
|
||||||
|
queryWrapper.eq("id", queryDTO.getId());
|
||||||
|
}
|
||||||
|
|
||||||
Page<SmsTemplateDO> page = new Page<SmsTemplateDO>()
|
Page<SmsTemplateDO> page = new Page<SmsTemplateDO>()
|
||||||
.setSize(queryDTO.getSize())
|
.setSize(queryDTO.getSize())
|
||||||
@ -102,9 +105,39 @@ public class SmsServiceImpl implements SmsService {
|
|||||||
.setDesc("create_time");
|
.setDesc("create_time");
|
||||||
|
|
||||||
IPage<SmsTemplateDO> signPage = smsTemplateMapper.selectPage(page, queryWrapper);
|
IPage<SmsTemplateDO> signPage = smsTemplateMapper.selectPage(page, queryWrapper);
|
||||||
|
|
||||||
List<PageSmsTemplateBO.Template> templateList
|
List<PageSmsTemplateBO.Template> templateList
|
||||||
= SmsTemplateConvert.INSTANCE.convert(signPage.getRecords());
|
= 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()
|
return new PageSmsTemplateBO()
|
||||||
.setData(templateList)
|
.setData(templateList)
|
||||||
.setCurrent(signPage.getCurrent())
|
.setCurrent(signPage.getCurrent())
|
||||||
@ -121,7 +154,7 @@ public class SmsServiceImpl implements SmsService {
|
|||||||
new QueryWrapper<SmsSignDO>()
|
new QueryWrapper<SmsSignDO>()
|
||||||
.eq("platform", platform)
|
.eq("platform", platform)
|
||||||
.eq("sign", sign)
|
.eq("sign", sign)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (smsSignDO != null) {
|
if (smsSignDO != null) {
|
||||||
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(),
|
throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(),
|
||||||
|
Loading…
Reference in New Issue
Block a user