修改Auth有效期方便测试,将用户未读红点添加至Redis中,方便别人调用
This commit is contained in:
parent
02bc08b1e4
commit
edbab6dbee
@ -27,7 +27,7 @@ public class TokenService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
private final static long EXPIRE_TIME = Constants.TOKEN_EXPIRE * 60;
|
private final static long EXPIRE_TIME = Constants.TOKEN_EXPIRE * 6000;
|
||||||
|
|
||||||
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package com.xhpc.gateway.filter;
|
package com.xhpc.gateway.filter;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.xhpc.common.core.constant.CacheConstants;
|
import com.xhpc.common.core.constant.CacheConstants;
|
||||||
import com.xhpc.common.core.constant.Constants;
|
import com.xhpc.common.core.constant.Constants;
|
||||||
import com.xhpc.common.core.domain.R;
|
import com.xhpc.common.core.domain.R;
|
||||||
|
import com.xhpc.common.core.utils.ServletUtils;
|
||||||
import com.xhpc.common.core.utils.StringUtils;
|
import com.xhpc.common.core.utils.StringUtils;
|
||||||
import com.xhpc.common.redis.service.RedisService;
|
import com.xhpc.common.redis.service.RedisService;
|
||||||
import com.xhpc.gateway.config.properties.IgnoreWhiteProperties;
|
import com.xhpc.gateway.config.properties.IgnoreWhiteProperties;
|
||||||
@ -14,6 +16,7 @@ import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
|||||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
@ -22,6 +25,8 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网关鉴权
|
* 网关鉴权
|
||||||
*
|
*
|
||||||
@ -38,8 +43,8 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IgnoreWhiteProperties ignoreWhite;
|
private IgnoreWhiteProperties ignoreWhite;
|
||||||
|
|
||||||
// @Resource(name = "stringRedisTemplate")
|
@Resource(name = "stringRedisTemplate")
|
||||||
// private ValueOperations<String, String> sops;
|
private ValueOperations<String, String> sops;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
@ -48,34 +53,34 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
|
||||||
String url = exchange.getRequest().getURI().getPath();
|
String url = exchange.getRequest().getURI().getPath();
|
||||||
// // 跳过不需要验证的路径
|
// 跳过不需要验证的路径
|
||||||
// if (StringUtils.matches(url, ignoreWhite.getWhites())) {
|
if (StringUtils.matches(url, ignoreWhite.getWhites())) {
|
||||||
// return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
// }
|
}
|
||||||
// String token = getToken(exchange.getRequest());
|
String token = getToken(exchange.getRequest());
|
||||||
// if (StringUtils.isBlank(token)) {
|
if (StringUtils.isBlank(token)) {
|
||||||
// return setUnauthorizedResponse(exchange, "令牌不能为空");
|
return setUnauthorizedResponse(exchange, "令牌不能为空");
|
||||||
// }
|
}
|
||||||
// String userStr = sops.get(getTokenKey(token));
|
String userStr = sops.get(getTokenKey(token));
|
||||||
// if (StringUtils.isNull(userStr)) {
|
if (StringUtils.isNull(userStr)) {
|
||||||
// userStr = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
userStr = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
||||||
// if (StringUtils.isNull(userStr)) {
|
if (StringUtils.isNull(userStr)) {
|
||||||
// return setUnauthorizedResponse(exchange, "登录状态已过期");
|
return setUnauthorizedResponse(exchange, "登录状态已过期");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// JSONObject obj = JSONObject.parseObject(userStr);
|
JSONObject obj = JSONObject.parseObject(userStr);
|
||||||
// String userid = obj.getString("userid");
|
String userid = obj.getString("userid");
|
||||||
// String username = obj.getString("username");
|
String username = obj.getString("username");
|
||||||
// if (StringUtils.isBlank(userid) || StringUtils.isBlank(username)) {
|
if (StringUtils.isBlank(userid) || StringUtils.isBlank(username)) {
|
||||||
// return setUnauthorizedResponse(exchange, "令牌验证失败");
|
return setUnauthorizedResponse(exchange, "令牌验证失败");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 设置过期时间
|
// 设置过期时间
|
||||||
// redisService.expire(getTokenKey(token), EXPIRE_TIME);
|
redisService.expire(getTokenKey(token), EXPIRE_TIME);
|
||||||
// // 设置用户信息到请求
|
// 设置用户信息到请求
|
||||||
// ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid)
|
ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid)
|
||||||
// .header(CacheConstants.DETAILS_USERNAME, ServletUtils.urlEncode(username)).build();
|
.header(CacheConstants.DETAILS_USERNAME, ServletUtils.urlEncode(username)).build();
|
||||||
// ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build();
|
ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build();
|
||||||
|
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public interface XhpcInvoiceMapper {
|
|||||||
BigDecimal allNotInvoicedMoney();
|
BigDecimal allNotInvoicedMoney();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新指定发票状态,让其成为已开发票状态
|
* 更新指定发票状态,让其成为已开发票状态,并设置用户未阅读标签
|
||||||
*
|
*
|
||||||
* @param requestData 更新数据的来源
|
* @param requestData 更新数据的来源
|
||||||
* @return Long 返回更新受影响的条数
|
* @return Long 返回更新受影响的条数
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
package com.xhpc.invoice.service.impl;
|
package com.xhpc.invoice.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.extra.mail.MailUtil;
|
import cn.hutool.extra.mail.MailUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
|
import cn.hutool.poi.excel.ExcelWriter;
|
||||||
import com.xhpc.common.core.utils.DateUtils;
|
import com.xhpc.common.core.utils.DateUtils;
|
||||||
import com.xhpc.common.core.utils.bean.BeanUtils;
|
import com.xhpc.common.core.utils.bean.BeanUtils;
|
||||||
import com.xhpc.common.domain.XhpcChargingStation;
|
import com.xhpc.common.domain.XhpcChargingStation;
|
||||||
|
import com.xhpc.common.redis.service.RedisService;
|
||||||
import com.xhpc.invoice.constant.InvoiceMapHistoryOrderStatusConst;
|
import com.xhpc.invoice.constant.InvoiceMapHistoryOrderStatusConst;
|
||||||
import com.xhpc.invoice.domain.*;
|
import com.xhpc.invoice.domain.*;
|
||||||
import com.xhpc.invoice.mapper.*;
|
import com.xhpc.invoice.mapper.*;
|
||||||
@ -48,6 +52,8 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
|
|||||||
XhpcHistoryOrderMapper xhpcHistoryOrderMapper;
|
XhpcHistoryOrderMapper xhpcHistoryOrderMapper;
|
||||||
@Resource
|
@Resource
|
||||||
Environment environment;
|
Environment environment;
|
||||||
|
@Resource
|
||||||
|
RedisService redisService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过requestData中的申请人、申请人类型、发票状态、发票起始时间、发票申请终止时间、开票起始时间、开票终点时间、当前所在页数、当前页所要显示几行,来查询发票列表信息
|
* 通过requestData中的申请人、申请人类型、发票状态、发票起始时间、发票申请终止时间、开票起始时间、开票终点时间、当前所在页数、当前页所要显示几行,来查询发票列表信息
|
||||||
@ -128,11 +134,13 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
|
|||||||
electricInvoiceFile.delete();
|
electricInvoiceFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//更新发票数据
|
//更新发票数据,并设置用户未阅读状态
|
||||||
Long successFlag = xhpcInvoiceMapper.invoiceToUser(requestData);
|
Long successFlag = xhpcInvoiceMapper.invoiceToUser(requestData);
|
||||||
if (successFlag == 0) {
|
if (successFlag == 0) {
|
||||||
throw new RuntimeException("无法更新指定发票,传入的数据有问题");
|
throw new RuntimeException("无法更新指定发票,传入的数据有问题");
|
||||||
}
|
}
|
||||||
|
//将该用户未阅读的数量放入到redis中
|
||||||
|
putNoReadInvoiceCountIntoRedis(requestData);
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +154,28 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
|
|||||||
xhpcInvoiceMapper.failInvoiceToUser(requestData);
|
xhpcInvoiceMapper.failInvoiceToUser(requestData);
|
||||||
//解除锁定
|
//解除锁定
|
||||||
xhpcInvoiceMapHistoryOrderMapper.unlockHistoryOrdersByInvoiceId(requestData.getInvoiceId());
|
xhpcInvoiceMapHistoryOrderMapper.unlockHistoryOrdersByInvoiceId(requestData.getInvoiceId());
|
||||||
|
//将该用户未阅读的数量放入到redis中
|
||||||
|
putNoReadInvoiceCountIntoRedis(requestData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将该用户没有阅读的发票的数量放入到Redis中保存,供别人调用
|
||||||
|
*
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 13:54
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
private void putNoReadInvoiceCountIntoRedis(InvoiceToUserRequest requestData) {
|
||||||
|
|
||||||
|
XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(requestData.getInvoiceId());
|
||||||
|
String redisKey = generateRedisKey(xhpcInvoice);
|
||||||
|
if (redisService.getCacheObject(redisKey) == null) {
|
||||||
|
redisService.setCacheObject(redisKey, 1);
|
||||||
|
} else {
|
||||||
|
Integer noReadCount = redisService.getCacheObject(redisKey);
|
||||||
|
noReadCount = noReadCount + 1;
|
||||||
|
redisService.setCacheObject(redisKey, noReadCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -261,11 +291,62 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
|
|||||||
historyOrdersDTO.setTotalItems(historyOrdersList.size());
|
historyOrdersDTO.setTotalItems(historyOrdersList.size());
|
||||||
specificInvoicedResponse.setHistoryOrders(historyOrdersDTO);
|
specificInvoicedResponse.setHistoryOrders(historyOrdersDTO);
|
||||||
|
|
||||||
//一旦调了详情接口,就去掉该已开发票的未读状态
|
//一旦调了详情接口,就去掉该已开发票的未读状态,同时redis中的未读数量数据-1
|
||||||
xhpcInvoiceMapper.updateByInvoiceId(invoiceId);
|
xhpcInvoiceMapper.updateByInvoiceId(invoiceId);
|
||||||
|
reduceNoReadInvoiceCount(xhpcInvoice);
|
||||||
return specificInvoicedResponse;
|
return specificInvoicedResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将用户未读的发票数量-1
|
||||||
|
*
|
||||||
|
* @param xhpcInvoice 用户查看的发票
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 13:55
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
private void reduceNoReadInvoiceCount(XhpcInvoice xhpcInvoice) {
|
||||||
|
|
||||||
|
String redisKey = generateRedisKey(xhpcInvoice);
|
||||||
|
if (redisService.getCacheObject(redisKey).equals(1)) {
|
||||||
|
redisService.deleteObject(redisKey);
|
||||||
|
} else {
|
||||||
|
Integer noReadCount = redisService.getCacheObject(redisKey);
|
||||||
|
noReadCount = noReadCount - 1;
|
||||||
|
redisService.setCacheObject(redisKey, noReadCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成该用户在Redis中的唯一表示key
|
||||||
|
*
|
||||||
|
* @param xhpcInvoice 用户查看的发票
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 13:52
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
private String generateRedisKey(XhpcInvoice xhpcInvoice) {
|
||||||
|
|
||||||
|
String redisKey = "global:invoice:";
|
||||||
|
switch (xhpcInvoice.getCreatorType()) {
|
||||||
|
case 0:
|
||||||
|
redisKey = redisKey + "C" + xhpcInvoice.getCreatorId();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
redisKey = redisKey + "L" + xhpcInvoice.getCreatorId();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
redisKey = redisKey + "ST" + xhpcInvoice.getCreatorId();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
redisKey = redisKey + "BE" + xhpcInvoice.getCreatorId();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return redisKey;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据前端传递过来的请求参数,查询所需要的开发票历史记录
|
* 根据前端传递过来的请求参数,查询所需要的开发票历史记录
|
||||||
*
|
*
|
||||||
@ -396,6 +477,28 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
|
|||||||
return xhpcInvoiceMapper.findNotReadCount(creatorId, creatorType);
|
return xhpcInvoiceMapper.findNotReadCount(creatorId, creatorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出所有发票记录(已开与未开)到Excel中
|
||||||
|
*
|
||||||
|
* @param invoiceIds 发票id
|
||||||
|
* @author WH
|
||||||
|
* @date 2021/12/30 10:16
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void exportExcel(List<Integer> invoiceIds) {
|
||||||
|
|
||||||
|
Integer integer = invoiceIds.get(0);
|
||||||
|
//获取要导出的发票记录
|
||||||
|
XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(Long.valueOf(integer));
|
||||||
|
List<XhpcInvoice> rows = CollUtil.newArrayList(xhpcInvoice);
|
||||||
|
//写出记录到excel表中
|
||||||
|
ExcelWriter writer = ExcelUtil.getWriter("d:/writeTest.xlsx");
|
||||||
|
writer.write(rows);
|
||||||
|
writer.close();
|
||||||
|
//写入到Response中
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过发票id查找对应的发票数据
|
* 通过发票id查找对应的发票数据
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user