初始化
commit
5b3a61e706
|
@ -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
|
|
@ -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"]
|
|
@ -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>
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0可用1已删除
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0不默认选中,1默认选中
|
||||||
|
*/
|
||||||
|
private String defaultStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1是系统属性,不可删除,0是自定义属性可以删除
|
||||||
|
*/
|
||||||
|
private String system;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private String orderBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属类型:文献类型中0代表期刊1代表非刊2代表开放资源
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解释、备注
|
||||||
|
*/
|
||||||
|
private String text;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 sheet最大行数,默认65536
|
||||||
|
*/
|
||||||
|
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 文件
|
||||||
|
* 对excel表单默认第一个索引名转换成list
|
||||||
|
*
|
||||||
|
* @param file 导入的文件
|
||||||
|
* @return 转换后集合
|
||||||
|
*/
|
||||||
|
public List<T> importExcel(MultipartFile file) throws Exception {
|
||||||
|
return importExcel(StringUtils.EMPTY, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对excel表单指定表格索引名转换成list
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*/
|
||||||
|
public void exportExcel(HttpServletResponse response){
|
||||||
|
try{
|
||||||
|
wb.write(response.getOutputStream());
|
||||||
|
} catch (Exception e){
|
||||||
|
log.error("导出Excel异常{}", e.getMessage());
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(wb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*
|
||||||
|
* @param list 导出数据集合
|
||||||
|
* @param sheetName 工作表的名称
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public String exportExcel(List<T> list, String sheetName) {
|
||||||
|
this.init(list, sheetName, Type.EXPORT);
|
||||||
|
return exportExcel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
|
@ -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 胡杨
|
||||||
|
* @name:MuYuPay
|
||||||
|
* @Date:2024/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 模块启动成功!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
Spring Boot Version: ${spring-boot.version}
|
||||||
|
Spring Application Name: ${spring.application.name}
|
|
@ -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
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue