| | |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ltkj.common.core.controller.BaseController; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.common.core.page.TableDataInfo; |
| | | import com.ltkj.common.utils.SecurityUtils; |
| | | import com.ltkj.common.utils.StringUtils; |
| | | import com.ltkj.framework.config.UserHoder; |
| | | import com.ltkj.hosp.domain.*; |
| | | import com.ltkj.hosp.service.*; |
| | | import com.ltkj.mall.mallOrderUtils.TjConstants; |
| | | import com.ltkj.web.config.pdfutils.PDFBinaryUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.server.session.InMemoryWebSessionStore; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URL; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | |
| | | return AjaxResult.success("该客户在没有体检项目数据!"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序点击体检报告查询详情,显示身高体重体重指数收缩压舒张压 |
| | | */ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序点击下载报告 |
| | | */ |
| | | @GetMapping("/downloadReport") |
| | | @ApiOperation(value = "小程序-下载报告") |
| | | public AjaxResult downloadReport(@RequestParam @ApiParam(value = "体检号") String tjNumber) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | return AjaxResult.success(map); |
| | | Map<String,String> res=new HashMap<>(); |
| | | LambdaQueryWrapper<TjReport> we = new LambdaQueryWrapper<>(); |
| | | we.eq(TjReport::getTjNumber, tjNumber); |
| | | we.eq(TjReport::getType, "体检报告"); |
| | | TjReport one = reportService.getOne(we); |
| | | if ("pdf".equals(one.getPrint())){ |
| | | res.put("flag","0"); |
| | | res.put("url",one.getPath()); |
| | | return AjaxResult.success(res); |
| | | }else if ("报表".equals(one.getPrint())){ |
| | | res.put("flag","1"); |
| | | res.put("url",one.getPath()); |
| | | return AjaxResult.success(res); |
| | | }else { |
| | | return AjaxResult.error("暂无体检报告"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @GetMapping("/preview/{flag}/{TjNumber}") |
| | | @ApiOperation(value = "下载体检报告") |
| | | public void preview(HttpServletResponse response, @PathVariable("flag") boolean flag, @PathVariable("TjNumber") String tjNumber) { |
| | | //修改order表中的下载报告时间为当前时间 |
| | | // LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | // updateWrapper.eq(TjOrder::getTjNumber, tjNumber); |
| | | // updateWrapper.set(TjOrder::getPrintLastTime, new Date()); |
| | | // updateWrapper.set(TjOrder::getDownloadLastTime, new Date()); |
| | | // updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END); |
| | | // orderService.update(updateWrapper); |
| | | |
| | | |
| | | LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>(); |
| | | wq1.eq(TjOrder::getTjNumber, tjNumber); |
| | | TjOrder tjOrder = orderService.getOne(wq1); |
| | | |
| | | |
| | | LambdaQueryWrapper<TjCustomer> wq2 = new LambdaQueryWrapper<>(); |
| | | wq2.eq(TjCustomer::getCusId, tjOrder.getUserId()); |
| | | TjCustomer tjCustomer = customerService.getOne(wq2); |
| | | |
| | | |
| | | LambdaQueryWrapper<TjReport> we = new LambdaQueryWrapper<>(); |
| | | we.eq(TjReport::getTjNumber, tjNumber); |
| | | we.eq(TjReport::getType, "体检报告"); |
| | | TjReport one = reportService.getOne(we); |
| | | if (one == null) { |
| | | return; |
| | | } |
| | | final UUID uuid = UUID.randomUUID(); |
| | | final String substring = uuid.toString().substring(0, 5); |
| | | |
| | | // String userId = SecurityUtils.getLoginUser().getUsername(); |
| | | PDFBinaryUtil.base64StringToPDF(one.getReport(), FileUtil.mkdir(value).getPath() + "\\" +substring+ tjNumber + tjCustomer.getCusName() + "_体检报告.pdf"); |
| | | //String filePath = one.getPath(); |
| | | String filePath = value + "\\" +substring + tjNumber + tjCustomer.getCusName() + "_体检报告.pdf"; |
| | | File f = new File(filePath); |
| | | if (filePath.isEmpty()) { |
| | | System.out.println("文件不存在!"); |
| | | return; |
| | | } |
| | | BufferedInputStream br = null; |
| | | OutputStream out = null; |
| | | FileInputStream fileInputStream = null; |
| | | try { |
| | | fileInputStream = new FileInputStream(f); |
| | | br = new BufferedInputStream(fileInputStream); |
| | | byte[] bs = new byte[1024]; |
| | | int len = 0; |
| | | response.reset(); // 非常重要 |
| | | if (flag) { |
| | | // 在线打开方式 |
| | | URL u = new URL("file:///" + filePath); |
| | | //System.out.println(u); |
| | | String contentType = u.openConnection().getContentType(); |
| | | response.setContentType(contentType); |
| | | response.setHeader("Content-Disposition", "inline;filename=" |
| | | +substring+ tjNumber + ".pdf"); |
| | | } else { |
| | | // 纯下载方式 |
| | | response.setContentType("application/x-msdownload"); |
| | | response.setContentType("application/pdf;charset=utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" |
| | | +substring+ tjNumber + ".pdf"); |
| | | } |
| | | out = response.getOutputStream(); |
| | | while ((len = br.read(bs)) > 0) { |
| | | out.write(bs, 0, len); |
| | | } |
| | | out.flush(); |
| | | out.close(); |
| | | br.close(); |
| | | fileInputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | //System.out.println("pdf处理文件异常" + e); |
| | | } finally { |
| | | if (out != null) { |
| | | try { |
| | | out.close(); |
| | | br.close(); |
| | | fileInputStream.close(); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 小程序查询体检历史报告列表 |
| | | */ |