feat:云音箱

This commit is contained in:
dzc committed 2026-04-28 15:39:09 +08:00
1 parent e6eb95f057
commit 810038864d
6 files changed
+156 -4

No files matched your search

@@ -23,6 +23,7 @@ public enum HardTypeEnum {
OTHER("6", "其他支付方式(第三方接口对接)"),
MERCHANT_ACT("7", "商户活动"),
FARMER("8", "共富商城(助农)"),
YYX("10", "4G云音响"),
;
private final String type;
private final String description;
@@ -0,0 +1,22 @@
package com.bsd.pjcloud.hard.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "yyx")
@Data
public class YyxConf {
private String url;
/**
* 模板
* ${price}-价格
* ${phone-last}-手机尾号
* 浦江智慧后勤,收款${price}元
*/
private String template;
}
@@ -0,0 +1,11 @@
package com.bsd.pjcloud.hard.service;
/**
* @author liusiyang_dxm
* @since 2026/4/28
*/
public interface YyxService {
void send(Long mchId, Integer payPrice, String phone);
}
@@ -161,6 +161,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
private final RemoteMallProductService remoteMallProductService;
private final HardManagerMapper hardManagerMapper;
private final YyxService yyxService;
private final StringRedisTemplate redisTemplate;
private final HardThirdMiOrderMapper hardThirdMiOrderMapper;
@@ -782,6 +783,9 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
getSelf().generateCode(orderObj);
// 扣减库存
// getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
// 云音箱播报
yyxService.send(orderObj.getMerchantId(), orderObj.getPayPrice(), userDetail.getSysUser().getPhone());
return orderObj.getId();
}
@@ -0,0 +1,113 @@
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;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.entity.manager.HardManagerEntity;
import com.bsd.pjcloud.hard.config.YyxConf;
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
import com.bsd.pjcloud.hard.service.YyxService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.List;
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class YyxServiceImpl implements YyxService {
private final String TAG = "4G云音箱";
private final YyxConf yyxConf;
private final HardManagerMapper hardManagerMapper;
@Override
public void send(Long mchId, Integer payPrice, String phone) {
if (!ObjectUtil.isAllNotEmpty(mchId, payPrice, phone)) {
return;
}
// 查询商户绑定的云音箱设备
List<HardManagerEntity> yyxList = hardManagerMapper.selectList(new LambdaQueryWrapper<HardManagerEntity>().eq(HardManagerEntity::getMerchantId, mchId)
.eq(HardManagerEntity::getType, HardTypeEnum.YYX.getType())
);
if (ObjectUtil.isEmpty(yyxList)) {
return;
}
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));
}
private boolean httpSend(String deviceId, String msg) {
String msgid = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + RandomUtil.randomString(8);
try {
HashMap<String, Object> data = new HashMap<>();
data.put("cmd", "voice");
data.put("msg", msg);
data.put("msgid", msgid);
HashMap<String, Object> body = new HashMap<>();
body.put("sbx_id", deviceId);
body.put("agent_id", JSONUtil.toJsonStr(data));
String res = HttpUtil.post(yyxConf.getUrl(), JSONUtil.toJsonStr(body));
if (ObjectUtil.isEmpty(res)) {
log.error("|{}|发送失败,返回结果为空", TAG);
return false;
}
JSON resJson = JSONUtil.parse(res);
String requestId = resJson.getByPath("RequestId", String.class);
if (ObjectUtil.isEmpty(requestId)) {
log.error("|{}|发送失败,返回结果错误res:|{}|", res, TAG);
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("|{}|发送失败,异常:{}", TAG, e.getMessage());
return false;
}
}
private String phoneToLastPhone(String phone) {
if (ObjectUtil.isEmpty(phone)) {
return "";
}
return phone.substring(phone.length() - 4);
}
private String fenToYuan(Integer payPrice) {
if (ObjectUtil.isEmpty(payPrice)) {
return "0";
}
BigDecimal fen = new BigDecimal(payPrice);
return fen.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString();
}
}
@@ -27,9 +27,6 @@ import java.util.List;
/**
* 充值套餐表
*
* @author dzc
* @date 2025-01-03 18:33:55
*/
@RestController
@RequiredArgsConstructor
@@ -66,7 +63,10 @@ public class WalletRechargePackageController {
@Operation(summary = "查询全部", description = "查询全部")
@GetMapping("/app/list")
public R appList() {
return R.ok(walletRechargePackageService.list(new LambdaQueryWrapper<>()));
LambdaQueryWrapper<WalletRechargePackageEntity> wrapper = Wrappers.lambdaQuery();
wrapper.orderByAsc(WalletRechargePackageEntity::getPayPrice);
wrapper.orderByDesc(WalletRechargePackageEntity::getCreateTime);
return R.ok(walletRechargePackageService.list(wrapper));
}
/* ************************************* end app end ************************************* */
@@ -75,6 +75,7 @@ public class WalletRechargePackageController {
@PreAuthorize("@pms.hasPermission('wallet_walletRechargePackage_view')")
public R getWalletRechargePackagePage(@ParameterObject Page page, @ParameterObject WalletRechargePackageEntity walletRechargePackage) {
LambdaQueryWrapper<WalletRechargePackageEntity> wrapper = Wrappers.lambdaQuery();
wrapper.orderByAsc(WalletRechargePackageEntity::getPayPrice);
wrapper.orderByDesc(WalletRechargePackageEntity::getCreateTime);
return R.ok(walletRechargePackageService.page(page, wrapper));
}