diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index 52fbce4a..1aabb3cf 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -282,25 +282,27 @@ public class GoodsServiceImpl extends ServiceImpl implements public Boolean updateGoodsMarketAble(List goodsIds, GoodsStatusEnum goodsStatusEnum, String underReason) { boolean result; - AuthUser currentUser = UserContext.getCurrentUser(); - if (currentUser == null || (currentUser.getRole().equals(UserEnums.STORE) && currentUser.getStoreId() == null)) { - throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR); - } - //如果商品为空,直接返回 if (goodsIds == null || goodsIds.isEmpty()) { return true; } LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().in(Goods::getId, goodsIds); updateWrapper.set(Goods::getMarketEnable, goodsStatusEnum.name()); updateWrapper.set(Goods::getUnderMessage, underReason); - updateWrapper.eq(Goods::getStoreId, currentUser.getStoreId()); + AuthUser currentUser = UserContext.getCurrentUser(); + if (currentUser == null || (currentUser.getRole().equals(UserEnums.STORE) && currentUser.getStoreId() == null)) { + throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR); + } else if (currentUser.getRole().equals(UserEnums.STORE) && currentUser.getStoreId() != null) { + updateWrapper.eq(Goods::getStoreId, currentUser.getStoreId()); + queryWrapper.eq(Goods::getStoreId, currentUser.getStoreId()); + } updateWrapper.in(Goods::getId, goodsIds); result = this.update(updateWrapper); //修改规格商品 - List goodsList = this.list(new LambdaQueryWrapper().in(Goods::getId, goodsIds).eq(Goods::getStoreId, currentUser.getStoreId())); + List goodsList = this.list(queryWrapper); for (Goods goods : goodsList) { goodsSkuService.updateGoodsSkuStatus(goods); } diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index 743abc04..32b9c45c 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -199,7 +199,6 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements resultMap.put(KEY_FAIL, 0); resultMap.put(KEY_PROCESSED, 0); cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix() + "", resultMap); - cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true); if (!goodsIndexList.isEmpty()) { goodsIndexRepository.deleteAll(); for (EsGoodsIndex goodsIndex : goodsIndexList) { diff --git a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java index 6d5c31ca..31ce2559 100644 --- a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java +++ b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java @@ -80,9 +80,15 @@ public class ElasticsearchController { public ResultMessage init() { Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); + if (flag == null) { + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false); + } if (Boolean.TRUE.equals(flag)) { return ResultUtil.error(100000, "当前有任务在执行"); } + + cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null); + cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true); ThreadUtil.execAsync(() -> { //查询商品信息 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -129,9 +135,13 @@ public class ElasticsearchController { @GetMapping("/progress") public ResultMessage> getProgress() { - Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); - Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); - map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0); - return ResultUtil.data(map); + try { + Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); + Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); + map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0); + return ResultUtil.data(map); + } catch (Exception e) { + return ResultUtil.data(null); + } } }