From 8c7f1e8067b8aaa3634c59edf4b9a502b07444aa Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Thu, 15 Jun 2023 16:49:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=9F=A5=E8=AF=A2=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E5=92=8C=E7=A7=AF=E5=88=86=E8=BF=94=E5=88=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BsStoreCidServiceImpl.java | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java index 3148fd4..09402a6 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java @@ -5,6 +5,7 @@ import com.hfkj.common.Base64Util; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.RedisUtil; import com.hfkj.config.CommonSysConst; import com.hfkj.dao.BsStoreCidMapper; import com.hfkj.dao.BsStorePushRecordMapper; @@ -41,6 +42,9 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { @Resource private BsStorePushRecordMapper storePushRecordMapper; + @Resource + private RedisUtil redisUtil; + @Override public void insertStoreCid(BsStoreCid storeCid) { bsStoreCidMapper.insert(storeCid); @@ -82,45 +86,49 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { public void storePush(JSONObject object) { try { - if (object == null || - object.getBigDecimal("price") == null || - object.getLong("storeId") == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - - Map map = new HashMap<>(); - map.put("storeId", object.getLong("storeId")); - BsStoreCid bsStoreCid = findByMap(map); - - if (bsStoreCid == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "不存在推送关系"); - } - - // 获取语音播报地址 - String auditPath = HWYunSisService.ttsCustomDemo(object); - if (auditPath == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "生成语音失败"); + String key = "APP_PUSH" + object.getLong("storeId"); + + if (redisUtil.get(key) == null) { + redisUtil.set(key,object.getLong("storeId"), 5); + if (object.getBigDecimal("price") == null || object.getLong("storeId") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + Map map = new HashMap<>(); + map.put("storeId", object.getLong("storeId")); + BsStoreCid bsStoreCid = findByMap(map); + + if (bsStoreCid == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "不存在推送关系"); + } + + // 获取语音播报地址 + String auditPath = HWYunSisService.ttsCustomDemo(object); + + if (auditPath == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "生成语音失败"); + } + + String taskNo = Base64Util.generateOrderNo(); + object.put("taskNo", taskNo); + object.put("cid", bsStoreCid.getCid()); + String msg = CommonSysConst.getSysConfig().getDomainName() + auditPath + "!@#PUSH#@!" + taskNo + "!@#PUSH#@!" + "惠支付收款:" + object.getBigDecimal("price"); + object.put("body", msg); + if (UniPushService.pushToSingleByCid(object)) { + BsStorePushRecord storePushRecord = new BsStorePushRecord(); + storePushRecord.setStoreId(object.getLong("storeId")); + storePushRecord.setCreateTime(new Date()); + storePushRecord.setUpdateTime(new Date()); + storePushRecord.setStatus(2); + storePushRecord.setExt1(taskNo); + storePushRecord.setVoiceUrl(msg); + insertStorePushRecord(storePushRecord); + } + } else { + storePush(object); } - String taskNo = Base64Util.generateOrderNo(); - object.put("taskNo", taskNo); - object.put("cid", bsStoreCid.getCid()); - String msg = CommonSysConst.getSysConfig().getDomainName() + auditPath + "!@#PUSH#@!" + taskNo + "!@#PUSH#@!" + "惠支付收款:" + object.getBigDecimal("price"); - object.put("body", msg); - if (UniPushService.pushToSingleByCid(object)) { - BsStorePushRecord storePushRecord = new BsStorePushRecord(); - storePushRecord.setStoreId(object.getLong("storeId")); - storePushRecord.setCreateTime(new Date()); - storePushRecord.setUpdateTime(new Date()); - storePushRecord.setStatus(2); - storePushRecord.setExt1(taskNo); - storePushRecord.setVoiceUrl(msg); - insertStorePushRecord(storePushRecord); - } - - - } catch (Exception e) { log.info("请求超时:" + e); } @@ -167,6 +175,8 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { if (storePushRecord != null) { storePushRecord.setStatus(1); storePushRecordMapper.updateByPrimaryKey(storePushRecord); + + redisUtil.del("APP_PUSH" + storePushRecord.getStoreId()); } getPushRecord(storeId);