Merge remote-tracking branch 'origin/main'

This commit is contained in:
zhangji committed 2025-08-13 08:15:34 +08:00
commit cd0c2aff92
6 files changed
+83 -15

No files matched your search

@@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.product.controller.admin.device;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -18,11 +20,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.product.controller.admin.device.vo.*;
@@ -53,6 +57,12 @@ public class DeviceController {
return success(true);
}
@GetMapping("/refresh-wechat-code")
@Operation(summary = "刷新小程序二维码")
public CommonResult<String> refreshWechantCode(@RequestParam Long id) {
return success(deviceService.refreshWechantCode(id));
}
@DeleteMapping("/delete")
@Operation(summary = "删除贩卖机信息")
@Parameter(name = "id", description = "编号", required = true)
@@ -84,12 +94,12 @@ public class DeviceController {
@PreAuthorize("@ss.hasPermission('product:device:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDeviceExcel(@Valid DevicePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DeviceDO> list = deviceService.getDevicePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "贩卖机信息.xls", "数据", DeviceRespVO.class,
BeanUtils.toBean(list, DeviceRespVO.class));
BeanUtils.toBean(list, DeviceRespVO.class));
}
}
@@ -31,6 +31,11 @@ public interface DeviceService {
*/
void updateDevice(@Valid DeviceSaveReqVO updateReqVO);
/**
* 刷新小程序二维码
*/
String refreshWechantCode(Long id);
/**
* 删除贩卖机信息
*
@@ -1,19 +1,26 @@
package cn.iocoder.yudao.module.product.service.device;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.product.api.device.dto.DeviceRespDto;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.service.device.bo.DispenseRequestBo;
import cn.iocoder.yudao.module.product.service.device.bo.DispenseResponseBo;
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
import cn.iocoder.yudao.module.product.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -39,6 +46,11 @@ public class DeviceServiceImpl implements DeviceService {
@Resource
private DeviceMapper deviceMapper;
@Resource
private SocialClientApi socialClientApi;
@Resource
private FileApi fileApi;
// TOKEN
@Value("${xr.cabinet.token}")
private String token;
@@ -47,6 +59,9 @@ public class DeviceServiceImpl implements DeviceService {
@Value("${xr.cabinet.api_device_url}")
private String api_url;
@Value("${xr.cabinet.wechat-product-path}")
private String wechatProductPath;
@Override
public Long createDevice(DeviceSaveReqVO createReqVO) {
// 插入
@@ -54,7 +69,7 @@ public class DeviceServiceImpl implements DeviceService {
deviceMapper.insert(device);
DispenseRequestBo request = new DispenseRequestBo();
request.setDeviceId(createReqVO.getDeviceId());
request.setMessage(createReqVO.getProductUrl()+","+createReqVO.getFileUrl());
request.setMessage(createReqVO.getProductUrl() + "," + createReqVO.getFileUrl());
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
@@ -82,12 +97,12 @@ public class DeviceServiceImpl implements DeviceService {
System.out.println("上传成功!详情: " + body.getData());
} else {
System.out.println("操作失败!原因: " + body.getMsg());
log.error("设备--{}:[图片上传失败]:原因: {}",createReqVO.getDeviceId(), body.getMsg());
log.error("设备--{}:[图片上传失败]:原因: {}", createReqVO.getDeviceId(), body.getMsg());
}
}
} catch (Exception e) {
System.err.println("图片上传请求异常: " + e.getMessage());
log.error("设备--{}:[图片上传异常]:原因: {}",createReqVO.getDeviceId(), e.getMessage());
log.error("设备--{}:[图片上传异常]:原因: {}", createReqVO.getDeviceId(), e.getMessage());
}
// 返回
return device.getId();
@@ -101,7 +116,7 @@ public class DeviceServiceImpl implements DeviceService {
DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class);
DispenseRequestBo request = new DispenseRequestBo();
request.setDeviceId(updateReqVO.getDeviceId());
request.setMessage(updateReqVO.getProductUrl()+","+updateReqVO.getFileUrl());
request.setMessage(updateReqVO.getProductUrl() + "," + updateReqVO.getFileUrl());
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
@@ -129,16 +144,52 @@ public class DeviceServiceImpl implements DeviceService {
System.out.println("上传成功!详情: " + body.getData());
} else {
System.out.println("操作失败!原因: " + body.getMsg());
log.error("设备--{}:[图片上传失败]:原因: {}",updateReqVO.getDeviceId(), body.getMsg());
log.error("设备--{}:[图片上传失败]:原因: {}", updateReqVO.getDeviceId(), body.getMsg());
}
}
} catch (Exception e) {
System.err.println("图片上传请求异常: " + e.getMessage());
log.error("设备--{}:[图片上传异常]:原因: {}",updateReqVO.getDeviceId(), e.getMessage());
log.error("设备--{}:[图片上传异常]:原因: {}", updateReqVO.getDeviceId(), e.getMessage());
}
deviceMapper.updateById(updateObj);
}
@Override
public String refreshWechantCode(Long id) {
// 校验存在
validateDeviceExists(id);
String wechatPagePath = wechatProductPath;
String wechatPathParams = String.format("deviceId=%s", id);
String wechatFullPath = String.format("%s?%s", wechatPagePath, wechatPathParams);
SocialWxQrcodeReqDTO codeObj = new SocialWxQrcodeReqDTO();
codeObj.setPath(wechatPagePath);
codeObj.setAutoColor(false);
codeObj.setHyaline(false);
codeObj.setScene(wechatPathParams);
try {
// 生成微信小程序二维码
byte[] imageByte = socialClientApi.getWxaQrcode(codeObj);
// 保存二维码
String file = fileApi.createFile(imageByte);
if (ObjectUtil.isEmpty(file)) {
log.error("设备--{}:[微信二维码保存失败]", id);
return null;
}
// 更新一下
DeviceDO updateObj = DeviceDO.builder().id(id).productUrl(wechatFullPath).fileUrl(file).build();
deviceMapper.updateById(updateObj);
// 刷新一下硬件设备
updateDevice(BeanUtil.toBean(deviceMapper.selectById(id), DeviceSaveReqVO.class));
return file;
} catch (Exception e) {
e.printStackTrace();
log.error("设备--{}:[微信二维码生成失败]:原因: {}", id, e.getMessage());
}
return "";
}
@Override
public void deleteDevice(Long id) {
// 校验存在
@@ -80,7 +80,7 @@ spring:
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 10 # 数据库索引
password: 123456 # 密码,建议生产环境开启
# password: 123456 # 密码,建议生产环境开启
--- #################### 定时任务相关配置 ####################
@@ -236,7 +236,7 @@ yudao:
enable: false
demo: false # 关闭演示模式
wxa-code:
env-version: develop # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
env-version: trial # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
wxa-subscribe-message:
miniprogram-state: developer # 跳转小程序类型:开发版为 “developer”;体验版为 “trial”为;正式版为 “formal”
tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
@@ -221,7 +221,7 @@ yudao:
enable: false
demo: false # 关闭演示模式
wxa-code:
env-version: develop # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
env-version: release # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop"
wxa-subscribe-message:
miniprogram-state: developer # 跳转小程序类型:开发版为 “developer”;体验版为 “trial”为;正式版为 “formal”
tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
@@ -3,8 +3,8 @@ spring:
name: yudao-server
profiles:
active: prod
# active: local
# active: prod
active: local
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
@@ -368,4 +368,6 @@ xr:
cabinet:
token: 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhcHAxIiwiaWF0IjoxNzQ5MTMzNzE5LCJleHAiOjIwNjAxNzM3MTl9.u2VUKxPxE2H8xldabMVRYSJKf6LN-XZfbcfyj1T7czI'
api_url: 'http://9527.asset-cloud.com.cn/ots/multiDispense'
api_device_url: 'http://9527.asset-cloud.com.cn/ots/deviceScreen'
api_device_url: 'http://9527.asset-cloud.com.cn/ots/deviceScreen'
# 小程序的自提柜商品
wechat-product-path: 'pages/selfpickupcabinet/index'