feat:云音箱
This commit is contained in:
1 parent
0cc7a0a91d
commit
e7ecc2fd2c
4 files changed
+72
-20
No files matched your search
+2
-1
@@ -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;
|
||||
|
||||
+40
@@ -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<Boolean> send() {
|
||||
// yyxService.send(1931916121241079810L, 100, "17683843144");
|
||||
// return R.ok(true);
|
||||
// }
|
||||
|
||||
}
|
||||
+8
-4
@@ -130,9 +130,11 @@ public class HardManagerServiceImpl extends ServiceImpl<HardManagerMapper, HardM
|
||||
}
|
||||
SysDept deptHardGroup = deptService.getParentDeptHardGroup(user.getDeptId()).getData();
|
||||
if (ObjectUtil.isEmpty(deptHardGroup)) {
|
||||
throw new RuntimeException("请设置顶级部门硬件分组");
|
||||
// throw new RuntimeException("请设置顶级部门硬件分组");
|
||||
} else {
|
||||
dto.setHardGroupId(deptHardGroup.getHardGroupId());
|
||||
}
|
||||
dto.setHardGroupId(deptHardGroup.getHardGroupId());
|
||||
// dto.setHardGroupId(deptHardGroup.getHardGroupId());
|
||||
dto.setDeptId(mch.getDeptId());
|
||||
// mq地址和端口
|
||||
dto.setMqSocketAddress(mqttConfig.getAndroidAddress());
|
||||
@@ -166,10 +168,12 @@ public class HardManagerServiceImpl extends ServiceImpl<HardManagerMapper, HardM
|
||||
}
|
||||
SysDept deptHardGroup = deptService.getParentDeptHardGroup(detail.getDeptId()).getData();
|
||||
if (ObjectUtil.isEmpty(deptHardGroup)) {
|
||||
throw new RuntimeException("请设置顶级部门硬件分组");
|
||||
// throw new RuntimeException("请设置顶级部门硬件分组");
|
||||
} else {
|
||||
dto.setHardGroupId(deptHardGroup.getHardGroupId());
|
||||
}
|
||||
dto.setDeptId(mch.getDeptId());
|
||||
dto.setHardGroupId(deptHardGroup.getHardGroupId());
|
||||
// dto.setHardGroupId(deptHardGroup.getHardGroupId());
|
||||
if (!ObjectUtil.equals(dto.getMerchantId(), detail.getMerchantId())) {
|
||||
// topic
|
||||
String topic = createMqConfigByAction(deptHardGroup.getHardGroupId(), null, null, 1) + "/#";
|
||||
|
||||
+22
-15
@@ -1,7 +1,6 @@
|
||||
package com.bsd.pjcloud.hard.service.impl.yyx;
|
||||
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
@@ -45,7 +44,7 @@ public class YyxServiceImpl implements YyxService {
|
||||
}
|
||||
// 查询商户绑定的云音箱设备
|
||||
List<HardManagerEntity> yyxList = hardManagerMapper.selectList(new LambdaQueryWrapper<HardManagerEntity>().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<String, Object> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user