package com.song.manage.impl;
import com.alibaba.fastjson.JSONObject;
import com.song.common.api.BaseApiService;
import com.song.common.constants.Constants;
import com.song.common.constants.DBTableName;
import com.song.common.constants.MQInterfaceType;
import com.song.common.enums.MsgCode;
import com.song.common.redis.BaseRedisService;
import com.song.common.utils.DateUtils;
import com.song.common.utils.MD5Util;
import com.song.common.utils.TokenUtils;
import com.song.dao.UserDao;
import com.song.entity.UserEntity;
import com.song.manage.UserServiceManage;
import com.song.mq.producer.RegisterMailboxProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.catalina.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.jms.Destination;
import java.util.Map;
/**
* created on 2019/3/8 13:51
*
* @author nfboy_liusong@163.com
* @version 1.0.0
*/
@Slf4j
@Service
public class UserServiceManageImpl extends BaseApiService implements UserServiceManage {
@Autowired
private UserDao userDao;
@Autowired
private TokenUtils tokenUtils;
@Autowired
private BaseRedisService baseRedisService;
@Autowired
private RegisterMailboxProducer registerMailboxProducer;
@Value("${messages.queue}")
private String MESSAGES_QUEUE;
@Override
@Transactional(rollbackFor = Exception.class)
public void register(UserEntity userEntity) {
userEntity.setCreated(DateUtils.getTimestamp());
userEntity.setUpdated(DateUtils.getTimestamp());
String phone = userEntity.getPhone();
String password = userEntity.getPassword();
userEntity.setPassword(md5PassSalt(phone, password));
userDao.save(userEntity, DBTableName.TABLE_MB_USER);
//队列
Destination activeMQQueue = new ActiveMQQueue(MESSAGES_QUEUE);
//JSON 组装
String mailMessage = mailMessage(userEntity.getEmail(), userEntity.getUserName());
log.info("----- register() 注册发送邮件报文 mailMessage:{}", mailMessage);
registerMailboxProducer.send(activeMQQueue, mailMessage);
}
/**
* 组装报文
*
* @param email
* @param userName
* @return
*/
private String mailMessage(String email, String userName) {
JSONObject root = new JSONObject();
JSONObject header = new JSONObject();
header.put("interfaceType", MQInterfaceType.SMS_MAIL);
JSONObject content = new JSONObject();
content.put("mail", email);
content.put("userName", userName);
root.put("header", header);
root.put("content", content);
return root.toJSONString();
}
@Override
public String md5PassSalt(String phone, String password) {
String newPassword = MD5Util.MD5(phone + password);
return newPassword;
}
/**
* 登录查找并生成 Token
*
* @param userEntity
* @return
*/
@Override
public Map<String, Object> login(UserEntity userEntity) {
//往数据库进行查找数据
String phone = userEntity.getPhone();
String password = userEntity.getPassword();
String newPassword = md5PassSalt(phone, password);
UserEntity userPhoneAndPwd = userDao.getUserPhoneAndPwd(phone, newPassword);
if (userPhoneAndPwd == null) {
return setResultError(MsgCode.SYS_ACCOUNT_ERROR.getMessage());
}
String openId = userEntity.getOpenId();
if (!StringUtils.isEmpty(openId)){
//关联到数据库中,update
UserEntity newUserEntity = new UserEntity();
newUserEntity.setOpenId(openId);
newUserEntity.setUpdated(DateUtils.getTimestamp());
userDao.update(newUserEntity, DBTableName.TABLE_MB_USER, userPhoneAndPwd.getId());
}
String token = setLoginToken(userPhoneAndPwd.getId());
return setResultSuccessData(token);
}
@Override
public Map<String, Object> getUser(String token) {
//从redis中查找userId
String userId = baseRedisService.get(token);
if (StringUtils.isEmpty(userId)){
return setResultError(MsgCode.SYS_INVALID_LOGIN.getMessage());
}
Long newUserId = Long.parseLong(userId);
UserEntity userEntity = userDao.getUserInfo(newUserId);
userEntity.setPassword(null);
return setResultSuccessData(userEntity);
}
@Override
public UserEntity getUserInfo(String phone, String email) {
return userDao.getUser(phone, email);
}
@Override
public Map<String, Object> findLogin(String openId) {
UserEntity userEntity = userDao.findOpenId(openId);
if (null == userEntity){
return setResultError(MsgCode.SYS_USER_IS_NOT_EXIT.getMessage());
}
//自动登录
String token = setLoginToken(userEntity.getId());
return setResultSuccessData(token);
}
private String setLoginToken(Long userId) {
//生成对应的token
String token = tokenUtils.getToken();
//key为自定义令牌,用户的userId作作为value 存放在redis中
baseRedisService.set(token, userId + "", Constants.USER_TOKEN_TERM_VALIDITY);
return token;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
MySQL项目管理工具使用Maven、版本控制工具使用GIT、项目自动部署工具使用Jenkins消息中间件使用ActiveMQ、分布式任务调度系统使用XXLJOB、反向代理工具使用Nginx日志管理插件工具使用lombok、分布式日志收集使用Logstash、解析J… 各领域数据集,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! 软件开发设计:PHP、QT、应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、IOS、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 云计算与大数据:数据集、包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计&课程设计-MySQL项目管理工具使用Maven、版本控制工具使用GIT.zip (130个子文件)
xmapp_b17276b.css 131KB
order.css 131KB
order_info.css 131KB
login.css 18KB
index.css 14KB
user.css 9KB
cart.css 2KB
loading.css 2KB
adaptive.css 2KB
common.css 1021B
iconfont1.eot 16KB
login.ftl 13KB
localRegister.ftl 11KB
associatedAccount.ftl 9KB
bottom.ftl 1KB
index.ftl 42B
song-shop-parent.iml 80B
UserServiceManageImpl.java 5KB
LoginController.java 5KB
ReflectionUtils.java 4KB
DateUtils.java 3KB
PaymentInfoServiceImpl.java 3KB
UserServiceImpl.java 3KB
LogAspectServiceApi.java 2KB
BaseApiService.java 2KB
RegisterController.java 2KB
BaseProvider.java 2KB
ConsumerDistribute.java 2KB
BaseRedisService.java 1KB
BaseController.java 1KB
CookieUtil.java 1KB
SMSMailboxService.java 1KB
PaymentInfoService.java 1KB
UserService.java 1KB
MsgCode.java 1KB
MD5Util.java 1KB
UserDao.java 1KB
PaymentInfoDao.java 1KB
DemoApiServiceImpl.java 1KB
BaseDao.java 803B
UserServiceManage.java 751B
RegisterMailboxProducer.java 663B
DemoApiService.java 645B
DemoController.java 632B
PaymentInfo.java 574B
AppMobile.java 569B
UserEntity.java 542B
EureKaServer.java 526B
MessagesServer.java 510B
MemberServer.java 496B
PayServer.java 479B
Constants.java 427B
BaseApiConstants.java 420B
BaseEntity.java 396B
PaymentType.java 396B
PaymentTypeDao.java 378B
MessageAdapter.java 334B
TokenUtils.java 319B
TestEntity.java 309B
UserFeign.java 305B
DBTableName.java 217B
MQInterfaceType.java 201B
TDSjiancebi_04!720x720.jpg 203KB
TDSjiancebi_02!720x720.jpg 203KB
TDSjiancebi_01!720x720.jpg 164KB
TDSjiancebi_03!720x720.jpg 144KB
TDSbihaoshuigai!720x720.jpg 124KB
T1NKV_BvZT1RXrhCrK!720x720.jpg 122KB
TDSjiancebi_07!720x720.jpg 115KB
T19OV_BgKT1RXrhCrK!720x720.jpg 109KB
T1Z0b_BgWv1RXrhCrK!720x720.jpg 109KB
TDSjiancebi_05!720x720.jpg 105KB
TDSjiancebi_06!720x720.jpg 67KB
banner1.jpg 64KB
T1QtxTBvET1RXrhCrK.jpg 32KB
banner2.jpg 24KB
T1wLDTBbxT1RXrhCrK.jpg 20KB
T1ltWvBCxv1RXrhCrK!180x180.jpg 14KB
order1.jpg 14KB
T1QtxTBvET1RXrhCrK!180x180.jpg 11KB
TDSjiancebi_09!720x720.jpg 10KB
T1ggWQBybT1RXrhCrK!180x180.jpg 10KB
order2.jpg 8KB
T1zFxvB7xT1RXrhCrK.jpg 5KB
T13yAgBvZT1RXrhCrK.jpg 5KB
T1DhbvBsbv1RXrhCrK.jpg 5KB
swipe.js 12KB
ready.js 739B
base.2019-03-07.log 79KB
base.2019-03-05.log 9KB
cart.png 31KB
4.png 8KB
6.png 8KB
2.png 6KB
b5-0.png 5KB
3.png 5KB
5.png 5KB
1.png 4KB
logo.png 507B
sign_icon.png 401B
共 130 条
- 1
- 2
资源评论
妄北y
- 粉丝: 9668
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功