package com.ltkj.web.controller.system; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.core.domain.entity.SysUser; import com.ltkj.common.core.redis.RedisCache; import com.ltkj.common.utils.SecurityUtils; import com.ltkj.common.utils.StringUtils; import com.ltkj.framework.config.MatchUtils; import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; import com.ltkj.hosp.vodomain.CsProVo; import com.ltkj.hosp.vodomain.UpdateOrderRemarkVo; import com.ltkj.mall.mallOrderUtils.TjConstants; import com.ltkj.system.service.ISysConfigService; import com.ltkj.system.service.ISysDeptService; import com.ltkj.system.service.ISysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.aspectj.weaver.AjAttribute; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; /** * @Author: 西安路泰科技有限公司/赵佳豪 * @Date: 2022/12/6 14:29 */ @RestController @RequestMapping("/check") @Api(tags = "总检医师相关接口") public class TjCheckController { @Resource private ITjOrderService orderService; @Resource private ITjOrderDetailService detailService; @Resource private ITjCustomerService customerService; @Resource private ITjProjectService projectService; @Resource private IDictCompService compService; @Resource private ITjStandardService tjStandardService; @Resource private ITjAdviceService tjAdviceService; @Resource private ITjOrderRemarkService orderRemarkService; @Resource private ITbTransitionService transitionService; @Resource private ISysUserService userService; @Resource private RedisCache redisCache; @Resource private TjAsyncService asyncService; @Resource private ITjConfirmLogService confirmLogService; @Autowired private ISysConfigService configService; @Resource private ISysDeptService deptService; @GetMapping("/getOperationPermissionsByTjNum") @ApiOperation(value = "(初审页面 和 医生页面)根据体检号获取是否可操作权限接口 true可操作 反之不可") public AjaxResult getOperationPermissionsByTjNum(@ApiParam(value = "体检号") @RequestParam String tjNumber) { TjOrder order = orderService.getOrderByTjNum(tjNumber); if(null !=order){ Integer status = order.getStatus(); if(status<300){ return AjaxResult.success(true); } if(status>300){ return AjaxResult.success(false); } } return AjaxResult.success(false); } @GetMapping("/getCsList") @ApiOperation(value = "初审查询体检记录客户列表")//0待1已 @Transactional public AjaxResult getCsList(@ApiParam(value = "审核状态 0待审核 1已审核") @RequestParam(required = false) Integer checkStatus, @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize, @ApiParam(value = "体检单号") @RequestParam(required = false) String tjNumber, @ApiParam(value = "单位") @RequestParam(required = false) Long compId, @ApiParam(value = "姓名)") @RequestParam(required = false) String name, @ApiParam(value = "开始时间") @RequestParam(required = false) String beginTime, @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime) { DateTime beginTimes = null; DateTime endTimes = null; if (null != beginTime && null != endTime) { beginTimes = DateUtil.beginOfDay(DateUtil.parse(beginTime)); endTimes = DateUtil.endOfDay(DateUtil.parse(endTime)); } //初始化体检订单表 List orderList = null; List customerList = new ArrayList<>(); Map map = new HashMap<>(); if (checkStatus == 0) asyncService.wCScheckSetCustomerLisByRedis(orderService.getCsTjOrderList(tjNumber, checkStatus, compId, beginTimes, endTimes)); if (checkStatus == 1) asyncService.yCScheckSetCustomerLisByRedis(orderService.getCsTjOrderList(tjNumber, checkStatus, compId, beginTimes, endTimes)); //根据姓名查询 if (null != name && !"".equals(name)) { List list = customerService.getTjCustomerList(name); if (null != list && list.size() > 0) { List lists = new ArrayList<>(); for (TjCustomer customer : list) { orderList = orderService.getCsTjOrderListByCusId(customer.getCusId()); if (null != orderList && orderList.size() > 0) { for (TjOrder tjOrder : orderList) { customer.setTjNumber(tjOrder.getTjNumber()); customer.setTjStatus(Long.valueOf(tjOrder.getCheckStatus())); customer.setOrderId(tjOrder.getOrderId()); customer.setTjTime(tjOrder.getFinishTime()); customer.setFinishTime(tjOrder.getFinishTime()); customer.setCusName(MatchUtils.hideCusName(customer.getCusName())); customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); customer.setConfirmStatus(String.valueOf(tjOrder.getStatus())); if (tjOrder.getFirmId().equals("0")) { customer.setTjCompName(null); } else { customer.setTjCompName(compService.selectDictCompByDrugManufacturerId(tjOrder.getFirmId()).getCnName()); } lists.add(customer); } } } List customers = null; if (lists.size() > 0) { customers = lists.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); } map.put("customers", customers); map.put("total", lists.size()); return AjaxResult.success(map); } return AjaxResult.success("暂无数据"); } //条件查询 if(null != tjNumber || null !=compId || (null !=beginTime && null !=endTime)){ orderList = orderService.getCsTjOrderList(tjNumber, checkStatus, compId, beginTimes, endTimes); return getResult(page, pageSize, orderList, customerList, map); } List customers = null; if (checkStatus == 0) { customers = redisCache.getCacheMapValue("cScheck", "ws"); } if (checkStatus == 1) { customers = redisCache.getCacheMapValue("cScheck", "ys"); } if (customers != null && customers.size() > 0) { List customerLists = customers.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); map.put("customers", customerLists); map.put("total", customers.size()); return AjaxResult.success(map); } else { orderList = orderService.getCsTjOrderList(tjNumber, checkStatus, compId, beginTimes, endTimes); return getResult(page, pageSize, orderList, customerList, map); } } /** * 初审 */ @GetMapping("/cSWebGetProByTjNumAndOrderId") @ApiOperation(value = "(初审页面)点击体检人员展示体检项目接口") public AjaxResult cSWebGetProByTjNumAndOrderId(@ApiParam(value = "体检号") @RequestParam String tjNumber) { List orderRemarkList = orderRemarkService.getTjOrderRemarkListByTjNum(tjNumber); List list = new ArrayList<>(); if (null != orderRemarkList && orderRemarkList.size() > 0) { for (TjOrderRemark remark : orderRemarkList) { CsProVo vo = new CsProVo(); vo.setDeptName(deptService.getById(remark.getDeptId()).getDeptName()); vo.setProName(projectService.getById(remark.getProId()).getProName()); vo.setType(remark.getType()); if(null !=remark.getDoctorName()){ vo.setDoctorName(userService.getById(remark.getDoctorName()).getNickName()); vo.setBcdoctorName(userService.getById(remark.getDoctorName()).getNickName()); } vo.setSffs("统收"); vo.setIsPay("已收费"); vo.setQdcreateTime(remark.getCreateTime()); vo.setBcupdateTime(remark.getUpdateTime()); vo.setZhupdateTime(remark.getUpdateTime()); list.add(vo); } } return AjaxResult.success(list); } /** * 初审 */ @GetMapping("/confirmOrder") @ApiOperation(value = "初审(并修改状态)接口") // @PreAuthorize("@ss.hasPermi('check:check:confirmOrder')") @Transactional public AjaxResult confirmOrder(@ApiParam(value = "tjNumber") @RequestParam String tjNumber, @ApiParam(value = "状态 0同意1拒绝 默认同意") @RequestParam(defaultValue = "0") Integer status, @ApiParam(value = "驳回理由") @RequestParam(required = false) String remark) { int num = orderRemarkService.getTjYqOrderRemarkByTjNum(tjNumber); if (num > 0) return AjaxResult.error("有延期项目暂不能审核!"); if (null != tjNumber) { Long userId = Long.valueOf(SecurityUtils.getLoginUser().getUserId()); SysUser sysUser = userService.getById(userId); LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); TjOrder tjOrder = orderService.getOne(wq1); if (null != tjOrder) { tjOrder.setConfirmTime(new DateTime()); tjOrder.setConfirmDoctor(sysUser.getNickName()); tjOrder.setConfirmStatus(remark); if(status==0){ tjOrder.setStatus(TjConstants.TJ_CHECK); }else { tjOrder.setStatus(TjConstants.TJ_REFUSED); } if (orderService.updateById(tjOrder)) { TjConfirmLog confirmLog = new TjConfirmLog(); confirmLog.setOrderId(String.valueOf(tjOrder.getOrderId())); confirmLog.setTjNum(tjNumber); confirmLog.setStatus(status); confirmLogService.save(confirmLog); return AjaxResult.success("操作成功"); } return AjaxResult.error("操作失败"); } return AjaxResult.success("数据不存在"); } return AjaxResult.error(); } /** * 查询体检记录客户列表 * * @param tjNumber * @param checkStatus * @param page * @param pageSize * @param compId * @param beginTime * @param endTime * @return */ @GetMapping("/getList") @ApiOperation(value = "查询体检记录客户列表")//0待1已 // @PreAuthorize("@ss.hasPermi('check:check:getList')") public AjaxResult getList(@ApiParam(value = "审核状态0待审核1已审核") @RequestParam(required = false) Integer checkStatus, @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer page, @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize, @ApiParam(value = "体检单号") @RequestParam(required = false) String tjNumber, @ApiParam(value = "单位") @RequestParam(required = false) Long compId, @ApiParam(value = "姓名)") @RequestParam(required = false) String name, @ApiParam(value = "开始时间") @RequestParam(required = false) String beginTime, @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime) { String config = configService.selectConfigByKey("tj_confirm"); DateTime beginTimes = null; DateTime endTimes = null; if (null != beginTime && null != endTime) { beginTimes = DateUtil.beginOfDay(DateUtil.parse(beginTime)); endTimes = DateUtil.endOfDay(DateUtil.parse(endTime)); } asyncService.checkSetCustomerLisByRedis(config); //初始化体检订单表 List orderList = null; List customerList = new ArrayList<>(); Map map = new HashMap<>(); //姓名查询 if (null != name && !"".equals(name)) { List list = customerService.getTjCustomerList(name); if (null != list && list.size() > 0) { List lists = new ArrayList<>(); for (TjCustomer customer : list) { if ("Y".equals(config)) { orderList = orderService.getCsTjOrderListByCusId1(customer.getCusId()); } else { orderList = orderService.getTjOrderListByCusId(customer.getCusId()); } if (null != orderList && orderList.size() > 0) { for (TjOrder tjOrder : orderList) { customer.setTjNumber(tjOrder.getTjNumber()); customer.setTjStatus(Long.valueOf(tjOrder.getCheckStatus())); customer.setOrderId(tjOrder.getOrderId()); customer.setTjTime(tjOrder.getFinishTime()); customer.setFinishTime(tjOrder.getFinishTime()); customer.setCusName(MatchUtils.hideCusName(customer.getCusName())); customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); customer.setConfirmStatus(String.valueOf(tjOrder.getStatus())); if (tjOrder.getFirmId().equals("0")) { customer.setTjCompName(null); } else { customer.setTjCompName(compService.selectDictCompByDrugManufacturerId(tjOrder.getFirmId()).getCnName()); } lists.add(customer); } } } List customers = null; if (lists.size() > 0) { customers = lists.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); } map.put("customers", customers); map.put("total", lists.size()); return AjaxResult.success(map); } return AjaxResult.success("暂无数据"); } //条件查询 if(null != tjNumber || null !=compId || (null !=beginTime && null !=endTime)){ //判断是否开启初审 if ("Y".equals(config)) { orderList = orderService.getCsTjOrderList1(tjNumber, checkStatus, compId, beginTimes, endTimes); } else { orderList = orderService.getTjOrderList(tjNumber, checkStatus, compId, beginTimes, endTimes); } return getResult(page, pageSize, orderList, customerList, map); } List customers = null; if (null != checkStatus && checkStatus == 0) { customers = redisCache.getCacheMapValue("check", "ws"); } if (null != checkStatus && checkStatus == 1) { customers = redisCache.getCacheMapValue("check", "ys"); } if (customers != null && customers.size() > 0) { List customerLists = customers.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); map.put("customers", customerLists); map.put("total", customers.size()); return AjaxResult.success(map); } else { //判断是否开启初审 if ("Y".equals(config)) { orderList = orderService.getCsTjOrderList1(tjNumber, checkStatus, compId, beginTimes, endTimes); } else { orderList = orderService.getTjOrderList(tjNumber, checkStatus, compId, beginTimes, endTimes); } return getResult(page, pageSize, orderList, customerList, map); } } /** * 根据体检订单号获取体检详情信息接口 * * @param tjNumber * @param advice * @param checkStatus * @return */ @PutMapping("/getTjdetailList") @ApiOperation(value = "根据体检订单号获取体检详情信息(并修改状态)接口") // @PreAuthorize("@ss.hasPermi('check:check:getTjdetailList')") public AjaxResult getTjdetailList(@ApiParam(value = "体检tjNumber") @RequestParam String tjNumber, @ApiParam(value = "总检建议") @RequestParam(required = false) String advice, @ApiParam(value = "审核状态0待审核1已审核") @RequestParam Integer checkStatus) { int num = orderRemarkService.getTjYqOrderRemarkByTjNum(tjNumber); if (num > 0) return AjaxResult.error("有延期项目暂不能生成报告!!!"); if (null != tjNumber) { Long userId = Long.valueOf(SecurityUtils.getLoginUser().getUserId()); SysUser sysUser = userService.getById(userId); LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); TjOrder tjOrder = orderService.getOne(wq1); if (null != tjOrder) { tjOrder.setCheckAdvice(advice); tjOrder.setCheckStatus(checkStatus); tjOrder.setStatus(TjConstants.TJ_CHECK); tjOrder.setCheckDoctor(sysUser.getNickName()); tjOrder.setCheckTime(new Date()); tjOrder.setStatus(401); if (orderService.updateById(tjOrder)) { TjCustomer customer = customerService.getById(tjOrder.getUserId()); if (null != customer) { customer.setCusNumber(customer.getCusNumber() + 1); if (customerService.updateById(customer)) { LambdaQueryWrapper wqq = new LambdaQueryWrapper<>(); wqq.eq(TbTransition::getCusId, customer.getCusIdcard()); transitionService.remove(wqq); return AjaxResult.success("操作成功"); } return AjaxResult.error("操作失败"); } } return AjaxResult.error("操作失败"); } return AjaxResult.success("数据不存在"); } return AjaxResult.error(); } /** * 总检点击体检信息详情 * * @param tjNumber * @return */ @GetMapping("/updateCheckType") @ApiOperation(value = "总检点击体检信息详情") // @PreAuthorize("@ss.hasPermi('check:check:updateCheckType')") public AjaxResult updateCheckType(@ApiParam(value = "客户体检号") @RequestParam String tjNumber) { List> list = new ArrayList<>(); LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjOrder::getTjNumber, tjNumber); TjOrder one = orderService.getOne(wq1); if (one == null) { return AjaxResult.error("暂无数据!!"); } 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.eq(TjOrderRemark::getType, 1); List remarkList = orderRemarkService.list(wqm); if (null != remarkList && remarkList.size() > 0) { for (TjOrderRemark remark : remarkList) { Map parent = new HashMap<>(); parent.put("checkAdvice", one.getCheckAdvice()); TjProject project = projectService.selectTjProjectByProId(remark.getProId()); if (null != project) { parent.put("parent", project.getProName()); parent.put("parentId", project.getProId().toString()); } LambdaQueryWrapper wq2 = new LambdaQueryWrapper<>(); wq2.eq(TjProject::getProParentId, remark.getProId()); List sonsTjProjectList = projectService.list(wq2).stream().map(TjProject::getProId).collect(Collectors.toList()); if (sonsTjProjectList.size() > 0) { 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) { for (TjOrderDetail tjOrderDetail : tjOrderDetails) { LambdaQueryWrapper wqqqq = new LambdaQueryWrapper<>(); wqqqq.eq(TjProject::getProId, tjOrderDetail.getProId()); tjOrderDetail.setProject(projectService.getOne(wqqqq)); LambdaQueryWrapper wq6 = new LambdaQueryWrapper<>(); wq6.eq(TjStandard::getProId, tjOrderDetail.getProId()); List list2 = tjStandardService.list(wq6); if (list2.size() == 0) { tjOrderDetail.setStandard(new TjStandard()); } 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(tjStandardService.getOne(wq8)); } } } String summary = remark.getSummary(); if (null != summary) { String[] split = summary.split(";"); LambdaQueryWrapper wq3 = new LambdaQueryWrapper<>(); wq3.in(TjAdvice::getId, Arrays.asList(split)); List advices = tjAdviceService.list(wq3); if (null != advices && advices.size() > 0) { StringBuilder string = new StringBuilder(); for (TjAdvice advice : advices) { string.append(advice.getTitle()).append(";"); } parent.put("parentAdvice", string); } } else { parent.put("parentAdvice", null); } parent.put("sons", tjOrderDetails); parent.put("remark", remark.getRemark()); if (remark.getDoctorName() != null && null != userService.getById(remark.getDoctorName())) { parent.put("doctorName", userService.getById(remark.getDoctorName()).getNickName()); } list.add(parent); } else { return AjaxResult.success("该客户没有体检项目数据"); } } } return AjaxResult.success(list); } return AjaxResult.success("该客户没有体检项目数据!"); } @GetMapping("/getTm") @ApiOperation(value = "获取条码") // @PreAuthorize("@ss.hasPermi('check:check:getTm')") public AjaxResult getTm(@ApiParam(value = "客户体检号") @RequestParam String tjNumber) { return AjaxResult.success(tjNumber); } /** * 总检修改备注 * @return */ @PostMapping("/checkUpdateOrderRemark") @ApiOperation(value = "总检修改备注接口") public AjaxResult checkUpdateOrderRemark(@RequestBody List updateOrderRemarkVos) { if (null != updateOrderRemarkVos && updateOrderRemarkVos.size() > 0) { for (UpdateOrderRemarkVo remarkVo : updateOrderRemarkVos) { LambdaQueryWrapper wqm = new LambdaQueryWrapper<>(); wqm.eq(TjOrderRemark::getTjNumber, remarkVo.getTjNumber()); wqm.eq(TjOrderRemark::getProId, remarkVo.getProId()); TjOrderRemark remark = orderRemarkService.getOne(wqm); if (null != remark) { remark.setRemark(remarkVo.getRemarks()); orderRemarkService.updateById(remark); } } } return AjaxResult.success(); } private AjaxResult getResult(Integer page, Integer pageSize, List orderList, List customerList, Map map) { for (TjOrder tjOrder : orderList) { if (null != tjOrder) { TjCustomer customer = customerService.selectTjCustomerByCusId(tjOrder.getUserId()); if (customer == null) { continue; } customer.setCusName(MatchUtils.hideCusName(customer.getCusName())); customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); customer.setTjNumber(tjOrder.getTjNumber()); customer.setTjStatus(Long.valueOf(tjOrder.getCheckStatus())); customer.setOrderId(tjOrder.getOrderId()); customer.setTjTime(tjOrder.getCreateTime()); customer.setFinishTime(tjOrder.getFinishTime()); customer.setConfirmStatus(String.valueOf(tjOrder.getStatus())); if (tjOrder.getFirmId() == null) { customer.setTjCompName("无"); } else { DictComp byId = compService.selectDictCompByDrugManufacturerId(tjOrder.getFirmId()); if (byId != null) { customer.setTjCompName(byId.getCnName()); } } customerList.add(customer); } } List customers = customerList.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); map.put("customers", customers); map.put("total", customerList.size()); return AjaxResult.success(map); } /*private boolean getAjaxResult(@RequestParam(defaultValue = "1") @ApiParam("页码数(默认1)") Integer page, @RequestParam(defaultValue = "10") @ApiParam("显示条数(默认10)") Integer pageSize, List orderList, List customerList, Map map) { if (null != orderList && orderList.size() > 0) { for (TjOrder tjOrder : orderList) { TjCustomer customer = customerService.selectTjCustomerByCusId(tjOrder.getUserId()); if (null == customer) { continue; } customer.setCusName(MatchUtils.hideCusName(customer.getCusName())); customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); customer.setTjNumber(tjOrder.getTjNumber()); customer.setTjStatus(Long.valueOf(tjOrder.getCheckStatus())); customer.setOrderId(tjOrder.getOrderId()); customer.setTjTime(tjOrder.getCreateTime()); customer.setFinishTime(tjOrder.getFinishTime()); if (tjOrder.getFirmId() == null || tjOrder.getFirmId().equals("0")) { customer.setTjCompName("无"); } else { customer.setTjCompName(compService.getById(tjOrder.getFirmId()).getCnName()); } customerList.add(customer); } List customers = customerList.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); map.put("customers", customers); map.put("total", customerList.size()); return true; } return false; }*/ }