feat(微信用户): 新增微信用户管理模块

新增微信用户管理模块,包括实体类、Mapper、Service、DTO、查询条件、命令类、模型工厂、应用服务及控制器,实现对微信用户信息的增删改查功能。
This commit is contained in:
dzq 2025-04-07 14:58:27 +08:00
parent 090bd7ecbe
commit e01ddf0b9c
14 changed files with 477 additions and 1 deletions

View File

@ -0,0 +1,68 @@
package com.agileboot.admin.controller.shop;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.shop.wxuser.WxUserInfoApplicationService;
import com.agileboot.domain.shop.wxuser.command.AddWxUserInfoCommand;
import com.agileboot.domain.shop.wxuser.command.UpdateWxUserInfoCommand;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoEntity;
import com.agileboot.domain.shop.wxuser.dto.WxUserInfoDTO;
import com.agileboot.domain.shop.wxuser.query.SearchWxUserInfoQuery;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.RestController;
@RestController
@RequestMapping("/shop/wxuser")
@RequiredArgsConstructor
@Validated
public class WxUserInfoController extends BaseController {
private final WxUserInfoApplicationService applicationService;
@Operation(summary = "微信用户列表")
@GetMapping
public ResponseDTO<PageDTO<WxUserInfoDTO>> list(SearchWxUserInfoQuery<WxUserInfoEntity> query) {
PageDTO<WxUserInfoDTO> page = applicationService.getWxUserList(query);
return ResponseDTO.ok(page);
}
@Operation(summary = "新增微信用户")
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.ADD)
@PostMapping
public ResponseDTO<Void> add(@Validated @RequestBody AddWxUserInfoCommand command) {
applicationService.addWxUser(command);
return ResponseDTO.ok();
}
@Operation(summary = "修改微信用户")
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping("/{id}")
public ResponseDTO<Void> edit(@PathVariable Long id, @Validated @RequestBody UpdateWxUserInfoCommand command) {
command.setWxUserId(id);
applicationService.updateWxUser(command);
return ResponseDTO.ok();
}
@Operation(summary = "删除微信用户")
@AccessLog(title = "微信用户管理", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/{ids}")
public ResponseDTO<Void> remove(@PathVariable @NotNull List<Long> ids) {
applicationService.deleteWxUser(new BulkOperationCommand<>(ids));
return ResponseDTO.ok();
}
}

View File

@ -0,0 +1,51 @@
package com.agileboot.domain.shop.wxuser;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.shop.wxuser.command.AddWxUserInfoCommand;
import com.agileboot.domain.shop.wxuser.command.UpdateWxUserInfoCommand;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoEntity;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoService;
import com.agileboot.domain.shop.wxuser.dto.WxUserInfoDTO;
import com.agileboot.domain.shop.wxuser.model.WxUserInfoModel;
import com.agileboot.domain.shop.wxuser.model.WxUserInfoModelFactory;
import com.agileboot.domain.shop.wxuser.query.SearchWxUserInfoQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class WxUserInfoApplicationService {
private final WxUserInfoService wxUserInfoService;
private final WxUserInfoModelFactory wxUserInfoModelFactory;
public PageDTO<WxUserInfoDTO> getWxUserList(SearchWxUserInfoQuery<WxUserInfoEntity> query) {
Page<WxUserInfoEntity> page = wxUserInfoService.getWxUserInfoList(query);
List<WxUserInfoDTO> dtoList = page.getRecords().stream()
.map(WxUserInfoDTO::new)
.collect(Collectors.toList());
return new PageDTO<>(dtoList, page.getTotal());
}
public void addWxUser(AddWxUserInfoCommand command) {
WxUserInfoModel model = wxUserInfoModelFactory.create();
model.loadAddCommand(command);
model.insert();
}
public void updateWxUser(UpdateWxUserInfoCommand command) {
WxUserInfoModel model = wxUserInfoModelFactory.loadById(command.getWxUserId());
model.loadUpdateCommand(command);
model.updateById();
}
public void deleteWxUser(BulkOperationCommand<Long> command) {
for (Long id : command.getIds()) {
WxUserInfoModel model = wxUserInfoModelFactory.loadById(id);
model.deleteById();
}
}
}

View File

@ -0,0 +1,11 @@
package com.agileboot.domain.shop.wxuser.command;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class AddWxUserInfoCommand extends WxUserInfoEntity {
}

View File

@ -0,0 +1,16 @@
package com.agileboot.domain.shop.wxuser.command;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class UpdateWxUserInfoCommand extends AddWxUserInfoCommand {
@NotNull
@PositiveOrZero
private Long wxUserId;
}

View File

@ -0,0 +1,56 @@
package com.agileboot.domain.shop.wxuser.db;
import com.agileboot.common.core.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 微信用户基本信息表
* </p>
*
* @author valarchie
* @since 2025-04-07
*/
@Getter
@Setter
@TableName("wx_user_info")
@ApiModel(value = "WxUserInfoEntity对象", description = "微信用户基本信息表")
public class WxUserInfoEntity extends BaseEntity<WxUserInfoEntity> {
private static final long serialVersionUID = 1L;
@ApiModelProperty("微信用户唯一ID")
@TableId(value = "wx_user_id", type = IdType.AUTO)
private Long wxUserId;
@ApiModelProperty("微信开放平台唯一标识")
@TableField("openid")
private String openid;
@ApiModelProperty("用户昵称")
@TableField("nickname")
private String nickname;
@ApiModelProperty("性别0未知 1男 2女")
@TableField("sex")
private Integer sex;
@ApiModelProperty("手机号码")
@TableField("mobile")
private String mobile;
@Override
public Serializable pkVal() {
return this.wxUserId;
}
}

View File

@ -0,0 +1,46 @@
package com.agileboot.domain.shop.wxuser.db;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* <p>
* 微信用户基本信息表 Mapper 接口
* </p>
*
* @author valarchie
* @since 2025-04-07
*/
public interface WxUserInfoMapper extends BaseMapper<WxUserInfoEntity> {
@Select("SELECT wx_user_id, openid, nickname, sex, mobile " +
"FROM wx_user_info " +
"${ew.customSqlSegment}")
Page<WxUserInfoEntity> getWxUserInfoList(
Page<WxUserInfoEntity> page,
@Param(Constants.WRAPPER) Wrapper<WxUserInfoEntity> queryWrapper
);
@Select("SELECT * " +
"FROM wx_user_info " +
"WHERE enable = '1' " +
"ORDER BY create_time DESC " +
"LIMIT 1")
WxUserInfoEntity selectFirstEnabled();
@Select("SELECT * " +
"FROM wx_user_info " +
"WHERE enable = '1' " +
"ORDER BY create_time DESC")
List<WxUserInfoEntity> selectAllEnabled();
@Select("SELECT * FROM wx_user_info WHERE openid = #{openid} LIMIT 1")
WxUserInfoEntity selectByOpenid(String openid);
@Select("SELECT * FROM wx_user_info WHERE wx_user_id = #{wxUserId} LIMIT 1")
WxUserInfoEntity selectByWxUserId(Long wxUserId);
}

View File

@ -0,0 +1,27 @@
package com.agileboot.domain.shop.wxuser.db;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* <p>
* 微信用户基本信息表 服务类
* </p>
*
* @author valarchie
* @since 2025-04-07
*/
public interface WxUserInfoService extends IService<WxUserInfoEntity> {
Page<WxUserInfoEntity> getWxUserInfoList(AbstractPageQuery<WxUserInfoEntity> query);
List<WxUserInfoEntity> selectAllEnabled();
WxUserInfoEntity selectFirstEnabled();
WxUserInfoEntity selectByOpenid(String openid);
WxUserInfoEntity selectByWxUserId(Long wxUserId);
}

View File

@ -0,0 +1,46 @@
package com.agileboot.domain.shop.wxuser.db;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 微信用户基本信息表 服务实现类
* </p>
*
* @author valarchie
* @since 2025-04-07
*/
@Service
public class WxUserInfoServiceImpl extends ServiceImpl<WxUserInfoMapper, WxUserInfoEntity> implements WxUserInfoService {
@Override
public Page<WxUserInfoEntity> getWxUserInfoList(AbstractPageQuery<WxUserInfoEntity> query) {
return this.page(query.toPage(), query.toQueryWrapper());
}
@Override
public List<WxUserInfoEntity> selectAllEnabled() {
return baseMapper.selectAllEnabled();
}
@Override
public WxUserInfoEntity selectFirstEnabled() {
return baseMapper.selectFirstEnabled();
}
@Override
public WxUserInfoEntity selectByOpenid(String openid) {
return baseMapper.selectByOpenid(openid);
}
@Override
public WxUserInfoEntity selectByWxUserId(Long wxUserId) {
return baseMapper.selectByWxUserId(wxUserId);
}
}

View File

@ -0,0 +1,48 @@
package com.agileboot.domain.shop.wxuser.dto;
import cn.hutool.core.bean.BeanUtil;
import com.agileboot.common.annotation.ExcelColumn;
import com.agileboot.common.annotation.ExcelSheet;
import com.agileboot.domain.common.cache.CacheCenter;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoEntity;
import com.agileboot.domain.system.user.db.SysUserEntity;
import lombok.Data;
@ExcelSheet(name = "微信用户信息列表")
@Data
public class WxUserInfoDTO {
public WxUserInfoDTO(WxUserInfoEntity entity) {
if (entity != null) {
BeanUtil.copyProperties(entity, this);
switch (entity.getSex()) {
case 1:
this.sexStr = "";
break;
case 2:
this.sexStr = "";
break;
default:
this.sexStr = "未知";
}
}
}
@ExcelColumn(name = "微信用户ID")
private Long wxUserId;
@ExcelColumn(name = "微信开放平台ID")
private String openid;
@ExcelColumn(name = "用户昵称")
private String nickname;
private Integer sex;
@ExcelColumn(name = "性别")
private String sexStr;
@ExcelColumn(name = "手机号码")
private String mobile;
}

View File

@ -0,0 +1,37 @@
package com.agileboot.domain.shop.wxuser.model;
import cn.hutool.core.bean.BeanUtil;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoEntity;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoService;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class WxUserInfoModel extends WxUserInfoEntity {
private WxUserInfoService wxUserInfoService;
public WxUserInfoModel(WxUserInfoEntity entity, WxUserInfoService wxUserInfoService) {
this(wxUserInfoService);
if (entity != null) {
BeanUtil.copyProperties(entity, this);
}
}
public WxUserInfoModel(WxUserInfoService wxUserInfoService) {
this.wxUserInfoService = wxUserInfoService;
}
public void loadAddCommand(Object addCommand) {
if (addCommand != null) {
BeanUtil.copyProperties(addCommand, this, "id");
}
}
public void loadUpdateCommand(Object updateCommand) {
if (updateCommand != null) {
loadAddCommand(updateCommand);
}
}
}

View File

@ -0,0 +1,27 @@
package com.agileboot.domain.shop.wxuser.model;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoEntity;
import com.agileboot.domain.shop.wxuser.db.WxUserInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class WxUserInfoModelFactory {
private final WxUserInfoService wxUserInfoService;
public WxUserInfoModel loadById(Long wxUserId) {
WxUserInfoEntity entity = wxUserInfoService.getById(wxUserId);
if (entity == null) {
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, wxUserId, "微信用户");
}
return new WxUserInfoModel(entity, wxUserInfoService);
}
public WxUserInfoModel create() {
return new WxUserInfoModel(wxUserInfoService);
}
}

View File

@ -0,0 +1,38 @@
package com.agileboot.domain.shop.wxuser.query;
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 lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class SearchWxUserInfoQuery<T> extends AbstractPageQuery<T> {
private Long wxUserId;
private String openid;
private String nickname;
private Integer sex;
private String mobile;
private Date startTime;
private Date endTime;
@Override
public QueryWrapper<T> addQueryCondition() {
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
queryWrapper
.eq(wxUserId != null, "wx_user_id", wxUserId)
.eq(StrUtil.isNotEmpty(openid), "openid", openid)
.like(StrUtil.isNotEmpty(nickname), "nickname", nickname)
.eq(sex != null, "sex", sex)
.eq(StrUtil.isNotEmpty(mobile), "mobile", mobile)
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
this.timeRangeColumn = "create_time";
return queryWrapper;
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.agileboot.domain.shop.wxuser.db.WxUserInfoMapper">
</mapper>

View File

@ -61,7 +61,7 @@ public class CodeGenerator {
//生成的类 放在orm子模块下的/target/generated-code目录底下 //生成的类 放在orm子模块下的/target/generated-code目录底下
.module("/agileboot-orm/target/generated-code") .module("/agileboot-orm/target/generated-code")
.parentPackage("com.agileboot") .parentPackage("com.agileboot")
.tableName("return_approval") .tableName("wx_user_info")
// 决定是否继承基类 // 决定是否继承基类
.isExtendsFromBaseEntity(true) .isExtendsFromBaseEntity(true)
.build(); .build();