From 9dd57047b5204cab0d1d366033a5429cf1358cff Mon Sep 17 00:00:00 2001 From: dzq Date: Sat, 24 May 2025 16:12:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(qywx):=20=E6=B7=BB=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=94=A8=E6=88=B7=E6=80=BB=E4=BD=99=E9=A2=9D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增了获取企业微信用户总余额的功能,包括在QyUserService、QyUserMapper、QyUserApplicationService和QyUserController中添加相关方法和接口。同时,调整了ShopOrderGoodsMapper中的查询限制条件,并新增了用户VIP信息表和相关SQL脚本。 --- .../controller/qywx/QyUserController.java | 17 +++++---- .../qywx/user/QyUserApplicationService.java | 6 +++ .../domain/qywx/user/db/QyUserMapper.java | 12 ++++++ .../domain/qywx/user/db/QyUserService.java | 4 ++ .../qywx/user/db/QyUserServiceImpl.java | 12 ++++++ .../qywx/user/query/SearchQyUserQuery.java | 5 +++ .../shop/order/db/ShopOrderGoodsMapper.java | 4 +- sql/20250522_ab98_user_vip.sql | 38 +++++++++++++++++++ 8 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 sql/20250522_ab98_user_vip.sql diff --git a/agileboot-admin/src/main/java/com/agileboot/admin/controller/qywx/QyUserController.java b/agileboot-admin/src/main/java/com/agileboot/admin/controller/qywx/QyUserController.java index fe25075..023d198 100644 --- a/agileboot-admin/src/main/java/com/agileboot/admin/controller/qywx/QyUserController.java +++ b/agileboot-admin/src/main/java/com/agileboot/admin/controller/qywx/QyUserController.java @@ -20,18 +20,13 @@ import com.agileboot.domain.qywx.user.db.QyUserEntity; import com.agileboot.domain.qywx.user.dto.QyUserDTO; import com.agileboot.domain.qywx.user.query.SearchQyUserQuery; import io.swagger.v3.oas.annotations.Operation; + +import java.math.BigDecimal; 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; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/qywx/users") @@ -108,4 +103,10 @@ public class QyUserController extends BaseController { UserIdResponse response = QywxApiUtil.convertToUserid(accessToken.getAccessToken(), openid); return ResponseDTO.ok(JSONUtil.toJsonStr(response)); } + + @GetMapping("/getTotalBalance") + public ResponseDTO getTotalBalance(@RequestParam(required = false) String corpid) { + BigDecimal totalBalance = qyUserApplicationService.selectTotalBalance(corpid); + return ResponseDTO.ok(totalBalance); + } } \ No newline at end of file diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/QyUserApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/QyUserApplicationService.java index e7edcbd..34cdf7c 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/QyUserApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/QyUserApplicationService.java @@ -21,6 +21,8 @@ import com.agileboot.domain.system.user.db.SysUserEntity; import com.agileboot.domain.system.user.db.SysUserService; import com.agileboot.domain.system.user.dto.UserDTO; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.math.BigDecimal; import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -133,4 +135,8 @@ public class QyUserApplicationService { } } } + + public BigDecimal selectTotalBalance(String corpid) { + return userService.selectTotalBalance(corpid); + } } \ No newline at end of file diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserMapper.java b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserMapper.java index 382fea8..5d52a97 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserMapper.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserMapper.java @@ -4,6 +4,8 @@ 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.math.BigDecimal; import java.util.List; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -43,4 +45,14 @@ public interface QyUserMapper extends BaseMapper { "AND sr.role_key = 'admin'") List selectAdminUserIds(); + @Select("SELECT SUM(balance) " + + "FROM qy_user " + + "WHERE deleted = 0") + BigDecimal selectTotalBalance(); + + @Select("SELECT SUM(balance) " + + "FROM qy_user " + + "WHERE deleted = 0 AND corpid = #{corpid}") + BigDecimal selectTotalBalanceByCorpid(@Param("corpid") String corpid); + } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserService.java b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserService.java index 5dbff87..3f70970 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserService.java @@ -3,6 +3,8 @@ package com.agileboot.domain.qywx.user.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.math.BigDecimal; import java.util.List; /** @@ -22,4 +24,6 @@ public interface QyUserService extends IService { QyUserEntity getUserByUserId(String userid, String corpid); List selectAdminUserIds(); + + BigDecimal selectTotalBalance(String corpid); } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserServiceImpl.java b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserServiceImpl.java index aaa06ce..b5e7868 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserServiceImpl.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/db/QyUserServiceImpl.java @@ -1,6 +1,7 @@ package com.agileboot.domain.qywx.user.db; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; /** @@ -14,6 +15,8 @@ import org.springframework.stereotype.Service; import com.agileboot.common.core.page.AbstractPageQuery; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.math.BigDecimal; import java.util.List; @Service @@ -43,4 +46,13 @@ public class QyUserServiceImpl extends ServiceImpl i public List selectAdminUserIds() { return baseMapper.selectAdminUserIds(); } + + @Override + public BigDecimal selectTotalBalance(String corpid) { + if (StringUtils.isBlank(corpid)) { + return baseMapper.selectTotalBalance(); + } else { + return baseMapper.selectTotalBalanceByCorpid(corpid); + } + } } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/query/SearchQyUserQuery.java b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/query/SearchQyUserQuery.java index d6cac70..a7aebd8 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/query/SearchQyUserQuery.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/qywx/user/query/SearchQyUserQuery.java @@ -3,6 +3,8 @@ package com.agileboot.domain.qywx.user.query; import cn.hutool.core.util.StrUtil; import com.agileboot.common.core.page.AbstractPageQuery; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import java.math.BigDecimal; import java.util.Date; import lombok.Data; import lombok.EqualsAndHashCode; @@ -21,6 +23,8 @@ public class SearchQyUserQuery extends AbstractPageQuery { private Date startTime; private Date endTime; private Long sysRoleId; + // 是否查询余额大于0的用户,1为是 + private Integer balancePage; @Override public QueryWrapper addQueryCondition() { @@ -35,6 +39,7 @@ public class SearchQyUserQuery extends AbstractPageQuery { .eq(StrUtil.isNotBlank(department), "department", department) .eq(StrUtil.isNotBlank(mainDepartment), "main_department", mainDepartment) .eq(StrUtil.isNotBlank(enable), "enable", enable) + .gt(balancePage != null && balancePage.equals(1), "balance", BigDecimal.ZERO) .between(startTime != null && endTime != null, "create_time", startTime, endTime) .orderByDesc("id"); diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsMapper.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsMapper.java index 0c0e692..78b2fd3 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsMapper.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsMapper.java @@ -30,7 +30,7 @@ public interface ShopOrderGoodsMapper extends BaseMapper { "WHERE sog.deleted = 0 AND sg.deleted = 0 AND sog.goods_id != 6 " + "GROUP BY sog.goods_id, sg.goods_name, sg.cover_img " + "ORDER BY occurrence_count DESC " + - "LIMIT 10") + "LIMIT 9") List selectTopGoodsByOccurrence(); @Select("SELECT sog.*, so.name AS buyer_name " + @@ -39,7 +39,7 @@ public interface ShopOrderGoodsMapper extends BaseMapper { "WHERE sog.deleted = 0 AND so.deleted = 0 " + "AND DATE(sog.create_time) = CURRENT_DATE " + "ORDER BY sog.create_time DESC " + - "LIMIT 10") + "LIMIT 4") List selectTodayLatestOrderGoods(); @Select("SELECT og.* " + diff --git a/sql/20250522_ab98_user_vip.sql b/sql/20250522_ab98_user_vip.sql new file mode 100644 index 0000000..293dd63 --- /dev/null +++ b/sql/20250522_ab98_user_vip.sql @@ -0,0 +1,38 @@ +DROP TABLE IF EXISTS `ab98_user_vip`; + +CREATE TABLE `ab98_user_vip` ( + `vip_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `ab98_user_id` BIGINT NOT NULL COMMENT '关联用户ID', + `vip_level` TINYINT NOT NULL DEFAULT 1 COMMENT 'VIP等级', + `start_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '会员开始时间', + `end_time` DATETIME NULL COMMENT '会员结束时间', + `status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '状态(1有效 0无效)', + `creator_id` BIGINT DEFAULT 0 COMMENT '创建者ID', + `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater_id` BIGINT DEFAULT 0 COMMENT '更新者ID', + `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)', + PRIMARY KEY (`vip_id`), + KEY `idx_user` (`ab98_user_id`), + KEY `idx_level` (`vip_level`), + CONSTRAINT `fk_vip_user` FOREIGN KEY (`ab98_user_id`) REFERENCES `ab98_user` (`ab98_user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户VIP信息表'; + +DROP TABLE IF EXISTS `ab98_vip_level`; + +CREATE TABLE `ab98_vip_level` ( + `level_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `level_name` VARCHAR(50) NOT NULL COMMENT '等级名称', + `level_value` TINYINT NOT NULL COMMENT '等级值', + `discount_rate` DECIMAL(5,2) NOT NULL COMMENT '折扣率', + `point_multiplier` DECIMAL(5,2) NOT NULL COMMENT '积分倍数', + `free_shipping` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否免邮(0否 1是)', + `birthday_benefit` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '生日特权(0无 1有)', + `creator_id` BIGINT DEFAULT 0 COMMENT '创建者ID', + `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater_id` BIGINT DEFAULT 0 COMMENT '更新者ID', + `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)', + PRIMARY KEY (`level_id`), + UNIQUE KEY `uk_level` (`level_value`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='VIP等级权限表'; \ No newline at end of file