添加用户登陆、新增用户功能

后台菜单管理
省份地域管理
excel操作工具
sale
tianea 3 years ago
parent 3af22ea7dd
commit ec33e6fc92

@ -33,25 +33,7 @@
<version>3.17</version>
</dependency>
<!-- ECharts -->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>ECharts</artifactId>
<version>3.0.0.6</version>
</dependency>
<!-- jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.1</version>
</dependency>
<dependency>
<groupId>com.spring4all</groupId>

@ -22,6 +22,4 @@ public class SystemUtil {
}
public static final String PIC_PATH = getProperty("pic_path");
}

@ -0,0 +1,45 @@
package com.tz.platform.common.core.tools;
public class Constants {
private Constants() {
}
public final static String ADMIN = "admin";// admin
public final static Integer FREEZE = 3;// 冻结状态
public final static String REGEX_MOBILE = "^1[0-9]{10}$";
/**
* session
*
* @author wujing
*/
public interface Session {
public final static String BOSS_MENU = "BOSS_MENU";//
public final static String USER_NO = "USERNO"; // userno
public final static String USER_VO = "USERVO";// 不能使用user关键词
public final static String REAL_NAME = "REALNAME";//
}
/**
* cookie
*
* @author wujing
*/
public interface Cookie {
public final static String USER_TOKEN = "USERTOKEN";
}
/**
*
*
* @author wujing
*/
public interface DATE {
public final static String YYYYMMDD = "yyyyMMdd";
public final static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public final static String YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
public final static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public final static String YYYY_MM_DD = "yyyy-MM-dd";
}
}

@ -0,0 +1,414 @@
package com.tz.platform.common.core.tools;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
/**
*
*/
private DateUtil() {
}
/**
*
*
* @param format yyyy-MM-dd
* @param time 131380123456789
* @return (yyyy-MM-dd)
*/
public static String formatToString(String format, long time) {
if (time == 0) {
return "";
}
return new SimpleDateFormat(format).format(new Date(time));
}
/**
*
*
* @param format yyyy-MM-dd
* @return 13 (1380123456789)
*/
public static long formatToLong(String format) {
SimpleDateFormat f = new SimpleDateFormat(format);
return Timestamp.valueOf(f.format(new Date())).getTime();
}
/**
*
*
* @return yyyy (2016)
*/
public static int getYear() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.YEAR);
}
/**
*
*
* @return MM (06)
*/
public static String getMonth() {
Calendar cal = Calendar.getInstance();
return new DecimalFormat("00").format(cal.get(Calendar.MONTH));
}
/**
*
*
* @param dateStr String
* @param format String
* @return Date
*/
public static Date parseDate(String dateStr, String format) {
try {
DateFormat dateFormat = new SimpleDateFormat(format);
String dt = dateStr.replaceAll("-", "/");
dt = dateStr;
if ((!dt.equals("")) && (dt.length() < format.length())) {
dt += format.substring(dt.length()).replaceAll("[YyMmDdHhSs]", "0");
}
Date date = dateFormat.parse(dt);
return date;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
*
*
* @param dateStr String YYYY-MM-DD
* @return Date
*/
public static Date parseDate(String dateStr) {
return parseDate(dateStr, "yyyy-MM-dd");
}
/**
*
*
* @param date Date
* @param format String
* @return
*/
public static String format(Date date, String format) {
String result = "";
try {
if (date != null) {
DateFormat dateFormat = new SimpleDateFormat(format);
result = dateFormat.format(date);
}
} catch (Exception e) {
}
return result;
}
/**
*
*
* @param date Date
* @return
*/
public static String format(Date date) {
return format(date, "yyyy-MM-dd");
}
/**
*
*
* @param date Date
* @return
*/
public static int getYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.YEAR);
}
/**
*
*
* @param date Date
* @return
*/
public static int getMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.MONTH) + 1;
}
/**
*
*
* @param date Date
* @return
*/
public static int getDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_MONTH);
}
/**
*
*
* @param date
* @return
*/
public static int getHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.HOUR_OF_DAY);
}
/**
*
*
* @param date
* @return
*/
public static int getMinute(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.MINUTE);
}
/**
*
*
* @param date Date
* @return
*/
public static int getSecond(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.SECOND);
}
/**
*
*
* @param date
* @return
*/
public static long getMillis(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.getTimeInMillis();
}
/**
*
*
* @param date
* @return yyyy-MM-dd
*/
public static String getDate(Date date) {
return format(date, "yyyy-MM-dd");
}
/**
*
*
* @param date Date
* @return HH:mm:ss
*/
public static String getTime(Date date) {
return format(date, "HH:mm:ss");
}
/**
*
*
* @param date Date
* @return yyyy-MM-dd HH:mm:ss
*/
public static String getDateTime(Date date) {
return format(date, "yyyy-MM-dd HH:mm:ss");
}
/**
*
*
* @param date Date
* @param day int
* @return
*/
public static Date addDate(Date date, int day) {
Calendar calendar = Calendar.getInstance();
long millis = getMillis(date) + ((long) day) * 24 * 3600 * 1000;
calendar.setTimeInMillis(millis);
return calendar.getTime();
}
/**
*
*
* @param date
* @param year
* @return
*/
public static Date addYear(Date date, int year) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, 1);
return calendar.getTime();
}
/**
*
*
* @param date yyyy-MM-dd
* @param day int
* @return
* @throws ParseException
*/
public static String add(String date, int day) throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
long d = df.parse(date).getTime();
long millis = d + ((long) day) * 24 * 3600 * 1000;
return df.format(new Date(millis));
}
/**
*
*
* @param date Date
* @param date1 Date
* @return
*/
public static int diffDate(Date date, Date date1) {
return (int) ((getMillis(date) - getMillis(date1)) / (24 * 3600 * 1000));
}
/**
*
*
* @param strdate String
* @return String yyyy-MM-dd
*/
public static String getMonthBegin(String strdate) {
Date date = parseDate(strdate);
return format(date, "yyyy-MM") + "-01";
}
/**
*
*
* @param strdate String
* @return String yyyy-MM-dd
*/
public static String getMonthEnd(String strdate) {
Date date = parseDate(getMonthBegin(strdate));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, 2);
calendar.add(Calendar.DAY_OF_YEAR, -1);
return formatDate(calendar.getTime());
}
/**
*
*
* @param date Date
* @return String yyyy-MM-dd
*/
public static String formatDate(Date date) {
return formatDateByFormat(date, "yyyy-MM-dd");
}
/**
*
*
* @param date Date
* @param format String
* @return String
*/
public static String formatDateByFormat(Date date, String format) {
String result = "";
if (date != null) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
result = sdf.format(date);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return result;
}
/**
*
*
* @param beginDate yyy-MM-dd
* @param endDate yyy-MM-dd
* @return
* @throws ParseException
*/
public static int getDay(String beginDate, String endDate) throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
long to = df.parse(endDate).getTime();
long from = df.parse(beginDate).getTime();
return (int) ((to - from) / (1000 * 60 * 60 * 24));
}
/**
*
*
* @param startYear yyy-MM-dd
* @param endYear yyy-MM-dd
* @return
*/
public static int yearDateDiff(String startYear, String endYear) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar startDate = Calendar.getInstance();
Calendar endDate = Calendar.getInstance();
try {
startDate.setTime(sdf.parse(startYear));
endDate.setTime(sdf.parse(endYear));
} catch (Exception ex) {
ex.printStackTrace();
}
return (endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR));
}
/**
*
*
* @return
*/
public static DateTime lastMonth() {
return offsetMonth(new DateTime(), -1);
}
/**
*
*
* @param date
* @param offset
* @return
*/
public static DateTime offsetMonth(Date date, int offset) {
return offset(date, DateField.MONTH, offset);
}
public static DateTime offset(Date date, DateField dateField, int offset) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(dateField.getValue(), offset);
return new DateTime(cal.getTime());
}
}

@ -0,0 +1,478 @@
package com.tz.platform.common.core.tools;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.util.StringUtils;
import java.awt.*;
import java.awt.Color;
import java.io.*;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ExcelUtil {
private String templatePath ;
private String outPath;
private FileInputStream is;
private XSSFWorkbook excel ;
//获取第一个sheet
private XSSFSheet sheet0 ;
private Font defaultFont;
private CellStyle cellStyle;
private CellStyle numStyle ;
public ExcelUtil(){
initNumStyle();
}
public ExcelUtil(String template,String out) throws Exception{
this.templatePath = template;
is = new FileInputStream(templatePath);
excel = new XSSFWorkbook(is);
defaultFont = excel.createFont();
((XSSFFont) defaultFont).setColor(new XSSFColor(new Color(0,0,0)));
cellStyle = excel.createCellStyle();
cellStyle.setFont(defaultFont);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
initNumStyle();
//获取第一个sheet
sheet0 = excel.getSheetAt(0);
outPath = out;
}
public ExcelUtil(InputStream fileInputStream) throws Exception{
excel = new XSSFWorkbook(fileInputStream);
sheet0 = excel.getSheetAt(0);
}
public int getLastRowNum(){
return this.sheet0.getLastRowNum();
}
private void initNumStyle(){
if(excel!=null){
numStyle = excel.createCellStyle();
XSSFDataFormat df = excel.createDataFormat();//此处设置数据格式  
numStyle.setDataFormat(df.getFormat("#,#0.000")); //小数点后保留两位可以写contentStyle.setDataFormat(df.getFormat("#,#0.00"));
}
}
public ExcelUtil(String template,String out,int sheetIndex) throws Exception{
this.templatePath = template;
is = new FileInputStream(templatePath);
excel = new XSSFWorkbook(is);
//获取第一个sheet
sheet0 = excel.getSheetAt(sheetIndex);
outPath = out;
}
public void CreateExcel(java.util.List datas, ExcelHeader[] headers, String fileName, String sheetName){
if(excel == null){
excel = new XSSFWorkbook();
}
XSSFWorkbook workbook =excel;
XSSFSheet sheet = workbook.createSheet(sheetName);
int rowNum = 0;
// System.out.println("Creating excel");
int colNum = 0;
Row rowHeader = sheet.createRow(0);
for(ExcelHeader header :headers){
Cell cell = rowHeader.createCell(colNum++);
cell.setCellValue(header.getAliax());
}
rowNum=1;
colNum=0;
appendDataToExcel(sheet,datas,rowNum,colNum,headers);
String filePath = fileName;
outPath =filePath;
}
public Row getRow(int rowNo){
Row row = sheet0.getRow(rowNo);
if(row==null){
row = sheet0.createRow(rowNo);
}
return row;
}
public Row getRow(XSSFSheet sheet,int rowNo){
Row row = sheet.getRow(rowNo);
if(row==null){
row = sheet.createRow(rowNo);
}
return row;
}
public void setRichValue(String location,String value,int start,int end){
Cell cell = get("A21");
System.out.println(cell.getStringCellValue());
Font font = excel.createFont();
font.setBold(true);
((XSSFFont) font).setColor(new XSSFColor(new Color(0,0,0)));
XSSFRichTextString richTextString1 = new XSSFRichTextString(value);
richTextString1.applyFont(start,end,font);
cell.setCellValue(richTextString1);
}
public Cell getCell(Row row, int cNo){
Cell cell = row.getCell(cNo);
if(cell == null ) {
cell = row.createCell(cNo);
}
return cell;
}
public Cell getCell(int rowNo,int colNo){
Row row = getRow(rowNo);
return getCell(row,colNo);
}
public void setValue(String location,Object value){
Cell cell = get(location);
setCellValue(cell,value);
}
public void setValue(String location,Object value,String formula){
Cell cell = get(location);
cell.setCellValue(formula);
setCellValue(cell,value);
}
public void setFormula(String location,String formula){
Cell cell = get(location);
cell.setCellFormula(formula);
}
public Cell get(String location){
Pattern pattern = Pattern.compile("([A-Z]+)(\\d+)");
Matcher matcher = pattern.matcher(location.toUpperCase());
if(matcher.matches()){
String y = matcher.group(1);
String x = matcher.group(2);
int rowNum = coverToXIndex(x);
int colNum = covertToYIndex(y);
Row row = getRow(rowNum);
return getCell(row,colNum);
}
return null;
}
private int coverToXIndex(String x){
return Integer.parseInt(x)-1;
}
private int covertToYIndex(String y){
int result = 0;
for(int i = y.length()-1;i>=0;i--){
char c = y.charAt(i);
int power = ((y.length()-1)-i);
if(power>0){
result +=(c-'A'+1)*Math.pow(26,power);
}else{
result +=(c-'A');
}
}
return result;
}
public void appendDataToExcel(XSSFSheet sheet, java.util.List datas, int rowNo, int colNo, ExcelHeader[] headers){
if(sheet==null){
return;
}
try {
for(int r = 0;r<datas.size();r++){
Row row = getRow(sheet,rowNo+r);
Object t = datas.get(r);
Class tClass = t.getClass();
Field[] fields =tClass.getDeclaredFields();
if(headers!=null){
for(int c=0;c<headers.length;c++){
Cell cell =getCell(row,c+colNo);
if(cell == null){
cell = row.createCell(c+colNo);
}
ExcelHeader header = headers[c];
Field f = Arrays.stream(fields).filter(field -> field.getName().equals(header.name)).findFirst().orElse(null);
f.setAccessible(true);
Object v = f.get(t);
setCellValue(cell, v);
}
}else{
for(int c = 0;c<fields.length;c++){
Cell cell = getCell(row,c+colNo);
Field f = fields[c];
f.setAccessible(true);
Object v = f.get(t);
setCellValue(cell, v);
}
}
}
}catch (Exception ex){
}
}
public void appendDataToExcel(int sheetIndex, java.util.List datas, int rowNo, int colNo, ExcelHeader[] headers){
XSSFSheet sheet = excel.getSheetAt(sheetIndex);
if(sheet == null ) {return ;}
appendDataToExcel(sheet,datas,rowNo,colNo,headers);
}
public void appendDataToExcel(List datas, int rowNo, int colNo, ExcelHeader[] headers){
appendDataToExcel(sheet0,datas,rowNo,colNo,headers);
}
public void setValue(int rowNo,int columNo,Object value){
Row row =getRow(rowNo);
Cell cell = getCell(row,columNo);
// if(isMerged(rowNo,columNo)){
// System.out.println( getMergedRegionValue(rowNo,columNo));
// setCellValue(cell,value);
// }else{
setCellValue(cell,value);
// }
}
public boolean isMerged(int row,int column){
int sheetMergeCount = sheet0.getNumMergedRegions();
for (int i = 0; i < sheetMergeCount; i++) {
CellRangeAddress range = sheet0.getMergedRegion(i);
int firstColumn = range.getFirstColumn();
int lastColumn = range.getLastColumn();
int firstRow = range.getFirstRow();
int lastRow = range.getLastRow();
if(row == firstRow && row == lastRow){
if(column >= firstColumn && column <= lastColumn){
return true;
}
}
}
return false;
}
public String getMergedRegionValue(int row , int column){
int sheetMergeCount = sheet0.getNumMergedRegions();
for(int i = 0 ; i < sheetMergeCount ; i++){
CellRangeAddress ca = sheet0.getMergedRegion(i);
int firstColumn = ca.getFirstColumn();
int lastColumn = ca.getLastColumn();
int firstRow = ca.getFirstRow();
int lastRow = ca.getLastRow();
if(row >= firstRow && row <= lastRow){
if(column >= firstColumn && column <= lastColumn){
Row fRow = sheet0.getRow(firstRow);
Cell fCell = fRow.getCell(firstColumn);
return getCellValue(fCell) ;
}
}
}
return null ;
}
/**
*
* @param cell
* @return
*/
public String getCellValue(Cell cell){
if(cell == null) {return "";}
if(cell.getCellType() == Cell.CELL_TYPE_STRING){
return cell.getStringCellValue();
}else if(cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){
return String.valueOf(cell.getBooleanCellValue());
}else if(cell.getCellType() == Cell.CELL_TYPE_FORMULA){
return cell.getCellFormula() ;
}else if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
String dateTime = getDateTime(cell);
if(StringUtils.isEmpty(dateTime)){
return String.valueOf(cell.getNumericCellValue());
}
return dateTime;
}
return "";
}
private String getDateTime(Cell cell){
String result = "";
//1、判断是否是数值格式
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
short format = cell.getCellStyle().getDataFormat();
SimpleDateFormat sdf = null;
if(format == 14 || format == 31 || format == 57 || format == 58){
//日期
sdf = new SimpleDateFormat("yyyy-MM-dd");
}else if (format == 20 || format == 32) {
//时间
sdf = new SimpleDateFormat("HH:mm");
}else if(format == 176){
sdf =new SimpleDateFormat("yyyy/MM/dd");
}else{
return "";
}
double value = cell.getNumericCellValue();
Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value);
result = sdf.format(date);
}
return result;
}
public boolean save(){
if(WriteExcel(excel,outPath)){
excel = null;
return true;
}
return false;
}
private boolean WriteExcel(XSSFWorkbook workbook,String filePath){
try {
if(filePath==null) {return false;}
FileOutputStream outputStream = new FileOutputStream(filePath);
workbook.write(outputStream);
workbook.close();
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
private void setCellValue(Cell cell , Object value){
cell.setCellStyle(cellStyle);
if(value instanceof String){
cell.setCellValue((String) value);
}else if(value instanceof Integer){
cell.setCellValue((Integer)value);
}else if(value instanceof Float){
cell.setCellValue((Float) value);
}else if(value instanceof Double){
cell.setCellValue((Double)value);
}else if(value instanceof BigDecimal){
BigDecimal tmp = ((BigDecimal) value).abs();
if(numStyle==null){
initNumStyle();
}
cell.setCellStyle(numStyle);
cell.setCellValue(tmp.doubleValue());
}
}
public class ExcelHeader{
String name;
String aliax;
ParserValue parserValue;
public ExcelHeader(String name,String aliax,ParserValue... pv){
this.name = name;
this.aliax = aliax;
if(pv!=null&&pv.length>0){
this.parserValue = pv[0];
}
}
/**
*
* @return
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
*
* @return
*/
public String getAliax() {
return aliax;
}
public void setAliax(String aliax) {
this.aliax = aliax;
}
/**
*
* @return
*/
public ParserValue getParserValue() {
return parserValue;
}
public void setParserValue(ParserValue parserValue) {
this.parserValue = parserValue;
}
}
@FunctionalInterface
public interface ParserValue{
String parser(Object object);
}
}

@ -14,8 +14,8 @@ import java.util.Date;
public class JWTUtil {
protected static final Logger logger = LoggerFactory.getLogger(JWTUtil.class);
private static final String TOKEN_SECRET = "eyJhbGciOiJIUzI1NiJ9";
private static final String ISSUER = "RONCOO";
private static final String TOKEN_SECRET = "ekfyJhciOiJfkIUzI1J9";
private static final String ISSUER = "TIANZE";
public static final String USERNO = "userNo";
public static final Long DATE = 30 * 24 * 3600 * 1000L; // 1个月

@ -0,0 +1,22 @@
package com.tz.platform.common.core.tools;
import cn.hutool.core.util.RandomUtil;
import java.util.Date;
public class NOUtil {
private NOUtil() {
}
public static Long getOrderNo() {
return Long.valueOf(DateUtil.format(new Date(), Constants.DATE.YYYYMMDDHHMMSS) + RandomUtil.randomNumbers(3));
}
public static Long getSerialNumber() {
return Long.valueOf(DateUtil.format(new Date(), Constants.DATE.YYYYMMDDHHMMSS) + RandomUtil.randomNumbers(4));
}
public static Long getUserNo() {
return Long.valueOf(DateUtil.format(new Date(), Constants.DATE.YYYYMMDDHHMMSS) + RandomUtil.randomNumbers(2));
}
}

@ -0,0 +1,34 @@
package com.tz.platform.common.core.tools;
import cn.hutool.core.util.IdUtil;
import java.util.Random;
public class StrUtil {
private StrUtil() {
}
public static String getSuffix(String fileName) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
}
public static String getPrefix(String fileName) {
return fileName.substring(0, fileName.lastIndexOf("."));
}
/**
* @return
*/
public static String getRandom(int bound) {
Random ra = new Random();
String result = "";
for (int i = 1; i <= bound; i++) {
result += ra.nextInt(10);
}
return result;
}
public static String get32UUID() {
return IdUtil.simpleUUID();
}
}

@ -55,6 +55,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>

@ -42,7 +42,7 @@ import java.util.stream.Collectors;
public class TzGlobalFilter implements GlobalFilter {
private static final Logger logger = LoggerFactory.getLogger(TzGlobalFilter.class);
private static final String TOKEN = "token";
private static final String TOKEN = "tz_token";
private static final String USERNO = "userNo";
@Autowired
@ -93,11 +93,41 @@ public class TzGlobalFilter implements GlobalFilter {
return false;
}
private String getRemoteIp(ServerHttpRequest request){
HttpHeaders headers = request.getHeaders();
String ip = headers.getFirst("x-forwarded-for");
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个ip值第一个ip才是真实ip
if (ip.indexOf(",") != -1) {
ip = ip.split(",")[0];
}
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = headers.getFirst("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = headers.getFirst("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = headers.getFirst("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = headers.getFirst("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = headers.getFirst("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddress().getAddress().getHostAddress();
}
return ip;
}
private Mono<String> modifiedBody(ServerWebExchange serverWebExchange, Long userNo) {
MediaType mediaType = serverWebExchange.getRequest().getHeaders().getContentType();
ServerRequest serverRequest = ServerRequest.create(serverWebExchange, HandlerStrategies.withDefaults().messageReaders());
// String ip = getRemoteIp(serverWebExchange.getRequest());
return serverRequest.bodyToMono(String.class).flatMap(body -> {
JSONObject bodyJson;
if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) {
@ -109,6 +139,7 @@ public class TzGlobalFilter implements GlobalFilter {
if (ObjectUtil.isNotNull(userNo)) {
bodyJson.set(USERNO, userNo);
}
// bodyJson.set("ip",ip);
return Mono.just(JSONUtil.toJsonStr(bodyJson));
});
}

@ -0,0 +1,22 @@
package com.tz.platform.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
@Data
public class Menu {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String title;
private String icon;
private Integer parentId;
}

@ -0,0 +1,18 @@
package com.tz.platform.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
@Data
public class Province {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String name;
private Integer regionId;
}

@ -0,0 +1,18 @@
package com.tz.platform.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
@Entity
@Data
public class Region implements Serializable {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String name;
}

@ -1,11 +1,15 @@
package com.tz.platform.entity;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "user")
public class User {
@Data
public class User implements Serializable {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@ -21,81 +25,24 @@ public class User {
private String mobile;
private String userName;
private String username;
private String studentNo;
private String mobileSalt;
private String mobilePsw;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
public Integer getStatusId() {
return statusId;
}
public void setStatusId(Integer statusId) {
this.statusId = statusId;
}
public Long getUserNo() {
return userNo;
}
public void setUserNo(Long userNo) {
this.userNo = userNo;
}
private String school;
public String getMobile() {
return mobile;
}
private String name;
public void setMobile(String mobile) {
this.mobile = mobile == null ? null : mobile.trim();
}
private String mobileSalt;
public String getMobileSalt() {
return mobileSalt;
}
private String mobilePsw;
public void setMobileSalt(String mobileSalt) {
this.mobileSalt = mobileSalt == null ? null : mobileSalt.trim();
}
private Integer userType;
public String getMobilePsw() {
return mobilePsw;
}
private String avatar;
public void setMobilePsw(String mobilePsw) {
this.mobilePsw = mobilePsw == null ? null : mobilePsw.trim();
}
private static final long serialVersionUID = 1L;
@Override
public String toString() {

@ -0,0 +1,9 @@
package com.tz.platform.repository;
import com.tz.platform.entity.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface MenuDao extends JpaRepository<Menu,Integer> {
}

@ -0,0 +1,9 @@
package com.tz.platform.repository;
import com.tz.platform.entity.Province;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ProvinceDao extends JpaRepository<Province,Integer> {
}

@ -0,0 +1,9 @@
package com.tz.platform.repository;
import com.tz.platform.entity.Region;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface RegionDao extends JpaRepository<Region,Integer> {
}

@ -1,10 +1,31 @@
package com.tz.platform.repository;
import com.tz.platform.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserDao extends JpaRepository<User,Long> {
/**
*
* @param mobile
* @return
*/
User findByMobile(String mobile);
/**
*
* @param username
* @return
*/
User getByUsername(String username);
/**
*
* @param pageable
* @return
*/
Page<User> findAll(Pageable pageable);
}

@ -1,24 +1,45 @@
package com.tz.platform.user.api;
import com.tz.platform.common.core.base.BaseController;
import com.tz.platform.common.core.base.Result;
import com.tz.platform.entity.User;
import com.tz.platform.repository.UserDao;
import com.tz.platform.user.api.biz.ApiUserInfoBiz;
import com.tz.platform.user.api.bo.UserLoginPasswordBO;
import com.tz.platform.user.api.dto.UserInfoDTO;
import com.tz.platform.user.api.dto.UserLoginDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(path = "/api/user")
public class UserInfoController {
public class UserInfoController extends BaseController {
@Autowired
UserDao userDao;
@Autowired
ApiUserInfoBiz apiUserInfoBiz;
@GetMapping(path = "test")
public String test(){
List<User> userList = userDao.findAll();
return "user count:"+userList.size();
}
@PostMapping(path = "login")
public Result<UserLoginDTO> loginPassword(@RequestBody UserLoginPasswordBO userLoginPasswordBO){
log(userLoginPasswordBO);
return apiUserInfoBiz.loginPassword(userLoginPasswordBO);
}
@GetMapping(path = "info")
public Result<UserInfoDTO> info(){
UserInfoDTO userInfoDTO = new UserInfoDTO();
return Result.success(userInfoDTO);
}
}

@ -0,0 +1,130 @@
package com.tz.platform.user.api.biz;
import cn.hutool.crypto.digest.DigestUtil;
import com.tz.platform.common.core.base.Result;
import com.tz.platform.common.core.enmus.UserTypeEnum;
import com.tz.platform.common.core.tools.JWTUtil;
import com.tz.platform.common.core.tools.StrUtil;
import com.tz.platform.entity.User;
import com.tz.platform.repository.UserDao;
import com.tz.platform.user.api.bo.UserLoginPasswordBO;
import com.tz.platform.user.api.bo.UserRegisterBO;
import com.tz.platform.user.api.dto.UserLoginDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.io.File;
@Component
public class ApiUserInfoBiz {
@Autowired
private UserDao userDao;
@Autowired
private RedisTemplate<String, String> redisTemplate;
/**
*
* @param userRegisterBO
* @return
*/
@Transactional
public Result<UserLoginDTO> register(UserRegisterBO userRegisterBO) {
if (StringUtils.isEmpty(userRegisterBO.getUserName())) {
return Result.error("用户名不能为空");
}
if (StringUtils.isEmpty(userRegisterBO.getPassword())) {
return Result.error("密码不能为空");
}
// 手机号重复校验
User user = userDao.getByUsername(userRegisterBO.getUserName());
if (null != user) {
return Result.error("该用户已经注册,请更换手用户名");
}
// 用户注册
// 用户基本信息
user = reg(userRegisterBO);
UserLoginDTO dto = new UserLoginDTO();
dto.setUserNo(user.getId());
dto.setUsername(user.getUsername());
dto.setToken(JWTUtil.create(user.getId(), JWTUtil.DATE));
return Result.success(dto);
}
public User reg(UserRegisterBO bo){
User user = new User();
user.setUsername(bo.getUserName());
user.setStudentNo(bo.getStudentNo());
user.setSchool(bo.getSchool());
user.setMobileSalt(StrUtil.get32UUID());
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + bo.getPassword()));
user.setUserType(UserTypeEnum.USER.getCode());
user = userDao.save(user);
return user;
}
/**
*
* @param file
* @return
*/
public int batchImportUser(File file){
return 0;
}
/**
*
* @param userLoginPasswordBO
* @return
*/
public Result<UserLoginDTO> loginPassword(UserLoginPasswordBO userLoginPasswordBO){
if (StringUtils.isEmpty(userLoginPasswordBO.getUsername())) {
return Result.error("用户名不能为空");
}
if (StringUtils.isEmpty(userLoginPasswordBO.getPassword())) {
return Result.error("密码不能为空");
}
// 密码错误次数校验
// 用户校验
User user = userDao.getByUsername(userLoginPasswordBO.getUsername());
if (null == user) {
return Result.error("账号或者密码不正确");
}
// 密码校验
if (!DigestUtil.sha1Hex(user.getMobileSalt() + userLoginPasswordBO.getPassword()).equals(user.getMobilePsw())) {
// 放入缓存,错误次数+1
return Result.error("账号或者密码不正确");
}
// 登录日志
// loginLog(user.getUserNo(), userLoginPasswordBO.getClientId(), LoginStatusEnum.SUCCESS, userLoginPasswordBO.getIp());
UserLoginDTO dto = new UserLoginDTO();
dto.setUserNo(user.getId());
dto.setUsername(user.getUsername());
dto.setToken(JWTUtil.create(user.getId(), JWTUtil.DATE));
// 登录成功,存入缓存,单点登录使用
// redisTemplate.opsForValue().set(dto.getUserNo().toString(), dto.getToken(), 1, TimeUnit.DAYS);
return Result.success(dto);
}
}

@ -1,20 +0,0 @@
package com.tz.platform.user.api.biz;
import com.tz.platform.common.core.base.Result;
import com.tz.platform.repository.UserDao;
import com.tz.platform.user.api.bo.UserLoginPasswordBO;
import com.tz.platform.user.api.dto.UserLoginDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class apiUserInfoBiz {
@Autowired
private UserDao userDao;
public Result<UserLoginDTO> loginPassword(UserLoginPasswordBO userLoginPasswordBO){
UserLoginDTO userLoginDTO = new UserLoginDTO();
return Result.success(userLoginDTO);
}
}

@ -15,18 +15,13 @@ public class UserLoginPasswordBO implements Serializable {
/**
*
*/
@ApiModelProperty(value = "手机号", required = true)
private String mobile;
@ApiModelProperty(value = "用户名", required = true)
private String username;
/**
*
*/
@ApiModelProperty(value = "密码", required = true)
private String password;
/**
* clientId
*/
@ApiModelProperty(value = "clientId", required = true)
private String clientId;
private String ip;
}

@ -0,0 +1,42 @@
package com.tz.platform.user.api.bo;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class UserRegisterBO implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@ApiModelProperty(value = "用户名", required = true)
private String userName;
/**
*
*/
@ApiModelProperty(value = "密码", required = true)
private String password;
/**
*
*/
@ApiModelProperty(value="学号")
private String studentNo;
@ApiModelProperty(value = "学校")
private String school;
@ApiModelProperty(value = "ip地址")
private String ip;
}

@ -0,0 +1,17 @@
package com.tz.platform.user.api.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class UserInfoDTO implements Serializable {
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "头像")
private String avatar;
}

@ -22,8 +22,8 @@ public class UserLoginDTO implements Serializable {
/**
*
*/
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "用户名")
private String username;
/**
* token1
*/

@ -0,0 +1,21 @@
package com.tz.platform.user.pc.biz;
import com.tz.platform.entity.User;
import com.tz.platform.repository.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
@Component
public class PcUserInfoBiz {
@Autowired
private UserDao userDao;
public Page<User> listPage(Integer pageNo){
Pageable pageable = PageRequest.of(pageNo,20);
Page<User> userPage = userDao.findAll(pageable);
return userPage;
}
}

@ -19,7 +19,6 @@ public class UserRepositoryTest {
user.setMobile("18600024112");
user.setMobileSalt("");
user.setMobilePsw("11111111");
user.setUserSource("1123123");
userDao.save(user);
}

@ -0,0 +1,29 @@
package com.tz.platform.user.api.biz;
import com.tz.platform.entity.User;
import com.tz.platform.user.api.bo.UserRegisterBO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class ApiUserInfoBizTest {
@Autowired
private ApiUserInfoBiz apiUserInfoBiz;
@Test
public void singleInsert(){
UserRegisterBO userRegisterBO = new UserRegisterBO();
userRegisterBO.setPassword("111111");
userRegisterBO.setUserName("admin");
userRegisterBO.setSchool("BJ");
userRegisterBO.setStudentNo("000000");
User user = apiUserInfoBiz.reg(userRegisterBO);
System.out.println(user.getId());
}
@Test
public void batchImport() {
}
}
Loading…
Cancel
Save