Skip to content

Commit

Permalink
🎨 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
oddfar committed Jul 20, 2023
1 parent a778bd0 commit 7c800ad
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public R update(@Validated @RequestBody SysUserEntity user) {
&& !(userService.checkEmailUnique(user))) {
return R.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}

user.setPassword(null);

return R.ok(userService.updateUser(user));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.oddfar.campus.business.api;

import cn.hutool.http.HttpUtil;
import com.oddfar.campus.business.entity.IUser;
import com.oddfar.campus.common.domain.entity.SysOperLogEntity;
import com.oddfar.campus.common.utils.StringUtils;
import com.oddfar.campus.framework.manager.AsyncManager;

import java.util.HashMap;
import java.util.Map;
import java.util.TimerTask;

/**
* @author zhiyuan
*/
public class PushPlusApi {


public static void sendNotice(IUser iUser, SysOperLogEntity operLog) {
String token = iUser.getPushPlusToken();
if (StringUtils.isEmpty(token)) {
return;
}
String title, content;
if (operLog.getStatus() == 0) {
//预约成功
title = iUser.getMobile() + "-i茅台预约成功";
content = operLog.getJsonResult();
AsyncManager.me().execute(sendNotice(token, title, content, "json"));
} else {
//预约失败
title = iUser.getMobile() + "-i茅台预约失败";
content = title;
AsyncManager.me().execute(sendNotice(token, title, content, "txt"));
}


}

/**
* push推送
*
* @param token token
* @param title 消息标题
* @param content 具体消息内容
* @param template 发送消息模板
*/
public static TimerTask sendNotice(String token, String title, String content, String template) {
return new TimerTask() {
@Override
public void run() {
String url = "http://www.pushplus.plus/send";
Map<String, Object> map = new HashMap<>();
map.put("token", token);
map.put("title", title);
map.put("content", content);
if (StringUtils.isEmpty(template)) {
map.put("template", "html");
}
HttpUtil.post(url, map);
}
};
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.oddfar.campus.business.entity;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
Expand All @@ -9,6 +10,8 @@

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
* I茅台用户对象 i_user
Expand Down Expand Up @@ -72,6 +75,11 @@ public class IUser {
*/
private int shopType;

/**
* push_plus_token
*/
private String pushPlusToken;

/**
* 返回参数
*/
Expand All @@ -89,6 +97,9 @@ public class IUser {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date expireTime;

@TableField(exist = false)
private Map<String, Object> params;

public IUser() {
}

Expand All @@ -105,4 +116,11 @@ public IUser(Long mobile, JSONObject jsonObject) {
Date thirtyDaysLater = calendar.getTime();
this.expireTime = thirtyDaysLater;
}

public Map<String, Object> getParams() {
if (params == null) {
params = new HashMap<>();
}
return params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public interface IUserMapper extends BaseMapperX<IUser> {
default PageResult<IUser> selectPage(IUser iUser) {

return selectPage(new LambdaQueryWrapperX<IUser>()
.eqIfPresent(IUser::getUserId, iUser.getUserId())
.eqIfPresent(IUser::getMobile, iUser.getMobile())
.eqIfPresent(IUser::getProvinceName, iUser.getProvinceName())
.orderByAsc(IUser::getCreateTime)
// .betweenIfPresent(IUser::getCreateTime, iUser.getParams())
.eqIfPresent(IUser::getUserId, iUser.getUserId())
.eqIfPresent(IUser::getMobile, iUser.getMobile())
.eqIfPresent(IUser::getProvinceName, iUser.getProvinceName())
.betweenIfPresent(IUser::getExpireTime, iUser.getParams())
.orderByAsc(IUser::getCreateTime)

);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
//推送
PushPlusApi.sendNotice(iUser,operLog);
}

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

AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
//推送
PushPlusApi.sendNotice(iUser,operLog);
}

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

AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
//推送
PushPlusApi.sendNotice(iUser,operLog);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
Expand Down Expand Up @@ -54,6 +55,21 @@ public class IMTServiceImpl implements IMTService {
private final static String AES_KEY = "qbhajinldepmucsonaaaccgypwuvcjaa";
private final static String AES_IV = "2018534749963515";

/**
* 项目启动时,初始化数据
*/
@PostConstruct
public void init() {
new Thread(new Runnable() {
@Override
public void run() {
refreshAll();
}
}).start();

}


@Override
public String getMTVersion() {
String mtVersion = Convert.toStr(redisCache.getCacheObject("mt_version"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import com.oddfar.campus.business.domain.IMTItemInfo;
import com.oddfar.campus.business.domain.MapPoint;
Expand All @@ -15,6 +16,7 @@
import com.oddfar.campus.business.mapper.IShopMapper;
import com.oddfar.campus.business.service.IShopService;
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;
Expand Down Expand Up @@ -132,12 +134,22 @@ public List<IMTItemInfo> getShopsByProvince(String province, String itemId) {

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")) {
String urlRes = HttpUtil.get(url);
JSONObject res = null;
try {
res = JSONObject.parseObject(urlRes);
} catch (JSONException jsonException) {
throw new ServiceException("查询所在省市的投放产品和数量error," + province + "-" + itemId);
}

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

JSONObject data = res.getJSONObject("data");
JSONArray shopList = data.getJSONArray("shops");

Expand Down Expand Up @@ -176,6 +188,7 @@ public String getShopId(int shopType, String itemId, String province, String cit
//预约本市出货量最大的门店
shopId = getMaxInventoryShopId(shopList, list, city);
if (StringUtils.isEmpty(shopId)) {
//本市没有则预约本省最近的
shopId = getMinDistanceShopId(list, province, lat, lng);
}
}
Expand Down
3 changes: 2 additions & 1 deletion campus-modular/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring:
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
password: oddfar_imaotai
#redis配置
redis:
host: campus-redis
Expand All @@ -18,6 +18,7 @@ spring:
max-wait: -1
max-idle: 5
min-idle: 0
password: oddfar_imaotai

#mybatis-plus配置
mybatis-plus:
Expand Down
2 changes: 1 addition & 1 deletion campus-modular/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ campus:
# 名称
name: campus-imaotai
# 版本
version: 1.0.1
version: 1.0.2

server:
port: 8160
Expand Down
26 changes: 15 additions & 11 deletions sql/campus_imaotai-V1.0.0.sql → sql/campus_imaotai-1.0.2.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;

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

-- ----------------------------
-- Records of i_user
-- ----------------------------
BEGIN;
COMMIT;

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

-- ----------------------------
-- Records of sys_log_login
-- ----------------------------
BEGIN;
COMMIT;

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

) ENGINE=InnoDB AUTO_INCREMENT=1682020188803141634 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='操作日志记录';

-- ----------------------------
-- Records of sys_log_oper
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for sys_menu
Expand Down Expand Up @@ -492,8 +496,8 @@ CREATE TABLE `sys_user` (
-- Records of sys_user
-- ----------------------------
BEGIN;
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', '[email protected]', '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');
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', '[email protected]', '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');
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', '[email protected]', '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');
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', '[email protected]', '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');
COMMIT;

-- ----------------------------
Expand Down
Loading

0 comments on commit 7c800ad

Please sign in to comment.