| | |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.RoleConstant; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.DateTimeUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | import org.sxkj.common.model.TimeRange; |
| | | import org.sxkj.common.utils.HeaderUtils; |
| | | import org.sxkj.common.utils.TimeRangeUtils; |
| | | import org.sxkj.resource.dto.AttachDto; |
| | | import org.sxkj.resource.dto.WaylineJobInfoQueryDto; |
| | | import org.sxkj.resource.dto.WaylineJobInfoQueryParam; |
| | | import org.sxkj.resource.entity.Attach; |
| | | import org.sxkj.resource.feign.IAttachClient; |
| | | import org.sxkj.resource.param.AttachPageParam; |
| | | import org.sxkj.resource.param.AttachParam; |
| | | import org.sxkj.resource.service.IAttachService; |
| | | import org.sxkj.resource.vo.*; |
| | | import org.sxkj.system.vo.TreeVo; |
| | |
| | | |
| | | private final IAttachService attachService; |
| | | |
| | | private final IAttachClient attachClient; |
| | | |
| | | /** |
| | | * 详情 |
| | | */ |
| | | @GetMapping("/detail") |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "附件详情", notes = "传入attach") |
| | | public R<Attach> detail(Attach attach) { |
| | | Attach detail = attachService.getOne(Condition.getQueryWrapper(attach)); |
| | | public R<Attach> detail(AttachParam attach) { |
| | | Attach detail = attachService.getOne(Wrappers.lambdaQuery(Attach.class).eq(Attach::getId, attach.getId())); |
| | | return R.data(detail); |
| | | } |
| | | |
| | |
| | | @GetMapping("/page") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "附件分页", notes = "传入attach") |
| | | public R<IPage<AttachVO>> page(AttachVO attach, Query query) { |
| | | String areaCode = HeaderUtils.getAreaCode(); |
| | | attach.setAreaCode(areaCode); |
| | | public R<IPage<AttachVO>> page(AttachPageParam attach, Query query) { |
| | | IPage<AttachVO> pages = attachService.selectAttachPage(Condition.getPage(query), attach); |
| | | AttachVO.settingNickName(pages.getRecords()); |
| | | return R.data(pages); |
| | | } |
| | | |
| | |
| | | @PostMapping("/submit") |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "新增或修改", notes = "传入attach") |
| | | public R submit(@Valid @RequestBody Attach attach) { |
| | | public R submit(@Valid @RequestBody AttachDto attachDto) { |
| | | Attach attach = Objects.requireNonNull(BeanUtil.copy(attachDto, Attach.class)); |
| | | return R.status(attachService.saveOrUpdate(attach)); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 分页 附件表 |
| | | */ |
| | | // @GetMapping("/list") |
| | | // @ApiOperationSupport(order = 2) |
| | | // @ApiOperation(value = "附件分页", notes = "传入attach") |
| | | // public R<IPage<Attach>> list(Attach attach, Query query) { |
| | | // List<String> wayLineJobIds = attach.getWayLineJobIds(); |
| | | // QueryWrapper<Attach> queryWrapper1 = Condition.getQueryWrapper(attach); |
| | | // QueryWrapper<Attach> queryWrapper = queryWrapper1.in(!CollectionUtils.isEmpty(wayLineJobIds), "wayline_job_id", wayLineJobIds); |
| | | // queryWrapper.eq("is_deleted", 0); |
| | | // IPage<Attach> pages = attachService.page(Condition.getPage(query), queryWrapper); |
| | | // return R.data(pages); |
| | | // } |
| | | @GetMapping("/list") |
| | | @ApiOperationSupport(order = 2) |
| | | @ApiOperation(value = "附件分页", notes = "传入attach") |
| | | public R<IPage<Attach>> list(Attach attach, Query query) { |
| | | List<String> wayLineJobIds = attach.getWayLineJobIds(); |
| | | QueryWrapper<Attach> queryWrapper1 = Condition.getQueryWrapper(attach); |
| | | QueryWrapper<Attach> queryWrapper = queryWrapper1.in(!CollectionUtils.isEmpty(wayLineJobIds), "wayline_job_id", wayLineJobIds); |
| | | queryWrapper.eq("is_deleted", 0); |
| | | IPage<Attach> pages = attachService.page(Condition.getPage(query), queryWrapper); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | /** |
| | | * 自定义分页 附件表 |
| | |
| | | /** |
| | | * 新增 附件表 |
| | | */ |
| | | // @PostMapping("/save") |
| | | // @ApiOperationSupport(order = 4) |
| | | // @ApiOperation(value = "新增", notes = "传入attach") |
| | | // public R save(@Valid @RequestBody Attach attach) { |
| | | // return R.status(attachService.save(attach)); |
| | | // } |
| | | @PostMapping("/save") |
| | | @ApiOperationSupport(order = 4) |
| | | @ApiOperation(value = "新增", notes = "传入attach") |
| | | public R save(@Valid @RequestBody Attach attach) { |
| | | return R.status(attachService.save(attach)); |
| | | } |
| | | |
| | | /** |
| | | * 修改 附件表 |
| | | */ |
| | | // @PostMapping("/update") |
| | | // @ApiOperationSupport(order = 5) |
| | | // @ApiOperation(value = "修改", notes = "传入attach") |
| | | // public R update(@Valid @RequestBody Attach attach) { |
| | | // return R.status(attachService.updateById(attach)); |
| | | // } |
| | | @PostMapping("/update") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "修改", notes = "传入attach") |
| | | public R update(@Valid @RequestBody Attach attach) { |
| | | return R.status(attachService.updateById(attach)); |
| | | } |
| | | |
| | | /** |
| | | * 流式附件下载接口,支持下载zip压缩包,不使用本地存储 |
| | | * @param param |
| | | * @param response |
| | | * @throws IOException |
| | | */ |
| | | @ApiOperation(value = "流式附件下载接口", notes = "使用流方式返回数据,不使用本地存储") |
| | | @PostMapping("/downloadByByte") |
| | | public void downloadByByte( |
| | | @ApiParam(value = "附件下载参数") @RequestBody AttachmentDownloadParam param, |
| | | HttpServletResponse response) throws IOException { |
| | | |
| | | // 设置文件名 |
| | | String timestamp = DateTimeUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmss"); |
| | | String fileName = "attachments_" + timestamp + ".zip"; |
| | | |
| | | // 设置响应头 |
| | | response.setContentType("application/zip"); |
| | | response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())); |
| | | |
| | | // 获取响应输出流 |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | outputStream = response.getOutputStream(); |
| | | |
| | | Boolean result = attachService.downloadByByte(param, outputStream); |
| | | if (!result) { |
| | | return; |
| | | } |
| | | } catch (Exception e) { |
| | | if (!response.isCommitted()) { |
| | | response.reset(); |
| | | response.setContentType("application/json;charset=UTF-8"); |
| | | ResponseResult errorResult = ResponseResult.error("下载文件失败: " + e.getMessage()); |
| | | |
| | | // 使用输出流写入错误信息,避免getWriter()冲突 |
| | | try { |
| | | byte[] errorBytes = JSON.toJSONString(errorResult).getBytes(StandardCharsets.UTF_8); |
| | | outputStream.write(errorBytes); |
| | | } catch (IOException ioException) { |
| | | log.error("Error writing error response: {}", ioException.getMessage()); |
| | | } |
| | | } else { |
| | | log.error("Cannot send error response: response already committed. Exception: {}", e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除 附件表及对应的附件信息 |