Commit fe4b325f by zhangxiaoyan

conflict

parents 0add82f8 5a47a71c
......@@ -66,7 +66,18 @@
<mail.valid_time>3</mail.valid_time>
<report.url>http://ec2-54-222-233-230.cn-north-1.compute.amazonaws.com.cn:9010</report.url>
<!--Redis setting-->
<redis.key.validtime>120</redis.key.validtime>
<redis.ip.requesttimes>5</redis.ip.requesttimes>
<redis.ip.unknown.requesttimes>5</redis.ip.unknown.requesttimes>
<redis.surl.host>192.168.2.57</redis.surl.host>
<redis.surl.port>6379</redis.surl.port>
<redis.event.host>192.168.2.57</redis.event.host>
<redis.event.port>6379</redis.event.port>
<redis.event.database>0</redis.event.database>
<!--Redis setting//end-->
</properties>
</profile>
......
package common.controller;
import common.model.Menu;
import com.sun.corba.se.spi.ior.ObjectKey;
import common.model.User;
import common.repository.MenuRepository;
import common.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import util.CipherUtil;
import util.ResultModel;
import security.RedisLoginStatusManager;
import security.TokenManager;
import security.annotation.CurrentAccount;
import security.interceptor.AuthorizationInterceptor;
import util.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
@Controller
......@@ -25,19 +33,35 @@ public class LoginController {
@Autowired
private UserRepository userRepository;
@Autowired
RedisLoginStatusManager redisLoginStatusManager;
@Autowired
TokenManager tokenManager;
@RequestMapping(value = "login", method = RequestMethod.GET)
@ResponseBody
public ResultModel login(HttpServletResponse response, @RequestParam String email, @RequestParam String password) {
User user = userRepository.login(email, CipherUtil.generatePassword(password));
if(null != user){
Cookie cookie = new Cookie("TOKEN", user.getId().toString());
//存储token
String token = tokenManager.createToken(String.valueOf(user.getId()));
//存储登陆密码
redisLoginStatusManager.createLoginStatus(token, user.getPassword());
Cookie cookie = new Cookie("TOKEN", token);
cookie.setPath("/");
cookie.setMaxAge(60 * 60 * 24 * 7);
response.addCookie(cookie);
return ResultModel.OK(true);
Map<String, Object> map = new HashMap();
map.put("TOKEN", token);
map.put("user", user);
map.put("code",200);
return ResultModel.OK(map);
}
return ResultModel.OK(false);
Map<String, Object> map = new HashMap();;
map.put("code",300);
return ResultModel.OK(map);
}
@RequestMapping(value = "login/check", method = RequestMethod.GET)
@ResponseBody
......@@ -48,6 +72,32 @@ public class LoginController {
}
return ResultModel.OK(false);
}
@RequestMapping(value = "logout", method = RequestMethod.GET)
@ResponseBody
public ResultModel logout(HttpServletRequest request, HttpServletResponse response, @CurrentAccount User user ) {
if (user != null) {
String token = request.getHeader("Authorization");
if(!ValidateUtil.isValid(token)){
Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("TOKEN")) {
token = cookie.getValue();
}
}
}
}
//删除session,token
request.getSession().removeAttribute(Constant.CURRENT_ACCOUNT);
tokenManager.delRelationshipByToken(token);
redisLoginStatusManager.deleteLoginStatus(token);
Cookie cookie = new Cookie("TOKEN", null);
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
}
return ResultModel.OK(true);
}
}
......@@ -19,7 +19,7 @@ public class Account4Web {
private Integer backTime;
private String user;
private String tell;
private Integer money;
private Long money;
private Boolean ioStatus;
private Boolean trackStatus;
......@@ -121,11 +121,11 @@ public class Account4Web {
this.tell = tell;
}
public Integer getMoney() {
public Long getMoney() {
return money;
}
public void setMoney(Integer money) {
public void setMoney(Long money) {
this.money = money;
}
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
/**
* Created by mxq on 2017/12/26.
*/
@Entity
public class BackVisit {
private Long id;
private Long accountId;
private String email;
private String platform;
private Long visitTime;
private String visitDesc;
private Long user;
private Date visitDate;
private String ds;
private String userName;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getAccountId() {
return accountId;
}
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public Long getVisitTime() {
return visitTime;
}
public void setVisitTime(Long visitTime) {
this.visitTime = visitTime;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public Date getVisitDate() {
return visitDate;
}
public void setVisitDate(Date visitDate) {
this.visitDate = visitDate;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getVisitDesc() {
return visitDesc;
}
public void setVisitDesc(String visitDesc) {
this.visitDesc = visitDesc;
}
@Override
public String toString() {
return "BackVisit{" +
"id=" + id +
", accountId=" + accountId +
", email='" + email + '\'' +
", platform='" + platform + '\'' +
", visitTime=" + visitTime +
", user=" + user +
", visitDate=" + visitDate +
'}';
}
}
package common.model;
/**
* Created by mxq on 2017/12/26.
*/
public class KeyValue {
private String email;
private Integer timenum;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getTimenum() {
return timenum;
}
public void setTimenum(Integer timenum) {
this.timenum = timenum;
}
public KeyValue(String email, Integer timenum) {
this.email = email;
this.timenum = timenum;
}
public KeyValue() {
}
@Override
public String toString() {
return "KeyValue{" +
"email='" + email + '\'' +
", timenum=" + timenum +
'}';
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
/**
* Created by mxq on 2017/12/26.
*/
@Entity
public class Payment {
private Long id;
private Long accountId;
private String email;
private String platform;
private String type;
private Long money;
private Long user;
private Date payDate;
private String ds;
private String userName;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getAccountId() {
return accountId;
}
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getMoney() {
return money;
}
public void setMoney(Long money) {
this.money = money;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public Date getPayDate() {
return payDate;
}
public void setPayDate(Date payDate) {
this.payDate = payDate;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
/**
* Created by mxq on 2017/12/26.
*/
@Entity
public class Reminder {
private Long id;
private Long accountId;
private String email;
private String platform;
private Boolean remindStatus;
private Long user;
private String userName;
private Date modifyTime;
private String ds;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getAccountId() {
return accountId;
}
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public Boolean getRemindStatus() {
return remindStatus;
}
public void setRemindStatus(Boolean remindStatus) {
this.remindStatus = remindStatus;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
......@@ -3,9 +3,16 @@ package common.repository;
import common.model.Account4Web;
import common.model.Auth;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Account;
import java.util.List;
@Transactional
public interface Account4WebRepository extends JpaRepository<Account4Web, Long> {
@Query(value = "SELECT * from account4web where email in ?1", nativeQuery = true)
List<Account4Web> findByEmails(List<String> emails);
}
package common.repository;
import common.model.Auth;
import common.model.BackVisit;
import common.model.KeyValue;
import common.model.Reminder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Account;
import java.util.List;
@Transactional
public interface BackVisitRepository extends JpaRepository<BackVisit, Long> {
@Query(value = "SELECT * from back_visit", nativeQuery = true)
List<BackVisit> findAllCount();
@Query(value = "select * from back_visit where account_id = ?1 and ds > ?2 and ds < ?3 and platform = ?4", nativeQuery = true)
List<BackVisit> findAll(Long accountId, String startDate, String endDate, String platform);
}
package common.repository;
import common.model.Auth;
import common.model.BackVisit;
import common.model.Payment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public interface PaymentRepository extends JpaRepository<Payment, Long> {
@Query(value = "select * from payment where account_id = ?1 and ds > ?2 and ds < ?3 and platform = ?4", nativeQuery = true)
List<Payment> findAll(Long accountId, String startDate, String endDate, String platform);
}
package common.repository;
import common.model.Auth;
import common.model.Reminder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface ReminderRepository extends JpaRepository<Reminder, Long> {
@Query(value = "select * from reminder where account_id = ?1 and ds > ?2 and ds < ?3 and platform = ?4", nativeQuery = true)
List<Reminder> findAll(Long accountId, String startDate, String endDate, String platform);
}
package security;
import security.exception.MethodNotSupportException;
import java.util.UUID;
public abstract class AbstractTokenManager implements TokenManager {
protected int tokenExpireSeconds = 7 * 24 * 3600;
protected boolean singleTokenWithUser = false;
protected boolean flushExpireAfterOperation = true;
public void setTokenExpireSeconds(int tokenExpireSeconds) {
this.tokenExpireSeconds = tokenExpireSeconds;
}
public void setSingleTokenWithUser(boolean singleTokenWithUser) {
this.singleTokenWithUser = singleTokenWithUser;
}
public void setFlushExpireAfterOperation(boolean flushExpireAfterOperation) {
this.flushExpireAfterOperation = flushExpireAfterOperation;
}
@Override
public void delRelationshipByKey(String key) {
//如果是多个Token关联同一个Key,不允许直接通过Key删除所有Token,防止误操作
if (!singleTokenWithUser) {
throw new MethodNotSupportException("非单点登录时无法调用该方法");
}
delSingleRelationshipByKey(key);
}
/**
* 一个用户只能绑定一个Token时通过Key删除关联关系
* @param key
*/
protected abstract void delSingleRelationshipByKey(String key);
private void createRelationship(String key, String token) {
//根据设置的每个用户是否只允许绑定一个Token,调用不同的方法
if (singleTokenWithUser) {
createSingleRelationship(key, token);
} else {
createMultipleRelationship(key, token);
}
}
/**
* 一个用户可以绑定多个Token时创建关联关系
* @param key
* @param token
*/
protected abstract void createMultipleRelationship(String key, String token);
/**
* 一个用户只能绑定一个Token时创建关联关系
* @param key
* @param token
*/
protected abstract void createSingleRelationship(String key, String token);
@Override
public String getKeyFromToken(String token) {
String key = getKeyByToken(token);
//根据设置,在每次有效操作后刷新过期时间
if (key != null && flushExpireAfterOperation) {
flushExpireAfterOperation(key, token);
}
return key;
}
@Override
public String getTokenFromKey(String key) {
return getTokenByKey(key);
}
@Override
public String createToken(String key) {
final String token = generateToken();
createRelationship(key, token);
return token;
}
protected String generateToken(){
return UUID.randomUUID().toString();
}
/**
* 通过Token获得Key
* @param token
* @return
*/
protected abstract String getKeyByToken(String token);
/**
* 通过key获取token
* @param key
* @return
*/
protected abstract String getTokenByKey(String key);
/**
* 在操作后刷新Token的过期时间
* @param key
* @param token
*/
protected abstract void flushExpireAfterOperation(String key, String token);
}
\ No newline at end of file
package security;
/**
* Created by sunhao on 17/3/3.
*/
public interface RedisLoginStatusManager {
/**
* 根据token和状态在redis中创建登陆状态
*/
void createLoginStatus(String token, String status);
/**
* 根据token删除登陆状态
*/
void deleteLoginStatus(String token);
/**
* 根据token获取登陆密码
*/
String getLoginPassword(String token);
/**
* 根据token获取登陆状态
*/
boolean getLoginStatusByKey(String token);
}
package security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import util.StringUtil;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
* Created by sunhao on 17/3/3.
*/
@Service
public class RedisLoginStatusManagerImpl implements RedisLoginStatusManager {
protected int tokenExpireSeconds = 7 * 24 * 3600;
@Autowired
private RedisTemplate redisTemplate;
/**
* Redis中记录login密码的Token的前缀
*/
private static final String REDIS_LOGIN_PREFIX = "LOGIN_STATUS_TOKEN_";
@Override
public void createLoginStatus(String token, String pwd) {
String formatToken = formatKey(token);
String loginStatus = getLoginPassword(formatToken);
if(!StringUtil.isEmpty(loginStatus)) {
delete(formatToken);
}
set(formatToken,pwd,tokenExpireSeconds);
}
@Override
public void deleteLoginStatus(String token) {
delete(formatKey(token));
}
@Override
public boolean getLoginStatusByKey(String token) {
String pwd = getLoginPassword(token);
return !StringUtil.isEmpty(pwd);
}
@Override
public String getLoginPassword(String token) {
String pwd = get(formatKey(token));
//每次取的时候重置失效时间
if(!StringUtil.isEmpty(pwd)) {
expire(formatKey(token), tokenExpireSeconds);
}
return pwd;
}
private String formatKey(String token) {
return REDIS_LOGIN_PREFIX.concat(token);
}
/**
* 取redis
*/
private String get(String key) {
return (String) redisTemplate.opsForValue().get(key);
}
/**
* 存redis
*/
private String set(String key, String value, int expireSeconds) {
redisTemplate.opsForValue().set(key, value);
redisTemplate.expire(key, expireSeconds, TimeUnit.SECONDS);
return value;
}
/**
* 设置过期时间
*/
private void expire(String key, int seconds) {
redisTemplate.expire(key, seconds, TimeUnit.SECONDS);
}
/**
* 删除redis记录
*/
private void delete(String... keys) {
redisTemplate.delete(Arrays.asList(keys));
}
}
package security;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Created by nolan on 11/11/2016.
* description:
*/
@Service
public class RedisTokenManager extends AbstractTokenManager {
private final String GLOBAL_TOKEN = "GLOBAL_TOKEN";
/**
* Redis中Key的前缀
*/
private static final String REDIS_KEY_PREFIX = "MANAGER_AUTHORIZATION_KEY_";
/**
* Redis中Token的前缀
*/
private static final String REDIS_TOKEN_PREFIX = "MANAGER_AUTHORIZATION_TOKEN_";
/**
* Redis中账户的前缀
*/
private static final String REDIS_ACCOUNT_PREFIX = "MANAGER_AUTHORIZATION_ACCOUNT_";
@Autowired
private RedisTemplate<String, String> redisTemplate;
/**
* 踢出此账号下的所有登陆
*/
@Override
public void delMultiRelationshipByKey(String key) {
if(Strings.isNullOrEmpty(key))
return;
//获取所有登陆TOKEN
Set<String> tokenSet = this.smembers(formatAccountKey(key));
if(!CollectionUtils.isEmpty(tokenSet)){
//删除这些TOKEN
delete(tokenSet);
//删除对应关系
delete(formatAccountKey(key));
}
}
@Override
protected void delSingleRelationshipByKey(String key) {
String token = getToken(key);
if (token != null) {
delete(formatKey(key), formatToken(token));
}
}
/**
* 根据token删掉关系
* @param token
*/
@Override
public void delRelationshipByToken(String token) {
final String formatToken = formatToken(token);
if (singleTokenWithUser) {
String key = getKeyFromToken(token);
delete(formatKey(key), formatToken);
} else {
//删除对应关系中的token
srem(formatAccountKey(get(formatToken)),formatToken);
//删除token
delete(formatToken);
}
}
/**
* 创建单点登陆的登陆关系
* @param key
* @param token
*/
@Override
protected void createSingleRelationship(String key, String token) {
String oldToken = get(formatKey(key));
if (oldToken != null) {
delete(formatToken(oldToken));
}
set(formatToken(token), key, tokenExpireSeconds);
set(formatKey(key), token, tokenExpireSeconds);
}
/**
* 创建多点登陆的登陆关系
* @param key
* @param token
*/
@Override
protected void createMultipleRelationship(String key, String token) {
set(formatToken(token), key, tokenExpireSeconds);
//添加到账户KEY对应的SET中
sadd(formatAccountKey(key), formatToken(token), tokenExpireSeconds);
}
@Override
protected String getKeyByToken(String token) {
return get(formatToken(token));
}
@Override
protected String getTokenByKey(String key) {
return get(formatKey(key));
}
/**
* 操作后刷新登陆关系时长
* @param key
* @param token
*/
@Override
protected void flushExpireAfterOperation(String key, String token) {
if (singleTokenWithUser) {
expire(formatKey(key), tokenExpireSeconds);
}
expire(formatToken(token), tokenExpireSeconds);
//刷新对应关系时长
expire(formatAccountKey(get(formatToken(token))), tokenExpireSeconds);
}
private String get(String key) {
return redisTemplate.opsForValue().get(key);
}
private String set(String key, String value, int expireSeconds) {
redisTemplate.opsForValue().set(key, value);
redisTemplate.expire(key, expireSeconds, TimeUnit.SECONDS);
return value;
}
/**
* 添加value 对于的KEY set
*/
private Long sadd(String key, String value, int expireSeconds){
Long num = redisTemplate.opsForSet().add(key, value);
if(0 != num){
redisTemplate.expire(key, expireSeconds, TimeUnit.SECONDS);
}
return num;
}
/**
* 删除set中的某个
*/
private Long srem(String key, String value){
return redisTemplate.opsForSet().remove(key,value);
}
/**
* 获取set中所有元素
*/
private Set<String> smembers(String key){
return redisTemplate.opsForSet().members(key);
}
private void expire(String key, int seconds) {
redisTemplate.expire(key, seconds, TimeUnit.SECONDS);
}
private void delete(String... keys) {
redisTemplate.delete(Arrays.asList(keys));
}
private void delete(Collection<String> collection){
redisTemplate.delete(collection);
}
private String getToken(String key) {
return get(formatKey(key));
}
private String formatKey(String key) {
return REDIS_KEY_PREFIX.concat(key);
}
private String formatToken(String token) {
return REDIS_TOKEN_PREFIX.concat(token);
}
private String formatAccountKey(String key){
return REDIS_ACCOUNT_PREFIX.concat(key);
}
}
package security;
/**
* Created by nolan on 11/11/2016.
* description:
*/
public interface TokenManager {
void delMultiRelationshipByKey(String key);
/**
* 通过key删除关联关系
*
* @param key
*/
void delRelationshipByKey(String key);
/**
* 通过token删除关联关系
*
* @param token
*/
void delRelationshipByToken(String token);
/**
* 通过token获得对应的key
*
* @param token
* @return
*/
String getKeyFromToken(String token);
/**
* 通过key获得对应token
* @param key
* @return
*/
String getTokenFromKey(String key);
/**
* 根据key生成对应token
* @param key
* @return
*/
String createToken(String key);
}
package security.cors;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by sunhao on 17/3/13.
* dec: 设置跨域
*/
public class CorsFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
httpServletResponse.addHeader("Access-Control-Allow-Origin", "*");
if (httpServletRequest.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(httpServletRequest.getMethod())) {
httpServletResponse.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
httpServletResponse.addHeader("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
httpServletResponse.addHeader("Access-Control-Max-Age", "3600");
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}
package security.exception;
public class MethodNotSupportException extends RuntimeException {
public MethodNotSupportException(String message) {
super(message);
}
}
\ No newline at end of file
......@@ -6,6 +6,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import security.RedisLoginStatusManager;
import security.TokenManager;
import util.Constant;
import util.StringUtil;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
......@@ -18,21 +22,42 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
@Autowired
private UserRepository userRepository;
@Autowired
private TokenManager manager;
@Autowired
private RedisLoginStatusManager redisLoginStatusManager;
//鉴权信息的无用前缀,默认为空
private String httpHeaderPrefix = "";
public void setHttpHeaderName(String httpHeaderName) {
this.httpHeaderName = httpHeaderName;
}
public void setHttpHeaderPrefix(String httpHeaderPrefix) {
this.httpHeaderPrefix = httpHeaderPrefix;
}
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//放开登录
/*if (request.getRequestURL().indexOf("login/login") != -1){
return true;
}
//从header中得到token
String token = request.getHeader(httpHeaderName);
System.out.println(token);
String id = getCookieToken(request.getCookies(), "TOKEN");
if(null != id){
User account = userRepository.findOne(Long.parseLong(id));
User sessionAct = (User) request.getSession().getAttribute("$CURRENT_ACCOUNT$");
if (sessionAct == null || !account.getId().equals(sessionAct.getId())) {
request.getSession().setAttribute("$CURRENT_ACCOUNT$", account);
token = StringUtil.isEmpty(token) ? getCookieToken(request.getCookies(), "TOKEN") : token;
token = token.substring(httpHeaderPrefix.length());
//验证token
String key = manager.getKeyFromToken(token);
//登陆状态
boolean loginStatus = redisLoginStatusManager.getLoginStatusByKey(token);
if (!StringUtil.isEmpty(key)) {
String id = getCookieToken(request.getCookies(), "TOKEN");
User one = userRepository.findOne(Long.parseLong(key));
User sessionAct = (User) request.getSession().getAttribute(Constant.CURRENT_ACCOUNT);
if (sessionAct == null) {
request.getSession().setAttribute(Constant.CURRENT_ACCOUNT,one);
}
return true;
}
......
package tkio.controller;
import common.model.BackVisit;
import common.model.Payment;
import common.model.Reminder;
import common.model.User;
import common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import security.annotation.CurrentAccount;
import tkio.service.TkioAccountService;
import util.ResultModel;
/**
* Created by mxq on 2017/12/21.
*/
@Controller
@RequestMapping("marketing/accountmng/tkio")
public class TkioAccountController {
@Autowired
TkioAccountService tkioAccountService;
//客户列表
@RequestMapping(value = "/findAll", method = RequestMethod.GET)
@ResponseBody
public ResultModel find(@CurrentAccount User loginAccount) {
return ResultModel.OK(tkioAccountService.findAll(loginAccount));
}
//关闭到期提醒
@RequestMapping(value = "/forbiden", method = RequestMethod.PUT)
@ResponseBody
public ResultModel forbiden(@CurrentAccount User loginAccount, @RequestBody Reminder resource) {
return ResultModel.OK(tkioAccountService.forbiden(loginAccount, resource));
}
//开启到期提醒
@RequestMapping(value = "/enable", method = RequestMethod.PUT)
@ResponseBody
public ResultModel enable(@CurrentAccount User loginAccount, @RequestBody Reminder resource) {
return ResultModel.OK(tkioAccountService.enable(loginAccount, resource));
}
//缴费
@RequestMapping(value = "/pay", method = RequestMethod.PUT)
@ResponseBody
public ResultModel pay(@CurrentAccount User loginAccount, @RequestBody Payment resource) {
return ResultModel.OK(tkioAccountService.pay(loginAccount, resource));
}
//回访
@RequestMapping(value = "/visit", method = RequestMethod.PUT)
@ResponseBody
public ResultModel visit(@CurrentAccount User loginAccount, @RequestBody BackVisit resource) {
return ResultModel.OK( tkioAccountService.visit(loginAccount, resource));
}
//功能使用查询
@RequestMapping(value = "/find/function/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel updateName(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK(tkioAccountService.findFunTimes(accountId,startDate,endDate));
}
//功能使用查询
@RequestMapping(value = "/find/pv/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel pv(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK(tkioAccountService.findPv(accountId,startDate,endDate));
}
//到期提醒查询
@RequestMapping(value = "/find/reminder/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel findRed(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK(tkioAccountService.findRed(accountId,startDate,endDate));
}
//回访查询
@RequestMapping(value = "/find/visit/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel findVisit(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK(tkioAccountService.findVisit(accountId,startDate,endDate));
}
//缴费查询
@RequestMapping(value = "/find/pay/{accountId}", method = RequestMethod.GET)
@ResponseBody
public ResultModel findPay(@CurrentAccount User loginAccount, @RequestParam String startDate,
@RequestParam String endDate, @PathVariable Long accountId) {
return ResultModel.OK(tkioAccountService.findPay(accountId,startDate,endDate));
}
}
package tkio.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
@Entity
public class Campaign
{
private Long id;
private Long app;
private String os;
private String type;
private Long channel;
private String channelCategory;
private String channelType;
private String campaignid;
private String name;
private String callback;
private String url;
private String surl;
private Integer addParam;
private String campaignpackid;
private String specialKeys;
private String advertiserid;
private String bundleid;
private Boolean awssuccess = false;
private Date createTime;
private Long createAccount;
private Date modifyTime;
private Long modifyAccount;
private Boolean delFlag = false;
private Long account;
private String holderids;
private String pack_channelid;
private int batchNumber;
private int startNumber;
private String campaignName;
@Transient
public int getStartNumber() {
return startNumber;
}
public void setStartNumber(int startNumber) {
this.startNumber = startNumber;
}
@Transient
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
@Transient
public int getBatchNumber()
{
return batchNumber;
}
public void setBatchNumber(int batchNumber)
{
this.batchNumber = batchNumber;
}
@Transient
public String getHolderids()
{
return holderids;
}
public void setHolderids(String holderids)
{
this.holderids = holderids;
}
public Long getAccount()
{
return account;
}
public void setAccount(Long account)
{
this.account = account;
}
public Campaign()
{
super();
}
public Campaign(String campaignid, String name)
{
this.campaignid = campaignid;
this.name = name;
}
public Long getApp()
{
return app;
}
public String getCallback()
{
return callback;
}
/* public Long getCampaignGroup() {
return campaignGroup;
}*/
public Long getChannel()
{
return channel;
}
@Id
@GeneratedValue
public Long getId()
{
return id;
}
public String getName()
{
return name;
}
public String getSurl()
{
return surl;
}
public String getType()
{
return type;
}
public String getUrl()
{
return url;
}
public void setApp(Long app)
{
this.app = app;
}
public void setCallback(String callback)
{
this.callback = callback;
}
/* public void setCampaignGroup(Long campaignGroup) {
this.campaignGroup = campaignGroup;
}*/
public void setChannel(Long channel)
{
this.channel = channel;
}
public String getChannelCategory()
{
return channelCategory;
}
public void setChannelCategory(String channelCategory)
{
this.channelCategory = channelCategory;
}
public String getChannelType()
{
return channelType;
}
public void setChannelType(String channelType)
{
this.channelType = channelType;
}
public void setId(Long id)
{
this.id = id;
}
public void setName(String name)
{
this.name = name;
}
public void setSurl(String surl)
{
this.surl = surl;
}
public void setType(String type)
{
this.type = type;
}
public void setUrl(String url)
{
this.url = url;
}
public String getSpecialKeys()
{
return specialKeys;
}
public void setSpecialKeys(String specialKeys)
{
this.specialKeys = specialKeys;
}
public Integer getAddParam()
{
return addParam;
}
public void setAddParam(Integer addParam)
{
this.addParam = addParam;
}
public String getOs()
{
return os;
}
public void setOs(String os)
{
this.os = os;
}
public boolean isAwssuccess()
{
return awssuccess;
}
public void setAwssuccess(boolean awssuccess)
{
this.awssuccess = awssuccess;
}
public String getCampaignpackid()
{
return campaignpackid;
}
public void setCampaignpackid(String campaignpackid)
{
this.campaignpackid = campaignpackid;
}
public String getAdvertiserid()
{
return advertiserid;
}
public void setAdvertiserid(String advertiserid)
{
this.advertiserid = advertiserid;
}
public String getBundleid()
{
return bundleid;
}
public void setBundleid(String bundleid)
{
this.bundleid = bundleid;
}
public Date getCreateTime()
{
return createTime;
}
public void setCreateTime(Date createTime)
{
this.createTime = createTime;
}
public Date getModifyTime()
{
return modifyTime;
}
public void setModifyTime(Date modifyTime)
{
this.modifyTime = modifyTime;
}
public Boolean getDelFlag()
{
return delFlag;
}
public void setDelFlag(Boolean delFlag)
{
this.delFlag = delFlag;
}
public String getCampaignid()
{
return campaignid;
}
public void setCampaignid(String campaignid)
{
this.campaignid = campaignid;
}
public Long getCreateAccount()
{
return createAccount;
}
public void setCreateAccount(Long createAccount)
{
this.createAccount = createAccount;
}
public Long getModifyAccount()
{
return modifyAccount;
}
public void setModifyAccount(Long modifyAccount)
{
this.modifyAccount = modifyAccount;
}
public String getPack_channelid()
{
return pack_channelid;
}
public void setPack_channelid(String pack_channelid)
{
this.pack_channelid = pack_channelid;
}
public Boolean getAwssuccess()
{
return awssuccess;
}
public void setAwssuccess(Boolean awssuccess)
{
this.awssuccess = awssuccess;
}
@Override
public String toString()
{
return "Campaign{" +
"id=" + id +
", app=" + app +
", os='" + os + '\'' +
", type='" + type + '\'' +
", channel=" + channel +
", channelCategory='" + channelCategory + '\'' +
", channelType='" + channelType + '\'' +
", campaignid='" + campaignid + '\'' +
", name='" + name + '\'' +
", callback='" + callback + '\'' +
", url='" + url + '\'' +
", surl='" + surl + '\'' +
", addParam=" + addParam +
", campaignpackid='" + campaignpackid + '\'' +
", specialKeys='" + specialKeys + '\'' +
", advertiserid='" + advertiserid + '\'' +
", bundleid='" + bundleid + '\'' +
", awssuccess=" + awssuccess +
", createTime=" + createTime +
", createAccount=" + createAccount +
", modifyTime=" + modifyTime +
", modifyAccount=" + modifyAccount +
", delFlag=" + delFlag +
", account=" + account +
", holderids='" + holderids + '\'' +
", pack_channelid='" + pack_channelid + '\'' +
", batchNumber=" + batchNumber +
'}';
}
}
package tkio.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public class Channel {
private Long id;
private String name;
private String category;
private Long account;
private String url;
private String type;
private String uniqueName;
private String firstchar;
private boolean ishttps=false;
private Boolean osAndroid;
private Boolean osIos;
private Boolean osWeb;
private String trackurl;
private String androidparam;
private String iosparam;
private boolean istrackurlspecial=false;
private Date createTime;
private Long createAccount;
private Date modifyTime;
private Long modifyAccount;
private Boolean delFlag;
private String specialParams;
private String nodeUrl;
public String getNodeUrl() {
return nodeUrl;
}
public void setNodeUrl(String nodeUrl) {
this.nodeUrl = nodeUrl;
}
private boolean isintegrate = false;
private Integer iscostrecovery; //0:没对接,1:API,2:爬虫。
private Integer orderindex;
//0 正常渠道 1 被合并渠道,不再显示
private Boolean isNotShow;
//0 正常渠道 1 未覆盖中国,不再显示 例如:Search Ads
private Boolean isNotCover;
public Channel() {
super();
}
public Channel(String name, String category, String url) {
super();
this.name = name;
this.category = category;
this.url = url;
}
public Channel(Long channelId, String name){
super();
this.id = channelId;
this.name = name;
}
public String getCategory() {
return category;
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public void setCategory(String category) {
this.category = category;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setUrl(String url) {
this.url = url;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUniqueName() {
return uniqueName;
}
public void setUniqueName(String uniqueName) {
this.uniqueName = uniqueName;
}
public String getFirstchar() {
return firstchar;
}
public void setFirstchar(String firstchar) {
this.firstchar = firstchar;
}
public boolean isIshttps() {
return ishttps;
}
public void setIshttps(boolean ishttps) {
this.ishttps = ishttps;
}
public Boolean getOsAndroid() {
return osAndroid;
}
public void setOsAndroid(Boolean osAndroid) {
this.osAndroid = osAndroid;
}
public Boolean getOsIos() {
return osIos;
}
public void setOsIos(Boolean osIos) {
this.osIos = osIos;
}
public Boolean getOsWeb() {
return osWeb;
}
public void setOsWeb(Boolean osWeb) {
this.osWeb = osWeb;
}
public String getTrackurl() {
return trackurl;
}
public void setTrackurl(String trackurl) {
this.trackurl = trackurl;
}
public String getAndroidparam() {
return androidparam;
}
public void setAndroidparam(String androidparam) {
this.androidparam = androidparam;
}
public String getIosparam() {
return iosparam;
}
public void setIosparam(String iosparam) {
this.iosparam = iosparam;
}
public boolean isIstrackurlspecial() {
return istrackurlspecial;
}
public void setIstrackurlspecial(boolean istrackurlspecial) {
this.istrackurlspecial = istrackurlspecial;
}
public boolean isIsintegrate() {
return isintegrate;
}
public void setIsintegrate(boolean isintegrate) {
this.isintegrate = isintegrate;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Boolean getDelFlag() {
return delFlag;
}
public void setDelFlag(Boolean delFlag) {
this.delFlag = delFlag;
}
public Long getCreateAccount() {
return createAccount;
}
public void setCreateAccount(Long createAccount) {
this.createAccount = createAccount;
}
public Long getModifyAccount() {
return modifyAccount;
}
public void setModifyAccount(Long modifyAccount) {
this.modifyAccount = modifyAccount;
}
public Long getAccount() {
return account;
}
public void setAccount(Long account) {
this.account = account;
}
public String getSpecialParams() {
return specialParams;
}
public void setSpecialParams(String specialParams) {
this.specialParams = specialParams;
}
public Integer getIscostrecovery() {
return iscostrecovery;
}
public void setIscostrecovery(Integer iscostrecovery) {
this.iscostrecovery = iscostrecovery;
}
public Integer getOrderindex()
{
return orderindex;
}
public void setOrderindex(Integer orderindex)
{
this.orderindex = orderindex;
}
public Boolean getNotShow() {
return isNotShow;
}
public void setNotShow(Boolean notShow) {
isNotShow = notShow;
}
public Boolean getNotCover() {
return isNotCover;
}
public void setNotCover(Boolean notCover) {
isNotCover = notCover;
}
}
......@@ -22,4 +22,12 @@ public interface AccountRepository extends JpaRepository<Account, Long> {
@Query(value = "SELECT * from account where is_super_user is true and `status` = 1 and past_date < ?1", nativeQuery = true)
List<Account> findRootParentsPast(String today);
@Query(value = "SELECT * from account where is_super_user is true and bussinessman = ?1", nativeQuery = true)
List<Account> findBussnissMan(List<Integer> bussinussIds);
@Query(value = "select * from account where root_parent = ?1", nativeQuery = true)
List<Account> findByRootParent(Long accountId);
@Query(value = "select count(*) from account where root_parent = ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByRootParent(Long accountId, String startDate, String endDate);
}
......@@ -5,63 +5,17 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import tkio.model.App;
import java.math.BigInteger;
import java.util.List;
public interface AppRepository extends JpaRepository<App, Long> {
@Query(value = "select * from app where account in (select id from account where parent = ?1 or id = ?1) and del_flag is not true", nativeQuery = true)
List<App> listAppByRootAccount(Long account);
@Query(value="select appkey from app where id = ?1",nativeQuery=true)
String findAppkeyById(Long id);
List<App> findByAccount(Long account);
@Query(value = "select * from app where account =?1 and bundleid = ?2 and del_flag is not true", nativeQuery = true)
App findByBundleidInNotDel(Long account, String bundleid);
@Query(value = "select * from app where account =?1 and name = ?2 and del_flag is not true", nativeQuery = true)
App findByNameNotDel(Long account, String name);
@Query(value = "select count(*) from app where account in ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByAccount(List<Long> accountId, String startDate, String endDate);
@Query(value = "select * from app where sync_ddb is false and del_flag is not true", nativeQuery = true)
List<App> findNotSyncAppDebug();
@Query(value = "select * from app where token = ?1 limit 1", nativeQuery = true)
App findOneByAppToken(String token);
@Query(value = "select * from app where id in ?1", nativeQuery = true)
List<App> findByIds(List<Long> ids);
@Query(value = "SELECT DISTINCT t2.* FROM campaign t0 JOIN channel t1 ON t0.channel = t1.id JOIN app t2 ON t0.app = t2.id WHERE t0.del_flag is not true and (t1.type!='ry_coop' or t1.type is NULL) and t1.category = 'ADVERTISING' and t2.id in ?1 and t2.platform = ?2 and t2.del_flag is not TRUE" , nativeQuery = true)
List<App> findAppsFromOnelink(List<Long> appids, String platform);
@Query(value = "SELECT DISTINCT t2.* FROM campaign t0 JOIN channel t1 ON t0.channel = t1.id JOIN app t2 ON t0.app = t2.id WHERE t0.del_flag is not true and (t1.type!='ry_coop' or t1.type is NULL) and t1.category = 'ADVERTISING' and t2.id = ?1" , nativeQuery = true)
App findAppFromOnelink(Long appid);
@Query(value = "select * from app where appkey in ?1", nativeQuery = true)
List<App> findByAppkeys(List<String> appkeys);
@Query(value = "select * from app a join auth b on a.id = b.app where b.account = ?1 and b.create_account in (select id from account where root_parent = ?2) ", nativeQuery = true)
List<App> findAuthAppByRootParent(Long subAccountId, Long rootParent);
@Query(value = "select * from app a join auth b on a.id = b.app where b.account = ?1 ", nativeQuery = true)
List<App> findAuthApp(Long subAccountId);
@Query(value="select platform from app where id = ?1",nativeQuery=true)
String findPlatformByAppId(Long appId);
@Query(value="select categoryname from category where categoryid=(select game_genre from app where id=?1);",nativeQuery=true)
String findGameCategoryByAppID(Long appId);
@Query(value="select categoryname from category where categoryid=(select app_genre from app where id=?1);",nativeQuery=true)
String findAppGenreNameByAppID(Long id);
@Query(value = "select DISTINCT a.* from app a right join data_auth d on a.id = d.app where d.account = ?1 and d.app in ?2 and d.channel = ?3 and (d.all_campaign is true or d.channel_permit is true)", nativeQuery = true)
List<App> listTotalAuthorizedApp(Long accountId, List<Long> appIdList, Long channelId);
@Query(value = "select create_account from app where appkey=?1", nativeQuery = true)
String findCreateAccountByAppkey(String appKey);
@Query(value = "select DISTINCT a.* from app a right join data_auth d on a.id = d.app where d.account = ?1 and d.channel = ?2 and (d.all_campaign is true or d.channel_permit is true)", nativeQuery = true)
List<App> listApps(Long accountId, Long channelId);
@Query(value = "select appkey from app where account in ?1", nativeQuery = true)
List<String> findAppkeys(List<Long> accountId);
}
package tkio.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Campaign;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface CampaignRepository extends JpaRepository<Campaign, Long> {
Iterable<Campaign> findByApp(Long id);
@Query(value = "select count(*) from campaign where account in ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByAccount(List<Long> accountId, String startDate, String endDate);
}
package tkio.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.Channel;
import java.math.BigInteger;
import java.util.List;
@Transactional
public interface ChannelRepository extends JpaRepository<Channel, Long> {
@Query(value = "select count(*) from channel where account in ?1 and create_time > ?2 and create_time < ?3", nativeQuery = true)
BigInteger countByAccount(List<Long> accountId, String startDate, String endDate);
}
......@@ -5,8 +5,16 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import tkio.model.SalesManLeader;
import java.util.List;
@Transactional
public interface SalesManLeaderRepository extends JpaRepository<SalesManLeader, Long> {
@Query(value = "select email from sales_man_leader where id=(select leader from sales_man_leader where id=?1)", nativeQuery = true)
String findLeaderByBussinessMan(Long bussinessMan);
@Query(value = "select * from sales_man_leader where leader = (select id from sales_man_leader where email = ?1)", nativeQuery = true)
List<SalesManLeader> findByEmail(String email);
@Query(value = "select * from sales_man_leader where email = ?1", nativeQuery = true)
SalesManLeader findOneByEmail(String email);
}
package tkio.service;
import common.model.*;
import java.util.List;
import java.util.Map;
/**
* Created by mxq on 2017/12/26.
*/
public interface TkioAccountService {
List<Account4Web> findAll(User user);
//到期提醒关闭
Reminder forbiden(User user, Reminder resource);
//到期提醒开启
Reminder enable(User user, Reminder resource);
//缴费
Payment pay(User user, Payment resource);
//回访
BackVisit visit(User user, BackVisit resource);
//查询功能使用情况
Map<String, Integer> findFunTimes(Long account, String startDate, String endDate);
//查询功能使用情况
List<Map<String, Object>> findPv(Long account, String startDate, String endDate);
List<Reminder> findRed(Long account, String startDate, String endDate);
List<BackVisit> findVisit(Long account, String startDate, String endDate);
List<Payment> findPay(Long account, String startDate, String endDate);
}
......@@ -6,8 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import tkio.model.Account;
import tkio.model.AccountRestrict4Web;
import tkio.model.PackageType;
import tkio.model.SalesManLeader;
import tkio.repository.AccountRepository;
import tkio.repository.PackageTypeRepository;
import tkio.repository.SalesManLeaderRepository;
import tkio.service.AccountFlowRestrictService;
import util.DateUtil;
import util.ValidateUtil;
......@@ -34,7 +36,12 @@ public class AccountTask {
@Autowired
private PackageTypeRepository packageTypeRepository;
@Autowired
SalesManLeaderRepository salesManLeaderRepository;
public void task(){
//清空前一天数据
account4WebRepository.deleteAll();
List<Account4Web> list = new ArrayList<>();
//未过期的查询是否流量到期
List<Account> accountValidList = accountRepository.findRootParentsUnPast(DateUtil.getBeforeDays(1));
......@@ -57,7 +64,8 @@ public class AccountTask {
}
account4Web.setIoStatus(restrict4Web.getAllowBehavior());
account4Web.setTrackStatus(restrict4Web.getTrackFlowNotified());
account4Web.setUser(ac.getBussinessman().toString());
account4Web.setUser(ac.getName());
account4Web.setTell(ac.getPhone());
list.add(account4Web);
}
}
......@@ -81,7 +89,8 @@ public class AccountTask {
account4Web.setTrack("----");
account4Web.setIoStatus(false);
account4Web.setTrackStatus(false);
account4Web.setUser(ac.getBussinessman().toString());
account4Web.setUser(ac.getName());
account4Web.setTell(ac.getPhone());
list.add(account4Web);
}
}
......
......@@ -22,6 +22,12 @@ public class Constant {
public static ResourceBundle commonBundle = ResourceBundle.getBundle("common");
public static String reportUrl = commonBundle.getString("report.url");
public static ResourceBundle redis = ResourceBundle.getBundle("redis");
public static String REDIS_KEY_VALID_TIME = redis.getString("redis.key.validtime");
public static String REDIS_IP_REQUEST_TIMES = redis.getString("redis.ip.requesttimes");
public static String REDIS_IP_UNKNOWN_REQUEST_TIMES = redis.getString("redis.ip.unknown.requesttimes");
......
package util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
/**
* 单节点Jedis.
* @author Administrator
*
*/
public class RedisUtilNew {
protected static Logger logger = LoggerFactory.getLogger(RedisUtilNew.class);
private static RedisUtilNew redisUtil = new RedisUtilNew();
private JedisPool pool;
//
// private ResourceBundle resourceBundle;
private RedisUtilNew() {
ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
pool = new JedisPool(resourceBundle.getString("redis.surl.host"),
Integer.valueOf(resourceBundle.getString("redis.surl.port")));
}
public static RedisUtilNew getInstance() {
return redisUtil;
}
public Map<String, String> hgetAll(String key) {
Map<String, String> result = new HashMap<String, String>();
Jedis jedis = pool.getResource();
result = jedis.hgetAll(key);
pool.returnResource(jedis);
return result;
}
public void hsetAll(String key, Map<String, String> map) {
Jedis jedis = pool.getResource();
jedis.hmset(key, map);
pool.returnResource(jedis);
}
public void delete(String key) {
Jedis jedis = pool.getResource();
jedis.del(key);
pool.returnResource(jedis);
}
/**
* 取值
*
* @param key
* @return
*/
public String get(String key) {
Jedis jedis = pool.getResource();
try {
String result = jedis.get(key);
if (result == null) {
return null;
}
return result;
} finally {
pool.returnResource(jedis);
}
}
/**
* 向redis中写入数据
* @param key
* @param value
*/
public void set(String key,String value)
{
Jedis jedis = pool.getResource();
jedis.set(key,value);
pool.returnResource(jedis);
}
public Long getExpireTime(String key)
{
Jedis jedis = pool.getResource();
Long m = jedis.ttl(key);
pool.returnResource(jedis);
return m;
}
/**
* 加锁.
*
* @param key
* @param expireTime
* 超时时间单位秒.
* @return 锁定的value,返回null值加锁失败,供释放锁时使用.
*/
public String tryLock(String key, int expireTime) {
Jedis jedis = pool.getResource();
try {
String value = Long.toString(System.currentTimeMillis() + (expireTime * 1000));
String result = jedis.set(key, value, "NX", "EX", expireTime);
if (result == null) {
return null;
}
return value;
} finally {
pool.returnResource(jedis);
}
}
public String expireValue(String key, String value, int expireTime)
{
Jedis jedis = pool.getResource();
try {
String result = jedis.set(key, value, "NX", "EX", expireTime);
if (result == null) {
return null;
}
return value;
} finally {
pool.returnResource(jedis);
}
}
public void releaseLock(String key) {
Jedis jedis = pool.getResource();
try {
Set<String> set = jedis.keys(key);
String[] kk = new String[set.size()];
jedis.del(set.toArray(kk));
} catch (Exception e) {
e.printStackTrace();
} finally {
pool.returnResource(jedis);
}
}
public static void main(String[] args) {
RedisUtilNew redisUtilNew = RedisUtilNew.getInstance();
//redisUtilNew.expireValue("test005","12",1000);
Long outtime = redisUtilNew.getExpireTime("test005");
redisUtilNew.delete("test005");
redisUtilNew.expireValue("test005","12",outtime.intValue());
System.out.println(outtime);
}
}
......@@ -14,7 +14,7 @@
<task:scheduled-tasks>
<!--//定时同步短链数据(每5分钟执行一次)-->
<task:scheduled ref="tkioAccountTask" method="task" cron="0 32 19 * * ?"/>
<task:scheduled ref="tkioAccountTask" method="task" cron="0 26 10 * * ?"/>
</task:scheduled-tasks>
<bean id="SyncAppDataTask" class="tkio.task.SyncAppDataTask"></bean>
......
......@@ -22,8 +22,25 @@
<context:component-scan base-package="track" />
<context:component-scan base-package="common" />
<context:component-scan base-package="dmp" />
<context:component-scan base-package="security" />
<context:property-placeholder location="classpath:persistence.properties"/>
<context:property-placeholder location="classpath:redis.properties" />
<!--Redis配置-->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="300" />
<property name="maxTotal" value="600" />
<property name="maxWaitMillis" value="1000"></property>
<property name="testOnBorrow" value="true" />
</bean>
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:hostName="${redis.surl.host}" p:port="${redis.surl.port}" p:poolConfig-ref="poolConfig"/>
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<!--//Redis配置 -->
<bean id="parentDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="driverClassName" value="${dataSource.driverClassName}"/>
......
# Redis common settings
redis.key.validtime=${redis.key.validtime}
redis.ip.requesttimes=${redis.ip.requesttimes}
redis.ip.unknown.requesttimes=${redis.ip.unknown.requesttimes}
redis.maxIdle=300
redis.testOnBorrow=true
# token
redis.surl.host=${redis.surl.host}
redis.surl.port=${redis.surl.port}
# event
redis.event.host=${redis.event.host}
redis.event.port=${redis.event.port}
redis.event.database=${redis.event.database}
......@@ -51,6 +51,15 @@
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<!-- <filter>
<filter-name>cors</filter-name>
<filter-class>security.cors.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cors</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->
<welcome-file-list>
<welcome-file>/home.html</welcome-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