diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/device/DeviceController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/device/DeviceController.java index f86b7b9..08dec9b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/device/DeviceController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/device/DeviceController.java @@ -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 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 list = deviceService.getDevicePage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "贩卖机信息.xls", "数据", DeviceRespVO.class, - BeanUtils.toBean(list, DeviceRespVO.class)); + BeanUtils.toBean(list, DeviceRespVO.class)); } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceService.java index 6c52ca9..77c1bc1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceService.java @@ -31,6 +31,11 @@ public interface DeviceService { */ void updateDevice(@Valid DeviceSaveReqVO updateReqVO); + /** + * 刷新小程序二维码 + */ + String refreshWechantCode(Long id); + /** * 删除贩卖机信息 * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceServiceImpl.java index be66145..675c247 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/device/DeviceServiceImpl.java @@ -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) { // 校验存在 diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index ce33a4c..627b168 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -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 diff --git a/yudao-server/src/main/resources/application-prod.yaml b/yudao-server/src/main/resources/application-prod.yaml index 5e6fd5b..f961325 100644 --- a/yudao-server/src/main/resources/application-prod.yaml +++ b/yudao-server/src/main/resources/application-prod.yaml @@ -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 diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 71e83b0..777c4e7 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -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' \ No newline at end of file + api_device_url: 'http://9527.asset-cloud.com.cn/ots/deviceScreen' + # 小程序的自提柜商品 + wechat-product-path: 'pages/selfpickupcabinet/index'