Commit 3c5affeb authored by leyboy's avatar leyboy

1.登录和修改密码接口对接完毕

parent e94771ec
This diff is collapsed.
This diff is collapsed.
package com.adc.da.znks.server;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* znks server
*
* @author ley
**/
public class ZnksServer {
private static final Logger logger = LoggerFactory.getLogger(ZnksServer.class);
/**
* init znks server
**/
public static void initZnksServer(int port) {
//服务类
ServerBootstrap bootstrap = new ServerBootstrap();
//boss和worker
//EventLoopGroup用来管理和调度netty中的各种线程
EventLoopGroup boss = new NioEventLoopGroup();
EventLoopGroup worker = new NioEventLoopGroup();
try {
//设置线程池
bootstrap.group(boss, worker);
//设置socket工厂、
bootstrap.channel(NioServerSocketChannel.class);
//设置管道工厂
bootstrap.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
}
});
//设置参数,TCP参数
bootstrap.option(ChannelOption.SO_BACKLOG, 2048);//serverSocketchannel的设置,链接缓冲池的大小
bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);//socketchannel的设置,维持链接的活跃,清除死链接
bootstrap.childOption(ChannelOption.TCP_NODELAY, true);//socketchannel的设置,关闭延迟发送
//绑定端口
ChannelFuture future = bootstrap.bind(port);
logger.info("57所netty监听服务启动成功...");
//等待服务端关闭
future.channel().closeFuture().sync();
} catch (Exception e) {
e.printStackTrace();
} finally {
//释放资源
boss.shutdownGracefully();
worker.shutdownGracefully();
}
}
}
package com.adc.da.znks.server.handler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;
/**
* request decoder
**/
public class RequestDecoder extends ByteToMessageDecoder {
/**
*
* **/
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
}
}
package com.adc.da.znks.server.handler;
import com.adc.da.znks.server.utils.ClientUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* znks server handler
*
* @author ley
**/
public class ZnksServerHandler extends ChannelInboundHandlerAdapter {
private static final Logger logger = LoggerFactory.getLogger(ZnksServerHandler.class);
/**
* 存有连接进来的客户端
**/
public static final Map<String, ChannelHandlerContext> clientMap =
new ConcurrentHashMap<>(64);
/**
* 客户端数量
**/
private final AtomicInteger clientNumber = new AtomicInteger(0);
/**
* 接受客户端数据
**/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
}
/**
* 新客户端接入
**/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
String key = ClientUtils.getClientIpAndPort(ctx);
clientMap.put(key, ctx);
clientNumber.incrementAndGet();
logger.info("客户端: {}, 连接成功", key);
logger.info("连接服务端的客户端个数: {}", clientNumber.get());
}
/**
* 客户端断开
**/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
}
/**
* 处理异常
**/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
}
}
package com.adc.da.znks.server.utils;
import io.netty.channel.ChannelHandlerContext;
import java.net.InetSocketAddress;
/**
* client utility class
*
* @author ley
**/
public class ClientUtils {
/**
* get client ip and port
**/
public static String getClientIpAndPort(ChannelHandlerContext context) {
InetSocketAddress clientSocket = (InetSocketAddress) context.channel().remoteAddress();
String clientIp = clientSocket.getAddress().getHostAddress();
int clientPort = clientSocket.getPort();
return clientIp + ":" + clientPort;
}
}
...@@ -43,7 +43,7 @@ public class UserService extends BaseService<User, String> { ...@@ -43,7 +43,7 @@ public class UserService extends BaseService<User, String> {
public Boolean getUserByPhoneNumber(String phoneNumber) { public Boolean getUserByPhoneNumber(String phoneNumber) {
Boolean flag = false; Boolean flag = false;
User user = dao.getUserByPhoneNumber(phoneNumber); User user = dao.getUserByPhoneNumber(phoneNumber);
if(user != null) { if (user != null) {
flag = true; flag = true;
} }
return flag; return flag;
...@@ -60,19 +60,29 @@ public class UserService extends BaseService<User, String> { ...@@ -60,19 +60,29 @@ public class UserService extends BaseService<User, String> {
public boolean updatePassword(User user) { public boolean updatePassword(User user) {
List<String> encryptList = encryptList(user.getPlainPassword()); List<String> encryptList = encryptList(user.getPlainPassword());
Asserts.notNull(encryptList, "encrypt list must not be null."); Asserts.notNull(encryptList, "encrypt list must not be null.");
user.setEncryptkey(encryptList.get(0));
user.setPassword(encryptList.get(1));
UserPage userPage = new UserPage(); UserPage userPage = new UserPage();
user.setTemphone(user.getTemphone()); userPage.setTemphone(user.getTemphone());
User findUser = dao.queryByList(userPage).get(0); List<User> users = dao.queryByList(userPage);
User updateUser = new User(); if (CollectionUtils.isEmpty(users)) {//通过验证码登录时,用户不存在,新增用户
updateUser.setPassword(encryptList.get(1)); user.setId(UUID.randomUUID());
updateUser.setEncryptkey(encryptList.get(0)); user.setPassword(encryptList.get(1));
int result = dao.updateByPrimaryKeySelective(updateUser); user.setEncryptkey(encryptList.get(0));
if (result != 0) { dao.insert(user);
return true; return true;
} else { } else {
return false; //
User findUser = dao.queryByList(userPage).get(0);
logger.info("findUser: {}", findUser);
User updateUser = new User();
updateUser.setPassword(encryptList.get(1));
updateUser.setEncryptkey(encryptList.get(0));
updateUser.setId(findUser.getId());
int result = dao.updateByPrimaryKeySelective(updateUser);
if (result != 0) {
return true;
} else {
return false;
}
} }
} }
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
# =============================== # ===============================
#spring.datasource.driverClassName = oracle.jdbc.OracleDriver #spring.datasource.driverClassName = oracle.jdbc.OracleDriver
##数据库服务器外网ip221.239.111.146 内网10.10.0.3 ##数据库服务器外网ip221.239.111.146 内网10.10.0.3
spring.datasource.ds2.url = jdbc:oracle:thin:@60.30.69.61:1521:ADC #spring.datasource.ds2.url = jdbc:oracle:thin:@60.30.69.61:1521:ADC
spring.datasource.ds2.username = cedet_baoxin #spring.datasource.ds2.username = cedet_baoxin
spring.datasource.ds2.password = cedet_baoxin #spring.datasource.ds2.password = cedet_baoxin
spring.datasource.type = com.alibaba.druid.pool.DruidDataSource spring.datasource.type = com.alibaba.druid.pool.DruidDataSource
# 下面为连接池的补充设置,应用到上面所有数据源中 # 下面为连接池的补充设置,应用到上面所有数据源中
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.adc.da.znks.dao.BaseEODao" >
<!-- 损伤情况中英文对照信息 -->
<select id="queryUser" resultType="java.util.Map">
select * from sys_user
</select>
</mapper>
127.0.0.1 127.0.0.1
192.168.1.109
localhost localhost
index.html index.html
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4" /> <module version="4">
\ No newline at end of file <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment