共富商城
This commit is contained in:
1 parent
d747ad5241
commit
b5c78ec3d4
20 files changed
+278
-298
No files matched your search
+1
-1
@@ -58,7 +58,7 @@ public class MallCategoryEntity extends Model<MallCategoryEntity> {
|
||||
* 状态(0正常,1下架)
|
||||
*/
|
||||
@Schema(description="状态(0正常,1下架)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 分类图片
|
||||
|
||||
+64
-167
@@ -3,198 +3,95 @@ package com.bsd.pjcloud.supermarket.constant;
|
||||
/**
|
||||
* 商城相关常量
|
||||
*
|
||||
* @author zjf
|
||||
* @author pjcloud
|
||||
* @date 2025-01-27
|
||||
*/
|
||||
public class MallConstants {
|
||||
public interface MallConstants {
|
||||
|
||||
/**
|
||||
* 角色编码常量
|
||||
* 状态相关常量
|
||||
*/
|
||||
public static class RoleCode {
|
||||
/** 商户用户角色 */
|
||||
public static final String MERCHANT_USER = "MALL_MCH";
|
||||
|
||||
/** 商城用户角色 */
|
||||
// public static final String MALL_USER = "Mall_USER";
|
||||
/** 商城管理员角色 */
|
||||
// public static final String MALL_ADMIN = "Mall_ADMIN";
|
||||
interface Status {
|
||||
/**
|
||||
* 启用状态
|
||||
*/
|
||||
String ENABLED = "0";
|
||||
|
||||
/**
|
||||
* 禁用状态
|
||||
*/
|
||||
String DISABLED = "1";
|
||||
|
||||
/**
|
||||
* 上架状态
|
||||
*/
|
||||
String ON_SALE = "1";
|
||||
|
||||
/**
|
||||
* 下架状态
|
||||
*/
|
||||
String OFF_SALE = "0";
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户用户角色类型
|
||||
* 角色相关常量
|
||||
*/
|
||||
public static class MerchantUserRoleType {
|
||||
/** 管理员 */
|
||||
public static final Integer ADMIN = 1;
|
||||
/** 普通用户 */
|
||||
public static final Integer USER = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态常量
|
||||
*/
|
||||
public static class Status {
|
||||
/** 启用 */
|
||||
public static final Integer ENABLED = 1;
|
||||
/** 禁用 */
|
||||
public static final Integer DISABLED = 0;
|
||||
interface RoleCode {
|
||||
/**
|
||||
* 商户用户角色
|
||||
*/
|
||||
String MERCHANT_USER = "MALL_MCH";
|
||||
|
||||
/**
|
||||
* 超市管理员角色
|
||||
*/
|
||||
String SUPERMARKET_ADMIN = "SUPERMARKET_ADMIN";
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品相关常量
|
||||
*/
|
||||
public static class Product {
|
||||
/** 商品状态 - 上架 */
|
||||
public static final Integer STATUS_ON_SALE = 1;
|
||||
/** 商品状态 - 下架 */
|
||||
public static final Integer STATUS_OFF_SALE = 0;
|
||||
/** 商品状态 - 草稿 */
|
||||
public static final Integer STATUS_DRAFT = 2;
|
||||
interface Product {
|
||||
/**
|
||||
* 定价方式 - 多SKU
|
||||
*/
|
||||
Integer PRICE_TYPE_MULTI_SKU = 1;
|
||||
|
||||
/** 价格类型 - 统一价格 */
|
||||
public static final Integer PRICE_TYPE_UNIFIED = 1;
|
||||
/** 价格类型 - SKU价格 */
|
||||
public static final Integer PRICE_TYPE_SKU = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类相关常量
|
||||
*/
|
||||
public static class Category {
|
||||
/** 分类状态 - 启用 */
|
||||
public static final Integer STATUS_ENABLED = 0;
|
||||
/** 分类状态 - 禁用 */
|
||||
public static final Integer STATUS_DISABLED = 1;
|
||||
/**
|
||||
* 定价方式 - 单价SPU
|
||||
*/
|
||||
Integer PRICE_TYPE_SINGLE_SPU = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户相关常量
|
||||
*/
|
||||
public static class Merchant {
|
||||
/** 商户状态 - 正常 */
|
||||
public static final Integer STATUS_NORMAL = 1;
|
||||
/** 商户状态 - 停用 */
|
||||
public static final Integer STATUS_DISABLED = 0;
|
||||
/** 商户状态 - 审核中 */
|
||||
public static final Integer STATUS_PENDING = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存相关常量
|
||||
*/
|
||||
public static class Stock {
|
||||
/** 库存操作 - 增加 */
|
||||
public static final String OPERATION_ADD = "ADD";
|
||||
/** 库存操作 - 减少 */
|
||||
public static final String OPERATION_REDUCE = "REDUCE";
|
||||
/** 库存操作 - 设置 */
|
||||
public static final String OPERATION_SET = "SET";
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单相关常量
|
||||
*/
|
||||
public static class Order {
|
||||
/** 订单状态 - 待支付 */
|
||||
public static final Integer STATUS_PENDING_PAYMENT = 1;
|
||||
/** 订单状态 - 已支付 */
|
||||
public static final Integer STATUS_PAID = 2;
|
||||
/** 订单状态 - 已发货 */
|
||||
public static final Integer STATUS_SHIPPED = 3;
|
||||
/** 订单状态 - 已完成 */
|
||||
public static final Integer STATUS_COMPLETED = 4;
|
||||
/** 订单状态 - 已取消 */
|
||||
public static final Integer STATUS_CANCELLED = 5;
|
||||
/** 订单状态 - 已退款 */
|
||||
public static final Integer STATUS_REFUNDED = 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限相关常量
|
||||
*/
|
||||
public static class Permission {
|
||||
/** 商品管理权限前缀 */
|
||||
public static final String PRODUCT_PREFIX = "supermarket_mallProduct_";
|
||||
/** 商户管理权限前缀 */
|
||||
public static final String MERCHANT_PREFIX = "supermarket_mallMerchant_";
|
||||
/** 分类管理权限前缀 */
|
||||
public static final String CATEGORY_PREFIX = "supermarket_mallCategory_";
|
||||
/** 商户用户绑定权限前缀 */
|
||||
public static final String MERCHANT_USER_PREFIX = "supermarket_mallMerchantUser_";
|
||||
interface Merchant {
|
||||
/**
|
||||
* 商户状态 - 正常
|
||||
*/
|
||||
String STATUS_NORMAL = "1";
|
||||
|
||||
/** 查看权限 */
|
||||
public static final String VIEW = "view";
|
||||
/** 新增权限 */
|
||||
public static final String ADD = "add";
|
||||
/** 编辑权限 */
|
||||
public static final String EDIT = "edit";
|
||||
/** 删除权限 */
|
||||
public static final String DEL = "del";
|
||||
/** 导出权限 */
|
||||
public static final String EXPORT = "export";
|
||||
/**
|
||||
* 商户状态 - 停用
|
||||
*/
|
||||
String STATUS_DISABLED = "0";
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存相关常量
|
||||
* 删除标记
|
||||
*/
|
||||
public static class Cache {
|
||||
/** 商品缓存前缀 */
|
||||
public static final String PRODUCT_PREFIX = "mall:product:";
|
||||
/** 商户缓存前缀 */
|
||||
public static final String MERCHANT_PREFIX = "mall:merchant:";
|
||||
/** 分类缓存前缀 */
|
||||
public static final String CATEGORY_PREFIX = "mall:category:";
|
||||
/** 用户商户绑定缓存前缀 */
|
||||
public static final String MERCHANT_USER_PREFIX = "mall:merchant_user:";
|
||||
interface DelFlag {
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
String NORMAL = "0";
|
||||
|
||||
/** 缓存过期时间 - 1小时 */
|
||||
public static final long EXPIRE_1_HOUR = 3600;
|
||||
/** 缓存过期时间 - 1天 */
|
||||
public static final long EXPIRE_1_DAY = 86400;
|
||||
/** 缓存过期时间 - 1周 */
|
||||
public static final long EXPIRE_1_WEEK = 604800;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页相关常量
|
||||
*/
|
||||
public static class Page {
|
||||
/** 默认页码 */
|
||||
public static final Integer DEFAULT_PAGE_NUM = 1;
|
||||
/** 默认页大小 */
|
||||
public static final Integer DEFAULT_PAGE_SIZE = 10;
|
||||
/** 最大页大小 */
|
||||
public static final Integer MAX_PAGE_SIZE = 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传相关常量
|
||||
*/
|
||||
public static class File {
|
||||
/** 图片文件类型 */
|
||||
public static final String[] IMAGE_TYPES = {"jpg", "jpeg", "png", "gif", "bmp", "webp"};
|
||||
/** 最大文件大小 - 5MB */
|
||||
public static final long MAX_FILE_SIZE = 5 * 1024 * 1024;
|
||||
/** 商品图片路径 */
|
||||
public static final String PRODUCT_IMAGE_PATH = "/mall/product/";
|
||||
/** 商户图片路径 */
|
||||
public static final String MERCHANT_IMAGE_PATH = "/mall/merchant/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务异常相关常量
|
||||
*/
|
||||
public static class ErrorCode {
|
||||
/** 用户未绑定商户 */
|
||||
public static final String USER_NOT_BOUND_MERCHANT = "USER_NOT_BOUND_MERCHANT";
|
||||
/** 商户不存在 */
|
||||
public static final String MERCHANT_NOT_EXISTS = "MERCHANT_NOT_EXISTS";
|
||||
/** 商品不存在 */
|
||||
public static final String PRODUCT_NOT_EXISTS = "PRODUCT_NOT_EXISTS";
|
||||
/** 库存不足 */
|
||||
public static final String INSUFFICIENT_STOCK = "INSUFFICIENT_STOCK";
|
||||
/** 权限不足 */
|
||||
public static final String INSUFFICIENT_PERMISSION = "INSUFFICIENT_PERMISSION";
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
String DELETED = "1";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+41
-101
@@ -242,20 +242,11 @@ public class MallAppController {
|
||||
@Operation(summary = "商户创建商品", description = "移动端商户创建商品,支持包含SKU")
|
||||
public R<String> createProduct(@RequestBody MallProductCreateDTO productCreateDTO) {
|
||||
try {
|
||||
// 获取当前用户绑定的商户ID
|
||||
Long currentUserId = SecurityUtils.getUser().getId();
|
||||
Long userMerchantId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
|
||||
if (userMerchantId == null) {
|
||||
return R.failed("用户未绑定商户");
|
||||
}
|
||||
|
||||
Long userMerchantId = validateMerchant();
|
||||
|
||||
// 自动设置商户ID
|
||||
productCreateDTO.setMerchantId(userMerchantId);
|
||||
|
||||
// 验证商户权限和状态
|
||||
validateMerchant(userMerchantId);
|
||||
|
||||
// 创建商品
|
||||
boolean success = mallProductService.createProductWithSkus(productCreateDTO);
|
||||
if (success) {
|
||||
@@ -275,37 +266,17 @@ public class MallAppController {
|
||||
@Operation(summary = "商户更新商品", description = "移动端商户更新商品,支持包含SKU")
|
||||
public R<String> updateProduct(@RequestBody MallProductCreateDTO productCreateDTO) {
|
||||
try {
|
||||
// 获取当前用户绑定的商户ID
|
||||
Long currentUserId = SecurityUtils.getUser().getId();
|
||||
|
||||
Long userMerchantId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
|
||||
if (userMerchantId == null) {
|
||||
return R.failed("用户未绑定商户");
|
||||
}
|
||||
|
||||
//验证商户
|
||||
Long merchantId = validateMerchant();
|
||||
//验证商品数据
|
||||
validateProductPermission(productCreateDTO.getId(),merchantId);
|
||||
|
||||
|
||||
// 验证商品ID
|
||||
if (productCreateDTO.getId() == null) {
|
||||
return R.failed("商品ID不能为空");
|
||||
}
|
||||
|
||||
// 验证商品是否存在
|
||||
MallProductEntity existingProduct = mallProductService.getById(productCreateDTO.getId());
|
||||
if (existingProduct == null) {
|
||||
return R.failed("商品不存在");
|
||||
}
|
||||
|
||||
// 验证商户权限(只能更新自己的商品)
|
||||
if (!userMerchantId.equals(existingProduct.getMerchantId())) {
|
||||
return R.failed("无权限更新此商品");
|
||||
}
|
||||
|
||||
// 自动设置商户ID
|
||||
productCreateDTO.setMerchantId(userMerchantId);
|
||||
|
||||
// 验证商户权限和状态
|
||||
validateMerchant(userMerchantId);
|
||||
|
||||
// 更新商品
|
||||
boolean success = mallProductService.updateProductWithSkus(productCreateDTO);
|
||||
if (success) {
|
||||
@@ -318,13 +289,18 @@ public class MallAppController {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateMerchant(Long merchantId) {
|
||||
/**
|
||||
* 验证商户权限和状态
|
||||
* @return 商户id
|
||||
*/
|
||||
private Long validateMerchant() {
|
||||
// 获取当前用户ID
|
||||
Long currentUserId = SecurityUtils.getUser().getId();
|
||||
if (currentUserId == null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
Long merchantIdByUserId=null;
|
||||
// 验证用户是否有商户角色
|
||||
List<Long> roleIds = SecurityUtils.getRoleIds();
|
||||
R<List<SysRole>> mallMchUserLists = remoteRoleService.findRolesByCodes(Arrays.asList(MallConstants.RoleCode.MERCHANT_USER));
|
||||
@@ -333,35 +309,34 @@ public class MallAppController {
|
||||
if (CollectionUtils.isEmpty(list) || CollUtil.isEmpty(roleIds) || !roleIds.contains(list.get(0).getRoleId())) {
|
||||
throw new BusinessException("请分配商户角色");
|
||||
}
|
||||
//有商户角色,然后查询自己绑定的商户信息
|
||||
merchantIdByUserId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
if (merchantIdByUserId == null){
|
||||
throw new BusinessException("当前用户未绑定商户");
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new BusinessException("基础用户服务异常");
|
||||
}
|
||||
|
||||
// 验证用户是否绑定到指定商户
|
||||
if (merchantId != null) {
|
||||
boolean hasPermission = mallMerchantUserService.hasPermission(currentUserId, merchantId);
|
||||
if (!hasPermission) {
|
||||
throw new BusinessException("无权限操作此商户的商品");
|
||||
}
|
||||
} else {
|
||||
// 如果没有指定商户ID,获取用户绑定的商户ID
|
||||
Long userMerchantId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
if (userMerchantId == null) {
|
||||
throw new BusinessException("用户未绑定商户");
|
||||
}
|
||||
}
|
||||
return merchantIdByUserId;
|
||||
}
|
||||
|
||||
// 验证商户是否存在和状态
|
||||
if (merchantId != null) {
|
||||
MallMerchantEntity merchant = mallMerchantService.getById(merchantId);
|
||||
if (merchant == null) {
|
||||
throw new BusinessException("商户不存在");
|
||||
}
|
||||
if (!MallConstants.Status.ENABLED.equals(merchant.getStatus())) {
|
||||
throw new BusinessException("商户状态异常,无法操作商品");
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证是否有处理该条商品数据的权限
|
||||
*/
|
||||
private void validateProductPermission(Long productId, Long merchantId) {
|
||||
|
||||
MallProductEntity mallProduct = mallProductService.getById(productId);
|
||||
if (mallProduct == null) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
if (!merchantId.equals(mallProduct.getMerchantId())) {
|
||||
throw new BusinessException("无权限处理此商品");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户获取自己的商品列表
|
||||
*/
|
||||
@@ -375,28 +350,9 @@ public class MallAppController {
|
||||
@RequestParam(required = false) Integer status
|
||||
) {
|
||||
try {
|
||||
// 获取当前用户绑定的商户ID
|
||||
Long currentUserId = SecurityUtils.getUser().getId();
|
||||
Long userMerchantId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
|
||||
if (userMerchantId == null) {
|
||||
return R.failed("用户未绑定商户");
|
||||
}
|
||||
|
||||
// 如果指定了商户ID,验证权限
|
||||
if (merchantId != null && !merchantId.equals(userMerchantId)) {
|
||||
return R.failed("无权限查看其他商户的商品");
|
||||
}
|
||||
|
||||
// 使用用户绑定的商户ID
|
||||
Long targetMerchantId = merchantId != null ? merchantId : userMerchantId;
|
||||
|
||||
// 验证商户是否存在
|
||||
MallMerchantEntity merchant = mallMerchantService.getById(targetMerchantId);
|
||||
if (merchant == null) {
|
||||
return R.failed("商户不存在");
|
||||
}
|
||||
|
||||
|
||||
Long targetMerchantId = validateMerchant();
|
||||
|
||||
LambdaQueryWrapper<MallProductEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(MallProductEntity::getMerchantId, targetMerchantId);
|
||||
wrapper.eq(categoryId != null, MallProductEntity::getCategoryId, categoryId);
|
||||
@@ -456,25 +412,9 @@ public class MallAppController {
|
||||
@Operation(summary = "商户删除商品", description = "移动端商户删除自己的商品")
|
||||
public R<String> deleteProduct(@PathVariable("id") Long id) {
|
||||
try {
|
||||
// 获取当前用户绑定的商户ID
|
||||
Long currentUserId = SecurityUtils.getUser().getId();
|
||||
Long userMerchantId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
|
||||
if (userMerchantId == null) {
|
||||
return R.failed("用户未绑定商户");
|
||||
}
|
||||
|
||||
// 验证商品是否存在
|
||||
MallProductEntity product = mallProductService.getById(id);
|
||||
if (product == null) {
|
||||
return R.failed("商品不存在");
|
||||
}
|
||||
|
||||
// 验证商户权限
|
||||
if (!userMerchantId.equals(product.getMerchantId())) {
|
||||
return R.failed("无权限删除此商品");
|
||||
}
|
||||
|
||||
|
||||
Long l = validateMerchant();
|
||||
validateProductPermission(id, l);
|
||||
// 删除商品(逻辑删除)
|
||||
boolean success = mallProductService.removeById(id);
|
||||
if (success) {
|
||||
|
||||
+56
-10
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.supermarket.dto.MerchantUserSingleBindDTO;
|
||||
import com.bsd.pjcloud.supermarket.entity.MallMerchantUserEntity;
|
||||
import com.bsd.pjcloud.supermarket.service.MallMerchantUserService;
|
||||
import com.bsd.pjcloud.supermarket.constant.MallConstants;
|
||||
import com.bsd.pjcloud.supermarket.vo.MallMerchantUserVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -71,9 +72,24 @@ public class MallMerchantUserController {
|
||||
@Operation(summary = "获取商户用户列表", description = "根据商户ID获取绑定的用户列表")
|
||||
@GetMapping("/merchant/{merchantId}/users")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_mallMerchant_view')" )
|
||||
public R<List<MallMerchantUserEntity>> getMerchantUsers(@PathVariable("merchantId") Long merchantId) {
|
||||
public R<List<MallMerchantUserVo>> getMerchantUsers(@PathVariable("merchantId") Long merchantId) {
|
||||
List<MallMerchantUserEntity> users = mallMerchantUserService.getMerchantUsers(merchantId);
|
||||
return R.ok(users);
|
||||
|
||||
// 转换为VO对象
|
||||
List<MallMerchantUserVo> userVos = users.stream().map(entity -> {
|
||||
MallMerchantUserVo vo = new MallMerchantUserVo();
|
||||
vo.setId(entity.getId());
|
||||
vo.setMerchantId(entity.getMerchantId());
|
||||
vo.setUserId(entity.getUserId());
|
||||
vo.setName(entity.getUserName());
|
||||
vo.setPhone(entity.getUserPhone());
|
||||
vo.setStatus(entity.getStatus());
|
||||
vo.setStatusDesc("1".equals(entity.getStatus()) ? "启用" : "0".equals(entity.getStatus()) ? "禁用" : "未知");
|
||||
|
||||
return vo;
|
||||
}).toList();
|
||||
|
||||
return R.ok(userVos);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,10 +138,20 @@ public class MallMerchantUserController {
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_mallMerchant_add')" )
|
||||
@SysLog("批量商户用户绑定")
|
||||
public R<String> batchBindUsers(@Valid @RequestBody MerchantUserBindDTO bindDTO) {
|
||||
// 添加调试日志
|
||||
System.out.println("接收到的数据: " + bindDTO);
|
||||
System.out.println("merchantId: " + bindDTO.getMerchantId());
|
||||
System.out.println("userIds: " + bindDTO.getUserIds());
|
||||
System.out.println("roleType: " + bindDTO.getRoleType());
|
||||
try {
|
||||
// 将String类型的userIds转换为Long类型
|
||||
List<Long> userIds = bindDTO.getUserIds().stream()
|
||||
.map(Long::valueOf)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
int successCount = mallMerchantUserService.batchBindUsersToMerchant(
|
||||
bindDTO.getMerchantId(),
|
||||
bindDTO.getUserIds(),
|
||||
userIds,
|
||||
bindDTO.getRoleType()
|
||||
);
|
||||
|
||||
@@ -146,12 +172,18 @@ public class MallMerchantUserController {
|
||||
* 解绑单个用户
|
||||
*/
|
||||
@Operation(summary = "解绑用户", description = "解绑单个用户")
|
||||
@DeleteMapping("/unbind/{userId}")
|
||||
@DeleteMapping("/unbind")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_mallMerchant_add')" )
|
||||
@SysLog("商户用户解绑")
|
||||
public R<String> unbindUser(@PathVariable("userId") Long userId) {
|
||||
public R<String> unbindUser(@RequestBody MerchantUserBindDTO bindDTO) {
|
||||
try {
|
||||
boolean success = mallMerchantUserService.unbindUserFromMerchant(userId);
|
||||
// 从userIds中取第一个用户ID
|
||||
if (bindDTO.getUserIds() == null || bindDTO.getUserIds().isEmpty()) {
|
||||
return R.failed("用户ID不能为空");
|
||||
}
|
||||
|
||||
Long userId = Long.valueOf(bindDTO.getUserIds().get(0));
|
||||
boolean success = mallMerchantUserService.unbindUserFromMerchant(bindDTO.getMerchantId(), userId);
|
||||
if (success) {
|
||||
return R.ok("用户解绑成功");
|
||||
} else {
|
||||
@@ -169,9 +201,14 @@ public class MallMerchantUserController {
|
||||
@DeleteMapping("/batchUnbind")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_mallMerchant_add')" )
|
||||
@SysLog("批量商户用户解绑")
|
||||
public R<String> batchUnbindUsers(@RequestBody List<Long> userIds) {
|
||||
public R<String> batchUnbindUsers(@RequestBody MerchantUserBindDTO bindDTO) {
|
||||
try {
|
||||
int successCount = mallMerchantUserService.batchUnbindUsersFromMerchant(userIds);
|
||||
// 将String类型的userIds转换为Long类型
|
||||
List<Long> userIds = bindDTO.getUserIds().stream()
|
||||
.map(Long::valueOf)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
int successCount = mallMerchantUserService.batchUnbindUsersFromMerchant(bindDTO.getMerchantId(), userIds);
|
||||
if (successCount > 0) {
|
||||
return R.ok(String.format("成功解绑%d个用户", successCount));
|
||||
} else {
|
||||
@@ -220,14 +257,14 @@ public class MallMerchantUserController {
|
||||
@SysLog("更新商户用户状态")
|
||||
public R<String> updateUserStatus(
|
||||
@RequestParam Long userId,
|
||||
@RequestParam Integer status
|
||||
@RequestParam String status
|
||||
) {
|
||||
try {
|
||||
MallMerchantUserEntity merchantUser = mallMerchantUserService.getByUserId(userId);
|
||||
if (merchantUser == null) {
|
||||
return R.failed("用户绑定关系不存在");
|
||||
}
|
||||
|
||||
|
||||
merchantUser.setStatus(status);
|
||||
boolean success = mallMerchantUserService.updateById(merchantUser);
|
||||
if (success) {
|
||||
@@ -258,4 +295,13 @@ public class MallMerchantUserController {
|
||||
return R.ok(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试JSON反序列化
|
||||
*/
|
||||
@Operation(summary = "测试JSON反序列化", description = "测试JSON反序列化")
|
||||
@PostMapping("/testJson")
|
||||
public R<String> testJson(@RequestBody MerchantUserBindDTO bindDTO) {
|
||||
return R.ok("JSON反序列化成功: " + bindDTO);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -30,9 +30,9 @@ public class MallProductCreateDTO {
|
||||
/**
|
||||
* 商户ID
|
||||
*/
|
||||
@NotNull(message = "商户ID不能为空")
|
||||
@Schema(description = "商户ID")
|
||||
private Long merchantId;
|
||||
// @NotNull(message = "商户ID不能为空")
|
||||
// @Schema(description = "商户ID")
|
||||
// private Long merchantId;
|
||||
|
||||
/**
|
||||
* 类目ID
|
||||
@@ -101,7 +101,7 @@ public class MallProductCreateDTO {
|
||||
* 状态(1上架 0下架)
|
||||
*/
|
||||
@Schema(description = "状态(1上架 0下架)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 开售时间
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class MallProductSkuCreateDTO {
|
||||
* 状态(1启用 0停用)
|
||||
*/
|
||||
@Schema(description = "状态(1启用 0停用)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -22,8 +22,9 @@ public class MerchantUserBindDTO {
|
||||
|
||||
@NotNull(message = "用户ID列表不能为空")
|
||||
@Schema(description = "用户ID列表")
|
||||
private List<Long> userIds;
|
||||
private List<String> userIds;
|
||||
|
||||
@Schema(description = "角色类型(1:管理员 2:普通用户)", example = "1")
|
||||
private Integer roleType = 1;
|
||||
}
|
||||
|
||||
+1
@@ -32,3 +32,4 @@ public class MerchantUserSingleBindDTO {
|
||||
@Schema(description = "角色类型(1:管理员 2:普通用户)", example = "1")
|
||||
private Integer roleType = 1;
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public class MallMerchantEntity extends Model<MallMerchantEntity> {
|
||||
* 状态(1启用 0停用)
|
||||
*/
|
||||
@Schema(description="状态(1启用 0停用)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 营业执照号
|
||||
|
||||
+2
-1
@@ -62,7 +62,7 @@ public class MallMerchantUserEntity extends Model<MallMerchantUserEntity> {
|
||||
* 状态(1:启用 0:禁用)
|
||||
*/
|
||||
@Schema(description = "状态(1:启用 0:禁用)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
@@ -106,3 +106,4 @@ public class MallMerchantUserEntity extends Model<MallMerchantUserEntity> {
|
||||
@Schema(description = "租户编号")
|
||||
private Long tenantId;
|
||||
}
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class MallProductEntity extends Model<MallProductEntity> {
|
||||
* 状态(1上架 0下架)
|
||||
*/
|
||||
@Schema(description="状态(1上架 0下架)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 开售时间
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class MallProductSkuEntity extends Model<MallProductSkuEntity> {
|
||||
* 状态(1启用 0停用)
|
||||
*/
|
||||
@Schema(description="状态(1启用 0停用)")
|
||||
private Integer status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
|
||||
+1
@@ -8,3 +8,4 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface MallMerchantUserMapper extends PjcloudBaseMapper<MallMerchantUserEntity> {
|
||||
|
||||
}
|
||||
|
||||
+4
-2
@@ -41,10 +41,11 @@ public interface MallMerchantUserService extends IService<MallMerchantUserEntity
|
||||
|
||||
/**
|
||||
* 解绑用户和商户
|
||||
* @param merchantId 商户ID
|
||||
* @param userId 用户ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean unbindUserFromMerchant(Long userId);
|
||||
boolean unbindUserFromMerchant(Long merchantId, Long userId);
|
||||
|
||||
/**
|
||||
* 验证用户是否有权限操作指定商户
|
||||
@@ -65,10 +66,11 @@ public interface MallMerchantUserService extends IService<MallMerchantUserEntity
|
||||
|
||||
/**
|
||||
* 批量解绑用户和商户
|
||||
* @param merchantId 商户ID
|
||||
* @param userIds 用户ID列表
|
||||
* @return 解绑成功的数量
|
||||
*/
|
||||
int batchUnbindUsersFromMerchant(List<Long> userIds);
|
||||
int batchUnbindUsersFromMerchant(Long merchantId, List<Long> userIds);
|
||||
|
||||
/**
|
||||
* 根据商户ID获取绑定的用户列表(包含用户信息)
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.supermarket.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.bsd.pjcloud.supermarket.constant.MallConstants;
|
||||
import com.bsd.pjcloud.supermarket.dto.SelectOptionDTO;
|
||||
import com.bsd.pjcloud.supermarket.entity.MallCategoryEntity;
|
||||
import com.bsd.pjcloud.supermarket.entity.MallMerchantEntity;
|
||||
@@ -61,7 +62,7 @@ public class SelectOptionService {
|
||||
public List<SelectOptionDTO> getCategorySelectList() {
|
||||
return mallCategoryService.listScope()
|
||||
.stream()
|
||||
.filter(category -> category.getStatus() == 1) // 只返回启用状态的分类
|
||||
.filter(category -> category.getStatus() == MallConstants.Status.ENABLED) // 只返回启用状态的分类
|
||||
.map(category -> new SelectOptionDTO(
|
||||
category.getId(),
|
||||
category.getName(),
|
||||
@@ -89,7 +90,7 @@ public class SelectOptionService {
|
||||
*/
|
||||
private List<SelectOptionDTO> buildCategorySelectTree(List<MallCategoryEntity> allCategories, Long parentId, String prefix) {
|
||||
return allCategories.stream()
|
||||
.filter(category -> category.getStatus() == 1 &&
|
||||
.filter(category -> category.getStatus() == MallConstants.Status.ENABLED &&
|
||||
(parentId == null ? category.getParentId() == null : parentId.equals(category.getParentId())))
|
||||
.map(category -> {
|
||||
String label = prefix + category.getName();
|
||||
|
||||
+7
-5
@@ -72,9 +72,10 @@ public class MallMerchantUserServiceImpl extends ServiceImpl<MallMerchantUserMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unbindUserFromMerchant(Long userId) {
|
||||
public boolean unbindUserFromMerchant(Long merchantId, Long userId) {
|
||||
LambdaQueryWrapper<MallMerchantUserEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(MallMerchantUserEntity::getUserId, userId);
|
||||
wrapper.eq(MallMerchantUserEntity::getMerchantId, merchantId)
|
||||
.eq(MallMerchantUserEntity::getUserId, userId);
|
||||
return this.remove(wrapper);
|
||||
}
|
||||
|
||||
@@ -126,13 +127,14 @@ public class MallMerchantUserServiceImpl extends ServiceImpl<MallMerchantUserMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchUnbindUsersFromMerchant(List<Long> userIds) {
|
||||
if (userIds == null || userIds.isEmpty()) {
|
||||
public int batchUnbindUsersFromMerchant(Long merchantId, List<Long> userIds) {
|
||||
if (merchantId == null || userIds == null || userIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<MallMerchantUserEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.in(MallMerchantUserEntity::getUserId, userIds);
|
||||
wrapper.eq(MallMerchantUserEntity::getMerchantId, merchantId)
|
||||
.in(MallMerchantUserEntity::getUserId, userIds);
|
||||
return this.remove(wrapper) ? userIds.size() : 0;
|
||||
}
|
||||
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.bsd.pjcloud.supermarket.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 商户用户绑定信息VO
|
||||
*
|
||||
* @author pjcloud
|
||||
* @date 2025-01-27
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商户用户绑定信息")
|
||||
public class MallMerchantUserVo {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商户ID
|
||||
*/
|
||||
@Schema(description = "商户ID")
|
||||
private Long merchantId;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Schema(description = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
@Schema(description = "用户名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用户手机号
|
||||
*/
|
||||
@Schema(description = "用户手机号")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 角色类型(1:管理员 2:普通用户)
|
||||
*/
|
||||
@Schema(description = "角色类型(1:管理员 2:普通用户)")
|
||||
private Integer roleType;
|
||||
|
||||
/**
|
||||
* 角色类型描述
|
||||
*/
|
||||
@Schema(description = "角色类型描述")
|
||||
private String roleTypeDesc;
|
||||
|
||||
/**
|
||||
* 状态(1:启用 0:禁用)
|
||||
*/
|
||||
@Schema(description = "状态(1:启用 0:禁用)")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
@Schema(description = "状态描述")
|
||||
private String statusDesc;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -125,3 +125,4 @@ public class MallProductDetailAppVo {
|
||||
@Schema(description = "SKU列表")
|
||||
private List<MallProductSkuAppVo> skuList;
|
||||
}
|
||||
|
||||
+1
@@ -105,3 +105,4 @@ public class MallProductListAppVo {
|
||||
@Schema(description = "最低价格")
|
||||
private BigDecimal minPrice;
|
||||
}
|
||||
|
||||
+1
@@ -81,3 +81,4 @@ public class MallProductSkuAppVo {
|
||||
@Schema(description = "状态")
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user