Explorar o código

一键绑定所有商户配置

xw hai 1 mes
pai
achega
c95e3fa4ed

+ 81 - 3
fs-admin/src/main/java/com/fs/course/controller/FsCoursePlaySourceConfigController.java

@@ -24,6 +24,8 @@ import com.fs.course.param.FsCoursePlaySourceConfigEditParam;
 import com.fs.course.service.IFsCoursePlaySourceConfigService;
 import com.fs.course.vo.FsCoursePlaySourceConfigVO;
 import com.fs.framework.web.service.TokenService;
+import com.fs.his.domain.MerchantAppConfig;
+import com.fs.his.service.IMerchantAppConfigService;
 import com.fs.system.service.ISysConfigService;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
@@ -42,6 +44,7 @@ public class FsCoursePlaySourceConfigController extends BaseController {
     private final IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
     private final TokenService tokenService;
     private final ISysConfigService configService;
+    private final IMerchantAppConfigService merchantAppConfigService;
 
 //    @PreAuthorize("@ss.hasPermi('course:playSourceConfig:list')")
     @GetMapping("/list")
@@ -99,7 +102,7 @@ public class FsCoursePlaySourceConfigController extends BaseController {
         if (fsCoursePlaySourceConfigService.count(queryWrapper) > 0) {
             return AjaxResult.error("appid已存在");
         }
-        
+
         // 校验自定义授权配置
         if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 1) {
             if (param.getMiniAppAuthType() == null) {
@@ -109,7 +112,7 @@ public class FsCoursePlaySourceConfigController extends BaseController {
                 return AjaxResult.error("选择服务号授权时必须填写授权域名");
             }
         }
-        
+
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         FsCoursePlaySourceConfig config = new FsCoursePlaySourceConfig();
         config.setCreateUserId(loginUser.getUserId());
@@ -141,7 +144,6 @@ public class FsCoursePlaySourceConfigController extends BaseController {
             return AjaxResult.error("appid已存在");
         }
 
-        // 校验自定义授权配置
         if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 1) {
             if (param.getMiniAppAuthType() == null) {
                 return AjaxResult.error("开启自定义授权时必须选择授权方式");
@@ -152,6 +154,13 @@ public class FsCoursePlaySourceConfigController extends BaseController {
         }
 
         BeanUtils.copyProperties(param, config);
+
+        if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 0) {
+            config.setCustomAuthEnabled(0);
+            config.setMiniAppAuthType(null);
+            config.setUserCourseAuthDomain(null);
+        }
+
         fsCoursePlaySourceConfigService.updateById(config);
         return AjaxResult.success();
     }
@@ -179,6 +188,75 @@ public class FsCoursePlaySourceConfigController extends BaseController {
         return AjaxResult.success();
     }
 
+    @PreAuthorize("@ss.hasPermi('course:playSourceConfig:bind')")
+    @Log(title = "批量绑定商户支付配置", businessType = BusinessType.UPDATE)
+    @PostMapping("/batchBindMerchantConfig")
+    public AjaxResult batchBindMerchantConfig(@RequestBody Map<String, Object> params) {
+        Object idsObj = params.get("ids");
+        if (idsObj == null) {
+            return AjaxResult.error("请选择需要绑定的商户配置");
+        }
+
+        List<Long> merchantConfigIds = new ArrayList<>();
+        if (idsObj instanceof List) {
+            for (Object id : (List<?>) idsObj) {
+                if (id instanceof Integer) {
+                    merchantConfigIds.add(((Integer) id).longValue());
+                } else if (id instanceof Long) {
+                    merchantConfigIds.add((Long) id);
+                } else if (id instanceof String) {
+                    merchantConfigIds.add(Long.parseLong((String) id));
+                }
+            }
+        }
+
+        if (merchantConfigIds.isEmpty()) {
+            return AjaxResult.error("请选择需要绑定的商户配置");
+        }
+
+        int totalBindCount = 0;
+        StringBuilder errorMsg = new StringBuilder();
+
+        for (Long merchantConfigId : merchantConfigIds) {
+            try {
+                MerchantAppConfig merchantConfig = merchantAppConfigService.selectMerchantAppConfigById(merchantConfigId);
+                if (merchantConfig == null || merchantConfig.getAppId() == null || merchantConfig.getAppId().trim().isEmpty()) {
+                    errorMsg.append("商户配置ID:").append(merchantConfigId).append(" 不存在或AppId为空; ");
+                    continue;
+                }
+
+                for (String appId : merchantConfig.getAppId().split(",")) {
+                    appId = appId.trim();
+                    if (appId.isEmpty()) continue;
+
+                    QueryWrapper<FsCoursePlaySourceConfig> queryWrapper = new QueryWrapper<>();
+                    queryWrapper.eq("appid", appId).eq("is_del", 0);
+                    List<FsCoursePlaySourceConfig> configs = fsCoursePlaySourceConfigService.list(queryWrapper);
+
+                    for (FsCoursePlaySourceConfig config : configs) {
+                        FsCoursePlaySourceConfig updateConfig = new FsCoursePlaySourceConfig();
+                        updateConfig.setId(config.getId());
+                        updateConfig.setMerchantConfigId(merchantConfigId);
+                        fsCoursePlaySourceConfigService.updateById(updateConfig);
+                        totalBindCount++;
+                    }
+                }
+            } catch (Exception e) {
+                errorMsg.append("商户配置ID:").append(merchantConfigId).append(" 绑定异常:").append(e.getMessage()).append("; ");
+            }
+        }
+
+        if (totalBindCount == 0) {
+            return AjaxResult.error("批量绑定失败:" + (errorMsg.length() > 0 ? errorMsg.toString() : "未找到匹配的小程序配置"));
+        }
+
+        String message = "批量绑定成功,共绑定 " + totalBindCount + " 个小程序配置";
+        if (errorMsg.length() > 0) {
+            message += "。部分失败:" + errorMsg.toString();
+        }
+        return AjaxResult.success(message);
+    }
+
     @PreAuthorize("@ss.hasPermi('course:playSourceConfig:remove')")
     @Log(title = "点播播放源配置", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")

+ 3 - 0
fs-service/src/main/java/com/fs/course/vo/FsCoursePlaySourceConfigVO.java

@@ -65,6 +65,9 @@ public class FsCoursePlaySourceConfigVO {
     @ApiModelProperty("小程序状态:0正常,1半封禁,2封禁")
     private Integer status;
 
+    @ApiModelProperty("商户支付配置id")
+    private Long merchantConfigId;
+
     @ApiModelProperty("是否开启自定义授权 0-否 1-是")
     private Integer customAuthEnabled;