zjh
2024-02-29 edb81cb36ef2ff4560afdbe7918a747adbad998f
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCheckController.java
@@ -5,14 +5,20 @@
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.annotation.RepeatSubmit;
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.enums.DataSourceType;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.framework.datasource.DynamicDataSourceContextHolder;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.mapper.TestMapper;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.sqlDomain.*;
import com.ltkj.hosp.vodomain.CsProVo;
import com.ltkj.hosp.vodomain.UpdateOrderRemarkVo;
import com.ltkj.mall.mallOrderUtils.TjConstants;
@@ -31,6 +37,9 @@
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import static org.apache.poi.hemf.record.emfplus.HemfPlusRecordType.save;
import static org.apache.poi.hemf.record.emfplus.HemfPlusRecordType.setClipRect;
/**
 * @Author: 西安路泰科技有限公司/赵佳豪
@@ -70,28 +79,39 @@
    private ISysConfigService configService;
    @Resource
    private ISysDeptService deptService;
    @Resource
    private TestMapper testMapper;
    @Resource
    private TjvLtkjvtjpatService tjvLtkjvtjpatService;
    @Resource
    private LtkjMiddleDetailService middleDetailService;
    @Resource
    private LtkjMiddleHeadService headService;
    @Resource
    private LtkjExamJcbgdService ltkjExamJcbgdService;
    @Resource
    private LtkjExamJcsqdService ltkjExamJcsqdService;
    @Resource
    private LtkjHybgdService ltkjHybgdService;
    @Resource
    private LtkjHysqdService ltkjHysqdService;
    @GetMapping("/getOperationPermissionsByTjNum")
    @ApiOperation(value = "(初审页面  和 医生页面)根据体检号获取是否可操作权限接口  true可操作  反之不可")
    public AjaxResult getOperationPermissionsByTjNum(@ApiParam(value = "体检号") @RequestParam String tjNumber) {
        TjOrder order = orderService.getOrderByTjNum(tjNumber);
        if(null !=order){
        if (null != order) {
            Integer status = order.getStatus();
            if(status<300){
            if (status < 300) {
                return AjaxResult.success(true);
            }
            if(status>300){
            if (status > 300) {
                return AjaxResult.success(false);
            }
        }
        return AjaxResult.success(false);
    }
    @GetMapping("/getCsList")
@@ -106,84 +126,90 @@
                                @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<TjOrder> orderList = null;
        List<TjCustomer> customerList = new ArrayList<>();
        Map<String, Object> 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<TjCustomer> list = customerService.getTjCustomerList(name);
            if (null != list && list.size() > 0) {
                List<TjCustomer> 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<TjCustomer> 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<TjCustomer> 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<TjCustomer> 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);
        }
//        DateTime beginTimes = null;
//        DateTime endTimes = null;
//        if (null != beginTime && null != endTime) {
//            beginTimes = DateUtil.beginOfDay(DateUtil.parse(beginTime));
//            endTimes = DateUtil.endOfDay(DateUtil.parse(endTime));
//        }
//        //初始化体检订单表
//        List<TjOrder> orderList = null;
//        List<TjCustomer> customerList = new ArrayList<>();
//        Map<String, Object> 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<TjCustomer> list = customerService.getTjCustomerList(name);
//            if (null != list && list.size() > 0) {
//                List<TjCustomer> 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.getCreateTime());
//                            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<TjCustomer> 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<TjCustomer> 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<TjCustomer> 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);
//        }
        String value = String.valueOf(compId);
        if (tjNumber == null) tjNumber = "";
        if (compId == null) value = "";
        if (name == null) name = "";
        if (beginTime == null) beginTime = "";
        if (endTime == null) endTime = "";
        return AjaxResult.success(orderService.getCsCunChuGuoChengCustomerList(tjNumber, page, pageSize, checkStatus, value, beginTime, endTime, name));
    }
    /**
@@ -192,25 +218,42 @@
    @GetMapping("/cSWebGetProByTjNumAndOrderId")
    @ApiOperation(value = "(初审页面)点击体检人员展示体检项目接口")
    public AjaxResult cSWebGetProByTjNumAndOrderId(@ApiParam(value = "体检号") @RequestParam String tjNumber) {
        List<TjOrderRemark> orderRemarkList = orderRemarkService.getTjOrderRemarkListByTjNum(tjNumber);
        List<CsProVo> 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());
//        List<TjOrderRemark> orderRemarkList = orderRemarkService.getTjOrderRemarkListByTjNum(tjNumber);
//        List<CsProVo> 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);
//            }
//            List<CsProVo> list1 = orderRemarkService.cSWebGetProByTjNumAndOrderId(tjNumber);
//            Collections.sort(list, new Comparator<CsProVo>() {
//                @Override
//                public int compare(CsProVo o1, CsProVo o2) {
//                    return o1.getType() - o2.getType();
//                }
//            });
//        }
        List<CsProVo> list = orderRemarkService.cSWebGetProByTjNumAndOrderId(tjNumber);
        if (null != list && list.size() > 0) {
            list.sort(new Comparator<CsProVo>() {
                @Override
                public int compare(CsProVo o1, CsProVo o2) {
                    return o1.getType() - o2.getType();
                }
                vo.setSffs("统收");
                vo.setIsPay("已收费");
                vo.setQdcreateTime(remark.getCreateTime());
                vo.setBcupdateTime(remark.getUpdateTime());
                vo.setZhupdateTime(remark.getUpdateTime());
                list.add(vo);
            }
            });
        }
        return AjaxResult.success(list);
    }
@@ -220,27 +263,25 @@
     * 初审
     */
    @GetMapping("/confirmOrder")
        @ApiOperation(value = "初审(并修改状态)接口")
    @PreAuthorize("@ss.hasPermi('check:check:confirmOrder')")
    @ApiOperation(value = "初审(并修改状态)接口")
    @Transactional
    public AjaxResult confirmOrder(@ApiParam(value = "tjNumber") @RequestParam String tjNumber,
                                   @ApiParam(value = "状态 0同意1拒绝 默认同意") @RequestParam(defaultValue = "0") Integer status,
                                   @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 (num > 0) return AjaxResult.error("请先同步体检项目!");
        if (null != tjNumber) {
            Long userId = Long.valueOf(SecurityUtils.getLoginUser().getUserId());
            SysUser sysUser = userService.getById(userId);
            LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
            wq1.eq(TjOrder::getTjNumber, tjNumber);
            TjOrder tjOrder = orderService.getOne(wq1);
            TjOrder tjOrder = orderService.getOrderByTjNum(tjNumber);
            if (null != tjOrder) {
                tjOrder.setConfirmTime(new DateTime());
                tjOrder.setConfirmDoctor(sysUser.getNickName());
                tjOrder.setConfirmStatus(remark);
                if(status==0){
                tjOrder.setConfirmStatus(String.valueOf(status));
                if (status == 0) {
                    tjOrder.setStatus(TjConstants.TJ_CHECK);
                }else {
                    asyncService.updateCheckType(tjNumber);
                } else {
                    tjOrder.setStatus(TjConstants.TJ_REFUSED);
                }
                if (orderService.updateById(tjOrder)) {
@@ -249,6 +290,8 @@
                    confirmLog.setTjNum(tjNumber);
                    confirmLog.setStatus(status);
                    confirmLogService.save(confirmLog);
                    asyncService.wCScheckSetCustomerLisByRedis(orderService.getCsTjOrderList(tjNumber, 0, null, null, null));
                    asyncService.yCScheckSetCustomerLisByRedis(orderService.getCsTjOrderList(tjNumber, 1, null, null, null));
                    return AjaxResult.success("操作成功");
                }
                return AjaxResult.error("操作失败");
@@ -260,20 +303,66 @@
    /**
     * 同步sql server数据到本地数据库数据接口
     */
    @GetMapping("/dataSynchronization")
    @ApiOperation(value = "同步sql server数据到本地数据库数据接口")
    @RepeatSubmit
    public AjaxResult dataSynchronization(@RequestParam String tjNumber) {
        //根据配置调取存储过程 将临时表数据存入预约表2023.12.12
        final String getInfoFromSqlData = configService.selectConfigByKey("getInfoFromSqlData");
        if ("Y".equals(getInfoFromSqlData)) {
            TjOrder order = orderService.getOrderByTjNum(tjNumber);
            if (null != order) {
                List<LtkjHysqd> one = testMapper.getHysqdByTmh(order.getCardId());
                if (one != null && one.size() > 0) {
                    for (LtkjHysqd ltkjHysqd : one) {
//                        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
                        LtkjHysqd hysqd = ltkjHysqdService.getLtkjHysqdByTjhAndTmh(ltkjHysqd.getTjh(), ltkjHysqd.getTmh());
                        if (hysqd == null) {
                            ltkjHysqdService.save(ltkjHysqd);
                            DynamicDataSourceContextHolder.clearDataSourceType();
                            List<LtkjHybgd> one1 = testMapper.getHybgdByTmh(ltkjHysqd.getTmh());
                            if (one1 != null && one1.size() > 0) {
                                DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
                                ltkjHybgdService.saveBatch(one1);
                                DynamicDataSourceContextHolder.clearDataSourceType();
                            }
                        }
                    }
                }
//                List<LtkjExamJcsqd> one2 = testMapper.getExamJcsqdTmh(tjNumber);
//                if (one2 != null && one2.size() > 0) {
//                    DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
//                    ltkjExamJcsqdService.saveBatch(one2);
//                    DynamicDataSourceContextHolder.clearDataSourceType();
//                    for (LtkjExamJcsqd ltkjExamJcsqd : one2) {
//                        List<LtkjExamJcbgd> one3 = testMapper.getExamJcbgdByTjh(ltkjExamJcsqd.getTmh());
//                        if (one3 != null && one3.size() > 0) {
//                            DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
//                            ltkjExamJcbgdService.saveBatch(one3);
//                            DynamicDataSourceContextHolder.clearDataSourceType();
//                        }
//                    }
//                }
                //同步化验项目
                testMapper.updateDetailByCall(order.getCardId(), String.valueOf(order.getOrderId()), order.getTjNumber(), UserHoder.getLoginUser().getUserId());
                //同步检查项目
                testMapper.updateDetailByTjJcCall(order.getCardId(), String.valueOf(order.getOrderId()), order.getTjNumber(), UserHoder.getLoginUser().getUserId());
                asyncService.updateCheckType(order.getTjNumber());
            }
        }
        return AjaxResult.success("同步成功");
    }
    /**
     * 查询体检记录客户列表
     *
     * @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')")
//    @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,
@@ -282,94 +371,102 @@
                              @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<TjOrder> orderList = null;
        List<TjCustomer> customerList = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        //姓名查询
        if (null != name && !"".equals(name)) {
            List<TjCustomer> list = customerService.getTjCustomerList(name);
            if (null != list && list.size() > 0) {
                List<TjCustomer> 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<TjCustomer> 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<TjCustomer> 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<TjCustomer> 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);
        }
        //        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<TjOrder> orderList = null;
//        List<TjCustomer> customerList = new ArrayList<>();
//        Map<String, Object> map = new HashMap<>();
//
//        //姓名查询
//        if (null != name && !"".equals(name)) {
//            List<TjCustomer> list = customerService.getTjCustomerList(name);
//            if (null != list && list.size() > 0) {
//                List<TjCustomer> 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()));
//                            customer.setTjCategory(tjOrder.getTjCategory());
//                            if (tjOrder.getFirmId().equals("0")) {
//                                customer.setTjCompName(null);
//                            } else {
//                                customer.setTjCompName(compService.selectDictCompByDrugManufacturerId(tjOrder.getFirmId()).getCnName());
//                            }
//                            lists.add(customer);
//                        }
//                    }
//                }
//                List<TjCustomer> 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<TjCustomer> 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) {
////            asyncService.addRedis(customers);
//            List<TjCustomer> 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);
//        }
        String value = String.valueOf(compId);
        if (tjNumber == null) tjNumber = "";
        if (compId == null) value = "";
        if (name == null) name = "";
        if (beginTime == null) beginTime = "";
        if (endTime == null) endTime = "";
        return AjaxResult.success(orderService.getCunChuGuoChengCustomerList(tjNumber, page, pageSize, checkStatus, value, beginTime, endTime, name));
    }
    /**
@@ -382,7 +479,7 @@
     */
    @PutMapping("/getTjdetailList")
    @ApiOperation(value = "根据体检订单号获取体检详情信息(并修改状态)接口")
    @PreAuthorize("@ss.hasPermi('check:check:getTjdetailList')")
//    @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) {
@@ -409,7 +506,9 @@
                        if (customerService.updateById(customer)) {
                            LambdaQueryWrapper<TbTransition> wqq = new LambdaQueryWrapper<>();
                            wqq.eq(TbTransition::getCusId, customer.getCusIdcard());
                            wqq.eq(TbTransition::getCardId, customer.getCardId());
                            transitionService.remove(wqq);
                            asyncService.updateCheckType(tjNumber);
                            return AjaxResult.success("操作成功");
                        }
                        return AjaxResult.error("操作失败");
@@ -424,96 +523,169 @@
    /**
     * 总检点击体检信息详情
     * 总检点击体检信息详情————非化验项目
     *
     * @param tjNumber
     * @return
     */
    @GetMapping("/updateCheckType")
    @ApiOperation(value = "总检点击体检信息详情")
    @PreAuthorize("@ss.hasPermi('check:check:updateCheckType')")
    @ApiOperation(value = "总检点击体检信息详情————非化验项目")
    public AjaxResult updateCheckType(@ApiParam(value = "客户体检号") @RequestParam String tjNumber) {
//        if (redisCache.hasKey("updateCheckType" + tjNumber)) {
//            List<Map<String, Object>> cacheMapValue = redisCache.getCacheMapValue("updateCheckType" + tjNumber, tjNumber);
//            return AjaxResult.success(cacheMapValue);
//        }
        return getAjaxResult(tjNumber);
    }
    private AjaxResult getAjaxResult(String tjNumber) {
        asyncService.updateCheckType(tjNumber);
        List<Map<String, Object>> list = new ArrayList<>();
        LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
        wq1.eq(TjOrder::getTjNumber, tjNumber);
        TjOrder one = orderService.getOne(wq1);
        TjOrder one = orderService.getOrderByTjNum(tjNumber);
        if (one == null) {
            return AjaxResult.error("暂无数据!!");
        }
        LambdaQueryWrapper<TjCustomer> wq22 = new LambdaQueryWrapper<>();
        wq22.eq(TjCustomer::getCusId, one.getUserId());
        TjCustomer customer = customerService.getOne(wq22);
        LambdaQueryWrapper<TjOrderRemark> wqm = new LambdaQueryWrapper<>();
        wqm.eq(TjOrderRemark::getTjNumber, tjNumber);
        wqm.eq(TjOrderRemark::getType, 1);
        List<TjOrderRemark> remarkList = orderRemarkService.list(wqm);
        TjCustomer customer = customerService.getById(one.getUserId());
        List<TjOrderRemark> remarkList = orderRemarkService.getRemarkListByTjNumAndType(tjNumber);
        if (null != remarkList && remarkList.size() > 0) {
            for (TjOrderRemark remark : remarkList) {
                Map<String, Object> parent = new HashMap<>();
                parent.put("checkAdvice", one.getCheckAdvice());
                TjProject project = projectService.selectTjProjectByProId(remark.getProId());
                //判断该项目是否需要打印报告
                if ("N".equals(project.getNeedReport())) {
                    continue;
                }
                //判断该项目是否检验科项目  2024/2/28g
                if (project.getDeptId() == 241) {
                    continue;
                }
                if (null != project) {
                    parent.put("parent", project.getProName());
                    parent.put("parentId", project.getProId().toString());
                }
                LambdaQueryWrapper<TjProject> wq2 = new LambdaQueryWrapper<>();
                wq2.eq(TjProject::getProParentId, remark.getProId());
                List<Long> sonsTjProjectList = projectService.list(wq2).stream().map(TjProject::getProId).collect(Collectors.toList());
                if (sonsTjProjectList.size() > 0) {
                    LambdaQueryWrapper<TjOrderDetail> wq = new LambdaQueryWrapper<>();
                    wq.eq(TjOrderDetail::getOrderId, one.getOrderId());
                    wq.in(TjOrderDetail::getProId, sonsTjProjectList);
                    List<TjOrderDetail> tjOrderDetails = detailService.list(wq);
                    if (null != tjOrderDetails && tjOrderDetails.size() > 0) {
                        for (TjOrderDetail tjOrderDetail : tjOrderDetails) {
                            LambdaQueryWrapper<TjProject> wqqqq = new LambdaQueryWrapper<>();
                            wqqqq.eq(TjProject::getProId, tjOrderDetail.getProId());
                            tjOrderDetail.setProject(projectService.getOne(wqqqq));
                            LambdaQueryWrapper<TjStandard> wq6 = new LambdaQueryWrapper<>();
                            wq6.eq(TjStandard::getProId, tjOrderDetail.getProId());
                            List<TjStandard> 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<TjStandard> 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<TjAdvice> wq3 = new LambdaQueryWrapper<>();
                            wq3.in(TjAdvice::getId, Arrays.asList(split));
                            List<TjAdvice> 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);
                            }
                List<TjOrderDetail> tjOrderDetails = detailService.getDetailByOrderIdAndParId(one.getOrderId(), remark.getProId());
                if (null != tjOrderDetails && tjOrderDetails.size() > 0) {
                    for (TjOrderDetail tjOrderDetail : tjOrderDetails) {
                        final TjProject byId = projectService.selectTjProjectByProId(tjOrderDetail.getProId());
                        if (null == byId) {
                            detailService.removeById(tjOrderDetail.getOrderDetailId());
                        } else {
                            parent.put("parentAdvice", null);
                            tjOrderDetail.setProject(byId);
                        }
                        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<TjStandard> list2 = tjStandardService.getTjStandardListByProId(String.valueOf(tjOrderDetail.getProId()));
                        if (list2.size() == 0) {
                            tjOrderDetail.setStandard(new TjStandard());
                        } else if (list2.size() == 1) {
                            tjOrderDetail.setStandard(list2.get(0));
                        } else {
                            final int ageType = StringUtils.getAgeType(DateUtil.ageOfNow(customer.getCusBrithday()));
                            TjStandard tjStandard1 = tjStandardService.getListBySexAndType(customer.getCusSex(), ageType, String.valueOf(tjOrderDetail.getProId()));
                            tjOrderDetail.setStandard(tjStandard1);
                        }
                        list.add(parent);
                    } else {
                        return AjaxResult.success("该客户没有体检项目数据");
                    }
                    String summary = remark.getSummary();
                    if (null != summary) {
                        String[] split = summary.split(";");
//                        List<Long> longList = new ArrayList<>();
//                        for (String str : split) {
//                            if(!"".equals(str)){
//                                longList.add(Long.valueOf(str));
//                            }
//                        }
                        parent.put("parentAdvice", tjAdviceService.getAdviceStringByIds(split));
                    } 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("该客户没有体检项目数据!");
    }
    /**
     * 总检点击体检信息详情————化验项目
     *
     * @param tjNumber
     * @return
     */
    @GetMapping("/updateCheckTypeHuaYan")
    @ApiOperation(value = "总检点击体检信息详情————化验项目")
    public AjaxResult updateCheckTypeHuaYan(@ApiParam(value = "客户体检号") @RequestParam String tjNumber) {
//        asyncService.updateCheckType(tjNumber);
        List<Map<String, Object>> list = new ArrayList<>();
        TjOrder one = orderService.getOrderByTjNum(tjNumber);
        if (one == null) {
            return AjaxResult.error("暂无数据!!");
        }
        TjCustomer customer = customerService.getById(one.getUserId());
        List<TjOrderRemark> remarkList = orderRemarkService.addHuaYanTable(tjNumber);
        List<TjOrderDetail> tjOrderDetails = detailService.addHuaYanTable(tjNumber);
        if (null != remarkList && remarkList.size() > 0) {
            for (TjOrderRemark remark : remarkList) {
                Map<String, Object> parent = new HashMap<>();
                parent.put("checkAdvice", one.getCheckAdvice());
                parent.put("parent", remark.getProName());
                parent.put("parentId", remark.getProId().toString());
                if (null != tjOrderDetails && tjOrderDetails.size() > 0) {
                    for (TjOrderDetail tjOrderDetail : tjOrderDetails) {
                        final TjProject byId = projectService.selectTjProjectByProId(tjOrderDetail.getProId());
                        if (null == byId) {
                            detailService.removeById(tjOrderDetail.getOrderDetailId());
                        } else {
                            tjOrderDetail.setProject(byId);
                        }
                        List<TjStandard> list2 = tjStandardService.getTjStandardListByProId(String.valueOf(tjOrderDetail.getProId()));
                        if (list2.size() == 0) {
                            tjOrderDetail.setStandard(new TjStandard());
                        } else if (list2.size() == 1) {
                            tjOrderDetail.setStandard(list2.get(0));
                        } else {
                            final int ageType = StringUtils.getAgeType(DateUtil.ageOfNow(customer.getCusBrithday()));
                            TjStandard tjStandard1 = tjStandardService.getListBySexAndType(customer.getCusSex(), ageType, String.valueOf(tjOrderDetail.getProId()));
                            tjOrderDetail.setStandard(tjStandard1);
                        }
                    }
                    String summary = remark.getSummary();
                    if (null != summary) {
                        String[] split = summary.split(";");
                        parent.put("parentAdvice", tjAdviceService.getAdviceStringByIds(split));
                    } 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);
@@ -524,13 +696,14 @@
    @GetMapping("/getTm")
    @ApiOperation(value = "获取条码")
    @PreAuthorize("@ss.hasPermi('check:check:getTm')")
//    @PreAuthorize("@ss.hasPermi('check:check:getTm')")
    public AjaxResult getTm(@ApiParam(value = "客户体检号") @RequestParam String tjNumber) {
        return AjaxResult.success(tjNumber);
    }
    /**
     * 总检修改备注
     *
     * @return
     */
    @PostMapping("/checkUpdateOrderRemark")
@@ -568,6 +741,7 @@
                customer.setTjTime(tjOrder.getCreateTime());
                customer.setFinishTime(tjOrder.getFinishTime());
                customer.setConfirmStatus(String.valueOf(tjOrder.getStatus()));
                customer.setTjCategory(tjOrder.getTjCategory());
                if (tjOrder.getFirmId() == null) {
                    customer.setTjCompName("无");
                } else {
@@ -585,37 +759,4 @@
        return AjaxResult.success(map);
    }
    /*private boolean getAjaxResult(@RequestParam(defaultValue = "1") @ApiParam("页码数(默认1)") Integer page,
                                  @RequestParam(defaultValue = "10") @ApiParam("显示条数(默认10)") Integer pageSize,
                                  List<TjOrder> orderList,
                                  List<TjCustomer> customerList,
                                  Map<String, Object> 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<TjCustomer> 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;
    }*/
}