liurunyu
2024-10-19 9cb1f5cf9cc383d8f09b0735e75ee7a0ef181804
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/WebFileCtrl.java
@@ -20,12 +20,11 @@
import java.util.Date;
/**
 * web文件上传示例
 * web文件上传
 */
@Slf4j
@RestController
@RequestMapping(path="webFile")
@SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked"
public class WebFileCtrl {
    @Autowired
@@ -36,18 +35,19 @@
    @Value("${dy.webFile.fmUrl}")
    private String fmUrl ;
    //支持的文件类型
    //支持的文档文件类型
    @Value("${dy.webFile.supportedFileTypes}")
    private String supportedFileTypes ;
    /**
     * 上传照片图片文件 (当前只对png jpg格式图片支持缩略图)
     * @param file
     * @return
     * @param file web端上传文件的post对象
     * @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
    //参考: 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) {
        try {
            if (file != null) {
@@ -63,7 +63,13 @@
                                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()), frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
                        FileVo fvo = new FileVo(id,
                                frVo.fileNameHash,
                                fileNameGrp[0],
                                fileNameGrp[1],
                                (frVo.getFileWebUrl() + frVo.getFileWebPath()),
                                fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()),
                                frVo.fileWebDownloadPath + id) ;
                        return  BaseResponseUtils.buildSuccess(fvo) ;
                    }else {
                        return BaseResponseUtils.buildError("未得到上传文件的扩展名");
@@ -82,8 +88,8 @@
    /**
     * 上传录音音频文件
     * @param file
     * @return
     * @param file web端上传文件的post对象
     * @return 返回结果
     */
    @PostMapping("/upPhone")
    @SsoPowerAop(power = "-1")
@@ -102,7 +108,13 @@
                                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, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
                        FileVo fvo = new FileVo(id,
                                frVo.fileNameHash,
                                fileNameGrp[0],
                                fileNameGrp[1],
                                frVo.getFileWebUrl() + frVo.getFileWebPath(),
                                null,
                                frVo.fileWebDownloadPath + id) ;
                        return  BaseResponseUtils.buildSuccess(fvo) ;
                    }else {
                        return BaseResponseUtils.buildError("未得到上传文件的扩展名");
@@ -122,8 +134,8 @@
    /**
     * 上传录像视频文件
     * @param file
     * @return
     * @param file web端上传文件的post对象
     * @return 返回结果
     */
    @PostMapping("/upVideo")
    @SsoPowerAop(power = "-1")
@@ -142,7 +154,13 @@
                                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, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
                        FileVo fvo = new FileVo(id,
                                frVo.fileNameHash,
                                fileNameGrp[0],
                                fileNameGrp[1],
                                frVo.getFileWebUrl() + frVo.getFileWebPath(),
                                null,
                                frVo.fileWebDownloadPath + id) ;
                        return  BaseResponseUtils.buildSuccess(fvo) ;
                    }else {
                        return BaseResponseUtils.buildError("未得到上传文件的扩展名");
@@ -162,8 +180,8 @@
    /**
     * 上传文档文件
     * @param file
     * @return
     * @param file web端上传文件的post对象
     * @return 返回结果
     */
    @PostMapping("/upDocument")
    @SsoPowerAop(power = "-1")
@@ -186,7 +204,12 @@
                                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, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ;
                        FileVo fvo = new FileVo(id,
                                frVo.fileNameHash,
                                fileNameGrp[0], fileNameGrp[1],
                                frVo.getFileWebUrl() + frVo.getFileWebPath(),
                                null,
                                frVo.fileWebDownloadPath + id) ;
                        return  BaseResponseUtils.buildSuccess(fvo) ;
                    }else {
                        return BaseResponseUtils.buildError("未得到上传文件的扩展名");
@@ -211,7 +234,7 @@
     * @param newName 文件新名称
     * @param hash  文件新名称的哈希值
     * @param filePath 文件服务端存储相对路径
     * @return
     * @return 数据记录主键
     */
    private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath){
        OthFile po = new OthFile() ;