zhaowenxuan
2025-06-18 75ee6a6218f67d3720f9ab8824809ddb2abe525c
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjFlowingWaterController.java
@@ -1,6 +1,7 @@
package com.ltkj.web.controller.system;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
@@ -23,6 +24,7 @@
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.mapper.TjSamplingMapper;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.vodomain.TjCollectFeesVo;
import com.ltkj.hosp.vodomain.TjRefundProInfoVo;
@@ -35,6 +37,7 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
@@ -53,6 +56,7 @@
 * @author ltkj
 * @date 2022-11-25
 */
@Slf4j
@RestController
@RequestMapping("/hosp/water")
@Api(tags = "体检流水接口")
@@ -99,6 +103,10 @@
    private TjOrderController tjOrderController;
    @Autowired
    private ITbTransitionService tbTransitionService;
    @Autowired
    private TjSamplingMapper tjSamplingMapper;
    @Autowired
    private TjProBlService blService;
    /**
     * 查询该体检号对应的订单流水列表
@@ -235,8 +243,8 @@
//        tjFlowingWater.setPayStasus(1L);
        TjOrder order = orderService.getById(tjFlowingWater.getOrderId());
        if (order.getFinishTime() != null) {
            return AjaxResult.error("该人员已签离,不可补录项目!");
        if (order.getPrintLastTime() != null) {
            return AjaxResult.error("该人员报告已打印,不可补录项目!");
        }
        TjCustomer customer = customerService.getById(order.getUserId());
@@ -285,6 +293,38 @@
                        wrapper.gt(TbTransition::getNowPrice, 0);
                        List<TbTransition> list = transitionService.list(wrapper);
                        List<TbTransition> transitions = transitionService.getBlTbTransitionListByCusId(customer.getCusIdcard(), order.getCardId(), jxbz);
                        if(null==transitions || transitions.isEmpty()){
                                remarkService.deleteTjOrderDetailByjxbz(jxbz);
                                detailService.deleteTjOrderDetailByjxbz(jxbz);
                                tjFlowingWaterService.deleteTjOrderDetailByjxbz(jxbz);
                                transitionService.deleteTjOrderDetailByjxbz(jxbz);
                                blService.remove(new LambdaQueryWrapper<TjProBl>().eq(TjProBl::getTjh,order.getTjNumber()).eq(TjProBl::getBldh, jxbz));
                            List<String> ids=new ArrayList<>();
                            ids.add(jxbz);
                            tjSamplingMapper.deleteByTjNumAndCusIdAndJxbz(order.getTjNumber(), order.getUserId(),ids);
                            return AjaxResult.error("补录失败,所选项目可能已存在 不可补录!");
                        }
                        BigDecimal zongjia = new BigDecimal("0.0");
                        // his直接单开体检费单项目总价编码
                        String tjfhisxmbm = configService.selectConfigByKey("tjfhisxmbm");
                        // 是否开启his直接单开体检费单项目 N使用明细开单 其他都为单项目开总价
                        String lycdzjhmxj = configService.selectConfigByKey("lycdzjhmxj");
                        // 是否使用his价格传递规则 Y开启
                        String sfsyhisjgrule = configService.selectConfigByKey("sfsyhisjgrule");
                        // his价格传递规则保留得位数 默认2位
                        String sfsyhisjgrulebaoliuweishu = configService.selectConfigByKey("sfsyhisjgrulebaoliuweishu");
                        // his价格传递规则 1四舍五入 2直接舍去
                        String sfsyhisjgrulesconfig = configService.selectConfigByKey("sfsyhisjgrulesconfig");
                        // 传递项目是否使用his科室
                        String isUseHisKs = configService.selectConfigByKey("isCreateMenZhenFyUseHisKs");
                        String createMenZhenFyZJUseHisKs = configService.selectConfigByKey("createMenZhenFyZJUseHisKs");
                        for (TbTransition transition : list) {
                            LambdaQueryWrapper<TjProject> wrapper1 = new LambdaQueryWrapper<>();
                            wrapper1.eq(TjProject::getProId, transition.getProId());
@@ -298,21 +338,67 @@
                            BigDecimal danjia = transition.getNowPrice();
                            Integer sl = project.getSl();
                            BigDecimal allPrice = danjia.multiply(new BigDecimal(sl));
                            if (StrUtil.isNotBlank(sfsyhisjgrule) && sfsyhisjgrule.equalsIgnoreCase("Y")){
                                int baoliuweishu = 2;
                                if (StrUtil.isNotBlank(sfsyhisjgrulebaoliuweishu)){
                                    try {
                                        baoliuweishu = Integer.parseInt(sfsyhisjgrulebaoliuweishu);
                                    } catch (NumberFormatException e) {
                                        log.error("his价格传递规则保留位数转换异常 配置值->{}\n{}{}",sfsyhisjgrulebaoliuweishu,e,e.getMessage());
                                        return AjaxResult.error();
                                    }
                                }
                                if (StrUtil.isNotBlank(sfsyhisjgrulesconfig) && !sfsyhisjgrulesconfig.equalsIgnoreCase("1")){
                                    // 其他自定义的规则计算方法
                                }else {
                                    // 四舍五入
                                    danjia = danjia.setScale(baoliuweishu, RoundingMode.HALF_UP);
                                    allPrice = danjia.multiply(new BigDecimal(sl)).setScale(baoliuweishu, RoundingMode.HALF_UP);
                                }
                            }
                            obj.putOpt("danJia", danjia);
                            obj.putOpt("jieSuanJe", allPrice);
                            obj.putOpt("shuliang", sl);
                            obj.putOpt("zhiXingKs", dept.getDeptId());
                            obj.putOpt("zhiXingKsMc", dept.getDeptName());
                            if (isUseHisKs.equalsIgnoreCase("Y")) {
                                obj.putOpt("zhiXingKs", dept.getHisksid());
                                obj.putOpt("zhiXingKsMc", dept.getHisksmc());
                            }else {
                                obj.putOpt("zhiXingKs", dept.getDeptId());
                                obj.putOpt("zhiXingKsMc", dept.getDeptName());
                            }
                            obj.putOpt("shouFeiXmId", project.getHisXmbm());
                            obj.putOpt("shouFeiXmMc", project.getHisXmmc());
//                        obj.putOpt("zhiXingKs","7805");
//                        obj.putOpt("zhiXingKsMc","体检科");
//                        obj.putOpt("shouFeiXmId","4735346");
//                        obj.putOpt("shouFeiXmMc","体检费");
                            array.add(obj);
                            zongjia = zongjia.add(allPrice);
                        }
                        map.put("feiYongInfoList", array);
                        if(StringUtil.isNotBlank(lycdzjhmxj) && lycdzjhmxj.equalsIgnoreCase("N")){
                            map.put("feiYongInfoList", array);
                        }else {
                            zongjia = tjFlowingWater.getPaidIn();
                            JSONArray zjarray = JSONUtil.createArray();
                            JSONObject obj = JSONUtil.createObj();
                            int sl = 1;
                            obj.putOpt("danJia", zongjia);
                            obj.putOpt("jieSuanJe", zongjia);
                            obj.putOpt("shuliang", sl);
                            if (isUseHisKs.equalsIgnoreCase("Y")) {
                                if (StrUtil.isBlank(createMenZhenFyZJUseHisKs)) return AjaxResult.error();
                                obj.putOpt("zhiXingKs", createMenZhenFyZJUseHisKs);
                            }else {
                                obj.putOpt("zhiXingKs", "100");
                            }
                            obj.putOpt("zhiXingKsMc","体检中心");
                            obj.putOpt("shouFeiXmId", tjfhisxmbm);
                            obj.putOpt("shouFeiXmMc", "体检费");
                            zjarray.add(obj);
                            map.put("feiYongInfoList", zjarray);
                        }
                        log.info("补录调用His接口前 收费总价:{}", zongjia.toString());
                        String post = HttpClientUtils.sendPost(apiUrl + "/api/his/" + hospbm + "/creatCostInfo", map);
                        JSONObject object = JSONUtil.parseObj(post);
@@ -320,7 +406,7 @@
                            JSONObject data = object.getJSONObject("data");
                            tjFlowingWater.setHisWaterId(data.getStr("feiYongId"));
                            JSONArray mxList = data.getJSONArray("mxList");
                            if (mxList != null && mxList.size() > 0) {
                            if (mxList != null && !mxList.isEmpty()) {
                                List<TjFlowingWaterHis> his = mxList.toList(TjFlowingWaterHis.class);
                                tjFlowingWaterHisService.saveBatch(his);
                            }
@@ -656,7 +742,7 @@
                    .or()
                    .eq(TjCustomer::getCusPhone, tjPhone);
            List<TjCustomer> customerList = customerService.list(wq0);
            if (null != customerList && customerList.size() > 0) {
            if (null != customerList && !customerList.isEmpty()) {
                List<TjRefundVo> tjRefundVoList = new ArrayList<>();
                for (TjCustomer customer : customerList) {
                    LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>();
@@ -665,7 +751,7 @@
                    wq1.orderByDesc(TjOrder::getCreateTime);
                    List<TjOrder> tjOrders = orderService.list(wq1);
                    TjOrder order = null;
                    if (null != tjOrders && tjOrders.size() > 0) {
                    if (null != tjOrders && !tjOrders.isEmpty()) {
                        order = tjOrders.get(0);
                    }
                    if (null == order) {
@@ -701,7 +787,7 @@
            wq1.likeLeft(TjOrder::getTjNumber, tjNum);
            wq1.eq(TjOrder::getCheckStatus, 0);
            List<TjOrder> orderList = orderService.list(wq1);
            if (null != orderList && orderList.size() > 0) {
            if (null != orderList && !orderList.isEmpty()) {
                List<TjRefundVo> tjRefundVoList = new ArrayList<>();
                for (TjOrder order : orderList) {
                    LambdaQueryWrapper<TjFlowingWater> wrapper = new LambdaQueryWrapper<>();