Compare commits
7 Commits
b2335d34a5
...
dev
Author | SHA1 | Date | |
---|---|---|---|
1ad79f600d | |||
c87006e721 | |||
6985cf39aa | |||
5b4d2afc5a | |||
3daffdf323 | |||
927fab3bdd | |||
f0f2b779f8 |
@ -4,6 +4,7 @@ import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.greenorange.promotion.annotation.RequiresPermission;
|
||||
import com.greenorange.promotion.common.ErrorCode;
|
||||
import com.greenorange.promotion.exception.BusinessException;
|
||||
import com.greenorange.promotion.exception.ThrowUtils;
|
||||
import com.greenorange.promotion.model.entity.UserInfo;
|
||||
import com.greenorange.promotion.model.enums.UserRoleEnum;
|
||||
@ -57,9 +58,14 @@ public class PermissionCheck {
|
||||
ThrowUtils.throwIf(interfaceRoleEnum == null, ErrorCode.NO_AUTH_ERROR);
|
||||
// 获取用户权限
|
||||
String token = request.getHeader("Authorization");
|
||||
ThrowUtils.throwIf(StringUtils.isBlank(token), ErrorCode.NO_AUTH_ERROR, "JWT为空");
|
||||
ThrowUtils.throwIf(StringUtils.isBlank(token), ErrorCode.NO_AUTH_ERROR, "token为空");
|
||||
// 解析token
|
||||
DecodedJWT decodedJWT = jwtUtils.verify(token);
|
||||
DecodedJWT decodedJWT;
|
||||
try {
|
||||
decodedJWT = jwtUtils.verify(token);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(ErrorCode.NO_AUTH_ERROR, "token已过期");
|
||||
}
|
||||
String userAccount = decodedJWT.getClaim("userAccount").asString();
|
||||
String userPassword = decodedJWT.getClaim("userPassword").asString();
|
||||
String userRole = decodedJWT.getClaim("userRole").asString();
|
||||
|
@ -1,44 +1,44 @@
|
||||
package com.greenorange.promotion.config;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "wx.mini")
|
||||
public class WxOpenConfig {
|
||||
|
||||
private String appId;
|
||||
|
||||
private String appSecret;
|
||||
|
||||
private WxMaService wxMaService;
|
||||
|
||||
/**
|
||||
* 单例模式
|
||||
*/
|
||||
public WxMaService getWxMaService() {
|
||||
if (wxMaService != null) {
|
||||
return wxMaService;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (wxMaService != null) {
|
||||
return wxMaService;
|
||||
}
|
||||
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
config.setAppid(appId);
|
||||
config.setSecret(appSecret);
|
||||
WxMaService service = new WxMaServiceImpl();
|
||||
service.setWxMaConfig(config);
|
||||
wxMaService = service;
|
||||
return wxMaService;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//package com.greenorange.promotion.config;
|
||||
//
|
||||
//import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
//import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
//import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
//@Data
|
||||
//@Slf4j
|
||||
//@Configuration
|
||||
//@ConfigurationProperties(prefix = "wx.mini")
|
||||
//public class WxOpenConfig {
|
||||
//
|
||||
// private String appId;
|
||||
//
|
||||
// private String appSecret;
|
||||
//
|
||||
// private WxMaService wxMaService;
|
||||
//
|
||||
// /**
|
||||
// * 单例模式
|
||||
// */
|
||||
// public WxMaService getWxMaService() {
|
||||
// if (wxMaService != null) {
|
||||
// return wxMaService;
|
||||
// }
|
||||
// synchronized (this) {
|
||||
// if (wxMaService != null) {
|
||||
// return wxMaService;
|
||||
// }
|
||||
// WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
|
||||
// config.setAppid(appId);
|
||||
// config.setSecret(appSecret);
|
||||
// WxMaService service = new WxMaServiceImpl();
|
||||
// service.setWxMaConfig(config);
|
||||
// wxMaService = service;
|
||||
// return wxMaService;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,78 +1,78 @@
|
||||
package com.greenorange.promotion.config;
|
||||
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.util.IOUtil;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@Component("WxPayConfig")
|
||||
@ConfigurationProperties(prefix = "wx.pay")
|
||||
public class WxPayConfig {
|
||||
|
||||
private String appId;
|
||||
|
||||
private String apiV3Key;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String merchantId;
|
||||
|
||||
private String privateKeyPath;
|
||||
|
||||
private String merchantSerialNumber;
|
||||
|
||||
// RSA配置
|
||||
private RSAAutoCertificateConfig RSAConfig;
|
||||
|
||||
// JSAPI支付
|
||||
private JsapiServiceExtension jsapiServiceExtension;
|
||||
|
||||
// 退款
|
||||
private RefundService refundService;
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
*/
|
||||
@Bean
|
||||
public boolean initWxPayConfig() throws IOException {
|
||||
this.RSAConfig = buildRSAAutoCertificateConfig();
|
||||
this.jsapiServiceExtension = buildJsapiServiceExtension(RSAConfig);
|
||||
this.refundService = buildRefundService(RSAConfig);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 构建并使用自动更新平台证书的RSA配置,一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
|
||||
private RSAAutoCertificateConfig buildRSAAutoCertificateConfig() throws IOException {
|
||||
// 将 resource 目录下的文件转为 InputStream,然后利用 IOUtil.toString(inputStream) 转化为密钥
|
||||
String privateKey = IOUtil.toString(new ClassPathResource(privateKeyPath).getInputStream());
|
||||
return new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(merchantId)
|
||||
.privateKey(privateKey)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.apiV3Key(apiV3Key)
|
||||
.build();
|
||||
}
|
||||
|
||||
// 构建JSAPI支付
|
||||
private JsapiServiceExtension buildJsapiServiceExtension(RSAAutoCertificateConfig config) {
|
||||
return new JsapiServiceExtension.Builder().config(config).build();
|
||||
}
|
||||
|
||||
// 构建退款
|
||||
private RefundService buildRefundService(RSAAutoCertificateConfig config) {
|
||||
return new RefundService.Builder().config(config).build();
|
||||
}
|
||||
|
||||
}
|
||||
//package com.greenorange.promotion.config;
|
||||
//
|
||||
//import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
//import com.wechat.pay.java.core.util.IOUtil;
|
||||
//import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
//import com.wechat.pay.java.service.refund.RefundService;
|
||||
//import lombok.Data;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.core.io.ClassPathResource;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//@Data
|
||||
//@Slf4j
|
||||
//@Configuration
|
||||
//@Component("WxPayConfig")
|
||||
//@ConfigurationProperties(prefix = "wx.pay")
|
||||
//public class WxPayConfig {
|
||||
//
|
||||
// private String appId;
|
||||
//
|
||||
// private String apiV3Key;
|
||||
//
|
||||
// private String notifyUrl;
|
||||
//
|
||||
// private String merchantId;
|
||||
//
|
||||
// private String privateKeyPath;
|
||||
//
|
||||
// private String merchantSerialNumber;
|
||||
//
|
||||
// // RSA配置
|
||||
// private RSAAutoCertificateConfig RSAConfig;
|
||||
//
|
||||
// // JSAPI支付
|
||||
// private JsapiServiceExtension jsapiServiceExtension;
|
||||
//
|
||||
// // 退款
|
||||
// private RefundService refundService;
|
||||
//
|
||||
// /**
|
||||
// * 初始化配置
|
||||
// */
|
||||
// @Bean
|
||||
// public boolean initWxPayConfig() throws IOException {
|
||||
// this.RSAConfig = buildRSAAutoCertificateConfig();
|
||||
// this.jsapiServiceExtension = buildJsapiServiceExtension(RSAConfig);
|
||||
// this.refundService = buildRefundService(RSAConfig);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// // 构建并使用自动更新平台证书的RSA配置,一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
|
||||
// private RSAAutoCertificateConfig buildRSAAutoCertificateConfig() throws IOException {
|
||||
// // 将 resource 目录下的文件转为 InputStream,然后利用 IOUtil.toString(inputStream) 转化为密钥
|
||||
// String privateKey = IOUtil.toString(new ClassPathResource(privateKeyPath).getInputStream());
|
||||
// return new RSAAutoCertificateConfig.Builder()
|
||||
// .merchantId(merchantId)
|
||||
// .privateKey(privateKey)
|
||||
// .merchantSerialNumber(merchantSerialNumber)
|
||||
// .apiV3Key(apiV3Key)
|
||||
// .build();
|
||||
// }
|
||||
//
|
||||
// // 构建JSAPI支付
|
||||
// private JsapiServiceExtension buildJsapiServiceExtension(RSAAutoCertificateConfig config) {
|
||||
// return new JsapiServiceExtension.Builder().config(config).build();
|
||||
// }
|
||||
//
|
||||
// // 构建退款
|
||||
// private RefundService buildRefundService(RSAAutoCertificateConfig config) {
|
||||
// return new RefundService.Builder().config(config).build();
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -58,4 +58,8 @@ public interface UserConstant {
|
||||
*/
|
||||
String STAFF_ROLE = "staff";
|
||||
|
||||
/**
|
||||
* 申请通知
|
||||
*/
|
||||
String APPLY_NOTICE_KEY = "applyNotice";
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ public class CourseController {
|
||||
public BaseResponse<List<CourseCardVO>> miniQueryCourseByKeyword(@Valid @RequestBody CommonStringRequest commonStringRequest) {
|
||||
String keyword = commonStringRequest.getTemplateString();
|
||||
LambdaQueryWrapper<Course> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(Course::getIsShelves, 1);
|
||||
lambdaQueryWrapper.like(Course::getName, keyword);
|
||||
List<Course> courseList = courseService.list(lambdaQueryWrapper);
|
||||
List<CourseCardVO> courseCardVOS = commonService.convertList(courseList, CourseCardVO.class);
|
||||
|
@ -18,11 +18,9 @@ import com.greenorange.promotion.model.dto.CommonRequest;
|
||||
import com.greenorange.promotion.model.dto.courseOrder.CourseOrderAddRequest;
|
||||
import com.greenorange.promotion.model.dto.courseOrder.CourseOrderQueryRequest;
|
||||
import com.greenorange.promotion.model.dto.courseOrder.CourseOrderUpdateRequest;
|
||||
import com.greenorange.promotion.model.entity.Course;
|
||||
import com.greenorange.promotion.model.entity.CourseOrder;
|
||||
import com.greenorange.promotion.model.entity.CoursePromotionCommissionPending;
|
||||
import com.greenorange.promotion.model.entity.UserPerformanceSummary;
|
||||
import com.greenorange.promotion.model.entity.*;
|
||||
import com.greenorange.promotion.model.enums.CommissionStatusEnum;
|
||||
import com.greenorange.promotion.model.enums.UserRoleEnum;
|
||||
import com.greenorange.promotion.model.vo.course.CourseCardVO;
|
||||
import com.greenorange.promotion.model.vo.course.CourseVO;
|
||||
import com.greenorange.promotion.model.vo.courseOrder.CourseOrderBaseInfoVO;
|
||||
@ -93,6 +91,10 @@ public class CourseOrderController {
|
||||
@SysLog(title = "课程订单管理", content = "小程序端用户生成课程订单")
|
||||
public BaseResponse<Long> addCourseOrder(@Valid @RequestBody CourseOrderAddRequest courseOrderAddRequest, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
String userRole = userInfo.getUserRole();
|
||||
UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
|
||||
ThrowUtils.throwIf(!UserRoleEnum.USER.equals(userRoleEnum), ErrorCode.NO_AUTH_ERROR, "只有普通用户才能创建订单");
|
||||
Long courseId = courseOrderAddRequest.getCourseId();
|
||||
Course course = courseService.getById(courseId);
|
||||
ThrowUtils.throwIf(course == null, ErrorCode.OPERATION_ERROR, "该课程不存在");
|
||||
|
@ -1,72 +1,72 @@
|
||||
package com.greenorange.promotion.controller.course;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.greenorange.promotion.annotation.RequiresPermission;
|
||||
import com.greenorange.promotion.annotation.SysLog;
|
||||
import com.greenorange.promotion.common.BaseResponse;
|
||||
import com.greenorange.promotion.common.ResultUtils;
|
||||
import com.greenorange.promotion.constant.UserConstant;
|
||||
import com.greenorange.promotion.model.dto.CommonBatchRequest;
|
||||
import com.greenorange.promotion.model.dto.refundRecord.RefundRecordAddRequest;
|
||||
import com.greenorange.promotion.model.dto.refundRecord.RefundRecordQueryRequest;
|
||||
import com.greenorange.promotion.model.dto.refundRecord.RefundRecordUpdateRequest;
|
||||
import com.greenorange.promotion.model.entity.RefundRecord;
|
||||
import com.greenorange.promotion.model.vo.refundRecord.RefundRecordVO;
|
||||
import com.greenorange.promotion.service.common.CommonService;
|
||||
import com.greenorange.promotion.service.refund.RefundRecordService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.greenorange.promotion.model.dto.CommonRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 退款记录 控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("refundRecord")
|
||||
@Slf4j
|
||||
@Tag(name = "退款记录模块")
|
||||
@Transactional
|
||||
public class RefundRecordController {
|
||||
|
||||
@Resource
|
||||
private RefundRecordService refundRecordService;
|
||||
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
|
||||
/**
|
||||
* Web端管理员分页查询退款记录
|
||||
* @param refundRecordQueryRequest 退款记录查询请求体
|
||||
* @return 退款记录列表
|
||||
*/
|
||||
@PostMapping("page")
|
||||
@Operation(summary = "Web端管理员分页查询退款记录", description = "参数:退款记录查询请求体,权限:管理员,方法名:listRefundRecordByPage")
|
||||
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
|
||||
@SysLog(title = "退款记录管理", content = "Web端管理员分页查询退款记录")
|
||||
public BaseResponse<Page<RefundRecordVO>> listRefundRecordByPage(@Valid @RequestBody RefundRecordQueryRequest refundRecordQueryRequest) {
|
||||
long current = refundRecordQueryRequest.getCurrent();
|
||||
long pageSize = refundRecordQueryRequest.getPageSize();
|
||||
QueryWrapper<RefundRecord> queryWrapper = refundRecordService.getQueryWrapper(refundRecordQueryRequest);
|
||||
Page<RefundRecord> page = refundRecordService.page(new Page<>(current, pageSize), queryWrapper);
|
||||
List<RefundRecord> refundRecordList = page.getRecords();
|
||||
List<RefundRecordVO> refundRecordVOList = commonService.convertList(refundRecordList, RefundRecordVO.class);
|
||||
Page<RefundRecordVO> voPage = new Page<>(current, pageSize);
|
||||
voPage.setRecords(refundRecordVOList);
|
||||
voPage.setPages(page.getPages());
|
||||
voPage.setTotal(page.getTotal());
|
||||
return ResultUtils.success(voPage);
|
||||
}
|
||||
}
|
||||
//package com.greenorange.promotion.controller.course;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.greenorange.promotion.annotation.RequiresPermission;
|
||||
//import com.greenorange.promotion.annotation.SysLog;
|
||||
//import com.greenorange.promotion.common.BaseResponse;
|
||||
//import com.greenorange.promotion.common.ResultUtils;
|
||||
//import com.greenorange.promotion.constant.UserConstant;
|
||||
//import com.greenorange.promotion.model.dto.CommonBatchRequest;
|
||||
//import com.greenorange.promotion.model.dto.refundRecord.RefundRecordAddRequest;
|
||||
//import com.greenorange.promotion.model.dto.refundRecord.RefundRecordQueryRequest;
|
||||
//import com.greenorange.promotion.model.dto.refundRecord.RefundRecordUpdateRequest;
|
||||
//import com.greenorange.promotion.model.entity.RefundRecord;
|
||||
//import com.greenorange.promotion.model.vo.refundRecord.RefundRecordVO;
|
||||
//import com.greenorange.promotion.service.common.CommonService;
|
||||
//import com.greenorange.promotion.service.refund.RefundRecordService;
|
||||
//import io.swagger.v3.oas.annotations.Operation;
|
||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestBody;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.greenorange.promotion.model.dto.CommonRequest;
|
||||
//import jakarta.validation.Valid;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 退款记录 控制器
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("refundRecord")
|
||||
//@Slf4j
|
||||
//@Tag(name = "退款记录模块")
|
||||
//@Transactional
|
||||
//public class RefundRecordController {
|
||||
//
|
||||
// @Resource
|
||||
// private RefundRecordService refundRecordService;
|
||||
//
|
||||
// @Resource
|
||||
// private CommonService commonService;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Web端管理员分页查询退款记录
|
||||
// * @param refundRecordQueryRequest 退款记录查询请求体
|
||||
// * @return 退款记录列表
|
||||
// */
|
||||
// @PostMapping("page")
|
||||
// @Operation(summary = "Web端管理员分页查询退款记录", description = "参数:退款记录查询请求体,权限:管理员,方法名:listRefundRecordByPage")
|
||||
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
|
||||
// @SysLog(title = "退款记录管理", content = "Web端管理员分页查询退款记录")
|
||||
// public BaseResponse<Page<RefundRecordVO>> listRefundRecordByPage(@Valid @RequestBody RefundRecordQueryRequest refundRecordQueryRequest) {
|
||||
// long current = refundRecordQueryRequest.getCurrent();
|
||||
// long pageSize = refundRecordQueryRequest.getPageSize();
|
||||
// QueryWrapper<RefundRecord> queryWrapper = refundRecordService.getQueryWrapper(refundRecordQueryRequest);
|
||||
// Page<RefundRecord> page = refundRecordService.page(new Page<>(current, pageSize), queryWrapper);
|
||||
// List<RefundRecord> refundRecordList = page.getRecords();
|
||||
// List<RefundRecordVO> refundRecordVOList = commonService.convertList(refundRecordList, RefundRecordVO.class);
|
||||
// Page<RefundRecordVO> voPage = new Page<>(current, pageSize);
|
||||
// voPage.setRecords(refundRecordVOList);
|
||||
// voPage.setPages(page.getPages());
|
||||
// voPage.setTotal(page.getTotal());
|
||||
// return ResultUtils.success(voPage);
|
||||
// }
|
||||
//}
|
@ -37,7 +37,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaQrcode;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.greenorange.promotion.annotation.RequiresPermission;
|
||||
import com.greenorange.promotion.annotation.SysLog;
|
||||
@ -84,46 +85,129 @@ public class UserInfoController {
|
||||
// @PostMapping("test")
|
||||
// public BaseResponse<Boolean> test() throws IOException {
|
||||
// List<UserInfo> list = userInfoService.list();
|
||||
// List<UserMainInfo> userMainInfoList = userMainInfoService.list();
|
||||
// Map<Long, UserInfo> map = new HashMap<>();
|
||||
// for (UserInfo userInfo : list) {
|
||||
// map.put(userInfo.getId(), userInfo);
|
||||
// }
|
||||
// List<UserMainInfo> userMainInfoList = userMainInfoService.list();
|
||||
// for (UserMainInfo userMainInfo : userMainInfoList) {
|
||||
// Long userId = userMainInfo.getUserId();
|
||||
// UserInfo userInfo = map.get(userId);
|
||||
// String userRole = userInfo.getUserRole();
|
||||
// UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
|
||||
// String wxQrCode = wechatGetQrcodeService.getWxQrCode(userInfo.getInvitationCode(), userRoleEnum);
|
||||
// UserMainInfo userMainInfo = UserMainInfo.builder().userId(userInfo.getId()).inviteQrCode(wxQrCode).build();
|
||||
// userMainInfoList.add(userMainInfo);
|
||||
// String view = wechatGetQrcodeService.getWxQrCode(userInfo.getInvitationCode(), userRoleEnum);
|
||||
// userMainInfo.setInviteQrCode(view);
|
||||
// }
|
||||
// userMainInfoService.saveOrUpdateBatch(userMainInfoList);
|
||||
// return ResultUtils.success(true);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户校验token
|
||||
* @return 是否校验成功
|
||||
*/
|
||||
@PostMapping("verify/token")
|
||||
@Operation(summary = "小程序端用户校验token", description = "参数:token, 权限:管理员(boss, admin),方法名:verifyToken")
|
||||
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
|
||||
public BaseResponse<Boolean> verifyToken() {
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* web端修改员工申请须知
|
||||
* @param commonStringRequest 修改内容
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@PostMapping("modify/applyNotice")
|
||||
@Operation(summary = "web端修改员工申请须知", description = "参数:昵称,权限:管理员(boss, admin),方法名:modifyApplyNotice")
|
||||
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<Boolean> modifyApplyNotice(@Valid @RequestBody CommonStringRequest commonStringRequest) {
|
||||
String applyNotice = commonStringRequest.getTemplateString();
|
||||
redisTemplate.opsForValue().set(UserConstant.APPLY_NOTICE_KEY, applyNotice);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端查询员工申请须知
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@PostMapping("query/applyNotice")
|
||||
@Operation(summary = "小程序端查询员工申请须知", description = "参数:无,权限:管理员(boss, admin),方法名:queryApplyNotice")
|
||||
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<String> queryApplyNotice() {
|
||||
String applyNotice = redisTemplate.opsForValue().get(UserConstant.APPLY_NOTICE_KEY);
|
||||
return ResultUtils.success(applyNotice);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户修改用户昵称
|
||||
* @param commonStringRequest 昵称
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@PostMapping("modify/nickname")
|
||||
@Operation(summary = "小程序端用户修改用户昵称", description = "参数:昵称,权限:管理员(boss, admin),方法名:modifyNickname")
|
||||
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
|
||||
public BaseResponse<Boolean> modifyNickname(@Valid @RequestBody CommonStringRequest commonStringRequest, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
String nickName = commonStringRequest.getTemplateString();
|
||||
LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(UserInfo::getNickName, nickName);
|
||||
queryWrapper.ne(UserInfo::getId, userId);
|
||||
ThrowUtils.throwIf(userInfoService.count(queryWrapper) > 0, ErrorCode.PARAMS_ERROR, "昵称已存在");
|
||||
|
||||
LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(UserInfo::getId, userId).set(UserInfo::getNickName, nickName);
|
||||
userInfoService.update(updateWrapper);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户修改用户头像
|
||||
* @param commonStringRequest 头像view值
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@PostMapping("modify/avatar")
|
||||
@Operation(summary = "小程序端用户修改用户头像", description = "参数:头像view值,权限:管理员(boss, admin),方法名:modifyUserAvatar")
|
||||
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
|
||||
public BaseResponse<Boolean> modifyUserAvatar(@Valid @RequestBody CommonStringRequest commonStringRequest, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
String view = commonStringRequest.getTemplateString();
|
||||
LambdaUpdateWrapper<UserInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(UserInfo::getId, userId).set(UserInfo::getUserAvatar, view);
|
||||
userInfoService.update(updateWrapper);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户获取验证码(用于注册)
|
||||
* @param commonStringRequest 手机号
|
||||
* @param verificationCodeGetRequest 验证码获取请求体
|
||||
* @return 验证码
|
||||
*/
|
||||
@PostMapping("code/register")
|
||||
@Operation(summary = "小程序端用户获取验证码(用于注册)", description = "参数:手机号,权限:管理员(boss, admin),方法名:getVerificationCodeForRegister")
|
||||
public BaseResponse<String> getVerificationCodeForRegister(@Valid @RequestBody CommonStringRequest commonStringRequest) {
|
||||
String phoneNumber = commonStringRequest.getTemplateString();
|
||||
String verificationCode = userInfoService.getVerificationCodeForRegister(phoneNumber);
|
||||
public BaseResponse<String> getVerificationCodeForRegister(@Valid @RequestBody VerificationCodeGetRequest verificationCodeGetRequest) {
|
||||
String verificationCode = userInfoService.getVerificationCodeForRegister(verificationCodeGetRequest);
|
||||
return ResultUtils.success(verificationCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户获取验证码(用于密码登录和忘记密码)
|
||||
* @param commonStringRequest 手机号
|
||||
* @param verificationCodeGetRequest 验证码获取请求体
|
||||
* @return 验证码
|
||||
*/
|
||||
@PostMapping("code/pwd")
|
||||
@Operation(summary = "小程序端用户获取验证码(用于密码登录和忘记密码)", description = "参数:手机号,权限:管理员(boss, admin),方法名:getVerificationCode")
|
||||
// @SysLog(title = "用户管理", content = "小程序端用户获取验证码")
|
||||
public BaseResponse<String> getVerificationCode(@Valid @RequestBody CommonStringRequest commonStringRequest) {
|
||||
String phoneNumber = commonStringRequest.getTemplateString();
|
||||
String verificationCode = userInfoService.getVerificationCodeForPwdLogin(phoneNumber);
|
||||
public BaseResponse<String> getVerificationCode(@Valid @RequestBody VerificationCodeGetRequest verificationCodeGetRequest) {
|
||||
String verificationCode = userInfoService.getVerificationCodeForPwdLogin(verificationCodeGetRequest);
|
||||
return ResultUtils.success(verificationCode);
|
||||
}
|
||||
|
||||
|
@ -1,153 +1,153 @@
|
||||
package com.greenorange.promotion.controller.wechat;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import com.greenorange.promotion.annotation.RequiresPermission;
|
||||
import com.greenorange.promotion.common.BaseResponse;
|
||||
import com.greenorange.promotion.common.ErrorCode;
|
||||
import com.greenorange.promotion.common.ResultUtils;
|
||||
import com.greenorange.promotion.config.WxOpenConfig;
|
||||
import com.greenorange.promotion.constant.OrderStatusConstant;
|
||||
import com.greenorange.promotion.constant.UserConstant;
|
||||
import com.greenorange.promotion.exception.BusinessException;
|
||||
import com.greenorange.promotion.exception.ThrowUtils;
|
||||
import com.greenorange.promotion.model.dto.CommonRequest;
|
||||
import com.greenorange.promotion.model.dto.wxPay.WechatPayRequest;
|
||||
import com.greenorange.promotion.model.entity.CourseOrder;
|
||||
import com.greenorange.promotion.model.entity.UserInfo;
|
||||
import com.greenorange.promotion.service.course.CourseOrderService;
|
||||
import com.greenorange.promotion.service.userInfo.UserInfoService;
|
||||
import com.greenorange.promotion.service.wechat.WechatPayService;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import com.wechat.pay.java.service.refund.model.Refund;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "微信支付")
|
||||
@RequestMapping("/wxPay")
|
||||
@Transactional
|
||||
public class WechatPayController {
|
||||
|
||||
|
||||
@Resource
|
||||
private WechatPayService weChatService;
|
||||
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Resource
|
||||
private CourseOrderService courseOrderService;
|
||||
|
||||
@Resource
|
||||
private WxOpenConfig wxOpenConfig;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* JSAPI 下单
|
||||
*/
|
||||
@PostMapping("/payment/create")
|
||||
@Operation(summary = "JSAPI 下单", description = "参数:订单id, 权限:所有人, 方法名:createPayment")
|
||||
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
|
||||
public BaseResponse<PrepayWithRequestPaymentResponse> createPayment(@Valid @RequestBody WechatPayRequest wechatPayRequest, HttpServletRequest request) {
|
||||
|
||||
String code = wechatPayRequest.getCode();
|
||||
WxMaJscode2SessionResult sessionInfo;
|
||||
String miniOpenId;
|
||||
try {
|
||||
WxMaService wxMaService = wxOpenConfig.getWxMaService();
|
||||
sessionInfo = wxMaService.jsCode2SessionInfo(code);
|
||||
miniOpenId = sessionInfo.getOpenid();
|
||||
if (StringUtils.isAnyBlank(miniOpenId)) {
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
|
||||
}
|
||||
} catch (WxErrorException e) {
|
||||
log.error("userLoginByWxOpen error", e);
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败,系统错误");
|
||||
}
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
|
||||
Long orderId = wechatPayRequest.getOrderId();
|
||||
CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
ThrowUtils.throwIf(courseOrder == null, ErrorCode.NOT_FOUND_ERROR, "订单不存在");
|
||||
ThrowUtils.throwIf(!courseOrder.getOrderStatus().equals(OrderStatusConstant.PENDING), ErrorCode.OPERATION_ERROR, "订单状态错误");
|
||||
if (!userInfo.getId().equals(courseOrder.getUserId())) {
|
||||
throw new BusinessException(ErrorCode.NO_AUTH_ERROR, "你不是该订单用户!");
|
||||
}
|
||||
PrepayWithRequestPaymentResponse response = weChatService.createPayment(String.valueOf(orderId), miniOpenId, courseOrder.getTotalAmount());
|
||||
return ResultUtils.success(response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* JSAPI 下单回调
|
||||
*/
|
||||
@Hidden
|
||||
@PostMapping("/payment/callback")
|
||||
@Operation(summary = "JSAPI 下单回调", description = "参数:订单id, 权限:所有人, 方法名:callbackPayment")
|
||||
public synchronized BaseResponse<Boolean> callbackPayment(HttpServletRequest request) throws IOException {
|
||||
// 获取下单信息
|
||||
Transaction transaction = weChatService.getTransactionInfo(request);
|
||||
System.out.println("下单信息:" + transaction);
|
||||
// 支付回调
|
||||
boolean result = weChatService.paymentCallback(transaction);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "微信支付回调失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Web管理员部分退款
|
||||
* @param commonRequest 订单id
|
||||
*/
|
||||
@PostMapping("/refund/part/create")
|
||||
@Operation(summary = "Web管理员部分退款", description = "参数:订单id, 权限:web端管理员, 方法名:createPartRefund")
|
||||
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<Refund> createPartRefund(@Valid @RequestBody CommonRequest commonRequest) {
|
||||
Long orderId = commonRequest.getId();
|
||||
CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
ThrowUtils.throwIf(courseOrder == null, ErrorCode.OPERATION_ERROR, "订单不存在");
|
||||
|
||||
Refund refund = weChatService.refundPartPayment(String.valueOf(orderId), courseOrder.getTotalAmount());
|
||||
return ResultUtils.success(refund);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 部分退款回调
|
||||
*/
|
||||
@Hidden
|
||||
@PostMapping("/refund/part/callback")
|
||||
@Operation(summary = "部分退款回调", description = "参数:订单id, 权限:web端管理员, 方法名:callbackRefundPart")
|
||||
public BaseResponse<Boolean> callbackRefundPart(HttpServletRequest request) {
|
||||
// 获取退款信息
|
||||
RefundNotification refundNotification = weChatService.getRefundInfo(request);
|
||||
// 退款回调
|
||||
boolean result = weChatService.refundPartCallback(refundNotification);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "退款回调失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.greenorange.promotion.controller.wechat;
|
||||
//
|
||||
//import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
//import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
//import com.greenorange.promotion.annotation.RequiresPermission;
|
||||
//import com.greenorange.promotion.common.BaseResponse;
|
||||
//import com.greenorange.promotion.common.ErrorCode;
|
||||
//import com.greenorange.promotion.common.ResultUtils;
|
||||
//import com.greenorange.promotion.config.WxOpenConfig;
|
||||
//import com.greenorange.promotion.constant.OrderStatusConstant;
|
||||
//import com.greenorange.promotion.constant.UserConstant;
|
||||
//import com.greenorange.promotion.exception.BusinessException;
|
||||
//import com.greenorange.promotion.exception.ThrowUtils;
|
||||
//import com.greenorange.promotion.model.dto.CommonRequest;
|
||||
//import com.greenorange.promotion.model.dto.wxPay.WechatPayRequest;
|
||||
//import com.greenorange.promotion.model.entity.CourseOrder;
|
||||
//import com.greenorange.promotion.model.entity.UserInfo;
|
||||
//import com.greenorange.promotion.service.course.CourseOrderService;
|
||||
//import com.greenorange.promotion.service.userInfo.UserInfoService;
|
||||
//import com.greenorange.promotion.service.wechat.WechatPayService;
|
||||
//import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
//import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
//import com.wechat.pay.java.service.refund.model.Refund;
|
||||
//import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
//import io.swagger.v3.oas.annotations.Hidden;
|
||||
//import io.swagger.v3.oas.annotations.Operation;
|
||||
//import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import jakarta.servlet.http.HttpServletRequest;
|
||||
//import jakarta.validation.Valid;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import me.chanjar.weixin.common.error.WxErrorException;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestBody;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//@Slf4j
|
||||
//@RestController
|
||||
//@Tag(name = "微信支付")
|
||||
//@RequestMapping("/wxPay")
|
||||
//@Transactional
|
||||
//public class WechatPayController {
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private WechatPayService weChatService;
|
||||
//
|
||||
// @Resource
|
||||
// private UserInfoService userInfoService;
|
||||
//
|
||||
// @Resource
|
||||
// private CourseOrderService courseOrderService;
|
||||
//
|
||||
// @Resource
|
||||
// private WxOpenConfig wxOpenConfig;
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * JSAPI 下单
|
||||
// */
|
||||
// @PostMapping("/payment/create")
|
||||
// @Operation(summary = "JSAPI 下单", description = "参数:订单id, 权限:所有人, 方法名:createPayment")
|
||||
// @RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
|
||||
// public BaseResponse<PrepayWithRequestPaymentResponse> createPayment(@Valid @RequestBody WechatPayRequest wechatPayRequest, HttpServletRequest request) {
|
||||
//
|
||||
// String code = wechatPayRequest.getCode();
|
||||
// WxMaJscode2SessionResult sessionInfo;
|
||||
// String miniOpenId;
|
||||
// try {
|
||||
// WxMaService wxMaService = wxOpenConfig.getWxMaService();
|
||||
// sessionInfo = wxMaService.jsCode2SessionInfo(code);
|
||||
// miniOpenId = sessionInfo.getOpenid();
|
||||
// if (StringUtils.isAnyBlank(miniOpenId)) {
|
||||
// throw new BusinessException(ErrorCode.SYSTEM_ERROR);
|
||||
// }
|
||||
// } catch (WxErrorException e) {
|
||||
// log.error("userLoginByWxOpen error", e);
|
||||
// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败,系统错误");
|
||||
// }
|
||||
// Long userId = (Long) request.getAttribute("userId");
|
||||
// UserInfo userInfo = userInfoService.getById(userId);
|
||||
//
|
||||
// Long orderId = wechatPayRequest.getOrderId();
|
||||
// CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
// ThrowUtils.throwIf(courseOrder == null, ErrorCode.NOT_FOUND_ERROR, "订单不存在");
|
||||
// ThrowUtils.throwIf(!courseOrder.getOrderStatus().equals(OrderStatusConstant.PENDING), ErrorCode.OPERATION_ERROR, "订单状态错误");
|
||||
// if (!userInfo.getId().equals(courseOrder.getUserId())) {
|
||||
// throw new BusinessException(ErrorCode.NO_AUTH_ERROR, "你不是该订单用户!");
|
||||
// }
|
||||
// PrepayWithRequestPaymentResponse response = weChatService.createPayment(String.valueOf(orderId), miniOpenId, courseOrder.getTotalAmount());
|
||||
// return ResultUtils.success(response);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * JSAPI 下单回调
|
||||
// */
|
||||
// @Hidden
|
||||
// @PostMapping("/payment/callback")
|
||||
// @Operation(summary = "JSAPI 下单回调", description = "参数:订单id, 权限:所有人, 方法名:callbackPayment")
|
||||
// public synchronized BaseResponse<Boolean> callbackPayment(HttpServletRequest request) throws IOException {
|
||||
// // 获取下单信息
|
||||
// Transaction transaction = weChatService.getTransactionInfo(request);
|
||||
// System.out.println("下单信息:" + transaction);
|
||||
// // 支付回调
|
||||
// boolean result = weChatService.paymentCallback(transaction);
|
||||
// ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "微信支付回调失败");
|
||||
// return ResultUtils.success(true);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Web管理员部分退款
|
||||
// * @param commonRequest 订单id
|
||||
// */
|
||||
// @PostMapping("/refund/part/create")
|
||||
// @Operation(summary = "Web管理员部分退款", description = "参数:订单id, 权限:web端管理员, 方法名:createPartRefund")
|
||||
// @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
|
||||
// public BaseResponse<Refund> createPartRefund(@Valid @RequestBody CommonRequest commonRequest) {
|
||||
// Long orderId = commonRequest.getId();
|
||||
// CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
// ThrowUtils.throwIf(courseOrder == null, ErrorCode.OPERATION_ERROR, "订单不存在");
|
||||
//
|
||||
// Refund refund = weChatService.refundPartPayment(String.valueOf(orderId), courseOrder.getTotalAmount());
|
||||
// return ResultUtils.success(refund);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 部分退款回调
|
||||
// */
|
||||
// @Hidden
|
||||
// @PostMapping("/refund/part/callback")
|
||||
// @Operation(summary = "部分退款回调", description = "参数:订单id, 权限:web端管理员, 方法名:callbackRefundPart")
|
||||
// public BaseResponse<Boolean> callbackRefundPart(HttpServletRequest request) {
|
||||
// // 获取退款信息
|
||||
// RefundNotification refundNotification = weChatService.getRefundInfo(request);
|
||||
// // 退款回调
|
||||
// boolean result = weChatService.refundPartCallback(refundNotification);
|
||||
// ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "退款回调失败");
|
||||
// return ResultUtils.success(true);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.greenorange.promotion.model.dto.userInfo;
|
||||
|
||||
import com.greenorange.promotion.annotation.EnumValue;
|
||||
import com.greenorange.promotion.model.enums.UserRoleEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 验证码发送请求体
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "验证码发送请求体", requiredProperties = {"phoneNumber", "userRole"})
|
||||
public class VerificationCodeGetRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@Schema(description = "手机号", example = "15888610253")
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* 权限
|
||||
*/
|
||||
@NotBlank(message = "权限不能为空")
|
||||
@EnumValue(enumClass = UserRoleEnum.class)
|
||||
@Schema(description = "权限", example = "user")
|
||||
private String userRole;
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -58,13 +58,13 @@ public interface UserInfoService extends IService<UserInfo> {
|
||||
/**
|
||||
* 小程序用户获取验证码(用于密码登录和忘记密码)
|
||||
*/
|
||||
String getVerificationCodeForPwdLogin(String phoneNumber);
|
||||
String getVerificationCodeForPwdLogin(VerificationCodeGetRequest verificationCodeGetRequest);
|
||||
|
||||
|
||||
/**
|
||||
* 小程序用户获取验证码(用于注册)
|
||||
*/
|
||||
String getVerificationCodeForRegister(String phoneNumber);
|
||||
String getVerificationCodeForRegister(VerificationCodeGetRequest verificationCodeGetRequest);
|
||||
|
||||
|
||||
/**
|
||||
@ -101,4 +101,6 @@ public interface UserInfoService extends IService<UserInfo> {
|
||||
* 查询当前用户的所有下级用户(包括间接)
|
||||
*/
|
||||
List<Long> findAllSubUser(Long userId);
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.greenorange.promotion.common.ErrorCode;
|
||||
import com.greenorange.promotion.config.WxOpenConfig;
|
||||
import com.greenorange.promotion.constant.CommonConstant;
|
||||
import com.greenorange.promotion.constant.SystemConstant;
|
||||
import com.greenorange.promotion.constant.UserConstant;
|
||||
@ -162,12 +161,20 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void userInfoMiniRegister(UserInfoRegisterRequest userInfoRegisterRequest) {
|
||||
String nickName = userInfoRegisterRequest.getNickName();
|
||||
String phoneNumber = userInfoRegisterRequest.getPhoneNumber();
|
||||
String verificationCode = userInfoRegisterRequest.getVerificationCode();
|
||||
String userRole = userInfoRegisterRequest.getUserRole();
|
||||
UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
|
||||
// 校验用户手机号和验证码
|
||||
checkPhoneAndVerificationCode(phoneNumber, verificationCode, userRoleEnum);
|
||||
// 如果注册主管,校验昵称是否重复
|
||||
if (UserRoleEnum.SUPERVISOR.equals(userRoleEnum)) {
|
||||
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserInfo::getNickName, nickName).eq(UserInfo::getUserRole, UserConstant.SUPERVISOR_ROLE);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo != null, ErrorCode.OPERATION_ERROR, "昵称已存在");
|
||||
}
|
||||
|
||||
// 根据邀请码获得上级用户信息
|
||||
String invitationCode = userInfoRegisterRequest.getInvitationCode();
|
||||
@ -220,15 +227,26 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phoneNumber), ErrorCode.PARAMS_ERROR, "手机号格式无效");
|
||||
String userPassword = userInfoMiniPasswordLoginRequest.getUserPassword();
|
||||
String userRole = userInfoMiniPasswordLoginRequest.getUserRole();
|
||||
UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
|
||||
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
|
||||
lambdaQueryWrapper.eq(UserInfo::getUserRole, userRole);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
|
||||
if (UserRoleEnum.USER.equals(userRoleEnum)) {
|
||||
lambdaQueryWrapper.eq(UserInfo::getUserRole, userRole);
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
|
||||
} else {
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
|
||||
lambdaQueryWrapper.in(UserInfo::getUserRole, UserRoleEnum.STAFF.getValue(), UserRoleEnum.SUPERVISOR.getValue(), UserRoleEnum.MANAGER.getValue());
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
|
||||
UserRoleEnum currentUserRoleEnum = UserRoleEnum.getEnumByValue(userInfo.getUserRole());
|
||||
ThrowUtils.throwIf(!userRoleEnum.equals(currentUserRoleEnum), ErrorCode.OPERATION_ERROR, "该手机号为" + currentUserRoleEnum.getText() + "账号");
|
||||
}
|
||||
lambdaQueryWrapper.eq(UserInfo::getUserPassword, userPassword);
|
||||
userInfo = this.getOne(lambdaQueryWrapper);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "密码不正确");
|
||||
|
||||
|
||||
Map<String, String> payload = new HashMap<>();
|
||||
payload.put("userAccount", phoneNumber);
|
||||
payload.put("userPassword", userPassword);
|
||||
@ -301,12 +319,14 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
* 小程序用户获取验证码(用于密码登录和忘记密码)
|
||||
*/
|
||||
@Override
|
||||
public String getVerificationCodeForPwdLogin(String phoneNumber) {
|
||||
public String getVerificationCodeForPwdLogin(VerificationCodeGetRequest verificationCodeGetRequest) {
|
||||
String phoneNumber = verificationCodeGetRequest.getPhoneNumber();
|
||||
String userRole = verificationCodeGetRequest.getUserRole();
|
||||
ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phoneNumber), ErrorCode.PARAMS_ERROR, "手机号格式错误");
|
||||
|
||||
// 判断手机号是否已注册
|
||||
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber).eq(UserInfo::getUserRole, userRole);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
|
||||
|
||||
@ -321,11 +341,19 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
* 小程序用户获取验证码(用于注册)
|
||||
*/
|
||||
@Override
|
||||
public String getVerificationCodeForRegister(String phoneNumber) {
|
||||
public String getVerificationCodeForRegister(VerificationCodeGetRequest verificationCodeGetRequest) {
|
||||
String phoneNumber = verificationCodeGetRequest.getPhoneNumber();
|
||||
String userRole = verificationCodeGetRequest.getUserRole();
|
||||
ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phoneNumber), ErrorCode.PARAMS_ERROR, "手机号格式错误");
|
||||
|
||||
// 判断手机号是否已注册
|
||||
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
|
||||
if (userRoleEnum == UserRoleEnum.USER) {
|
||||
lambdaQueryWrapper.eq(UserInfo::getUserRole, UserConstant.DEFAULT_ROLE);
|
||||
} else {
|
||||
lambdaQueryWrapper.in(UserInfo::getUserRole, UserConstant.STAFF_ROLE, UserConstant.SUPERVISOR_ROLE, UserConstant.MANAGER_ROLE);
|
||||
}
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo != null, ErrorCode.OPERATION_ERROR, "手机号已注册");
|
||||
@ -337,6 +365,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 校验用户手机号和验证码
|
||||
*/
|
||||
@ -348,7 +377,11 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
phoneNumberLambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
|
||||
phoneNumberLambdaQueryWrapper = getQueryWrapperByUserRole(userRoleEnum, phoneNumberLambdaQueryWrapper);
|
||||
UserInfo userInfo = this.getOne(phoneNumberLambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo != null, ErrorCode.OPERATION_ERROR, "手机号已注册");
|
||||
if (userInfo != null) {
|
||||
String userRole = userInfo.getUserRole();
|
||||
UserRoleEnum currentUserRoleEnum = UserRoleEnum.getEnumByValue(userRole);
|
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "该手机号为"+ currentUserRoleEnum.getText() +"账号");
|
||||
}
|
||||
}
|
||||
String code = redisTemplate.opsForValue().get(SystemConstant.VERIFICATION_CODE + ":" + verificationCode);
|
||||
ThrowUtils.throwIf(code == null, ErrorCode.OPERATION_ERROR, "验证码已失效");
|
||||
@ -382,6 +415,11 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
AdvancementApply advancementApply = advancementApplyService.getById(applyId);
|
||||
String phoneNumber = advancementApply.getPhone();
|
||||
ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phoneNumber), ErrorCode.PARAMS_ERROR, "手机号格式无效");
|
||||
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber)
|
||||
.in(UserInfo::getUserRole, UserConstant.STAFF_ROLE, UserConstant.SUPERVISOR_ROLE, UserConstant.MANAGER_ROLE);
|
||||
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
|
||||
ThrowUtils.throwIf(userInfo != null, ErrorCode.OPERATION_ERROR, "手机号已注册");
|
||||
|
||||
// 根据邀请码获得上级用户信息
|
||||
Long userId = advancementApplyApproveRequest.getUserId();
|
||||
@ -408,7 +446,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
|
||||
// 生成邀请二维码
|
||||
String invitationQrcode = generateInvitationQrcode(myUserInfo.getInvitationCode(), UserRoleEnum.STAFF);
|
||||
UserMainInfo userMainInfo = UserMainInfo.builder().userId(userId).inviteQrCode(invitationQrcode).build();
|
||||
UserMainInfo userMainInfo = UserMainInfo.builder().userId(myUserInfo.getId()).inviteQrCode(invitationQrcode).build();
|
||||
userMainInfoService.save(userMainInfo);
|
||||
|
||||
// // 批量保存当前用户的项目明细抽佣记录和下级用户项目明细抽佣记录
|
||||
@ -568,6 +606,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,8 +120,7 @@ public class WechatGetQrcodeServiceImpl implements WechatGetQrcodeService {
|
||||
param.put("page", "pages/loginModule/register/register");
|
||||
param.put("scene", inviteCode + "=" + userRoleEnum.getValue());
|
||||
param.put("width", 430);
|
||||
param.put("check_path", false);
|
||||
param.put("env_version", "develop");
|
||||
param.put("env_version", "release");
|
||||
String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken;
|
||||
String jsonParams = JSONUtil.toJsonStr(param);
|
||||
byte[] responseBytes = HttpUtil.createPost(url)
|
||||
|
@ -1,368 +1,367 @@
|
||||
package com.greenorange.promotion.service.wechat.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.greenorange.promotion.common.ErrorCode;
|
||||
import com.greenorange.promotion.config.WxPayConfig;
|
||||
import com.greenorange.promotion.constant.OrderStatusConstant;
|
||||
import com.greenorange.promotion.constant.SystemConstant;
|
||||
import com.greenorange.promotion.exception.ThrowUtils;
|
||||
import com.greenorange.promotion.model.entity.*;
|
||||
import com.greenorange.promotion.model.enums.CommissionStatusEnum;
|
||||
import com.greenorange.promotion.service.common.CommonService;
|
||||
import com.greenorange.promotion.service.course.CourseOrderService;
|
||||
import com.greenorange.promotion.service.course.CoursePromotionCommissionPendingService;
|
||||
import com.greenorange.promotion.service.course.CourseService;
|
||||
import com.greenorange.promotion.service.refund.RefundRecordService;
|
||||
import com.greenorange.promotion.service.userInfo.UserInfoService;
|
||||
import com.greenorange.promotion.service.userInfo.UserPerformanceSummaryService;
|
||||
import com.greenorange.promotion.service.wechat.WechatPayService;
|
||||
import com.greenorange.promotion.utils.RefundUtils;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RequestParam;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||
import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||
import com.wechat.pay.java.service.refund.model.Refund;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author 陈新知
|
||||
*/
|
||||
@Service
|
||||
public class WechatPayServiceImpl implements WechatPayService {
|
||||
|
||||
|
||||
@Resource
|
||||
private WxPayConfig wxPayConfig;
|
||||
|
||||
|
||||
@Resource
|
||||
private CourseOrderService courseOrderService;
|
||||
|
||||
|
||||
@Resource
|
||||
private CourseService courseService;
|
||||
|
||||
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
|
||||
@Resource
|
||||
private RefundRecordService refundRecordService;
|
||||
|
||||
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
|
||||
@Resource
|
||||
private UserPerformanceSummaryService userPerformanceSummaryService;
|
||||
|
||||
|
||||
@Resource
|
||||
private CoursePromotionCommissionPendingService coursePromotionCommissionPendingService;
|
||||
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
public static RequestParam requestParam = null;
|
||||
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*/
|
||||
@Override
|
||||
public PrepayWithRequestPaymentResponse createPayment(String orderId, String miniOpenId, BigDecimal amount) {
|
||||
// request.setXxx(val)设置所需参数,具体参数可见Request定义
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
// 金额
|
||||
Amount WxAmount = new Amount();
|
||||
WxAmount.setTotal(amount.movePointRight(2).intValue());
|
||||
WxAmount.setCurrency("CNY");
|
||||
request.setAmount(WxAmount);
|
||||
// 公众号id
|
||||
request.setAppid(wxPayConfig.getAppId());
|
||||
// 商户号
|
||||
request.setMchid(wxPayConfig.getMerchantId());
|
||||
// 支付者信息
|
||||
Payer payer = new Payer();
|
||||
payer.setOpenid(miniOpenId);
|
||||
request.setPayer(payer);
|
||||
// 获取订单号
|
||||
CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
String orderNumber = courseOrder.getOrderNumber();
|
||||
// 描述
|
||||
request.setDescription("订单号:" + orderNumber);
|
||||
// 微信回调地址
|
||||
request.setNotifyUrl(wxPayConfig.getNotifyUrl() + "/wxPay/payment/callback");
|
||||
// 商户订单号
|
||||
request.setOutTradeNo(orderNumber);
|
||||
//返回数据,前端调起支付
|
||||
return wxPayConfig.getJsapiServiceExtension().prepayWithRequestPayment(request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付回调
|
||||
*/
|
||||
@Override
|
||||
public boolean paymentCallback(Transaction transaction) throws IOException {
|
||||
System.out.println("---------------------------微信支付回调(开始)-------------------------------");
|
||||
// 获取订单信息
|
||||
String orderNumber = transaction.getOutTradeNo();
|
||||
LambdaQueryWrapper<CourseOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CourseOrder::getOrderNumber, orderNumber);
|
||||
CourseOrder courseOrder = courseOrderService.getOne(queryWrapper);
|
||||
|
||||
// 修改订单状态
|
||||
LambdaUpdateWrapper<CourseOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(CourseOrder::getId, courseOrder.getId())
|
||||
.set(CourseOrder::getOrderStatus, OrderStatusConstant.SUCCESS);
|
||||
courseOrderService.update(updateWrapper);
|
||||
|
||||
// 修改当前课程下单人数
|
||||
Long courseId = courseOrder.getCourseId();
|
||||
Course course = courseService.getById(courseId);
|
||||
if (course != null) {
|
||||
course.setOrderCount(course.getOrderCount() + 1);
|
||||
courseService.updateById(course);
|
||||
}
|
||||
|
||||
// 更新主管和员工的绩效记录
|
||||
Long userId = courseOrder.getUserId();
|
||||
List<Long> pathToRoot = userInfoService.findPathToRoot(userId);
|
||||
List<Long> superUserIdList = pathToRoot.subList(1, 3);
|
||||
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(superUserIdList, userPerformanceSummaryService, Function.identity(), UserPerformanceSummary::getUserId);
|
||||
BigDecimal rate;
|
||||
Map<String, BigDecimal> rateMap = userPerformanceSummaryService.queryRakeRewardsRate();
|
||||
for (int i = 0; i < userPerformanceSummaryList.size(); i ++ ) {
|
||||
if (i == 0) rate = rateMap.get("first");
|
||||
else rate = rateMap.get("second");
|
||||
// 计算理论上获得的最大提成奖励
|
||||
BigDecimal rakeRewards = courseOrder.getTotalAmount().multiply(rate);
|
||||
UserPerformanceSummary userPerformanceSummary = userPerformanceSummaryList.get(i);
|
||||
|
||||
userPerformanceSummary.setTotalAmount(userPerformanceSummary.getTotalAmount().add(courseOrder.getTotalAmount()));
|
||||
userPerformanceSummary.setNetAmount(userPerformanceSummary.getNetAmount().add(courseOrder.getTotalAmount().multiply(SystemConstant.FEE_RATE)));
|
||||
userPerformanceSummary.setOrderCount(userPerformanceSummary.getOrderCount() + 1);
|
||||
userPerformanceSummary.setToRelease(userPerformanceSummary.getToRelease().add(rakeRewards.multiply(SystemConstant.REFUND_RATE)));
|
||||
userPerformanceSummary.setToSettle(userPerformanceSummary.getToSettle().add(rakeRewards.multiply(SystemConstant.FEE_RATE)));
|
||||
}
|
||||
userPerformanceSummaryService.updateBatchById(userPerformanceSummaryList);
|
||||
|
||||
|
||||
// 添加课程推广待提成记录
|
||||
Long firstUserId = pathToRoot.get(0);
|
||||
Long secondUserId = pathToRoot.get(1);
|
||||
CoursePromotionCommissionPending coursePromotionCommissionPending = CoursePromotionCommissionPending.builder()
|
||||
.firstUserId(firstUserId)
|
||||
.secondUserId(secondUserId)
|
||||
.courseId(courseId)
|
||||
.name(courseOrder.getName())
|
||||
.type(courseOrder.getType())
|
||||
.image(courseOrder.getImage())
|
||||
.orderId(courseOrder.getId())
|
||||
.userId(userId)
|
||||
.firstRate(rateMap.get("first"))
|
||||
.secondRate(rateMap.get("second"))
|
||||
.firstReward(courseOrder.getTotalAmount().multiply(rateMap.get("first")))
|
||||
.secondReward(courseOrder.getTotalAmount().multiply(rateMap.get("second")))
|
||||
.totalAmount(courseOrder.getTotalAmount())
|
||||
.commissionStatus(CommissionStatusEnum.PENDING.getValue())
|
||||
.orderCreateTime(courseOrder.getCreateTime())
|
||||
.build();
|
||||
coursePromotionCommissionPendingService.save(coursePromotionCommissionPending);
|
||||
|
||||
|
||||
System.out.println("---------------------------微信支付回调(结束)-------------------------------");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 部分退款申请
|
||||
*/
|
||||
@Override
|
||||
public Refund refundPartPayment(String orderId, BigDecimal refundAmount) {
|
||||
// 获取订单
|
||||
CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
ThrowUtils.throwIf(courseOrder == null, ErrorCode.OPERATION_ERROR, "订单不存在");
|
||||
// 判断该订单是否已经退款
|
||||
ThrowUtils.throwIf(courseOrder.getOrderStatus().equals(OrderStatusConstant.REFUNDED), ErrorCode.OPERATION_ERROR, "订单已退款");
|
||||
|
||||
String orderNumber = courseOrder.getOrderNumber();
|
||||
// 退款请求
|
||||
CreateRequest createRequest = new CreateRequest();
|
||||
// 商户订单号
|
||||
createRequest.setOutTradeNo(orderNumber);
|
||||
// 商户退款单号
|
||||
String outRefundNo = RefundUtils.generateRefundNo();
|
||||
createRequest.setOutRefundNo(outRefundNo);
|
||||
// 退款结果回调
|
||||
createRequest.setNotifyUrl(wxPayConfig.getNotifyUrl() + "/wxPay/refund/part/callback");
|
||||
// 退款金额
|
||||
AmountReq amountReq = new AmountReq();
|
||||
|
||||
amountReq.setRefund(refundAmount.movePointRight(2).longValue());
|
||||
amountReq.setTotal(courseOrder.getTotalAmount().movePointRight(2).longValue());
|
||||
amountReq.setCurrency("CNY");
|
||||
createRequest.setAmount(amountReq);
|
||||
|
||||
// // 生成退款记录
|
||||
// Course course = courseService.getById(courseOrder.getCourseId());
|
||||
// RefundRecord refundRecord = commonService.copyProperties(course, RefundRecord.class);
|
||||
// refundRecord.setId(null);
|
||||
// refundRecord.setOutTradeNo(orderNumber);
|
||||
// refundRecord.setOutRefundNo(outRefundNo);
|
||||
// refundRecord.setTotalAmount(courseOrder.getTotalAmount().movePointRight(2));
|
||||
// refundRecord.setRefundAmount(refundAmount.movePointRight(2));
|
||||
// refundRecord.setUserId(courseOrder.getUserId());
|
||||
// refundRecord.setCreateTime(null);
|
||||
// refundRecord.setUpdateTime(null);
|
||||
// refundRecordService.save(refundRecord);
|
||||
|
||||
// 申请退款
|
||||
System.out.println("退款请求:" + createRequest);
|
||||
Refund refund = wxPayConfig.getRefundService().create(createRequest);
|
||||
System.out.println("退款申请结果:" + refund);
|
||||
|
||||
return refund;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 部分退款回调
|
||||
*/
|
||||
@Override
|
||||
public boolean refundPartCallback(RefundNotification refundNotification) {
|
||||
System.out.println("---------------------------微信退款回调(开始)-------------------------------");
|
||||
// 获取订单信息
|
||||
String orderNumber = refundNotification.getOutTradeNo();
|
||||
LambdaQueryWrapper<CourseOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CourseOrder::getOrderNumber, orderNumber);
|
||||
CourseOrder courseOrder = courseOrderService.getOne(queryWrapper);
|
||||
|
||||
// 修改订单状态
|
||||
LambdaUpdateWrapper<CourseOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(CourseOrder::getId, courseOrder.getId())
|
||||
.set(CourseOrder::getOrderStatus, OrderStatusConstant.REFUNDED);
|
||||
courseOrderService.update(updateWrapper);
|
||||
|
||||
// 修改课程下单人数
|
||||
Long courseId = courseOrder.getCourseId();
|
||||
Course course = courseService.getById(courseId);
|
||||
if (course != null) {
|
||||
course.setOrderCount(course.getOrderCount() - 1);
|
||||
courseService.updateById(course);
|
||||
}
|
||||
|
||||
// 更新主管和员工的绩效记录
|
||||
Long userId = courseOrder.getUserId();
|
||||
List<Long> pathToRoot = userInfoService.findPathToRoot(userId);
|
||||
List<Long> superUserIdList = pathToRoot.subList(1, 3);
|
||||
List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(superUserIdList, userPerformanceSummaryService, Function.identity(), UserPerformanceSummary::getUserId);
|
||||
BigDecimal rate;
|
||||
LambdaQueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new LambdaQueryWrapper<>();
|
||||
coursePromotionQueryWrapper.eq(CoursePromotionCommissionPending::getOrderId, courseOrder.getId());
|
||||
CoursePromotionCommissionPending coursePromotionCommissionPending = coursePromotionCommissionPendingService.getOne(coursePromotionQueryWrapper);
|
||||
for (int i = 0; i < userPerformanceSummaryList.size(); i ++ ) {
|
||||
if (i == 0) rate = coursePromotionCommissionPending.getFirstRate();
|
||||
else rate = coursePromotionCommissionPending.getSecondRate();
|
||||
// 计算理论上获得的最大提成奖励
|
||||
BigDecimal rakeRewards = courseOrder.getTotalAmount().multiply(rate);
|
||||
UserPerformanceSummary userPerformanceSummary = userPerformanceSummaryList.get(i);
|
||||
|
||||
userPerformanceSummary.setTotalAmount(userPerformanceSummary.getTotalAmount().subtract(courseOrder.getTotalAmount()));
|
||||
userPerformanceSummary.setNetAmount(userPerformanceSummary.getNetAmount().subtract(courseOrder.getTotalAmount().multiply(SystemConstant.FEE_RATE)));
|
||||
userPerformanceSummary.setToRelease(userPerformanceSummary.getToRelease().subtract(rakeRewards.multiply(SystemConstant.REFUND_RATE)));
|
||||
userPerformanceSummary.setRefunded(userPerformanceSummary.getRefunded().add(courseOrder.getTotalAmount().multiply(SystemConstant.REFUND_RATE)));
|
||||
}
|
||||
userPerformanceSummaryService.updateBatchById(userPerformanceSummaryList);
|
||||
|
||||
// 修改课程推广待提成状态为"已失效"
|
||||
LambdaUpdateWrapper<CoursePromotionCommissionPending> coursePromotionUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
coursePromotionUpdateWrapper.eq(CoursePromotionCommissionPending::getOrderId, courseOrder.getId())
|
||||
.set(CoursePromotionCommissionPending::getCommissionStatus, CommissionStatusEnum.EXPIRED.getValue());
|
||||
coursePromotionCommissionPendingService.update(coursePromotionUpdateWrapper);
|
||||
|
||||
System.out.println("---------------------------微信退款回调(结束)-------------------------------");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取支付回调信息
|
||||
*/
|
||||
@Override
|
||||
public Transaction getTransactionInfo(HttpServletRequest request) {
|
||||
NotificationParser notificationParser = getNotificationParser(request);
|
||||
return notificationParser.parse(requestParam, Transaction.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取退款回调信息
|
||||
*/
|
||||
@Override
|
||||
public RefundNotification getRefundInfo(HttpServletRequest request) {
|
||||
NotificationParser notificationParser = getNotificationParser(request);
|
||||
return notificationParser.parse(requestParam, RefundNotification.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据微信官方发送的请求获取信息
|
||||
*/
|
||||
@SneakyThrows
|
||||
public NotificationParser getNotificationParser(HttpServletRequest request) {
|
||||
System.out.println("---------------------------获取信息-------------------------------");
|
||||
// 获取RSA配置
|
||||
NotificationParser notificationParser = new NotificationParser(wxPayConfig.getRSAConfig());
|
||||
// 构建请求
|
||||
StringBuilder bodyBuilder = new StringBuilder();
|
||||
BufferedReader reader = request.getReader();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
bodyBuilder.append(line);
|
||||
}
|
||||
String body = bodyBuilder.toString();
|
||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
String nonce = request.getHeader("Wechatpay-Nonce");
|
||||
String signature = request.getHeader("Wechatpay-Signature");
|
||||
String singType = request.getHeader("Wechatpay-Signature-Type");
|
||||
String wechatPayCertificateSerialNumber = request.getHeader("Wechatpay-Serial");
|
||||
requestParam = new RequestParam.Builder()
|
||||
.serialNumber(wechatPayCertificateSerialNumber)
|
||||
.nonce(nonce)
|
||||
.signature(signature)
|
||||
.timestamp(timestamp)
|
||||
.signType(singType)
|
||||
.body(body)
|
||||
.build();
|
||||
System.out.println(requestParam.toString());
|
||||
System.out.println("---------------------------信息获取完毕-------------------------------");
|
||||
return notificationParser;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.greenorange.promotion.service.wechat.impl;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
//import com.greenorange.promotion.common.ErrorCode;
|
||||
//import com.greenorange.promotion.constant.OrderStatusConstant;
|
||||
//import com.greenorange.promotion.constant.SystemConstant;
|
||||
//import com.greenorange.promotion.exception.ThrowUtils;
|
||||
//import com.greenorange.promotion.model.entity.*;
|
||||
//import com.greenorange.promotion.model.enums.CommissionStatusEnum;
|
||||
//import com.greenorange.promotion.service.common.CommonService;
|
||||
//import com.greenorange.promotion.service.course.CourseOrderService;
|
||||
//import com.greenorange.promotion.service.course.CoursePromotionCommissionPendingService;
|
||||
//import com.greenorange.promotion.service.course.CourseService;
|
||||
//import com.greenorange.promotion.service.refund.RefundRecordService;
|
||||
//import com.greenorange.promotion.service.userInfo.UserInfoService;
|
||||
//import com.greenorange.promotion.service.userInfo.UserPerformanceSummaryService;
|
||||
//import com.greenorange.promotion.service.wechat.WechatPayService;
|
||||
//import com.greenorange.promotion.utils.RefundUtils;
|
||||
//import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
//import com.wechat.pay.java.core.notification.RequestParam;
|
||||
//import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
//import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||
//import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||
//import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
//import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
//import com.wechat.pay.java.service.refund.model.AmountReq;
|
||||
//import com.wechat.pay.java.service.refund.model.CreateRequest;
|
||||
//import com.wechat.pay.java.service.refund.model.Refund;
|
||||
//import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import jakarta.servlet.http.HttpServletRequest;
|
||||
//import lombok.SneakyThrows;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.function.Function;
|
||||
//
|
||||
///**
|
||||
// * @author 陈新知
|
||||
// */
|
||||
//@Service
|
||||
//public class WechatPayServiceImpl implements WechatPayService {
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private WxPayConfig wxPayConfig;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private CourseOrderService courseOrderService;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private CourseService courseService;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private CommonService commonService;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private RefundRecordService refundRecordService;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private UserInfoService userInfoService;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private UserPerformanceSummaryService userPerformanceSummaryService;
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private CoursePromotionCommissionPendingService coursePromotionCommissionPendingService;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 请求参数
|
||||
// */
|
||||
// public static RequestParam requestParam = null;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 微信支付
|
||||
// */
|
||||
// @Override
|
||||
// public PrepayWithRequestPaymentResponse createPayment(String orderId, String miniOpenId, BigDecimal amount) {
|
||||
// // request.setXxx(val)设置所需参数,具体参数可见Request定义
|
||||
// PrepayRequest request = new PrepayRequest();
|
||||
// // 金额
|
||||
// Amount WxAmount = new Amount();
|
||||
// WxAmount.setTotal(amount.movePointRight(2).intValue());
|
||||
// WxAmount.setCurrency("CNY");
|
||||
// request.setAmount(WxAmount);
|
||||
// // 公众号id
|
||||
// request.setAppid(wxPayConfig.getAppId());
|
||||
// // 商户号
|
||||
// request.setMchid(wxPayConfig.getMerchantId());
|
||||
// // 支付者信息
|
||||
// Payer payer = new Payer();
|
||||
// payer.setOpenid(miniOpenId);
|
||||
// request.setPayer(payer);
|
||||
// // 获取订单号
|
||||
// CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
// String orderNumber = courseOrder.getOrderNumber();
|
||||
// // 描述
|
||||
// request.setDescription("订单号:" + orderNumber);
|
||||
// // 微信回调地址
|
||||
// request.setNotifyUrl(wxPayConfig.getNotifyUrl() + "/wxPay/payment/callback");
|
||||
// // 商户订单号
|
||||
// request.setOutTradeNo(orderNumber);
|
||||
// //返回数据,前端调起支付
|
||||
// return wxPayConfig.getJsapiServiceExtension().prepayWithRequestPayment(request);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 支付回调
|
||||
// */
|
||||
// @Override
|
||||
// public boolean paymentCallback(Transaction transaction) throws IOException {
|
||||
// System.out.println("---------------------------微信支付回调(开始)-------------------------------");
|
||||
// // 获取订单信息
|
||||
// String orderNumber = transaction.getOutTradeNo();
|
||||
// LambdaQueryWrapper<CourseOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(CourseOrder::getOrderNumber, orderNumber);
|
||||
// CourseOrder courseOrder = courseOrderService.getOne(queryWrapper);
|
||||
//
|
||||
// // 修改订单状态
|
||||
// LambdaUpdateWrapper<CourseOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
// updateWrapper.eq(CourseOrder::getId, courseOrder.getId())
|
||||
// .set(CourseOrder::getOrderStatus, OrderStatusConstant.SUCCESS);
|
||||
// courseOrderService.update(updateWrapper);
|
||||
//
|
||||
// // 修改当前课程下单人数
|
||||
// Long courseId = courseOrder.getCourseId();
|
||||
// Course course = courseService.getById(courseId);
|
||||
// if (course != null) {
|
||||
// course.setOrderCount(course.getOrderCount() + 1);
|
||||
// courseService.updateById(course);
|
||||
// }
|
||||
//
|
||||
// // 更新主管和员工的绩效记录
|
||||
// Long userId = courseOrder.getUserId();
|
||||
// List<Long> pathToRoot = userInfoService.findPathToRoot(userId);
|
||||
// List<Long> superUserIdList = pathToRoot.subList(1, 3);
|
||||
// List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(superUserIdList, userPerformanceSummaryService, Function.identity(), UserPerformanceSummary::getUserId);
|
||||
// BigDecimal rate;
|
||||
// Map<String, BigDecimal> rateMap = userPerformanceSummaryService.queryRakeRewardsRate();
|
||||
// for (int i = 0; i < userPerformanceSummaryList.size(); i ++ ) {
|
||||
// if (i == 0) rate = rateMap.get("first");
|
||||
// else rate = rateMap.get("second");
|
||||
// // 计算理论上获得的最大提成奖励
|
||||
// BigDecimal rakeRewards = courseOrder.getTotalAmount().multiply(rate);
|
||||
// UserPerformanceSummary userPerformanceSummary = userPerformanceSummaryList.get(i);
|
||||
//
|
||||
// userPerformanceSummary.setTotalAmount(userPerformanceSummary.getTotalAmount().add(courseOrder.getTotalAmount()));
|
||||
// userPerformanceSummary.setNetAmount(userPerformanceSummary.getNetAmount().add(courseOrder.getTotalAmount().multiply(SystemConstant.FEE_RATE)));
|
||||
// userPerformanceSummary.setOrderCount(userPerformanceSummary.getOrderCount() + 1);
|
||||
// userPerformanceSummary.setToRelease(userPerformanceSummary.getToRelease().add(rakeRewards.multiply(SystemConstant.REFUND_RATE)));
|
||||
// userPerformanceSummary.setToSettle(userPerformanceSummary.getToSettle().add(rakeRewards.multiply(SystemConstant.FEE_RATE)));
|
||||
// }
|
||||
// userPerformanceSummaryService.updateBatchById(userPerformanceSummaryList);
|
||||
//
|
||||
//
|
||||
// // 添加课程推广待提成记录
|
||||
// Long firstUserId = pathToRoot.get(0);
|
||||
// Long secondUserId = pathToRoot.get(1);
|
||||
// CoursePromotionCommissionPending coursePromotionCommissionPending = CoursePromotionCommissionPending.builder()
|
||||
// .firstUserId(firstUserId)
|
||||
// .secondUserId(secondUserId)
|
||||
// .courseId(courseId)
|
||||
// .name(courseOrder.getName())
|
||||
// .type(courseOrder.getType())
|
||||
// .image(courseOrder.getImage())
|
||||
// .orderId(courseOrder.getId())
|
||||
// .userId(userId)
|
||||
// .firstRate(rateMap.get("first"))
|
||||
// .secondRate(rateMap.get("second"))
|
||||
// .firstReward(courseOrder.getTotalAmount().multiply(rateMap.get("first")))
|
||||
// .secondReward(courseOrder.getTotalAmount().multiply(rateMap.get("second")))
|
||||
// .totalAmount(courseOrder.getTotalAmount())
|
||||
// .commissionStatus(CommissionStatusEnum.PENDING.getValue())
|
||||
// .orderCreateTime(courseOrder.getCreateTime())
|
||||
// .build();
|
||||
// coursePromotionCommissionPendingService.save(coursePromotionCommissionPending);
|
||||
//
|
||||
//
|
||||
// System.out.println("---------------------------微信支付回调(结束)-------------------------------");
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 部分退款申请
|
||||
// */
|
||||
// @Override
|
||||
// public Refund refundPartPayment(String orderId, BigDecimal refundAmount) {
|
||||
// // 获取订单
|
||||
// CourseOrder courseOrder = courseOrderService.getById(orderId);
|
||||
// ThrowUtils.throwIf(courseOrder == null, ErrorCode.OPERATION_ERROR, "订单不存在");
|
||||
// // 判断该订单是否已经退款
|
||||
// ThrowUtils.throwIf(courseOrder.getOrderStatus().equals(OrderStatusConstant.REFUNDED), ErrorCode.OPERATION_ERROR, "订单已退款");
|
||||
//
|
||||
// String orderNumber = courseOrder.getOrderNumber();
|
||||
// // 退款请求
|
||||
// CreateRequest createRequest = new CreateRequest();
|
||||
// // 商户订单号
|
||||
// createRequest.setOutTradeNo(orderNumber);
|
||||
// // 商户退款单号
|
||||
// String outRefundNo = RefundUtils.generateRefundNo();
|
||||
// createRequest.setOutRefundNo(outRefundNo);
|
||||
// // 退款结果回调
|
||||
// createRequest.setNotifyUrl(wxPayConfig.getNotifyUrl() + "/wxPay/refund/part/callback");
|
||||
// // 退款金额
|
||||
// AmountReq amountReq = new AmountReq();
|
||||
//
|
||||
// amountReq.setRefund(refundAmount.movePointRight(2).longValue());
|
||||
// amountReq.setTotal(courseOrder.getTotalAmount().movePointRight(2).longValue());
|
||||
// amountReq.setCurrency("CNY");
|
||||
// createRequest.setAmount(amountReq);
|
||||
//
|
||||
//// // 生成退款记录
|
||||
//// Course course = courseService.getById(courseOrder.getCourseId());
|
||||
//// RefundRecord refundRecord = commonService.copyProperties(course, RefundRecord.class);
|
||||
//// refundRecord.setId(null);
|
||||
//// refundRecord.setOutTradeNo(orderNumber);
|
||||
//// refundRecord.setOutRefundNo(outRefundNo);
|
||||
//// refundRecord.setTotalAmount(courseOrder.getTotalAmount().movePointRight(2));
|
||||
//// refundRecord.setRefundAmount(refundAmount.movePointRight(2));
|
||||
//// refundRecord.setUserId(courseOrder.getUserId());
|
||||
//// refundRecord.setCreateTime(null);
|
||||
//// refundRecord.setUpdateTime(null);
|
||||
//// refundRecordService.save(refundRecord);
|
||||
//
|
||||
// // 申请退款
|
||||
// System.out.println("退款请求:" + createRequest);
|
||||
// Refund refund = wxPayConfig.getRefundService().create(createRequest);
|
||||
// System.out.println("退款申请结果:" + refund);
|
||||
//
|
||||
// return refund;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 部分退款回调
|
||||
// */
|
||||
// @Override
|
||||
// public boolean refundPartCallback(RefundNotification refundNotification) {
|
||||
// System.out.println("---------------------------微信退款回调(开始)-------------------------------");
|
||||
// // 获取订单信息
|
||||
// String orderNumber = refundNotification.getOutTradeNo();
|
||||
// LambdaQueryWrapper<CourseOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(CourseOrder::getOrderNumber, orderNumber);
|
||||
// CourseOrder courseOrder = courseOrderService.getOne(queryWrapper);
|
||||
//
|
||||
// // 修改订单状态
|
||||
// LambdaUpdateWrapper<CourseOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
// updateWrapper.eq(CourseOrder::getId, courseOrder.getId())
|
||||
// .set(CourseOrder::getOrderStatus, OrderStatusConstant.REFUNDED);
|
||||
// courseOrderService.update(updateWrapper);
|
||||
//
|
||||
// // 修改课程下单人数
|
||||
// Long courseId = courseOrder.getCourseId();
|
||||
// Course course = courseService.getById(courseId);
|
||||
// if (course != null) {
|
||||
// course.setOrderCount(course.getOrderCount() - 1);
|
||||
// courseService.updateById(course);
|
||||
// }
|
||||
//
|
||||
// // 更新主管和员工的绩效记录
|
||||
// Long userId = courseOrder.getUserId();
|
||||
// List<Long> pathToRoot = userInfoService.findPathToRoot(userId);
|
||||
// List<Long> superUserIdList = pathToRoot.subList(1, 3);
|
||||
// List<UserPerformanceSummary> userPerformanceSummaryList = commonService.findByFieldInTargetField(superUserIdList, userPerformanceSummaryService, Function.identity(), UserPerformanceSummary::getUserId);
|
||||
// BigDecimal rate;
|
||||
// LambdaQueryWrapper<CoursePromotionCommissionPending> coursePromotionQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// coursePromotionQueryWrapper.eq(CoursePromotionCommissionPending::getOrderId, courseOrder.getId());
|
||||
// CoursePromotionCommissionPending coursePromotionCommissionPending = coursePromotionCommissionPendingService.getOne(coursePromotionQueryWrapper);
|
||||
// for (int i = 0; i < userPerformanceSummaryList.size(); i ++ ) {
|
||||
// if (i == 0) rate = coursePromotionCommissionPending.getFirstRate();
|
||||
// else rate = coursePromotionCommissionPending.getSecondRate();
|
||||
// // 计算理论上获得的最大提成奖励
|
||||
// BigDecimal rakeRewards = courseOrder.getTotalAmount().multiply(rate);
|
||||
// UserPerformanceSummary userPerformanceSummary = userPerformanceSummaryList.get(i);
|
||||
//
|
||||
// userPerformanceSummary.setTotalAmount(userPerformanceSummary.getTotalAmount().subtract(courseOrder.getTotalAmount()));
|
||||
// userPerformanceSummary.setNetAmount(userPerformanceSummary.getNetAmount().subtract(courseOrder.getTotalAmount().multiply(SystemConstant.FEE_RATE)));
|
||||
// userPerformanceSummary.setToRelease(userPerformanceSummary.getToRelease().subtract(rakeRewards.multiply(SystemConstant.REFUND_RATE)));
|
||||
// userPerformanceSummary.setRefunded(userPerformanceSummary.getRefunded().add(courseOrder.getTotalAmount().multiply(SystemConstant.REFUND_RATE)));
|
||||
// }
|
||||
// userPerformanceSummaryService.updateBatchById(userPerformanceSummaryList);
|
||||
//
|
||||
// // 修改课程推广待提成状态为"已失效"
|
||||
// LambdaUpdateWrapper<CoursePromotionCommissionPending> coursePromotionUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
// coursePromotionUpdateWrapper.eq(CoursePromotionCommissionPending::getOrderId, courseOrder.getId())
|
||||
// .set(CoursePromotionCommissionPending::getCommissionStatus, CommissionStatusEnum.EXPIRED.getValue());
|
||||
// coursePromotionCommissionPendingService.update(coursePromotionUpdateWrapper);
|
||||
//
|
||||
// System.out.println("---------------------------微信退款回调(结束)-------------------------------");
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 获取支付回调信息
|
||||
// */
|
||||
// @Override
|
||||
// public Transaction getTransactionInfo(HttpServletRequest request) {
|
||||
// NotificationParser notificationParser = getNotificationParser(request);
|
||||
// return notificationParser.parse(requestParam, Transaction.class);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 获取退款回调信息
|
||||
// */
|
||||
// @Override
|
||||
// public RefundNotification getRefundInfo(HttpServletRequest request) {
|
||||
// NotificationParser notificationParser = getNotificationParser(request);
|
||||
// return notificationParser.parse(requestParam, RefundNotification.class);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 根据微信官方发送的请求获取信息
|
||||
// */
|
||||
// @SneakyThrows
|
||||
// public NotificationParser getNotificationParser(HttpServletRequest request) {
|
||||
// System.out.println("---------------------------获取信息-------------------------------");
|
||||
// // 获取RSA配置
|
||||
// NotificationParser notificationParser = new NotificationParser(wxPayConfig.getRSAConfig());
|
||||
// // 构建请求
|
||||
// StringBuilder bodyBuilder = new StringBuilder();
|
||||
// BufferedReader reader = request.getReader();
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// bodyBuilder.append(line);
|
||||
// }
|
||||
// String body = bodyBuilder.toString();
|
||||
// String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
// String nonce = request.getHeader("Wechatpay-Nonce");
|
||||
// String signature = request.getHeader("Wechatpay-Signature");
|
||||
// String singType = request.getHeader("Wechatpay-Signature-Type");
|
||||
// String wechatPayCertificateSerialNumber = request.getHeader("Wechatpay-Serial");
|
||||
// requestParam = new RequestParam.Builder()
|
||||
// .serialNumber(wechatPayCertificateSerialNumber)
|
||||
// .nonce(nonce)
|
||||
// .signature(signature)
|
||||
// .timestamp(timestamp)
|
||||
// .signType(singType)
|
||||
// .body(body)
|
||||
// .build();
|
||||
// System.out.println(requestParam.toString());
|
||||
// System.out.println("---------------------------信息获取完毕-------------------------------");
|
||||
// return notificationParser;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -33,8 +33,8 @@ public class SendSmsUtil {
|
||||
|
||||
// 设置请求参数
|
||||
List<NameValuePair> data = new ArrayList<>();
|
||||
data.add(new BasicNameValuePair("account", "C08121984"));
|
||||
data.add(new BasicNameValuePair("password", "84a27a879413ec629bf26c5d84a25271"));
|
||||
data.add(new BasicNameValuePair("account", "C55991947"));
|
||||
data.add(new BasicNameValuePair("password", "d3979496a8d9c7e9a322804b7ed187e2"));
|
||||
data.add(new BasicNameValuePair("mobile", phoneNumber));
|
||||
data.add(new BasicNameValuePair("content", content));
|
||||
|
||||
|
@ -81,31 +81,11 @@ mybatis-plus:
|
||||
|
||||
|
||||
|
||||
|
||||
wx:
|
||||
mini:
|
||||
appId: wx3f968a09e31d6bed
|
||||
appSecret: 0b23498d19665dc323efdd3ed5367041
|
||||
|
||||
pay:
|
||||
#应用id(小程序id)
|
||||
appId: wx61b63e27bddf4ea2
|
||||
#商户号
|
||||
merchantId: 1700326544
|
||||
#商户API私钥
|
||||
privateKeyPath: apiclient_key.pem
|
||||
#商户证书序列号
|
||||
merchantSerialNumber: 6DC8953AB741D309920DA650B92F837BE38A2757
|
||||
#商户APIv3密钥
|
||||
apiV3Key: fbemuj4Xql7CYlQJAoTEPYxvPSNgYT2t
|
||||
#通知地址
|
||||
notifyUrl: https://winning-mouse-internally.ngrok-free.app
|
||||
#微信服务器地址
|
||||
domain: https://api.mch.weixin.qq.com
|
||||
#商户APIv2密钥
|
||||
apiV2Key: cvsOH6TgbbdNUUqFJyLmWGaIEKoSqANg
|
||||
#商户API证书
|
||||
certificatePath: static/apiclient_cert.p12
|
||||
|
||||
appId: wx8711c8d4fb04fef9
|
||||
appSecret: 3ec1f19949d99f059e2ae4be62d02123
|
||||
|
||||
|
||||
|
||||
|
@ -74,28 +74,8 @@ mybatis-plus:
|
||||
|
||||
wx:
|
||||
mini:
|
||||
appId: wx3f968a09e31d6bed
|
||||
appSecret: 0b23498d19665dc323efdd3ed5367041
|
||||
|
||||
pay:
|
||||
#应用id(小程序id)
|
||||
appId: wx61b63e27bddf4ea2
|
||||
#商户号
|
||||
merchantId: 1700326544
|
||||
#商户API私钥
|
||||
privateKeyPath: apiclient_key.pem
|
||||
#商户证书序列号
|
||||
merchantSerialNumber: 6DC8953AB741D309920DA650B92F837BE38A2757
|
||||
#商户APIv3密钥
|
||||
apiV3Key: fbemuj4Xql7CYlQJAoTEPYxvPSNgYT2t
|
||||
#通知地址
|
||||
notifyUrl: https://winning-mouse-internally.ngrok-free.app
|
||||
#微信服务器地址
|
||||
domain: https://api.mch.weixin.qq.com
|
||||
#商户APIv2密钥
|
||||
apiV2Key: cvsOH6TgbbdNUUqFJyLmWGaIEKoSqANg
|
||||
#商户API证书
|
||||
certificatePath: static/apiclient_cert.p12
|
||||
appId: wx8711c8d4fb04fef9
|
||||
appSecret: 3ec1f19949d99f059e2ae4be62d02123
|
||||
|
||||
|
||||
|
||||
|
@ -63,32 +63,11 @@ mybatis-plus:
|
||||
|
||||
|
||||
|
||||
|
||||
wx:
|
||||
mini:
|
||||
appId: wx3f968a09e31d6bed
|
||||
appSecret: 0b23498d19665dc323efdd3ed5367041
|
||||
|
||||
pay:
|
||||
#应用id(小程序id)
|
||||
appId: wx61b63e27bddf4ea2
|
||||
#商户号
|
||||
merchantId: 1700326544
|
||||
# #商户API私钥
|
||||
# privateKeyPath: apiclient_key.pem
|
||||
#商户证书序列号
|
||||
merchantSerialNumber: 6DC8953AB741D309920DA650B92F837BE38A2757
|
||||
# #商户APIv3密钥
|
||||
# apiV3Key: fbemuj4Xql7CYlQJAoTEPYxvPSNgYT2t
|
||||
#通知地址
|
||||
notifyUrl: https://winning-mouse-internally.ngrok-free.app
|
||||
#微信服务器地址
|
||||
domain: https://api.mch.weixin.qq.com
|
||||
#商户APIv2密钥
|
||||
apiV2Key: cvsOH6TgbbdNUUqFJyLmWGaIEKoSqANg
|
||||
#商户API证书
|
||||
certificatePath: static/apiclient_cert.p12
|
||||
|
||||
|
||||
appId: wx8711c8d4fb04fef9
|
||||
appSecret: 3ec1f19949d99f059e2ae4be62d02123
|
||||
|
||||
|
||||
knife4j:
|
||||
|
112
src/main/resources/application-prod.yml
Normal file
112
src/main/resources/application-prod.yml
Normal file
@ -0,0 +1,112 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://160.202.242.36:3306/qingcheng_test?serverTimezone=Asia/Shanghai
|
||||
username: qingcheng
|
||||
password: Qc@8ls2jf
|
||||
hikari:
|
||||
maximum-pool-size: 300
|
||||
max-lifetime: 120000
|
||||
|
||||
|
||||
rabbitmq:
|
||||
host: 160.202.242.36
|
||||
port: 5672
|
||||
username: qingcheng
|
||||
password: cksys6509
|
||||
virtual-host: vhost-test
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1
|
||||
|
||||
|
||||
data:
|
||||
redis:
|
||||
port: 6379
|
||||
host: 160.202.242.36
|
||||
database: 8
|
||||
password: Cksys6509
|
||||
|
||||
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 20MB
|
||||
max-request-size: 20MB
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
|
||||
|
||||
# 文件上传和下载地址
|
||||
file:
|
||||
upload-dir: /www/wwwroot/fileUpload_qc/
|
||||
# upload-dir: D:/qingcheng/image/
|
||||
|
||||
|
||||
|
||||
springdoc:
|
||||
default-flat-param-object: true
|
||||
|
||||
#线程池配置
|
||||
threadpool:
|
||||
corePoolSize: 10
|
||||
maxPoolSize: 50
|
||||
queueCapacity: 1024
|
||||
keepAliveTime: 60
|
||||
|
||||
|
||||
server:
|
||||
port: 9095
|
||||
ssl:
|
||||
key-store: classpath:static/www.chenxinzhi.top.jks
|
||||
key-store-password: 3fqodotz
|
||||
key-store-type: JKS
|
||||
|
||||
|
||||
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: false
|
||||
# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
db-config:
|
||||
logic-delete-field: isDelete #全局逻辑删除的实体字段名
|
||||
logic-delete-value: 1 #逻辑已删除值(默认为1)
|
||||
logic-not-delete-value: 0 #逻辑未删除值(默认为0)
|
||||
type-handlers-package: com.cultural.heritage.handler
|
||||
|
||||
|
||||
|
||||
wx:
|
||||
mini:
|
||||
appId: wx8711c8d4fb04fef9
|
||||
appSecret: 3ec1f19949d99f059e2ae4be62d02123
|
||||
#
|
||||
# pay:
|
||||
# #应用id(小程序id)
|
||||
# appId: wx61b63e27bddf4ea2
|
||||
# #商户号
|
||||
# merchantId: 1700326544
|
||||
# #商户API私钥
|
||||
# privateKeyPath: apiclient_key.pem
|
||||
# #商户证书序列号
|
||||
# merchantSerialNumber: 6DC8953AB741D309920DA650B92F837BE38A2757
|
||||
# #商户APIv3密钥
|
||||
# apiV3Key: fbemuj4Xql7CYlQJAoTEPYxvPSNgYT2t
|
||||
# #通知地址
|
||||
# notifyUrl: https://winning-mouse-internally.ngrok-free.app
|
||||
# #微信服务器地址
|
||||
# domain: https://api.mch.weixin.qq.com
|
||||
# #商户APIv2密钥
|
||||
# apiV2Key: cvsOH6TgbbdNUUqFJyLmWGaIEKoSqANg
|
||||
# #商户API证书
|
||||
# certificatePath: static/apiclient_cert.p12
|
||||
|
||||
|
||||
|
||||
|
||||
knife4j:
|
||||
enable: true
|
@ -77,28 +77,28 @@ mybatis-plus:
|
||||
|
||||
wx:
|
||||
mini:
|
||||
appId: wx3f968a09e31d6bed
|
||||
appSecret: 0b23498d19665dc323efdd3ed5367041
|
||||
|
||||
pay:
|
||||
#应用id(小程序id)
|
||||
appId: wx61b63e27bddf4ea2
|
||||
#商户号
|
||||
merchantId: 1700326544
|
||||
#商户API私钥
|
||||
privateKeyPath: apiclient_key.pem
|
||||
#商户证书序列号
|
||||
merchantSerialNumber: 6DC8953AB741D309920DA650B92F837BE38A2757
|
||||
#商户APIv3密钥
|
||||
apiV3Key: fbemuj4Xql7CYlQJAoTEPYxvPSNgYT2t
|
||||
#通知地址
|
||||
notifyUrl: https://winning-mouse-internally.ngrok-free.app
|
||||
#微信服务器地址
|
||||
domain: https://api.mch.weixin.qq.com
|
||||
#商户APIv2密钥
|
||||
apiV2Key: cvsOH6TgbbdNUUqFJyLmWGaIEKoSqANg
|
||||
#商户API证书
|
||||
certificatePath: static/apiclient_cert.p12
|
||||
appId: wx8711c8d4fb04fef9
|
||||
appSecret: 3ec1f19949d99f059e2ae4be62d02123
|
||||
#
|
||||
# pay:
|
||||
# #应用id(小程序id)
|
||||
# appId: wx61b63e27bddf4ea2
|
||||
# #商户号
|
||||
# merchantId: 1700326544
|
||||
# #商户API私钥
|
||||
# privateKeyPath: apiclient_key.pem
|
||||
# #商户证书序列号
|
||||
# merchantSerialNumber: 6DC8953AB741D309920DA650B92F837BE38A2757
|
||||
# #商户APIv3密钥
|
||||
# apiV3Key: fbemuj4Xql7CYlQJAoTEPYxvPSNgYT2t
|
||||
# #通知地址
|
||||
# notifyUrl: https://winning-mouse-internally.ngrok-free.app
|
||||
# #微信服务器地址
|
||||
# domain: https://api.mch.weixin.qq.com
|
||||
# #商户APIv2密钥
|
||||
# apiV2Key: cvsOH6TgbbdNUUqFJyLmWGaIEKoSqANg
|
||||
# #商户API证书
|
||||
# certificatePath: static/apiclient_cert.p12
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
$libDir = "D:\青橙\backend\src\main\resources\lib" # 使用绝对路径指定 lib 目录
|
||||
$repositoryDir = "D:\software\Maven\maven-repository" # 设置自定义仓库目录
|
||||
|
||||
# 遍历 lib 目录下的所有 JAR 文件并安装到指定的仓库
|
||||
Get-ChildItem -Path $libDir -Filter "*.jar" | ForEach-Object {
|
||||
mvn install:install-file -Dfile=$_.FullName `
|
||||
-DgroupId=com.example `
|
||||
-DartifactId=$($_.BaseName) `
|
||||
-Dversion=1.0 `
|
||||
-Dpackaging=jar `
|
||||
-DlocalRepositoryPath=$repositoryDir
|
||||
}
|
BIN
src/main/resources/static/www.chenxinzhi.top.jks
Normal file
BIN
src/main/resources/static/www.chenxinzhi.top.jks
Normal file
Binary file not shown.
@ -1,79 +1,79 @@
|
||||
package com.greenorange.promotion.junit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.greenorange.promotion.model.dto.CommonBatchRequest;
|
||||
import com.greenorange.promotion.model.entity.PromoCode;
|
||||
import com.greenorange.promotion.service.project.impl.PromoCodeServiceImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PromoCodeServiceImplTest {
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private PromoCodeServiceImpl service;
|
||||
// Spy + InjectMocks:使用真实的 PromoCodeServiceImpl,但可以 stub 它的 list(...) 和 removeByIds(...)
|
||||
|
||||
/**
|
||||
* 当存在状态为“占用”的推广码时,应抛出异常并且不执行删除
|
||||
*/
|
||||
@Test
|
||||
void delBatchPromoCode_whenCodesInUse_shouldThrow() {
|
||||
// Arrange
|
||||
List<Long> ids = Arrays.asList(1L, 2L, 3L);
|
||||
CommonBatchRequest req = new CommonBatchRequest();
|
||||
req.setIds(ids);
|
||||
|
||||
// 模拟 list(...) 返回一个非空列表,表示有正在使用的推广码
|
||||
PromoCode inUse = new PromoCode();
|
||||
inUse.setId(2L);
|
||||
inUse.setPromoCodeStatus(true);
|
||||
doReturn(Collections.singletonList(inUse))
|
||||
.when(service).list(any(LambdaQueryWrapper.class));
|
||||
|
||||
// Act & Assert
|
||||
RuntimeException ex = assertThrows(RuntimeException.class,
|
||||
() -> service.delBatchPromoCode(req));
|
||||
assertTrue(ex.getMessage().contains("当前推广码正在使用中"));
|
||||
|
||||
// 验证 removeByIds(...) 从未被调用
|
||||
verify(service, never()).removeByIds(anyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 当所有推广码都未被占用时,应正常调用 removeByIds 删除
|
||||
*/
|
||||
@Test
|
||||
void delBatchPromoCode_whenNoCodesInUse_shouldRemove() {
|
||||
// Arrange
|
||||
List<Long> ids = Arrays.asList(4L, 5L);
|
||||
CommonBatchRequest req = new CommonBatchRequest();
|
||||
req.setIds(ids);
|
||||
|
||||
// 模拟 list(...) 返回空列表,表示无任何占用的推广码
|
||||
doReturn(Collections.emptyList())
|
||||
.when(service).list(any(LambdaQueryWrapper.class));
|
||||
|
||||
// 模拟 removeByIds(...) 返回 true,表示删除成功
|
||||
doReturn(true).when(service).removeByIds(ids);
|
||||
|
||||
// Act
|
||||
service.delBatchPromoCode(req);
|
||||
|
||||
// Assert
|
||||
// 验证 removeByIds(...) 被调用一次,且参数正是传入的 ids
|
||||
verify(service, times(1)).removeByIds(ids);
|
||||
}
|
||||
}
|
||||
//package com.greenorange.promotion.junit;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.greenorange.promotion.model.dto.CommonBatchRequest;
|
||||
//import com.greenorange.promotion.model.entity.PromoCode;
|
||||
//import com.greenorange.promotion.service.project.impl.PromoCodeServiceImpl;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.junit.jupiter.api.extension.ExtendWith;
|
||||
//import org.mockito.InjectMocks;
|
||||
//import org.mockito.Spy;
|
||||
//import org.mockito.junit.jupiter.MockitoExtension;
|
||||
//
|
||||
//import java.util.Arrays;
|
||||
//import java.util.Collections;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
//import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
//import static org.mockito.Mockito.*;
|
||||
//
|
||||
//@ExtendWith(MockitoExtension.class)
|
||||
//class PromoCodeServiceImplTest {
|
||||
//
|
||||
// @Spy
|
||||
// @InjectMocks
|
||||
// private PromoCodeServiceImpl service;
|
||||
// // Spy + InjectMocks:使用真实的 PromoCodeServiceImpl,但可以 stub 它的 list(...) 和 removeByIds(...)
|
||||
//
|
||||
// /**
|
||||
// * 当存在状态为“占用”的推广码时,应抛出异常并且不执行删除
|
||||
// */
|
||||
// @Test
|
||||
// void delBatchPromoCode_whenCodesInUse_shouldThrow() {
|
||||
// // Arrange
|
||||
// List<Long> ids = Arrays.asList(1L, 2L, 3L);
|
||||
// CommonBatchRequest req = new CommonBatchRequest();
|
||||
// req.setIds(ids);
|
||||
//
|
||||
// // 模拟 list(...) 返回一个非空列表,表示有正在使用的推广码
|
||||
// PromoCode inUse = new PromoCode();
|
||||
// inUse.setId(2L);
|
||||
// inUse.setPromoCodeStatus(true);
|
||||
// doReturn(Collections.singletonList(inUse))
|
||||
// .when(service).list(any(LambdaQueryWrapper.class));
|
||||
//
|
||||
// // Act & Assert
|
||||
// RuntimeException ex = assertThrows(RuntimeException.class,
|
||||
// () -> service.delBatchPromoCode(req));
|
||||
// assertTrue(ex.getMessage().contains("当前推广码正在使用中"));
|
||||
//
|
||||
// // 验证 removeByIds(...) 从未被调用
|
||||
// verify(service, never()).removeByIds(anyList());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 当所有推广码都未被占用时,应正常调用 removeByIds 删除
|
||||
// */
|
||||
// @Test
|
||||
// void delBatchPromoCode_whenNoCodesInUse_shouldRemove() {
|
||||
// // Arrange
|
||||
// List<Long> ids = Arrays.asList(4L, 5L);
|
||||
// CommonBatchRequest req = new CommonBatchRequest();
|
||||
// req.setIds(ids);
|
||||
//
|
||||
// // 模拟 list(...) 返回空列表,表示无任何占用的推广码
|
||||
// doReturn(Collections.emptyList())
|
||||
// .when(service).list(any(LambdaQueryWrapper.class));
|
||||
//
|
||||
// // 模拟 removeByIds(...) 返回 true,表示删除成功
|
||||
// doReturn(true).when(service).removeByIds(ids);
|
||||
//
|
||||
// // Act
|
||||
// service.delBatchPromoCode(req);
|
||||
//
|
||||
// // Assert
|
||||
// // 验证 removeByIds(...) 被调用一次,且参数正是传入的 ids
|
||||
// verify(service, times(1)).removeByIds(ids);
|
||||
// }
|
||||
//}
|
||||
|
@ -1,96 +1,96 @@
|
||||
package com.greenorange.promotion.junit;
|
||||
|
||||
import com.greenorange.promotion.model.dto.userAccount.UserAccountUpdateRequest;
|
||||
import com.greenorange.promotion.model.entity.UserAccount;
|
||||
import com.greenorange.promotion.service.common.CommonService;
|
||||
import com.greenorange.promotion.service.settle.impl.UserAccountServiceImpl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UserAccountServiceImplTest {
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private UserAccountServiceImpl userAccountService;
|
||||
// Spy + InjectMocks:用真实的 serviceImpl,但可以对它的方法做部分 stub
|
||||
|
||||
@Mock
|
||||
private CommonService commonService;
|
||||
// Mock CommonService,用于模拟 copyProperties
|
||||
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
// Mock HttpServletRequest,用于模拟获取 userId
|
||||
|
||||
@Test
|
||||
void updateUserAccount_shouldCopyProperties_setUserId_andUpdateById() {
|
||||
// --- Arrange 准备阶段 ---
|
||||
Long userId = 456L;
|
||||
// 模拟从 request 中拿到当前登录用户 ID
|
||||
when(request.getAttribute("userId")).thenReturn(userId);
|
||||
|
||||
// 构造更新请求 DTO,并设置要更新的账户 ID
|
||||
UserAccountUpdateRequest req = new UserAccountUpdateRequest();
|
||||
req.setId(99L);
|
||||
req.setCardHolder("李四");
|
||||
req.setIdCardNumber("110101199002022345");
|
||||
req.setPhoneNumber("15900001111");
|
||||
req.setBankCardNumber("6222020202020202");
|
||||
req.setOpenBank("中国农业银行");
|
||||
|
||||
// 准备一个空实体,模拟 commonService.copyProperties 拷贝结果
|
||||
UserAccount stubEntity = new UserAccount();
|
||||
// 假设 copyProperties 会拷贝所有字段,包括 id
|
||||
stubEntity.setId(req.getId());
|
||||
stubEntity.setCardHolder(req.getCardHolder());
|
||||
stubEntity.setIdCardNumber(req.getIdCardNumber());
|
||||
stubEntity.setPhoneNumber(req.getPhoneNumber());
|
||||
stubEntity.setBankCardNumber(req.getBankCardNumber());
|
||||
stubEntity.setOpenBank(req.getOpenBank());
|
||||
// stub copyProperties 返回我们准备的 stubEntity
|
||||
when(commonService.copyProperties(req, UserAccount.class))
|
||||
.thenReturn(stubEntity);
|
||||
|
||||
// 对 Spy 的 updateById(...) 方法做 stub,避免走到 MyBatis-Plus 真逻辑
|
||||
doReturn(true).when(userAccountService).updateById(any(UserAccount.class));
|
||||
|
||||
// --- Act 执行阶段 ---
|
||||
userAccountService.updateUserAccount(req, request);
|
||||
// 方法内部执行顺序:
|
||||
// 1. 取 request.getAttribute("userId") -> 456L
|
||||
// 2. commonService.copyProperties(req, UserAccount.class) -> stubEntity
|
||||
// 3. stubEntity.setUserId(456L)
|
||||
// 4. 调用 updateById(stubEntity)
|
||||
|
||||
// --- Assert 验证阶段 ---
|
||||
// 捕获 updateById 调用时传入的参数
|
||||
ArgumentCaptor<UserAccount> captor = ArgumentCaptor.forClass(UserAccount.class);
|
||||
verify(userAccountService).updateById(captor.capture());
|
||||
UserAccount updated = captor.getValue();
|
||||
|
||||
// 验证传给 updateById 的正是 stubEntity 对象
|
||||
assertSame(stubEntity, updated, "应该传入同一个 stubEntity 实例");
|
||||
|
||||
// 验证 userId 已正确赋值
|
||||
assertEquals(userId, updated.getUserId(), "userId 应该从 request 中取出并赋值");
|
||||
|
||||
// 验证其他字段都被 copyProperties 拷贝过来,包括账户 ID
|
||||
assertEquals(req.getId(), updated.getId(), "账户 ID 应保持一致");
|
||||
assertEquals("李四", updated.getCardHolder(), "持卡人应一致");
|
||||
assertEquals("110101199002022345", updated.getIdCardNumber(), "身份证号应一致");
|
||||
assertEquals("15900001111", updated.getPhoneNumber(), "手机号应一致");
|
||||
assertEquals("6222020202020202", updated.getBankCardNumber(),"银行卡号应一致");
|
||||
assertEquals("中国农业银行", updated.getOpenBank(), "开户银行应一致");
|
||||
}
|
||||
}
|
||||
//package com.greenorange.promotion.junit;
|
||||
//
|
||||
//import com.greenorange.promotion.model.dto.userAccount.UserAccountUpdateRequest;
|
||||
//import com.greenorange.promotion.model.entity.UserAccount;
|
||||
//import com.greenorange.promotion.service.common.CommonService;
|
||||
//import com.greenorange.promotion.service.settle.impl.UserAccountServiceImpl;
|
||||
//import jakarta.servlet.http.HttpServletRequest;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.junit.jupiter.api.extension.ExtendWith;
|
||||
//import org.mockito.ArgumentCaptor;
|
||||
//import org.mockito.InjectMocks;
|
||||
//import org.mockito.Mock;
|
||||
//import org.mockito.Spy;
|
||||
//import org.mockito.junit.jupiter.MockitoExtension;
|
||||
//
|
||||
//import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
//import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
//import static org.mockito.Mockito.*;
|
||||
//
|
||||
//@ExtendWith(MockitoExtension.class)
|
||||
//class UserAccountServiceImplTest {
|
||||
//
|
||||
// @Spy
|
||||
// @InjectMocks
|
||||
// private UserAccountServiceImpl userAccountService;
|
||||
// // Spy + InjectMocks:用真实的 serviceImpl,但可以对它的方法做部分 stub
|
||||
//
|
||||
// @Mock
|
||||
// private CommonService commonService;
|
||||
// // Mock CommonService,用于模拟 copyProperties
|
||||
//
|
||||
// @Mock
|
||||
// private HttpServletRequest request;
|
||||
// // Mock HttpServletRequest,用于模拟获取 userId
|
||||
//
|
||||
// @Test
|
||||
// void updateUserAccount_shouldCopyProperties_setUserId_andUpdateById() {
|
||||
// // --- Arrange 准备阶段 ---
|
||||
// Long userId = 456L;
|
||||
// // 模拟从 request 中拿到当前登录用户 ID
|
||||
// when(request.getAttribute("userId")).thenReturn(userId);
|
||||
//
|
||||
// // 构造更新请求 DTO,并设置要更新的账户 ID
|
||||
// UserAccountUpdateRequest req = new UserAccountUpdateRequest();
|
||||
// req.setId(99L);
|
||||
// req.setCardHolder("李四");
|
||||
// req.setIdCardNumber("110101199002022345");
|
||||
// req.setPhoneNumber("15900001111");
|
||||
// req.setBankCardNumber("6222020202020202");
|
||||
// req.setOpenBank("中国农业银行");
|
||||
//
|
||||
// // 准备一个空实体,模拟 commonService.copyProperties 拷贝结果
|
||||
// UserAccount stubEntity = new UserAccount();
|
||||
// // 假设 copyProperties 会拷贝所有字段,包括 id
|
||||
// stubEntity.setId(req.getId());
|
||||
// stubEntity.setCardHolder(req.getCardHolder());
|
||||
// stubEntity.setIdCardNumber(req.getIdCardNumber());
|
||||
// stubEntity.setPhoneNumber(req.getPhoneNumber());
|
||||
// stubEntity.setBankCardNumber(req.getBankCardNumber());
|
||||
// stubEntity.setOpenBank(req.getOpenBank());
|
||||
// // stub copyProperties 返回我们准备的 stubEntity
|
||||
// when(commonService.copyProperties(req, UserAccount.class))
|
||||
// .thenReturn(stubEntity);
|
||||
//
|
||||
// // 对 Spy 的 updateById(...) 方法做 stub,避免走到 MyBatis-Plus 真逻辑
|
||||
// doReturn(true).when(userAccountService).updateById(any(UserAccount.class));
|
||||
//
|
||||
// // --- Act 执行阶段 ---
|
||||
// userAccountService.updateUserAccount(req, request);
|
||||
// // 方法内部执行顺序:
|
||||
// // 1. 取 request.getAttribute("userId") -> 456L
|
||||
// // 2. commonService.copyProperties(req, UserAccount.class) -> stubEntity
|
||||
// // 3. stubEntity.setUserId(456L)
|
||||
// // 4. 调用 updateById(stubEntity)
|
||||
//
|
||||
// // --- Assert 验证阶段 ---
|
||||
// // 捕获 updateById 调用时传入的参数
|
||||
// ArgumentCaptor<UserAccount> captor = ArgumentCaptor.forClass(UserAccount.class);
|
||||
// verify(userAccountService).updateById(captor.capture());
|
||||
// UserAccount updated = captor.getValue();
|
||||
//
|
||||
// // 验证传给 updateById 的正是 stubEntity 对象
|
||||
// assertSame(stubEntity, updated, "应该传入同一个 stubEntity 实例");
|
||||
//
|
||||
// // 验证 userId 已正确赋值
|
||||
// assertEquals(userId, updated.getUserId(), "userId 应该从 request 中取出并赋值");
|
||||
//
|
||||
// // 验证其他字段都被 copyProperties 拷贝过来,包括账户 ID
|
||||
// assertEquals(req.getId(), updated.getId(), "账户 ID 应保持一致");
|
||||
// assertEquals("李四", updated.getCardHolder(), "持卡人应一致");
|
||||
// assertEquals("110101199002022345", updated.getIdCardNumber(), "身份证号应一致");
|
||||
// assertEquals("15900001111", updated.getPhoneNumber(), "手机号应一致");
|
||||
// assertEquals("6222020202020202", updated.getBankCardNumber(),"银行卡号应一致");
|
||||
// assertEquals("中国农业银行", updated.getOpenBank(), "开户银行应一致");
|
||||
// }
|
||||
//}
|
||||
|
@ -1,103 +1,103 @@
|
||||
package com.greenorange.promotion.junit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.greenorange.promotion.model.dto.userInfo.UserInfoMiniPasswordLoginRequest;
|
||||
import com.greenorange.promotion.model.entity.UserInfo;
|
||||
import com.greenorange.promotion.service.userInfo.impl.UserInfoServiceImpl;
|
||||
import com.greenorange.promotion.utils.JWTUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UserInfoServiceImplTest {
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private UserInfoServiceImpl userService; // 真实的 ServiceImpl,部分方法用 spy
|
||||
|
||||
@Mock
|
||||
private JWTUtils jwtUtils; // 用来生成 token 的工具
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// MockitoAnnotations.openMocks(this); // @ExtendWith 已自动初始化
|
||||
}
|
||||
|
||||
private UserInfoMiniPasswordLoginRequest buildRequest(String phone, String pwd) {
|
||||
UserInfoMiniPasswordLoginRequest req = new UserInfoMiniPasswordLoginRequest();
|
||||
req.setPhoneNumber(phone);
|
||||
req.setUserPassword(pwd);
|
||||
return req;
|
||||
}
|
||||
|
||||
/** 1. 手机号格式无效,应直接抛参数错误 */
|
||||
@Test
|
||||
void givenInvalidPhone_whenLoginByPwd_thenThrow() {
|
||||
UserInfoMiniPasswordLoginRequest req = buildRequest("not-a-phone", "whatever");
|
||||
assertThrows(RuntimeException.class, () -> userService.userInfoMiniLoginByPwd(req));
|
||||
}
|
||||
|
||||
/** 2. 手机号未注册,应抛操作错误 */
|
||||
@Test
|
||||
void givenUnregisteredPhone_whenLoginByPwd_thenThrow() {
|
||||
// stub 第一次 getOne(...) 返回 null
|
||||
doReturn(null)
|
||||
.when(userService).getOne(any(LambdaQueryWrapper.class));
|
||||
|
||||
UserInfoMiniPasswordLoginRequest req = buildRequest("13812345678", "pwd");
|
||||
assertThrows(RuntimeException.class, () -> userService.userInfoMiniLoginByPwd(req));
|
||||
}
|
||||
|
||||
/** 3. 密码不正确,应抛操作错误 */
|
||||
@Test
|
||||
void givenWrongPassword_whenLoginByPwd_thenThrow() {
|
||||
UserInfo dummy = new UserInfo();
|
||||
dummy.setPhoneNumber("13812345678");
|
||||
dummy.setUserPassword("rightPwd");
|
||||
|
||||
// stub 第一次 getOne(...) 返回非 null(手机号存在)
|
||||
// stub 第二次 getOne(...) 返回 null(密码校验失败)
|
||||
doReturn(dummy, null)
|
||||
.when(userService).getOne(any(LambdaQueryWrapper.class));
|
||||
|
||||
UserInfoMiniPasswordLoginRequest req = buildRequest("13812345678", "wrongPwd");
|
||||
assertThrows(RuntimeException.class, () -> userService.userInfoMiniLoginByPwd(req));
|
||||
}
|
||||
|
||||
/** 4. 成功场景:正确手机号 + 密码,返回 token,并验证 jwtUtils 调用 */
|
||||
@Test
|
||||
void givenValidCredentials_whenLoginByPwd_thenReturnToken() {
|
||||
UserInfo dummy = new UserInfo();
|
||||
dummy.setPhoneNumber("13812345678");
|
||||
dummy.setUserPassword("rightPwd");
|
||||
|
||||
// stub getOne(...) 两次都返回同一个 dummy(表示手机号存在且密码正确)
|
||||
doReturn(dummy, dummy)
|
||||
.when(userService).getOne(any(LambdaQueryWrapper.class));
|
||||
|
||||
// stub jwtUtils.generateToken(...)
|
||||
String expectedToken = "jwt-token-xyz";
|
||||
when(jwtUtils.generateToken(anyMap())).thenReturn(expectedToken);
|
||||
|
||||
UserInfoMiniPasswordLoginRequest req = buildRequest("13812345678", "rightPwd");
|
||||
String token = userService.userInfoMiniLoginByPwd(req);
|
||||
|
||||
assertEquals(expectedToken, token);
|
||||
|
||||
// 验证 payload 内容正确
|
||||
ArgumentCaptor<Map<String, String>> captor = ArgumentCaptor.forClass(Map.class);
|
||||
verify(jwtUtils, times(1)).generateToken(captor.capture());
|
||||
Map<String, String> payload = captor.getValue();
|
||||
assertEquals("13812345678", payload.get("userAccount"));
|
||||
assertEquals("rightPwd", payload.get("userPassword"));
|
||||
}
|
||||
}
|
||||
//package com.greenorange.promotion.junit;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import com.greenorange.promotion.model.dto.userInfo.UserInfoMiniPasswordLoginRequest;
|
||||
//import com.greenorange.promotion.model.entity.UserInfo;
|
||||
//import com.greenorange.promotion.service.userInfo.impl.UserInfoServiceImpl;
|
||||
//import com.greenorange.promotion.utils.JWTUtils;
|
||||
//import org.junit.jupiter.api.BeforeEach;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.junit.jupiter.api.extension.ExtendWith;
|
||||
//import org.mockito.*;
|
||||
//import org.mockito.junit.jupiter.MockitoExtension;
|
||||
//
|
||||
//import java.util.Map;
|
||||
//
|
||||
//import static org.junit.jupiter.api.Assertions.*;
|
||||
//import static org.mockito.ArgumentMatchers.any;
|
||||
//import static org.mockito.Mockito.*;
|
||||
//
|
||||
//@ExtendWith(MockitoExtension.class)
|
||||
//class UserInfoServiceImplTest {
|
||||
//
|
||||
// @Spy
|
||||
// @InjectMocks
|
||||
// private UserInfoServiceImpl userService; // 真实的 ServiceImpl,部分方法用 spy
|
||||
//
|
||||
// @Mock
|
||||
// private JWTUtils jwtUtils; // 用来生成 token 的工具
|
||||
//
|
||||
// @BeforeEach
|
||||
// void setUp() {
|
||||
// // MockitoAnnotations.openMocks(this); // @ExtendWith 已自动初始化
|
||||
// }
|
||||
//
|
||||
// private UserInfoMiniPasswordLoginRequest buildRequest(String phone, String pwd) {
|
||||
// UserInfoMiniPasswordLoginRequest req = new UserInfoMiniPasswordLoginRequest();
|
||||
// req.setPhoneNumber(phone);
|
||||
// req.setUserPassword(pwd);
|
||||
// return req;
|
||||
// }
|
||||
//
|
||||
// /** 1. 手机号格式无效,应直接抛参数错误 */
|
||||
// @Test
|
||||
// void givenInvalidPhone_whenLoginByPwd_thenThrow() {
|
||||
// UserInfoMiniPasswordLoginRequest req = buildRequest("not-a-phone", "whatever");
|
||||
// assertThrows(RuntimeException.class, () -> userService.userInfoMiniLoginByPwd(req));
|
||||
// }
|
||||
//
|
||||
// /** 2. 手机号未注册,应抛操作错误 */
|
||||
// @Test
|
||||
// void givenUnregisteredPhone_whenLoginByPwd_thenThrow() {
|
||||
// // stub 第一次 getOne(...) 返回 null
|
||||
// doReturn(null)
|
||||
// .when(userService).getOne(any(LambdaQueryWrapper.class));
|
||||
//
|
||||
// UserInfoMiniPasswordLoginRequest req = buildRequest("13812345678", "pwd");
|
||||
// assertThrows(RuntimeException.class, () -> userService.userInfoMiniLoginByPwd(req));
|
||||
// }
|
||||
//
|
||||
// /** 3. 密码不正确,应抛操作错误 */
|
||||
// @Test
|
||||
// void givenWrongPassword_whenLoginByPwd_thenThrow() {
|
||||
// UserInfo dummy = new UserInfo();
|
||||
// dummy.setPhoneNumber("13812345678");
|
||||
// dummy.setUserPassword("rightPwd");
|
||||
//
|
||||
// // stub 第一次 getOne(...) 返回非 null(手机号存在)
|
||||
// // stub 第二次 getOne(...) 返回 null(密码校验失败)
|
||||
// doReturn(dummy, null)
|
||||
// .when(userService).getOne(any(LambdaQueryWrapper.class));
|
||||
//
|
||||
// UserInfoMiniPasswordLoginRequest req = buildRequest("13812345678", "wrongPwd");
|
||||
// assertThrows(RuntimeException.class, () -> userService.userInfoMiniLoginByPwd(req));
|
||||
// }
|
||||
//
|
||||
// /** 4. 成功场景:正确手机号 + 密码,返回 token,并验证 jwtUtils 调用 */
|
||||
// @Test
|
||||
// void givenValidCredentials_whenLoginByPwd_thenReturnToken() {
|
||||
// UserInfo dummy = new UserInfo();
|
||||
// dummy.setPhoneNumber("13812345678");
|
||||
// dummy.setUserPassword("rightPwd");
|
||||
//
|
||||
// // stub getOne(...) 两次都返回同一个 dummy(表示手机号存在且密码正确)
|
||||
// doReturn(dummy, dummy)
|
||||
// .when(userService).getOne(any(LambdaQueryWrapper.class));
|
||||
//
|
||||
// // stub jwtUtils.generateToken(...)
|
||||
// String expectedToken = "jwt-token-xyz";
|
||||
// when(jwtUtils.generateToken(anyMap())).thenReturn(expectedToken);
|
||||
//
|
||||
// UserInfoMiniPasswordLoginRequest req = buildRequest("13812345678", "rightPwd");
|
||||
// String token = userService.userInfoMiniLoginByPwd(req);
|
||||
//
|
||||
// assertEquals(expectedToken, token);
|
||||
//
|
||||
// // 验证 payload 内容正确
|
||||
// ArgumentCaptor<Map<String, String>> captor = ArgumentCaptor.forClass(Map.class);
|
||||
// verify(jwtUtils, times(1)).generateToken(captor.capture());
|
||||
// Map<String, String> payload = captor.getValue();
|
||||
// assertEquals("13812345678", payload.get("userAccount"));
|
||||
// assertEquals("rightPwd", payload.get("userPassword"));
|
||||
// }
|
||||
//}
|
||||
|
Reference in New Issue
Block a user