feat:微信相关功能模块抽离重构,动态获取相关配置已经登录逻辑等的完善
This commit is contained in:
+112
@@ -0,0 +1,112 @@
|
||||
package com.central.user.controller;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.zlt.wechat.entity.WechatConfig;
|
||||
import com.zlt.wechat.service.PrivateKeyService;
|
||||
import com.zlt.wechat.service.WechatConfigService;
|
||||
import com.zlt.wechat.service.WechatPayService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "微信配置管理")
|
||||
@RequestMapping("/wechat/config")
|
||||
public class SysWechatConfigController {
|
||||
|
||||
@Autowired
|
||||
private WechatConfigService wechatConfigService;
|
||||
|
||||
@Autowired
|
||||
private WechatPayService wechatPayService;
|
||||
|
||||
@Autowired
|
||||
private PrivateKeyService privateKeyService;
|
||||
|
||||
@Operation(summary = "查询列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in= ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
return wechatConfigService.findList(params);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取微信配置")
|
||||
@GetMapping("/{type}")
|
||||
public Result<WechatConfig> getConfig(@PathVariable String type) {
|
||||
return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant()));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取微信配置")
|
||||
@GetMapping("/app/{id}")
|
||||
public Result<WechatConfig> getConfigByAppId(@PathVariable String appId) {
|
||||
return Result.succeed(wechatConfigService.getConfig(appId));
|
||||
}
|
||||
|
||||
@Operation(summary = "保存微信配置")
|
||||
@PostMapping
|
||||
public Result<Boolean> saveConfig(@RequestBody WechatConfig config) {
|
||||
config.setTenantId(TenantContextHolder.getTenant());
|
||||
return Result.succeed(wechatConfigService.saveConfig(config));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新微信配置")
|
||||
@PutMapping
|
||||
public Result<Boolean> updateConfig(@RequestBody WechatConfig config) {
|
||||
config.setTenantId(TenantContextHolder.getTenant());
|
||||
return Result.succeed(wechatConfigService.updateConfig(config));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除微信配置")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Boolean> deleteConfig(@PathVariable Long id) {
|
||||
return Result.succeed(wechatConfigService.deleteConfig(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "上传支付私钥")
|
||||
@PostMapping("/private-key")
|
||||
public Result<Boolean> uploadPrivateKey(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
String privateKey = new String(file.getBytes());
|
||||
return Result.succeed(wechatPayService.uploadPrivateKey(
|
||||
TenantContextHolder.getTenant(), privateKey));
|
||||
} catch (Exception e) {
|
||||
log.error("上传私钥文件失败", e);
|
||||
return Result.failed("上传私钥文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新支付配置")
|
||||
@PostMapping("/pay-config")
|
||||
public Result<Boolean> updatePayConfig(@RequestBody Map<String, String> config) {
|
||||
return Result.succeed(wechatPayService.updatePayConfig(
|
||||
TenantContextHolder.getTenant(), config));
|
||||
}
|
||||
|
||||
@Operation(summary = "切换微信配置")
|
||||
@PostMapping("/switch/{type}")
|
||||
public Result<Boolean> switchConfig(@PathVariable String type) {
|
||||
return Result.succeed(wechatConfigService.switchConfig(type, TenantContextHolder.getTenant()));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取当前配置")
|
||||
@GetMapping("/current/{type}")
|
||||
public Result<WechatConfig> getCurrentConfig(@PathVariable String type) {
|
||||
return Result.succeed(wechatConfigService.getConfig(type, TenantContextHolder.getTenant()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.central.user.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("sys_wechat_config")
|
||||
public class SysWechatConfig {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 配置类型:MP-公众号,MINI-小程序,PAY-支付
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 商户ID
|
||||
*/
|
||||
private String merchantId;
|
||||
|
||||
/**
|
||||
* 应用ID
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 应用密钥
|
||||
*/
|
||||
private String appSecret;
|
||||
|
||||
/**
|
||||
* 商户API密钥
|
||||
*/
|
||||
private String mchKey;
|
||||
|
||||
/**
|
||||
* 商户证书序列号
|
||||
*/
|
||||
private String mchSerialNo;
|
||||
|
||||
/**
|
||||
* 商户私钥文件路径
|
||||
*/
|
||||
private String privateKeyPath;
|
||||
|
||||
/**
|
||||
* APIv3密钥
|
||||
*/
|
||||
private String apiV3Key;
|
||||
|
||||
/**
|
||||
* 支付回调地址
|
||||
*/
|
||||
private String notifyUrl;
|
||||
|
||||
/**
|
||||
* 微信公众号token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 微信公众号aesKey
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
/**
|
||||
* 支付成功通知模板ID
|
||||
*/
|
||||
private String paymentSuccessTemplateId;
|
||||
|
||||
/**
|
||||
* 视频处理完成通知模板ID
|
||||
*/
|
||||
private String videoCompleteTemplateId;
|
||||
|
||||
/**
|
||||
* 视频处理失败通知模板ID
|
||||
*/
|
||||
private String videoFailTemplateId;
|
||||
|
||||
/**
|
||||
* 是否启用分账
|
||||
*/
|
||||
private Boolean profitSharingEnabled;
|
||||
|
||||
/**
|
||||
* 是否启用异步处理
|
||||
*/
|
||||
private Boolean asyncEnabled;
|
||||
|
||||
/**
|
||||
* 异步处理线程池大小
|
||||
*/
|
||||
private Integer asyncPoolSize;
|
||||
|
||||
/**
|
||||
* 状态:0-禁用,1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.central.user.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.user.model.SysWechatConfig;
|
||||
|
||||
public interface SysWechatConfigService extends IService<SysWechatConfig> {
|
||||
|
||||
/**
|
||||
* 获取微信配置
|
||||
*
|
||||
* @param type 配置类型
|
||||
* @return 微信配置
|
||||
*/
|
||||
SysWechatConfig getConfig(String type);
|
||||
|
||||
/**
|
||||
* 保存微信配置
|
||||
*
|
||||
* @param config 微信配置
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean saveConfig(SysWechatConfig config);
|
||||
|
||||
/**
|
||||
* 更新微信配置
|
||||
*
|
||||
* @param config 微信配置
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateConfig(SysWechatConfig config);
|
||||
|
||||
/**
|
||||
* 删除微信配置
|
||||
*
|
||||
* @param id 配置ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteConfig(Long id);
|
||||
|
||||
/**
|
||||
* 切换当前使用的微信配置
|
||||
*
|
||||
* @param type 配置类型
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean switchConfig(String type);
|
||||
|
||||
/**
|
||||
* 获取当前使用的微信配置
|
||||
*
|
||||
* @param type 配置类型
|
||||
* @return 微信配置
|
||||
*/
|
||||
SysWechatConfig getCurrentConfig(String type);
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.central.user.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.user.mapper.SysWechatConfigMapper;
|
||||
import com.central.user.model.SysWechatConfig;
|
||||
import com.central.user.service.SysWechatConfigService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SysWechatConfigServiceImpl extends ServiceImpl<SysWechatConfigMapper, SysWechatConfig>
|
||||
implements SysWechatConfigService {
|
||||
|
||||
private static final String CACHE_NAME = "wechat:config";
|
||||
private static final String CACHE_KEY_PATTERN = "#type";
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CACHE_NAME, key = CACHE_KEY_PATTERN, unless = "#result == null")
|
||||
public SysWechatConfig getConfig(String type) {
|
||||
return getOne(new LambdaQueryWrapper<SysWechatConfig>()
|
||||
.eq(SysWechatConfig::getType, type)
|
||||
.eq(SysWechatConfig::getTenantId, TenantContextHolder.getTenant())
|
||||
.eq(SysWechatConfig::getStatus, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CACHE_NAME, key = CACHE_KEY_PATTERN)
|
||||
public boolean saveConfig(SysWechatConfig config) {
|
||||
config.setTenantId(TenantContextHolder.getTenant());
|
||||
return save(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CACHE_NAME, key = CACHE_KEY_PATTERN)
|
||||
public boolean updateConfig(SysWechatConfig config) {
|
||||
config.setTenantId(TenantContextHolder.getTenant());
|
||||
return updateById(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CACHE_NAME, allEntries = true)
|
||||
public boolean deleteConfig(Long id) {
|
||||
return removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CACHE_NAME, key = CACHE_KEY_PATTERN)
|
||||
public boolean switchConfig(String type) {
|
||||
// 这里可以添加切换配置的具体逻辑
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CACHE_NAME, key = "'current:' + #type", unless = "#result == null")
|
||||
public SysWechatConfig getCurrentConfig(String type) {
|
||||
return getConfig(type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user