feat(微信用户): 新增微信用户管理接口及订单查询功能
- 新增WxUserController提供微信用户CRUD及余额管理接口 - 修改订单查询逻辑,支持通过ab98UserId查询关联订单 - 调整新用户创建时的初始余额为0
This commit is contained in:
parent
cd9913419b
commit
35870dc1f1
|
|
@ -0,0 +1,138 @@
|
|||
package com.agileboot.admin.controller.wx;
|
||||
|
||||
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.wx.user.WxUserApplicationService;
|
||||
import com.agileboot.domain.wx.user.command.AddWxUserCommand;
|
||||
import com.agileboot.domain.wx.user.command.UpdateWxUserCommand;
|
||||
import com.agileboot.domain.wx.user.db.SearchWxUserDO;
|
||||
import com.agileboot.domain.wx.user.dto.WxUserDTO;
|
||||
import com.agileboot.domain.wx.user.query.SearchWxUserQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Positive;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wx/users")
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class WxUserController {
|
||||
|
||||
private final WxUserApplicationService userApplicationService;
|
||||
|
||||
@Operation(summary = "微信用户列表(分页)")
|
||||
@GetMapping
|
||||
public ResponseDTO<PageDTO<WxUserDTO>> list(SearchWxUserQuery<SearchWxUserDO> query) {
|
||||
PageDTO<WxUserDTO> page = userApplicationService.getUserList(query);
|
||||
return ResponseDTO.ok(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "微信用户详情")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ResponseDTO<WxUserDTO> detail(@Parameter(description = "微信用户ID", required = true) @PathVariable @NotNull @Positive Long id) {
|
||||
WxUserDTO wxUserDetail = userApplicationService.getUserDetailInfo(id);
|
||||
return ResponseDTO.ok(wxUserDetail);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据openid获取微信用户详情")
|
||||
@GetMapping("/detail/by-openid")
|
||||
public ResponseDTO<WxUserDTO> detailByOpenid(@Parameter(description = "微信openid", required = true) @RequestParam @NotNull String openid) {
|
||||
WxUserDTO wxUserDetail = userApplicationService.getUserDetailByOpenid(openid);
|
||||
return ResponseDTO.ok(wxUserDetail);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据openid获取或创建微信用户")
|
||||
@GetMapping("/get-or-create/by-openid")
|
||||
public ResponseDTO<WxUserDTO> getOrCreateUserByOpenid(
|
||||
@Parameter(description = "微信openid", required = true) @RequestParam @NotNull String openid) {
|
||||
WxUserDTO wxUser = userApplicationService.getOrCreateUserByOpenid(openid);
|
||||
return ResponseDTO.ok(wxUser);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增微信用户")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.ADD)
|
||||
@PostMapping
|
||||
public ResponseDTO<Void> add(@Validated @RequestBody AddWxUserCommand command) {
|
||||
userApplicationService.addUser(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改微信用户")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PutMapping("/{id}")
|
||||
public ResponseDTO<Void> edit(@Parameter(description = "微信用户ID", required = true) @PathVariable @NotNull @Positive Long id,
|
||||
@Validated @RequestBody UpdateWxUserCommand command) {
|
||||
command.setWxUserId(id);
|
||||
userApplicationService.updateUser(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除微信用户")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.DELETE)
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseDTO<Void> remove(@Parameter(description = "微信用户ID", required = true) @PathVariable @NotNull @Positive Long id) {
|
||||
userApplicationService.deleteUser(id);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "批量删除微信用户")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.DELETE)
|
||||
@DeleteMapping("/batch/{ids}")
|
||||
public ResponseDTO<Void> removeBatch(@Parameter(description = "微信用户ID列表", required = true) @PathVariable @NotNull List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "用户ID列表不能为空"));
|
||||
}
|
||||
userApplicationService.deleteUsers(new BulkOperationCommand<>(ids));
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "增加微信用户余额")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PostMapping("/{id}/increase-balance")
|
||||
public ResponseDTO<Void> increaseBalance(
|
||||
@Parameter(description = "微信用户ID", required = true) @PathVariable @NotNull @Positive Long id,
|
||||
@Parameter(description = "增加金额(分)", required = true) @RequestParam @NotNull @Positive Integer amount) {
|
||||
userApplicationService.increaseBalance(id, amount);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "减少微信用户余额")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PostMapping("/{id}/decrease-balance")
|
||||
public ResponseDTO<Void> decreaseBalance(
|
||||
@Parameter(description = "微信用户ID", required = true) @PathVariable @NotNull @Positive Long id,
|
||||
@Parameter(description = "减少金额(分)", required = true) @RequestParam @NotNull @Positive Integer amount) {
|
||||
userApplicationService.decreaseBalance(id, amount);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "设置微信用户余额")
|
||||
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.MODIFY)
|
||||
@PostMapping("/{id}/set-balance")
|
||||
public ResponseDTO<Void> setBalance(
|
||||
@Parameter(description = "微信用户ID", required = true) @PathVariable @NotNull @Positive Long id,
|
||||
@Parameter(description = "余额(分)", required = true) @RequestParam @NotNull @Positive Integer balance) {
|
||||
userApplicationService.setBalance(id, balance);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -107,6 +107,14 @@ public class OrderApplicationService {
|
|||
private WxshopConfig wxshopConfig;
|
||||
|
||||
public PageDTO<OrderWithGoodsDTO> getOrderList(SearchShopOrderQuery<OrderWithGoodsDTO> query) {
|
||||
if (query.getAb98UserId() != null) {
|
||||
query.setOpenidList(wxUserService.getAllByAb98UserId(query.getAb98UserId()).stream().map(WxUserEntity::getOpenid).collect(Collectors.toList()));
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getOpenid()) && query.getOpenidList() != null && !query.getOpenidList().isEmpty()
|
||||
&& !query.getOpenidList().contains(query.getOpenid())) {
|
||||
query.getOpenidList().add(query.getOpenid());
|
||||
query.setOpenid(null);
|
||||
}
|
||||
Page<OrderWithGoodsDTO> page = orderService.getOrderList(query);
|
||||
return new PageDTO<>(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -15,10 +17,12 @@ public class SearchShopOrderQuery<T> extends AbstractPageQuery<T> {
|
|||
|
||||
private Long orderId;
|
||||
private String openid;
|
||||
private List<String> openidList;
|
||||
private String userid;
|
||||
private Long cellId;
|
||||
private Long cabinetId;
|
||||
private Long goodsId;
|
||||
private Long ab98UserId;
|
||||
private Integer status;
|
||||
private Integer payStatus;
|
||||
private Date startTime;
|
||||
|
|
@ -45,6 +49,7 @@ public class SearchShopOrderQuery<T> extends AbstractPageQuery<T> {
|
|||
queryWrapper
|
||||
.eq(orderId != null, "o.order_id", orderId)
|
||||
.eq(cellId != null, "og.cell_id", cellId)
|
||||
.in(openidList != null && !openidList.isEmpty(), "o.openid", openidList)
|
||||
.eq(StrUtil.isNotBlank(openid) && StrUtil.isBlank(userid), "o.openid", StringUtils.trim(openid))
|
||||
.eq(StrUtil.isNotBlank(userid) && StrUtil.isBlank(openid), "o.userid", StringUtils.trim(userid))
|
||||
.or(StrUtil.isNotBlank(userid) && StrUtil.isNotBlank(openid),
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ public class WxUserApplicationService {
|
|||
userService.updateById(wxUserEntity);
|
||||
}
|
||||
|
||||
ab98UserApplicationService.createAb98UserBalance(ab98UserEntity.getAb98UserId(), command.getCorpid(), 100000L);
|
||||
ab98UserApplicationService.createAb98UserBalance(ab98UserEntity.getAb98UserId(), command.getCorpid(), 0L);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue