|  |  |  | 
|---|
|  |  |  | import com.dy.pmsGlobal.dyFile.FileRestVo; | 
|---|
|  |  |  | import com.dy.pmsGlobal.dyFile.FileVo; | 
|---|
|  |  |  | import com.dy.pmsGlobal.pojoOth.OthFile; | 
|---|
|  |  |  | import jakarta.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * web文件上传示例 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Value("${dy.webFile.fmUrl}") | 
|---|
|  |  |  | private String fmUrl ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上传照片图片文件 (当前只对png jpg格式图片支持缩略图) | 
|---|
|  |  |  | * @param file | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/upPhoto") | 
|---|
|  |  |  | @SsoPowerAop(power = "-1") //登录与权限同时验证 | 
|---|
|  |  |  | //https://blog.zhengru.top/posts/33486.html#%E5%8D%95%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0 | 
|---|
|  |  |  | public BaseResponse<?> upPhoto(MultipartFile file, HttpServletRequest req) { | 
|---|
|  |  |  | public BaseResponse<?> upPhoto(MultipartFile file) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (file != null) { | 
|---|
|  |  |  | String[] fileNameGrp = fileOp.splitFileName(file) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | null); | 
|---|
|  |  |  | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; | 
|---|
|  |  |  | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath())) ; | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()), frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; | 
|---|
|  |  |  | return  BaseResponseUtils.buildSuccess(fvo) ; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上传录音音频文件 | 
|---|
|  |  |  | * @param file | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/upPhone") | 
|---|
|  |  |  | @SsoPowerAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<?> upPhone(MultipartFile file, HttpServletRequest req) { | 
|---|
|  |  |  | public BaseResponse<?> upPhone(MultipartFile file) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (file != null) { | 
|---|
|  |  |  | String[] fileNameGrp = fileOp.splitFileName(file) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | null); | 
|---|
|  |  |  | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; | 
|---|
|  |  |  | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null) ; | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; | 
|---|
|  |  |  | return  BaseResponseUtils.buildSuccess(fvo) ; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上传录像视频文件 | 
|---|
|  |  |  | * @param file | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/upVideo") | 
|---|
|  |  |  | @SsoPowerAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<?> upVideo(MultipartFile file, HttpServletRequest req) { | 
|---|
|  |  |  | public BaseResponse<?> upVideo(MultipartFile file) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (file != null) { | 
|---|
|  |  |  | String[] fileNameGrp = fileOp.splitFileName(file) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | null); | 
|---|
|  |  |  | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; | 
|---|
|  |  |  | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null) ; | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; | 
|---|
|  |  |  | return  BaseResponseUtils.buildSuccess(fvo) ; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上传文档文件 | 
|---|
|  |  |  | * @param file | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/upDocument") | 
|---|
|  |  |  | @SsoPowerAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<?> upDocument(MultipartFile file, HttpServletRequest req) { | 
|---|
|  |  |  | public BaseResponse<?> upDocument(MultipartFile file) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (file != null) { | 
|---|
|  |  |  | String[] fileNameGrp = fileOp.splitFileName(file) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | null); | 
|---|
|  |  |  | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; | 
|---|
|  |  |  | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null) ; | 
|---|
|  |  |  | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; | 
|---|
|  |  |  | return  BaseResponseUtils.buildSuccess(fvo) ; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); | 
|---|
|  |  |  | 
|---|
|  |  |  | po.newName = newName ; | 
|---|
|  |  |  | po.hash = hash ; | 
|---|
|  |  |  | po.filePath = filePath ; | 
|---|
|  |  |  | po.dt = new Date() ; | 
|---|
|  |  |  | return this.sv.save(po) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|