From 62a5dc2c028032147c2e19c166c25c60a21dc2b7 Mon Sep 17 00:00:00 2001 From: 935090232@qq.com <ak473600000> Date: Thu, 28 Oct 2021 11:58:52 +0800 Subject: [PATCH] 实现简单短信提醒 --- zq-erp/src/main/java/com/matrix/core/tools/SmsUtils.java | 6 - zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java | 19 ++++-- zq-erp/pom.xml | 5 + zq-erp/src/main/java/com/matrix/system/hive/service/TaiYanAliyunSmsService.java | 78 ++++++++++++++++++++++++++ zq-erp/src/test/java/com/matrix/TaiYanAliyunSmsServiceTest.java | 37 ++++++++++++ 5 files changed, 135 insertions(+), 10 deletions(-) diff --git a/zq-erp/pom.xml b/zq-erp/pom.xml index 661933d..b23716b 100644 --- a/zq-erp/pom.xml +++ b/zq-erp/pom.xml @@ -393,6 +393,11 @@ <artifactId>hutool-all</artifactId> <version>5.3.1</version> </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>26.0-jre</version> + </dependency> </dependencies> <build> <resources> diff --git a/zq-erp/src/main/java/com/matrix/core/tools/SmsUtils.java b/zq-erp/src/main/java/com/matrix/core/tools/SmsUtils.java index a39f00c..cb14c28 100644 --- a/zq-erp/src/main/java/com/matrix/core/tools/SmsUtils.java +++ b/zq-erp/src/main/java/com/matrix/core/tools/SmsUtils.java @@ -1,5 +1,6 @@ package com.matrix.core.tools; +import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.CommonRequest; @@ -7,7 +8,6 @@ import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.http.MethodType; -import com.google.gson.JsonObject; import com.matrix.config.properties.AliSmsProperties; import com.matrix.core.exception.GlobleException; import com.matrix.system.hive.bean.SysSmsTemplate; @@ -15,7 +15,6 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.HashMap; import java.util.Map; /** @@ -57,8 +56,7 @@ CommonRequest request = commonRequest(SysSmsTemplate.SMS_ACTION_SEND); request.putQueryParameter("PhoneNumbers", phoneNum); request.putQueryParameter("TemplateCode", templateCode); - String jsonStr = JSONObject.toJSONString(values); - request.putQueryParameter("TemplateParam", jsonStr); + request.putQueryParameter("TemplateParam", JSONUtil.parse(values).toString()); CommonResponse response = null; try { diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/TaiYanAliyunSmsService.java b/zq-erp/src/main/java/com/matrix/system/hive/service/TaiYanAliyunSmsService.java new file mode 100644 index 0000000..828f1ad --- /dev/null +++ b/zq-erp/src/main/java/com/matrix/system/hive/service/TaiYanAliyunSmsService.java @@ -0,0 +1,78 @@ +/** + * projectName: zq-erp + * fileName: TaiYanAliyunSmsService.java + * packageName: com.matrix.system.hive.service + * date: 2021-10-28 11:18 + * copyright(c) 2021 http://www.hydee.cn/ Inc. All rights reserved. + */ +package com.matrix.system.hive.service; + +import com.google.common.collect.Maps; +import com.matrix.core.tools.LogUtil; +import com.matrix.core.tools.SmsUtils; +import com.matrix.core.tools.StringUtils; +import com.matrix.system.hive.bean.SysBeauticianState; +import com.matrix.system.hive.bean.SysProjServices; +import com.matrix.system.hive.bean.SysVipInfo; +import com.matrix.system.hive.dao.SysVipInfoDao; +import lombok.AllArgsConstructor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @version: V1.0 + * @author: JiangYouYao + * @className: TaiYanAliyunSmsService + * @packageName: com.matrix.system.hive.service + * @description: 肽妍短信提醒服务 + * @data: 2021-10-28 11:18 + **/ +@Service +@AllArgsConstructor +public class TaiYanAliyunSmsService { + + SysVipInfoDao vipInfoDao; + + SmsUtils smsUtils; + + SysBeauticianStateService sysBeauticianStateService; + + /** + * 预约成功短信提醒 + * @param services + */ + @Async + public void sendYycgNotice(SysProjServices services) { + + //短信接口为肽妍公司定制,暂时写死 + if(services.getCompanyId()!=17L){ + return; + } + + SysVipInfo sysVipInfo = vipInfoDao.selectById(services.getVipId()); + + HashMap<String, String> param = Maps.newHashMap(); + + List<SysBeauticianState> sysBeauticianStates = sysBeauticianStateService.findBySerId(services.getId()); + + String projNames = sysBeauticianStates.stream().map(item -> { + if(item.getProjInfo()!=null){ + return item.getProjInfo().getName(); + }else{ + return ""; + } + } ).collect(Collectors.joining(",")); + + LogUtil.debug("发送阿里云短信手机号{},项目{}",sysVipInfo.getPhone(), projNames); + if(StringUtils.isNotBlank(projNames) + && StringUtils.isNotBlank(sysVipInfo.getPhone())){ + param.put("projName",projNames); + smsUtils.sendSms(sysVipInfo.getPhone(),"SMS_227005614",param); + } + + } +} \ No newline at end of file diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java index 2001275..83bdf21 100644 --- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java +++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java @@ -4,13 +4,9 @@ import com.matrix.component.asyncmessage.AsyncMessageManager; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; -import com.matrix.core.pojo.AjaxResult; import com.matrix.core.pojo.PaginationVO; import com.matrix.core.pojo.VerifyResult; -import com.matrix.core.tools.DateUtil; -import com.matrix.core.tools.LogUtil; -import com.matrix.core.tools.StringUtils; -import com.matrix.core.tools.WebUtil; +import com.matrix.core.tools.*; import com.matrix.system.app.dto.ServiceOrderListDto; import com.matrix.system.app.vo.ServiceOrderListVo; import com.matrix.system.common.bean.BusParameterSettings; @@ -68,7 +64,8 @@ private SysOutStoreItemDao sysOutStoreItemDao; @Autowired private SysBedInfoDao sysBedInfoDao; - + @Autowired + TaiYanAliyunSmsService taiYanAliyunSmsService; @Autowired private SysStoreInfoDao storeInfoDao; @@ -1054,6 +1051,7 @@ return flag; } + @Override public int confirmServiceOrder(Long id) { SysProjServices services = new SysProjServices(); @@ -1067,7 +1065,16 @@ uniformMsgParam.put("serviceId",services.getId()); asyncMessageManager.sendMsg(AsyncMessageRouting.SEND_UNIFORM_TEMPLATE_MSG ,uniformMsgParam); + taiYanAliyunSmsService.sendYycgNotice(services); + + } return i; } + + + + + + } diff --git a/zq-erp/src/test/java/com/matrix/TaiYanAliyunSmsServiceTest.java b/zq-erp/src/test/java/com/matrix/TaiYanAliyunSmsServiceTest.java new file mode 100644 index 0000000..5f2690e --- /dev/null +++ b/zq-erp/src/test/java/com/matrix/TaiYanAliyunSmsServiceTest.java @@ -0,0 +1,37 @@ +package com.matrix; + +import com.matrix.system.hive.bean.SysProjServices; +import com.matrix.system.hive.service.SysProjServicesService; +import com.matrix.system.hive.service.TaiYanAliyunSmsService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author jiangyouyao + * @email 512061637@qq.com + * @date 2019年2月25日 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {ZqErpApplication.class},webEnvironment =SpringBootTest.WebEnvironment.RANDOM_PORT) +public class TaiYanAliyunSmsServiceTest { + + + + @Autowired + private TaiYanAliyunSmsService taiYanAliyunSmsService; + @Autowired + SysProjServicesService projServicesService; + + + @Test + public void addSendYycgNotice(){ + SysProjServices byId = projServicesService.findById(215550L); + byId.setVipId(5949L); + taiYanAliyunSmsService.sendYycgNotice(byId); + } + + +} -- Gitblit v1.9.1