zjh
2025-04-10 6d09c6301492d3095ff64dba2336f0d0b69638e6
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjXdPictureController.java
@@ -1,24 +1,34 @@
package com.ltkj.web.controller.system;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.security.Security;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.entity.SysUser;
import com.ltkj.common.core.redis.RedisCache;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.sqlDomain.LtkjExamJcbgd;
import com.ltkj.hosp.vodomain.CsProVo;
import com.ltkj.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;
import com.ltkj.common.annotation.Log;
import com.ltkj.common.core.controller.BaseController;
@@ -36,6 +46,7 @@
@RestController
@RequestMapping("/picture/picture")
@Api(tags = "体检心电图管理")
@Slf4j
public class TjXdPictureController extends BaseController {
    @Resource
    private ITjXdPictureService tjXdPictureService;
@@ -51,7 +62,12 @@
    private ITjOrderRemarkService remarkService;
    @Resource
    private ITjProjectService projectService;
    @Resource
    private TjXdtgmdjgService xdtgmdjgService;
    @Resource
    private LtkjExamJcbgdService jcbgdService;
    @Resource
    private LtkjExamJcsqdService jcsqdService;
    /**
     * 查询体检心电图管理列表
     */
@@ -189,4 +205,223 @@
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tjXdPictureService.deleteTjXdPictureByIds(ids));
    }
    @GetMapping ("/getYxJcList")
    @ApiOperation (value = "影像检查列表(骨密度和心电图)")//0待1已
    @Transactional
    public AjaxResult getYxJcList(@ApiParam (value = "审核状态  0待审核  1已审核") @RequestParam  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 tcm,
                                @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.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);
//        }
        Long deptId = SecurityUtils.getDeptId();
        log.info("影像检查列表(骨密度和心电图)接口 当前登录人科室"+deptId);
        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 = "";
        if (tcm == null) tcm = "";
        return AjaxResult.success(orderService.getYxJcList(checkStatus,tjNumber, page, pageSize, value, beginTime, endTime, name,tcm,deptId.toString()));
    }
    @GetMapping ("/getYxJcXx")
    @ApiOperation (value = "影像检查骨密度心电图页面点击体检人员展示体检项目接口")
    public AjaxResult getYxJcXx(@ApiParam (value = "体检号") @RequestParam String tjNumber) {
        Long deptId = SecurityUtils.getDeptId();
        log.info("影像检查骨密度心电图页面点击体检人员展示体检项目接口当前登录人科室"+deptId);
        List<CsProVo> list = remarkService.getYxJcXx(tjNumber,deptId.toString());
        return AjaxResult.success(list);
    }
    @GetMapping ("/addYxJcXx")
    @ApiOperation (value = "提交影像检查骨密度心电图结果接口")
    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
    public AjaxResult addYxJcXx(@ApiParam (value = "体检号") @RequestParam String tjNumber,
                                @ApiParam (value = "项目id") @RequestParam String proId,
                                @ApiParam (value = "检查所见") @RequestParam String jcsj,
                                @ApiParam (value = "检查结论") @RequestParam String jcjl) {
        try {
            SysUser user = SecurityUtils.getLoginUser().getUser();
            TjOrder order = orderService.getOrderByTjNum(tjNumber);
            if(null !=order){
                TjProject project = projectService.getById(proId);
                if(null !=project){
                    List<TjProject> projects = projectService.getTjProjectListBySoneId(proId);
                    LambdaQueryWrapper<TjOrderDetail>wq1=new LambdaQueryWrapper<>();
                    wq1.eq(TjOrderDetail::getProId,projects.get(0).getProParentId());
                    wq1.eq(TjOrderDetail::getOrderId,order.getOrderId());
                    TjOrderDetail detail = detailService.getOne(wq1);
                    if(null !=detail){
                        detail.setProResult(jcjl+"。"+jcsj);
                        detail.setTjStatus(1L);
                        detailService.updateById(detail);
                        LambdaQueryWrapper<TjOrderRemark>wq2=new LambdaQueryWrapper<>();
                        wq2.eq(TjOrderRemark::getProId,proId);
                        wq2.eq(TjOrderRemark::getTjNumber,tjNumber);
                        TjOrderRemark orderRemark = remarkService.getOne(wq2);
                        if(null !=orderRemark){
                            orderRemark.setType(1);
                            remarkService.updateById(orderRemark);
                            xdtgmdjgService.deletedByTJhAndProId(tjNumber, proId);
                            TjXdtgmdjg xdtgmdjg=new TjXdtgmdjg();
                            xdtgmdjg.setTjh(tjNumber);
                            xdtgmdjg.setCardId(order.getCardId());
                            xdtgmdjg.setProId(proId);
                            xdtgmdjg.setProName(project.getProName());
                            xdtgmdjg.setJcsj(jcsj);
                            xdtgmdjg.setJcjl(jcjl);
                            xdtgmdjg.setCreateBy(user.getNickName());
                            xdtgmdjg.setCreateId(user.getUserId().toString());
                            xdtgmdjgService.save(xdtgmdjg);
                            saveTjXdtgmdjgByJcbgd(xdtgmdjg);
                        }
                    }
                }
                return AjaxResult.success();
            }
            return AjaxResult.error("暂无体检记录");
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            log.error("提交影像检查骨密度心电图结果接口"+e.getMessage());
            throw new RuntimeException("提交影像检查骨密度心电图结果接口");
        }
    }
    @Transactional(propagation = Propagation.REQUIRED) // 共享事务
    public void saveTjXdtgmdjgByJcbgd(TjXdtgmdjg xdtgmdjg) {
        try {
            int length = xdtgmdjg.getProId().length();
            // 确保字符串长度至少为6
            String last6 = length >= 6 ? xdtgmdjg.getProId().substring(length - 6) : xdtgmdjg.getProId();
            Date date = new Date();
            LtkjExamJcbgd jcbgd=new LtkjExamJcbgd();
            jcsqdService.deletedLtkjJcsqdByTjhandtmh(xdtgmdjg.getCardId(),xdtgmdjg.getTjh()+last6);
            jcbgdService.deletedLtkjJcbgdByTjhandtmh(xdtgmdjg.getCardId(),xdtgmdjg.getTjh()+last6);
            jcbgd.setTjh(xdtgmdjg.getCardId());
            jcbgd.setTmh(xdtgmdjg.getTjh()+last6);
            jcbgd.setXmdm(xdtgmdjg.getProId());
            jcbgd.setXmmc(xdtgmdjg.getProName());
            jcbgd.setBgNr(xdtgmdjg.getJcsj());
            jcbgd.setBgUrl("");
            jcbgd.setShysxm(xdtgmdjg.getCreateBy());
            jcbgd.setShysdm(xdtgmdjg.getCreateId());
            jcbgd.setYxzd(xdtgmdjg.getJcjl());
            jcbgd.setYxbx("未见异常");
            jcbgd.setZdsj(DateUtil.format(date,"yyyy-MM-dd"));
            jcbgd.setJcbw("");
            jcbgd.setSqsj(DateUtil.format(date,"yyyy-MM-dd"));
            jcbgd.setCreateTime(date);
            jcbgdService.save(jcbgd);
            jcsqdService.saveLtkjExamJcsqd(xdtgmdjg.getCardId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @GetMapping ("/getYxJcXxJg")
    @ApiOperation (value = "获取影像检查骨密度心电图结果接口")
    @Transactional
    public AjaxResult getYxJcXxJg(@ApiParam (value = "体检号") @RequestParam String tjNumber,
                                @ApiParam (value = "项目id") @RequestParam String proId) {
        TjOrder order = orderService.getOrderByTjNum(tjNumber);
        if(null !=order){
            LambdaQueryWrapper<TjXdtgmdjg> wq=new LambdaQueryWrapper<>();
            wq.eq(TjXdtgmdjg::getTjh,tjNumber);
            wq.eq(TjXdtgmdjg::getProId,proId);
            TjXdtgmdjg xdtgmdjg = xdtgmdjgService.getOne(wq);
            Map<String,Object>map=new HashMap<>();
            if(null !=xdtgmdjg ){
             map.put("jcsj",xdtgmdjg.getJcsj());
             map.put("jcjl",xdtgmdjg.getJcjl());
             return AjaxResult.success(map);
            }
            return AjaxResult.success(map);
        }
        return AjaxResult.error("暂无体检记录");
    }
}