Merge branch 'feature/gongfu' into feature/data-permission
This commit is contained in:
commit
8a6bbcc7a1
|
|
@ -11,7 +11,7 @@ public class FileSearch1Request extends PageRequest {
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型,0:派工单
|
* 类型,0:派工单,1:服务月报
|
||||||
*/
|
*/
|
||||||
private Integer type;
|
private Integer type;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,30 @@
|
||||||
package com.nflg.mobilebroken.gongfu.controller;
|
package com.nflg.mobilebroken.gongfu.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||||
import com.nflg.mobilebroken.common.pojo.PageData;
|
import com.nflg.mobilebroken.common.pojo.PageData;
|
||||||
import com.nflg.mobilebroken.common.pojo.request.FileSearch1Request;
|
import com.nflg.mobilebroken.common.pojo.request.FileSearch1Request;
|
||||||
|
import com.nflg.mobilebroken.common.util.AdminUserUtil;
|
||||||
|
import com.nflg.mobilebroken.gongfu.pojo.query.FileUploadQuery;
|
||||||
import com.nflg.mobilebroken.repository.entity.GongfuFile;
|
import com.nflg.mobilebroken.repository.entity.GongfuFile;
|
||||||
|
import com.nflg.mobilebroken.repository.service.IFileUploadRecordService;
|
||||||
import com.nflg.mobilebroken.repository.service.IGongfuFileService;
|
import com.nflg.mobilebroken.repository.service.IGongfuFileService;
|
||||||
|
import com.nflg.mobilebroken.starter.service.FileUploadService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -27,14 +36,19 @@ import java.util.Objects;
|
||||||
@RequestMapping("/file")
|
@RequestMapping("/file")
|
||||||
public class FileController extends ControllerBase {
|
public class FileController extends ControllerBase {
|
||||||
|
|
||||||
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IGongfuFileService fileService;
|
private IGongfuFileService fileService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileUploadService fileUploadService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件搜索
|
* 文件搜索
|
||||||
*/
|
*/
|
||||||
@PostMapping("/search")
|
@PostMapping("/search")
|
||||||
public ApiResult<PageData<GongfuFile>> search(@Valid @RequestBody FileSearch1Request request) {
|
public ApiResult<PageData<GongfuFile>> search(@RequestBody FileSearch1Request request) {
|
||||||
return ApiResult.success(
|
return ApiResult.success(
|
||||||
fileService.lambdaQuery()
|
fileService.lambdaQuery()
|
||||||
.eq(Objects.nonNull(request.getType()), GongfuFile::getType, request.getType())
|
.eq(Objects.nonNull(request.getType()), GongfuFile::getType, request.getType())
|
||||||
|
|
@ -43,6 +57,37 @@ public class FileController extends ControllerBase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传
|
||||||
|
* @param type 类型,1:服务月报
|
||||||
|
* @param fileName 文件名称
|
||||||
|
* @param file 文件
|
||||||
|
*/
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public ApiResult<Void> upload(@RequestParam Integer type,@RequestParam String fileName,@RequestParam MultipartFile file) throws IOException {
|
||||||
|
String url = fileUploadService.upload(buildFilePath(getFileType(file.getOriginalFilename())), file);
|
||||||
|
fileService.save(
|
||||||
|
new GongfuFile()
|
||||||
|
.setType(type)
|
||||||
|
.setFileName(fileName)
|
||||||
|
.setFileSize(file.getSize())
|
||||||
|
.setFileSuffix(FilenameUtils.getExtension(file.getOriginalFilename()))
|
||||||
|
.setFileUrl(url)
|
||||||
|
.setCreateBy(AdminUserUtil.getUserName())
|
||||||
|
.setCreateTime(LocalDateTime.now())
|
||||||
|
);
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildFilePath(String fileType) {
|
||||||
|
return StrUtil.format("gongfu/{}/{}/{}/{}{}", LocalDateTime.now().format(FORMATTER), AdminUserUtil.getUserId()
|
||||||
|
, RandomUtil.randomString(4), IdUtil.fastUUID(), fileType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFileType(String fileName) {
|
||||||
|
return "." + FilenameUtils.getExtension(fileName).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件删除
|
* 文件删除
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.nflg.mobilebroken.gongfu.pojo.query;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FileUploadQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型,1:服务月报
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名称
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private MultipartFile file;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue