记得上下班打卡 | git大法好,push需谨慎

Commit e09b0338 authored by 张国柄's avatar 张国柄

~API:藏品上架处理;

parent 3ef00d84
package com.liquidnet.service.platform.controller.goblin.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.candy.entity.CandyMgtCoupon;
import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import com.liquidnet.service.platform.service.impl.goblin.PlatformGoblinGoodsService;
import com.liquidnet.service.platform.service.impl.goblin.PlatformGoblinGoodsSkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
......@@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
......@@ -30,34 +28,42 @@ import java.util.stream.Collectors;
public class PlatformGoblinGoodsTaskController {
@Autowired
private PlatformGoblinGoodsService platformGoblinGoodsService;
@Autowired
private PlatformGoblinGoodsSkuService platformGoblinGoodsSkuService;
@PutMapping("onshelves")
public ResponseDto<String> ggoodsOnShelvesHandler() {
LocalDateTime now = LocalDateTime.now();
LambdaQueryWrapper<GoblinGoods> queryWrapper = Wrappers.lambdaQuery(GoblinGoods.class);
queryWrapper.eq(GoblinGoods::getDelFlg, "0");
queryWrapper.eq(GoblinGoods::getStatus, "3");
queryWrapper.eq(GoblinGoods::getSpuAppear, "0");
queryWrapper.eq(GoblinGoods::getShelvesHandle, "3");
queryWrapper.le(GoblinGoods::getShelvesTime, now);
// queryWrapper.eq(GoblinGoods::getShelvesStatus, "0");
queryWrapper.in(GoblinGoods::getShelvesStatus, "0", "1");
queryWrapper.orderByAsc(GoblinGoods::getShelvesTime);
queryWrapper.select(GoblinGoods::getSpuId);
List<GoblinGoods> goodsList = platformGoblinGoodsService.list(queryWrapper);
boolean empty = CollectionUtils.isEmpty(goodsList);
int totalCount = empty ? 0 : goodsList.size();
if (!empty) {
List<String> spuIdList = goodsList.stream().map(GoblinGoods::getSpuId).collect(Collectors.toList());
int spuCount = 0, skuCount = 0;
boolean spuShelvesFlg = true, skuShelvesFlg = true;
try {
platformGoblinGoodsService.shelvesProcessing(spuIdList);
} catch (Exception e) {
log.error("Ex.商品上架处理[totalCount={},spuIdList={}],{}", totalCount, JsonUtils.toJson(spuIdList), e.getMessage());
return ResponseDto.failure(String.format("商品上架处理失败[totalCount=%s]", totalCount));
{// 普通商品上架处理
List<GoblinGoods> shelvesSpuList = platformGoblinGoodsService.shelvesInquiry();
if (!CollectionUtils.isEmpty(shelvesSpuList)) {
spuCount += shelvesSpuList.size();
List<String> shelvesSpuIdList = shelvesSpuList.stream().map(GoblinGoods::getSpuId).collect(Collectors.toList());
try {
platformGoblinGoodsService.shelvesProcessing(shelvesSpuIdList);
} catch (Exception e) {
log.error("Ex.商品上架处理[totalCount={},spuIdList={}],{}", spuCount, JsonUtils.toJson(shelvesSpuIdList), e.getMessage());
spuShelvesFlg = false;
}
}
}
return ResponseDto.success(String.format("商品上架处理成功[totalCount=%s]", totalCount));
{// 数字藏品上架处理
List<GoblinGoodsSku> shelvesSkuList = platformGoblinGoodsSkuService.shelvesInquiry();
if (!CollectionUtils.isEmpty(shelvesSkuList)) {
skuCount += shelvesSkuList.size();
List<String> shelvesSkuIdList = shelvesSkuList.stream().map(GoblinGoodsSku::getSkuId).collect(Collectors.toList());
List<String> shelvesSpuIdList = shelvesSkuList.stream().map(GoblinGoodsSku::getSpuId).collect(Collectors.toList());
try {
platformGoblinGoodsSkuService.shelvesProcessing(shelvesSkuIdList, shelvesSpuIdList);
} catch (Exception e) {
log.error("Ex.藏品上架处理[skuCount={},skuIdList={}]", skuCount, JsonUtils.toJson(shelvesSkuIdList), e.getMessage());
skuShelvesFlg = false;
}
}
}
return ResponseDto.success(String.format("商品上架处理[spuCount=%s:%s;skuCount=%s:%s]", spuCount, spuShelvesFlg, skuCount, skuShelvesFlg));
}
}
package com.liquidnet.service.platform.service.impl.goblin;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -35,6 +36,22 @@ public class PlatformGoblinGoodsService extends ServiceImpl<GoblinGoodsMapper, G
@Autowired
private GoblinGoodsSkuMapper goblinGoodsSkuMapper;
public List<GoblinGoods> shelvesInquiry() {
LocalDateTime now = LocalDateTime.now();
LambdaQueryWrapper<GoblinGoods> queryWrapper = Wrappers.lambdaQuery(GoblinGoods.class);
queryWrapper.eq(GoblinGoods::getDelFlg, "0");
queryWrapper.eq(GoblinGoods::getStatus, "3");
// queryWrapper.eq(GoblinGoods::getSpuAppear, "0");
queryWrapper.eq(GoblinGoods::getShelvesHandle, "3");
queryWrapper.le(GoblinGoods::getShelvesTime, now);
// queryWrapper.eq(GoblinGoods::getShelvesStatus, "0");
queryWrapper.in(GoblinGoods::getShelvesStatus, "0", "1");
queryWrapper.orderByAsc(GoblinGoods::getShelvesTime);
queryWrapper.select(GoblinGoods::getSpuId);
return this.list(queryWrapper);
}
@Transactional
public void shelvesProcessing(List<String> spuIdList) {
LocalDateTime now = LocalDateTime.now();
......@@ -75,8 +92,14 @@ public class PlatformGoblinGoodsService extends ServiceImpl<GoblinGoodsMapper, G
List<GoblinGoodsSkuInfoVo> vos = mongoTemplate.find(query, GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
List<String> skuIdList = vos.stream().map(GoblinGoodsSkuInfoVo::getSkuId).collect(Collectors.toList());
spuIdList.forEach(spuId -> redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS.concat(spuId)));
skuIdList.forEach(skuId -> redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId)));
spuIdList.forEach(spuId -> {
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS.concat(spuId));
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_UNSHELVES.concat(spuId));
});
skuIdList.forEach(skuId -> {
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId));
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_SKU_UNSHELVES.concat(skuId));
});
return;
} else {
LocalDateTime of = LocalDateTime.of(2022, 1, 1, 0, 0);
......
package com.liquidnet.service.platform.service.impl.goblin;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.common.cache.redis.util.AbstractRedisUtil;
import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import com.liquidnet.service.goblin.mapper.GoblinGoodsMapper;
import com.liquidnet.service.goblin.mapper.GoblinGoodsSkuMapper;
import com.mongodb.client.result.UpdateResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PlatformGoblinGoodsSkuService extends ServiceImpl<GoblinGoodsSkuMapper, GoblinGoodsSku> {
@Autowired
private RedisDataSourceUtil redisDataSourceUtil;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private GoblinGoodsMapper goblinGoodsMapper;
public List<GoblinGoodsSku> shelvesInquiry() {
LocalDateTime now = LocalDateTime.now();
LambdaQueryWrapper<GoblinGoodsSku> queryWrapper = Wrappers.lambdaQuery(GoblinGoodsSku.class);
queryWrapper.eq(GoblinGoodsSku::getSkuType, 1);// 1-数字藏品
queryWrapper.eq(GoblinGoodsSku::getDelFlg, "0");
queryWrapper.eq(GoblinGoodsSku::getStatus, "3");
queryWrapper.eq(GoblinGoodsSku::getShelvesHandle, "3");
queryWrapper.le(GoblinGoodsSku::getShelvesTime, now);
queryWrapper.eq(GoblinGoodsSku::getShelvesStatus, "0");
queryWrapper.orderByAsc(GoblinGoodsSku::getShelvesTime);
queryWrapper.select(GoblinGoodsSku::getSkuId, GoblinGoodsSku::getSpuId);
return this.list(queryWrapper);
}
@Transactional
public void shelvesProcessing(List<String> skuIdList, List<String> spuIdList) {
LocalDateTime now = LocalDateTime.now();
LambdaUpdateWrapper<GoblinGoodsSku> updateSkuWrapper = Wrappers.lambdaUpdate(GoblinGoodsSku.class);
updateSkuWrapper.in(GoblinGoodsSku::getSkuId, skuIdList);
updateSkuWrapper.set(GoblinGoodsSku::getShelvesStatus, "3");
updateSkuWrapper.set(GoblinGoodsSku::getShelvesAt, now);
if (this.update(updateSkuWrapper)) {
GoblinGoods updateSpu = new GoblinGoods();
updateSpu.setShelvesAt(now);
updateSpu.setShelvesStatus("3");
LambdaUpdateWrapper<GoblinGoods> updateSpuWrapper = Wrappers.lambdaUpdate(GoblinGoods.class);
updateSpuWrapper.in(GoblinGoods::getSpuId, spuIdList);
updateSpuWrapper.eq(GoblinGoods::getDelFlg, "0");
LiquidnetServiceException liquidnetServiceException = new LiquidnetServiceException();
if (goblinGoodsMapper.update(updateSpu, updateSpuWrapper) > 0) {
UpdateResult updateSkuResult = mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("skuId").in(skuIdList).and("delFlg").is("0")).getQueryObject(),
Update.update("shelvesStatus", "3").set("shelvesAt", now).getUpdateObject()
);
if (updateSkuResult.getModifiedCount() > 0) {
UpdateResult updateSpuResult = mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("spuId").in(spuIdList).and("delFlg").is("0")).getQueryObject(),
Update.update("shelvesStatus", "3").set("shelvesAt", now).getUpdateObject()
);
if (updateSpuResult.getModifiedCount() > 0) {
AbstractRedisUtil redisGoblinUtil = redisDataSourceUtil.getRedisGoblinUtil();
skuIdList.forEach(skuId -> {
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_SKU.concat(skuId));
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_SKU_UNSHELVES.concat(skuId));
});
spuIdList.forEach(spuId -> {
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS.concat(spuId));
redisGoblinUtil.del(GoblinRedisConst.BASIC_GOODS_UNSHELVES.concat(spuId));
});
return;
} else {
LocalDateTime of = LocalDateTime.of(2022, 1, 1, 0, 0);
mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("skuId").in(skuIdList).and("shelvesAt").is(now)).getQueryObject(),
Update.update("shelvesStatus", "0").set("shelvesAt", of).getUpdateObject()
);
liquidnetServiceException.setMessage("更新失败:Mongo.GoblinGoodsSkuInfoVo");
}
} else {
liquidnetServiceException.setMessage("更新失败:Mongo.GoblinGoodsInfoVo");
}
} else {
liquidnetServiceException.setMessage("更新失败:Mysql.GoblinGoodsSku");
}
throw liquidnetServiceException;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment