add:agv模块看板
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
package org.nl.common.localStorage.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.localStorage.service.LocalStorageService;
|
||||
import org.nl.common.localStorage.service.entity.LocalStorage;
|
||||
import org.nl.common.pojo.CommonResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping({"/api/localStorage"})
|
||||
@SaIgnore
|
||||
public class LocalStorageController {
|
||||
|
||||
@Autowired
|
||||
private LocalStorageService localStorageService;
|
||||
|
||||
@GetMapping
|
||||
public CommonResult<Object> query(@RequestParam String annex) {
|
||||
List<LocalStorage> list = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(annex)){
|
||||
String[] split = annex.split(",");
|
||||
list = localStorageService.listByIds(Arrays.asList(split));
|
||||
}
|
||||
return CommonResult.data(list);
|
||||
}
|
||||
@PostMapping({"/upload"})
|
||||
public CommonResult<Object> upload(@RequestParam MultipartFile file) {
|
||||
LocalStorage localStorage = localStorageService.upload(file);
|
||||
return CommonResult.data(localStorage);
|
||||
}
|
||||
@GetMapping({"/download"})
|
||||
public void download(@RequestParam Long storageId , HttpServletResponse response, HttpServletRequest request) throws IOException {
|
||||
this.localStorageService.downloadFile(this.localStorageService.getById(storageId),request, response);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping
|
||||
public CommonResult delete(@RequestBody Long[] ids) {
|
||||
localStorageService.removeByIds(Arrays.asList(ids));
|
||||
return CommonResult.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.nl.common.localStorage.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.nl.common.localStorage.service.entity.LocalStorage;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface LocalStorageService extends IService<LocalStorage> {
|
||||
|
||||
LocalStorage upload(MultipartFile file);
|
||||
List<LocalStorage> batchUpload(MultipartFile[] file);
|
||||
|
||||
void download(List<LocalStorage> localStorageDtos, HttpServletResponse response) throws IOException;
|
||||
void downloadFile(LocalStorage localStorage, HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.nl.common.localStorage.service.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
@TableName("local_storage")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LocalStorage implements Serializable {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String name;
|
||||
private String suffix;
|
||||
private String path;
|
||||
private String type;
|
||||
private String size;
|
||||
private Integer orderCode;
|
||||
private Date createTime;
|
||||
private String createName;
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package org.nl.common.localStorage.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.nl.common.localStorage.service.LocalStorageService;
|
||||
import org.nl.common.localStorage.service.mapper.LocalStorageMapper;
|
||||
import org.nl.common.localStorage.service.entity.LocalStorage;
|
||||
import org.nl.common.util.FileProperties;
|
||||
import org.nl.common.util.FileUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
|
||||
@Service
|
||||
public class LocalStorageServiceImpl extends ServiceImpl<LocalStorageMapper, LocalStorage> implements LocalStorageService {
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
|
||||
@Override
|
||||
public LocalStorage upload(MultipartFile multipartFile) {
|
||||
String filename = multipartFile.getOriginalFilename();
|
||||
String suffix = FileUtil.getExtensionName(filename);
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(multipartFile, this.fileProperties.getPath().getPath() + type + File.separator);
|
||||
LocalStorage storage = LocalStorage.builder().name(filename)
|
||||
.path(file.getPath())
|
||||
.size(FileUtil.getSize(multipartFile.getSize()))
|
||||
.suffix(type)
|
||||
.type(type).createTime(new Date()).build();
|
||||
this.baseMapper.insertUseGeneratedKeys(storage);
|
||||
return storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalStorage> batchUpload(MultipartFile[] multipartFile) {
|
||||
List<LocalStorage> result = new ArrayList<>();
|
||||
if (multipartFile!=null){
|
||||
for (MultipartFile item : multipartFile) {
|
||||
String filename = item.getOriginalFilename();
|
||||
String suffix = FileUtil.getExtensionName(filename);
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(item, this.fileProperties.getPath().getPath() + type + File.separator);
|
||||
LocalStorage storage = LocalStorage.builder().name(filename)
|
||||
.path(file.getPath())
|
||||
.size(FileUtil.getSize(item.getSize()))
|
||||
.suffix(type)
|
||||
.type(type).createTime(new Date()).build();
|
||||
result.add(storage);
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(result)){
|
||||
this.saveBatch(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public void download(List<LocalStorage> queryAll, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList();
|
||||
Iterator var4 = queryAll.iterator();
|
||||
|
||||
while(var4.hasNext()) {
|
||||
LocalStorage localStorageDTO = (LocalStorage)var4.next();
|
||||
Map<String, Object> map = new LinkedHashMap();
|
||||
map.put("文件名", localStorageDTO.getName());
|
||||
map.put("备注名", localStorageDTO.getName());
|
||||
map.put("文件类型", localStorageDTO.getType());
|
||||
map.put("文件大小", localStorageDTO.getSize());
|
||||
map.put("创建者", localStorageDTO.getCreateName());
|
||||
map.put("创建日期", localStorageDTO.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFile(LocalStorage localStorage, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
String path = localStorage.getPath();
|
||||
File file = new File(path);
|
||||
FileUtil.downloadFile(request, response,file,false);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.nl.common.localStorage.service.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.nl.common.localStorage.service.entity.LocalStorage;
|
||||
|
||||
@Mapper
|
||||
public interface LocalStorageMapper extends BaseMapper<LocalStorage> {
|
||||
|
||||
@Insert("INSERT INTO local_storage (name, suffix, path, type, size, order_code, create_time, create_name, update_time) VALUES (#{name}, #{suffix}, #{path}, #{type}, #{size}, #{orderCode}, #{createTime}, #{createName}, #{updateTime})")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
void insertUseGeneratedKeys(LocalStorage user);
|
||||
}
|
||||
73
nl-common/src/main/java/org/nl/common/page/BaseQuery.java
Normal file
73
nl-common/src/main/java/org/nl/common/page/BaseQuery.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package org.nl.common.page;
|
||||
|
||||
import cn.hutool.core.lang.ParameterizedTypeImpl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import org.nl.common.util.MapOf;
|
||||
|
||||
/**
|
||||
* 泛型必须为数据tb对应do:由mybatis管理
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 6:33 下午
|
||||
*/
|
||||
@Data
|
||||
public class BaseQuery<T> {
|
||||
/**
|
||||
* 模糊查询
|
||||
*/
|
||||
private String blurry;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private String is_used;
|
||||
/**
|
||||
* 创建时间范围查询
|
||||
*/
|
||||
private String start_time;
|
||||
private String end_time;
|
||||
|
||||
|
||||
/**
|
||||
* 字段映射Map:指定字段对应QueryWrapper的查询类型
|
||||
* 字段与数据库字段对应,不支持驼峰
|
||||
* @see org.nl.common.page.QueryTEnum
|
||||
* 通过buid构建
|
||||
*/
|
||||
public Map<String, QParam> doP = MapOf.of("blurry", QParam.builder().k(new String[]{"name"}).type(QueryTEnum.LK).build()
|
||||
,"startTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LT).build()
|
||||
,"endTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LE).build()
|
||||
,"sort", QParam.builder().k(new String[]{"sort"}).type(QueryTEnum.BY).build()
|
||||
);
|
||||
|
||||
public QueryWrapper<T> build(){
|
||||
this.paramMapping();
|
||||
QueryWrapper<T> wrapper = new QueryWrapper<>();
|
||||
JSONObject json = (JSONObject)JSONObject.toJSON(this);
|
||||
Type[] types = ((ParameterizedTypeImpl) this.getClass().getGenericSuperclass()).getActualTypeArguments();
|
||||
Map<String, ColumnCache> columnMap = LambdaUtils.getColumnMap((Class<?>) types[0]);
|
||||
|
||||
String dopStr = "doP";
|
||||
json.forEach((key, vel) -> {
|
||||
if (vel != null && !key.equals(dopStr)){
|
||||
QParam qParam = doP.get(key);
|
||||
if (qParam != null){
|
||||
QueryTEnum.build(qParam.type,wrapper,qParam.k,vel);
|
||||
}else {
|
||||
ColumnCache columnCache = columnMap.get(LambdaUtils.formatKey(key));
|
||||
if (columnCache!=null){
|
||||
wrapper.eq(columnCache.getColumn(),vel);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public void paramMapping(){};
|
||||
}
|
||||
19
nl-common/src/main/java/org/nl/common/page/LConsumer.java
Normal file
19
nl-common/src/main/java/org/nl/common/page/LConsumer.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.nl.common.page;
|
||||
|
||||
/**
|
||||
* s
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 8:40 下午
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LConsumer<X,Y,Z> {
|
||||
|
||||
/**
|
||||
* 切面
|
||||
* @param x 、
|
||||
* @param y 、
|
||||
* @param z 、
|
||||
*/
|
||||
void accept(X x,Y y,Z z);
|
||||
|
||||
}
|
||||
135
nl-common/src/main/java/org/nl/common/page/PageQuery.java
Normal file
135
nl-common/src/main/java/org/nl/common/page/PageQuery.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package org.nl.common.page;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 分页参数
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-11-16
|
||||
*/
|
||||
@Data
|
||||
public class PageQuery implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
private Integer size=100;
|
||||
|
||||
/**
|
||||
* 当前页数
|
||||
*/
|
||||
private Integer page=0;
|
||||
|
||||
/**
|
||||
* 排序列menu_sort,desc
|
||||
*/
|
||||
private String sort;
|
||||
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
private Boolean isAsc;
|
||||
|
||||
/**
|
||||
* 当前记录起始索引 默认值
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_NUM = 1;
|
||||
|
||||
/**
|
||||
* 每页显示记录数 默认值 默认查全部
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
||||
|
||||
public <T> Page<T> build() {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i = i + 2) {
|
||||
String col = split[i];
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i + 1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public static void trimStringFields(Object obj) {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Field[] fields = obj.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (field.getType() == String.class) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
String value = (String) field.get(obj);
|
||||
if (value != null) {
|
||||
field.set(obj, value.trim().toUpperCase());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <R, T> Page<T> build(Class<R> r) {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)) {
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
String col = split[i];
|
||||
if ("id".equals(col)){
|
||||
String mId = mappingId(r);
|
||||
col = StringUtils.isNotEmpty(mId)?mId:col;
|
||||
}
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private <R> String mappingId(R r){
|
||||
if (r instanceof Class){
|
||||
Field[] fields = ((Class) r).getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
TableId[] byType = field.getAnnotationsByType(TableId.class);
|
||||
if (byType !=null && byType.length>0){
|
||||
TableId tableId = byType[0];
|
||||
return tableId.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
14
nl-common/src/main/java/org/nl/common/page/QParam.java
Normal file
14
nl-common/src/main/java/org/nl/common/page/QParam.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.nl.common.page;
|
||||
|
||||
import lombok.Builder;
|
||||
|
||||
/**
|
||||
* s
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/15 1:41 下午
|
||||
*/
|
||||
@Builder
|
||||
public class QParam {
|
||||
public String[] k;
|
||||
public QueryTEnum type;
|
||||
}
|
||||
81
nl-common/src/main/java/org/nl/common/page/QueryTEnum.java
Normal file
81
nl-common/src/main/java/org/nl/common/page/QueryTEnum.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package org.nl.common.page;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* s
|
||||
*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 8:26 下午
|
||||
*/
|
||||
@Getter
|
||||
public enum QueryTEnum {
|
||||
//
|
||||
EQ((q, k, v) -> {
|
||||
q.eq(k[0], v);
|
||||
}),
|
||||
IN((q, key, o) -> {
|
||||
if (o instanceof Collection) {
|
||||
q.in(key[0], (Collection) o);
|
||||
}
|
||||
}),
|
||||
LK((q, keys, o) -> {
|
||||
for (String key : keys) {
|
||||
q.like(key, o);
|
||||
}
|
||||
}),
|
||||
ORLK((q, k, o) -> {
|
||||
q.and(query -> {
|
||||
QueryWrapper queryWrapper = (QueryWrapper) query;
|
||||
for (int i = 0; i < k.length; i++) {
|
||||
queryWrapper.like(k[i], o);
|
||||
if (i != (k.length - 1)) {
|
||||
queryWrapper.or();
|
||||
}
|
||||
}
|
||||
});
|
||||
}),
|
||||
LE((q, k, v) -> {
|
||||
q.le(k[0], v);
|
||||
}),
|
||||
GE((q, k, v) -> {
|
||||
q.ge(k[0], v);
|
||||
}),
|
||||
BY((q, k, v) -> {
|
||||
q.orderByDesc(k[0], String.valueOf(v));
|
||||
}),
|
||||
NO((q, k, v) -> {
|
||||
q.isNull(k[0]);
|
||||
}),
|
||||
NULL_OR_EMPTY((queryWrapper, k, v) -> {
|
||||
queryWrapper.nested(a -> a.isNull(k[0]).or().eq(k[0], ""));
|
||||
}),
|
||||
LT((q, k, v) -> {
|
||||
q.lt(k[0], v);
|
||||
}),
|
||||
GT((q, k, v) -> {
|
||||
q.gt(k[0], v);
|
||||
}),
|
||||
OREQ((q, k, v) -> {
|
||||
if (StringUtils.isBlank((String) v)) {
|
||||
q.isNull(k[0]);
|
||||
} else {
|
||||
q.eq(k[0], v);
|
||||
}
|
||||
});
|
||||
|
||||
private LConsumer<QueryWrapper<T>, String[], Object> doP;
|
||||
|
||||
QueryTEnum(LConsumer<QueryWrapper<T>, String[], Object> doP) {
|
||||
this.doP = doP;
|
||||
}
|
||||
|
||||
public static void build(QueryTEnum type, QueryWrapper q, String[] k, Object v) {
|
||||
type.getDoP().accept(q, k, v);
|
||||
}
|
||||
}
|
||||
242
nl-common/src/main/java/org/nl/common/util/FileProperties.java
Normal file
242
nl-common/src/main/java/org/nl/common/util/FileProperties.java
Normal file
@@ -0,0 +1,242 @@
|
||||
package org.nl.common.util;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(
|
||||
prefix = "file"
|
||||
)
|
||||
public class FileProperties {
|
||||
private Long maxSize;
|
||||
private Long avatarMaxSize;
|
||||
private ElPath mac;
|
||||
private ElPath linux;
|
||||
private ElPath windows;
|
||||
|
||||
public ElPath getPath() {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.toLowerCase().startsWith("win")) {
|
||||
return this.windows;
|
||||
} else {
|
||||
return os.toLowerCase().startsWith("mac") ? this.mac : this.linux;
|
||||
}
|
||||
}
|
||||
|
||||
public FileProperties() {
|
||||
}
|
||||
|
||||
public Long getMaxSize() {
|
||||
return this.maxSize;
|
||||
}
|
||||
|
||||
public Long getAvatarMaxSize() {
|
||||
return this.avatarMaxSize;
|
||||
}
|
||||
|
||||
public ElPath getMac() {
|
||||
return this.mac;
|
||||
}
|
||||
|
||||
public ElPath getLinux() {
|
||||
return this.linux;
|
||||
}
|
||||
|
||||
public ElPath getWindows() {
|
||||
return this.windows;
|
||||
}
|
||||
|
||||
public void setMaxSize(final Long maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public void setAvatarMaxSize(final Long avatarMaxSize) {
|
||||
this.avatarMaxSize = avatarMaxSize;
|
||||
}
|
||||
|
||||
public void setMac(final ElPath mac) {
|
||||
this.mac = mac;
|
||||
}
|
||||
|
||||
public void setLinux(final ElPath linux) {
|
||||
this.linux = linux;
|
||||
}
|
||||
|
||||
public void setWindows(final ElPath windows) {
|
||||
this.windows = windows;
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof FileProperties)) {
|
||||
return false;
|
||||
} else {
|
||||
FileProperties other = (FileProperties)o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
} else {
|
||||
label71: {
|
||||
Object this$maxSize = this.getMaxSize();
|
||||
Object other$maxSize = other.getMaxSize();
|
||||
if (this$maxSize == null) {
|
||||
if (other$maxSize == null) {
|
||||
break label71;
|
||||
}
|
||||
} else if (this$maxSize.equals(other$maxSize)) {
|
||||
break label71;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$avatarMaxSize = this.getAvatarMaxSize();
|
||||
Object other$avatarMaxSize = other.getAvatarMaxSize();
|
||||
if (this$avatarMaxSize == null) {
|
||||
if (other$avatarMaxSize != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$avatarMaxSize.equals(other$avatarMaxSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
label57: {
|
||||
Object this$mac = this.getMac();
|
||||
Object other$mac = other.getMac();
|
||||
if (this$mac == null) {
|
||||
if (other$mac == null) {
|
||||
break label57;
|
||||
}
|
||||
} else if (this$mac.equals(other$mac)) {
|
||||
break label57;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$linux = this.getLinux();
|
||||
Object other$linux = other.getLinux();
|
||||
if (this$linux == null) {
|
||||
if (other$linux != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$linux.equals(other$linux)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$windows = this.getWindows();
|
||||
Object other$windows = other.getWindows();
|
||||
if (this$windows == null) {
|
||||
if (other$windows == null) {
|
||||
return true;
|
||||
}
|
||||
} else if (this$windows.equals(other$windows)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof FileProperties;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
boolean PRIME = true;
|
||||
int result = 1;
|
||||
Object $maxSize = this.getMaxSize();
|
||||
result = result * 59 + ($maxSize == null ? 43 : $maxSize.hashCode());
|
||||
Object $avatarMaxSize = this.getAvatarMaxSize();
|
||||
result = result * 59 + ($avatarMaxSize == null ? 43 : $avatarMaxSize.hashCode());
|
||||
Object $mac = this.getMac();
|
||||
result = result * 59 + ($mac == null ? 43 : $mac.hashCode());
|
||||
Object $linux = this.getLinux();
|
||||
result = result * 59 + ($linux == null ? 43 : $linux.hashCode());
|
||||
Object $windows = this.getWindows();
|
||||
result = result * 59 + ($windows == null ? 43 : $windows.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "FileProperties(maxSize=" + this.getMaxSize() + ", avatarMaxSize=" + this.getAvatarMaxSize() + ", mac=" + this.getMac() + ", linux=" + this.getLinux() + ", windows=" + this.getWindows() + ")";
|
||||
}
|
||||
|
||||
public static class ElPath {
|
||||
private String path;
|
||||
private String avatar;
|
||||
|
||||
public ElPath() {
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return this.avatar;
|
||||
}
|
||||
|
||||
public void setPath(final String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void setAvatar(final String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof ElPath)) {
|
||||
return false;
|
||||
} else {
|
||||
ElPath other = (ElPath)o;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
} else {
|
||||
Object this$path = this.getPath();
|
||||
Object other$path = other.getPath();
|
||||
if (this$path == null) {
|
||||
if (other$path != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$path.equals(other$path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object this$avatar = this.getAvatar();
|
||||
Object other$avatar = other.getAvatar();
|
||||
if (this$avatar == null) {
|
||||
if (other$avatar != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this$avatar.equals(other$avatar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof ElPath;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
boolean PRIME = true;
|
||||
int result = 1;
|
||||
Object $path = this.getPath();
|
||||
result = result * 59 + ($path == null ? 43 : $path.hashCode());
|
||||
Object $avatar = this.getAvatar();
|
||||
result = result * 59 + ($avatar == null ? 43 : $avatar.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "FileProperties.ElPath(path=" + this.getPath() + ", avatar=" + this.getAvatar() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
273
nl-common/src/main/java/org/nl/common/util/FileUtil.java
Normal file
273
nl-common/src/main/java/org/nl/common/util/FileUtil.java
Normal file
@@ -0,0 +1,273 @@
|
||||
package org.nl.common.util;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.nl.common.exception.CommonException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||
public static final String SYS_TEM_DIR;
|
||||
private static final int GB = 1073741824;
|
||||
private static final int MB = 1048576;
|
||||
private static final int KB = 1024;
|
||||
private static final DecimalFormat DF;
|
||||
public static final String IMAGE = "图片";
|
||||
public static final String TXT = "文档";
|
||||
public static final String MUSIC = "音乐";
|
||||
public static final String VIDEO = "视频";
|
||||
public static final String OTHER = "其他";
|
||||
|
||||
public FileUtil() {
|
||||
}
|
||||
|
||||
public static File toFile(MultipartFile multipartFile) {
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
String prefix = "." + getExtensionName(fileName);
|
||||
File file = null;
|
||||
|
||||
try {
|
||||
file = new File(SYS_TEM_DIR + IdUtil.simpleUUID() + prefix);
|
||||
multipartFile.transferTo(file);
|
||||
} catch (IOException var5) {
|
||||
IOException e = var5;
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public static String getExtensionName(String filename) {
|
||||
if (filename != null && filename.length() > 0) {
|
||||
int dot = filename.lastIndexOf(46);
|
||||
if (dot > -1 && dot < filename.length() - 1) {
|
||||
return filename.substring(dot + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
public static String getFileNameNoEx(String filename) {
|
||||
if (filename != null && filename.length() > 0) {
|
||||
int dot = filename.lastIndexOf(46);
|
||||
if (dot > -1 && dot < filename.length()) {
|
||||
return filename.substring(0, dot);
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
public static String getSize(long size) {
|
||||
String resultSize;
|
||||
if (size / 1073741824L >= 1L) {
|
||||
resultSize = DF.format((double)((float)size / 1.07374182E9F)) + "GB ";
|
||||
} else if (size / 1048576L >= 1L) {
|
||||
resultSize = DF.format((double)((float)size / 1048576.0F)) + "MB ";
|
||||
} else if (size / 1024L >= 1L) {
|
||||
resultSize = DF.format((double)((float)size / 1024.0F)) + "KB ";
|
||||
} else {
|
||||
resultSize = size + "B ";
|
||||
}
|
||||
|
||||
return resultSize;
|
||||
}
|
||||
|
||||
static File inputStreamToFile(InputStream ins, String name) throws Exception {
|
||||
File file = new File(SYS_TEM_DIR + name);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
} else {
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
int len = 8192;
|
||||
byte[] buffer = new byte[len];
|
||||
|
||||
int bytesRead;
|
||||
while((bytesRead = ins.read(buffer, 0, len)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
os.close();
|
||||
ins.close();
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
public static File upload(MultipartFile file, String filePath) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
|
||||
String name = getFileNameNoEx(file.getOriginalFilename());
|
||||
String suffix = getExtensionName(file.getOriginalFilename());
|
||||
String nowStr = "-" + format.format(date);
|
||||
|
||||
try {
|
||||
String fileName = name + nowStr + "." + suffix;
|
||||
String path = filePath + fileName;
|
||||
File dest = (new File(path)).getCanonicalFile();
|
||||
if (!dest.getParentFile().exists() && !dest.getParentFile().mkdirs()) {
|
||||
System.out.println("was not successful.");
|
||||
}
|
||||
|
||||
file.transferTo(dest);
|
||||
return dest;
|
||||
} catch (Exception var10) {
|
||||
Exception e = var10;
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
||||
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||
File file = new File(tempPath);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||
writer.write(list, true);
|
||||
SXSSFSheet sheet = (SXSSFSheet)writer.getSheet();
|
||||
sheet.trackAllColumnsForAutoSizing();
|
||||
writer.autoSizeColumnAll();
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
file.deleteOnExit();
|
||||
writer.flush(out, true);
|
||||
IoUtil.close(out);
|
||||
}
|
||||
|
||||
public static String getFileType(String type) {
|
||||
String documents = "txt doc pdf ppt pps xlsx xls docx";
|
||||
String music = "mp3 wav wma mpa ram ra aac aif m4a";
|
||||
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
|
||||
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg svg";
|
||||
if (image.contains(type)) {
|
||||
return "图片";
|
||||
} else if (documents.contains(type)) {
|
||||
return "文档";
|
||||
} else if (music.contains(type)) {
|
||||
return "音乐";
|
||||
} else {
|
||||
return video.contains(type) ? "视频" : "其他";
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkSize(long maxSize, long size) {
|
||||
int len = 1048576;
|
||||
if (size > maxSize * (long)len) {
|
||||
throw new CommonException("文件超出规定大小");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean check(File file1, File file2) {
|
||||
String img1Md5 = getMd5(file1);
|
||||
String img2Md5 = getMd5(file2);
|
||||
return img1Md5.equals(img2Md5);
|
||||
}
|
||||
|
||||
public static boolean check(String file1Md5, String file2Md5) {
|
||||
return file1Md5.equals(file2Md5);
|
||||
}
|
||||
|
||||
private static byte[] getByte(File file) {
|
||||
byte[] b = new byte[(int)file.length()];
|
||||
|
||||
try {
|
||||
InputStream in = new FileInputStream(file);
|
||||
|
||||
try {
|
||||
System.out.println(in.read(b));
|
||||
} catch (IOException var4) {
|
||||
IOException e = var4;
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return b;
|
||||
} catch (FileNotFoundException var5) {
|
||||
FileNotFoundException e = var5;
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMd5(byte[] bytes) {
|
||||
char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
try {
|
||||
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
||||
mdTemp.update(bytes);
|
||||
byte[] md = mdTemp.digest();
|
||||
int j = md.length;
|
||||
char[] str = new char[j * 2];
|
||||
int k = 0;
|
||||
byte[] var7 = md;
|
||||
int var8 = md.length;
|
||||
|
||||
for(int var9 = 0; var9 < var8; ++var9) {
|
||||
byte byte0 = var7[var9];
|
||||
str[k++] = hexDigits[byte0 >>> 4 & 15];
|
||||
str[k++] = hexDigits[byte0 & 15];
|
||||
}
|
||||
|
||||
return new String(str);
|
||||
} catch (Exception var11) {
|
||||
Exception e = var11;
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) {
|
||||
response.setCharacterEncoding(request.getCharacterEncoding());
|
||||
response.setContentType("application/octet-stream");
|
||||
FileInputStream fis = null;
|
||||
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
|
||||
IOUtils.copy(fis, response.getOutputStream());
|
||||
response.flushBuffer();
|
||||
} catch (Exception var14) {
|
||||
Exception e = var14;
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
if (deleteOnExit) {
|
||||
file.deleteOnExit();
|
||||
}
|
||||
} catch (IOException var13) {
|
||||
IOException e = var13;
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getMd5(File file) {
|
||||
return getMd5(getByte(file));
|
||||
}
|
||||
|
||||
static {
|
||||
SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator;
|
||||
DF = new DecimalFormat("0.00");
|
||||
}
|
||||
}
|
||||
20
nl-common/src/main/java/org/nl/common/util/MapOf.java
Normal file
20
nl-common/src/main/java/org/nl/common/util/MapOf.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nl.common.util;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/11/29 2:55 下午
|
||||
*/
|
||||
public class MapOf implements Serializable {
|
||||
|
||||
public static <K> HashMap of(K... key) {
|
||||
HashMap map = new HashMap<>();
|
||||
for (int i = 0; i < (key.length & ~1); i = i + 2) {
|
||||
map.put(key[i], key[i + 1]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user