111
This commit is contained in:
1 parent
bce1885ccf
commit
b3845e6d34
5 files changed
+166
-154
No files matched your search
+148
-137
@@ -1,4 +1,6 @@
|
||||
package com.bsd.pjcloud.supermarket.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bsd.pjcloud.common.api.encrypt.annotation.crypto.ApiCryptoAes;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
@@ -11,8 +13,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysRole;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteRoleService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
import com.bsd.pjcloud.supermarket.dto.MallProductCreateDTO;
|
||||
import com.bsd.pjcloud.supermarket.entity.MallCategoryEntity;
|
||||
@@ -110,6 +114,7 @@ public class MallAppController {
|
||||
@GetMapping("/merchant/list")
|
||||
@Operation(summary = "获取商户列表", description = "获取所有启用的商户列表,包含特色商品")
|
||||
public R<List<MallMerchantListAppVo>> getMerchantList(@RequestParam(defaultValue = "3") Integer productLimit) {
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
// 查询所有启用的商户
|
||||
// List<MallMerchantEntity> merchants = mallMerchantService.list(
|
||||
// Wrappers.<MallMerchantEntity>lambdaQuery()
|
||||
@@ -117,114 +122,119 @@ public class MallAppController {
|
||||
// .orderByAsc(MallMerchantEntity::getName)
|
||||
// );
|
||||
MchManageDto mchManageDto = new MchManageDto();
|
||||
mchManageDto.setVisibleMobile(YesNoEnum.YES.getCode());
|
||||
List<Long> selfMchIdList = remoteMchService.getSelfMchIdList(user.getId(), List.of(MerchantTypeEnum.FARMER)).getData();
|
||||
if (ObjectUtil.isNotEmpty(selfMchIdList)) {
|
||||
mchManageDto.setIds(selfMchIdList);
|
||||
}
|
||||
mchManageDto.setTypes(MerchantTypeEnum.FARMER.getType());
|
||||
R<List<MchManageVo>> listR = remoteMchService.list(mchManageDto);
|
||||
if (!listR.isOk()){
|
||||
if (!listR.isOk()) {
|
||||
return R.failed("商户服务异常!");
|
||||
}
|
||||
List<MchManageVo> merchants = listR.getData();
|
||||
if (CollectionUtils.isEmpty( merchants)) {
|
||||
if (CollectionUtils.isEmpty(merchants)) {
|
||||
return R.ok(List.of());
|
||||
}
|
||||
|
||||
// 获取商户ID列表
|
||||
List<Long> merchantIds = merchants.stream()
|
||||
.map(MchManageVo::getId)
|
||||
.collect(Collectors.toList());
|
||||
.map(MchManageVo::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查询每个商户的特色商品(按创建时间倒序,取前N个)
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<MallProductEntity> products = mallProductService.list(
|
||||
Wrappers.<MallProductEntity>lambdaQuery()
|
||||
.in(MallProductEntity::getMerchantId, merchantIds)
|
||||
.eq(MallProductEntity::getStatus, MallConstants.Status.ENABLED) // 只查上架商品
|
||||
.and(wrapper -> wrapper
|
||||
.isNull(MallProductEntity::getSaleStartTime)
|
||||
.or()
|
||||
.le(MallProductEntity::getSaleStartTime, now)
|
||||
)
|
||||
.and(wrapper -> wrapper
|
||||
.isNull(MallProductEntity::getSaleEndTime)
|
||||
.or()
|
||||
.ge(MallProductEntity::getSaleEndTime, now)
|
||||
)
|
||||
.orderByDesc(MallProductEntity::getCreateTime)
|
||||
Wrappers.<MallProductEntity>lambdaQuery()
|
||||
.in(MallProductEntity::getMerchantId, merchantIds)
|
||||
.eq(MallProductEntity::getStatus, MallConstants.Status.ENABLED) // 只查上架商品
|
||||
.and(wrapper -> wrapper
|
||||
.isNull(MallProductEntity::getSaleStartTime)
|
||||
.or()
|
||||
.le(MallProductEntity::getSaleStartTime, now)
|
||||
)
|
||||
.and(wrapper -> wrapper
|
||||
.isNull(MallProductEntity::getSaleEndTime)
|
||||
.or()
|
||||
.ge(MallProductEntity::getSaleEndTime, now)
|
||||
)
|
||||
.orderByDesc(MallProductEntity::getCreateTime)
|
||||
);
|
||||
|
||||
// 按商户ID分组商品
|
||||
Map<Long, List<MallProductEntity>> productMap = products.stream()
|
||||
.collect(Collectors.groupingBy(MallProductEntity::getMerchantId));
|
||||
.collect(Collectors.groupingBy(MallProductEntity::getMerchantId));
|
||||
|
||||
// 获取商品ID列表,查询SKU信息
|
||||
List<Long> productIds = products.stream()
|
||||
.map(MallProductEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
.map(MallProductEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MallProductSkuEntity> skuList = productIds.isEmpty() ? List.of() :
|
||||
mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.in(MallProductSkuEntity::getProductId, productIds)
|
||||
);
|
||||
List<MallProductSkuEntity> skuList = productIds.isEmpty() ? List.of() :
|
||||
mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.in(MallProductSkuEntity::getProductId, productIds)
|
||||
);
|
||||
|
||||
// 按商品ID分组SKU
|
||||
Map<Long, List<MallProductSkuEntity>> skuMap = skuList.stream()
|
||||
.collect(Collectors.groupingBy(MallProductSkuEntity::getProductId));
|
||||
Map<Long, List<MallProductSkuEntity>> skuMap = skuList.stream()
|
||||
.collect(Collectors.groupingBy(MallProductSkuEntity::getProductId));
|
||||
|
||||
// 转换为VO
|
||||
List<MallMerchantListAppVo> result = merchants.stream().map(merchant -> {
|
||||
MallMerchantListAppVo mallMerchantListAppVo = new MallMerchantListAppVo();
|
||||
mallMerchantListAppVo.setId(merchant.getId());
|
||||
mallMerchantListAppVo.setAddress(merchant.getAddressDes());
|
||||
mallMerchantListAppVo.setImages(merchant.getLogoPic());
|
||||
mallMerchantListAppVo.setName(merchant.getName());
|
||||
mallMerchantListAppVo.setContactPhone(merchant.getPhone());
|
||||
MallMerchantListAppVo mallMerchantListAppVo = new MallMerchantListAppVo();
|
||||
mallMerchantListAppVo.setId(merchant.getId());
|
||||
mallMerchantListAppVo.setAddress(merchant.getAddressDes());
|
||||
mallMerchantListAppVo.setImages(merchant.getLogoPic());
|
||||
mallMerchantListAppVo.setName(merchant.getName());
|
||||
mallMerchantListAppVo.setContactPhone(merchant.getPhone());
|
||||
|
||||
// 获取该商户的商品列表
|
||||
List<MallProductEntity> merchantProducts = productMap.getOrDefault(merchant.getId(), List.of());
|
||||
|
||||
// 设置商品总数
|
||||
mallMerchantListAppVo.setProductCount(merchantProducts.size());
|
||||
|
||||
// 获取特色商品(限制数量)
|
||||
List<MallProductListAppVo> featuredProducts = merchantProducts.stream()
|
||||
.limit(productLimit)
|
||||
.map(product -> {
|
||||
MallProductListAppVo productVo = BeanUtils.toBean(product, MallProductListAppVo.class);
|
||||
List<MallProductSkuEntity> skus = skuMap.getOrDefault(product.getId(), List.of());
|
||||
|
||||
// 计算最低价格
|
||||
productVo.setMinPrice(skus.stream()
|
||||
.map(MallProductSkuEntity::getPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0));
|
||||
// 获取该商户的商品列表
|
||||
List<MallProductEntity> merchantProducts = productMap.getOrDefault(merchant.getId(), List.of());
|
||||
|
||||
// 计算总库存
|
||||
productVo.setTotalStock(skus.stream()
|
||||
.map(MallProductSkuEntity::getStock)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum());
|
||||
// 设置商品总数
|
||||
mallMerchantListAppVo.setProductCount(merchantProducts.size());
|
||||
|
||||
// 获取特色商品(限制数量)
|
||||
List<MallProductListAppVo> featuredProducts = merchantProducts.stream()
|
||||
.limit(productLimit)
|
||||
.map(product -> {
|
||||
MallProductListAppVo productVo = BeanUtils.toBean(product, MallProductListAppVo.class);
|
||||
List<MallProductSkuEntity> skus = skuMap.getOrDefault(product.getId(), List.of());
|
||||
|
||||
// 计算最低价格
|
||||
productVo.setMinPrice(skus.stream()
|
||||
.map(MallProductSkuEntity::getPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0));
|
||||
|
||||
// 计算总库存
|
||||
productVo.setTotalStock(skus.stream()
|
||||
.map(MallProductSkuEntity::getStock)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum());
|
||||
|
||||
|
||||
return productVo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
mallMerchantListAppVo.setFeaturedProducts(featuredProducts);
|
||||
|
||||
// 设置商户营业时间
|
||||
return productVo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
mallMerchantListAppVo.setFeaturedProducts(featuredProducts);
|
||||
|
||||
// 设置商户营业时间
|
||||
// if (merchant.getBusinessHours() != null && !merchant.getBusinessHours().trim().isEmpty()) {
|
||||
// vo.setBusinessHours(merchant.getBusinessHours());
|
||||
// } else {
|
||||
// // 默认商户营业时间
|
||||
// vo.setBusinessHours("10:00-22:00");
|
||||
// }
|
||||
|
||||
return mallMerchantListAppVo;
|
||||
})
|
||||
.filter(vo -> vo.getProductCount() > 0) // 过滤掉没有商品的商户
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return mallMerchantListAppVo;
|
||||
})
|
||||
.filter(vo -> vo.getProductCount() > 0) // 过滤掉没有商品的商户
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
@@ -236,7 +246,7 @@ public class MallAppController {
|
||||
@Operation(summary = "获取商户详情", description = "根据ID获取商户详情")
|
||||
public R<MallMchManageVo> getMerchantDetail(@PathVariable("id") Long id) {
|
||||
R<MchManageVo> mchManageVoR = remoteMchService.getById(id);
|
||||
if (!mchManageVoR.isOk()){
|
||||
if (!mchManageVoR.isOk()) {
|
||||
return R.failed("商户服务异常!");
|
||||
}
|
||||
MchManageVo mchManageVo = mchManageVoR.getData();
|
||||
@@ -265,7 +275,7 @@ public class MallAppController {
|
||||
@ParameterObject Page page,
|
||||
@RequestParam(required = false) Long categoryId,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam Long merchantId
|
||||
@RequestParam Long merchantId
|
||||
) {
|
||||
LambdaQueryWrapper<MallProductEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(categoryId != null, MallProductEntity::getCategoryId, categoryId);
|
||||
@@ -274,41 +284,41 @@ public class MallAppController {
|
||||
wrapper.eq(MallProductEntity::getStatus, MallConstants.Status.ENABLED); // 只查上架商品
|
||||
|
||||
IPage<MallProductEntity> productPage = mallProductService.page(page, wrapper);
|
||||
|
||||
|
||||
// 获取商品ID列表
|
||||
List<Long> productIds = productPage.getRecords().stream()
|
||||
.map(MallProductEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
.map(MallProductEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查询SKU信息
|
||||
List<MallProductSkuEntity> skuList = productIds.isEmpty() ? List.of() :
|
||||
mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.in(MallProductSkuEntity::getProductId, productIds)
|
||||
);
|
||||
List<MallProductSkuEntity> skuList = productIds.isEmpty() ? List.of() :
|
||||
mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.in(MallProductSkuEntity::getProductId, productIds)
|
||||
);
|
||||
|
||||
// 按商品ID分组SKU
|
||||
Map<Long, List<MallProductSkuEntity>> skuMap = skuList.stream()
|
||||
.collect(Collectors.groupingBy(MallProductSkuEntity::getProductId));
|
||||
.collect(Collectors.groupingBy(MallProductSkuEntity::getProductId));
|
||||
|
||||
// 转换为VO
|
||||
IPage<MallProductListAppVo> voPage = productPage.convert(product -> {
|
||||
MallProductListAppVo vo = BeanUtils.toBean(product, MallProductListAppVo.class);
|
||||
List<MallProductSkuEntity> skus = skuMap.getOrDefault(product.getId(), List.of());
|
||||
|
||||
|
||||
// 计算最低价格
|
||||
vo.setMinPrice(skus.stream()
|
||||
.map(MallProductSkuEntity::getPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0));
|
||||
.map(MallProductSkuEntity::getPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0));
|
||||
|
||||
// 计算总库存
|
||||
vo.setTotalStock(skus.stream()
|
||||
.map(MallProductSkuEntity::getStock)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum());
|
||||
.map(MallProductSkuEntity::getStock)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum());
|
||||
|
||||
return vo;
|
||||
});
|
||||
@@ -328,16 +338,16 @@ public class MallAppController {
|
||||
}
|
||||
|
||||
MallProductDetailAppVo vo = BeanUtils.toBean(product, MallProductDetailAppVo.class);
|
||||
|
||||
|
||||
// 查询SKU列表
|
||||
List<MallProductSkuEntity> skuList = mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.eq(MallProductSkuEntity::getProductId, id)
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.eq(MallProductSkuEntity::getProductId, id)
|
||||
);
|
||||
|
||||
|
||||
vo.setSkuList(skuList.stream()
|
||||
.map(sku -> BeanUtils.toBean(sku, MallProductSkuAppVo.class))
|
||||
.collect(Collectors.toList()));
|
||||
.map(sku -> BeanUtils.toBean(sku, MallProductSkuAppVo.class))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return R.ok(vo);
|
||||
}
|
||||
@@ -350,23 +360,23 @@ public class MallAppController {
|
||||
public R<List<MallProductDetailAppVo>> getProductBatch(@RequestParam List<Long> ids) {
|
||||
List<MallProductEntity> products = mallProductService.listByIds(ids);
|
||||
List<MallProductDetailAppVo> result = new java.util.ArrayList<>();
|
||||
|
||||
|
||||
for (MallProductEntity product : products) {
|
||||
MallProductDetailAppVo vo = BeanUtils.toBean(product, MallProductDetailAppVo.class);
|
||||
|
||||
|
||||
// 查询SKU列表
|
||||
List<MallProductSkuEntity> skuList = mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.eq(MallProductSkuEntity::getProductId, product.getId())
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.eq(MallProductSkuEntity::getProductId, product.getId())
|
||||
);
|
||||
|
||||
|
||||
vo.setSkuList(skuList.stream()
|
||||
.map(sku -> BeanUtils.toBean(sku, MallProductSkuAppVo.class))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
.map(sku -> BeanUtils.toBean(sku, MallProductSkuAppVo.class))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
result.add(vo);
|
||||
}
|
||||
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@@ -383,7 +393,7 @@ public class MallAppController {
|
||||
|
||||
// 自动设置商户ID
|
||||
productCreateDTO.setMerchantId(userMerchantId);
|
||||
|
||||
|
||||
// 创建商品
|
||||
boolean success = mallProductService.createProductWithSkus(productCreateDTO);
|
||||
if (success) {
|
||||
@@ -405,11 +415,11 @@ public class MallAppController {
|
||||
try {
|
||||
|
||||
//验证商户
|
||||
Long merchantId = validateMerchant();
|
||||
Long merchantId = validateMerchant();
|
||||
//验证商品数据
|
||||
validateProductPermission(productCreateDTO.getId(),merchantId);
|
||||
validateProductPermission(productCreateDTO.getId(), merchantId);
|
||||
|
||||
|
||||
|
||||
// 验证商品ID
|
||||
if (productCreateDTO.getId() == null) {
|
||||
return R.failed("商品ID不能为空");
|
||||
@@ -428,12 +438,13 @@ public class MallAppController {
|
||||
|
||||
/**
|
||||
* 验证商户权限和状态
|
||||
*
|
||||
* @return 商户id
|
||||
*/
|
||||
private Long validateMerchant() {
|
||||
// 获取当前用户ID
|
||||
Long deptId = SecurityUtils.getUser().getDeptId();
|
||||
if (deptId== null) {
|
||||
if (deptId == null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
@@ -445,7 +456,7 @@ public class MallAppController {
|
||||
MchManageVo mchManageVo = mchManageVoR.getData();
|
||||
return mchManageVo.getId();
|
||||
|
||||
}else {
|
||||
} else {
|
||||
throw new BusinessException("该用户未分配共富商户");
|
||||
}
|
||||
// R<List<SysRole>> mallMchUserLists = remoteRoleService.findRolesByCodes(Arrays.asList(MallConstants.RoleCode.MERCHANT_USER));
|
||||
@@ -454,7 +465,7 @@ 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("当前用户未绑定商户");
|
||||
@@ -473,7 +484,7 @@ public class MallAppController {
|
||||
*/
|
||||
private void validateProductPermission(Long productId, Long merchantId) {
|
||||
|
||||
MallProductEntity mallProduct = mallProductService.getById(productId);
|
||||
MallProductEntity mallProduct = mallProductService.getById(productId);
|
||||
if (mallProduct == null) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
@@ -505,41 +516,41 @@ public class MallAppController {
|
||||
wrapper.eq(status != null, MallProductEntity::getStatus, status);
|
||||
|
||||
IPage<MallProductEntity> productPage = mallProductService.page(page, wrapper);
|
||||
|
||||
|
||||
// 获取商品ID列表
|
||||
List<Long> productIds = productPage.getRecords().stream()
|
||||
.map(MallProductEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
.map(MallProductEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查询SKU信息
|
||||
List<MallProductSkuEntity> skuList = productIds.isEmpty() ? List.of() :
|
||||
mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.in(MallProductSkuEntity::getProductId, productIds)
|
||||
);
|
||||
List<MallProductSkuEntity> skuList = productIds.isEmpty() ? List.of() :
|
||||
mallProductSkuService.list(
|
||||
Wrappers.<MallProductSkuEntity>lambdaQuery()
|
||||
.in(MallProductSkuEntity::getProductId, productIds)
|
||||
);
|
||||
|
||||
// 按商品ID分组SKU
|
||||
Map<Long, List<MallProductSkuEntity>> skuMap = skuList.stream()
|
||||
.collect(Collectors.groupingBy(MallProductSkuEntity::getProductId));
|
||||
.collect(Collectors.groupingBy(MallProductSkuEntity::getProductId));
|
||||
|
||||
// 转换为VO
|
||||
IPage<MallProductListAppVo> voPage = productPage.convert(product -> {
|
||||
MallProductListAppVo vo = BeanUtils.toBean(product, MallProductListAppVo.class);
|
||||
List<MallProductSkuEntity> skus = skuMap.getOrDefault(product.getId(), List.of());
|
||||
|
||||
|
||||
// 计算最低价格
|
||||
vo.setMinPrice(skus.stream()
|
||||
.map(MallProductSkuEntity::getPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0));
|
||||
.map(MallProductSkuEntity::getPrice)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0));
|
||||
|
||||
// 计算总库存
|
||||
vo.setTotalStock(skus.stream()
|
||||
.map(MallProductSkuEntity::getStock)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum());
|
||||
.map(MallProductSkuEntity::getStock)
|
||||
.filter(Objects::nonNull)
|
||||
.mapToDouble(Double::doubleValue)
|
||||
.sum());
|
||||
|
||||
return vo;
|
||||
});
|
||||
@@ -585,7 +596,7 @@ public class MallAppController {
|
||||
// 自动设置商户ID
|
||||
category.setMerchantId(merchantId);
|
||||
category.setDeptId(SecurityUtils.getUser().getDeptId());
|
||||
|
||||
|
||||
// 创建分类
|
||||
boolean success = mallCategoryService.save(category);
|
||||
if (success) {
|
||||
@@ -613,7 +624,7 @@ public class MallAppController {
|
||||
if (category.getId() == null) {
|
||||
return R.failed("分类ID不能为空");
|
||||
}
|
||||
|
||||
|
||||
// 更新分类
|
||||
boolean success = mallCategoryService.updateById(category);
|
||||
if (success) {
|
||||
@@ -635,7 +646,7 @@ public class MallAppController {
|
||||
try {
|
||||
Long merchantId = validateMerchant();
|
||||
validateCategoryPermission(id, merchantId);
|
||||
|
||||
|
||||
// 删除分类(逻辑删除)
|
||||
boolean success = mallCategoryService.removeById(id);
|
||||
if (success) {
|
||||
@@ -656,12 +667,12 @@ public class MallAppController {
|
||||
public R<List<MallCategoryEntity>> getMerchantCategoryList(@RequestParam(required = false) Long parentId) {
|
||||
try {
|
||||
Long merchantId = validateMerchant();
|
||||
|
||||
|
||||
LambdaQueryWrapper<MallCategoryEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(MallCategoryEntity::getMerchantId, merchantId);
|
||||
wrapper.eq(parentId != null, MallCategoryEntity::getParentId, parentId);
|
||||
wrapper.orderByAsc(MallCategoryEntity::getSort);
|
||||
|
||||
|
||||
List<MallCategoryEntity> list = mallCategoryService.list(wrapper);
|
||||
return R.ok(list);
|
||||
} catch (Exception e) {
|
||||
|
||||
+4
@@ -67,4 +67,8 @@ public interface RemoteMchService {
|
||||
@NoToken
|
||||
@GetMapping("/mch-manage/get-self-canteen-user-dept-id-list")
|
||||
R<List<Long>> getSelfCanteenUserDeptIdList(@RequestParam Long mchId);
|
||||
|
||||
@NoToken
|
||||
@GetMapping("/mch-manage/get-self-mch-id-list")
|
||||
R<List<Long>> getSelfMchIdList(@RequestParam Long userId, @RequestParam List<MerchantTypeEnum> mchTypeList);
|
||||
}
|
||||
+10
-13
@@ -67,17 +67,6 @@ public class MchManageController {
|
||||
@Inner
|
||||
@PostMapping("/list")
|
||||
public R<List<MchManageVo>> remoteList(@RequestBody MchManageDto body) {
|
||||
if (ObjectUtil.isNotEmpty(body.getScopeUserDeptId())) {
|
||||
MchManageVo targetMch = mchManageService.getViewsCanteenMchByDeptId(body.getScopeUserDeptId());
|
||||
if (ObjectUtil.isNotEmpty(targetMch)) {
|
||||
body.setIds(List.of(targetMch.getId()));
|
||||
} else {
|
||||
List<SysDept> deptIdList = remoteDeptService.getInnerDescendantList(body.getScopeUserDeptId()).getData();
|
||||
if (ObjectUtil.isNotEmpty(deptIdList)) {
|
||||
body.setDeptIds(deptIdList.stream().map(SysDept::getDeptId).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
List<MchManageVo> list = mchManageService.list(body);
|
||||
return R.ok(list);
|
||||
}
|
||||
@@ -172,6 +161,14 @@ public class MchManageController {
|
||||
return R.ok(userDeptIdList);
|
||||
}
|
||||
|
||||
@Inner
|
||||
@GetMapping("/get-self-mch-id-list")
|
||||
public R<List<Long>> getSelfMchIdList(@RequestParam Long userId, @RequestParam List<MerchantTypeEnum> mchTypeList) {
|
||||
List<Long> userDeptIdList = mchManageService.getSelfMchIdList(userId, mchTypeList);
|
||||
if (ObjectUtil.isEmpty(userDeptIdList)) return R.failed("商户不存在");
|
||||
return R.ok(userDeptIdList);
|
||||
}
|
||||
|
||||
/* ************************************* end 远程调用 end ************************************* */
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
@@ -193,7 +190,7 @@ public class MchManageController {
|
||||
public R<Page<MchManageVo>> appPageJoin(@ParameterObject Page page, @ParameterObject MchManageDto dto) {
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
dto.setVisibleMobile(YesNoEnum.YES.getCode());
|
||||
List<Long> selfMchIdList = mchManageService.getSelfCanteenMchIdList(user.getId(), List.of(MerchantTypeEnum.CANTEEN));
|
||||
List<Long> selfMchIdList = mchManageService.getSelfMchIdList(user.getId(), List.of(MerchantTypeEnum.CANTEEN));
|
||||
if (ObjectUtil.isNotEmpty(selfMchIdList)) {
|
||||
List<Long> ids = dto.getIds();
|
||||
if (ObjectUtil.isEmpty(ids)) ids = new ArrayList<>();
|
||||
@@ -267,7 +264,7 @@ public class MchManageController {
|
||||
public R getSelect(@ParameterObject Page page, @ParameterObject MchManageDto dto) {
|
||||
DataScope dataScope = null;
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
List<Long> selfMchIdList = mchManageService.getSelfCanteenMchIdList(user.getId(), List.of(MerchantTypeEnum.CANTEEN));
|
||||
List<Long> selfMchIdList = mchManageService.getSelfMchIdList(user.getId(), List.of(MerchantTypeEnum.CANTEEN));
|
||||
if (ObjectUtil.isNotEmpty(selfMchIdList)) {
|
||||
List<Long> ids = dto.getIds();
|
||||
if (ObjectUtil.isEmpty(ids)) ids = new ArrayList<>();
|
||||
|
||||
+2
-2
@@ -63,9 +63,9 @@ public interface MchManageService extends IService<MchManageEntity> {
|
||||
String lbLogin(PjcloudUser user);
|
||||
|
||||
/**
|
||||
* 获取用户的食堂商户列表
|
||||
* 获取用户的商户列表
|
||||
*/
|
||||
List<Long> getSelfCanteenMchIdList(Long userId, List<MerchantTypeEnum> mchTypeList);
|
||||
List<Long> getSelfMchIdList(Long userId, List<MerchantTypeEnum> mchTypeList);
|
||||
|
||||
/**
|
||||
* 获当前食堂商户列表对应的用户部门列表
|
||||
|
||||
+2
-2
@@ -471,7 +471,7 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getSelfCanteenMchIdList(Long userId, List<MerchantTypeEnum> mchTypeList) {
|
||||
public List<Long> getSelfMchIdList(Long userId, List<MerchantTypeEnum> mchTypeList) {
|
||||
List<Long> mchIds = new ArrayList<>();
|
||||
mchIds.add(-1L);
|
||||
List<Long> deptIdList = new ArrayList<>();
|
||||
@@ -481,7 +481,7 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
|
||||
}
|
||||
deptIdList.add(userInfo.getSysUser().getDeptId());
|
||||
// 查询下级部门
|
||||
List<SysDept> descendantList = remoteDeptService.getDescendantList(userInfo.getSysUser().getDeptId()).getData();
|
||||
List<SysDept> descendantList = remoteDeptService.getInnerDescendantList(userInfo.getSysUser().getDeptId()).getData();
|
||||
if (ObjectUtil.isNotEmpty(descendantList)) {
|
||||
List<Long> descendantIds = descendantList.stream().map(SysDept::getDeptId).toList();
|
||||
if (ObjectUtil.isNotEmpty(descendantIds)) deptIdList.addAll(descendantIds);
|
||||
|
||||
Reference in new issue
Block a user