package com.ltkj.web.controller.app; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; 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.hosp.sqlDomain.LtkjExamJcbgd; import com.ltkj.hosp.sqlDomain.LtkjExamJcsqd; import com.ltkj.hosp.sqlDomain.LtkjHybgd; import com.ltkj.hosp.sqlDomain.LtkjHysqd; import com.ltkj.hosp.vodomain.ShenGaoTiZhongVo; 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 lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.One; import org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTJcImpl; import org.springframework.beans.factory.annotation.Autowired; 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.*; import org.springframework.web.server.session.InMemoryWebSessionStore; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.math.BigDecimal; import java.net.URL; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; /** * @Author: 西安路泰科技有限公司/lige * @Date: 2023/1/10 15:42 */ @RestController @RequestMapping("/cus/getReport") @Api(tags = "小程序查看体检报告") @Slf4j public class ReportController extends BaseController { @Resource private ITjReportService reportService; @Resource private ITjCustomerService customerService; @Autowired private ITjOrderService orderService; @Autowired private ITjOrderDetailService detailService; @Resource private ITjProjectService projectService; @Resource private ITjOrderRemarkService remarkService; @Resource private ITjStandardService standardService; @Resource private ITjAdviceService adviceService; @Resource private IDictCompService compService; @Resource private ITjReportTemplateService reportTemplateService; @Value("${path.filePath}") private String value; @Resource private LtkjHybgdService ltkjHybgdService; @Resource private LtkjHysqdService ltkjHysqdService; @Resource private LtkjExamJcbgdService jcbgdService; @Resource private LtkjExamJcsqdService jcsqdService; /** * 小程序查询体检报告列表 */ @GetMapping("/getReportList") @ApiOperation(value = "小程序-体检报告列表") public AjaxResult getReportList(String cusPhone) { // Wxuser wxuser = UserHoder.getWxuser(); if (cusPhone == null) { return AjaxResult.error("请绑定手机号!"); } List result = new ArrayList<>(); LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjCustomer::getCusPhone, cusPhone); List list1 = customerService.list(wq1); if (list1.size() != 0) { for (TjCustomer tjCustomer : list1) { Map map = new HashMap<>(); QueryWrapper wq2 = new QueryWrapper<>(); wq2.eq("user_id", tjCustomer.getCusId()); wq2.eq("check_status", 1); wq2.isNotNull("finish_time"); wq2.orderByDesc("finish_time"); List list = orderService.list(wq2); if (null != list && list.size() > 0) { TjOrder tjOrder = orderService.list(wq2).get(0); map.put("report", tjOrder); map.put("customer", tjCustomer); result.add(map); } } return AjaxResult.success(result); } return AjaxResult.error("您还没有体检记录!"); } /** * 小程序查询体检报告列表 */ @GetMapping("/getRelativeReportList") @ApiOperation(value = "小程序-查询亲友最新报告") public AjaxResult getRelativeReportList(@RequestParam @ApiParam(value = "姓名") String cusName, @RequestParam @ApiParam(value = "身份证号") String cusIdcard) { LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.like(TjCustomer::getCusName, cusName); wq1.eq(TjCustomer::getCusIdcard, cusIdcard); TjCustomer customer = customerService.getOne(wq1); if (null != customer) { Map map = new HashMap<>(); QueryWrapper wq2 = new QueryWrapper<>(); wq2.eq("user_id", customer.getCusId()); wq2.eq("check_status", 1); wq2.isNotNull("finish_time"); wq2.orderByDesc("finish_time"); List list = orderService.list(wq2); if (null != list && list.size() > 0) { TjOrder tjOrder = orderService.list(wq2).get(0); map.put("report", tjOrder); map.put("customer", customer); return AjaxResult.success(map); } return AjaxResult.success("体检报告暂未生成"); } return AjaxResult.success("暂时没有体检记录!"); } /** * 小程序点击体检报告查询详情 */ @GetMapping("/getReportByTjNumber") @ApiOperation(value = "小程序-体检报告查询详情") public AjaxResult getReportByTjNumber(@RequestParam @ApiParam(value = "体检号") String tjNumber) { Map objectMap = new HashMap<>(); List> list = new ArrayList<>(); LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); wq1.eq(TjOrder::getCheckStatus, 1); TjOrder one = orderService.getOne(wq1); if (one == null) { return AjaxResult.success("体检暂未完成!!"); } LambdaQueryWrapper wq22 = new LambdaQueryWrapper<>(); wq22.eq(TjCustomer::getCusId, one.getUserId()); TjCustomer customer = customerService.getOne(wq22); LambdaQueryWrapper wqm = new LambdaQueryWrapper<>(); wqm.eq(TjOrderRemark::getTjNumber, tjNumber); wqm.in(TjOrderRemark::getDeptId,"100", "240", "253", "254", "255", "257", "258", "259", "269", "270"); List remarkList = remarkService.list(wqm); List> abnormalList = new ArrayList<>(); if (null != remarkList && remarkList.size() > 0) { for (TjOrderRemark remark : remarkList) { Map parent = new HashMap<>(); Map parent1 = new HashMap<>(); TjProject tjProject = projectService.getById(remark.getProId()); if (null != tjProject && tjProject.getNeedReport().equals("Y")) { parent.put("parent", tjProject.getProName()); parent1.put("parent", tjProject.getProName()); LambdaQueryWrapper wq2 = new LambdaQueryWrapper<>(); wq2.eq(TjProject::getProParentId, remark.getProId()); List sonsTjProjectList = null; if (null != projectService.list(wq2) && projectService.list(wq2).size() > 0) { sonsTjProjectList = projectService.list(wq2).stream().map(TjProject::getProId).collect(Collectors.toList()); } if (sonsTjProjectList == null) { log.info("我报空指针了::::::::::::" + remark.toString()); continue; } LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjOrderDetail::getOrderId, one.getOrderId()); wq.in(TjOrderDetail::getProId, sonsTjProjectList); List tjOrderDetails = detailService.list(wq); if (null != tjOrderDetails && tjOrderDetails.size() > 0) { List abnormals = new ArrayList<>(); for (TjOrderDetail tjOrderDetail : tjOrderDetails) { if (tjOrderDetail.getExceptionDesc() == 1) { abnormals.add(tjOrderDetail); parent1.put("abnormalList", abnormals); abnormalList.add(parent1); } LambdaQueryWrapper wqqqq = new LambdaQueryWrapper<>(); wqqqq.eq(TjProject::getProId, tjOrderDetail.getProId()); wqqqq.eq(TjProject::getNeedReport,"Y"); tjOrderDetail.setProject(projectService.getOne(wqqqq)); // LambdaQueryWrapper wq6 = new LambdaQueryWrapper<>(); // wq6.eq(TjStandard::getProId, tjOrderDetail.getProId()); // List list2 = standardService.list(wq6); // if (list2.size() == 0) { // tjOrderDetail.setStandard(null); // } else if (list2.size() == 1) { // tjOrderDetail.setStandard(list2.get(0)); // } else { // for (TjStandard tjStandard : list2) { // LambdaQueryWrapper wq8 = new LambdaQueryWrapper<>(); // if (tjStandard.getTjSex() != null) { // wq8.eq(TjStandard::getTjSex, customer.getCusSex()); // } // if (tjStandard.getTjType() != null) { // wq8.eq(TjStandard::getTjType, StringUtils.getAgeType(DateUtil.ageOfNow(customer.getCusBrithday()))); // } // tjOrderDetail.setStandard(standardService.getOne(wq8)); // } // } } LambdaQueryWrapper wq3 = new LambdaQueryWrapper<>(); wq3.eq(TjAdvice::getProId, remark.getProId()); parent.put("sons", tjOrderDetails); parent.put("parentAdvice", adviceService.list(wq3)); parent.put("advice", remark.getSummary()); list.add(parent); } else { return AjaxResult.success("该客户在没有体检项目数据"); } } } objectMap.put("list", list); objectMap.put("inspectionAdvice", one.getCheckAdvice()); objectMap.put("tjAbnormal", abnormalList); objectMap.put("customter", customer); return AjaxResult.success(objectMap); } return AjaxResult.success("该客户在没有体检项目数据!"); } @GetMapping("/getHyReportByTjNumber") @ApiOperation(value = "小程序-体检化验报告查询详情") public AjaxResult getHyReportByTjNumber(@RequestParam @ApiParam(value = "体检号") String tjNumber) { LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); wq1.eq(TjOrder::getCheckStatus, 1); TjOrder one = orderService.getOne(wq1); if (one == null) { return AjaxResult.success("体检暂未完成!!"); } List hysqdList = ltkjHysqdService.getLtkjHysqdByTjh(one.getCardId()); if(null !=hysqdList && hysqdList.size()>0){ List> list = new ArrayList<>(); for (LtkjHysqd hysqd : hysqdList) { Map map = new HashMap<>(); map.put("parent",hysqd.getXmmc()); List hybgdList = ltkjHybgdService.getJianYanBaoGaoDanList(hysqd.getTmh()); if(null !=hybgdList && hybgdList.size()>0){ for (LtkjHybgd hybgd : hybgdList) { String jyjg = hybgd.getJyjg(); String fwz = hybgd.getFwz(); if (jyjg != null && StrUtil.isNotBlank(jyjg) && fwz != null && StrUtil.isNotBlank(fwz)){ try { String[] fwzs = fwz.split("-"); BigDecimal min = new BigDecimal(fwzs[0]); BigDecimal max = new BigDecimal(fwzs[1]); BigDecimal jyjgval = new BigDecimal(jyjg); // 比较检验结果和范围值 if (jyjgval.compareTo(min) < 0) { // jyjg 小于范围最小值,添加下箭头 jyjg = jyjg + " ↓"; hybgd.setYcbz("1"); } else if (jyjgval.compareTo(max) > 0) { // jyjg 大于范围最大值,添加上箭头 jyjg = jyjg + " ↑"; hybgd.setYcbz("1"); }else { hybgd.setYcbz("0"); } hybgd.setJyjg(jyjg); } catch (Exception ignored) {} } } } map.put("sons",hybgdList); list.add(map); } return AjaxResult.success(list); } return AjaxResult.success("该客户在没有体检项目数据!"); } @GetMapping("/getJcReportByTjNumber") @ApiOperation(value = "小程序-体检检查报告查询详情") public AjaxResult getJcReportByTjNumber(@RequestParam @ApiParam(value = "体检号") String tjNumber) { LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); wq1.eq(TjOrder::getCheckStatus, 1); TjOrder one = orderService.getOne(wq1); if (one == null) { return AjaxResult.success("体检暂未完成!!"); } List jcsqdList = jcsqdService.getLtkjJcsqdByTjh(one.getCardId()); if(null !=jcsqdList && jcsqdList.size()>0){ List> list = new ArrayList<>(); for (LtkjExamJcsqd jcsqd : jcsqdList) { Map map = new HashMap<>(); map.put("parent",jcsqd.getJcxmmc()); map.put("jcbx",jcsqd.getJgbx()); List jcbgdList = jcbgdService.getJianJcBaoGaoDanList(jcsqd.getTmh()); map.put("sons",jcbgdList); list.add(map); } return AjaxResult.success(list); } return AjaxResult.success("该客户在没有体检项目数据!"); } /** * 小程序点击体检报告查询详情,显示身高体重体重指数收缩压舒张压 */ @GetMapping("/getShenGaoTiZhong") @ApiOperation(value = "小程序-体检报告查询详情") public AjaxResult getShenGaoTiZhong(@RequestParam @ApiParam(value = "体检号") String tjNumber) { // Map objectMap = new HashMap<>(); LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); wq1.eq(TjOrder::getCheckStatus, 1); TjOrder one = orderService.getOne(wq1); if (one == null) { return AjaxResult.success("体检暂未完成!!"); } List maps = detailService.getShenGaoTiZhongList(one.getTjNumber()); // if(null !=maps && maps.size()>0){ // for (Map map : maps) { // if (map.get("") == null) { // objectMap.put("shenggao", "无"); // } else { // objectMap.put("shenggao", one1.getProResult()); // } // if (one2 == null) { // objectMap.put("tizhong", "无"); // } else { // objectMap.put("tizhong", one2.getProResult()); // } // if (one3 == null) { // objectMap.put("tizhongzhishu", "无"); // } else { // objectMap.put("tizhongzhishu", one3.getProResult()); // } // if (one4 == null) { // objectMap.put("shousuoya", "无"); // } else { // objectMap.put("shousuoya", one4.getProResult()); // } // if (one5 == null) { // objectMap.put("shuzhangya", "无"); // } else { // objectMap.put("shuzhangya", one5.getProResult()); // } // } // } log.info("ltkj {}的体检报告查询详情"+maps,tjNumber); return AjaxResult.success(maps); } /** * 小程序点击下载报告 */ @GetMapping("/downloadReport") @ApiOperation(value = "小程序-下载报告") public AjaxResult downloadReport(@RequestParam @ApiParam(value = "体检号") String tjNumber) { Map res = new HashMap<>(); LambdaQueryWrapper 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 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 wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); TjOrder tjOrder = orderService.getOne(wq1); LambdaQueryWrapper wq2 = new LambdaQueryWrapper<>(); wq2.eq(TjCustomer::getCusId, tjOrder.getUserId()); TjCustomer tjCustomer = customerService.getOne(wq2); LambdaQueryWrapper 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() + File.separator + substring + tjNumber + tjCustomer.getCusName() + "_体检报告.pdf"); //String filePath = one.getPath(); String filePath = value + File.separator + 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(); } } } } /** * 小程序查询体检历史报告列表 */ @GetMapping("/getHistryReportList") @ApiOperation(value = "小程序-体检历史报告列表") public AjaxResult getHistryReportList(@RequestParam @ApiParam(value = "手机号") String cusPhone) { List result = new ArrayList<>(); QueryWrapper wq1 = new QueryWrapper<>(); wq1.eq("cus_phone", cusPhone); List list1 = customerService.list(wq1); if (list1.size() != 0) { for (TjCustomer tjCustomer : list1) { Map map = new HashMap<>(); QueryWrapper wq2 = new QueryWrapper<>(); wq2.eq("user_id", tjCustomer.getCusId()); wq2.eq("check_status", 1); wq2.isNotNull("finish_time"); wq2.orderByDesc("finish_time"); List list = orderService.list(wq2); if (null != list && list.size() > 0) { map.put("report", list); map.put("customer", tjCustomer); result.add(map); } } return AjaxResult.success(result); } return AjaxResult.success("您还没有体检记录!"); } }