管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-03-25 b6b0cb226fcf184525ee7b36af3a09471e9c0057
src/main/java/com/lf/server/controller/data/StyleController.java
@@ -1,12 +1,18 @@
package com.lf.server.controller.data;
import com.lf.server.aspect.SysLog;
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.HttpStatus;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.ctrl.DownloadReqEntity;
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.data.StyleEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.UploadService;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.all.UploadAttachService;
import com.lf.server.service.data.DownloadService;
import com.lf.server.service.data.StyleService;
import com.lf.server.service.sys.DownlogService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -36,9 +42,15 @@
    TokenService tokenService;
    @Autowired
    UploadService uploadService;
    DownloadService downloadService;
    private final static String TAB_NAME = "sys_style";
    @Autowired
    DownlogService downlogService;
    @Autowired
    UploadAttachService uploadAttachService;
    private final static String TAB_NAME = "lf.sys_style";
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -52,7 +64,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -74,7 +86,7 @@
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -102,14 +114,14 @@
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "com.lf.server.entity.data.StyleEntity", paramType = "body", example = "")
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "StyleEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertStyle", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertStyle(@RequestBody StyleEntity entity, HttpServletRequest req) {
@@ -123,14 +135,14 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "com.lf.server.entity.data.StyleEntity", paramType = "body", example = "")
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "StyleEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertStyles", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertStyles(@RequestBody List<StyleEntity> list, HttpServletRequest req) {
@@ -146,7 +158,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -162,7 +174,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -182,7 +194,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -204,7 +216,7 @@
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
            return fail(ex, -1);
        }
    }
@@ -220,7 +232,7 @@
            return success(styleEntity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -233,7 +245,7 @@
            List<StyleEntity> list = styleService.selectStyleAll();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
            return fail(ex, null);
        }
    }
@@ -244,7 +256,7 @@
    public ResponseMsg<String> upload(@RequestParam("file") MultipartFile file, HttpServletRequest req) {
        UserEntity ue = tokenService.getCurrentUser(req);
        return uploadService.upload(ue, TAB_NAME, file, this);
        return uploadAttachService.upload(ue, TAB_NAME, file, this);
    }
    @SysLog()
@@ -254,6 +266,56 @@
    })
    @GetMapping(value = "/download")
    public void download(String guid, HttpServletResponse res) {
        uploadService.download(guid, res);
        uploadAttachService.download(guid, res);
    }
    @SysLog()
    @ApiOperation(value = "下载文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
    public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                WebHelper.writeStr2Page(res, WebHelper.getErrJson(HttpStatus.UNAUTHORIZED, "用户未登录"));
            }
            DownloadEntity de = downloadService.selectByGuid(guid);
            if (de == null) {
                WebHelper.writeStr2Page(res, WebHelper.getErrJson(HttpStatus.NOT_FOUND, "文件不存在"));
            }
            downlogService.updateInfos(ue, de, req);
            String filePath = downloadService.getDownloadFilePath(de);
            WebHelper.download(filePath, de.getName(), res);
        } catch (Exception ex) {
            WebHelper.writeStr2Page(res, WebHelper.getErrJson(HttpStatus.UNAUTHORIZED, ex.getMessage()));
            log.error(ex.getMessage(), ex);
        }
    }
    @SysLog()
    @ApiOperation(value = "请求下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guids", value = "附件Guid数组", dataType = "String", paramType = "body", allowMultiple = true, example = "e5b6ae0889b88111f13a4b6e048348db,fa4f299e901a0c46e634f8fcc8185c0c")
    })
    @ResponseBody
    @PostMapping(value = "/downloadReqForGuids")
    public ResponseMsg<Object> downloadReqForGuids(@RequestBody DownloadReqEntity dre, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (null == dre || null == dre.getGuids() || dre.getGuids().isEmpty()) {
                return fail("Guid数组为空");
            }
            UserEntity ue = tokenService.getCurrentUser(req);
            String guid = uploadAttachService.downloadReqForGuids(ue, dre.getGuids());
            return success(guid);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
}