管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-23 298a420d8fa2435e2ca2fd7f4afa47118695f6bf
1
已修改2个文件
89 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/MetaController.java 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/show/ExportController.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/MetaController.java
@@ -2,10 +2,14 @@
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.data.DownloadEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.data.DownloadService;
import com.lf.server.service.data.MetaService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -16,6 +20,7 @@
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@@ -31,6 +36,9 @@
    @Autowired
    TokenService tokenService;
    @Autowired
    DownloadService downloadService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -252,4 +260,65 @@
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "请求下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pwd", value = "密码", dataType = "String", paramType = "body", example = ""),
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "body", example = "1,2")
    })
    @PostMapping(value = "/downloadReq")
    public ResponseMsg<Object> downloadReq(@RequestParam String pwd, @RequestParam List<Integer> ids, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (StringHelper.isEmpty(pwd)) {
                return fail("密码不能为空");
            }
            if (null == ids || ids.isEmpty()) {
                return fail("请选择要下载的文件");
            }
            return success(true);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @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) {
                writeInfo(HttpStatus.UNAUTHORIZED, "用户未登录", res);
                return;
            }
            DownloadEntity de = downloadService.selectByGuid(guid);
            if (de == null) {
                writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res);
                return;
            }
            de.setDcount(de.getDcount() + 1);
            de.setDownloadUser(ue.getId());
            int rows = downloadService.update(de);
            //String filePath = exportService.getDownloadFilePath(de);
            //WebHelper.download(filePath, de.getName(), res);
        } catch (Exception ex) {
            writeInfo(HttpStatus.ERROR, ex.getMessage(), res);
        }
    }
    private void writeInfo(HttpStatus status, String info, HttpServletResponse res) {
        try {
            WebHelper.write2Page(res, WebHelper.getErrJson(status, info));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
src/main/java/com/lf/server/controller/show/ExportController.java
@@ -114,12 +114,14 @@
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.UNAUTHORIZED, "用户未登录"));
                writeInfo(HttpStatus.UNAUTHORIZED, "用户未登录", res);
                return;
            }
            DownloadEntity de = downloadService.selectByGuid(guid);
            if (de == null) {
                WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.NOT_FOUND, "文件不存在"));
                writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res);
                return;
            }
            de.setDcount(de.getDcount() + 1);
@@ -129,11 +131,15 @@
            String filePath = exportService.getDownloadFilePath(de);
            WebHelper.download(filePath, de.getName(), res);
        } catch (Exception ex) {
            try {
                WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.UNAUTHORIZED, ex.getMessage()));
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
            writeInfo(HttpStatus.ERROR, ex.getMessage(), res);
        }
    }
    private void writeInfo(HttpStatus status, String info, HttpServletResponse res) {
        try {
            WebHelper.write2Page(res, WebHelper.getErrJson(status, info));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}