diff --git a/miaosha-admin/miaosha-admin-api/pom.xml b/miaosha-admin/miaosha-admin-api/pom.xml
index 80f6096..cbcac23 100644
--- a/miaosha-admin/miaosha-admin-api/pom.xml
+++ b/miaosha-admin/miaosha-admin-api/pom.xml
@@ -33,6 +33,8 @@
miaosha-common
0.0.1-SNAPSHOT
+
+
org.mybatis
mybatis-spring
diff --git a/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/entity/Account.java b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/entity/Account.java
new file mode 100644
index 0000000..4d8b46a
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/entity/Account.java
@@ -0,0 +1,63 @@
+package com.geekq.admin.entity;
+
+import com.geekq.common.utils.MD5.MD5Utils;
+import com.geekq.common.utils.numcal.BidConst;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.ibatis.type.Alias;
+
+import java.math.BigDecimal;
+
+/**
+ * 用户的帐户信息账户 一个LoginInfo 对应一个UserInfo对应一个Account
+ *
+ * @author 邱润泽
+ */
+@Getter
+@Setter
+@Alias("Account")
+public class Account extends BaseDomain {
+ private static final long serialVersionUID = 6760287512112252557L;
+ private int version;
+ private String tradePassword; // 交易密码
+ private BigDecimal usableAmount = BidConst.ZERO; // 可用余额
+ private BigDecimal freezedAmount = BidConst.ZERO; // 冻结金额
+ private BigDecimal unReceiveInterest = BidConst.ZERO; // 账户待收利息
+ private BigDecimal unReceivePrincipal = BidConst.ZERO; // 账户待收本金
+ private BigDecimal unReturnAmount = BidConst.ZERO; // 账户待还金额
+ private BigDecimal remainBorrowLimit = BidConst.ZERO; // 账户剩余授信额度
+ private BigDecimal borrowLimitAmount; // 授信额度(当前还可以信用借款额度)
+
+ private String abstractInfo;//摘要信息用于防篡改检查;
+
+ public String getAbstractInfo() {//可用余额 + 冻结金额 + 账户神域的授权额度
+ return MD5Utils.MD5(usableAmount.add(freezedAmount)
+ .add(remainBorrowLimit).toString());
+ }
+
+ public boolean checkAbstractInfo() {//可用余额 + 冻结金额 + 账户神域的授权额度
+ return MD5Utils.MD5(
+ usableAmount.add(freezedAmount).add(remainBorrowLimit)
+ .toString()).equals(abstractInfo);
+ }
+
+ public BigDecimal getTotalAmount() {
+ return usableAmount.add(freezedAmount).add(unReceivePrincipal);
+ }
+
+ public void addUseableAmount(BigDecimal amount) {
+ this.usableAmount = this.usableAmount.add(amount);
+ }
+
+ public void addFreezedAmount(BigDecimal amount) {
+ this.freezedAmount = this.freezedAmount.add(amount);
+ }
+
+ public static Account empty(Long id) {
+ Account account = new Account();
+ account.setId(id);
+ account.setBorrowLimitAmount(BidConst.DEFALUT_BORROWLIMITAMOUNT);
+ account.setRemainBorrowLimit(BidConst.DEFALUT_BORROWLIMITAMOUNT);
+ return account;
+ }
+}
diff --git a/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/IAccountService.java b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/IAccountService.java
new file mode 100644
index 0000000..2cfe823
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/IAccountService.java
@@ -0,0 +1,17 @@
+package com.geekq.admin.service;
+
+
+import com.geekq.admin.entity.Account;
+
+import java.util.List;
+
+public interface IAccountService {
+
+ void update(Account account);
+
+ Account get(Long id);
+
+ void recreateAbstractInfo();
+
+ List listAll();
+}
diff --git a/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/IUserService.java b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/IUserService.java
new file mode 100644
index 0000000..b18ee3d
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/IUserService.java
@@ -0,0 +1,19 @@
+package com.geekq.admin.service;
+
+
+import com.geekq.admin.entity.Userinfo;
+
+public interface IUserService {
+
+ void update(Userinfo userinfo);
+
+ Userinfo get(Long id);
+
+ boolean bindPhone(String phoneNumber, String verifyCode);
+
+ /**
+ * 修改基本信息
+ * @param userinfo
+ */
+ void updateBasicInfo(Userinfo userinfo);
+}
diff --git a/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/RedisCacheStorageService.java b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/RedisCacheStorageService.java
new file mode 100644
index 0000000..799bb21
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-api/src/main/java/com/geekq/admin/service/RedisCacheStorageService.java
@@ -0,0 +1,21 @@
+package com.geekq.admin.service;
+
+import com.geekq.admin.entity.Logininfo;
+
+import java.util.Map;
+
+public interface RedisCacheStorageService {
+
+ /**
+ * 在redis数据库中插入 key 和value
+ *
+ * @param key
+ * @param value
+ * @return
+ */
+ boolean set(String key, V value);
+
+
+
+ Logininfo get(String key);
+}
diff --git a/miaosha-admin/miaosha-admin-service/pom.xml b/miaosha-admin/miaosha-admin-service/pom.xml
index e159321..24146ba 100644
--- a/miaosha-admin/miaosha-admin-service/pom.xml
+++ b/miaosha-admin/miaosha-admin-service/pom.xml
@@ -11,6 +11,20 @@
war
+
+
+
+
+ org.springframework.data
+ spring-data-redis
+ 1.8.4.RELEASE
+
+
+ redis.clients
+ jedis
+ 2.9.0
+
+
com.geekq
miaosha-admin-api
@@ -58,7 +72,11 @@
org.springframework
spring-aspects
-
+
+ redis.clients
+ jedis
+ 2.9.0
+
org.mybatis
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/mapper/AccountMapper.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/mapper/AccountMapper.java
new file mode 100644
index 0000000..83d7109
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/mapper/AccountMapper.java
@@ -0,0 +1,18 @@
+package com.geekq.admin.mapper;
+
+
+import com.geekq.admin.entity.Account;
+
+import java.util.List;
+
+public interface AccountMapper {
+ int deleteByPrimaryKey(Long id);
+
+ int insert(Account record);
+
+ Account selectByPrimaryKey(Long id);
+
+ List selectAll();
+
+ int updateByPrimaryKey(Account record);
+}
\ No newline at end of file
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/mapper/AccountMapper.xml b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/mapper/AccountMapper.xml
new file mode 100644
index 0000000..ce97234
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/mapper/AccountMapper.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ delete from account
+ where id = #{id,jdbcType=BIGINT} and version=#{version}
+
+
+
+ insert into account (id,tradePassword, usableAmount, freezedAmount,
+ borrowLimitAmount, version, unReceiveInterest,
+ unReceivePrincipal, unReturnAmount, remainBorrowLimit,abstractInfo)
+ values (#{id},#{tradePassword,jdbcType=VARCHAR}, #{usableAmount,jdbcType=DECIMAL}, #{freezedAmount,jdbcType=DECIMAL},
+ #{borrowLimitAmount,jdbcType=DECIMAL}, 0, #{unReceiveInterest,jdbcType=DECIMAL},
+ #{unReceivePrincipal,jdbcType=DECIMAL}, #{unReturnAmount,jdbcType=DECIMAL}, #{remainBorrowLimit,jdbcType=DECIMAL},#{abstractInfo})
+
+
+
+ update account
+ set tradePassword = #{tradePassword,jdbcType=VARCHAR},
+ usableAmount = #{usableAmount,jdbcType=DECIMAL},
+ freezedAmount = #{freezedAmount,jdbcType=DECIMAL},
+ borrowLimitAmount = #{borrowLimitAmount,jdbcType=DECIMAL},
+ version = version+1,
+ unReceiveInterest = #{unReceiveInterest,jdbcType=DECIMAL},
+ unReceivePrincipal = #{unReceivePrincipal,jdbcType=DECIMAL},
+ unReturnAmount = #{unReturnAmount,jdbcType=DECIMAL},
+ remainBorrowLimit = #{remainBorrowLimit,jdbcType=DECIMAL},
+ abstractInfo=#{abstractInfo}
+ where id = #{id,jdbcType=BIGINT} and version=#{version}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/redis/RedisClient.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/redis/RedisClient.java
new file mode 100644
index 0000000..eac8422
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/redis/RedisClient.java
@@ -0,0 +1,144 @@
+package com.geekq.admin.redis;
+
+import com.alibaba.fastjson.JSON;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+import java.util.ResourceBundle;
+
+public class RedisClient {
+
+ /**
+ * 池化管理jedis链接池
+ */
+ public static JedisPool jedisPool;
+
+ static {
+
+ //读取相关的配置
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
+ int maxActive = Integer.parseInt(resourceBundle.getString("redis.pool.maxActive"));
+ int maxIdle = Integer.parseInt(resourceBundle.getString("redis.pool.maxIdle"));
+ int maxWait = Integer.parseInt(resourceBundle.getString("redis.pool.maxWait"));
+
+ String ip = resourceBundle.getString("redis.ip");
+ int port = Integer.parseInt(resourceBundle.getString("redis.port"));
+
+ JedisPoolConfig config = new JedisPoolConfig();
+ //设置最大连接数
+ config.setMaxTotal(maxActive);
+ //设置最大空闲数
+ config.setMaxIdle(maxIdle);
+ //设置超时时间
+ config.setMaxWaitMillis(maxWait);
+
+ //初始化连接池
+ jedisPool = new JedisPool(config, ip, port);
+ }
+
+ /**
+ * 向缓存中设置字符串内容
+ *
+ * @param key key
+ * @param value value
+ * @return
+ * @throws Exception
+ */
+ public static boolean set(String key, String value) throws Exception {
+ Jedis jedis = null;
+ try {
+ jedis = jedisPool.getResource();
+ jedis.set(key, value);
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ jedisPool.returnResource(jedis);
+ }
+ }
+
+ /**
+ * 向缓存中设置对象
+ *
+ * @param key
+ * @param value
+ * @return
+ */
+ public static boolean set(String key, Object value) {
+ Jedis jedis = null;
+ try {
+ String objectJson = JSON.toJSONString(value);
+ jedis = jedisPool.getResource();
+ jedis.set(key, objectJson);
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ jedisPool.returnResource(jedis);
+ }
+ }
+
+ /**
+ * 删除缓存中得对象,根据key
+ *
+ * @param key
+ * @return
+ */
+ public static boolean del(String key) {
+ Jedis jedis = null;
+ try {
+ jedis = jedisPool.getResource();
+ jedis.del(key);
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ jedisPool.returnResource(jedis);
+ }
+ }
+
+ /**
+ * 根据key 获取内容
+ *
+ * @param key
+ * @return
+ */
+ public static Object get(String key) {
+ Jedis jedis = null;
+ try {
+ jedis = jedisPool.getResource();
+ Object value = jedis.get(key);
+ return value;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ jedisPool.returnResource(jedis);
+ }
+ }
+
+
+ /**
+ * 根据key 获取对象
+ *
+ * @param key
+ * @return
+ */
+ public static T get(String key, Class clazz) {
+ Jedis jedis = null;
+ try {
+ jedis = jedisPool.getResource();
+ String value = jedis.get(key);
+ return JSON.parseObject(value, clazz);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ } finally {
+ jedisPool.returnResource(jedis);
+ }
+ }
+}
\ No newline at end of file
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/LogininfoServiceImpl.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/LogininfoServiceImpl.java
index 6fe9b88..bcc89c0 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/LogininfoServiceImpl.java
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/LogininfoServiceImpl.java
@@ -1,12 +1,15 @@
package com.geekq.admin.service.impl;
+import com.geekq.admin.entity.Account;
import com.geekq.admin.entity.IpLog;
import com.geekq.admin.entity.Logininfo;
import com.geekq.admin.entity.Userinfo;
+import com.geekq.admin.mapper.AccountMapper;
import com.geekq.admin.mapper.IpLogMapper;
import com.geekq.admin.mapper.LogininfoMapper;
import com.geekq.admin.mapper.UserinfoMapper;
import com.geekq.admin.service.ILogininfoService;
+import com.geekq.admin.service.RedisCacheStorageService;
import com.geekq.admin.utils.UserContext;
import com.geekq.common.enums.Constants;
import com.geekq.common.enums.ResultStatus;
@@ -37,6 +40,11 @@ public class LogininfoServiceImpl implements ILogininfoService {
@Autowired
private UserinfoMapper userinfoMapper;
+ @Autowired
+ private AccountMapper accountMapper;
+
+ @Autowired
+ private RedisCacheStorageService redisService;
@Override
public void register(String username, String password) {
@@ -54,7 +62,13 @@ public class LogininfoServiceImpl implements ILogininfoService {
logininfo.setLastLoginDate(new Date());
logininfo.setSalt(salt);
this.loginInfoMapper.insert(logininfo);
- //初始化一个Userinfo
+
+ //初始化一个account
+ Account account = Account.empty(logininfo.getId());
+ accountMapper.insert(account);
+
+
+ //初始化一个Userinfo
Userinfo userinfo = Userinfo.empty(logininfo.getId());
int result = this.userinfoMapper.insert(userinfo);
}else{
@@ -78,7 +92,8 @@ public class LogininfoServiceImpl implements ILogininfoService {
Logininfo current = this.loginInfoMapper.login(name,
MD5Utils.formPassToDBPass(password,salt), userType);
if(current != null){
- UserContext.putLogininfo(current);
+ redisService.set("Login"+current.getNickname(),current);
+// RedisCacheStorageService.set("login"+current.getId().toString(),10000,current);
log.setLoginInfoId(current.getId());
log.setLoginState(IpLog.LOGINSTATE_SUCCESS);
}
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/RedisCache.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/RedisCache.java
new file mode 100644
index 0000000..79bf807
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/RedisCache.java
@@ -0,0 +1,106 @@
+package com.geekq.admin.service.impl;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+
+import java.io.Serializable;
+
+@Service
+public class RedisCache implements Serializable {
+
+ /**
+ * 日志记录
+ */
+ final static Logger LOG = LoggerFactory.getLogger(RedisCache.class);
+
+ /**
+ * redis 连接池
+ */
+ @Autowired
+ private JedisPool pool;
+
+
+ /*static {
+ if (pool == null) {
+ //读取相关的配置
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
+ int maxActive = Integer.parseInt(resourceBundle.getString("redis.maxActive"));
+ int maxIdle = Integer.parseInt(resourceBundle.getString("redis.maxIdle"));
+ int maxWait = Integer.parseInt(resourceBundle.getString("redis.maxWait"));
+
+ String host = resourceBundle.getString("redis.host");
+ int port = Integer.parseInt(resourceBundle.getString("redis.port"));
+ String pass = resourceBundle.getString("redis.pass");
+
+ JedisPoolConfig config = new JedisPoolConfig();
+ //设置最大连接数
+ config.setMaxTotal(maxActive);
+ //设置最大空闲数
+ config.setMaxIdle(maxIdle);
+ //设置超时时间
+ config.setMaxWaitMillis(maxWait);
+
+ //初始化连接池
+ pool = new JedisPool(config, host, port, 2000, pass);
+ }
+ }*/
+
+ /**
+ * 获取jedis
+ *
+ * @return jedis
+ */
+ public Jedis getResource() {
+ Jedis jedis = null;
+ try {
+ jedis = pool.getResource();
+ } catch (Exception e) {
+ LOG.info("can't get the redis resource");
+ }
+ return jedis;
+ }
+
+ /**
+ * 关闭连接
+ *
+ * @param jedis j
+ */
+ public void disconnect(Jedis jedis) {
+ jedis.disconnect();
+ }
+
+ /**
+ * 将jedis 返还连接池
+ *
+ * @param jedis j
+ */
+ public void returnResource(Jedis jedis) {
+ if (null != jedis) {
+ try {
+ pool.returnResource(jedis);
+ } catch (Exception e) {
+ LOG.info("can't return jedis to jedisPool");
+ }
+ }
+ }
+
+ /**
+ * 无法返还jedispool,释放jedis客户端对象
+ *
+ * @param jedis j
+ */
+ public void brokenResource(Jedis jedis) {
+ if (jedis != null) {
+ try {
+ pool.returnBrokenResource(jedis);
+ } catch (Exception e) {
+ LOG.info("can't release jedis Object");
+ }
+ }
+ }
+
+}
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/RedisCacheStorageServiceImpl.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/RedisCacheStorageServiceImpl.java
new file mode 100644
index 0000000..3eceaf7
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/RedisCacheStorageServiceImpl.java
@@ -0,0 +1,87 @@
+package com.geekq.admin.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.geekq.admin.entity.Logininfo;
+import com.geekq.admin.service.RedisCacheStorageService;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import redis.clients.jedis.Jedis;
+
+@Service("redisCacheStorageServiceImpl")
+public class RedisCacheStorageServiceImpl implements RedisCacheStorageService {
+
+ final static Logger LOG = LoggerFactory.getLogger(RedisCache.class);
+
+
+ @Autowired
+ private RedisCache redisCache;
+ @Override
+ public boolean set(String key, Object value) {
+ Jedis jedis = null;
+ // 将key 和value 转换成 json 对象
+// String jKey = JSON.toJSONString(key);
+ String jValue = JSON.toJSONString(value);
+ // 操作是否成功
+ boolean isSucess = true;
+ if (StringUtils.isEmpty(key)) {
+ LOG.info("key is empty");
+ return false;
+ }
+ try {
+ // 获取客户端对象
+ jedis = redisCache.getResource();
+ // 执行插入
+ jedis.set(key,jValue);
+ } catch (Exception e) {
+ LOG.info("client can't connect server");
+ isSucess = false;
+ if (null != jedis) {
+ // 释放jedis对象
+ redisCache.brokenResource(jedis);
+ }
+ return false;
+ } finally {
+ if (isSucess) {
+ // 返还连接池
+ redisCache.returnResource(jedis);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public Logininfo get(String key) {
+ Jedis jedis = null;
+ try {
+ jedis = redisCache.getResource();
+ //生成真正的key
+ String str = jedis.get(key);
+ Logininfo t = stringToBean(str, Logininfo.class);
+ return t;
+ }finally {
+ redisCache.returnResource(jedis);
+ }
+ }
+
+
+
+ @SuppressWarnings("unchecked")
+ public static T stringToBean(String str, Class clazz) {
+ if(str == null || str.length() <= 0 || clazz == null) {
+ return null;
+ }
+ if(clazz == int.class || clazz == Integer.class) {
+ return (T)Integer.valueOf(str);
+ }else if(clazz == String.class) {
+ return (T)str;
+ }else if(clazz == long.class || clazz == Long.class) {
+ return (T)Long.valueOf(str);
+ }else {
+ return JSON.toJavaObject(JSON.parseObject(str), clazz);
+ }
+ }
+
+}
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/UserServiceImpl.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..b784f4f
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/service/impl/UserServiceImpl.java
@@ -0,0 +1,74 @@
+package com.geekq.admin.service.impl;
+
+import com.geekq.admin.entity.Userinfo;
+import com.geekq.admin.mapper.UserinfoMapper;
+import com.geekq.admin.service.IUserService;
+import com.geekq.admin.utils.UserContext;
+import com.geekq.common.utils.numcal.BitStatesUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Service("userServiceImpl")
+public class UserServiceImpl implements IUserService {
+
+ @Autowired
+ private UserinfoMapper userinfoMapper;
+
+ /*@Autowired
+ private ISendVerifyCodeService verifyCodeService;*/
+
+/*
+ @Value("${db.timeout}")
+ private String salt;
+*/
+
+ @Override
+ public void update(Userinfo userinfo) {
+ /* int ret = userinfoMapper.updateByPrimaryKey(userinfo,salt);
+ if (ret <= 0) {
+ throw new RuntimeException("乐观锁失败");*/
+ /* throw new RuntimeException("Userinfo对象:" + userinfo.getId()
+ + " 乐观锁失败!");*/
+ }
+
+ @Override
+ public Userinfo get(Long id) {
+
+ return null;/*userinfoMapper.selectByPrimaryKey(id,salt);*/
+ }
+
+ @Override
+ public boolean bindPhone(String phoneNumber, String verifyCode) {
+ return false;
+ }
+
+ /*@Override
+ public boolean bindPhone(String phoneNumber, String verifyCode) {
+ boolean ret = verifyCodeService.verifyCode(phoneNumber, verifyCode);
+ if (ret) {
+ Userinfo ui = this.get(UserContext.getCurrent().getId());
+ ui.setPhoneNumber(phoneNumber);
+ ui.addState(BitStatesUtils.OP_BIND_PHONE);
+ this.update(ui);
+ return true;
+ }
+ return false;
+ }*/
+
+ @Override
+ public void updateBasicInfo(Userinfo userinfo) {
+ /* Userinfo current = this.userinfoMapper.selectByPrimaryKey(UserContext
+ .getCurrent().getId(),salt);*/
+ /* current.setEducationBackground(userinfo.getEducationBackground());
+ current.setHouseCondition(userinfo.getHouseCondition());
+ current.setIncomeGrade(userinfo.getIncomeGrade());
+ current.setKidCount(userinfo.getKidCount());
+ current.setMarriage(userinfo.getMarriage());
+ if (!current.getBaseInfo()) {
+ current.addState(BitStatesUtils.OP_BASE_INFO);
+ }
+ this.update(current);*/
+ }
+
+}
diff --git a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/utils/UserContext.java b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/utils/UserContext.java
index b616889..d9644f2 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/utils/UserContext.java
+++ b/miaosha-admin/miaosha-admin-service/src/main/java/com/geekq/admin/utils/UserContext.java
@@ -2,23 +2,59 @@ package com.geekq.admin.utils;
import com.geekq.admin.entity.Logininfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
public class UserContext {
- public static final String LOGIN_IN_SESSION = "logininfo";
- public static final String VERIFYCODE_IN_SESSION = "VERIFYCODE_IN_SESSION";
+ @Autowired
+ private HttpSession session;
- private static HttpServletRequest getRequest() {
- return ((ServletRequestAttributes) RequestContextHolder
- .getRequestAttributes()).getRequest();
- }
+ @Autowired
+ private HttpServletRequest request;
+ public static final String LOGIN_IN_SESSION = "logininfo";
+ public static final String VERIFYCODE_IN_SESSION = "VERIFYCODE_IN_SESSION";
+
+ @Bean
+ public RequestContextListener requestContextListener(){
+ return new RequestContextListener();
+ }
+/* @Autowired
+ private RedisService redisService;*/
+
+ private static HttpServletRequest getRequest() {
+ return ((ServletRequestAttributes) RequestContextHolder
+ .getRequestAttributes()).getRequest();
+ }
+
+ private static ThreadLocal userHolder = new ThreadLocal();
+
+ /* public static void putLogininfo(Logininfo user) {
+
+ userHolder.set(user);
+ }
+ public static Logininfo getCurrent() {
+
+ return userHolder.get();
+ }*/
+
+ public static void removeUser() {
+
+ userHolder.remove();
+ }
public static void putLogininfo(Logininfo logininfo) {
- getRequest().getSession().setAttribute(LOGIN_IN_SESSION, logininfo);
+ HttpServletRequest a = ((ServletRequestAttributes) RequestContextHolder
+ .getRequestAttributes()).getRequest();
+ HttpSession b = a.getSession();
+ b.setAttribute(LOGIN_IN_SESSION, logininfo);
}
public static Logininfo getCurrent() {
diff --git a/miaosha-admin/miaosha-admin-service/src/main/resources/resource/db.properties b/miaosha-admin/miaosha-admin-service/src/main/resources/resource/db.properties
index d3b9969..0b9e1e3 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/resources/resource/db.properties
+++ b/miaosha-admin/miaosha-admin-service/src/main/resources/resource/db.properties
@@ -1,4 +1,5 @@
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/miaosha2?characterEncoding=utf-8
jdbc.username=root
-jdbc.password=nihaoma
+jdbc.password=aixiyue11
+db.properties
\ No newline at end of file
diff --git a/miaosha-admin/miaosha-admin-service/src/main/resources/resource/redis.properties b/miaosha-admin/miaosha-admin-service/src/main/resources/resource/redis.properties
new file mode 100644
index 0000000..4e52b2f
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/resources/resource/redis.properties
@@ -0,0 +1,11 @@
+
+#访问地址
+redis.host=39.107.245.253
+redis.port=6379
+redis.pass=youxin11
+
+redis.maxIdle=25
+redis.maxActive=100
+redis.maxWait=1000
+redis.testOnBorrow=false
+redis.testOnReturn=false
diff --git a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dao.xml b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dao.xml
index 2388a1a..f0786b0 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dao.xml
+++ b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dao.xml
@@ -52,4 +52,5 @@
+
diff --git a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dubbo-provider.xml b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dubbo-provider.xml
index 2f78015..c4afc86 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dubbo-provider.xml
+++ b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-dubbo-provider.xml
@@ -9,7 +9,7 @@
-
+
@@ -21,4 +21,10 @@
+
+
+
+
diff --git a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-redis.xml b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-redis.xml
new file mode 100644
index 0000000..c18c02a
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/applicationContext-redis.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/spring-context.xml b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/spring-context.xml
index ac44a1d..42b4f28 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/resources/spring/spring-context.xml
+++ b/miaosha-admin/miaosha-admin-service/src/main/resources/spring/spring-context.xml
@@ -2,10 +2,14 @@
-
+
-
+
+
+
+
+
diff --git a/miaosha-admin/miaosha-admin-service/src/main/webapp/WEB-INF/web.xml b/miaosha-admin/miaosha-admin-service/src/main/webapp/WEB-INF/web.xml
index 1975bba..3d19941 100644
--- a/miaosha-admin/miaosha-admin-service/src/main/webapp/WEB-INF/web.xml
+++ b/miaosha-admin/miaosha-admin-service/src/main/webapp/WEB-INF/web.xml
@@ -14,5 +14,9 @@
org.springframework.web.context.ContextLoaderListener
-
+
+
+ org.springframework.web.context.request.RequestContextListener
+
+
diff --git a/miaosha-admin/miaosha-admin-web/pom.xml b/miaosha-admin/miaosha-admin-web/pom.xml
index 3d7a951..4e5fc26 100644
--- a/miaosha-admin/miaosha-admin-web/pom.xml
+++ b/miaosha-admin/miaosha-admin-web/pom.xml
@@ -21,6 +21,12 @@
miaosha-admin-api
0.0.1-SNAPSHOT
+
+
+ com.geekq
+ miaosha-admin-service
+ 0.0.1-SNAPSHOT
+
org.freemarker
diff --git a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/LoginController.java b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/LoginController.java
index 8dbd67b..ebe7e4c 100644
--- a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/LoginController.java
+++ b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/LoginController.java
@@ -2,12 +2,14 @@ package com.geekq.web.controller;
import com.geekq.admin.entity.Logininfo;
import com.geekq.admin.service.ILogininfoService;
+import com.geekq.admin.service.RedisCacheStorageService;
import com.geekq.common.enums.Constants;
import com.geekq.common.utils.resultbean.ResultGeekQ;
import com.geekq.common.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -28,15 +30,24 @@ public class LoginController extends BaseController {
@Autowired
private ILogininfoService iLogininfoService;
+
+ @Autowired
+ private RedisCacheStorageService redisCacheStorageService;
+
+
+
@RequestMapping("/login" )
@ResponseBody
- public ResultGeekQ dologin(HttpServletResponse response,
+ public ResultGeekQ dologin(HttpServletResponse response,
HttpServletRequest request,
String username, String password) {
- ResultGeekQ result = ResultGeekQ.build();
+ ResultGeekQ result = ResultGeekQ.build();
+
+
ResultGeekQ login = this.iLogininfoService.login(username, password,
Constants.USERTYPE_NORMAL,request.getRemoteAddr());
- if(ResultGeekQ.isSuccess(login)){
+ result.setData(login.getData());
+ if(!ResultGeekQ.isSuccess(login)){
result.withError(login.getCode(),login.getMessage());
}
return result;
diff --git a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/PersonController.java b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/PersonController.java
new file mode 100644
index 0000000..7c3c51f
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/controller/PersonController.java
@@ -0,0 +1,35 @@
+package com.geekq.web.controller;
+
+import com.geekq.admin.entity.Logininfo;
+import com.geekq.admin.service.IAccountService;
+import com.geekq.admin.service.IUserService;
+import com.geekq.admin.service.RedisCacheStorageService;
+import com.geekq.admin.utils.UserContext;
+import com.geekq.web.interceptor.RequiredLogin;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class PersonController extends BaseController {
+
+ @Autowired
+ private IUserService userinfoService;
+
+ @Autowired
+ private IAccountService accountService;
+
+ @Autowired
+ private RedisCacheStorageService redisService;
+
+ @RequiredLogin
+ @RequestMapping("/personal")
+ public String personal(Model model) {
+ //从中拿到 用户信息对象
+ Logininfo info = redisService.get("Loginqiurunze11");
+ model.addAttribute("userinfo", userinfoService.get(info.getId()));
+// model.addAttribute("account", accountService.get(info.getId()));
+ return "personal";
+ }
+}
diff --git a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/AddGlobalUtilInterceptor.java b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/AddGlobalUtilInterceptor.java
new file mode 100644
index 0000000..1738e25
--- /dev/null
+++ b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/AddGlobalUtilInterceptor.java
@@ -0,0 +1,27 @@
+package com.geekq.web.interceptor;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class AddGlobalUtilInterceptor extends HandlerInterceptorAdapter {
+
+/* @Autowired
+ private SystemDictionaryUtil systemDicUtil;*/
+
+ @Override
+ public void postHandle(HttpServletRequest request,
+ HttpServletResponse response, Object handler,
+ ModelAndView modelAndView) throws Exception {
+ if (modelAndView != null) {
+/*
+ modelAndView.addObject("_DicUtil", systemDicUtil);
+*/
+ }
+ super.postHandle(request, response, handler, modelAndView);
+ }
+
+}
diff --git a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/LoginInterceptor.java b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/LoginInterceptor.java
index e540dd9..ba22d18 100644
--- a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/LoginInterceptor.java
+++ b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/interceptor/LoginInterceptor.java
@@ -1,23 +1,32 @@
package com.geekq.web.interceptor;
-import com.geekq.web.utils.UserContext;
+import com.geekq.admin.entity.Logininfo;
+import com.geekq.admin.service.RedisCacheStorageService;
+import com.geekq.admin.utils.UserContext;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginInterceptor extends HandlerInterceptorAdapter {
+ @Autowired
+ private RedisCacheStorageService redisService;
+
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod hm = (HandlerMethod) handler;
RequiredLogin rl = hm.getMethodAnnotation(RequiredLogin.class);
- if (rl != null) {
- if (request.getSession().getAttribute(
- UserContext.LOGIN_IN_SESSION) == null) {
+ System.out.println(request.getParameter("username"));
+ String username =request.getParameter("username");
+ if (rl != null) {
+ Logininfo current = redisService.get("Login"+username);
+ if (current == null) {
response.sendRedirect("/login.html");
return false;
}
diff --git a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/utils/UserContext.java b/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/utils/UserContext.java
deleted file mode 100644
index 3e3f167..0000000
--- a/miaosha-admin/miaosha-admin-web/src/main/java/com/geekq/web/utils/UserContext.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.geekq.web.utils;
-
-
-import com.geekq.admin.entity.Logininfo;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.servlet.http.HttpServletRequest;
-
-public class UserContext {
-
- public static final String LOGIN_IN_SESSION = "logininfo";
- public static final String VERIFYCODE_IN_SESSION = "VERIFYCODE_IN_SESSION";
-
- private static HttpServletRequest getRequest() {
- return ((ServletRequestAttributes) RequestContextHolder
- .getRequestAttributes()).getRequest();
- }
-
- public static void putLogininfo(Logininfo logininfo) {
- getRequest().getSession().setAttribute(LOGIN_IN_SESSION, logininfo);
- }
-
- public static Logininfo getCurrent() {
- return (Logininfo) getRequest().getSession().getAttribute(
- LOGIN_IN_SESSION);
- }
-
-// public static void putVerifyCode(VerifyCode code) {
-// getRequest().getSession().setAttribute(VERIFYCODE_IN_SESSION, code);
-// }
-//
-// public static VerifyCode getVerifyCode() {
-// return (VerifyCode) getRequest().getSession().getAttribute(
-// VERIFYCODE_IN_SESSION);
-// }
-}
diff --git a/miaosha-admin/miaosha-admin-web/src/main/resources/spring/applicationContext-dubbo-consumer.xml b/miaosha-admin/miaosha-admin-web/src/main/resources/spring/applicationContext-dubbo-consumer.xml
index 26f9ff3..75f7a8b 100644
--- a/miaosha-admin/miaosha-admin-web/src/main/resources/spring/applicationContext-dubbo-consumer.xml
+++ b/miaosha-admin/miaosha-admin-web/src/main/resources/spring/applicationContext-dubbo-consumer.xml
@@ -9,7 +9,7 @@
-
+
@@ -19,4 +19,13 @@
+
+
+
+
+
+
diff --git a/miaosha-admin/miaosha-admin-web/src/main/webapp/login.html b/miaosha-admin/miaosha-admin-web/src/main/webapp/login.html
index 3f4b9d1..b23c47b 100644
--- a/miaosha-admin/miaosha-admin-web/src/main/webapp/login.html
+++ b/miaosha-admin/miaosha-admin-web/src/main/webapp/login.html
@@ -42,12 +42,13 @@
//验证成功后,提交操作;
submitHandler:function(form){
$(form).ajaxSubmit(function(data){
- if(data.status='success'){
+ if(data.status == "SUCCESS"){
+ var username = data.data.nickname;
$.messager.confirm("提示","登陆成功,点击确定跳转到个人中心",function(){
- window.location.href="/personal.do";
+ window.location.href="/personal.do?username="+username;
});
}else{
- $.messager.alert("提示",data.msg);
+ $.messager.alert("提示","登录失败!");
}
});
},
diff --git a/miaosha-admin/miaosha-admin-web/src/main/webapp/register.html b/miaosha-admin/miaosha-admin-web/src/main/webapp/register.html
index fc41ee8..e88ccad 100644
--- a/miaosha-admin/miaosha-admin-web/src/main/webapp/register.html
+++ b/miaosha-admin/miaosha-admin-web/src/main/webapp/register.html
@@ -85,7 +85,7 @@
},
submitHandler:function(form){
$(form).ajaxSubmit(function(data){
- if(data.data){
+ if(data.success){
$.messager.confirm("提示","注册成功,请重新登录系统!",function(){
window.location.href="/login.html";
});
diff --git a/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/MD5/MD5Utils.java b/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/MD5/MD5Utils.java
index 8b1ca00..cd559cb 100644
--- a/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/MD5/MD5Utils.java
+++ b/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/MD5/MD5Utils.java
@@ -61,5 +61,4 @@ public class MD5Utils {
return MD5(str);
}
-
}
diff --git a/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/resultbean/AbstractResult.java b/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/resultbean/AbstractResult.java
index 16495c2..615e101 100644
--- a/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/resultbean/AbstractResult.java
+++ b/miaosha-admin/miaosha-common/src/main/java/com/geekq/common/utils/resultbean/AbstractResult.java
@@ -37,6 +37,7 @@ public class AbstractResult {
}
public AbstractResult withError(int code, String message) {
+ this.status = ResultStatus.SYSTEM_ERROR;
this.code = code;
this.message = message;
return this;
diff --git a/springboot-dubbo/consumer/src/main/resources/tcc-transaction-dubbo.xml b/springboot-dubbo/consumer/src/main/resources/tcc-transaction-dubbo.xml
index 225a8c6..067dcc6 100644
--- a/springboot-dubbo/consumer/src/main/resources/tcc-transaction-dubbo.xml
+++ b/springboot-dubbo/consumer/src/main/resources/tcc-transaction-dubbo.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/springboot-dubbo/privoder/src/main/resources/application.properties b/springboot-dubbo/privoder/src/main/resources/application.properties
index 0d2d5ac..87ae8d2 100644
--- a/springboot-dubbo/privoder/src/main/resources/application.properties
+++ b/springboot-dubbo/privoder/src/main/resources/application.properties
@@ -1,3 +1,3 @@
spring.application.name=dubbo-spring-boot-starter
spring.dubbo.server=true
-spring.dubbo.registry=zookeeper://localhost:2181
\ No newline at end of file
+spring.dubbo.registry=zookeeper://39.107.245.253:2181
\ No newline at end of file