From 0b71573faf42389be9587c8e3968a2d0be47e9c2 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Thu, 15 Jun 2023 12:17:45 +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 --- .../cweb/controller/BsStoreCidController.java | 7 ++-- .../com/hfkj/service/BsStoreCidService.java | 11 +----- .../service/impl/BsStoreCidServiceImpl.java | 21 ++++------ .../java/com/hfkj/unipush/UniPushService.java | 38 ++++++++++++++++--- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/cweb/src/main/java/com/cweb/controller/BsStoreCidController.java b/cweb/src/main/java/com/cweb/controller/BsStoreCidController.java index 7ccc1a0..d6e9f01 100644 --- a/cweb/src/main/java/com/cweb/controller/BsStoreCidController.java +++ b/cweb/src/main/java/com/cweb/controller/BsStoreCidController.java @@ -79,8 +79,6 @@ public class BsStoreCidController { bsStoreCidService.editStoreCid(bsStoreCid); } - bsStoreCidService.getPushRecord(storeCid.getStoreId()); - return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { @@ -92,10 +90,11 @@ public class BsStoreCidController { @RequestMapping(value="/voiceSucceed",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "语音播报成功") - public ResponseData voiceSucceed(@RequestParam(value = "storeId", required = true) Long storeId) { + public ResponseData voiceSucceed(@RequestParam(value = "storeId", required = true) Long storeId, + @RequestParam(value = "taskNo", required = true) String taskNo) { try { - bsStoreCidService.voiceSucceed(storeId); + bsStoreCidService.voiceSucceed(storeId , taskNo); return ResponseMsgUtil.success("操作成功"); diff --git a/service/src/main/java/com/hfkj/service/BsStoreCidService.java b/service/src/main/java/com/hfkj/service/BsStoreCidService.java index e766c83..45abe04 100644 --- a/service/src/main/java/com/hfkj/service/BsStoreCidService.java +++ b/service/src/main/java/com/hfkj/service/BsStoreCidService.java @@ -53,17 +53,8 @@ public interface BsStoreCidService { */ void storePush(JSONObject object); - /** - * @Author Sum1Dream - * @Name getPushRecord - * @Description // 推送播报记录 - * @Date 10:56 2023/6/15 - * @Param [storeId] - * @Return void - */ - void getPushRecord(Long storeId); - void voiceSucceed(Long storeId); + void voiceSucceed(Long storeId , String taskNo); /** * @Author Sum1Dream 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 5f6f5c1..b7b8a3f 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; -import com.hfkj.config.CommonSysConst; import com.hfkj.dao.BsStoreCidMapper; import com.hfkj.dao.BsStorePushRecordMapper; import com.hfkj.entity.BsStoreCid; @@ -21,7 +20,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -101,15 +99,10 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "生成语音失败"); } - BsStorePushRecord storePushRecord = new BsStorePushRecord(); - storePushRecord.setStoreId(bsStoreCid.getStoreId()); - storePushRecord.setCreateTime(new Date()); - storePushRecord.setUpdateTime(new Date()); - storePushRecord.setStatus(2); - storePushRecord.setVoiceUrl(CommonSysConst.getSysConfig().getDomainName() + auditPath); + object.put("cid", bsStoreCid.getCid()); + object.put("body", auditPath); + UniPushService.pushToSingleByCid(object); - storePushRecordMapper.insert(storePushRecord); - getPushRecord(bsStoreCid.getStoreId()); } catch (Exception e) { log.info("请求超时:" + e); @@ -117,8 +110,7 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { } - @Override - public void getPushRecord(Long storeId) { + private void getPushRecord(Long storeId) { Map map = new HashMap<>(); map.put("storeId", storeId); @@ -145,14 +137,17 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { } @Override - public void voiceSucceed(Long storeId) { + public void voiceSucceed(Long storeId , String taskNo) { Map pushMap = new HashMap<>(); pushMap.put("storeId" , storeId); + pushMap.put("ext1" , storeId); pushMap.put("status" , 2); BsStorePushRecord storePushRecord = findPushRecordByMap(pushMap); storePushRecord.setStatus(1); storePushRecordMapper.updateByPrimaryKey(storePushRecord); + + getPushRecord(storeId); } @Override diff --git a/service/src/main/java/com/hfkj/unipush/UniPushService.java b/service/src/main/java/com/hfkj/unipush/UniPushService.java index d4a7578..cd77e08 100644 --- a/service/src/main/java/com/hfkj/unipush/UniPushService.java +++ b/service/src/main/java/com/hfkj/unipush/UniPushService.java @@ -9,10 +9,18 @@ import com.getui.push.v2.sdk.common.ApiResult; import com.getui.push.v2.sdk.dto.req.Audience; import com.getui.push.v2.sdk.dto.req.message.PushDTO; import com.getui.push.v2.sdk.dto.req.message.PushMessage; +import com.hfkj.common.utils.DateUtil; +import com.hfkj.common.utils.IDGenerator; +import com.hfkj.config.CommonSysConst; +import com.hfkj.entity.BsStorePushRecord; +import com.hfkj.service.BsStoreCidService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Resource; +import java.util.Date; import java.util.Map; +import java.util.Random; /** * @author sum1dream @@ -20,6 +28,9 @@ import java.util.Map; public class UniPushService { private static Logger log = LoggerFactory.getLogger(UniPushService.class); + @Resource + private static BsStoreCidService bsStoreCidService; + /** * 创建请求 * @return @@ -49,7 +60,7 @@ public class UniPushService { * @Param [uniPushModel] * @Return void */ - public static String pushToSingleByCid(JSONObject object) { + public static void pushToSingleByCid(JSONObject object) { log.info("========= START 个推手机端推送 START ==========="); @@ -74,13 +85,28 @@ public class UniPushService { log.info("========= END 个推手机端推送 END ==========="); if (apiResult.isSuccess()) { - return apiResult.getData().toString(); - // success - } else { - return "code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg(); - // failed + if (apiResult.getData().toString().contains("successed_online")) { + BsStorePushRecord storePushRecord = new BsStorePushRecord(); + storePushRecord.setStoreId(object.getLong("storeid")); + storePushRecord.setCreateTime(new Date()); + storePushRecord.setUpdateTime(new Date()); + storePushRecord.setStatus(2); + storePushRecord.setExt1(generateOrderNo()); + storePushRecord.setVoiceUrl(CommonSysConst.getSysConfig().getDomainName() + object.getString("body") + "!@#PUSH#@!" + storePushRecord.getExt1()); + bsStoreCidService.insertStorePushRecord(storePushRecord); + } } } + public static String generateOrderNo(){ + try { + // 5位随机数 + 1位线程生成数 + String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); + // 生成订单号 + return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; + } catch (Exception e) { + return null; + } + } }