main
parent
47c9bc7f92
commit
7f26cbab55
@ -0,0 +1,26 @@
|
||||
package com.ssm;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import tk.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@SpringBootApplication(scanBasePackages="com.ssm")
|
||||
@EnableSwagger2
|
||||
@MapperScan("com.ssm.manage.mapper")
|
||||
@EnableScheduling
|
||||
@EnableAspectJAutoProxy
|
||||
//@ComponentScan(basePackages = {"com.ssm.filter"})
|
||||
//@ComponentScan(basePackages = {"com.ssm"})
|
||||
public class DmWebApp {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
SpringApplication.run(DmWebApp.class, args);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
//package com.ssm.Listener;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONArray;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.rabbitmq.client.Channel;
|
||||
//import com.ssm.manage.response.GenericResponse;
|
||||
//import com.ssm.manage.utils.SessionHelp;
|
||||
//import com.ssm.core.utils.ChuangLanSmsUtil;
|
||||
//import com.ssm.manage.entity.AccountTradeRecord;
|
||||
//import com.ssm.manage.entity.BaseStore;
|
||||
//import com.ssm.manage.entity.CashSignatureFile;
|
||||
//import com.ssm.manage.entity.SmsException;
|
||||
//import com.ssm.manage.query.CashListRequest;
|
||||
//import com.ssm.manage.service.SsmCashService;
|
||||
//import com.ssm.manage.utils.Constant;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang.StringUtils;
|
||||
//import org.springframework.amqp.core.Message;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.messaging.handler.annotation.Headers;
|
||||
//import org.springframework.messaging.handler.annotation.Payload;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//@Component
|
||||
//@Configuration
|
||||
//@Slf4j
|
||||
//public class SsmCashListener {
|
||||
// private static final String CASH_TOPIC_CHANGEGE = "cash_exchange";
|
||||
// private static final String CASH_QUEUE = "cash_queue";
|
||||
// @Autowired
|
||||
// private SsmCashService ssmCashService;
|
||||
//
|
||||
// /**
|
||||
// * 监听主队列~
|
||||
// *
|
||||
// * @param message
|
||||
// * @param map
|
||||
// * @param channel
|
||||
// * @throws InterruptedException
|
||||
// * @throws IOException
|
||||
// */
|
||||
// @RabbitListener(queues = CASH_QUEUE)
|
||||
// public void sendMiss(Message message, @Headers Map<String, Object> map, Channel channel) throws InterruptedException, IOException {
|
||||
// Map map1 = JSON.parseObject(message.getBody(), Map.class);
|
||||
//// JSONObject jsonObject = JSON.parse(message.getBody());
|
||||
//// JSONObject parseObject = JSON.parseObject(message.toString());
|
||||
//// List<CashListRequest> listRequests = parseObject.getJSONArray("cashListRequests").toJavaList(CashListRequest.class);
|
||||
//// BigDecimal spendMoney = parseObject.getBigDecimal("spendMoney");
|
||||
//// BigDecimal consumeMoney = parseObject.getBigDecimal("consumeMoney");
|
||||
//// Integer spendCount = parseObject.getInteger("spendCount");
|
||||
//// Integer consumeCount = parseObject.getInteger("consumeCount");
|
||||
//// String projectName = parseObject.getString("projectName");
|
||||
//// String memberPhone = parseObject.getString("memberPhone");
|
||||
//
|
||||
// JSONObject tradeRecordObj = (JSONObject) map1.get("accountTradeRecord");
|
||||
// AccountTradeRecord accountTradeRecord = tradeRecordObj.toJavaObject(AccountTradeRecord.class);
|
||||
// JSONObject storeObj = (JSONObject) map1.get("baseStore");
|
||||
// BaseStore baseStore = storeObj.toJavaObject(BaseStore.class);
|
||||
//
|
||||
// if (Constant.account_type_recharge_consume.equals(accountTradeRecord.getAccountType())) {
|
||||
// if (StringUtils.isNotBlank(baseStore.getSmsAccount())) {
|
||||
// try {
|
||||
// ChuangLanSmsUtil.sendCashByRechargeSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getAccountSpendMoney(), accountTradeRecord.getAccountConsumeMoney());
|
||||
// } catch (Exception e) {
|
||||
// log.error("SsmCashListener.sendMiss:", e);
|
||||
// //即放入死信队列-推送后续队列内消息即为抢单失败-
|
||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
|
||||
// }
|
||||
// }
|
||||
// } else if (Constant.account_type_project_consume.equals(accountTradeRecord.getAccountType())) {//疗程卡支付
|
||||
// //设置短信账户 发送 否则不发送
|
||||
// if (StringUtils.isNotBlank(baseStore.getSmsAccount())) {
|
||||
// try {
|
||||
// ChuangLanSmsUtil.sendCashByCourseSms(baseStore, accountTradeRecord.getMemberPhone(), accountTradeRecord.getTradeName(), accountTradeRecord.getAccountSpendCount(), accountTradeRecord.getAccountConsumeCount());
|
||||
// } catch (Exception e) {
|
||||
// log.error("SsmCashListener.sendMiss:", e);
|
||||
// //即放入死信队列-推送后续队列内消息即为抢单失败-
|
||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// //手动设置ACK接收确认当前消息消费完毕
|
||||
// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 监听死信队列-即发送短信失败
|
||||
// *
|
||||
// * @param message
|
||||
// * @param map
|
||||
// * @param channel
|
||||
// * @throws InterruptedException
|
||||
// * @throws IOException
|
||||
// */
|
||||
// @RabbitListener(queues = "deal_queue")
|
||||
// public static void sendMiss2(Message message, @Headers Map<String, Object> map, Channel channel) throws InterruptedException, IOException {
|
||||
// String msg = new String(message.getBody(), "UTF-8");
|
||||
// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
// log.error("SsmCashListener.sendMiss2:", "短信发送失败");
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.ssm.core.util;
|
||||
|
||||
import com.ssm.manage.utils.Constant;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import sun.misc.BASE64Decoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class Base64DecodedMultipartFileUtil implements MultipartFile {
|
||||
private final byte[] imgContent;
|
||||
private final String header;
|
||||
|
||||
public Base64DecodedMultipartFileUtil(byte[] imgContent, String header) {
|
||||
this.imgContent = imgContent;
|
||||
this.header = header.split(";")[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return System.currentTimeMillis() + Math.random() + "." + header.split("/")[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalFilename() {
|
||||
return System.currentTimeMillis() + (int) Math.random() * 10000 + "." + header.split("/")[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return header.split(":")[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return imgContent == null || imgContent.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return imgContent.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
return imgContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(imgContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||
new FileOutputStream(dest).write(imgContent);
|
||||
}
|
||||
|
||||
public static MultipartFile base64ToMultipart(String base64) {
|
||||
try {
|
||||
String[] baseStrs = base64.split(",");
|
||||
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
byte[] b = new byte[0];
|
||||
b = decoder.decodeBuffer(baseStrs[1]);
|
||||
|
||||
for (int i = 0; i < b.length; ++i) {
|
||||
if (b[i] < 0) {
|
||||
b[i] += 256;
|
||||
}
|
||||
}
|
||||
return new Base64DecodedMultipartFileUtil(b, baseStrs[0]);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,232 @@
|
||||
package com.ssm.core.util;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelReader;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.read.metadata.ReadSheet;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import com.ssm.core.utils.FtpUtils;
|
||||
import com.ssm.manage.entity.SmsException;
|
||||
import com.ssm.manage.response.ResponseCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
public class EasyExcelUtil {
|
||||
|
||||
private static final String SUFFIX_XLS = ".xls";
|
||||
private static final String SUFFIX_XLSX = ".xlsx";
|
||||
private static final String REGEX_EXCEL = ".+(.xls|.xlsx|.XLS|.XLSX)$";
|
||||
|
||||
|
||||
public static String templateResponseExports(String templateFileName, Object obj, List list, HttpServletRequest request, HttpServletResponse response) throws SmsException {
|
||||
String fileName = System.currentTimeMillis() + SUFFIX_XLSX;
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + FtpUtils.setFileDownloadHeader(request, fileName));
|
||||
ExcelWriter excelWriter = null;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = EasyExcelUtil.class.getClassLoader().getResourceAsStream(templateFileName);
|
||||
excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(stream).build();
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||
excelWriter.fill(obj, writeSheet);
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||
excelWriter.fill(list, fillConfig, writeSheet);
|
||||
} catch (Exception e) {
|
||||
log.error("EasyExcelUtil.templateResponseExports:",e);
|
||||
throw new SmsException(ResponseCode.FILE_DOWNLOAD_FAILED);
|
||||
} finally {
|
||||
// 千万别忘记关闭流
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (excelWriter != null) {
|
||||
excelWriter.finish();
|
||||
}
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public static String templateResponseExport(String templateFileName, Class<?> clas, List list, HttpServletRequest request, HttpServletResponse response) throws SmsException {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
String fileName = System.currentTimeMillis() + SUFFIX_XLSX;
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + FtpUtils.setFileDownloadHeader(request, fileName));
|
||||
out = response.getOutputStream();
|
||||
simpleTemplateFill(templateFileName, clas, list, out);
|
||||
return fileName;
|
||||
} catch (IOException e) {
|
||||
log.error("EasyExcelUtil.templateResponseExport:",e);
|
||||
throw new SmsException(ResponseCode.FILE_DOWNLOAD_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
public static String simpleResponseExport(String sheetName, Class<?> clas, List list, HttpServletRequest request, HttpServletResponse response) throws SmsException {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
String fileName = sheetName + System.currentTimeMillis() + SUFFIX_XLSX;
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + FtpUtils.setFileDownloadHeader(request, fileName));
|
||||
out = response.getOutputStream();
|
||||
simpleFill(sheetName, clas, list, out);
|
||||
return fileName;
|
||||
} catch (IOException e) {
|
||||
log.error("EasyExcelUtil.simpleResponseExport:",e);
|
||||
throw new SmsException(ResponseCode.FILE_DOWNLOAD_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
public static void simpleFill(String sheetName, Class<?> clas, List list, OutputStream out) {
|
||||
ExcelWriter excelWriter = null;
|
||||
try {
|
||||
excelWriter = EasyExcel.write(out, clas)
|
||||
// 去除默认样式
|
||||
.useDefaultStyle(false)
|
||||
// .registerWriteHandler(getStyleStrategy())
|
||||
.build();
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet(sheetName).build();
|
||||
excelWriter.write(list, writeSheet);
|
||||
} finally {
|
||||
// 千万别忘记finish 会帮忙关闭流
|
||||
if (excelWriter != null) {
|
||||
excelWriter.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void simpleTemplateFill(String templateFileName, Class<?> clas, List list, OutputStream out) throws SmsException {
|
||||
// 方案2 分多次 填充 会使用文件缓存(省内存)
|
||||
ExcelWriter excelWriter = null;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = EasyExcelUtil.class.getClassLoader().getResourceAsStream(templateFileName);
|
||||
excelWriter = EasyExcel.write(out, clas).withTemplate(stream).build();
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||
excelWriter.fill(list, fillConfig, writeSheet);
|
||||
} catch (Exception e) {
|
||||
log.error("EasyExcelUtil.simpleTemplateFill:",e);
|
||||
throw new SmsException(ResponseCode.FILE_DOWNLOAD_FAILED);
|
||||
} finally {
|
||||
// 千万别忘记关闭流
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
log.error("EasyExcelUtil.simpleTemplateFill:",e);
|
||||
}
|
||||
}
|
||||
if (excelWriter != null) {
|
||||
excelWriter.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List simpleWrite(MultipartFile multipartFile, Class<?> clas) throws SmsException {
|
||||
if (multipartFile == null || !verifyFilename(multipartFile.getOriginalFilename())) {
|
||||
throw new SmsException(ResponseCode.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
try {
|
||||
// 解析每行结果在listener中处理
|
||||
ExcelListener listener = new ExcelListener();
|
||||
InputStream inputStream = multipartFile.getInputStream();
|
||||
ExcelReader excelReader = EasyExcel.read(inputStream, clas, listener).build();
|
||||
ReadSheet readSheet = new ReadSheet();
|
||||
readSheet=EasyExcel.readSheet(0).build();
|
||||
excelReader.read(readSheet);
|
||||
return listener.getDatas();
|
||||
} catch (IOException e) {
|
||||
log.error("EasyExcelUtil.simpleWrite:",e);
|
||||
|
||||
}catch (Exception e){
|
||||
log.error("Exception:",e);
|
||||
throw new SmsException(ResponseCode.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
throw new SmsException(ResponseCode.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
|
||||
public static List simpleWrite(MultipartFile multipartFile, Class<?> clas, int headRowNumber) throws SmsException {
|
||||
if (multipartFile == null || !verifyFilename(multipartFile.getOriginalFilename())) {
|
||||
throw new SmsException(ResponseCode.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
try {
|
||||
// 解析每行结果在listener中处理
|
||||
ExcelListener listener = new ExcelListener();
|
||||
InputStream inputStream = multipartFile.getInputStream();
|
||||
ExcelReader excelReader = EasyExcel.read(inputStream, clas, listener).build();
|
||||
ReadSheet readSheet = EasyExcel.readSheet(0).build();
|
||||
readSheet.setHeadRowNumber(headRowNumber);
|
||||
excelReader.read(readSheet);
|
||||
return listener.getDatas();
|
||||
} catch (IOException e) {
|
||||
log.error("EasyExcelUtil.simpleWrite:",e);
|
||||
}
|
||||
throw new SmsException(ResponseCode.FILE_UPLOAD_FAILED);
|
||||
}
|
||||
|
||||
public static boolean verifyFilename(String fileName) {
|
||||
Matcher matcher = Pattern.compile(REGEX_EXCEL).matcher(fileName);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置样式 去除默认表头样式及设置内容居中
|
||||
*/
|
||||
public static HorizontalCellStyleStrategy getStyleStrategy() {
|
||||
//内容样式策略
|
||||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||
//垂直居中,水平居中
|
||||
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
|
||||
contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
|
||||
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
//设置 自动换行
|
||||
contentWriteCellStyle.setWrapped(true);
|
||||
// 字体策略
|
||||
WriteFont contentWriteFont = new WriteFont();
|
||||
// 字体大小
|
||||
contentWriteFont.setFontHeightInPoints((short) 12);
|
||||
contentWriteCellStyle.setWriteFont(contentWriteFont);
|
||||
//头策略使用默认
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
headWriteCellStyle.setShrinkToFit(false);
|
||||
headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
||||
return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
|
||||
}
|
||||
|
||||
public static CellStyle cellStyle(Workbook workbook) {
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
//居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
||||
//设置边框
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);
|
||||
return cellStyle;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.ssm.core.util;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class ExcelUtils {
|
||||
|
||||
|
||||
|
||||
|
||||
public static Workbook readExcel(String filePath) throws IOException {
|
||||
Workbook wb = null;
|
||||
if(filePath==null){
|
||||
return null;
|
||||
}
|
||||
String extString = filePath.substring(filePath.lastIndexOf("."));
|
||||
InputStream is = null;
|
||||
is = new FileInputStream(filePath);
|
||||
if(".xls".equals(extString)){
|
||||
wb = new HSSFWorkbook(is);
|
||||
}else if(".xlsx".equals(extString)){
|
||||
wb = new XSSFWorkbook(is);
|
||||
}else{
|
||||
wb = null;
|
||||
}
|
||||
|
||||
return wb;
|
||||
}
|
||||
|
||||
|
||||
public static Workbook readExcel(String fileName,InputStream inputStream) throws IOException {
|
||||
if(fileName.endsWith(".xls")){
|
||||
return new HSSFWorkbook(inputStream);
|
||||
}else if(fileName.endsWith(".xlsx")){
|
||||
return new XSSFWorkbook(inputStream);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Object getCellValue(Cell cell){
|
||||
Object value = null;
|
||||
DecimalFormat df = new DecimalFormat("0"); //格式化number String字符
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd"); //日期格式化
|
||||
DecimalFormat df2 = new DecimalFormat("0.00"); //格式化数字
|
||||
if(cell.getCellTypeEnum().equals(CellType.STRING)){
|
||||
value = cell.getRichStringCellValue().getString();
|
||||
}else if(cell.getCellTypeEnum().equals(CellType.NUMERIC)){
|
||||
if("General".equals(cell.getCellStyle().getDataFormatString())){
|
||||
value = df.format(cell.getNumericCellValue());
|
||||
}else if("m/d/yy".equals(cell.getCellStyle().getDataFormatString())){
|
||||
value = sdf.format(cell.getDateCellValue());
|
||||
}else{
|
||||
value = df2.format(cell.getNumericCellValue());
|
||||
}
|
||||
}else if(cell.getCellTypeEnum().equals(CellType.BOOLEAN)){
|
||||
value = cell.getBooleanCellValue();
|
||||
// }else if(cell.getCellTypeEnum().equals(CellType.BLANK)){
|
||||
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.ssm.core.util;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 获取用户访问ip地址
|
||||
*/
|
||||
public class IpUtil {
|
||||
public static String getIpAddress(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
// 获取到多个ip时取第一个作为客户端真实ip
|
||||
if (StringUtils.isNotEmpty(ip) && ip.contains(",")) {
|
||||
String[] ipArray = ip.split(",");
|
||||
if (ArrayUtils.isNotEmpty(ipArray)) {
|
||||
ip = ipArray[0];
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package com.ssm.core.util;
|
||||
|
||||
import com.ssm.core.utils.AESUtils;
|
||||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
||||
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
|
||||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
|
||||
import org.jasypt.util.text.BasicTextEncryptor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @Created with Intellij IDEA
|
||||
* @Author :
|
||||
* @Date : 2018/5/18 - 10:37
|
||||
* @Copyright (C), 2018-2018
|
||||
* @Descripition : Jasypt安全框架加密类工具包
|
||||
*/
|
||||
public class JasyptUtils {
|
||||
|
||||
/**
|
||||
* Jasypt生成加密结果
|
||||
*
|
||||
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
|
||||
* @param value 待加密值
|
||||
* @return
|
||||
*/
|
||||
public static String encryptPwd(String password, String value) {
|
||||
PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor();
|
||||
encryptOr.setConfig(cryptOr(password));
|
||||
String result = encryptOr.encrypt(value);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
|
||||
* @param value 待解密密文
|
||||
* @return
|
||||
*/
|
||||
public static String decyptPwd(String password, String value) {
|
||||
PooledPBEStringEncryptor encryptOr = new PooledPBEStringEncryptor();
|
||||
encryptOr.setConfig(cryptOr(password));
|
||||
String result = encryptOr.decrypt(value);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param password salt
|
||||
* @return
|
||||
*/
|
||||
public static SimpleStringPBEConfig cryptOr(String password) {
|
||||
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
|
||||
config.setPassword(password);
|
||||
config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
|
||||
config.setKeyObtentionIterations("1000");
|
||||
config.setPoolSize("1");
|
||||
config.setProviderName(null);
|
||||
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
|
||||
config.setStringOutputType("base64");
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// String docnum = "SYA00620230814001";
|
||||
// String substring = docnum.substring(docnum.length() - 11, docnum.length() - 5);
|
||||
// System.out.println("substring = " + substring);
|
||||
//spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dcmy-newedition?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&allowMultiQueries=true
|
||||
//spring.datasource.username=ENC(O1BQh3ko5C6HZslX7Mi6Yw==)
|
||||
//spring.datasource.password=ENC(jrlD4uGPqs4isJc70wkGgdX8IeVhqlaigr9NmoZU/gnB+u0J6mUBZZEI2zPu1E9rvkTEjt/EsIRzGpLHy88080PchNTKTTRxX7UwIeWgDAsMxW/wwdUBCct8a2NvAw27hVPFuD8KXSD5uEa9eQMl8Ws+t7vWnfDufO+cA9NVgZe+ngaRITTegg/XKCZkGo/JtjQY54UKF0+EtiCGuBTYbP5L+xeI8u9K7pcA1zEtVwoAoS5MkTlVtqV8FycWJKAc)
|
||||
//spring.datasource.username=ENC(O1BQh3ko5C6HZslX7Mi6Yw==)
|
||||
//spring.datasource.password=ENC(jrlD4uGPqs4isJc70wkGgdX8IeVhqlaigr9NmoZU/gnB+u0J6mUBZZEI2zPu1E9rvkTEjt/EsIRzGpLHy88080PchNTKTTRxX7UwIeWgDAsMxW/wwdUBCct8a2NvAw27hVPFuD8KXSD5uEa9eQMl8Ws+t7vWnfDufO+cA9NVgZe+ngaRITTegg/XKCZkGo/JtjQY54UKF0+EtiCGuBTYbP5L+xeI8u9K7pcA1zEtVwoAoS5MkTlVtqV8FycWJKAc)
|
||||
// System.out.println(AESUtils.encrypt("13927759532"));
|
||||
// System.out.println(AESUtils.encrypt("1392779532"));
|
||||
// System.out.println(AESUtils.encrypt("root123456"));
|
||||
// System.out.println(AESUtils.decrypt("993f014869ca9314b5edcb80eca2eb1f"));
|
||||
// System.out.println(AESUtils.encrypt("13662780023"));
|
||||
//// 'spring.datasource.username=ENC(O1BQh3ko5C6HZslX7Mi6Yw==)\nspring.datasource.password=ENC(TJU64ImcZASn8YLoEFQLOA==)';
|
||||
// System.out.println(AESUtils.encrypt("13543507408"));
|
||||
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
|
||||
//加密所需的salt
|
||||
textEncryptor.setPassword("wwqYunxi");
|
||||
System.out.println("用户===》"+textEncryptor.decrypt("qaa0BOUMC69RlSjW1EBYjg=="));
|
||||
System.out.println("密码===》"+textEncryptor.decrypt("5l0HQCNMy2H5gLhLP3NwcI/F4Q7uI1d+qE14OoS2LdQtxV0VPgvINj0Oh69MPW8SEt/KLbld+yQ="));
|
||||
System.out.println("用户===》"+textEncryptor.encrypt("root"));
|
||||
System.out.println("密码===》"+textEncryptor.encrypt("KKOwmQr4JjY6eFPeLZ/dpzxESv+Bb8uQTNYCKyPV"));
|
||||
|
||||
//org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fukajinSchedule': Unsatisfied dependency expressed through field 'ssmRechargeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ssmRechargeServiceImpl': Unsatisfied dependency expressed through field 'ssmStoreMemberService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ssmStoreMemberServiceImpl': Unsatisfied dependency expressed through field 'quartzManage'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quartzManage': Unsatisfied dependency expressed through field 'scheduler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduler' defined in class path resource [com/ssm/config/QuartzConfig.class]: Invocation of init method failed; nested exception is org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'quartzDS': java.sql.SQLException: Connections could not be acquired from the underlying database! [See nested exception: java.sql.SQLException: Connections could not be acquired from the underlying database!]
|
||||
// at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
|
||||
// at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
|
||||
// at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
|
||||
// at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378)
|
||||
// at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
|
||||
// at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
|
||||
// at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
//package com.ssm.core.util;
|
||||
//
|
||||
//import org.apache.ibatis.plugin.Interceptor;
|
||||
//import org.apache.ibatis.plugin.Invocation;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.Properties;
|
||||
//
|
||||
//@Component
|
||||
//public class MybatisInterceptor implements Interceptor {
|
||||
// @Override
|
||||
// public Object intercept(Invocation invocation) throws Throwable {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Object plugin(Object target) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setProperties(Properties properties) {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ssm.core.util;
|
||||
|
||||
import com.ssm.manage.entity.RechargeAccount;
|
||||
import com.ssm.manage.service.SsmBaseStoreService;
|
||||
import com.ssm.manage.service.SsmRechargeAccountService;
|
||||
import com.ssm.manage.service.impl.SsmRechargeAccountServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class text {
|
||||
public static void main(String[] args) {
|
||||
SsmRechargeAccountService ssmRechargeAccountService = new SsmRechargeAccountServiceImpl();
|
||||
List<Long> longs = Arrays.asList(347470857126223872L, 347158924979441664L);
|
||||
List<RechargeAccount> rechargeAccountList = ssmRechargeAccountService.selectByPrimaryKeyList(longs);
|
||||
System.out.println(rechargeAccountList.size());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
SsmBaseStoreService ssmBaseStoreService;
|
||||
|
||||
|
||||
public void test(){
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
//package com.ssm.filter;
|
||||
//import com.ssm.manage.entity.SmsException;
|
||||
//import com.ssm.manage.response.ResponseCode;
|
||||
//import org.apache.ibatis.executor.Executor;
|
||||
//import org.apache.ibatis.mapping.MappedStatement;
|
||||
//import org.apache.ibatis.plugin.*;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.Properties;
|
||||
//
|
||||
//@Intercepts({
|
||||
// @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
|
||||
//})
|
||||
//@Component
|
||||
//public class DeleteInterceptor implements Interceptor {
|
||||
//
|
||||
// @Override
|
||||
// public Object intercept(Invocation invocation) throws Throwable {
|
||||
// Object[] args = invocation.getArgs();
|
||||
// MappedStatement mappedStatement = (MappedStatement) args[0];
|
||||
// Object parameterObject = args[1];
|
||||
// // 判断是否为DELETE操作
|
||||
// if (mappedStatement.getSqlCommandType().name().equals("DELETE")) {
|
||||
// // 判断参数是否为空
|
||||
// if (parameterObject == null) {
|
||||
// throw new SmsException(ResponseCode.MSG,"删除条件不能为空");
|
||||
// }
|
||||
// // 可根据具体情况判断参数类型或其他条件
|
||||
// // 进行其他处理,如记录日志等
|
||||
// }
|
||||
// // 执行原始的方法
|
||||
// return invocation.proceed();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Object plugin(Object target) {
|
||||
// return Plugin.wrap(target, this);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setProperties(Properties properties) {
|
||||
// // 可以在配置文件中配置一些属性,进行初始化设置
|
||||
// }
|
||||
//}
|
||||
//
|
||||
@ -0,0 +1,235 @@
|
||||
package com.ssm.filter;
|
||||
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.ssm.manage.response.*;
|
||||
import com.ssm.manage.service.SsmSysRolePowerService;
|
||||
import com.ssm.manage.utils.Constant;
|
||||
import com.ssm.manage.utils.SessionHelp;
|
||||
import com.ssm.manage.utils.StringUtils;
|
||||
import com.ssm.util.RedisClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@Slf4j
|
||||
//@Component
|
||||
public class LoginInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private RedisClient<UserResponse> redisClient;
|
||||
|
||||
private static final ThreadLocal<StaffResponse> threadLocal = new ThreadLocal<>();
|
||||
|
||||
@Autowired
|
||||
private RedisClient<StaffResponse> staffResponseRedisClient;
|
||||
@Autowired
|
||||
private RedisClient<StaffTemporaryVo> staffTemporaryVoRedisClient;
|
||||
|
||||
@Autowired
|
||||
private RedisClient<MemberResponse> memberResponseRedisClient;
|
||||
|
||||
@Autowired
|
||||
private SsmSysRolePowerService ssmSysRolePowerService;
|
||||
|
||||
private static String STAFF_KEY = "staffKey";
|
||||
private static String USER_KEY = "userKey";
|
||||
private static String MEMBER_KEY = "memberKey";
|
||||
public static String hduserKey = "hduserKey";
|
||||
|
||||
|
||||
@Override
|
||||
public boolean preHandle(@NotNull HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String clientIP = ServletUtil.getClientIP(request);
|
||||
|
||||
StringBuffer requestURL = request.getRequestURL();
|
||||
if (requestURL.toString().contains("error") || requestURL.toString().contains("swagger")) {
|
||||
return true;
|
||||
}
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
String cacheToken = SessionHelp.getToken(session);
|
||||
String loginAccount = SessionHelp.getLoginAccount(session);
|
||||
String token = request.getHeader("token");
|
||||
|
||||
// //判断session中是否有登录信息
|
||||
// if (StringUtils.isNotBlank(loginAccount) && StringUtils.isNotBlank(token) && token.equals(cacheToken)) {
|
||||
// return true;
|
||||
// }
|
||||
if (StringUtils.isBlank(token)){
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = null;
|
||||
GenericResponse genericResponse = new GenericResponse();
|
||||
genericResponse.setCodeAndMsg(ResponseCode.TOKEN_IS_EXPIRED);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.append(gson.toJson(genericResponse));
|
||||
} catch (Exception e) {
|
||||
log.error("LoginInterceptor.preHandle", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
//根据token去做验证
|
||||
if (redisClient.hasKey(USER_KEY + loginAccount)){
|
||||
UserResponse userResponse = redisClient.get(USER_KEY + loginAccount);
|
||||
cacheToken = userResponse.getToken();
|
||||
if (StringUtils.isNotBlank(cacheToken) && cacheToken.equals(token)){
|
||||
return true;
|
||||
}else {
|
||||
//同一个账户 当前请求token和redis中最新的token不一致 销毁当前Session
|
||||
session.invalidate();
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = null;
|
||||
GenericResponse genericResponse = new GenericResponse();
|
||||
genericResponse.setCodeAndMsg(ResponseCode.TOKEN_IS_EXPIRED);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.append(gson.toJson(genericResponse));
|
||||
} catch (Exception e) {
|
||||
log.error("LoginInterceptor.preHandle", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (staffResponseRedisClient.hasKey(STAFF_KEY + loginAccount)){
|
||||
StaffResponse staffResponse = staffResponseRedisClient.get(STAFF_KEY + loginAccount);
|
||||
cacheToken = staffResponse.getToken();
|
||||
if (StringUtils.isNotBlank(cacheToken) && cacheToken.equals(token)){
|
||||
threadLocal.set(staffResponse);
|
||||
return true;
|
||||
}else {
|
||||
//同一个账户 当前请求token和redis中最新的token不一致 销毁当前Session
|
||||
session.invalidate();
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = null;
|
||||
GenericResponse genericResponse = new GenericResponse();
|
||||
genericResponse.setCodeAndMsg(ResponseCode.TOKEN_IS_EXPIRED);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.append(gson.toJson(genericResponse));
|
||||
} catch (Exception e) {
|
||||
log.error("LoginInterceptor.preHandle", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (memberResponseRedisClient.hasKey(MEMBER_KEY + loginAccount)){
|
||||
MemberResponse memberResponse = memberResponseRedisClient.get(MEMBER_KEY + loginAccount);
|
||||
cacheToken = memberResponse.getToken();
|
||||
if (StringUtils.isNotBlank(cacheToken) && cacheToken.equals(token)){
|
||||
return true;
|
||||
}else {
|
||||
//同一个账户 当前请求token和redis中最新的token不一致 销毁当前Session
|
||||
session.invalidate();
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = null;
|
||||
GenericResponse genericResponse = new GenericResponse();
|
||||
genericResponse.setCodeAndMsg(ResponseCode.TOKEN_IS_EXPIRED);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.append(gson.toJson(genericResponse));
|
||||
} catch (Exception e) {
|
||||
log.error("LoginInterceptor.preHandle", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (staffTemporaryVoRedisClient.hasKey(Constant.staffTemporary + token)){
|
||||
StaffTemporaryVo staffTemporaryVo = staffTemporaryVoRedisClient.get(Constant.staffTemporary + token);
|
||||
cacheToken = staffTemporaryVo.getToken();
|
||||
if (StringUtils.isNotBlank(cacheToken) && cacheToken.equals(token)){
|
||||
return true;
|
||||
}else {
|
||||
//同一个账户 当前请求token和redis中最新的token不一致 销毁当前Session
|
||||
session.invalidate();
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = null;
|
||||
GenericResponse genericResponse = new GenericResponse();
|
||||
genericResponse.setCodeAndMsg(ResponseCode.TOKEN_IS_EXPIRED);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.append(gson.toJson(genericResponse));
|
||||
} catch (Exception e) {
|
||||
log.error("LoginInterceptor.preHandle", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
PrintWriter out = null;
|
||||
GenericResponse genericResponse = new GenericResponse();
|
||||
genericResponse.setCodeAndMsg(ResponseCode.NOT_LOGIN);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.append(gson.toJson(genericResponse));
|
||||
} catch (Exception e) {
|
||||
log.error("LoginInterceptor.preHandle", e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
// 提供一个静态方法来获取当前线程中的用户信息
|
||||
public static StaffResponse getCurrentUserInfo() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
public static void clearThreadLocal() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
//package com.ssm.filter;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.web.servlet.HandlerInterceptor;
|
||||
//import org.springframework.web.servlet.ModelAndView;
|
||||
//
|
||||
//import javax.servlet.ServletOutputStream;
|
||||
//import javax.servlet.WriteListener;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import javax.servlet.http.HttpServletResponseWrapper;
|
||||
//import java.io.ByteArrayOutputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.io.OutputStreamWriter;
|
||||
//import java.io.PrintWriter;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.nio.charset.StandardCharsets;
|
||||
//
|
||||
//@Slf4j
|
||||
//public class ResponseInterceptor implements HandlerInterceptor {
|
||||
// private static ThreadLocal<ByteArrayOutputStream> bufferThreadLocal = new ThreadLocal<>();
|
||||
// @Override
|
||||
// public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
// ModelAndView modelAndView) throws Exception {
|
||||
// ByteArrayOutputStream buffer = bufferThreadLocal.get();
|
||||
// String responseBody = null;
|
||||
// if (buffer != null) {
|
||||
// responseBody = buffer.toString(response.getCharacterEncoding()).trim();
|
||||
// }
|
||||
//
|
||||
// // 在这里对响应数据进行处理
|
||||
//
|
||||
// // 输出响应数据(可选)
|
||||
// if (responseBody != null && !responseBody.isEmpty()) {
|
||||
// response.getWriter().write(responseBody);
|
||||
// }
|
||||
// log.error("拦截器生效了");
|
||||
// // 获取响应的输出流
|
||||
// }
|
||||
// @Override
|
||||
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
// // 创建缓冲区
|
||||
// bufferThreadLocal.set(new ByteArrayOutputStream());
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
// // 移除缓冲区
|
||||
// bufferThreadLocal.remove();
|
||||
// }
|
||||
//
|
||||
//}
|
||||
Loading…
Reference in New Issue