diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/domain/IMTCacheConstants.java b/campus-modular/src/main/java/com/oddfar/campus/business/domain/IMTCacheConstants.java new file mode 100644 index 0000000..502eb39 --- /dev/null +++ b/campus-modular/src/main/java/com/oddfar/campus/business/domain/IMTCacheConstants.java @@ -0,0 +1,15 @@ +package com.oddfar.campus.business.domain; + +/** + * i茅台缓存常量 + * + * @author oddfar + * @date 2024/4/12 + */ +public interface IMTCacheConstants { + String MT_VERSION = "mt_version"; + + String MT_SESSION_ID = "mt_session_id"; + + String MT_SHOP_LIST = "mt_shop_list"; +} diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/service/IShopService.java b/campus-modular/src/main/java/com/oddfar/campus/business/service/IShopService.java index 43be637..8140f66 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/service/IShopService.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/service/IShopService.java @@ -25,6 +25,17 @@ public interface IShopService extends IService { */ void refreshItem(); + /** + * 根据 iShopId 查询门店信息 + *

+ * 预约选择门店时,根据城市、经纬度选择门店 + * 之前这些参数是在账号配置里手动填写 + * 现在是查询门店的信息,把门店的这些信息填到账号配置里 + * 主要是这样避免用户填错信息 + * + * @param iShopId + * @return 门店信息 + */ IShop selectByIShopId(String iShopId); /** diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IMTServiceImpl.java b/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IMTServiceImpl.java index 8a21321..20c6b5e 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IMTServiceImpl.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IMTServiceImpl.java @@ -13,6 +13,7 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.oddfar.campus.business.domain.IMTCacheConstants; import com.oddfar.campus.business.entity.IUser; import com.oddfar.campus.business.mapper.IUserMapper; import com.oddfar.campus.business.service.IMTLogFactory; @@ -80,7 +81,7 @@ public void run() { @Override public String getMTVersion() { - String mtVersion = Convert.toStr(redisCache.getCacheObject("mt_version")); + String mtVersion = Convert.toStr(redisCache.getCacheObject(IMTCacheConstants.MT_VERSION)); if (StringUtils.isNotEmpty(mtVersion)) { return mtVersion; } @@ -92,7 +93,7 @@ public String getMTVersion() { mtVersion = matcher.group(1); mtVersion = mtVersion.replace("版本 ", ""); } - redisCache.setCacheObject("mt_version", mtVersion); + redisCache.setCacheObject(IMTCacheConstants.MT_VERSION, mtVersion); return mtVersion; @@ -100,7 +101,7 @@ public String getMTVersion() { @Override public void refreshMTVersion() { - redisCache.deleteObject("mt_version"); + redisCache.deleteObject(IMTCacheConstants.MT_VERSION); getMTVersion(); } @@ -241,8 +242,9 @@ public void run() { new Thread(runnable).start(); } + // 领取小茅运 - public void receiveReward(IUser iUser){ + public void receiveReward(IUser iUser) { String url = "https://h5.moutai519.com.cn/game/xmTravel/receiveReward"; HttpRequest request = HttpUtil.createRequest(Method.POST, url); @@ -256,14 +258,14 @@ public void receiveReward(IUser iUser){ HttpResponse execute = request.execute(); JSONObject body = JSONObject.parseObject(execute.body()); - if(body.getInteger("code") != 2000){ + if (body.getInteger("code") != 2000) { String message = "领取小茅运失败"; throw new ServiceException(message); } } - public void shareReward(IUser iUser){ - logger.info("「领取每日首次分享获取耐力」:"+iUser.getMobile()); + public void shareReward(IUser iUser) { + logger.info("「领取每日首次分享获取耐力」:" + iUser.getMobile()); String url = "https://h5.moutai519.com.cn/game/xmTravel/shareReward"; HttpRequest request = HttpUtil.createRequest(Method.POST, url); @@ -277,7 +279,7 @@ public void shareReward(IUser iUser){ HttpResponse execute = request.execute(); JSONObject body = JSONObject.parseObject(execute.body()); - if(body.getInteger("code") != 2000){ + if (body.getInteger("code") != 2000) { String message = "领取每日首次分享获取耐力失败"; throw new ServiceException(message); } @@ -561,7 +563,7 @@ public void appointmentResults() { throw new ServiceException(message); } JSONArray itemVOs = jsonObject.getJSONObject("data").getJSONArray("reservationItemVOS"); - if(Objects.isNull(itemVOs) || itemVOs.isEmpty()){ + if (Objects.isNull(itemVOs) || itemVOs.isEmpty()) { logger.info("申购记录为空: user->{}", iUser.getMobile()); continue; } @@ -574,7 +576,7 @@ public void appointmentResults() { } } } catch (Exception e) { - logger.error("查询申购结果失败:失败原因->{}", e.getMessage(),e); + logger.error("查询申购结果失败:失败原因->{}", e.getMessage(), e); } } diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IShopServiceImpl.java b/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IShopServiceImpl.java index 0ddf2e1..365c0f5 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IShopServiceImpl.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IShopServiceImpl.java @@ -8,6 +8,7 @@ import com.alibaba.fastjson2.JSONException; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.oddfar.campus.business.domain.IMTCacheConstants; import com.oddfar.campus.business.domain.IMTItemInfo; import com.oddfar.campus.business.domain.MapPoint; import com.oddfar.campus.business.entity.IItem; @@ -18,8 +19,7 @@ import com.oddfar.campus.common.core.RedisCache; import com.oddfar.campus.common.exception.ServiceException; import com.oddfar.campus.common.utils.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,9 +33,9 @@ import java.util.stream.Collectors; @Service +@Slf4j public class IShopServiceImpl extends ServiceImpl implements IShopService { - private static final Logger logger = LoggerFactory.getLogger(IShopServiceImpl.class); @Autowired IShopMapper iShopMapper; @@ -48,7 +48,7 @@ public class IShopServiceImpl extends ServiceImpl implements @Override public List selectShopList() { - List shopList = redisCache.getCacheList("mt_shop_list"); + List shopList = redisCache.getCacheList(IMTCacheConstants.MT_SHOP_LIST); if (shopList != null && shopList.size() > 0) { return shopList; @@ -74,7 +74,7 @@ public void refreshShop() { String shopUrl = body.getJSONObject("data").getJSONObject("mtshops_pc").getString("url"); //清空数据库 iShopMapper.truncateShop(); - redisCache.deleteObject("mt_shop_list"); + redisCache.deleteObject(IMTCacheConstants.MT_SHOP_LIST); String s = HttpUtil.get(shopUrl); @@ -88,12 +88,13 @@ public void refreshShop() { list.add(iShop); } this.saveBatch(list); - redisCache.setCacheList("mt_shop_list", list); + redisCache.setCacheList(IMTCacheConstants.MT_SHOP_LIST, list); + redisCache.expire(IMTCacheConstants.MT_SHOP_LIST, 2, TimeUnit.HOURS); } @Override public String getCurrentSessionId() { - String mtSessionId = Convert.toStr(redisCache.getCacheObject("mt_session_id")); + String mtSessionId = Convert.toStr(redisCache.getCacheObject(IMTCacheConstants.MT_SESSION_ID)); long dayTime = LocalDate.now().atStartOfDay().toInstant(ZoneOffset.of("+8")).toEpochMilli(); if (StringUtils.isNotEmpty(mtSessionId)) { @@ -107,7 +108,7 @@ public String getCurrentSessionId() { if (jsonObject.getString("code").equals("2000")) { JSONObject data = jsonObject.getJSONObject("data"); mtSessionId = data.getString("sessionId"); - redisCache.setCacheObject("mt_session_id", mtSessionId); + redisCache.setCacheObject(IMTCacheConstants.MT_SESSION_ID, mtSessionId, 2, TimeUnit.HOURS); iItemMapper.truncateItem(); //item插入数据库 @@ -126,7 +127,7 @@ public String getCurrentSessionId() { @Override public void refreshItem() { - redisCache.deleteObject("mt_session_id"); + redisCache.deleteObject(IMTCacheConstants.MT_SESSION_ID); getCurrentSessionId(); } @@ -138,7 +139,6 @@ public IShop selectByIShopId(String iShopId) { } else { return null; } -// return iShopMapper.selectOne(IShop::getIShopId, iShopId); } @Override @@ -167,14 +167,14 @@ public List reGetShopsByProvince(String province, String itemId) { res = JSONObject.parseObject(urlRes); } catch (JSONException jsonException) { String message = StringUtils.format("查询所在省市的投放产品和数量error: %s", url); - logger.error(message); + log.error(message); throw new ServiceException(message); } // JSONObject res = JSONObject.parseObject(HttpUtil.get(url)); if (!res.containsKey("code") || !res.getString("code").equals("2000")) { String message = StringUtils.format("查询所在省市的投放产品和数量error: %s", url); - logger.error(message); + log.error(message); throw new ServiceException(message); } //组合信息