From a778bd0e636e6c9c797a89452109aa5b83d5bd59 Mon Sep 17 00:00:00 2001 From: oddfar Date: Mon, 10 Jul 2023 14:31:22 +0800 Subject: [PATCH] :art: 1.0.1 --- README.md | 57 +------------------ .../business/controller/IUserController.java | 5 +- .../business/controller/TestController.java | 10 +++- .../campus/business/mapper/IUserMapper.java | 9 +-- .../business/service/IMTLogFactory.java | 22 ++++++- .../campus/business/service/IMTService.java | 5 ++ .../campus/business/service/IUserService.java | 1 + .../business/service/impl/IMTServiceImpl.java | 23 +++++++- .../service/impl/IShopServiceImpl.java | 6 ++ .../campus/business/task/CampusIMTTask.java | 17 +++--- .../src/main/resources/application-dev.yml | 0 .../src/main/resources/application-prod.yml | 29 ++++++++++ .../src/main/resources/application.yml | 11 ++-- vue_campus_admin/src/views/imt/user/index.vue | 11 +++- vue_campus_admin/src/views/index.vue | 14 ++++- 15 files changed, 136 insertions(+), 84 deletions(-) create mode 100644 campus-modular/src/main/resources/application-dev.yml create mode 100644 campus-modular/src/main/resources/application-prod.yml diff --git a/README.md b/README.md index 449db30..c5f1541 100644 --- a/README.md +++ b/README.md @@ -23,57 +23,8 @@ i茅台app,每日自动预约茅台,可添加多个用户,可选本市出 ## 使用教程 -### Docker部署 - -在 [release](https://github.com/oddfar/campus-imaotai/releases) 页面下载压缩包并解压。 - -- 构建docker服务:`docker-compose build` - -- 启动docker容器: `docker-compose up -d` - - 打开浏览器,输入:([http://localhost:80](http://localhost/)),若能正确展示页面,则表明环境搭建成功。 - - 第一次启动可能会失败,是因为 mysql 服务还没启动完成,campus-imt 就启动了,等mysql启动完毕后再启动一次即可 `docker-compose up -d` - - 一共4个服务 - - ![](.github/be983240837a2d5deb082157e4772d0f.png) - -使用端口,mysql:3306,redis:6379,nginx:80,campus-service:8160 - -若端口被占用,修改`docker-compose.yml`里的端口配置,例:`3306:3306` 改成 `3307:3306` - -### 本地部署 - - - -### 配置 - -**1、添加用户** - -i茅台->用户管理->添加账号(若你有token,可直接点击“直接添加”) - -**2、修改配置** - -添加完后,选中所手机号修改配置,添加维度、经度等配置 - -- 修改预约项目 - - 查看 `预约项目列表`,商品预约code,用@间隔,例如:`10213@10214`、`10213` - -- 修改经纬度、省份、城市 - - 地址查询:https://restapi.amap.com/v3/geocode/geo?key=0a7f4baae0a5e37e6f90e4dc88e3a10d&output=json&address=清华大学 - - 返回的key中:province省份、city城市、 "location": "116.326759,40.003304"左边是经度,右边是纬度 - - 注意⚠️ 省份和城市需填完整的,例如 `河北省`,`石家庄市` - -- 类型:1或2 - - 1:预约本市出货量最大的门店,2:预约你的位置附近门店 - - 若不需要预约,留空即可 +- 部署项目:[点击此处](https://github.com/oddfar/campus-imaotai/wiki/%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8#%E9%83%A8%E7%BD%B2%E9%A1%B9%E7%9B%AE) +- 使用项目:[点击此处](https://github.com/oddfar/campus-imaotai/wiki/%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8#%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8) ## 贡献代码 @@ -93,10 +44,6 @@ i茅台->用户管理->添加账号(若你有token,可直接点击“直接 - - - - ## 鸣谢 > [IntelliJ IDEA](https://zh.wikipedia.org/zh-hans/IntelliJ_IDEA) 是一个在各个方面都最大程度地提高开发人员的生产力的 IDE,适用于 JVM 平台语言。 diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/controller/IUserController.java b/campus-modular/src/main/java/com/oddfar/campus/business/controller/IUserController.java index 4b6912c..8f0d440 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/controller/IUserController.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/controller/IUserController.java @@ -52,16 +52,15 @@ public R sendCode(String mobile) { } /** - * 发送验证码 + * 预约 */ @GetMapping("/reservation") public R reservation(String mobile) { IUser user = iUserMapper.selectById(mobile); if (user == null || StringUtils.isEmpty(user.getItemCode())) { return R.error("用户不存在或配置不对"); - }else { + } else { imtService.reservation(user); - return R.ok(); } diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/controller/TestController.java b/campus-modular/src/main/java/com/oddfar/campus/business/controller/TestController.java index 752f38f..d897a4a 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/controller/TestController.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/controller/TestController.java @@ -1,11 +1,14 @@ package com.oddfar.campus.business.controller; +import com.oddfar.campus.business.entity.IShop; +import com.oddfar.campus.business.mapper.IShopMapper; import com.oddfar.campus.business.mapper.IUserMapper; import com.oddfar.campus.business.service.IMTService; import com.oddfar.campus.business.service.IShopService; import com.oddfar.campus.common.annotation.Anonymous; import com.oddfar.campus.common.annotation.ApiResource; import com.oddfar.campus.common.annotation.Log; +import com.oddfar.campus.common.core.RedisCache; import com.oddfar.campus.common.domain.R; import com.oddfar.campus.common.enums.ResBizTypeEnum; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequestMapping("/test") @ApiResource(name = "测试", appCode = "test", resBizType = ResBizTypeEnum.BUSINESS) @@ -25,6 +30,10 @@ public class TestController { private IMTService imtService; @Autowired private IUserMapper iUserMapper; + @Autowired + private IShopMapper iShopMapper; + @Autowired + private RedisCache redisCache; /** * 需要接口权限 @@ -52,7 +61,6 @@ public R test2() { @Anonymous @GetMapping(value = "/3", name = "测试3的接口") public R test3() { - return R.ok(); } diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/mapper/IUserMapper.java b/campus-modular/src/main/java/com/oddfar/campus/business/mapper/IUserMapper.java index 80f0424..b8b1651 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/mapper/IUserMapper.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/mapper/IUserMapper.java @@ -22,6 +22,7 @@ default PageResult selectPage(IUser iUser) { .eqIfPresent(IUser::getUserId, iUser.getUserId()) .eqIfPresent(IUser::getMobile, iUser.getMobile()) .eqIfPresent(IUser::getProvinceName, iUser.getProvinceName()) + .orderByAsc(IUser::getCreateTime) // .betweenIfPresent(IUser::getCreateTime, iUser.getParams()) ); @@ -30,10 +31,10 @@ default PageResult selectPage(IUser iUser) { default List selectReservationUser() { return selectList(new LambdaQueryWrapperX() .gt(IUser::getExpireTime, new Date()) - .ne(IUser::getLat,"") - .ne(IUser::getLng,"") - .ne(IUser::getShopType,"") - .ne(IUser::getItemCode,"") + .ne(IUser::getLat, "") + .ne(IUser::getLng, "") + .ne(IUser::getShopType, "") + .ne(IUser::getItemCode, "") ); diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTLogFactory.java b/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTLogFactory.java index aeb668c..30cf8cb 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTLogFactory.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTLogFactory.java @@ -23,10 +23,11 @@ public static void reservation(IUser iUser, String shopId, JSONObject json) { operLog.setOperTime(new Date()); operLog.setAppName("i茅台预约"); - if (json.getString("code").equals("2000")){ + if (json.getString("code").equals("2000")) { operLog.setLogName("预约成功"); - }else { + } else { operLog.setLogName("预约失败"); + operLog.setStatus(1); } operLog.setOperUserId(iUser.getMobile()); String str = String.format("[userId]:%s\n[shopId]:%s", iUser.getUserId().toString(), shopId); @@ -47,8 +48,25 @@ public static void reservation(IUser iUser, String shopId) { operLog.setOperUserId(iUser.getMobile()); String str = String.format("[userId]:%s\n[shopId]:%s\nshopId为空", iUser.getUserId().toString(), shopId); operLog.setLogContent(str); + operLog.setStatus(1); + AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); + } + + public static void reservation(IUser iUser, Exception e) { + SysOperLogEntity operLog = new SysOperLogEntity(); + + operLog.setOperTime(new Date()); + operLog.setAppName("i茅台预约"); + + operLog.setLogName("预约失败"); + operLog.setOperUserId(iUser.getMobile()); + String str = String.format("执行报错"); + operLog.setLogContent(str); + operLog.setStatus(1); + operLog.setErrorMsg(e.getMessage()); AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); } + } diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTService.java b/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTService.java index 3d6c855..bacd695 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTService.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/service/IMTService.java @@ -40,4 +40,9 @@ public interface IMTService { * 批量预约 */ void reservationBatch(); + + /** + * 刷新版本号,预约item,门店shop列表, + */ + void refreshAll(); } diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/service/IUserService.java b/campus-modular/src/main/java/com/oddfar/campus/business/service/IUserService.java index 77d4e9e..8888ee9 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/service/IUserService.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/service/IUserService.java @@ -21,6 +21,7 @@ public interface IUserService { /** * 查询预约用户列表 + * * @return */ List selectReservationUser(); 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 f537d87..d203974 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 @@ -184,7 +184,7 @@ public boolean login(String mobile, String code) { // return false; } - } + } @Override @@ -214,12 +214,29 @@ public void reservation(IUser iUser) { @Override public void reservationBatch() { List iUsers = iUserService.selectReservationUser(); -// logger.info(iUsers.toString()); + for (IUser iUser : iUsers) { - reservation(iUser); + try { + logger.info("「开始预约用户」" + iUser.getMobile()); + //预约 + reservation(iUser); + //延时一秒 +// TimeUnit.SECONDS.sleep(1); + } catch (Exception e) { + IMTLogFactory.reservation(iUser, e); + e.printStackTrace(); + } + } } + @Override + public void refreshAll() { + refreshMTVersion(); + iShopService.refreshShop(); + iShopService.refreshItem(); + } + public JSONObject reservation(IUser iUser, String itemId, String shopId) { Map map = new HashMap<>(); 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 b20b8b6..ab93e70 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 @@ -51,6 +51,11 @@ public List selectShopList() { return shopList; } shopList = iShopMapper.selectList(); + if (ObjectUtil.isEmpty(shopList)) { + refreshShop(); + shopList = iShopMapper.selectList(); + } + redisCache.setCacheList("mt_shop_list", shopList); return shopList; } @@ -126,6 +131,7 @@ public List getShopsByProvince(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 JSONObject res = JSONObject.parseObject(HttpUtil.get(url)); List imtItemInfoList = new ArrayList<>(); if (!res.getString("code").equals("2000")) { diff --git a/campus-modular/src/main/java/com/oddfar/campus/business/task/CampusIMTTask.java b/campus-modular/src/main/java/com/oddfar/campus/business/task/CampusIMTTask.java index 2689390..2597e24 100644 --- a/campus-modular/src/main/java/com/oddfar/campus/business/task/CampusIMTTask.java +++ b/campus-modular/src/main/java/com/oddfar/campus/business/task/CampusIMTTask.java @@ -1,24 +1,27 @@ package com.oddfar.campus.business.task; import com.oddfar.campus.business.service.IMTService; -import com.oddfar.campus.business.service.IShopService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; +import java.util.Date; + /** * i茅台定时任务 */ @Configuration @EnableScheduling public class CampusIMTTask { + private static final Logger logger = LoggerFactory.getLogger(CampusIMTTask.class); @Autowired private IMTService imtService; - @Autowired - private IShopService iShopService; + /** * 9:05执行 @@ -26,7 +29,7 @@ public class CampusIMTTask { @Async @Scheduled(cron = "0 5 9 ? * * ") public void reservationBatchTask() { - + logger.info("「批量预约开始」 " + new Date()); imtService.reservationBatch(); } @@ -34,10 +37,8 @@ public void reservationBatchTask() { @Async @Scheduled(cron = "0 25,55 6,7,8 ? * * ") public void refresh() { - - imtService.refreshMTVersion(); - iShopService.refreshShop(); - iShopService.refreshItem(); + logger.info("「刷新数据」开始刷新版本号,预约item,门店shop列表 " + new Date()); + imtService.refreshAll(); } diff --git a/campus-modular/src/main/resources/application-dev.yml b/campus-modular/src/main/resources/application-dev.yml new file mode 100644 index 0000000..e69de29 diff --git a/campus-modular/src/main/resources/application-prod.yml b/campus-modular/src/main/resources/application-prod.yml new file mode 100644 index 0000000..01053ed --- /dev/null +++ b/campus-modular/src/main/resources/application-prod.yml @@ -0,0 +1,29 @@ +spring: + #数据源配置 + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://campus-mysql:3306/campus_imaotai?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: 123456789 + #redis配置 + redis: + host: campus-redis + port: 6379 + database: 0 + timeout: 1800000 + lettuce: + pool: + max-active: 20 + #最大阻塞等待时间(负数表示没限制) + max-wait: -1 + max-idle: 5 + min-idle: 0 + +#mybatis-plus配置 +mybatis-plus: + #mybatis-plus日志 + configuration: + #开启打印 + #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + #关闭打印 + log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl \ No newline at end of file diff --git a/campus-modular/src/main/resources/application.yml b/campus-modular/src/main/resources/application.yml index c4860f7..f567d76 100644 --- a/campus-modular/src/main/resources/application.yml +++ b/campus-modular/src/main/resources/application.yml @@ -1,9 +1,9 @@ # 项目相关配置 campus: # 名称 - name: oddfar-campus + name: campus-imaotai # 版本 - version: 1.1.3 + version: 1.0.1 server: port: 8160 @@ -12,16 +12,16 @@ server: spring: application: name: oddfar + profiles: + active: dev #数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver -# url: jdbc:mysql://campus-mysql:3306/campus_imaotai?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3306/campus_imaotai?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8 username: root password: 123456789 #redis配置 redis: -# host: campus-redis host: 127.0.0.1 port: 6379 database: 0 @@ -81,7 +81,10 @@ mybatis-plus: mapper-locations: classpath*:mapper/**/*Mapper.xml #mybatis-plus日志 configuration: + #开启打印 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + #关闭打印 +# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl global-config: #逻辑删除 db-config: diff --git a/vue_campus_admin/src/views/imt/user/index.vue b/vue_campus_admin/src/views/imt/user/index.vue index 168cb3a..d5d4320 100644 --- a/vue_campus_admin/src/views/imt/user/index.vue +++ b/vue_campus_admin/src/views/imt/user/index.vue @@ -274,13 +274,20 @@ --> - + --> + @@ -354,7 +361,7 @@ export default { title: "", // 是否显示弹出层 open: false, - openUser:false, + openUser: false, // 查询参数 queryParams: { pageNum: 1, diff --git a/vue_campus_admin/src/views/index.vue b/vue_campus_admin/src/views/index.vue index b469b3d..71b9f23 100644 --- a/vue_campus_admin/src/views/index.vue +++ b/vue_campus_admin/src/views/index.vue @@ -1,6 +1,16 @@ @@ -10,7 +20,7 @@ export default { data() { return { // 版本号 - version: "3.8.4", + version: "1.0.1", }; }, methods: {