Commit 194c2b0e by wenyang Committed by jianan

0001059:【agms】-增加报表可以导出每个经纪人,每个月,登录了多少次赢家平台,以及每次登录的时长

parent 7b775fea
...@@ -26,16 +26,6 @@ public class AclCustomerSystemLog implements Serializable { ...@@ -26,16 +26,6 @@ public class AclCustomerSystemLog implements Serializable {
private String token; private String token;
/** /**
* 客户使用IP
*/
private String customerIp;
/**
* 客户使用来源
*/
private String customerHostname;
/**
* 监控系统(1: 银盾经纪; 2: 银盾在线; 3: AGMS; 4: Goup) * 监控系统(1: 银盾经纪; 2: 银盾在线; 3: AGMS; 4: Goup)
*/ */
private String fromSystem; private String fromSystem;
...@@ -55,5 +45,7 @@ public class AclCustomerSystemLog implements Serializable { ...@@ -55,5 +45,7 @@ public class AclCustomerSystemLog implements Serializable {
*/ */
private Integer isActive; private Integer isActive;
private Integer expiredMinute;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }
\ No newline at end of file
package com.yd.dal.mapper.customer; package com.yd.dal.mapper.customer;
import java.util.List;
import com.yd.dal.entity.customer.AclCustomerSystemLog; import com.yd.dal.entity.customer.AclCustomerSystemLog;
public interface AclCustomerSystemLogMapper { public interface AclCustomerSystemLogMapper {
...@@ -14,4 +16,9 @@ public interface AclCustomerSystemLogMapper { ...@@ -14,4 +16,9 @@ public interface AclCustomerSystemLogMapper {
int updateByPrimaryKeySelective(AclCustomerSystemLog record); int updateByPrimaryKeySelective(AclCustomerSystemLog record);
int updateByPrimaryKey(AclCustomerSystemLog record); int updateByPrimaryKey(AclCustomerSystemLog record);
List<AclCustomerSystemLog> findCustomerSystemLog(AclCustomerSystemLog aclCustomerSystemLog);
int updateEndTimeByPrimaryKey(Long id);
} }
\ No newline at end of file
...@@ -2,6 +2,8 @@ package com.yd.dal.service.customer; ...@@ -2,6 +2,8 @@ package com.yd.dal.service.customer;
import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO; import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO;
import com.yd.dal.entity.customer.AclCustomerLog; import com.yd.dal.entity.customer.AclCustomerLog;
import com.yd.dal.entity.customer.AclCustomerSystemLog;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
...@@ -27,4 +29,11 @@ public interface AclCustomerLogDALService { ...@@ -27,4 +29,11 @@ public interface AclCustomerLogDALService {
* @date: 2021/11/8 * @date: 2021/11/8
*/ */
Long findLogInfoByMobileNo(String mobileNo); Long findLogInfoByMobileNo(String mobileNo);
List<AclCustomerSystemLog> findCustomerSystemLog(AclCustomerSystemLog aclCustomerSystemLog);
int updateEndTimeByPrimaryKey(Long id);
int saveAclCustomerSystemLog(AclCustomerSystemLog aclCustomerSystemLog);
} }
package com.yd.dal.service.customer.impl; package com.yd.dal.service.customer.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO; import com.yd.api.practitioner.vo.login.PractitionerLoginRequestVO;
import com.yd.dal.entity.customer.AclCustomerLog; import com.yd.dal.entity.customer.AclCustomerLog;
import com.yd.dal.entity.customer.AclCustomerSystemLog;
import com.yd.dal.mapper.customer.AclCustomerLogMapper; import com.yd.dal.mapper.customer.AclCustomerLogMapper;
import com.yd.dal.mapper.customer.AclCustomerSystemLogMapper;
import com.yd.dal.service.customer.AclCustomerLogDALService; import com.yd.dal.service.customer.AclCustomerLogDALService;
import com.yd.util.CommonUtil;
import com.yd.util.SpringContextUtil; import com.yd.util.SpringContextUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service("aclCustomerLogDALService") @Service("aclCustomerLogDALService")
public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService { public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService {
...@@ -19,6 +22,9 @@ public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService { ...@@ -19,6 +22,9 @@ public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService {
@Resource @Resource
private AclCustomerLogMapper aclCustomerLogMapper; private AclCustomerLogMapper aclCustomerLogMapper;
@Resource
private AclCustomerSystemLogMapper aclCustomerSystemLogMapper;
/** /**
* 根据customerId查询指定用户的日志 * 根据customerId查询指定用户的日志
* @param customerId * @param customerId
...@@ -63,4 +69,18 @@ public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService { ...@@ -63,4 +69,18 @@ public class AclCustomerLogDALServiceImpl implements AclCustomerLogDALService {
public Long findLogInfoByMobileNo(String mobileNo) { public Long findLogInfoByMobileNo(String mobileNo) {
return aclCustomerLogMapper.findLogInfoByMobileNo(mobileNo); return aclCustomerLogMapper.findLogInfoByMobileNo(mobileNo);
} }
public List<AclCustomerSystemLog> findCustomerSystemLog(AclCustomerSystemLog aclCustomerSystemLog){
return aclCustomerSystemLogMapper.findCustomerSystemLog(aclCustomerSystemLog);
}
public int updateEndTimeByPrimaryKey(Long id){
return aclCustomerSystemLogMapper.updateEndTimeByPrimaryKey(id);
}
public int saveAclCustomerSystemLog(AclCustomerSystemLog aclCustomerSystemLog){
return aclCustomerSystemLogMapper.insertSelective(aclCustomerSystemLog);
}
} }
package com.yd.util.auth.filter; package com.yd.util.auth.filter;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
...@@ -15,6 +18,8 @@ import javax.servlet.http.HttpServletResponse; ...@@ -15,6 +18,8 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import com.yd.dal.entity.customer.AclCustomerSystemLog;
import com.yd.dal.service.customer.AclCustomerLogDALService;
import com.yd.util.CommonUtil; import com.yd.util.CommonUtil;
import com.yd.util.auth.setting.AudienceSetting; import com.yd.util.auth.setting.AudienceSetting;
import com.yd.util.auth.setting.JwtTokenUtil; import com.yd.util.auth.setting.JwtTokenUtil;
...@@ -30,6 +35,8 @@ public class HttpZuihuibiAuthorizeFilter implements Filter{ ...@@ -30,6 +35,8 @@ public class HttpZuihuibiAuthorizeFilter implements Filter{
private JwtTokenUtil jwtTokenUtil; private JwtTokenUtil jwtTokenUtil;
@Autowired @Autowired
private AudienceSetting audienceSetting; private AudienceSetting audienceSetting;
@Autowired
private AclCustomerLogDALService aclCustomerLogDALService;
private static final String BY_PASS_ALL = "TEST"; private static final String BY_PASS_ALL = "TEST";
@Override @Override
...@@ -90,14 +97,49 @@ public class HttpZuihuibiAuthorizeFilter implements Filter{ ...@@ -90,14 +97,49 @@ public class HttpZuihuibiAuthorizeFilter implements Filter{
}//not BY_PASS_ALL }//not BY_PASS_ALL
}//byPass != null }//byPass != null
//其他的URL请求,先获取head中的token,进行验证即可
boolean boole = false;
int issuerLength = audienceSetting.issuer.length();
String token = httpRequest.getHeader(audienceSetting.header);
if(!CommonUtil.isNullOrBlank(token) && token.length() > issuerLength){
String headStr = token.substring(0, issuerLength).toLowerCase();
if (headStr.compareTo(audienceSetting.issuer) == 0){
token = token.substring(issuerLength, token.length());
//token格式合法
if (jwtTokenUtil.validateToken(token)){
boole = true;
final String customerId = jwtTokenUtil.getCustomerIdToken(token);
final String tokenFinal = token;
if(CommonUtil.isNullOrBlank(customerId)){
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() {
@Override
public void run(){
AclCustomerSystemLog aclCustomerSystemLog = new AclCustomerSystemLog();
aclCustomerSystemLog.setCustomerId(Long.valueOf(customerId));
aclCustomerSystemLog.setToken(tokenFinal);
aclCustomerSystemLog.setExpiredMinute(10);
List<AclCustomerSystemLog> aclCustomerSystemLogList = aclCustomerLogDALService.findCustomerSystemLog(aclCustomerSystemLog);
if(aclCustomerSystemLogList != null && aclCustomerSystemLogList.size() > 0){
aclCustomerLogDALService.updateEndTimeByPrimaryKey(aclCustomerSystemLogList.get(0).getId());
}else{
aclCustomerSystemLog.setIsActive(1);
aclCustomerSystemLog.setFromSystem("1");
aclCustomerLogDALService.saveAclCustomerSystemLog(aclCustomerSystemLog);
}
}
});
}
}
}
}
if (isDoFilter){ if (isDoFilter){
chain.doFilter(request, response); chain.doFilter(request, response);
return; return;
} }
//其他的URL请求,先获取head中的token,进行验证即可
int issuerLength = audienceSetting.issuer.length();
String token = httpRequest.getHeader(audienceSetting.header);
/* /*
if (!isIpValid("ProdCheckIP") || !isIpValid("StageCheckIP")) { if (!isIpValid("ProdCheckIP") || !isIpValid("StageCheckIP")) {
if("autogeneral".equals(token)){ if("autogeneral".equals(token)){
...@@ -105,17 +147,10 @@ public class HttpZuihuibiAuthorizeFilter implements Filter{ ...@@ -105,17 +147,10 @@ public class HttpZuihuibiAuthorizeFilter implements Filter{
return; return;
} }
}*/ }*/
if(!CommonUtil.isNullOrBlank(token) && token.length() > issuerLength){ if(boole && !jwtTokenUtil.isTokenExpired(token)){
String headStr = token.substring(0, issuerLength).toLowerCase();
if (headStr.compareTo(audienceSetting.issuer) == 0){
token = token.substring(issuerLength, token.length());
//token格式合法并且没有失效
if (jwtTokenUtil.validateToken(token) && !jwtTokenUtil.isTokenExpired(token)){
chain.doFilter(request, response); chain.doFilter(request, response);
return; return;
} }
}
}
//验证失败,返回错误提示 //验证失败,返回错误提示
httpResponse.setCharacterEncoding("UTF-8"); httpResponse.setCharacterEncoding("UTF-8");
......
...@@ -29,7 +29,7 @@ public class AuthorizeServiceImpl implements AuthorizeService { ...@@ -29,7 +29,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
return responseVO; return responseVO;
} }
//获取TOKEN //获取TOKEN
String token = jwtTokenUtil.generateToken(requestVO.getTicket(),requestVO.getLoginId()); String token = jwtTokenUtil.generateToken(requestVO.getTicket(),requestVO.getLoginId(),requestVO.getCustomerId());
responseVO.setToken(token); responseVO.setToken(token);
responseVO.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000"))); responseVO.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000")));
return responseVO; return responseVO;
......
...@@ -32,6 +32,8 @@ public class JwtTokenUtil { ...@@ -32,6 +32,8 @@ public class JwtTokenUtil {
// private static final String CLAIM_KEY_BIRTHDAY = "birthDay"; // private static final String CLAIM_KEY_BIRTHDAY = "birthDay";
// private static final String CLAIM_KEY_ADDRESS = "address"; // private static final String CLAIM_KEY_ADDRESS = "address";
private static final String CLAIM_KEY_USERID = "UserId"; private static final String CLAIM_KEY_USERID = "UserId";
private static final String CLAIM_KEY_CUSTOMERID = "CustomerId";
@Autowired @Autowired
...@@ -206,12 +208,15 @@ public class JwtTokenUtil { ...@@ -206,12 +208,15 @@ public class JwtTokenUtil {
* @param ticket * @param ticket
* @return * @return
*/ */
public String generateToken(String ticket,String loginId){ public String generateToken(String ticket,String loginId, String customerId){
String token = null; String token = null;
Map<String, Object> claims = new HashMap<>(); Map<String, Object> claims = new HashMap<>();
if(!CommonUtil.isNullOrBlank(loginId)){ if(!CommonUtil.isNullOrBlank(loginId)){
claims.put(CLAIM_KEY_USERID, loginId); claims.put(CLAIM_KEY_USERID, loginId);
} }
if(!CommonUtil.isNullOrBlank(customerId)){
claims.put(CLAIM_KEY_CUSTOMERID, customerId);
}
claims.put(CLAIM_KEY_SUBJECT, ticket); claims.put(CLAIM_KEY_SUBJECT, ticket);
claims.put(CLAIM_KEY_CREATED, new Date()); claims.put(CLAIM_KEY_CREATED, new Date());
...@@ -276,4 +281,23 @@ public class JwtTokenUtil { ...@@ -276,4 +281,23 @@ public class JwtTokenUtil {
} }
return userId; return userId;
} }
/**
* 获取登录用户customerId
* @param token
* @return
*/
public String getCustomerIdToken(String token) {
String customerId = null ;
Map<String,Object> map = getClaimsFromToken(token);
String resultCode = (String)map.get("resultCode");
if("SUCCESS".equals(resultCode)){
Object obj = map.get("claims");
if(obj != null){
Claims claims = (Claims)obj;
customerId = (String)claims.get(CLAIM_KEY_CUSTOMERID);
}
}
return customerId;
}
} }
...@@ -4,6 +4,7 @@ public class ObtainTokenRequestVO { ...@@ -4,6 +4,7 @@ public class ObtainTokenRequestVO {
private String ticket; private String ticket;
private String ipAddress; private String ipAddress;
private String loginId; private String loginId;
private String customerId;
public String getTicket() { public String getTicket() {
return ticket; return ticket;
...@@ -23,4 +24,11 @@ public class ObtainTokenRequestVO { ...@@ -23,4 +24,11 @@ public class ObtainTokenRequestVO {
public void setLoginId(String loginId) { public void setLoginId(String loginId) {
this.loginId = loginId; this.loginId = loginId;
} }
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
} }
...@@ -5,15 +5,13 @@ ...@@ -5,15 +5,13 @@
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="customer_id" jdbcType="BIGINT" property="customerId" /> <result column="customer_id" jdbcType="BIGINT" property="customerId" />
<result column="token" jdbcType="VARCHAR" property="token" /> <result column="token" jdbcType="VARCHAR" property="token" />
<result column="customer_ip" jdbcType="VARCHAR" property="customerIp" />
<result column="customer_hostname" jdbcType="VARCHAR" property="customerHostname" />
<result column="from_system" jdbcType="VARCHAR" property="fromSystem" /> <result column="from_system" jdbcType="VARCHAR" property="fromSystem" />
<result column="start_time" jdbcType="TIMESTAMP" property="startTime" /> <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
<result column="end_time" jdbcType="TIMESTAMP" property="endTime" /> <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
<result column="is_active" jdbcType="INTEGER" property="isActive" /> <result column="is_active" jdbcType="INTEGER" property="isActive" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, customer_id, token, customer_ip, customer_hostname, from_system, start_time, id, customer_id, token, from_system, start_time,
end_time, is_active end_time, is_active
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
...@@ -27,11 +25,9 @@ ...@@ -27,11 +25,9 @@
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</delete> </delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerSystemLog" useGeneratedKeys="true"> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerSystemLog" useGeneratedKeys="true">
insert into ag_acl_customer_system_log (customer_id, token, customer_ip, insert into ag_acl_customer_system_log (customer_id, token, from_system, start_time,
customer_hostname, from_system, start_time,
end_time, is_active) end_time, is_active)
values (#{customerId,jdbcType=BIGINT}, #{token,jdbcType=VARCHAR}, #{customerIp,jdbcType=VARCHAR}, values (#{customerId,jdbcType=BIGINT}, #{token,jdbcType=VARCHAR}, #{fromSystem,jdbcType=VARCHAR}, #{startTime,jdbcType=TIMESTAMP},
#{customerHostname,jdbcType=VARCHAR}, #{fromSystem,jdbcType=VARCHAR}, #{startTime,jdbcType=TIMESTAMP},
#{endTime,jdbcType=TIMESTAMP}, #{isActive,jdbcType=INTEGER}) #{endTime,jdbcType=TIMESTAMP}, #{isActive,jdbcType=INTEGER})
</insert> </insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerSystemLog" useGeneratedKeys="true"> <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerSystemLog" useGeneratedKeys="true">
...@@ -43,12 +39,6 @@ ...@@ -43,12 +39,6 @@
<if test="token != null"> <if test="token != null">
token, token,
</if> </if>
<if test="customerIp != null">
customer_ip,
</if>
<if test="customerHostname != null">
customer_hostname,
</if>
<if test="fromSystem != null"> <if test="fromSystem != null">
from_system, from_system,
</if> </if>
...@@ -69,12 +59,6 @@ ...@@ -69,12 +59,6 @@
<if test="token != null"> <if test="token != null">
#{token,jdbcType=VARCHAR}, #{token,jdbcType=VARCHAR},
</if> </if>
<if test="customerIp != null">
#{customerIp,jdbcType=VARCHAR},
</if>
<if test="customerHostname != null">
#{customerHostname,jdbcType=VARCHAR},
</if>
<if test="fromSystem != null"> <if test="fromSystem != null">
#{fromSystem,jdbcType=VARCHAR}, #{fromSystem,jdbcType=VARCHAR},
</if> </if>
...@@ -98,12 +82,6 @@ ...@@ -98,12 +82,6 @@
<if test="token != null"> <if test="token != null">
token = #{token,jdbcType=VARCHAR}, token = #{token,jdbcType=VARCHAR},
</if> </if>
<if test="customerIp != null">
customer_ip = #{customerIp,jdbcType=VARCHAR},
</if>
<if test="customerHostname != null">
customer_hostname = #{customerHostname,jdbcType=VARCHAR},
</if>
<if test="fromSystem != null"> <if test="fromSystem != null">
from_system = #{fromSystem,jdbcType=VARCHAR}, from_system = #{fromSystem,jdbcType=VARCHAR},
</if> </if>
...@@ -123,12 +101,31 @@ ...@@ -123,12 +101,31 @@
update ag_acl_customer_system_log update ag_acl_customer_system_log
set customer_id = #{customerId,jdbcType=BIGINT}, set customer_id = #{customerId,jdbcType=BIGINT},
token = #{token,jdbcType=VARCHAR}, token = #{token,jdbcType=VARCHAR},
customer_ip = #{customerIp,jdbcType=VARCHAR},
customer_hostname = #{customerHostname,jdbcType=VARCHAR},
from_system = #{fromSystem,jdbcType=VARCHAR}, from_system = #{fromSystem,jdbcType=VARCHAR},
start_time = #{startTime,jdbcType=TIMESTAMP}, start_time = #{startTime,jdbcType=TIMESTAMP},
end_time = #{endTime,jdbcType=TIMESTAMP}, end_time = #{endTime,jdbcType=TIMESTAMP},
is_active = #{isActive,jdbcType=INTEGER} is_active = #{isActive,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<select id="findCustomerSystemLog" parameterType="com.yd.dal.entity.customer.AclCustomerSystemLog" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ag_acl_customer_system_log
where customer_id = #{customerId,jdbcType=BIGINT}
<if test="token != null">
and token = #{token,jdbcType=VARCHAR}
</if>
and to_days(start_time) = to_days(now())
and end_time > date_sub(now(),interval #{expiredMinute,jdbcType=BIGINT} minute)
and from_system = '1' and is_active = 1
</select>
<update id="updateEndTimeByPrimaryKey" parameterType="java.lang.Long">
update ag_acl_customer_system_log
set end_time = now()
where id = #{id,jdbcType=BIGINT}
</update>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment