Commit 5e895c4b authored by co_dengxiongwen's avatar co_dengxiongwen

tj

parent b278df33
package com.devplatform.admin.common.utils;
import com.devplatform.common.base.exception.RRException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Muceball-laptop
* @version 1.0
* @date 2021/2/23 11:50
*/
@Slf4j
public class XlsParseUtil {
private final String xlsFileName;
private final XSSFWorkbook workbook;
private final XSSFSheet sheet;
private final XSSFDrawing drawing;
// private final XSSFCellStyle whiteStyle;
// private final XSSFCellStyle yellowStyle;
private String path;
/**
* 初始化Excel
*
* @param fileName 导出文件名
* @param path 导出文件路径
* @param ins excel文件流
*/
public XlsParseUtil(String fileName, String path, InputStream ins) {
//文件名
this.xlsFileName = fileName;
//路径
this.path = path;
try {
this.workbook = new XSSFWorkbook(ins);
this.sheet = workbook.getSheetAt(0);
} catch (IOException e) {
log.error("解析文件失败");
throw new RRException(e.getMessage());
} finally {
if (ins != null) {
try {
ins.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
this.drawing = sheet.createDrawingPatriarch();
}
/**
* 获取最大行数
*
* @param
* @return java.lang.Integer
* @author dhl
* @date 2021/2/24 0024 9:49
*/
public Integer getLastRowNum() {
return this.sheet.getLastRowNum();
}
/**
* 获取当前行的最大列数
*
* @param rowNum
* @return java.lang.Integer
* @author dhl
* @date 2021/3/1 0001 10:43
*/
public Integer getLastCellNum(int rowNum) {
return Integer.valueOf(this.sheet.getRow(rowNum).getLastCellNum());
}
/**
* 获取单元格数据
*
* @param rowNum 行号(从0开始)
* @param colNum 列号(从0开始)
* @param c 返回值类型
* @return 单元格数据
*/
@SuppressWarnings("unchecked")
public <T> T getCellValue(int rowNum, int colNum, Class<T> c) {
XSSFRow row = sheet.getRow(rowNum);
if (row == null) {
return null;
}
XSSFCell cell = row.getCell(colNum);
if (cell == null) {
return null;
}
if (c == null || String.class.isAssignableFrom(c)) {
return (T) cell.getStringCellValue();
} else if (Date.class.isAssignableFrom(c)) {
return (T) cell.getDateCellValue();
} else if (boolean.class.isAssignableFrom(c) || Boolean.class.isAssignableFrom(c)) {
return (T) Boolean.valueOf(cell.getBooleanCellValue());
} else if (Integer.class.isAssignableFrom(c) || int.class.isAssignableFrom(c)) {
double numericCellValue = cell.getNumericCellValue();
return (T) Integer.valueOf(new Double(numericCellValue).intValue());
} else if (Double.class.isAssignableFrom(c) || double.class.isAssignableFrom(c)) {
return (T) Double.valueOf(cell.getNumericCellValue());
} else {
return null;
}
}
/**
* 获取单元格数据
*
* @param rowNum 行号(从0开始)
* @param colNum 列号(从0开始)
* @return 单元格数据
*/
public String getCellValue(int rowNum, int colNum) {
XSSFRow row = sheet.getRow(rowNum);
if (row == null) {
return null;
}
XSSFCell cell = row.getCell(colNum);
if (cell == null) {
return null;
}
String cellValue = "";
// 以下是判断数据的类型
CellType cellType = cell.getCellTypeEnum();
if (cellType == CellType.NUMERIC) { // 数字
if (DateUtil.isCellDateFormatted(cell)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date data = cell.getDateCellValue();
cellValue = sdf.format(data);
} else {
// cellValue = String.valueOf(cell.getNumericCellValue());
cell.setCellType(CellType.STRING);
cellValue = cell.getStringCellValue();
}
} else if (cellType == CellType.STRING) {
// 字符串
cellValue = cell.getStringCellValue();
} else if (cellType == CellType.BOOLEAN) {
// Boolean
cellValue = String.valueOf(cell.getBooleanCellValue());
} else if (cellType == CellType.FORMULA) {
// 公式
cellValue = cell.getCellFormula();
} else if (cellType == CellType.BLANK) {
// 空值
cellValue = "";
} else if (cellType == CellType.ERROR) {
// 故障
cellValue = null;
} else {
cellValue = null;
}
return cellValue;
}
/**
* 修改文件中的批注信息
*
* @param rowNum 行号(从0开始)
* @param colNum 列号(从0开始)
* @param commentStr 批注信息
*/
public void updateComment(int rowNum, int colNum, String commentStr) {
XSSFRow row = sheet.getRow(rowNum);
XSSFCell cell;
if (row == null) {
row = sheet.createRow(rowNum);
}
cell = row.getCell(colNum);
if (cell == null) {
cell = row.createCell(colNum);
cell.setCellValue("");
cell.setCellType(CellType.STRING);
}
XSSFCellStyle cellStyle = cell.getCellStyle();
if (StringUtils.isBlank(commentStr)) {
cell.removeCellComment();
// setStyle(cell, whiteStyle, IndexedColors.WHITE.getIndex());
if (cellStyle == null) {
XSSFCellStyle style = workbook.createCellStyle();
style.setFillPattern(FillPatternType.NO_FILL);
cell.setCellStyle(style);
} else {
CellStyle newStyle = workbook.createCellStyle();
// 克隆出一个 style
newStyle.cloneStyleFrom(cellStyle);
newStyle.setFillPattern(FillPatternType.NO_FILL);
cell.setCellStyle(newStyle);
}
} else {
Comment comment = cell.getCellComment();
if (comment == null) {
//批注为3行4列大小
comment = drawing.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, colNum, rowNum, colNum + 3, rowNum + 2));
}
// 输入批注信息
comment.setString(new XSSFRichTextString(commentStr));
// 添加作者
comment.setAuthor("Suntray");
// 将批注添加到单元格对象中
cell.setCellComment(comment);
if (cellStyle == null) {
XSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
style.setFillPattern(FillPatternType.NO_FILL);
cell.setCellStyle(style);
} else {
// CellStyle newStyle = cell.getRow().getSheet().getWorkbook().createCellStyle();
CellStyle newStyle = workbook.createCellStyle();
// 克隆出一个 style
newStyle.cloneStyleFrom(cellStyle);
newStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(newStyle);
}
}
}
/**
* 导出Excel文件
*/
@SuppressWarnings("all")
public void exportXlS() throws Exception {
if (StringUtils.isNotBlank(path) && !path.endsWith("/")) {
path = path + "/";
}
File file = new File(path);
if (!file.exists() && !file.isDirectory()) {
log.info("创建文件夹:" + path);
file.mkdirs();
}
try (FileOutputStream out = new FileOutputStream(path + xlsFileName)) {
workbook.write(out);
} finally {
workbook.close();
}
}
}
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.devplatform.admin.common.annotation.SysLogMethod;
import com.devplatform.admin.common.utils.*;
import com.devplatform.admin.modules.sys.bean.SysLogEntity;
import com.devplatform.admin.modules.sys.bean.SysSystem;
import com.devplatform.admin.modules.sys.bean.SysUserEntity;
import com.devplatform.admin.modules.sys.bean.SysUserRoleEntity;
import com.devplatform.admin.modules.sys.form.SysLoginForm;
......@@ -62,6 +63,8 @@ public class SysLoginController extends AbstractController {
private ShiroService shiroService;
@Autowired
private SysLogService sysLogService;
@Autowired
private SysSystemService sysSystemService;
/**
* 验证码
......@@ -103,6 +106,8 @@ public class SysLoginController extends AbstractController {
if (!captcha) {
return R.error("验证码不正确");
}
SysSystem sysSystem = sysSystemService.getById(Constants.CODE);
String u = Aes.decrypt(form.getUsername());
String p = Aes.decrypt(form.getPassword());
// 用户信息
......@@ -135,6 +140,7 @@ public class SysLoginController extends AbstractController {
}
user.setRoleIdList(roleIdList);
String jwtToken = null;
user.setSysSystem(sysSystem);
try {
jwtToken =
JwtUtil.createJwt("longingJWT", JwtUtil.generalSubject(user), 1000 * 60 * 60 * 24 * 7);
......@@ -156,7 +162,8 @@ public class SysLoginController extends AbstractController {
.put("token", jwtToken)
.put("permissions", permissions)
.put("userId", user.getUserId())
.put("userName", user.getName());
.put("userName", user.getName())
.put("sysSystem", JSON.toJSONString(sysSystem));
}
private void saveLog(
......
diff a/microservice-admin/src/main/java/com/devplatform/admin/modules/sys/controller/SysLoginController.java b/microservice-admin/src/main/java/com/devplatform/admin/modules/sys/controller/SysLoginController.java (rejected hunks)
@@ -135,7 +135,6 @@
}
user.setRoleIdList(roleIdList);
String jwtToken = null;
- user.setSysSystem(sysSystem);
try {
jwtToken =
JwtUtil.createJwt("longingJWT", JwtUtil.generalSubject(user), 1000 * 60 * 60 * 24 * 7);
package com.devplatform.admin.modules.sys.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.devplatform.admin.common.annotation.SysLogMethod;
import com.devplatform.admin.common.utils.AbstractController;
......@@ -7,7 +8,6 @@ import com.devplatform.admin.common.utils.Constants;
import com.devplatform.admin.modules.sys.bean.SysRoleEntity;
import com.devplatform.admin.modules.sys.service.SysRoleMenuService;
import com.devplatform.admin.modules.sys.service.SysRoleService;
import com.devplatform.admin.modules.sys.service.SysUserRoleService;
import com.devplatform.common.base.annotation.SysLog;
import com.devplatform.common.base.validator.ValidatorUtils;
import com.devplatform.common.util.PageUtils;
......@@ -17,20 +17,14 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 角色管理
......@@ -43,12 +37,8 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/sys/role")
public class SysRoleController extends AbstractController {
private static String CREATE_USER_ID = "create_user_id";
@Autowired private SysRoleService sysRoleService;
@Autowired private SysRoleMenuService sysRoleMenuService;
@Autowired private SysUserRoleService sysUserRoleService;
/** 角色列表 */
@ApiOperation(value = "根据条件获取分页数据列表", notes = "根据条件获取分页数据列表")
......@@ -66,11 +56,11 @@ public class SysRoleController extends AbstractController {
PageUtils page =
sysRoleService.queryPage(
params,
new QueryWrapper<SysRoleEntity>()
.like(StringUtil.checkNotNull(roleName), "role_name", roleName)
.eq(StringUtils.isNotBlank(createUserId), CREATE_USER_ID, createUserId)
.eq(StringUtils.isNotBlank(stationId), "station_id", stationId)
.orderByDesc("create_time"));
new LambdaQueryWrapper<SysRoleEntity>()
.like(StringUtil.checkNotNull(roleName), SysRoleEntity::getRoleName,roleName)
.eq(StringUtils.isNotBlank(createUserId), SysRoleEntity::getCreateUserId, createUserId)
.eq(StringUtils.isNotBlank(stationId), SysRoleEntity::getStationId, stationId)
.orderByDesc(SysRoleEntity::getCreateTime));
return R.ok().put("page", page);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment