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

Commit 282afe4d authored by jiangxiulong's avatar jiangxiulong

Merge remote-tracking branch 'origin/jxl_nft_per' into jxl_nft_per

parents 87aa6444 803aa092
......@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
/**
* <p>
......@@ -51,16 +52,13 @@ public class GoblinGoodsAnticipateServiceImpl implements IGoblinGoodsAnticipateS
if (!anticipateValueVo.getState().equals(1)) {
return ResponseDto.failure("该商品预约尚未开始或已经结束,不可预约!");
}
AdamUserInfoVo userInfo = goblinAnticipateUtils.getUserInfo();
if (userInfo==null){
return ResponseDto.failure("登陆信息有误");
}
//查询该用户是否预
GoblinGoodAnticipateUserVo userVo = goblinRedisUtils.getUserAboutAut(skuId, userInfo.getUid());
String uid = CurrentUtil.getCurrentUid();
GoblinGoodAnticipateUserVo userVo = goblinRedisUtils.getUserAboutAut(skuId, uid);
LinkedList<Object[]> sqlValue = CollectionUtil.linkedListObjectArr();
if (userVo == null) {
GoblinGoodAnticipateUserVo user = new GoblinGoodAnticipateUserVo();
user.setUid(userInfo.getUid());
user.setUid(uid);
user.setSkuId(skuId);
String mobile = StringUtils.defaultString(((String) CurrentUtil.getTokenClaims().get(CurrentUtil.TOKEN_MOBILE)), "");
user.setPhone(mobile);
......@@ -79,8 +77,13 @@ public class GoblinGoodsAnticipateServiceImpl implements IGoblinGoodsAnticipateS
});
sendRedis("goblin_goods_anticipate_user", sqlValue);
goblinRedisUtils.setSkuIdPeople(skuId);
//储存用户头像
goblinRedisUtils.setUserAvatar(skuId,userInfo.getAvatar());
//获取用户头像个数小于等于2则保存用户头像
List<String> userAvatar = goblinRedisUtils.getUserAvatar(skuId);
if (userAvatar != null && userAvatar.size() <= 2) {
//查询用户信息获取用户头像并保存
AdamUserInfoVo userInfo = goblinAnticipateUtils.getUserInfo();
goblinRedisUtils.setUserAvatar(skuId, userInfo.getAvatar());
}
}
return ResponseDto.success();
}
......@@ -89,11 +92,8 @@ public class GoblinGoodsAnticipateServiceImpl implements IGoblinGoodsAnticipateS
@Override
public ResponseDto<Boolean> selectAnticipate(String skuId) {
AdamUserInfoVo userInfo = goblinAnticipateUtils.getUserInfo();
if (userInfo == null){
return ResponseDto.failure("登陆信息有误!");
}
return ResponseDto.success(goblinRedisUtils.getUserAboutAut(skuId,userInfo.getUid()) != null) ;
String uid = CurrentUtil.getCurrentUid();
return ResponseDto.success(goblinRedisUtils.getUserAboutAut(skuId, uid) != null);
}
public void sendRedis(String sqlKey, LinkedList<Object[]> sqlData) {
......
......@@ -53,21 +53,21 @@ public class GoblinRedisUtils {
/**
* 该skuId已开启预约
*/
public void setValue(GoblinGoodsAnticipateValueVo valueVo){
redisUtil.set(GoblinRedisConst.ANTICIPATE_VALUE_SKUID.concat(valueVo.getSkuId()),valueVo);
public void setValue(GoblinGoodsAnticipateValueVo valueVo) {
redisUtil.set(GoblinRedisConst.ANTICIPATE_VALUE_SKUID.concat(valueVo.getSkuId()), valueVo);
}
/**
* 根据skuId获取valueVo
*/
public GoblinGoodsAnticipateValueVo getValueBySkuId(String skuId){
return (GoblinGoodsAnticipateValueVo)redisUtil.get(GoblinRedisConst.ANTICIPATE_VALUE_SKUID.concat(skuId));
public GoblinGoodsAnticipateValueVo getValueBySkuId(String skuId) {
return (GoblinGoodsAnticipateValueVo) redisUtil.get(GoblinRedisConst.ANTICIPATE_VALUE_SKUID.concat(skuId));
}
/**
* 获取关联
*/
public boolean getSkuId(String skuId){
public boolean getSkuId(String skuId) {
return redisUtil.get(GoblinRedisConst.ANTICIPATE_VALUE_SKUID.concat(skuId)) != null;
}
......@@ -75,7 +75,7 @@ public class GoblinRedisUtils {
/**
* 删除skuId已开启预约
*/
public void delSkuId(String skuId){
public void delSkuId(String skuId) {
redisUtil.del(GoblinRedisConst.ANTICIPATE_VALUE_SKUID.concat(skuId));
}
......@@ -88,7 +88,7 @@ public class GoblinRedisUtils {
*/
public void setUserAboutSku(GoblinGoodAnticipateUserVo user) {
goblinMongoUtils.setGoblinGoodsAnticipateUserVo(user);
redisUtil.set(GoblinRedisConst.USER_ANTICIPATE_STATE.concat(user.getSkuId()).concat(user.getUid()),user,60*60*24*30);
redisUtil.set(GoblinRedisConst.USER_ANTICIPATE_STATE.concat(user.getSkuId()).concat(user.getUid()), user, 60 * 60 * 24 * 30);
}
/**
......@@ -96,9 +96,9 @@ public class GoblinRedisUtils {
*/
public void setSkuIdPeople(String skuId) {
BigInteger num = (BigInteger) redisUtil.get(GoblinRedisConst.ANTICIPATE_PEOPLE.concat(skuId));
num = num!=null?num: BigInteger.valueOf(0);
num = num != null ? num : BigInteger.valueOf(0);
//新预约 +1
redisUtil.set(GoblinRedisConst.ANTICIPATE_PEOPLE.concat(skuId),num.add(BigInteger.valueOf(1)));
redisUtil.set(GoblinRedisConst.ANTICIPATE_PEOPLE.concat(skuId), num.add(BigInteger.valueOf(1)));
//跟新valueVo
GoblinGoodsAnticipateValueVo anticipateValueVo = getValueBySkuId(skuId);
......@@ -116,24 +116,22 @@ public class GoblinRedisUtils {
/**
* 保存用户头像
*/
public void setUserAvatar(String skuId,String avatar) {
public void setUserAvatar(String skuId, String avatar) {
Object list = redisUtil.get(GoblinRedisConst.ANTICIPATE_SKUID_AVATAR.concat(skuId));
List<String> urlList = list != null ? (List<String>)list : CollectionUtil.arrayListString();
if (urlList.size()<=2){
urlList.add(avatar);
redisUtil.set(GoblinRedisConst.ANTICIPATE_SKUID_AVATAR.concat(skuId),urlList);
}
List<String> urlList = list != null ? (List<String>) list : CollectionUtil.arrayListString();
urlList.add(avatar);
redisUtil.set(GoblinRedisConst.ANTICIPATE_SKUID_AVATAR.concat(skuId), urlList);
}
/**
* 获取用户预约头像
*/
public List<String> getUserAvatar(String skuId){
public List<String> getUserAvatar(String skuId) {
String rdk = GoblinRedisConst.ANTICIPATE_SKUID_AVATAR.concat(skuId);
Object obj = redisUtil.get(rdk);
if(obj==null){
if (obj == null) {
return CollectionUtil.arrayListString();
}else{
} else {
return (List<String>) obj;
}
}
......@@ -1638,46 +1636,47 @@ public class GoblinRedisUtils {
}
/**
* private int skuType 商品类型[0-常规|1-数字藏品]
* private String status 审核状态[0-初始编辑|1-审核中|2-审核不通过|3-审核通过];
* private String shelvesStatus 单品上架状态[0-待上架|1-下架|2-违规|3-上架];
* private String skuAppear 是否隐藏[0-默认展示|1-隐藏];
* private String delFlg 删除标记[0-未删除|1-删除];
*
* private LocalDateTime saleStartTime 开售时间;
* private LocalDateTime saleStopTime 停售时间 预留 暂时不做处理;
* private String soldoutStatus 是否售罄[0-否|1-是];
*
* private String skuCanbuy 是否购买[0-否|1-是] 这个用来预览 前端自己判断;
*
* Integer upchain NFT上传声明状态[0-待上传|1-已声明|2-声明失败|9-声明中]
*
* String unbox; 是否盲盒[0-否|1-是]
* private int skuType 商品类型[0-常规|1-数字藏品]
* private String status 审核状态[0-初始编辑|1-审核中|2-审核不通过|3-审核通过];
* private String shelvesStatus 单品上架状态[0-待上架|1-下架|2-违规|3-上架];
* private String skuAppear 是否隐藏[0-默认展示|1-隐藏];
* private String delFlg 删除标记[0-未删除|1-删除];
* <p>
* private LocalDateTime saleStartTime 开售时间;
* private LocalDateTime saleStopTime 停售时间 预留 暂时不做处理;
* private String soldoutStatus 是否售罄[0-否|1-是];
* <p>
* private String skuCanbuy 是否购买[0-否|1-是] 这个用来预览 前端自己判断;
* <p>
* Integer upchain NFT上传声明状态[0-待上传|1-已声明|2-声明失败|9-声明中]
* <p>
* String unbox; 是否盲盒[0-否|1-是]
*/
// 获取盲盒下藏品的库存 各种状态下不能算库存的排除掉
public int getSkuAllStatusStock(GoblinGoodsSkuInfoVo info) {
if (
info != null
&& LocalDateTime.now().isAfter(info.getSaleStartTime())
&& (null == info.getSoldoutStatus() || info.getSoldoutStatus().equals("0"))
&& (null == info.getHitRatio() || info.getHitRatio().compareTo(BigDecimal.ZERO) > 0)
&& (null == info.getSkuCanbuy() || info.getSkuCanbuy().equals("1"))
info != null
&& LocalDateTime.now().isAfter(info.getSaleStartTime())
&& (null == info.getSoldoutStatus() || info.getSoldoutStatus().equals("0"))
&& (null == info.getHitRatio() || info.getHitRatio().compareTo(BigDecimal.ZERO) > 0)
&& (null == info.getSkuCanbuy() || info.getSkuCanbuy().equals("1"))
) {// 可以返回库存
return getSkuStock(null, info.getSkuId());
} else {// 不计入库存
return 0;
}
}
// 各种状态下判断藏品是否可以展示
public boolean getSkuAllStatusShow(GoblinGoodsSkuInfoVo info) {
if (
info != null
&& info.getSkuType() == 1
&& info.getStatus().equals("3")
&& info.getShelvesStatus().equals("3")
&& (info.getSkuAppear() == null || info.getSkuAppear().equals("0"))
&& info.getDelFlg().equals("0")
&& ((info.getUnbox().equals("0") && info.getUpchain() == 1) || info.getUnbox().equals("1"))
info != null
&& info.getSkuType() == 1
&& info.getStatus().equals("3")
&& info.getShelvesStatus().equals("3")
&& (info.getSkuAppear() == null || info.getSkuAppear().equals("0"))
&& info.getDelFlg().equals("0")
&& ((info.getUnbox().equals("0") && info.getUpchain() == 1) || info.getUnbox().equals("1"))
// && (info.getUnbox().equals("1") || info.getUpchain() == 1)
) {
return true;
......@@ -1685,13 +1684,14 @@ public class GoblinRedisUtils {
return false;
}
}
// 各种状态下判断藏品总库存
public Integer getSkuTotalStock(GoblinGoodsSkuInfoVo info) {
if (
info != null
&& LocalDateTime.now().isAfter(info.getSaleStartTime())
&& (null == info.getSoldoutStatus() || info.getSoldoutStatus().equals("0"))
&& (null == info.getHitRatio() || info.getHitRatio().compareTo(BigDecimal.ZERO) > 0)
info != null
&& LocalDateTime.now().isAfter(info.getSaleStartTime())
&& (null == info.getSoldoutStatus() || info.getSoldoutStatus().equals("0"))
&& (null == info.getHitRatio() || info.getHitRatio().compareTo(BigDecimal.ZERO) > 0)
) {// 可以返回库存
return info.getSkuStock();
} else {// 不计入库存
......
package com.liquidnet.service.goblin.test;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.liquidnet.commons.lang.util.JsonUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
//@ActiveProfiles("test")
@SpringBootTest
public class TestGoblinMongo {
@Autowired
private MongoTemplate mongoTemplate;
@SneakyThrows
@Test
public void testMongoUpdateLocalDateTime() {
ObjectWriter om = JsonUtils.OM().writerWithDefaultPrettyPrinter();
LocalDateTime now = LocalDateTime.now();
Object nowTimeMdbObj = mongoTemplate.getConverter().convertToMongoType(now);
Date from = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
log.info("now:{},mdbObj:{},from:{}", now, nowTimeMdbObj, from);
// GoblinGoodsSkuInfoVo findRstVo = mongoTemplate.findOne(Query.query(Criteria.where("delFlg").is("0").and("deletedAt").is("2022-04-18T04:33:12.443+00:00")), GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
// log.info("MDB.findOne:{}", om.writeValueAsString(findRstVo));
// LocalDateTime now = LocalDateTime.now();
// Object nowObj = mongoTemplate.getConverter().convertToMongoType(now);
// UpdateResult updateResult = mongoTemplate.getCollection(GoblinGoodsSkuInfoVo.class.getSimpleName()).updateOne(
// Query.query(Criteria.where("skuId").is(findRstVo.getSkuId())).getQueryObject(),
// Update.update("deletedAt", nowObj).set("deletedBy", "local.test").set("updatedAt", now).set("updatedBy", "local.test").getUpdateObject()
// );
// log.info("MDB.getCollection(...).updateOne:{}", JsonUtils.toJson(updateResult));
//
// findRstVo = mongoTemplate.findOne(Query.query(Criteria.where("delFlg").is("0")), GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
// log.info("MDB.findOne:{}", om.writeValueAsString(findRstVo));
}
@Test
public void testUpdate(){
// String skuId = "1234567890-sku-0225";
// Query query = Query.query(Criteria.where("skuId").is(skuId));
// GalaxySeriesNftInfoBo seriesNftInfoBo = dataUtils.getSeriesNftInfoBo2("zxinchain",skuId);
// log.info(seriesNftInfoBo.toString());
//1、插入时间正确 为UTC时间
// seriesNftInfoBo.setSkuId("1234567890-sku-0226");
// seriesNftInfoBo.setCreatedAt(LocalDateTime.now());
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// Document document = (Document)mongoConverter.convertToMongoType(seriesNftInfoBo);
// mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).insertOne(document);
//2、插入时间正确
// UpdateResult result = mongoTemplate.updateMulti(
// query,
// Update.update("nftName", "正在映画NFT名字003").set("updatedAt", LocalDateTime.now()),
// GalaxySeriesNftInfoVo2.class.getSimpleName()
// );
//3、插入时间正确 为UTC时间
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// BasicDBObject basicDBObject = new BasicDBObject();
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// basicDBObject.append("$set", mongoConverter.convertToMongoType(seriesNftInfoBo))
// );
//4、时间插入正确
// BasicDBObject basicDBObject = new BasicDBObject();
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// Document result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).findOneAndUpdate(
// query.getQueryObject(),
// basicDBObject.append("$set", mongoConverter.convertToMongoType(seriesNftInfoBo)),
// new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
// );
// log.info("updateSeriesNftCrtCount result:{}", result.toString());
//5、插入时间正确 为UTC时间
//注意:使用mongoConverter.convertToMongoType转换时 update.set不生效
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// Document document = (Document)mongoConverter.convertToMongoType(seriesNftInfoBo);
// Update update = Update.fromDocument(document);
// update.set("updatedAt",LocalDateTime.now());//
// UpdateResult result = mongoTemplate.updateFirst(query,update, GalaxySeriesNftInfoVo2.class,GalaxySeriesNftInfoVo2.class.getSimpleName());
//6、插入时间正确 插入为非UTC时间 2022-04-14T17:03:23.269
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(seriesNftInfoBo)));
// mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// orderObject
// );
//7、时间插入正确 为UTC
// HashMap<String, Object> map = new HashMap<>();
// map.put("nftName", "正在映画NFT名字002");
// map.put("updatedAt", LocalDateTime.now());
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// new BasicDBObject("$set", mongoConverter.convertToMongoType(map))
// );
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
//8、时间插入正确 为UTC
// HashMap<String, Object> map = new HashMap<>();
// map.put("nftName", "正在映画NFT名字003");
// map.put("updatedAt", LocalDateTime.now());
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// new Document("$set", mongoConverter.convertToMongoType(map))
// );
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
//1、时间插入错误
// 把当前时间强制转换为了UTC时间 直接在时间后加'Z' 2022-04-14T07:19:35.374Z
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// new Document("$set", new Document("updatedAt", LocalDateTime.now()).append("nftName", "正在映画NFT名字002"))
// );
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
//2、时间插入错误
// 把当前时间强制转换为了UTC时间 直接在时间后加'Z' 2022-04-14T07:19:35.374Z
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// Update.update("nftName", "正在映画NFT名字001").set("updatedAt", LocalDateTime.now()).getUpdateObject());
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
//3、插入时间错误
//把当前时间强制转换为了UTC时间 直接在时间后加'Z' 2022-04-14T07:19:35.374Z
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateMany(
// query.getQueryObject(),
// Update.update("nftName", "正在映画NFT名字001").set("updatedAt", LocalDateTime.now()).getUpdateObject());
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
//4、时间插入错误
// 把当前时间强制转换为了UTC时间 直接在时间后加'Z' 2022-04-14T07:19:35.374Z
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// Document result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).findOneAndUpdate(
// query.getQueryObject(),
// Update.update("nftName", "正在映画NFT名字001").set("updatedAt", LocalDateTime.now()).getUpdateObject(),
// new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
// );
// log.info("updateSeriesNftCrtCount result:{}", result.toString());
//5、插入时间未知,执行报错
// seriesNftInfoBo.setUpdatedAt(LocalDateTime.now());
// Update update = Update.fromDocument(Document.parse(JsonUtils.toJson(seriesNftInfoBo)));
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateMany(
// query.getQueryObject(),
// update.getUpdateObject());
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
//6、时间插入错误
// 把当前时间强制转换为了UTC时间 直接在时间后加'Z' 2022-04-14T07:19:35.374Z
// HashMap<String, Object> map = new HashMap<>();
// map.put("nftName", "正在映画NFT名字002");
// map.put("updatedAt", LocalDateTime.now());
// UpdateResult result = mongoTemplate.getCollection(GalaxySeriesNftInfoVo2.class.getSimpleName()).updateOne(
// query.getQueryObject(),
// new BasicDBObject("$set", map)
// );
// log.info("updateSeriesNftCrtCount result:{}",result.toString());
}
}
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