From d1a793729a2ca30c6942264fcfcc128deef091dd Mon Sep 17 00:00:00 2001 From: "sin-ning@aliyun.com" Date: Mon, 27 May 2019 00:24:14 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=20admin=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/SmsTemplateController.java | 27 ++++++------ .../mall/admin/api/bo/sms/PageSmsSignBO.java | 3 -- .../admin/api/bo/sms/PageSmsTemplateBO.java | 26 +++++++++++- .../mall/admin/api/constant/SmsTypeEnum.java | 4 +- .../api/dto/sms/PageQuerySmsTemplateDTO.java | 8 +++- .../mall/admin/convert/SmsSignConvert.java | 2 + .../admin/convert/SmsTemplateConvert.java | 6 ++- .../mall/admin/service/SmsServiceImpl.java | 41 +++++++++++++++++-- 8 files changed, 91 insertions(+), 26 deletions(-) diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SmsTemplateController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SmsTemplateController.java index 8166ba586..ae5739b12 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SmsTemplateController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/SmsTemplateController.java @@ -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 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); } } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java index dba25d9c3..da23d814d 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsSignBO.java @@ -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; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java index 739e3edc2..76c870738 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/sms/PageSmsTemplateBO.java @@ -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 { /** * 编号 */ diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsTypeEnum.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsTypeEnum.java index 07b6ef449..aa862efca 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsTypeEnum.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/SmsTypeEnum.java @@ -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(); diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/sms/PageQuerySmsTemplateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/sms/PageQuerySmsTemplateDTO.java index 207bfee80..82e13f430 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/sms/PageQuerySmsTemplateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/sms/PageQuerySmsTemplateDTO.java @@ -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; } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java index 5babbb79d..d8f8a1e60 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsSignConvert.java @@ -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 convert(List smsSignDOList); + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java index 8d3ec5bbc..6743552c5 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/SmsTemplateConvert.java @@ -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 convert(List smsTemplateDO); + List convert(List smsTemplateDOList); + + @Mappings({}) + List convertTemplateSign(List smsSignDOList); } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java index 49972ab18..52834143a 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/SmsServiceImpl.java @@ -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 page = new Page() .setSize(queryDTO.getSize()) @@ -102,9 +105,39 @@ public class SmsServiceImpl implements SmsService { .setDesc("create_time"); IPage signPage = smsTemplateMapper.selectPage(page, queryWrapper); + List 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 smsSignIds = templateList.stream().map( + PageSmsTemplateBO.Template::getSmsSignId).collect(Collectors.toSet()); + + List smsSignDOList = smsSignMapper.selectList( + new QueryWrapper().in("id", smsSignIds)); + + List signList = SmsTemplateConvert.INSTANCE.convertTemplateSign(smsSignDOList); + + Map 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() .eq("platform", platform) .eq("sign", sign) - ); + ); if (smsSignDO != null) { throw new ServiceException(AdminErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(),