diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardTypeEnum.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardTypeEnum.java index 1ad3afdcf..73afb35bf 100644 --- a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardTypeEnum.java +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/constant/HardTypeEnum.java @@ -23,7 +23,8 @@ public enum HardTypeEnum { OTHER("6", "其他支付方式(第三方接口对接)"), MERCHANT_ACT("7", "商户活动"), FARMER("8", "共富商城(助农)"), - YYX("10", "4G云音响"), + YYX("10", "4G-云音响"), + YYX_WIFI("11", "wifi-云音响"), ; private final String type; private final String description; diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/yyx/HardYyxController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/yyx/HardYyxController.java new file mode 100644 index 000000000..cc9d2eb27 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/yyx/HardYyxController.java @@ -0,0 +1,40 @@ +package com.bsd.pjcloud.hard.controller.yyx; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum; +import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.common.security.annotation.Inner; +import com.bsd.pjcloud.hard.api.entity.HardApptEntity; +import com.bsd.pjcloud.hard.service.YyxService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 云音箱 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/yyx") +@Tag(description = "hard-appt", name = "设备预约管理管理") +@SecurityRequirement(name = HttpHeaders.AUTHORIZATION) +public class HardYyxController { + + private final YyxService yyxService; + +// @Operation(summary = "发送消息", description = "发送消息") +// @GetMapping("/send") +// @Inner(value = false) +// public R send() { +// yyxService.send(1931916121241079810L, 100, "17683843144"); +// return R.ok(true); +// } + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/manager/HardManagerServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/manager/HardManagerServiceImpl.java index 537fedd45..3100fb105 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/manager/HardManagerServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/manager/HardManagerServiceImpl.java @@ -130,9 +130,11 @@ public class HardManagerServiceImpl extends ServiceImpl yyxList = hardManagerMapper.selectList(new LambdaQueryWrapper().eq(HardManagerEntity::getMerchantId, mchId) - .eq(HardManagerEntity::getType, HardTypeEnum.YYX.getType()) + .in(HardManagerEntity::getType, List.of(HardTypeEnum.YYX.getType(), HardTypeEnum.YYX_WIFI.getType())) ); if (ObjectUtil.isEmpty(yyxList)) { return; @@ -54,22 +53,30 @@ public class YyxServiceImpl implements YyxService { String yuanPrice = fenToYuan(payPrice); String lastPhone = phoneToLastPhone(phone); - String template = yyxConf.getTemplate(); - // 把`template`中的`${price}`替换为`yuanPrice` - template = template.replace("${price}", yuanPrice); - // 把`template`中的`${phone}`替换为`lastPhone` - template = template.replace("${phone-last}", lastPhone); - - - String finalTemplate = template; - yyxList.forEach(v -> httpSend(v.getUniqueCode(), finalTemplate)); + yyxList.forEach(v -> { + // 4G版云音箱 + if (ObjectUtil.equals(v.getType(), HardTypeEnum.YYX.getType())) { + String template = yyxConf.getTemplate(); + // 把`template`中的`${price}`替换为`yuanPrice` + template = template.replace("${price}", yuanPrice); + // 把`template`中的`${phone}`替换为`lastPhone` + template = template.replace("${phone-last}", lastPhone); + yyx4gHttpSend(v.getUniqueCode(), template); + } + // WIFI版云音箱 + else if (ObjectUtil.equals(v.getType(), HardTypeEnum.YYX_WIFI.getType())) { + String template = "收款" + yuanPrice + "元"; + yyx4gHttpSend(v.getUniqueCode(), template); + } + }); } catch (Exception e) { log.error("|{}|发送失败,异常:{}", TAG, e.getMessage()); } } - private boolean httpSend(String deviceId, String msg) { + // 发送语音 + private boolean yyx4gHttpSend(String deviceId, String msg) { String msgid = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + RandomUtil.randomString(8); try { HashMap data = new HashMap<>(); @@ -83,18 +90,18 @@ public class YyxServiceImpl implements YyxService { String res = HttpUtil.post(yyxConf.getUrl(), JSONUtil.toJsonStr(body)); if (ObjectUtil.isEmpty(res)) { - log.error("|{}|发送失败,返回结果为空", TAG); + log.error("|{}|4G版云音箱发送语音,发送失败,返回结果为空", TAG); return false; } JSON resJson = JSONUtil.parse(res); String requestId = resJson.getByPath("RequestId", String.class); if (ObjectUtil.isEmpty(requestId)) { - log.error("|{}|发送失败,返回结果错误res:|{}|", res, TAG); + log.error("|{}|4G版云音箱发送语音,发送失败,返回结果错误res:|{}|", res, TAG); } return true; } catch (Exception e) { e.printStackTrace(); - log.error("|{}|发送失败,异常:{}", TAG, e.getMessage()); + log.error("|{}|4G版云音箱发送语音,发送失败,异常:{}", TAG, e.getMessage()); return false; } }