refactor: 订单会员相关代码重构优化

This commit is contained in:
郝先瑞 2022-06-22 07:57:02 +08:00
parent b7934d024c
commit a5141bcb08
11 changed files with 96 additions and 87 deletions

View File

@ -4,12 +4,11 @@ import com.youlai.mall.pms.api.SkuFeignClient;
import com.youlai.mall.ums.api.MemberFeignClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { MemberFeignClient.class, SkuFeignClient.class})
@EnableTransactionManagement

View File

@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
/**
* 线程池配置
* 自定义订单线程池
*
* @author haoxr
* @date 2022/2/13
@ -20,6 +20,6 @@ public class ThreadPoolConfig {
@Bean
public ThreadPoolExecutor threadPoolExecutor() {
return new ThreadPoolExecutor(50, 500, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), new NamedThreadFactory("订单线程"));
return new ThreadPoolExecutor(50, 500, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000), new NamedThreadFactory("oms"));
}
}

View File

@ -14,10 +14,5 @@ public interface OmsConstants {
String ORDER_SN_PREFIX = "order:sn:";
/**
* 释放锁lua脚本
*/
String RELEASE_LOCK_LUA_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
}

View File

@ -16,6 +16,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@ -40,7 +41,6 @@ public class OrderController {
return PageResult.success(result);
}
/**
* 订单确认 进入创建订单页面
* <p>
@ -52,27 +52,21 @@ public class OrderController {
*/
@ApiOperation("订单确认")
@PostMapping("/_confirm")
public Result<OrderConfirmVO> confirm(
@RequestParam(required = false) Long skuId
) {
OrderConfirmVO result = orderService.confirm(skuId);
public Result<OrderConfirmVO> confirmOrder(@RequestParam(required = false) Long skuId) {
OrderConfirmVO result = orderService.confirmOrder(skuId);
return Result.success(result);
}
@ApiOperation("订单提交")
@PostMapping("/_submit")
public Result submit(@Valid @RequestBody OrderSubmitForm orderSubmitForm) {
OrderSubmitVO result = orderService.submit(orderSubmitForm);
public Result submitOrder(@RequestBody @Validated OrderSubmitForm orderSubmitForm) {
OrderSubmitVO result = orderService.submitOrder(orderSubmitForm);
return Result.success(result);
}
@ApiOperation("订单支付")
@PostMapping("/{orderId}/_pay")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "payType", value = "支付方式", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "appId", value = "小程序appId", paramType = "query", dataType = "String")
})
@ApiImplicitParams({@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "payType", value = "支付方式", paramType = "query", dataType = "Integer"), @ApiImplicitParam(name = "appId", value = "小程序appId", paramType = "query", dataType = "String")})
public <T> Result<T> pay(@PathVariable Long orderId, Integer payType, String appId) {
PayTypeEnum payTypeEnum = IBaseEnum.getEnumByValue(payType, PayTypeEnum.class);

View File

@ -31,12 +31,12 @@ public interface IOrderService extends IService<OmsOrder> {
* @param skuId 直接购买必填购物车结算不填
* @return
*/
OrderConfirmVO confirm(Long skuId);
OrderConfirmVO confirmOrder(Long skuId);
/**
* 订单提交
*/
OrderSubmitVO submit(OrderSubmitForm orderSubmitForm) ;
OrderSubmitVO submitOrder(OrderSubmitForm orderSubmitForm) ;
/**
* 订单支付

View File

@ -1,29 +0,0 @@
package com.youlai.mall.ums.api;
import com.youlai.common.result.Result;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
/**
* 会员地址 Feign 客户端
*
* @author haoxr
* @date 2022/2/12
*/
@FeignClient(name = "mall-ums", contextId = "address")
public interface MemberAddressFeignClient {
/**
* 获取当前会员地址列表
*
* @return
*/
@GetMapping("/app-api/v1/addresses")
Result<List<MemberAddressDTO>> listCurrMemberAddresses();
}

View File

@ -2,12 +2,15 @@ package com.youlai.mall.ums.api;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.vo.ProductHistoryVO;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import com.youlai.mall.ums.dto.MemberAuthDTO;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.dto.MemberInfoDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@FeignClient(name = "mall-ums", contextId = "member")
public interface MemberFeignClient {
@ -58,6 +61,16 @@ public interface MemberFeignClient {
@GetMapping("/app-api/v1/members/mobile/{mobile}")
Result<MemberAuthDTO> loadUserByMobile(@PathVariable String mobile);
/**
* 获取会员地址列表
*
* @param memberId
* @return
*/
@GetMapping("/app-api/v1/members/{memberId}/addresses")
Result<List<MemberAddressDTO>> listMemberAddresses(@PathVariable Long memberId);
/**
* 实验室修改会员余额
*

View File

@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.dto.MemberInfoDTO;
import com.youlai.mall.ums.pojo.entity.UmsMember;
import com.youlai.mall.ums.service.IUmsMemberService;
@ -29,7 +28,7 @@ public class UmsMemberController {
@ApiOperation(value = "会员分页列表")
@GetMapping
public PageResult<UmsMember> listMembersWithPage(
public PageResult<UmsMember> listPageMembers(
@ApiParam("页码") Long pageNum,
@ApiParam("每页数量") Long pageSize,
@ApiParam("会员昵称") String nickName
@ -57,15 +56,16 @@ public class UmsMemberController {
return Result.judge(status);
}
@ApiOperation(value = "选择性修改会员")
@PatchMapping("/{id}")
public <T> Result<T> patch(
@ApiParam("会员ID") @PathVariable Long id,
@ApiOperation(value = "修改会员状态")
@PatchMapping("/{memberId}/status")
public <T> Result<T> updateMemberStatus(
@ApiParam("会员ID") @PathVariable Long memberId,
@RequestBody UmsMember member
) {
boolean status = memberService.update(new LambdaUpdateWrapper<UmsMember>()
.eq(UmsMember::getId, id)
.set(member.getStatus() != null, UmsMember::getStatus, member.getStatus())
boolean status = memberService.update(
new LambdaUpdateWrapper<UmsMember>()
.eq(UmsMember::getId, memberId)
.set(UmsMember::getStatus, member.getStatus())
);
return Result.judge(status);
}

View File

@ -6,6 +6,7 @@ import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.pms.pojo.vo.ProductHistoryVO;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import com.youlai.mall.ums.dto.MemberAuthDTO;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.pojo.entity.UmsMember;
@ -18,6 +19,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@Api(tags = "「移动端」会员管理")
@ -30,14 +32,9 @@ public class MemberController {
@ApiOperation(value = "根据会员ID获取openid")
@GetMapping("/{memberId}/openid")
public Result<String> getMemberById(
@ApiParam("会员ID") @PathVariable Long memberId
) {
UmsMember member = memberService.getOne(
new LambdaQueryWrapper<UmsMember>()
.eq(UmsMember::getId, memberId)
.select(UmsMember::getOpenid)
);
public Result<String> getMemberById(@ApiParam("会员ID") @PathVariable Long memberId) {
UmsMember member = memberService.getOne(new LambdaQueryWrapper<UmsMember>()
.eq(UmsMember::getId, memberId).select(UmsMember::getOpenid));
String openid = member.getOpenid();
return Result.success(openid);
}
@ -51,8 +48,8 @@ public class MemberController {
@ApiOperation(value = "获取登录会员信息")
@GetMapping("/me")
public Result<MemberVO> getCurrentMemberInfo() {
MemberVO memberVO = memberService.getCurrentMemberInfo();
public Result<MemberVO> getCurrMemberInfo() {
MemberVO memberVO = memberService.getCurrMemberInfo();
return Result.success(memberVO);
}
@ -62,8 +59,7 @@ public class MemberController {
Long memberId = MemberUtils.getMemberId();
boolean result = memberService.update(new LambdaUpdateWrapper<UmsMember>()
.setSql("balance = balance - " + balances)
.eq(UmsMember::getId, memberId)
);
.eq(UmsMember::getId, memberId));
return Result.judge(result);
}
@ -89,9 +85,7 @@ public class MemberController {
@ApiOperation(value = "根据 openid 获取会员认证信息")
@GetMapping("/openid/{openid}")
public Result<MemberAuthDTO> getByOpenid(
@ApiParam("微信身份标识") @PathVariable String openid
) {
public Result<MemberAuthDTO> getByOpenid(@ApiParam("微信身份标识") @PathVariable String openid) {
MemberAuthDTO memberAuthInfo = memberService.getByOpenid(openid);
if (memberAuthInfo == null) {
return Result.failed(ResultCode.USER_NOT_EXIST);
@ -102,20 +96,23 @@ public class MemberController {
/**
* 根据手机号获取会员认证信息
*
* @param mobile
* @param mobile 手机号码
* @return
*/
@GetMapping("/mobile/{mobile}")
public Result<MemberAuthDTO> getByMobile(
@ApiParam("手机号码") @PathVariable String mobile
) {
MemberAuthDTO memberAuthInfo = memberService.getByMobile(mobile);
public Result<MemberAuthDTO> getMemberByMobile(@ApiParam("手机号码") @PathVariable String mobile) {
MemberAuthDTO memberAuthInfo = memberService.getMemberByMobile(mobile);
if (memberAuthInfo == null) {
return Result.failed(ResultCode.USER_NOT_EXIST);
}
return Result.success(memberAuthInfo);
}
@ApiOperation("获取会员地址列表")
@GetMapping("/{memberId}/addresses")
public Result<List<MemberAddressDTO>> listMemberAddress(@ApiParam("会员ID") @PathVariable Long memberId) {
List<MemberAddressDTO> addresses = memberService.listMemberAddress(memberId);
return Result.success(addresses);
}
}

View File

@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.vo.ProductHistoryVO;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import com.youlai.mall.ums.dto.MemberAuthDTO;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.dto.MemberInfoDTO;
import com.youlai.mall.ums.pojo.entity.UmsMember;
import com.youlai.mall.ums.pojo.vo.MemberVO;
import java.util.List;
import java.util.Set;
/**
@ -41,7 +43,7 @@ public interface IUmsMemberService extends IService<UmsMember> {
* @param mobile
* @return
*/
MemberAuthDTO getByMobile(String mobile);
MemberAuthDTO getMemberByMobile(String mobile);
/**
* 新增会员
@ -56,9 +58,16 @@ public interface IUmsMemberService extends IService<UmsMember> {
*
* @return
*/
MemberVO getCurrentMemberInfo();
MemberVO getCurrMemberInfo();
/**
* 获取会员地址列表
*
* @param memberId
* @return
*/
List<MemberAddressDTO> listMemberAddress(Long memberId);
/**
* 实验室修改会员余额
*
@ -84,4 +93,7 @@ public interface IUmsMemberService extends IService<UmsMember> {
* @return
*/
MemberInfoDTO getMemberInfo(Long memberId);
}

View File

@ -11,15 +11,20 @@ import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.web.utils.MemberUtils;
import com.youlai.mall.pms.pojo.vo.ProductHistoryVO;
import com.youlai.mall.ums.constant.UmsConstants;
import com.youlai.mall.ums.convert.AddressConvert;
import com.youlai.mall.ums.convert.MemberConvert;
import com.youlai.mall.ums.dto.MemberAddressDTO;
import com.youlai.mall.ums.dto.MemberAuthDTO;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.dto.MemberInfoDTO;
import com.youlai.mall.ums.mapper.UmsMemberMapper;
import com.youlai.mall.ums.pojo.entity.UmsAddress;
import com.youlai.mall.ums.pojo.entity.UmsMember;
import com.youlai.mall.ums.pojo.vo.MemberVO;
import com.youlai.mall.ums.service.IUmsAddressService;
import com.youlai.mall.ums.service.IUmsMemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -35,11 +40,15 @@ import java.util.Set;
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class UmsMemberServiceImpl extends ServiceImpl<UmsMemberMapper, UmsMember> implements IUmsMemberService {
private final RedisTemplate redisTemplate;
private final MemberConvert memberConvert;
private final AddressConvert addressConvert;
private final IUmsAddressService addressService;
@Override
public IPage<UmsMember> list(Page<UmsMember> page, String nickname) {
List<UmsMember> list = this.baseMapper.list(page, nickname);
@ -90,7 +99,7 @@ public class UmsMemberServiceImpl extends ServiceImpl<UmsMemberMapper, UmsMember
* @return
*/
@Override
public MemberAuthDTO getByMobile(String mobile) {
public MemberAuthDTO getMemberByMobile(String mobile) {
UmsMember entity = this.getOne(new LambdaQueryWrapper<UmsMember>()
.eq(UmsMember::getMobile, mobile)
.select(UmsMember::getId,
@ -126,7 +135,7 @@ public class UmsMemberServiceImpl extends ServiceImpl<UmsMemberMapper, UmsMember
* @return
*/
@Override
public MemberVO getCurrentMemberInfo() {
public MemberVO getCurrMemberInfo() {
Long memberId = MemberUtils.getMemberId();
UmsMember umsMember = this.getOne(new LambdaQueryWrapper<UmsMember>()
.eq(UmsMember::getId, memberId)
@ -142,6 +151,25 @@ public class UmsMemberServiceImpl extends ServiceImpl<UmsMemberMapper, UmsMember
return memberVO;
}
/**
* 获取会员地址
*
* @param memberId
* @return
*/
@Override
public List<MemberAddressDTO> listMemberAddress(Long memberId) {
log.info("memberId:{}", MemberUtils.getMemberId());
List<UmsAddress> entities = addressService.list(
new LambdaQueryWrapper<UmsAddress>()
.eq(UmsAddress::getMemberId, memberId)
);
List<MemberAddressDTO> list = addressConvert.entity2DTO(entities);
return list;
}
/**
* 实验室修改会员余额