Browse Source

增加生成收集手机号二维码+小程序端查询素材详情接口

cgp 2 ngày trước cách đây
mục cha
commit
dfdd9eab62

+ 53 - 14
fs-company/src/main/java/com/fs/company/controller/qw/FsCompanyCustomerController.java

@@ -23,6 +23,7 @@ import com.fs.his.param.PrescribePhoneParam;
 import com.fs.his.service.IFsDoctorPatientService;
 import com.fs.his.service.IFsPrescribeDataScrmService;
 import com.fs.his.service.IFsPrescribeService;
+import com.fs.hisStore.dto.CreatePhoneQRCodeDTO;
 import com.fs.hisStore.param.FsCompanyCustomerOrderParam;
 import com.fs.hisStore.service.IFsUserInformationCollectionService;
 import com.fs.hisStore.vo.FsStoreOrderVO;
@@ -86,6 +87,10 @@ public class FsCompanyCustomerController extends BaseController {
     @Autowired
     private ISysConfigService sysConfigService;
 
+    //商城小程序appId配置常量
+    private static final String APP_ID_CONFIG_KEY = "appStore.appId.config";
+    private static final String DEFAULT_APP_ID = "wx50bcb040b4963a7e";
+
     /**
      * 查询客户列表
      */
@@ -368,7 +373,7 @@ public class FsCompanyCustomerController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         Long companyUserId = loginUser.getUser().getUserId();
         if (companyUserId == null){
-            throw new CustomException("销售登录信息获取异常");
+            throw new CustomException("登录信息已过期,请重新登录");
         }
         fsDoctorPatient.setCompanyUserId(companyUserId);
         PageHelper.startPage(fsDoctorPatient.getPageNum(), fsDoctorPatient.getPageSize());
@@ -404,7 +409,7 @@ public class FsCompanyCustomerController extends BaseController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         Long companyUserId = loginUser.getUser().getUserId();
         if (companyUserId == null){
-            throw new CustomException("销售登录信息获取异常");
+            throw new CustomException("登录信息已过期,请重新登录");
         }
         PageHelper.startPage(customerOrderParam.getPageNum(), customerOrderParam.getPageSize());
         List<FsStoreOrderVO> list = fsCompanyCustomerService.selectStoreOrderScrmByCompanyCustomerParam(customerOrderParam);
@@ -430,18 +435,8 @@ public class FsCompanyCustomerController extends BaseController {
      * */
     @GetMapping("/getQRCode/{orderId}")
     public R getQRCode(@PathVariable("orderId") Long orderId){
-        String configValue = sysConfigService.selectConfigByKey("appStore.appId.config");
-        String appId = null;
-        if (StringUtils.isNotEmpty(configValue)) {
-            // 解析JSON
-            JSONObject json = JSONUtil.parseObj(configValue);
-            appId = json.getStr("appId");
-        }
-        // 如果配置不存在或解析失败,使用默认值
-        if (StringUtils.isEmpty(appId)) {
-            log.error("未配置制单小程序appId");
-            appId = "wx50bcb040b4963a7e";//默认为营口市小程序;
-        }
+        //获取appId
+        String appId = getAppId();
         return informationCollectionService.getCustomerGenerateQRCode(orderId,appId);
     }
 
@@ -478,4 +473,48 @@ public class FsCompanyCustomerController extends BaseController {
     public AjaxResult improve(@RequestBody FsCompanyCustomer fsCompanyCustomer){
         return toAjax(fsCompanyCustomerService.improve(fsCompanyCustomer));
     }
+
+    /**
+     * 生成收集手机号二维码
+     * */
+    @PostMapping("/createPhoneQRCode")
+    public R createPhoneQRCode(@RequestBody CreatePhoneQRCodeDTO qrCodeDTO) {
+        // 登录用户ID
+        Long companyUserId;
+        try {
+            LoginUser loginUser = SecurityUtils.getLoginUser();
+            companyUserId = loginUser.getUser().getUserId();
+        } catch (Exception e) {
+            log.error("获取当前登录用户信息失败", e);
+            throw new CustomException("登录信息已过期,请重新登录");
+        }
+        // 当前配置的商城小程序appId
+        String appId = getAppId();
+        return fsCompanyCustomerService.createPhoneQRCode(qrCodeDTO,companyUserId, appId);
+    }
+
+    /**
+     * 获取 appId 的私有方法
+     */
+    private String getAppId() {
+        try {
+            String configValue = sysConfigService.selectConfigByKey(APP_ID_CONFIG_KEY);
+            if (StringUtils.isNotEmpty(configValue)) {
+                JSONObject json = JSONUtil.parseObj(configValue);
+                String appId = json.getStr("appId");
+                if (StringUtils.isNotEmpty(appId)) {
+                    return appId;
+                } else {
+                    log.warn("配置 {} 中 appId 字段为空,使用默认值", APP_ID_CONFIG_KEY);
+                }
+            } else {
+                log.warn("未找到配置 {},使用默认值", APP_ID_CONFIG_KEY);
+            }
+        } catch (Exception e) {
+            log.error("解析 appId 配置异常,configValue={}",
+                    sysConfigService.selectConfigByKey(APP_ID_CONFIG_KEY), e);
+        }
+        //默认值
+        return DEFAULT_APP_ID;
+    }
 }

+ 15 - 0
fs-service/src/main/java/com/fs/hisStore/dto/CreatePhoneQRCodeDTO.java

@@ -0,0 +1,15 @@
+package com.fs.hisStore.dto;
+
+import lombok.Data;
+
+/**
+ * 创建收集客户手机号二维码入参
+ * */
+@Data
+public class CreatePhoneQRCodeDTO {
+    /*素材id*/
+    private String materialId;
+
+    /*1:图片,2:视频*/
+    private Integer type;
+}

+ 11 - 0
fs-service/src/main/java/com/fs/qw/service/IFsCompanyCustomerService.java

@@ -1,7 +1,9 @@
 package com.fs.qw.service;
 
+import com.fs.common.core.domain.R;
 import com.fs.company.domain.CompanyUser;
 import com.fs.his.vo.CustomerInfoVO;
+import com.fs.hisStore.dto.CreatePhoneQRCodeDTO;
 import com.fs.hisStore.param.FsCompanyCustomerOrderParam;
 import com.fs.hisStore.vo.FsStoreOrderVO;
 import com.fs.qw.domain.FsCompanyCustomer;
@@ -57,4 +59,13 @@ public interface IFsCompanyCustomerService {
      * @return 导入结果(成功条数 + 错误信息)
      */
     ImportResult importCustomers(List<ImportCustomerDTO> list, CompanyUser companyUser);
+
+    /**
+     * 创建收集手机号的二维码
+     * @param companyUserId 公司用户id
+     * @param appId 微信公众号appId
+     * @param qrCodeDTO 前端传递的部分二维码参数
+     * @return 创建结果
+     */
+    R createPhoneQRCode(CreatePhoneQRCodeDTO qrCodeDTO,Long companyUserId, String appId);
 }

+ 45 - 0
fs-service/src/main/java/com/fs/qw/service/impl/FsCompanyCustomerServiceImpl.java

@@ -1,9 +1,11 @@
 package com.fs.qw.service.impl;
 
+import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.TypeReference;
+import com.fs.common.core.domain.R;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
@@ -11,6 +13,7 @@ import com.fs.company.domain.CompanyDept;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyDeptMapper;
 import com.fs.company.mapper.CompanyUserMapper;
+import com.fs.core.config.WxMaConfiguration;
 import com.fs.his.domain.FsDoctor;
 import com.fs.his.domain.FsImportMember;
 import com.fs.his.domain.FsPrescribeDataScrm;
@@ -20,8 +23,10 @@ import com.fs.his.mapper.FsPrescribeDataScrmMapper;
 import com.fs.his.service.IFsUserAddressService;
 import com.fs.his.vo.CustomerInfoVO;
 import com.fs.his.vo.CustomerQuestionAnswerVO;
+import com.fs.hisStore.dto.CreatePhoneQRCodeDTO;
 import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
 import com.fs.hisStore.param.FsCompanyCustomerOrderParam;
+import com.fs.hisStore.utils.QRCodeImageCleaner;
 import com.fs.hisStore.vo.FsStoreOrderItemVO;
 import com.fs.hisStore.vo.FsStoreOrderVO;
 import com.fs.qw.domain.FsCompanyCustomer;
@@ -33,7 +38,10 @@ import com.fs.qw.mapper.FsCompanyExternalPayReceiptMapper;
 import com.fs.qw.param.TransferCustomerParam;
 import com.fs.qw.service.IFsCompanyCustomerService;
 import com.fs.qw.vo.ImportResult;
+import com.fs.system.oss.CloudStorageService;
+import com.fs.system.oss.OSSFactory;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -454,4 +462,41 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
         }
         return new ImportResult(success, errors);
     }
+
+    @Override
+    public R createPhoneQRCode(CreatePhoneQRCodeDTO qrCodeDTO, Long companyUserId, String appId) {
+        final WxMaService wxMaService = WxMaConfiguration.getMaService(appId);
+        String scene="cuId="+ companyUserId+ "&materialId=" + qrCodeDTO.getMaterialId();
+        byte[] file;
+        try {
+            file = wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(
+                    scene,
+                    "pages/shopping/paymentOrder",
+                    true,
+                    "release",
+                    430,
+                    true,
+                    null,
+                    false);
+            // ======= 处理图片,替换中间的文字(/n:实现文字换行效果) =======
+            file = QRCodeImageCleaner.replaceCenterText(file, "益寿缘\n大药房");
+            // ==========================================
+            // 上传图片到存储桶
+            String suffix = ".png";
+            CloudStorageService storage = OSSFactory.build();
+            String url;
+            try {
+                url = storage.uploadSuffix(file, suffix);
+            }  catch (Exception e) {
+                log.error("生成图片失败:{}",e.getMessage(),e);
+                return R.error("生成图片失败");
+            }
+            // 返回成功信息
+            return R.ok().put("url",url);
+
+        } catch (WxErrorException e) {
+            log.error(e.getMessage(), e);
+            return R.error("微信接口调用失败: " + e.getMessage());
+        }
+    }
 }

+ 36 - 0
fs-user-app/src/main/java/com/fs/app/controller/store/FsShareMaterialController.java

@@ -0,0 +1,36 @@
+package com.fs.app.controller.store;
+
+
+import com.fs.common.core.domain.R;
+import com.fs.his.domain.FsShareMaterial;
+import com.fs.his.service.IFsShareMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * 分享素材Controller
+ * 
+ * @author fs
+ * @date 2026-06-25
+ */
+@RestController
+@RequestMapping("/store/app/shareMaterial")
+public class FsShareMaterialController
+{
+    @Autowired
+    private IFsShareMaterialService fsShareMaterialService;
+
+    /**
+     * 根据素材id查询素材类型以及url
+     * */
+    @GetMapping("/getShareMaterial/{shareMaterialId}")
+    public R shareMaterialOptions(@PathVariable Long shareMaterialId){
+        FsShareMaterial fsShareMaterial = fsShareMaterialService.selectFsShareMaterialById(shareMaterialId);
+        return R.ok().put("data",fsShareMaterial);
+    }
+
+}