Skip to content

Commit

Permalink
feat:当日预约门店缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
oddfar committed Sep 16, 2023
1 parent df98e4e commit a716037
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ i茅台app,每日自动预约茅台

不会Docker部署的,可使用客户端:<https://github.com/lisongkun/hygge-imaotai>

## 关注&交流

欢迎各位老哥进群进行**技术交流**(只交流技术,不谈茅台)

因进群门槛太低,导致有广告等不好现象,进群需**在群里发6.66**🧧,或提供**公益捐款**(腾讯公益等公益项目)大于10元记录(截图提供,要求3天内的)

若您接受上面所述,请添加我微信备注(**进群campus**),我将拉您进群

**群目前有三百多人**

<img src="https://note.oddfar.com/img/my-wechat.jpg" alt="wechat" style="height:280px;" />

**私信不解决项目使用问题,请提交 issues,或在群里询问!**



## 贡献代码

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ public <T> long setCacheList(final String key, final List<T> dataList) {
return count == null ? 0 : count;
}

/**
* 重新set缓存List数据
*
* @param key 缓存的键值
* @param dataList 待缓存的List数据
* @return 缓存的对象
*/
public <T> long reSetCacheList(final String key, final List<T> dataList) {
this.deleteObject(key);
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
return count == null ? 0 : count;
}

/**
* 获得缓存的list对象
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
Expand All @@ -51,7 +52,7 @@ public List<IShop> selectShopList() {

if (shopList != null && shopList.size() > 0) {
return shopList;
}else {
} else {
refreshShop();
}

Expand Down Expand Up @@ -142,25 +143,39 @@ public IShop selectByIShopId(String iShopId) {

@Override
public List<IMTItemInfo> getShopsByProvince(String province, String itemId) {
String key = "mt_province:" + province + "." + getCurrentSessionId() + "." + itemId;
List<IMTItemInfo> cacheList = redisCache.getCacheList(key);
if (cacheList != null && cacheList.size() > 0) {
return cacheList;
} else {
List<IMTItemInfo> imtItemInfoList = reGetShopsByProvince(province, itemId);
redisCache.reSetCacheList(key, imtItemInfoList);
redisCache.expire(key, 60, TimeUnit.MINUTES);
return imtItemInfoList;
}
}

public List<IMTItemInfo> reGetShopsByProvince(String province, String itemId) {

long dayTime = LocalDate.now().atStartOfDay().toInstant(ZoneOffset.of("+8")).toEpochMilli();

String url = "https://static.moutai519.com.cn/mt-backend/xhr/front/mall/shop/list/slim/v3/" + getCurrentSessionId() + "/" + province + "/" + itemId + "/" + dayTime;
//TODO

String urlRes = HttpUtil.get(url);
JSONObject res = null;
try {
res = JSONObject.parseObject(urlRes);
} catch (JSONException jsonException) {
logger.info(url);
throw new ServiceException("查询所在省市的投放产品和数量error," + province + "-" + itemId);
String message = StringUtils.format("查询所在省市的投放产品和数量error: %s", url);
logger.error(message);
throw new ServiceException(message);
}

// JSONObject res = JSONObject.parseObject(HttpUtil.get(url));
if (!res.containsKey("code") || !res.getString("code").equals("2000")) {
logger.info(url);
logger.error("查询所在省市的投放产品和数量error," + province + "-" + itemId);
throw new ServiceException("查询所在省市的投放产品和数量error," + province + "-" + itemId);
String message = StringUtils.format("查询所在省市的投放产品和数量error: %s", url);
logger.error(message);
throw new ServiceException(message);
}
//组合信息
List<IMTItemInfo> imtItemInfoList = new ArrayList<>();
Expand Down

0 comments on commit a716037

Please sign in to comment.