From cc25bc0eec2d50da39d62f9896ed4d5e66805366 Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期五, 11 七月 2025 18:04:05 +0800
Subject: [PATCH] zjh20250711

---
 ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCompPayController.java |  233 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 139 insertions(+), 94 deletions(-)

diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCompPayController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCompPayController.java
index 81dcc3b..33f25fd 100644
--- a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCompPayController.java
+++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCompPayController.java
@@ -1,6 +1,7 @@
 package com.ltkj.web.controller.system;
 
 
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ltkj.common.core.domain.AjaxResult;
 import com.ltkj.common.utils.SecurityUtils;
@@ -14,6 +15,7 @@
 import io.swagger.annotations.ApiParam;
 import jodd.util.StringUtil;
 import org.aspectj.weaver.AjAttribute;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import com.ltkj.common.core.controller.BaseController;
 import oshi.hardware.platform.mac.MacUsbDevice;
@@ -21,10 +23,7 @@
 import javax.annotation.Resource;
 import java.lang.annotation.ElementType;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.ltkj.framework.datasource.DynamicDataSourceContextHolder.log;
@@ -46,8 +45,6 @@
     @Resource
     private ITjTeamSelectRecordService selectRecordService;
     @Resource
-    private ITjPackageService packageService;
-    @Resource
     private IDictCompService compService;
     @Resource
     private ITjReservationService reservationService;
@@ -56,29 +53,62 @@
     @Resource
     private ITjCustomerService customerService;
     @Resource
-    private ITjDwDeptService dwDeptService;
-    @Resource
     private ITjDwGroupingService dwGroupingService;
     @Resource
     private ITjOrderRemarkService remarkService;
+    @Resource
+    private ITjFlowingWaterService tjFlowingWaterService;
+    @Resource
+    private ITbTransitionService transitionService;
     /**
      * 鍥綋浣撴鏀惰垂鎺ュ彛
      */
     @PostMapping
     @ApiOperation(value = "鍥綋浣撴鏀惰垂鎺ュ彛")
-    public AjaxResult add(@RequestBody TjCompPayInfo compPayInfo) {
-        if (null==compPayInfo) {
-            return AjaxResult.error();
+    @Transactional
+    public AjaxResult add(@RequestBody TjCompPay compPay) {
+        try {
+            if (null==compPay.getTjhs() || compPay.getTjhs().isEmpty()) {
+                return AjaxResult.error("璇烽�夋嫨缁撹处浜哄憳!");
+            }
+            Date date = DateUtil.date();
+            String s = String.valueOf(SecurityUtils.getLoginUser().getUser().getNickName());
+            compPay.setPayee(s);
+            compPay.setSerialNumber("TT"+SecurityUtils.getUsername() + DateUtil.format(date, "yyMMddHHmmssSSS"));
+            compPay.setInvoiceNo("FP" + DateUtil.format(date, "yyMMddHHmmssSSS"));
+            if(compPayService.save(compPay)){
+                for (String tjh : compPay.getTjhs()) {
+                    TjOrder tjOrder = orderService.getOrderByTjNum(tjh);
+                    if(null != tjOrder){
+                        TjFlowingWater water = tjFlowingWaterService.getOne(new LambdaQueryWrapper<TjFlowingWater>()
+                                .eq(TjFlowingWater::getOrderId, tjOrder.getOrderId()).eq(TjFlowingWater::getIsAddition, "N"));
+                        if(null != water){
+                            TjCompPayInfo payInfo =  new TjCompPayInfo();
+                            payInfo.setTjh(tjh);
+                            payInfo.setTjCompPayId(compPay.getId());
+                            payInfo.setTransactionAmount(water.getPaidIn());
+                            payInfo.setPaymentMethod(compPay.getPaymentMethod());
+                            payInfo.setCardNo(compPay.getCardNo());
+                            payInfo.setPayer(compPay.getPayer());
+                            payInfo.setPayee(compPay.getPayee());
+                            payInfoService.save(payInfo);
+                            water.setSfjs("1");
+                            water.setJsdh(compPay.getSerialNumber());
+                            water.setJsrq(DateUtil.date());
+                            water.setJsrxm(s);
+                            water.setJsrdm(SecurityUtils.getLoginUser().getUser().getUserId().toString());
+                            tjFlowingWaterService.updateById(water);
+                        }
+                    }
+
+                }
+                return AjaxResult.success("鏀惰垂鎴愬姛");
+            }
+            return AjaxResult.error("鎿嶄綔澶辫触");
+        } catch (Exception e) {
+            log.error("鏀惰垂寮傚父", e);
+            throw new RuntimeException(e);
         }
-        compPayInfo.setPayee(String.valueOf(SecurityUtils.getLoginUser().getUser().getNickName()));
-        TjCompPay tjCompPay =compPayService.getById(compPayInfo.getTjCompPayId());
-        BigDecimal paidIn = tjCompPay.getPaidIn();
-                   paidIn =paidIn.add(compPayInfo.getTransactionAmount());
-        if(paidIn.compareTo(tjCompPay.getCopeWith())>0 || tjCompPay.getDifference().compareTo(BigDecimal.valueOf(0))==0){
-            return AjaxResult.error("鏆傛棤鏀惰垂闇�姹�");
-        }
-        if (getAjaxResult(compPayInfo, tjCompPay)) return AjaxResult.success("鏀惰垂鎴愬姛");
-        return AjaxResult.error("鎿嶄綔澶辫触");
     }
 
     /**
@@ -86,52 +116,35 @@
      */
     @PostMapping("/refund")
     @ApiOperation(value = "鍥綋浣撴閫�璐规帴鍙�")
-    public AjaxResult refund(@RequestBody TjCompPayInfo compPayInfo) {
-        if (null==compPayInfo) {
-            return AjaxResult.error();
-        }
-        compPayInfo.setPayee(String.valueOf(SecurityUtils.getLoginUser().getUser().getNickName()));
-        TjCompPay tjCompPay =compPayService.getById(compPayInfo.getTjCompPayId());
-        BigDecimal paidIn = tjCompPay.getPaidIn();
-        paidIn =paidIn.add(compPayInfo.getTransactionAmount());
-        //鍒ゆ柇瀹炰粯閲戦鍜屼氦鏄撻噾棰濈殑鏁板��
-        if(paidIn.compareTo(BigDecimal.valueOf(0.00))==0 || compPayInfo.getTransactionAmount().compareTo(tjCompPay.getPaidIn())>0 ){
-            return AjaxResult.error("鏆傛棤閫�璐归渶姹�");
-        }
-        compPayInfo.setTransactionAmount(BigDecimal.valueOf(0.00).subtract(compPayInfo.getTransactionAmount()));
-        compPayInfo.setPaymentMethod(3L);
-        if (getAjaxResult(compPayInfo, tjCompPay)) return AjaxResult.success("閫�璐规垚鍔�");
-        return AjaxResult.error("鎿嶄綔澶辫触");
-    }
-
-    private boolean getAjaxResult(@RequestBody TjCompPayInfo compPayInfo, TjCompPay tjCompPay) {
-        if(payInfoService.saveOrUpdate(compPayInfo)){
-            LambdaQueryWrapper<TjCompPayInfo> wq=new LambdaQueryWrapper<>();
-            wq.eq(TjCompPayInfo::getTjCompPayId,tjCompPay.getId());
-            List<TjCompPayInfo> list = payInfoService.list(wq);
-            BigDecimal bigDecimal=new BigDecimal("0.00");
-            if(null !=list && !list.isEmpty()){
-                for (TjCompPayInfo payInfo : list) {
-                    bigDecimal=bigDecimal.add(payInfo.getTransactionAmount());
+    @Transactional
+    public AjaxResult refund(@RequestBody TjCompPay compPay) {
+        try {
+            if(null !=compPay){
+                if (compPayService.removeById(compPay)) {
+                    LambdaQueryWrapper<TjCompPayInfo>wq=new LambdaQueryWrapper<>();
+                    wq.eq(TjCompPayInfo::getTjCompPayId,compPay.getId());
+                    payInfoService.remove(wq);
+                    LambdaQueryWrapper<TjFlowingWater> waterLambdaQueryWrappe=new LambdaQueryWrapper<>();
+                    waterLambdaQueryWrappe.eq(TjFlowingWater::getJsdh,compPay.getSerialNumber());
+                    List<TjFlowingWater> waterList = tjFlowingWaterService.list(waterLambdaQueryWrappe);
+                    if(null != waterList && !waterList.isEmpty()){
+                        for (TjFlowingWater water : waterList) {
+                            water.setSfjs("0");
+                            water.setJsdh(null);
+                            water.setJsrq(null);
+                            water.setJsrxm(null);
+                            water.setJsrdm(null);
+                            tjFlowingWaterService.updateById(water);
+                        }
+                    }
+                    return AjaxResult.success("鎿嶄綔鎴愬姛");
                 }
             }
-            tjCompPay.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
-            if(bigDecimal.compareTo(BigDecimal.valueOf(0.00))>= 0){
-                tjCompPay.setPaidIn(bigDecimal);
-            }else {
-                tjCompPay.setPaidIn(BigDecimal.valueOf(0.00));
-            }
-            tjCompPay.setDifference(tjCompPay.getCopeWith().subtract(bigDecimal));
-            compPayService.updateById(tjCompPay);
-            LambdaQueryWrapper<TjTeamSelectRecord>wq0=new LambdaQueryWrapper<>();
-            wq0.eq(TjTeamSelectRecord::getTeamNo,tjCompPay.getTeamNo());
-            wq0.eq(TjTeamSelectRecord::getCompId,tjCompPay.getCompId());
-            TjTeamSelectRecord record = selectRecordService.getOne(wq0);
-            record.setTransactionAmount(tjCompPay.getPaidIn());
-            selectRecordService.updateById(record);
-            return true;
+            return AjaxResult.error("鎿嶄綔澶辫触");
+        } catch (Exception e) {
+            log.error("鎿嶄綔澶辫触", e);
+            throw new RuntimeException(e);
         }
-        return false;
     }
 
     /**
@@ -157,20 +170,13 @@
                 wq.eq(TjTeamSelectRecord::getPacId, entry.getKey());
                 wq.eq(TjTeamSelectRecord::getCompId,compId);
                 TjTeamSelectRecord recordServiceOne = selectRecordService.getOne(wq);
-                if (null != recordServiceOne) {
-                    recordServiceOne.setPacId(entry.getKey());
-                    recordServiceOne.setCompId(compId);
-                    recordServiceOne.setTeamNo(entry.getValue().get(0).getTeamNo());
-                    recordServiceOne.setTransactionAmount(new BigDecimal("0.00"));
-                    recordServiceOne.setCount(entry.getValue().size());
-                    recordServiceOne.setDifference(compPay);
-                    selectRecordService.updateById(recordServiceOne);
-                } else {
+                if (null == recordServiceOne) {
                     TjTeamSelectRecord selectRecord = new TjTeamSelectRecord();
                     selectRecord.setCompId(compId);
                     selectRecord.setPacId(entry.getKey());
                     selectRecord.setTeamNo(entry.getValue().get(0).getTeamNo());
                     selectRecord.setTransactionAmount(new BigDecimal("0.00"));
+                    selectRecord.setCopeWith(compPay);
                     selectRecord.setCount(entry.getValue().size());
                     selectRecord.setDifference(compPay);
                     selectRecordService.save(selectRecord);
@@ -182,12 +188,13 @@
         if(null !=compId){
             wq0.eq(TjTeamSelectRecord::getCompId,compId);
         }
-        wq0.ne(TjTeamSelectRecord::getDifference,0);
         List<TjTeamSelectRecord> selectRecordList = selectRecordService.list(wq0);
         if(null !=selectRecordList && !selectRecordList.isEmpty()){
             for(TjTeamSelectRecord selectRecord : selectRecordList){
-                TjDwGrouping dwGrouping = dwGroupingService.getById(selectRecord.getPacId());
+                selectRecord.setSjCount(orderService.count(new LambdaQueryWrapper<TjOrder>()
+                        .eq(TjOrder::getTeamNo,selectRecord.getTeamNo()).eq(TjOrder::getPacId,selectRecord.getPacId())));
 
+                TjDwGrouping dwGrouping = dwGroupingService.getById(selectRecord.getPacId());
                 if(null !=dwGrouping){
                     selectRecord.setPacName(dwGrouping.getGroupingName());
                     selectRecord.setSigningPrice(dwGrouping.getSigningPrice());
@@ -195,18 +202,17 @@
                 LambdaQueryWrapper<TjCompPay>wq1=new LambdaQueryWrapper<>();
                 wq1.eq(TjCompPay::getCompId,compId);
                 wq1.eq(TjCompPay::getTeamNo,selectRecord.getTeamNo());
-                TjCompPay compPay = compPayService.getOne(wq1);
-                if (null !=compPay) {
-                    LambdaQueryWrapper<TjCompPayInfo>wq=new LambdaQueryWrapper<>();
-                    wq.eq(TjCompPayInfo::getTjCompPayId,compPay.getId());
-                    selectRecord.setPayInfoList(payInfoService.list(wq));
-                    selectRecord.setCopeWith(selectRecord.getDifference());
-                    selectRecord.setDifference(selectRecord.getDifference());
-                    selectRecord.setPayer(compService.getById(compPay.getCompId()).getContactPerson());
-                    selectRecord.setSjCount(orderService.count(new LambdaQueryWrapper<TjOrder>().eq(TjOrder::getTeamNo,compPay.getTeamNo())));
-                    TjCompPayInfo payInfo = new TjCompPayInfo();
-                    payInfo.setTjCompPayId(compPay.getId());
-                    selectRecord.setPayInfo(payInfo);
+                wq1.eq(TjCompPay::getPacId,selectRecord.getPacId());
+                List<TjCompPay> compPay = compPayService.list(wq1);
+                BigDecimal sumZje = compPayService.sumZje(compId,selectRecord.getTeamNo(),selectRecord.getPacId());
+                List<String> SerialNumbers = compPayService.serialNumbers(compId,selectRecord.getTeamNo(),selectRecord.getPacId());
+                if (null !=compPay && !compPay.isEmpty()) {
+                    selectRecord.setTransactionAmount(sumZje);
+                    selectRecord.setDifference(selectRecord.getCopeWith().subtract(sumZje));
+                    selectRecord.setYjsrs(tjFlowingWaterService.count(new LambdaQueryWrapper<TjFlowingWater>()
+                            .in(TjFlowingWater::getJsdh,SerialNumbers)));
+                }else {
+                    selectRecord.setYjsrs(0);
                 }
             }
         }
@@ -236,9 +242,11 @@
                 for (TjReservation reservation : reservationList) {
                     TeamTjPeopleVo vo = new TeamTjPeopleVo();
                     vo.setName(reservation.getName());
+                    vo.setXb(reservation.getSex().toString());
+                    vo.setDh(reservation.getPhoe());
                     TjCustomer customer = null;
                     try {
-                        customer = customerService.getOne(new LambdaQueryWrapper<TjCustomer>().eq(TjCustomer::getCusIdcard, reservation.getIdCard()));
+                        customer = customerService.getTjCustomerByCusIdCard( reservation.getIdCard());
                     } catch (Exception e) {
                         log.error("鏍规嵁鍥㈤槦缂栧彿鏌ヨ鍥㈤槦棰勭害淇℃伅寮傚父"+reservation.getIdCard());
                         throw new RuntimeException(e);
@@ -246,20 +254,30 @@
                     if (null != customer) {
                         TjOrder tjOrder = orderService.getOne(new LambdaQueryWrapper<TjOrder>().eq(TjOrder::getUserId, customer.getCusId()).eq(TjOrder::getTeamNo, teamNo));
                         if (null != tjOrder) {
-                            int sfwc = remarkService.panduaniswancheng(tjOrder.getTjNumber());
-                            if (sfwc==0) {
-                                vo.setTjStatus("宸插畬鎴�");
-                                vo.setTjTime(tjOrder.getCreateTime());
-                            } else {
-                                vo.setTjStatus("鍦� 妫�");
+                            TjFlowingWater water = tjFlowingWaterService.getOne(new LambdaQueryWrapper<TjFlowingWater>()
+                                    .eq(TjFlowingWater::getOrderId, tjOrder.getOrderId()).eq(TjFlowingWater::getIsAddition, "N"));
+                            if(null != water && water.getSfjs().equals("0") && water.getJsrq() ==null){
+                                vo.setTjh(tjOrder.getTjNumber());
+                                int sfwc = remarkService.panduaniswancheng(tjOrder.getTjNumber());
+                                if (sfwc==0) {
+                                    vo.setTjStatus("宸插畬鎴�");
+                                    vo.setTjTime(DateUtil.format(tjOrder.getCreateTime(),"yyyy-MM-dd"));
+                                    vo.setTjf(water.getPaidIn());
+                                } else {
+                                    vo.setTjTime(DateUtil.format(tjOrder.getCreateTime(),"yyyy-MM-dd"));
+                                    vo.setTjf(water.getPaidIn());
+                                    vo.setTjStatus("鍦� 妫�");
+                                }
+                                yjwjzList.add(vo);
                             }
-                            yjwjzList.add(vo);
                         } else {
                             vo.setTjStatus("鏈� 妫�");
+                            vo.setTjf(transitionService.sumNowPrice(reservation.getIdCard()));
                             wjList.add(vo);
                         }
                     }else {
                         vo.setTjStatus("鏈� 妫�");
+                        vo.setTjf(transitionService.sumNowPrice(reservation.getIdCard()));
                         wjList.add(vo);
                     }
                     syList.add(vo);
@@ -276,4 +294,31 @@
             throw new RuntimeException(e);
         }
     }
+
+
+
+    @GetMapping("/getTjCompPay")
+    @ApiOperation(value = "鏍规嵁鍥㈤槦浣撴缂栧彿鍜屽椁恑d鑾峰彇缁撹处淇℃伅")
+    public AjaxResult getTjCompPay(@RequestParam @ApiParam(value = "鍥㈤槦缂栧彿") String teamNo,
+                                          @RequestParam(required = false) @ApiParam(value = "鍗曚綅id") String pacId) {
+
+        try {
+             LambdaQueryWrapper<TjCompPay> wq = new LambdaQueryWrapper<>();
+             wq.eq(TjCompPay::getTeamNo, teamNo);
+             wq.eq(TjCompPay::getCompId, pacId);
+             List<TjCompPay> tjCompPays = compPayService.list(wq);
+             if(null !=tjCompPays && !tjCompPays.isEmpty()){
+                 for (TjCompPay pay : tjCompPays) {
+                     LambdaQueryWrapper<TjCompPayInfo> wqInfo = new LambdaQueryWrapper<>();
+                     wqInfo.eq(TjCompPayInfo::getTjCompPayId, pay.getId());
+                     List<TjCompPayInfo> payInfos = payInfoService.list(wqInfo);
+                     pay.setPayInfo(payInfos);
+                 }
+             }
+            return AjaxResult.success(tjCompPays);
+        } catch (Exception e) {
+            log.error("鏌ヨ鍥㈤槦浣撴浜哄憳淇℃伅寮傚父");
+            throw new RuntimeException(e);
+        }
+    }
 }

--
Gitblit v1.8.0