初始化

master
面包骑士 2024-08-11 14:17:22 +08:00
commit 5b3a61e706
20 changed files with 1720 additions and 0 deletions

46
.gitignore vendored 100644
View File

@ -0,0 +1,46 @@
######################################################################
# Build Tools
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
target/
!.mvn/wrapper/maven-wrapper.jar
######################################################################
# IDE
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### JRebel ###
rebel.xml
### NetBeans ###
nbproject/private/
build/*
nbbuild/
dist/
nbdist/
.nb-gradle/
######################################################################
# Others
*.log
*.xml.versionsBackup
*.swp
!*/build/*.java
!*/build/*.html
!*/build/*.xml

12
Dockerfile 100644
View File

@ -0,0 +1,12 @@
# |- home
# |- app.jar
# |- logs
FROM openjdk:17-jdk
WORKDIR /home
VOLUME ["/home/logs/cloud-pay-server"]
COPY ./cloud-resource-server/target/cloud-resource-server.jar /home/cloud-resource-server.jar
ENTRYPOINT ["java","-jar","/home/cloud-resource-server.jar"]

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-resource</artifactId>
<version>3.6.5</version>
</parent>
<artifactId>cloud-resource-common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,78 @@
package com.muyu.resource.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import com.muyu.resource.domain.req.ResourceReq;
import lombok.*;
/**
* @Author:
* @Name: ResourceInfo
* @Description:
* @CreatedDate: 2024/8/10 9:51
* @FilePath: com.muyu.resource.domain
*/
@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResourceInfo {
private String id;
private String recommendId;
private String title;
private String titleFormat;
private String otherTitle;
private String seriesNumber;
private String seriesTitle;
private String pissn;
private String eissn;
private String pisbn;
private String eisbn;
private String orderNumber;
private String subject;
private String publisher;
private String country;
private String pubYear;
private String foundedYear;
private String language;
private String pubFeq;
private String intro;
private String classiNumber;
private String url;
private String carrier;
private String type;
private String pubPattern;
private String pubStatus;
private String price;
private String currency;
private String oA;
private String sysTime;
private String sysUserId;
private String organId;
private String orderStatus;
private String distributionStatus;
private String reviewStatus;
private String updReviewStatus;
private String totalScore;
private String factor;
private String note;
private String inlet;
private String oldId;
private String systemId;
private String resVol;
// 是否是精确查询
private Boolean flag;
/**
*
*/
public void setFlag(ResourceReq req) {
this.flag = this.getTitle().equals(req.getTitle())
&& this.getPissn().equals(req.getPissn())
&& this.getEissn().equals(req.getEissn())
&& this.getPisbn().equals(req.getPisbn())
&& this.getEisbn().equals(req.getEisbn());
}
}

View File

@ -0,0 +1,94 @@
package com.muyu.resource.domain;
import lombok.*;
/**
* @Author:
* @Name: SysParam
* @Description:
* @CreatedDate: 2024/8/10 9:45
* @FilePath: com.muyu.resource.domain
*/
@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SysParam {
/**
* id
*/
private String id;
/**
*
*/
private String code;
/**
* 01
*/
private String isDel;
/**
*
*/
private String level;
/**
*
*/
private String name;
/**
*
*/
private String startNum;
/**
*
*/
private String endNum;
/**
* id
*/
private String pid;
/**
*
*/
private String score;
/**
*
*/
private String weight;
/**
* 01
*/
private String defaultStatus;
/**
* 10
*/
private String system;
/**
*
*/
private String orderBy;
/**
* 012
*/
private String type;
/**
*
*/
private String text;
}

View File

@ -0,0 +1,24 @@
package com.muyu.resource.domain.req;
import lombok.*;
/**
* @Author:
* @Name: ResourceInfo
* @Description:
* @CreatedDate: 2024/8/10 9:51
* @FilePath: com.muyu.resource.domain
*/
@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResourceReq {
private String title;
private String pissn;
private String eissn;
private String pisbn;
private String eisbn;
}

View File

@ -0,0 +1,90 @@
package com.muyu.resource.domain.resp;
import com.alibaba.excel.annotation.ExcelProperty;
import com.muyu.common.core.annotation.Excel;
import lombok.*;
/**
* @Author:
* @Name: ResourceInfo
* @Description:
* @CreatedDate: 2024/8/10 9:51
* @FilePath: com.muyu.resource.domain
*/
@Data
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResourceInfoResp {
/*
*
*/
@Excel(name = "题名")
private String title;
/**
*
*/
@Excel(name = "题名译名")
private String otherTitle;
/**
* ISSN
*/
@Excel(name = "PISSN")
private String pissn;
/**
* ISSN
*/
@Excel(name = "EISSN")
private String eissn;
/**
* isbn
*/
@Excel(name = "PISBN")
private String pisbn;
/**
* isbn
*/
@Excel(name = "EISBN")
private String eisbn;
/**
*
*/
@Excel(name = "文献类型")
private String type;
/**
*
*/
@Excel(name = "载体")
private String carrier;
/**
*
*/
@Excel(name = "学科")
private String subject;
/**
*
*/
@Excel(name = "国家/地区")
private String country;
/**
*
*/
@Excel(name = "语种")
private String language;
}

View File

@ -0,0 +1,34 @@
package com.muyu.resource.domain.result;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author DongZl
* @description:
*/
@Data
public class PageResult<T> implements Serializable {
/**
*
*/
private long total;
/**
*
*/
private List<T> list;
public PageResult() {
}
public PageResult(long total, List<T> list) {
this.total = total;
this.list = list;
}
public static <T> PageResult<T> toPageResult(long total, List<T> list){
return new PageResult(total , list);
}
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
return Result.success(PageResult.toPageResult(total,list));
}
}

View File

@ -0,0 +1,76 @@
package com.muyu.resource.domain.result;
import com.muyu.common.core.constant.Constants;
import lombok.Data;
import java.io.Serializable;
/**
* @author DongZl
* @description:
*/
@Data
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
public static final int SUCCESS = Constants.SUCCESS;
/**
*
*/
public static final int FAIL = Constants.FAIL;
/**
*
*/
private int code;
/**
*
*/
private String msg;
/**
*
*/
private T data;
public static <T> Result<T> success() {
return restResult(null, SUCCESS, Constants.LOGIN_SUCCESS);
}
public static <T> Result<T> success(T data) {
return restResult(data, SUCCESS, Constants.LOGIN_SUCCESS);
}
public static <T> Result<T> success(T data, String msg) {
return restResult(data, SUCCESS, msg);
}
public static <T> Result<T> error() {
return restResult(null, FAIL, Constants.LOGIN_FAIL);
}
public static <T> Result<T> error(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> Result<T> error(T data) {
return restResult(data, FAIL, Constants.LOGIN_FAIL);
}
public static <T> Result<T> error(T data, String msg) {
return restResult(data, FAIL, msg);
}
public static <T> Result<T> error(int code, String msg) {
return restResult(null, code, msg);
}
private static <T> Result<T> restResult(T data, int code, String msg) {
Result<T> apiResult = new Result<>();
apiResult.setCode(code);
apiResult.setData(data);
apiResult.setMsg(msg);
return apiResult;
}
}

View File

@ -0,0 +1,798 @@
package com.muyu.resource.utils;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.annotation.Excel.Type;
import com.muyu.common.core.annotation.Excels;
import com.muyu.common.core.text.Convert;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.core.utils.SpringUtils;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.reflect.ReflectUtils;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
/**
* Excel
*/
@Log4j2
public class ExcelUtils<T>{
/**
* Excel sheet65536
*/
public static final int SHEET_SIZE = 65536;
/**
*
*/
private String sheetName;
/**
* EXPORT:IMPORT
*/
private Type type;
/**
*
*/
private Workbook wb;
/**
*
*/
private Sheet sheet;
/**
*
*/
private Map<String, CellStyle> styles;
/**
*
*/
private List<T> list;
/**
*
*/
private List<Object[]> fields;
/**
*
*/
public Class<T> clazz;
public ExcelUtils(Class<T> clazz) {
this.clazz = clazz;
}
public void init(List<T> list, String sheetName, Type type) {
if (list == null) {
list = new ArrayList<>();
}
this.list = list;
this.sheetName = sheetName;
this.type = type;
createExcelField();
createWorkbook();
}
/**
* Excel
* excellist
*
* @param file
* @return
*/
public List<T> importExcel(MultipartFile file) throws Exception {
return importExcel(StringUtils.EMPTY, file);
}
/**
* excellist
*
* @param sheetName
* @param file
* @return
*/
public List<T> importExcel(String sheetName,MultipartFile file) throws Exception {
InputStream is = file.getInputStream();
this.type = Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> list = new ArrayList<>();
Sheet sheet;
if (StringUtils.isNotEmpty(sheetName)) {
// 如果指定sheet名,则取指定sheet中的内容.
sheet = wb.getSheet(sheetName);
} else {
// 如果传入的sheet名不存在则默认指向第1个sheet.
sheet = wb.getSheetAt(0);
}
if (sheet == null) {
throw new IOException("文件sheet不存在");
}
int rows = sheet.getPhysicalNumberOfRows();
if (rows > 0) {
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<>();
// 获取表头
Row heard = sheet.getRow(2);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) {
Cell cell = heard.getCell(i);
if (cell != null) {
String value = this.getCellValue(heard, i).toString();
cellMap.put(value, i);
}
else {
cellMap.put(null, i);
}
}
// 有数据时才处理 得到类的所有field.
Field[] allFields = clazz.getDeclaredFields();
// 定义一个map用于存放列的序号和field.
Map<Integer, Field> fieldsMap = new HashMap<>();
for (Field field : allFields) {
Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) {
// 设置类的私有字段属性可访问.
field.setAccessible(true);
Integer column = cellMap.get(attr.name());
//模板名称检测
if(column == null){
column = cellMap.get("*"+attr.name());
if (column == null) {
System.out.println("模板错误:Excel表头和项目里面设置的表头[" + attr.name() + "]不一致,请检查!");
return new ArrayList<>();
}
}
fieldsMap.put(column, field);
}
}
// 获取数据
for (int i = 3; i < rows; i++) {
// 从第2行开始取数据,默认第一行是表头.
Row row = sheet.getRow(i);
T entity = null;
for (Map.Entry<Integer, Field> entry : fieldsMap.entrySet()) {
if (entry.getKey() == null){
continue;
}
Object val = this.getCellValue(row, entry.getKey());
// 如果不存在实例则新建.
entity = (entity == null ? clazz.newInstance() : entity);
// 从map中得到对应列的field.
Field field = fieldsMap.get(entry.getKey());
// 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType();
if (String.class == fieldType) {
String s = Convert.toStr(val);
if (StringUtils.endsWith(s, ".0")) {
val = StringUtils.substringBefore(s, ".0");
} else {
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StringUtils.isNotEmpty(dateFormat)) {
val = DateUtils.parseDateToStr(dateFormat, (Date) val);
} else {
val = Convert.toStr(val);
}
}
} else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) {
val = Convert.toInt(val);
} else if ((Long.TYPE == fieldType) || (Long.class == fieldType)) {
val = Convert.toLong(val);
} else if ((Double.TYPE == fieldType) || (Double.class == fieldType)) {
val = Convert.toDouble(val);
} else if ((Float.TYPE == fieldType) || (Float.class == fieldType)) {
val = Convert.toFloat(val);
} else if (BigDecimal.class == fieldType) {
val = Convert.toBigDecimal(val);
} else if (Date.class == fieldType) {
if (val instanceof String) {
val = DateUtils.parseDate(val);
} else if (val instanceof Double) {
val = DateUtil.getJavaDate((Double) val);
}
}
//模板检测判断
if (val==null){
System.out.println("模板错误:第"+(i+1)+"行,第"+(entry.getKey()+1)+"列Excel的数据格式和数据库格式不一致");
return new ArrayList<>();
}
Excel attr = field.getAnnotation(Excel.class);
String propertyName = field.getName();
if (StringUtils.isNotEmpty(attr.targetAttr())) {
propertyName = field.getName() + "." + attr.targetAttr();
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
val = reverseByExp(String.valueOf(val), attr.readConverterExp());
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
list.add(entity);
}
}
return list;
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName){
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
this.init(list, sheetName, Type.EXPORT);
writeSheet();
exportExcel(response);
}
/**
* listexcel
*/
public void exportExcel(HttpServletResponse response){
try{
wb.write(response.getOutputStream());
} catch (Exception e){
log.error("导出Excel异常{}", e.getMessage());
} finally {
IOUtils.closeQuietly(wb);
}
}
/**
* listexcel
*
* @param list
* @param sheetName
* @return
*/
public String exportExcel(List<T> list, String sheetName) {
this.init(list, sheetName, Type.EXPORT);
return exportExcel();
}
/**
* listexcel
*
* @param sheetName
* @return
*/
public String importTemplateExcel(String sheetName) {
this.init(null, sheetName, Type.IMPORT);
return exportExcel();
}
/**
* sheet
*/
public void writeSheet(){
// 取出一共有多少个sheet.
double sheetNo = Math.ceil(list.size() / SHEET_SIZE);
for (int index = 0; index <= sheetNo; index++) {
createSheet(sheetNo, index);
// 产生一行
Row row = sheet.createRow(0);
int column = 0;
// 写入各个字段的列头名称
for (Object[] os : fields) {
Excel excel = (Excel) os[1];
this.createCell(excel, row, column++);
}
if (Type.EXPORT.equals(type)) {
fillExcelData(index, row);
}
}
}
/**
* listexcel
*
* @return
*/
public String exportExcel() {
OutputStream out = null;
try {
writeSheet();
String filename = encodingFilename(sheetName);
out = new FileOutputStream(getAbsoluteFile(filename));
wb.write(out);
return filename;
} catch (Exception e) {
log.error("导出Excel异常{}", e.getMessage());
e.printStackTrace();
} finally {
try {
if (wb != null) {
wb.close();
}
if (out != null) {
out.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
return "";
}
/**
* excel
*
* @param index
* @param row
*/
public void fillExcelData(int index, Row row) {
int startNo = index * SHEET_SIZE;
int endNo = Math.min(startNo + SHEET_SIZE, list.size());
for (int i = startNo; i < endNo; i++) {
row = sheet.createRow(i + 1 - startNo);
// 得到导出对象.
T vo = (T) list.get(i);
int column = 0;
for (Object[] os : fields) {
Field field = (Field) os[0];
Excel excel = (Excel) os[1];
// 设置实体类私有属性可访问
field.setAccessible(true);
this.addCell(excel, row, vo, field, column++);
}
}
}
/**
*
*
* @param wb
* @return
*/
private Map<String, CellStyle> createStyles(Workbook wb) {
// 写入各条记录,每条记录对应excel表中的一行
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = wb.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBold(true);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put("header", style);
return styles;
}
/**
*
*/
public Cell createCell(Excel attr, Row row, int column) {
// 创建列
Cell cell = row.createCell(column);
// 写入列信息
cell.setCellValue(attr.name());
setDataValidation(attr, row, column);
cell.setCellStyle(styles.get("header"));
return cell;
}
/**
*
*
* @param value
* @param attr
* @param cell
*/
public void setCellVo(Object value, Excel attr, Cell cell) {
if (ColumnType.STRING == attr.cellType()) {
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(value == null ? attr.defaultValue() : value + attr.suffix());
} else if (ColumnType.NUMERIC == attr.cellType()) {
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(Integer.parseInt(value + ""));
}
}
/**
*
*/
public void setDataValidation(Excel attr, Row row, int column) {
if (attr.name().indexOf("注:") >= 0) {
sheet.setColumnWidth(column, 6000);
} else {
// 设置列宽
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
row.setHeight((short) (attr.height() * 20));
}
// 如果设置了提示信息则鼠标放上去提示.
if (StringUtils.isNotEmpty(attr.prompt())) {
// 这里默认设了2-101列提示.
setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
}
// 如果设置了combo属性则本列只能选择不能输入
if (attr.combo().length > 0) {
// 这里默认设了2-101列只能选择不能输入.
setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
}
}
/**
*
*/
public Cell addCell(Excel attr, Row row, T vo, Field field, int column) {
Cell cell = null;
try {
// 设置行高
row.setHeight((short) (attr.height() * 20));
// 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
if (attr.isExport()) {
// 创建cell
cell = row.createCell(column);
cell.setCellStyle(styles.get("data"));
// 用于读取对象中的属性
Object value = getTargetValue(vo, field, attr);
//时间类型格式化
String dateFormat = attr.dateFormat();
//读取表达式
String readConverterExp = attr.readConverterExp();
//分隔符
String splitStr = attr.separator();
//反射对象
Class<?> invokeClass = attr.invokeClass();
//反射方法名称
String invokeMethod = attr.invokeMethod();
if (StringUtils.isNotEmpty(dateFormat) && value != null) {
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
} else if (StringUtils.isNotEmpty(readConverterExp) && value != null) {
// 判断是否有分隔符
if (StringUtils.isNotEmpty(splitStr)){
StringBuilder cellValue = new StringBuilder();
String valueStr = String.valueOf(value);
String[] valueStrSplit = valueStr.split(splitStr);
int valueStrSplitLength = valueStrSplit.length;
for (int i = 0; ; i++) {
cellValue.append(convertByExp(valueStrSplit[i], readConverterExp));
if (i == valueStrSplitLength-1){
break;
}
cellValue.append(",");
}
cell.setCellValue(cellValue.toString());
} else {
cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp));
}
}
// 判断是否需要取值
else if((!invokeClass.getName().equals(String.class.getName())) && StringUtils.isNotEmpty(invokeMethod)){
Object bean = SpringUtils.getBean(invokeClass);
Method thisMethod = null;
Method[] methods = invokeClass.getMethods();
for (Method method : methods) {
if (method.getName().equals(invokeMethod)){
thisMethod = method;
continue;
}
}
cell.setCellValue(thisMethod.invoke(bean,value).toString());
} else {
// 设置列类型
setCellVo(value, attr, cell);
}
}
} catch (Exception e) {
log.error("导出Excel失败{}", e);
}
return cell;
}
/**
* POI XSSFSheet
*
* @param sheet
* @param promptTitle
* @param promptContent
* @param firstRow
* @param endRow
* @param firstCol
* @param endCol
*/
public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
DataValidation dataValidation = helper.createValidation(constraint, regions);
dataValidation.createPromptBox(promptTitle, promptContent);
dataValidation.setShowPromptBox(true);
sheet.addValidationData(dataValidation);
}
/**
* ,.
*
* @param sheet sheet.
* @param textlist
* @param firstRow
* @param endRow
* @param firstCol
* @param endCol
* @return sheet.
*/
public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
// 加载下拉列表内容
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
// 数据有效性对象
DataValidation dataValidation = helper.createValidation(constraint, regions);
// 处理Excel兼容性问题
if (dataValidation instanceof XSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(true);
dataValidation.setShowErrorBox(true);
} else {
dataValidation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(dataValidation);
}
/**
* 0=,1=,2=
*
* @param propertyValue
* @param converterExp
* @return
* @throws Exception
*/
public static String convertByExp(String propertyValue, String converterExp) throws Exception {
try {
String[] convertSource = converterExp.split(",");
for (String item : convertSource) {
String[] itemArray = item.split("=");
if (itemArray[0].equals(propertyValue)) {
return itemArray[1];
}
}
} catch (Exception e) {
throw e;
}
return propertyValue;
}
/**
* =0,=1,=2
*
* @param propertyValue
* @param converterExp
* @return
* @throws Exception
*/
public static String reverseByExp(String propertyValue, String converterExp) throws Exception {
try {
String[] convertSource = converterExp.split(",");
for (String item : convertSource) {
String[] itemArray = item.split("=");
if (itemArray[1].equals(propertyValue)) {
return itemArray[0];
}
}
} catch (Exception e) {
throw e;
}
return propertyValue;
}
/**
*
*/
public String encodingFilename(String filename) {
filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
return filename;
}
/**
*
*
* @param filename
*/
public String getAbsoluteFile(String filename) {
String downloadPath = System.getProperty("user.dir") + File.separator + filename;
File desc = new File(downloadPath);
if (!desc.getParentFile().exists()) {
desc.getParentFile().mkdirs();
}
return downloadPath;
}
/**
* bean
*
* @param vo
* @param field
* @param excel
* @return
* @throws Exception
*/
private Object getTargetValue(T vo, Field field, Excel excel) throws Exception {
Object o = field.get(vo);
if (StringUtils.isNotEmpty(excel.targetAttr())) {
String target = excel.targetAttr();
if (target.indexOf(".") > -1) {
String[] targets = target.split("[.]");
for (String name : targets) {
o = getValue(o, name);
}
} else {
o = getValue(o, target);
}
}
return o;
}
/**
* get
*
* @param o
* @param name
* @return value
* @throws Exception
*/
private Object getValue(Object o, String name) throws Exception {
if (StringUtils.isNotEmpty(name)) {
Class<?> clazz = o.getClass();
String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
Method method = clazz.getMethod(methodName);
o = method.invoke(o);
}
return o;
}
/**
*
*/
private void createExcelField() {
this.fields = new ArrayList<>();
List<Field> tempFields = new ArrayList<>();
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
for (Field field : tempFields) {
// 单注解
if (field.isAnnotationPresent(Excel.class)) {
putToField(field, field.getAnnotation(Excel.class));
}
// 多注解
if (field.isAnnotationPresent(Excels.class)) {
Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value();
for (Excel excel : excels) {
putToField(field, excel);
}
}
}
}
/**
*
*/
private void putToField(Field field, Excel attr) {
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) {
this.fields.add(new Object[] { field, attr });
}
}
/**
* 簿
*/
public void createWorkbook() {
this.wb = new SXSSFWorkbook(500);
}
/**
*
*
* @param sheetNo sheet
* @param index
*/
public void createSheet(double sheetNo, int index) {
this.sheet = wb.createSheet();
this.styles = createStyles(wb);
// 设置工作表的名称.
if (sheetNo == 0) {
wb.setSheetName(index, sheetName);
} else {
wb.setSheetName(index, sheetName + index);
}
}
/**
*
*
* @param row
* @param column
* @return
*/
public Object getCellValue(Row row, int column) {
if (row == null) {
return row;
}
Object val = "";
try {
Cell cell = row.getCell(column);
if (cell != null) {
if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA) {
val = cell.getNumericCellValue();
if (HSSFDateUtil.isCellDateFormatted(cell)) {
val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换
} else {
if ((Double) val % 1 > 0) {
val = new DecimalFormat("0.00").format(val);
} else {
val = new DecimalFormat("0").format(val);
}
}
} else if (cell.getCellTypeEnum() == CellType.STRING) {
val = cell.getStringCellValue();
} else if (cell.getCellTypeEnum() == CellType.BOOLEAN) {
val = cell.getBooleanCellValue();
} else if (cell.getCellTypeEnum() == CellType.ERROR) {
val = cell.getErrorCellValue();
}
}
} catch (Exception e) {
return val;
}
return val;
}
}

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-resource</artifactId>
<version>3.6.5</version>
</parent>
<artifactId>cloud-resource-server</artifactId>
<version>3.6.5</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datasource</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-log</artifactId>
</dependency>
<!-- 接口模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-resource-common</artifactId>
<version>3.6.5</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.2.6</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>yun-releases</id>
<name>yun-releases</name>
<url>http://47.116.173.119:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
</project>

View File

@ -0,0 +1,28 @@
package com.muyu.resource;
import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author
* @nameMuYuPay
* @Date2024/7/31 10:05
* @Description: com.muyu.pay
*/
@EnableCustomConfig
@EnableMyFeignClients
@SpringBootApplication
public class ResourceApplication {
public static void main(String[] args) {
try {
SpringApplication.run(ResourceApplication.class, args);
} catch (Exception e) {
throw new RuntimeException(e);
}
System.out.println("Resource 模块启动成功!");
}
}

View File

@ -0,0 +1,64 @@
package com.muyu.resource.controller;
import javax.annotation.Resource;
import com.muyu.common.core.domain.Result;
import com.muyu.resource.domain.ResourceInfo;
import com.muyu.resource.domain.req.ResourceReq;
import com.muyu.resource.domain.resp.ResourceInfoResp;
import com.muyu.resource.domain.result.PageResult;
import com.muyu.resource.service.ResourceService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @Author:
* @Name: Resource
* @Description:
* @CreatedDate: 2024/8/10 10:42
* @FilePath: com.muyu.resource.controller
*/
@Slf4j
@RestController
@RequestMapping("/Resource")
@Tag(name = "资源控制层", description = "存储资源控制的各种方法")
public class ResourceController {
@Resource
private ResourceService service;
@Resource
private HttpServletRequest request;
/**
* excel
* @param file
* @return
*/
@PostMapping("/upload")
public Result<PageResult<ResourceInfoResp>> upload(@RequestParam("file") MultipartFile file) {
return Result.success(service.upload(file));
}
/**
*
* @param pageNum
* @return
*/
@GetMapping("/list")
public Result<PageResult<ResourceInfoResp>> list(@RequestParam("pageNum") Integer pageNum) {
return Result.success(service.list(pageNum));
}
/**
*
* @return
*/
@PostMapping("/find")
public Result<List<ResourceInfo>> pissn(@RequestBody ResourceReq req) {
return Result.success(service.findResourceByPissn(req));
}
}

View File

@ -0,0 +1,26 @@
package com.muyu.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.resource.domain.ResourceInfo;
import com.muyu.resource.domain.req.ResourceReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author:
* @Name: Resource
* @Description:
* @CreatedDate: 2024/8/10 10:38
* @FilePath: com.muyu.resource.mapper
*/
@Repository
@Mapper
public interface ResourceMapper{
List<ResourceInfo> findResourceByPissn(ResourceReq req);
}

View File

@ -0,0 +1,25 @@
package com.muyu.resource.service;
import com.muyu.resource.domain.result.PageResult;
import com.muyu.resource.domain.ResourceInfo;
import com.muyu.resource.domain.req.ResourceReq;
import com.muyu.resource.domain.resp.ResourceInfoResp;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @Author:
* @Name: Resource
* @Description:
* @CreatedDate: 2024/8/10 10:41
* @FilePath: com.muyu.resource.service
*/
public interface ResourceService{
PageResult<ResourceInfoResp> upload(MultipartFile file);
List<ResourceInfo> findResourceByPissn(ResourceReq req);
PageResult<ResourceInfoResp> list(Integer pageNum);
}

View File

@ -0,0 +1,87 @@
package com.muyu.resource.service.impl;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSONObject;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.resource.domain.result.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.resource.domain.ResourceInfo;
import com.muyu.resource.domain.req.ResourceReq;
import com.muyu.resource.domain.resp.ResourceInfoResp;
import com.muyu.resource.mapper.ResourceMapper;
import com.muyu.resource.service.ResourceService;
import com.muyu.resource.utils.ExcelUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* @Author:
* @Name: Resource
* @Description:
* @CreatedDate: 2024/8/10 10:41
* @FilePath: com.muyu.resource.service.impl
*/
@Slf4j
@Service
public class ResourceServiceImpl implements ResourceService {
@Resource
private ResourceMapper mapper;
@Resource
private RedisTemplate<String,String> redisTemplate;
@Override
public PageResult<ResourceInfoResp> upload(MultipartFile file) {
ExcelUtils<ResourceInfoResp> excelUtils = new ExcelUtils<>(ResourceInfoResp.class);
try {
PageHelper.startPage(1, 10);
// 调用导入方法
List<ResourceInfoResp> respList = excelUtils.importExcel(null, file);
redisTemplate.opsForValue().set("list",JSONObject.toJSONString(respList),1,TimeUnit.HOURS);
PageInfo<ResourceInfoResp> pageInfo = new PageInfo<>(respList);
return PageResult.toPageResult(pageInfo.getTotal(), pageInfo.getList());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public List<ResourceInfo> findResourceByPissn(ResourceReq req) {
String resString = redisTemplate.opsForValue().get(req.toString());
if (StringUtils.isNotEmpty(resString)){
return JSONObject.parseObject(resString, List.class);
}
List<ResourceInfo> resourceInfos = mapper.findResourceByPissn(req);
resourceInfos.forEach(resourceInfo -> resourceInfo.setFlag(req));
redisTemplate.opsForValue().set(req.toString(), JSONObject.toJSONString(resourceInfos),1, TimeUnit.HOURS);
return resourceInfos;
}
@Override
public PageResult<ResourceInfoResp> list(Integer pageNum) {
String resString = redisTemplate.opsForValue().get("list");
if (StringUtils.isNotEmpty(resString)){
List<ResourceInfoResp> respList = JSONObject.parseObject(resString, List.class);
int index = (pageNum-1)*10;
int toIndex = (pageNum-1)*10+10;
if (toIndex>respList.size()){
return null;
}
return PageResult.toPageResult(respList.size(),
respList.subList(index,toIndex));
}
return null;
}
}

View File

@ -0,0 +1,2 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}

View File

@ -0,0 +1,52 @@
# Tomcat
server:
port: 9801
# nacos线上地址
nacos:
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: 9a848700-2a37-4ca1-bb66-3ef384e4c3b9
# Spring
spring:
main:
allow-bean-definition-overriding: true
application:
# 应用名称
name: cloud-resource
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间
namespace: ${nacos.namespace}
config:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间
namespace: ${nacos.namespace}
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
# 系统共享配置
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 系统环境Config共享配置
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.system.mapper: DEBUG

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.resource.mapper.ResourceMapper">
<select id="findResourceByPissn" resultType="com.muyu.resource.domain.ResourceInfo">
SELECT * FROM
t_resource_info
WHERE
REPLACE(pissn,'-','') = #{pissn} OR
REPLACE(eissn,'-','') = #{eissn} OR
REPLACE(pisbn,'-','') = #{pisbn} OR
REPLACE(eisbn,'-','') = #{eisbn} OR
title = #{title}
</select>
</mapper>

28
pom.xml 100644
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-server-parent</artifactId>
<version>3.6.5</version>
</parent>
<artifactId>cloud-resource</artifactId>
<version>3.6.5</version>
<packaging>pom</packaging>
<modules>
<module>cloud-resource-common</module>
<module>cloud-resource-server</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>