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

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

~JOB:+商品上架任务;

parent eec88506
package com.liquidnet.service.feign.platform.task;
import com.liquidnet.service.base.ResponseDto;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PutMapping;
@Component
@FeignClient(
name = "liquidnet-service-platform",
contextId = "FeignPlatformGoblinTaskClient",
path = "platform",
url = "${liquidnet.service.platform.url}",
fallback = FallbackFactory.Default.class
)
public interface FeignPlatformGoblinTaskClient {
@PutMapping("ggoods/task/onshelves")
ResponseDto<String> goodsOnShelvesHandler();
}
package com.liquidnet.service.executor.main.handler;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.feign.platform.task.FeignPlatformGoblinTaskClient;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* platform:goblin
*/
@Component
public class PlatformGoblinTaskHandler {
private static final Logger log = LoggerFactory.getLogger(PlatformGoblinTaskHandler.class);
@Autowired
private FeignPlatformGoblinTaskClient feignPlatformGoblinTaskClient;
// 商城:商品预约上架
@XxlJob(value = "sev-platform:goblinGoodsOnShelvesHandler")
public ReturnT<String> goblinGoodsOnShelvesHandler() {
try {
ResponseDto<String> dto = feignPlatformGoblinTaskClient.goodsOnShelvesHandler();
String dtoStr = JsonUtils.toJson(dto);
log.info("result of handler:{}", dtoStr);
ReturnT<String> success = ReturnT.SUCCESS;
success.setMsg(dtoStr);
return success;
} catch (Exception e) {
log.error("exception of handler:{}", e.getMessage(), e);
ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
}
}
}
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.platform.service.impl.goblin.PlatformGoblinGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
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;
/**
* 商城商品任务处理
*
* @author zhanggb
* Created by IntelliJ IDEA at 2022/1/21
*/
@Slf4j
@RestController
@RequestMapping("ggoods/task")
public class PlatformGoblinGoodsTaskController {
@Autowired
private PlatformGoblinGoodsService platformGoblinGoodsService;
@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.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());
try {
platformGoblinGoodsService.shelvesProcessing(spuIdList);
} catch (Exception e) {
log.error("商品上架处理[totalCount={},spuIdList={}]", totalCount, JsonUtils.toJson(spuIdList));
return ResponseDto.failure(String.format("商品上架处理失败[totalCount=%s]", totalCount));
}
}
return ResponseDto.success(String.format("商品上架处理成功[totalCount=%s]", totalCount));
}
}
package com.liquidnet.service.platform.service.impl.goblin;
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 java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PlatformGoblinGoodsService extends ServiceImpl<GoblinGoodsMapper, GoblinGoods> {
@Autowired
private RedisDataSourceUtil redisDataSourceUtil;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private GoblinGoodsSkuMapper goblinGoodsSkuMapper;
@Transactional
public void shelvesProcessing(List<String> spuIdList) {
LocalDateTime now = LocalDateTime.now();
LambdaUpdateWrapper<GoblinGoods> updateSpuWrapper = Wrappers.lambdaUpdate(GoblinGoods.class);
updateSpuWrapper.in(GoblinGoods::getSpuId, spuIdList);
updateSpuWrapper.set(GoblinGoods::getShelvesStatus, "3");
updateSpuWrapper.set(GoblinGoods::getShelvesAt, now);
if (this.update(updateSpuWrapper)) {
GoblinGoodsSku updateSku = new GoblinGoodsSku();
updateSku.setShelvesAt(now);
updateSku.setShelvesStatus("3");
LambdaUpdateWrapper<GoblinGoodsSku> updateSkuWrapper = Wrappers.lambdaUpdate(GoblinGoodsSku.class);
updateSkuWrapper.in(GoblinGoodsSku::getSpuId, spuIdList);
updateSkuWrapper.eq(GoblinGoodsSku::getDelFlg, "0");
if (goblinGoodsSkuMapper.update(updateSku, updateSkuWrapper) > 0) {
UpdateResult updateSpuResult = mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("spuId").in(spuIdList).and("shelvesStatus").is("0").and("shelvesHandle").is("3")).getQueryObject(),
Update.update("shelvesStatus", "3").set("shelvesAt", now).getUpdateObject()
);
if (updateSpuResult.getModifiedCount() > 0) {
UpdateResult updateSkuResult = mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("spuId").in(spuIdList).and("delFlg").is("0")).getQueryObject(),
Update.update("shelvesStatus", "3").set("shelvesAt", now).getUpdateObject()
);
if (updateSkuResult.getModifiedCount() > 0) {
AbstractRedisUtil redisGoblinUtil = redisDataSourceUtil.getRedisGoblinUtil();
Query query = Query.query(Criteria.where("delFlg").is("0").and("spuId").in(spuIdList));
query.fields().include("skuId");
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)));
return;
} else {
LocalDateTime of = LocalDateTime.of(2022, 1, 1, 0, 0);
mongoTemplate.getCollection(GoblinGoodsInfoVo.class.getSimpleName()).updateMany(
Query.query(Criteria.where("spuId").in(spuIdList).and("shelvesAt").is(now)).getQueryObject(),
Update.update("shelvesStatus", "0").set("shelvesAt", of).getUpdateObject()
);
}
}
}
throw new 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