Skip to content

Commit 7c800ad

Browse files
committed
🎨 1.0.2
1 parent a778bd0 commit 7c800ad

File tree

11 files changed

+185
-54
lines changed

11 files changed

+185
-54
lines changed

campus-admin/src/main/java/com/oddfar/campus/admin/controller/system/SysUserController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public R update(@Validated @RequestBody SysUserEntity user) {
9292
&& !(userService.checkEmailUnique(user))) {
9393
return R.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
9494
}
95-
95+
user.setPassword(null);
9696

9797
return R.ok(userService.updateUser(user));
9898
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.oddfar.campus.business.api;
2+
3+
import cn.hutool.http.HttpUtil;
4+
import com.oddfar.campus.business.entity.IUser;
5+
import com.oddfar.campus.common.domain.entity.SysOperLogEntity;
6+
import com.oddfar.campus.common.utils.StringUtils;
7+
import com.oddfar.campus.framework.manager.AsyncManager;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.TimerTask;
12+
13+
/**
14+
* @author zhiyuan
15+
*/
16+
public class PushPlusApi {
17+
18+
19+
public static void sendNotice(IUser iUser, SysOperLogEntity operLog) {
20+
String token = iUser.getPushPlusToken();
21+
if (StringUtils.isEmpty(token)) {
22+
return;
23+
}
24+
String title, content;
25+
if (operLog.getStatus() == 0) {
26+
//预约成功
27+
title = iUser.getMobile() + "-i茅台预约成功";
28+
content = operLog.getJsonResult();
29+
AsyncManager.me().execute(sendNotice(token, title, content, "json"));
30+
} else {
31+
//预约失败
32+
title = iUser.getMobile() + "-i茅台预约失败";
33+
content = title;
34+
AsyncManager.me().execute(sendNotice(token, title, content, "txt"));
35+
}
36+
37+
38+
}
39+
40+
/**
41+
* push推送
42+
*
43+
* @param token token
44+
* @param title 消息标题
45+
* @param content 具体消息内容
46+
* @param template 发送消息模板
47+
*/
48+
public static TimerTask sendNotice(String token, String title, String content, String template) {
49+
return new TimerTask() {
50+
@Override
51+
public void run() {
52+
String url = "http://www.pushplus.plus/send";
53+
Map<String, Object> map = new HashMap<>();
54+
map.put("token", token);
55+
map.put("title", title);
56+
map.put("content", content);
57+
if (StringUtils.isEmpty(template)) {
58+
map.put("template", "html");
59+
}
60+
HttpUtil.post(url, map);
61+
}
62+
};
63+
}
64+
65+
}

campus-modular/src/main/java/com/oddfar/campus/business/entity/IUser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.oddfar.campus.business.entity;
22

33
import com.alibaba.fastjson2.JSONObject;
4+
import com.baomidou.mybatisplus.annotation.TableField;
45
import com.baomidou.mybatisplus.annotation.TableId;
56
import com.baomidou.mybatisplus.annotation.TableName;
67
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -9,6 +10,8 @@
910

1011
import java.util.Calendar;
1112
import java.util.Date;
13+
import java.util.HashMap;
14+
import java.util.Map;
1215

1316
/**
1417
* I茅台用户对象 i_user
@@ -72,6 +75,11 @@ public class IUser {
7275
*/
7376
private int shopType;
7477

78+
/**
79+
* push_plus_token
80+
*/
81+
private String pushPlusToken;
82+
7583
/**
7684
* 返回参数
7785
*/
@@ -89,6 +97,9 @@ public class IUser {
8997
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
9098
private Date expireTime;
9199

100+
@TableField(exist = false)
101+
private Map<String, Object> params;
102+
92103
public IUser() {
93104
}
94105

@@ -105,4 +116,11 @@ public IUser(Long mobile, JSONObject jsonObject) {
105116
Date thirtyDaysLater = calendar.getTime();
106117
this.expireTime = thirtyDaysLater;
107118
}
119+
120+
public Map<String, Object> getParams() {
121+
if (params == null) {
122+
params = new HashMap<>();
123+
}
124+
return params;
125+
}
108126
}

campus-modular/src/main/java/com/oddfar/campus/business/mapper/IUserMapper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ public interface IUserMapper extends BaseMapperX<IUser> {
1919
default PageResult<IUser> selectPage(IUser iUser) {
2020

2121
return selectPage(new LambdaQueryWrapperX<IUser>()
22-
.eqIfPresent(IUser::getUserId, iUser.getUserId())
23-
.eqIfPresent(IUser::getMobile, iUser.getMobile())
24-
.eqIfPresent(IUser::getProvinceName, iUser.getProvinceName())
25-
.orderByAsc(IUser::getCreateTime)
26-
// .betweenIfPresent(IUser::getCreateTime, iUser.getParams())
22+
.eqIfPresent(IUser::getUserId, iUser.getUserId())
23+
.eqIfPresent(IUser::getMobile, iUser.getMobile())
24+
.eqIfPresent(IUser::getProvinceName, iUser.getProvinceName())
25+
.betweenIfPresent(IUser::getExpireTime, iUser.getParams())
26+
.orderByAsc(IUser::getCreateTime)
27+
2728
);
2829

2930
}

campus-modular/src/main/java/com/oddfar/campus/business/service/IMTLogFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.alibaba.fastjson2.JSON;
44
import com.alibaba.fastjson2.JSONObject;
5+
import com.oddfar.campus.business.api.PushPlusApi;
56
import com.oddfar.campus.business.entity.IUser;
67
import com.oddfar.campus.common.domain.entity.SysOperLogEntity;
78
import com.oddfar.campus.common.utils.StringUtils;
@@ -36,6 +37,8 @@ public static void reservation(IUser iUser, String shopId, JSONObject json) {
3637
operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(json), 0, 2000));
3738

3839
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
40+
//推送
41+
PushPlusApi.sendNotice(iUser,operLog);
3942
}
4043

4144
public static void reservation(IUser iUser, String shopId) {
@@ -51,6 +54,8 @@ public static void reservation(IUser iUser, String shopId) {
5154
operLog.setStatus(1);
5255

5356
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
57+
//推送
58+
PushPlusApi.sendNotice(iUser,operLog);
5459
}
5560

5661
public static void reservation(IUser iUser, Exception e) {
@@ -67,6 +72,8 @@ public static void reservation(IUser iUser, Exception e) {
6772
operLog.setErrorMsg(e.getMessage());
6873

6974
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
75+
//推送
76+
PushPlusApi.sendNotice(iUser,operLog);
7077
}
7178

7279
}

campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IMTServiceImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.beans.factory.annotation.Autowired;
2626
import org.springframework.stereotype.Service;
2727

28+
import javax.annotation.PostConstruct;
2829
import java.security.MessageDigest;
2930
import java.security.NoSuchAlgorithmException;
3031
import java.util.HashMap;
@@ -54,6 +55,21 @@ public class IMTServiceImpl implements IMTService {
5455
private final static String AES_KEY = "qbhajinldepmucsonaaaccgypwuvcjaa";
5556
private final static String AES_IV = "2018534749963515";
5657

58+
/**
59+
* 项目启动时,初始化数据
60+
*/
61+
@PostConstruct
62+
public void init() {
63+
new Thread(new Runnable() {
64+
@Override
65+
public void run() {
66+
refreshAll();
67+
}
68+
}).start();
69+
70+
}
71+
72+
5773
@Override
5874
public String getMTVersion() {
5975
String mtVersion = Convert.toStr(redisCache.getCacheObject("mt_version"));

campus-modular/src/main/java/com/oddfar/campus/business/service/impl/IShopServiceImpl.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cn.hutool.http.HttpUtil;
77
import cn.hutool.http.Method;
88
import com.alibaba.fastjson2.JSONArray;
9+
import com.alibaba.fastjson2.JSONException;
910
import com.alibaba.fastjson2.JSONObject;
1011
import com.oddfar.campus.business.domain.IMTItemInfo;
1112
import com.oddfar.campus.business.domain.MapPoint;
@@ -15,6 +16,7 @@
1516
import com.oddfar.campus.business.mapper.IShopMapper;
1617
import com.oddfar.campus.business.service.IShopService;
1718
import com.oddfar.campus.common.core.RedisCache;
19+
import com.oddfar.campus.common.exception.ServiceException;
1820
import com.oddfar.campus.common.utils.StringUtils;
1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
@@ -132,12 +134,22 @@ public List<IMTItemInfo> getShopsByProvince(String province, String itemId) {
132134

133135
String url = "https://static.moutai519.com.cn/mt-backend/xhr/front/mall/shop/list/slim/v3/" + getCurrentSessionId() + "/" + province + "/" + itemId + "/" + dayTime;
134136
//TODO
135-
JSONObject res = JSONObject.parseObject(HttpUtil.get(url));
136-
List<IMTItemInfo> imtItemInfoList = new ArrayList<>();
137-
if (!res.getString("code").equals("2000")) {
137+
String urlRes = HttpUtil.get(url);
138+
JSONObject res = null;
139+
try {
140+
res = JSONObject.parseObject(urlRes);
141+
} catch (JSONException jsonException) {
142+
throw new ServiceException("查询所在省市的投放产品和数量error," + province + "-" + itemId);
143+
}
144+
145+
// JSONObject res = JSONObject.parseObject(HttpUtil.get(url));
146+
if (!res.containsKey("code") || !res.getString("code").equals("2000")) {
138147
logger.error("查询所在省市的投放产品和数量error," + province + "-" + itemId);
139-
return null;
148+
throw new ServiceException("查询所在省市的投放产品和数量error," + province + "-" + itemId);
140149
}
150+
//组合信息
151+
List<IMTItemInfo> imtItemInfoList = new ArrayList<>();
152+
141153
JSONObject data = res.getJSONObject("data");
142154
JSONArray shopList = data.getJSONArray("shops");
143155

@@ -176,6 +188,7 @@ public String getShopId(int shopType, String itemId, String province, String cit
176188
//预约本市出货量最大的门店
177189
shopId = getMaxInventoryShopId(shopList, list, city);
178190
if (StringUtils.isEmpty(shopId)) {
191+
//本市没有则预约本省最近的
179192
shopId = getMinDistanceShopId(list, province, lat, lng);
180193
}
181194
}

campus-modular/src/main/resources/application-prod.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ spring:
44
driver-class-name: com.mysql.cj.jdbc.Driver
55
url: jdbc:mysql://campus-mysql:3306/campus_imaotai?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
66
username: root
7-
password: 123456789
7+
password: oddfar_imaotai
88
#redis配置
99
redis:
1010
host: campus-redis
@@ -18,6 +18,7 @@ spring:
1818
max-wait: -1
1919
max-idle: 5
2020
min-idle: 0
21+
password: oddfar_imaotai
2122

2223
#mybatis-plus配置
2324
mybatis-plus:

campus-modular/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ campus:
33
# 名称
44
name: campus-imaotai
55
# 版本
6-
version: 1.0.1
6+
version: 1.0.2
77

88
server:
99
port: 8160
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
SET NAMES utf8;
32
SET FOREIGN_KEY_CHECKS = 0;
43

@@ -61,17 +60,13 @@ CREATE TABLE `i_user` (
6160
`lat` varchar(50) DEFAULT NULL COMMENT '纬度',
6261
`lng` varchar(50) DEFAULT NULL COMMENT '经度',
6362
`shop_type` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '1:预约本市出货量最大的门店;2:预约你的位置(经纬度)附近门店;',
63+
`push_plus_token` varchar(50) DEFAULT NULL COMMENT 'push_plus_token',
6464
`json_result` varchar(2000) DEFAULT NULL COMMENT '返回参数',
6565
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
6666
`expire_time` datetime DEFAULT NULL COMMENT '到期时间',
6767
PRIMARY KEY (`mobile`) USING BTREE
6868
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='I茅台用户表';
6969

70-
-- ----------------------------
71-
-- Records of i_user
72-
-- ----------------------------
73-
BEGIN;
74-
COMMIT;
7570

7671
-- ----------------------------
7772
-- Table structure for sys_config
@@ -205,8 +200,13 @@ CREATE TABLE `sys_log_login` (
205200
`msg` varchar(255) DEFAULT '' COMMENT '提示消息',
206201
`login_time` datetime DEFAULT NULL COMMENT '访问时间',
207202
PRIMARY KEY (`info_id`)
208-
) ENGINE=InnoDB AUTO_INCREMENT=1676846836129824770 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='系统访问记录';
203+
) ENGINE=InnoDB AUTO_INCREMENT=1682003222308331523 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='系统访问记录';
209204

205+
-- ----------------------------
206+
-- Records of sys_log_login
207+
-- ----------------------------
208+
BEGIN;
209+
COMMIT;
210210

211211
-- ----------------------------
212212
-- Table structure for sys_log_oper
@@ -228,9 +228,13 @@ CREATE TABLE `sys_log_oper` (
228228
`error_msg` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '错误消息',
229229
`oper_time` datetime DEFAULT NULL COMMENT '操作时间',
230230
PRIMARY KEY (`oper_id`)
231-
) ENGINE=InnoDB AUTO_INCREMENT=1677121504527036418 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='操作日志记录';
232-
231+
) ENGINE=InnoDB AUTO_INCREMENT=1682020188803141634 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='操作日志记录';
233232

233+
-- ----------------------------
234+
-- Records of sys_log_oper
235+
-- ----------------------------
236+
BEGIN;
237+
COMMIT;
234238

235239
-- ----------------------------
236240
-- Table structure for sys_menu
@@ -492,8 +496,8 @@ CREATE TABLE `sys_user` (
492496
-- Records of sys_user
493497
-- ----------------------------
494498
BEGIN;
495-
INSERT INTO `sys_user` (`user_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `login_ip`, `login_date`, `remark`, `create_user`, `create_time`, `update_user`, `update_time`, `del_flag`) VALUES (1, 'admin', 'admin', '00', 'oddfar@163.com', '15888888888', '0', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '127.0.0.1', '2023-07-06 14:53:35', '管理员', 0, '2022-10-05 15:28:43', 1, '2023-07-06 14:53:35', b'0');
496-
INSERT INTO `sys_user` (`user_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `login_ip`, `login_date`, `remark`, `create_user`, `create_time`, `update_user`, `update_time`, `del_flag`) VALUES (2, 'zhiyuan', '致远', '00', 'a_zhiyuan@163.com', '15666666666', '1', '', '$2a$10$LtM4R7ovl31aBeT8yLrb.uoMFjU4TisUHHSZk4/PsLVkkyZT.Fgf.', '0', '127.0.0.1', '2023-02-25 23:01:16', '测试', 0, '2022-10-05 15:28:43', 2, '2023-02-25 23:01:16', b'0');
499+
INSERT INTO `sys_user` (`user_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `login_ip`, `login_date`, `remark`, `create_user`, `create_time`, `update_user`, `update_time`, `del_flag`) VALUES (1, 'admin', 'admin', '00', 'oddfar@163.com', '15888888888', '0', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '127.0.0.1', '2023-07-20 20:23:13', '管理员', 0, '2022-10-05 15:28:43', 1, '2023-07-20 20:23:13', b'0');
500+
INSERT INTO `sys_user` (`user_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `login_ip`, `login_date`, `remark`, `create_user`, `create_time`, `update_user`, `update_time`, `del_flag`) VALUES (2, 'zhiyuan', '致远', '00', 'a_zhiyuan@163.com', '15666666666', '1', 'https://img0.baidu.com/it/u=1183896628,1403534286&fm=253&fmt=auto&app=138&f=PNG', '$2a$10$0522gOEarwIDNCk57dsrNeGqXTDwx2Zpy447d8R7W5MbH4/j1rcQi', '0', '127.0.0.1', '2023-02-25 23:01:16', '测试1', 0, '2022-10-05 15:28:43', 1, '2023-07-15 23:18:08', b'0');
497501
COMMIT;
498502

499503
-- ----------------------------

0 commit comments

Comments
 (0)