Skip to content

Commit

Permalink
🎨 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oddfar committed Jul 10, 2023
1 parent a58400a commit a778bd0
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 84 deletions.
57 changes: 2 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

### 本地部署

<https://oddfar.github.io/campus-doc/pages/3c5985/>

### 配置

**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)

## 贡献代码

Expand All @@ -93,10 +44,6 @@ i茅台->用户管理->添加账号(若你有token,可直接点击“直接







## 鸣谢

> [IntelliJ IDEA](https://zh.wikipedia.org/zh-hans/IntelliJ_IDEA) 是一个在各个方面都最大程度地提高开发人员的生产力的 IDE,适用于 JVM 平台语言。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -25,6 +30,10 @@ public class TestController {
private IMTService imtService;
@Autowired
private IUserMapper iUserMapper;
@Autowired
private IShopMapper iShopMapper;
@Autowired
private RedisCache redisCache;

/**
* 需要接口权限
Expand Down Expand Up @@ -52,7 +61,6 @@ public R test2() {
@Anonymous
@GetMapping(value = "/3", name = "测试3的接口")
public R test3() {

return R.ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ default PageResult<IUser> 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())
);

Expand All @@ -30,10 +31,10 @@ default PageResult<IUser> selectPage(IUser iUser) {
default List<IUser> selectReservationUser() {
return selectList(new LambdaQueryWrapperX<IUser>()
.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, "")

);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public interface IMTService {
* 批量预约
*/
void reservationBatch();

/**
* 刷新版本号,预约item,门店shop列表,
*/
void refreshAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IUserService {

/**
* 查询预约用户列表
*
* @return
*/
List<IUser> selectReservationUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public boolean login(String mobile, String code) {
// return false;
}

}
}


@Override
Expand Down Expand Up @@ -214,12 +214,29 @@ public void reservation(IUser iUser) {
@Override
public void reservationBatch() {
List<IUser> 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<String, Object> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public List<IShop> selectShopList() {
return shopList;
}
shopList = iShopMapper.selectList();
if (ObjectUtil.isEmpty(shopList)) {
refreshShop();
shopList = iShopMapper.selectList();
}

redisCache.setCacheList("mt_shop_list", shopList);
return shopList;
}
Expand Down Expand Up @@ -126,6 +131,7 @@ public List<IMTItemInfo> 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<IMTItemInfo> imtItemInfoList = new ArrayList<>();
if (!res.getString("code").equals("2000")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
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执行
*/
@Async
@Scheduled(cron = "0 5 9 ? * * ")
public void reservationBatchTask() {

logger.info("「批量预约开始」 " + new Date());
imtService.reservationBatch();

}

@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();

}

Expand Down
Empty file.
29 changes: 29 additions & 0 deletions campus-modular/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit a778bd0

Please sign in to comment.