From edbfa6b1a3a45e79cb17b06f3798535c3b1ba395 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期三, 18 十一月 2026 09:12:39 +0800
Subject: [PATCH] 修改了增值税城建税

---
 ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java |  624 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 528 insertions(+), 96 deletions(-)

diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
index 20a5bff..b488cf0 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
@@ -16,11 +16,13 @@
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.enums.ApplyTypeEnum;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.HttpClientKit;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.DtoConversionUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.project.common.FundNotifyMessageBuilder;
 import com.ruoyi.project.common.IdGeneratorUtils;
 import com.ruoyi.project.domain.*;
 import com.ruoyi.project.domain.vo.*;
@@ -28,6 +30,7 @@
 import com.ruoyi.project.service.*;
 import com.ruoyi.system.mapper.SysUserMapper;
 import com.ruoyi.system.mapper.SysUserRoleMapper;
+import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysUserService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
@@ -61,6 +64,10 @@
 public class ServiceFundServiceImpl extends ServiceImpl<ServiceFundMapper, ServiceFund> implements IServiceFundService {
     @Autowired
     ServiceFundMapper serviceFundMapper;
+
+    /** 涓撳鍔冲姟璐� 9 鏉¤垂鐢ㄦ帶鍒惰鍒欐牎楠岋紙鍚屼竴妗堜緥绱锛� */
+    @Autowired
+    private ExpertFeeValidateService expertFeeValidateService;
 
     @Autowired
     private DingTalkService dingTalkService;
@@ -137,6 +144,35 @@
     @Value("${spring.profiles.active}")
     private String active;
 
+    @Autowired
+    private ISysConfigService sysConfigService;
+
+    /**
+     * 瀹℃壒鍗曟槸鍚︿笂浼犲尰闄㈠崗鍙嬶紙鑷磋繙锛夌郴缁燂細0=涓嶄笂浼狅紙娴嬭瘯鐜锛夛紝1=涓婁紶锛堟寮忕幆澧冿級銆�
+     *
+     * <p>2026-10-09 鏂板锛氬師鏉ョ敤 {@code spring.profiles.active == druid} 鍒ゆ柇鏄惁鎺ㄩ�侊紝
+     * 娴嬭瘯鐜涓庢寮忕幆澧冩棤娉曢�氳繃鍙傛暟鍖哄垎銆傛敼涓虹郴缁熷弬鏁版帶鍒躲��
+     */
+    private static final String CFG_UPLOAD_OA = "sys.approval.upload.oa";
+
+    /** 鍙傛暟缂虹渷鍊硷細涓婁紶锛堜繚鎸佹寮忕幆澧冨師鏈夎涓猴級 */
+    private static final boolean DEFAULT_UPLOAD_OA = true;
+
+    /** 瀹℃壒鍗曟槸鍚﹂渶瑕佷笂浼犲尰闄㈠崗鍙嬶紙鑷磋繙锛夌郴缁� */
+    private boolean isUploadOaEnabled() {
+        String value = null;
+        try {
+            value = sysConfigService.selectConfigByKey(CFG_UPLOAD_OA);
+        } catch (Exception e) {
+            log.warn("璇诲彇鍙傛暟 {} 澶辫触锛屾寜榛樿鍊� {} 澶勭悊", CFG_UPLOAD_OA, DEFAULT_UPLOAD_OA, e);
+        }
+        if (value == null || value.trim().isEmpty()) {
+            return DEFAULT_UPLOAD_OA;
+        }
+        String v = value.trim();
+        return "1".equals(v) || "true".equalsIgnoreCase(v) || "y".equalsIgnoreCase(v) || "on".equalsIgnoreCase(v);
+    }
+
     /**
      * 鑷磋繙绯荤粺娴佺▼閫�鍥�
      *
@@ -199,6 +235,12 @@
         String phone = null;
         String applytype = null;
         Long flowlevel = null;
+        //閽夐拤閫氱煡鐢ㄧ殑鍗曟嵁淇℃伅
+        Double amount = null;
+        String donorName = null;
+        String billNo = null;
+        String travelers = null;
+        String reason = null;
         if (serviceProcessVO.getApplytype().equals("0")) {
             ServiceReimbursement serviceReimbursement = new ServiceReimbursement();
             serviceReimbursement.setId(StringUtils.isNotEmpty(serviceProcessVO.getBackCode()) ? Long.valueOf(serviceProcessVO.getBackCode()) : null);
@@ -213,6 +255,11 @@
             phone = serviceReimbursementList.get(0).getPhone();
             flowlevel = serviceReimbursementList.get(0).getFlowlevel();
             applytype = "0";
+            amount = serviceReimbursementList.get(0).getAmountrequested();
+            billNo = FundNotifyMessageBuilder.billNo(serviceReimbursementList.get(0).getBh(),
+                    serviceReimbursementList.get(0).getId());
+            travelers = serviceReimbursementList.get(0).getTravelers();
+            reason = serviceReimbursementList.get(0).getReason();
         } else {
             ServiceFund serviceFund = new ServiceFund();
             serviceFund.setId(StringUtils.isNotEmpty(serviceProcessVO.getBackCode()) ? Long.valueOf(serviceProcessVO.getBackCode()) : null);
@@ -226,6 +273,10 @@
             phone = serviceFunds.get(0).getPhone();
             flowlevel = serviceFunds.get(0).getFlowlevel();
             applytype = serviceFunds.get(0).getApplytype();
+            amount = serviceFunds.get(0).getPretaxcost();
+            donorName = serviceFunds.get(0).getDonorname();
+            billNo = FundNotifyMessageBuilder.billNo(serviceFunds.get(0).getBh(),
+                    serviceFunds.get(0).getId());
         }
 
 //        //灏嗘搷浣滀繚瀛樺埌fundflow琛ㄤ腑
@@ -248,7 +299,16 @@
 
 
         SysUser sysUser = sysUserService.selectUserByUserName(userNo);
-        sendMeg(serviceProcessVO, phone);
+
+        //閽夐拤閫氱煡鍐呭锛氬崟鎹俊鎭紙绫诲瀷/鎶ラ攢浜�/閲戦/妗堜緥/缂栧彿锛�+ 瀹℃壒浜�/瀹℃壒鏃堕棿/鎰忚
+        List<ConcurrentHashMap<String, Object>> notifyRows = FundNotifyMessageBuilder.newRows();
+        FundNotifyMessageBuilder.addBillInfo(notifyRows, applytype, userName, amount, donorName, billNo);
+        FundNotifyMessageBuilder.addTravelInfo(notifyRows, travelers, reason);
+        FundNotifyMessageBuilder.addAuditResult(notifyRows, serviceProcessVO.getCheckusername(),
+                serviceProcessVO.getCheckTime(),
+                FundNotifyMessageBuilder.opinion(serviceProcessVO.getFlowconclusion(),
+                        serviceProcessVO.getFlowcontent()));
+        sendMeg(serviceProcessVO, phone, notifyRows);
         //鍙戦�佷俊鎭繚瀛�
         ServiceSystemmessage serviceSystemmessage = new ServiceSystemmessage();
         serviceSystemmessage.setFundtype(1);
@@ -260,7 +320,7 @@
         serviceSystemmessage.setUpdateBy(sysUser.getNickName());
         serviceSystemmessage.setIsread(0);
         serviceSystemmessage.setMessagetype(1);
-        serviceSystemmessage.setMessagetitle("璐㈠姟绯荤粺淇℃伅");
+        serviceSystemmessage.setMessagetitle("OPO绯荤粺瀹℃壒");
         serviceSystemmessage.setMessagecontent(serviceProcessVO.getFlowcontent());
         iServiceSystemmessageService.save(serviceSystemmessage);
 
@@ -374,6 +434,7 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Map<String, String> checkFund(CheckFundVO checkFundVO, LoginUser loginUser) {
         ServiceFund serviceFund = getById(checkFundVO.getFundid());
         Map<String, String> map = new HashMap<>();
@@ -381,6 +442,19 @@
         if (serviceFund == null) {
             map.put(HttpStatus.NO_CONTENT + "", "璐圭敤缂栧彿涓嶆纭�");
             return map;
+        }
+
+        // 涓撳鍔冲姟璐癸細瀹℃牳鈥滈�氳繃鈥濆墠鏍¢獙 9 鏉¤垂鐢ㄦ帶鍒惰鍒欙紙鍚屼竴妗堜緥绱锛夛紱涓嶉�氳繃鍒欎笉闃绘柇
+        if (checkFundVO.getFlowconclusion() != null && checkFundVO.getFlowconclusion() == 1) {
+            ExpertFeeCheckResult expertFeeResult = expertFeeValidateService.validateBeforeCheck(checkFundVO.getFundid());
+            if (expertFeeResult.hasError()) {
+                map.put(HttpStatus.ERROR + "", expertFeeResult.errorMessage());
+                return map;
+            }
+            if (expertFeeResult.hasWarning()) {
+                // 瑙勫垯 5銆�6 浠呮彁绀猴紝涓嶉樆鏂鏍�
+                log.warn("涓撳鍔冲姟璐瑰鏍告牎楠屾彁绀猴細fundId={}锛寋}", checkFundVO.getFundid(), expertFeeResult.warningMessage());
+            }
         }
 
         Integer TotalLevel = 0;
@@ -409,6 +483,11 @@
         Integer RecordStatus = serviceFund.getRecordstatus();
         Integer FlowLevel = serviceFund.getFlowlevel().intValue();
         Integer OriginalFlowLevel = FlowLevel;
+        //瀹℃壒缁撹蹇呭~锛氬師瀹炵幇鐩存帴 == 1 鎷嗙锛屾帴鍙h鐩磋皟浼� null 浼� NPE 500
+        if (checkFundVO.getFlowconclusion() == null) {
+            map.put(HttpStatus.ERROR + "", "瀹℃壒缁撹涓嶈兘涓虹┖");
+            return map;
+        }
         if (checkFundVO.getFlowconclusion() == 1) {
             CheckFlag = 1;
             if (TotalLevel == 0) {
@@ -437,8 +516,9 @@
                 if (newSwitch == 1) {
                     aBoolean1 = sendData(serviceFund);
                     if (!aBoolean1) {
-                        map.put("500", "鍙戦�佸け璐�");
-                        return map;
+                        // 鎺ㄩ�佸尰闄㈠崗鍙嬬郴缁熷け璐ワ細鏁翠釜瀹℃壒涓嶇敓鏁堬紙浜嬪姟鍥炴粴锛夛紝鍏佽涓嬫閲嶆柊瀹℃壒
+                        log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷け璐ワ紝瀹℃壒涓嶇敓鏁堬紝fundId={}锛岃閲嶆柊瀹℃壒", serviceFund.getId());
+                        throw new ServiceException("鍖婚櫌鍗忓弸绯荤粺鎺ユ敹澶辫触锛屾湰娆″鎵规湭鐢熸晥锛岃绋嶅悗閲嶆柊瀹℃壒");
                     }
                 }
                 //淇濆瓨瀹℃壒娴佺▼琛�
@@ -479,22 +559,25 @@
                     FlowLevel = 0;
                 }
             }
-
-            SysUser sysUser = sysUserService.selectUserByUserName(serviceFund.getUserno());
-            ArrayList<ConcurrentHashMap<String, Object>> contentList = new ArrayList<>();
-            ConcurrentHashMap cmap = new ConcurrentHashMap();
-            cmap.put("瀹℃壒浜猴細", loginUser.getUser().getUserName());
-            cmap.put("瀹℃壒鏃堕棿锛�", new Date());
-            cmap.put("鎰忚锛�", "涓嶉�氳繃");
-            if (StringUtils.isNotBlank(checkFundVO.getFlowcontent())) cmap.put("鎰忚锛�", checkFundVO.getFlowcontent());
-            contentList.add(cmap);
+        }
+        SysUser sysUser = sysUserService.selectUserByUserName(serviceFund.getUserno());
+        //瀹℃壒鏈�氳繃锛氬崟鎹俊鎭� + 瀹℃壒浜�/瀹℃壒鏃堕棿/鎰忚锛堟剰瑙� = "瀹℃壒鏈�氳繃銆�" + 椹冲洖鎰忚锛�
+        List<ConcurrentHashMap<String, Object>> contentList = FundNotifyMessageBuilder.newRows();
+        FundNotifyMessageBuilder.addBillInfo(contentList, serviceFund.getApplytype(),
+                serviceFund.getUsername(), serviceFund.getPretaxcost(), serviceFund.getDonorname(),
+                FundNotifyMessageBuilder.billNo(serviceFund.getBh(), serviceFund.getId()));
+        FundNotifyMessageBuilder.addAuditResult(contentList, loginUser.getUser().getNickName(), new Date(),
+                FundNotifyMessageBuilder.opinion(checkFundVO.getFlowconclusion()+"",
+                        checkFundVO.getFlowcontent()));
+        try {
             DingTalkReqVo dingTalkReqVo = new DingTalkReqVo();
-            dingTalkReqVo.setTitle("璐㈠姟绯荤粺椹冲洖淇℃伅");
+            dingTalkReqVo.setTitle(FundNotifyMessageBuilder.TITLE);
             dingTalkReqVo.setNumber(sysUser.getPhonenumber());
             dingTalkReqVo.setContents(contentList);
             dingTalkService.sendNotification(dingTalkReqVo);
+        } catch (Exception e) {
+            log.error("璐圭敤---瀹℃壒鏈�氳繃閽夐拤閫氱煡澶辫触锛宖undId={}", serviceFund.getId(), e);
         }
-
         serviceFund.setRecordstatus(RecordStatus);
         serviceFund.setFlowlevel(FlowLevel.longValue());
         //  serviceFund.setBackflowlevel(serviceFund.getFlowlevel());
@@ -519,26 +602,32 @@
         log.info("sserviceFund淇濆瓨鐨勭殑鍊兼槸-------- :{}", aBoolean);
 
         //鍔炲叕瀹ゅ鎵归�氳繃涔嬪悗锛屽氨闇�瑕佹妸鈥滃姙鍏涓讳换鈥濈殑鍚嶅瓧濉笂
-        List<SysUser> sysUsers =null;
-        if(StringUtils.isNotEmpty(user.getUserName())) {
-            SysUser su = new SysUser();
-            su.setUserName(user.getUserName());
-           sysUsers = sysUserMapper.selectAllocatedList(su);
-           log.info("璐圭敤sysUsers杩斿洖鐨勫�间负:{}", sysUsers);
+        SysUser sysUsers = null;
+        if (StringUtils.isNotEmpty(user.getUserName())) {
+            sysUsers = sysUserMapper.selectUserByUserName(user.getUserName());
+            log.info("璐圭敤sysUsers杩斿洖鐨勫�间负:{}", sysUsers);
         }
-        if (checkFundVO.getFlowconclusion() == 1 && sysUsers != null && !sysUsers.isEmpty()
-                && sysUsers.get(0).getRoles() != null
-                && sysUsers.get(0).getRoles().stream().anyMatch(role -> "officedirector".equals(role.getRoleKey()))) {
-            serviceFund.setOfficedirector(user.getNickName());
+        // 2026-10-09锛氭帹閫佹潯浠剁敱"褰撳墠瀹℃牳浜烘湁 officedirector 瑙掕壊"鏀逛负"鏈瀹℃壒鍚庡埌杈炬渶鍚庝竴绾�"銆�
+        // 鍘熷啓娉曞湪"鏈�鍚庝竴绾у鏍镐汉娌℃湁璇ヨ鑹�"鏃舵案杩滀笉浼氭帹閫侊紝鑰�"闈炴渶鍚庝竴绾х殑 officedirector"浼氭彁鍓嶆帹閫併��
+        boolean uploadAtLastLevel = checkFundVO.getFlowconclusion() == 1
+                && TotalLevel != null && TotalLevel != 0 && TotalLevel == OriginalFlowLevel + 1;
+        if (uploadAtLastLevel) {
+            // 浠嶅彧鍦ㄨ瑙掕壊瀹℃壒鏃惰褰曞姙鍏涓讳换锛屼繚鎸佸瓧娈佃涔変笉鍙�
+            if (sysUsers != null && sysUsers.getRoles() != null
+                    && sysUsers.getRoles().stream().anyMatch(role -> "officedirector".equals(role.getRoleKey()))) {
+                serviceFund.setOfficedirector(user.getNickName());
+            }
             serviceFund.setUploadStates(1);
             //鏁版嵁鍙戦��
             Boolean aBoolean1 = null;
             if (newSwitch == 1) {
+                log.info("璐圭敤newSwitch杩斿洖鐨勫�间负:{}", newSwitch);
                 //鎼炰竴涓紑鍏筹紝鍒奖鍝嶈�佹祦绋�
                 aBoolean1 = sendData(serviceFund);
                 if (!aBoolean1) {
-                    map.put("500", "鍙戦�佸け璐�");
-                    return map;
+                    // 鎺ㄩ�佸尰闄㈠崗鍙嬬郴缁熷け璐ワ細鏁翠釜瀹℃壒涓嶇敓鏁堬紙浜嬪姟鍥炴粴锛夛紝鍏佽涓嬫閲嶆柊瀹℃壒
+                    log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷け璐ワ紝瀹℃壒涓嶇敓鏁堬紝fundId={}锛岃閲嶆柊瀹℃壒", serviceFund.getId());
+                    throw new ServiceException("鍖婚櫌鍗忓弸绯荤粺鎺ユ敹澶辫触锛屾湰娆″鎵规湭鐢熸晥锛岃绋嶅悗閲嶆柊瀹℃壒");
                 }
             }
         }
@@ -602,9 +691,36 @@
 
     }
 
+    /**
+     * 瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬶紙鑷磋繙锛夌郴缁熴��
+     *
+     * <p>2026-10-09锛氬灞傚寘涓�灞傚厹搴曪紝淇濊瘉**浠讳綍寮傚父閮戒笉浼氬悜澶栨姏**锛堝師鏉� strRes 涓� null 鏃�
+     * 浼氬湪 parseObject 鍚庡彇 code 瑙﹀彂 NPE锛屾妸鏁翠釜瀹℃壒璇锋眰鎵撴垚 500锛夈��
+     * 杩斿洖 false 琛ㄧず鎺ㄩ�佸け璐ワ紝璋冪敤鏂规寜"瀹℃壒涓嶇敓鏁堛�佸厑璁镐笅娆¢噸鏂板鎵�"澶勭悊銆�
+     */
     public Boolean sendData(ServiceFund serviceFund) {
-        // fund鍜宖unddetail鐨勬暟鎹幏鍙�
-        addFundSharedInfo(serviceFund.getId());
+        if (!isUploadOaEnabled()) {
+            // 涓婁紶寮�鍏冲叧闂紙濡傛祴璇曠幆澧冿級锛氳烦杩囦笂浼犲苟瑙嗕负鎴愬姛锛岀粷涓嶈兘鍥犳闃绘柇瀹℃壒
+            log.info("瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷凡鍏抽棴锛坰ys.approval.upload.oa != 1锛夛紝璺宠繃涓婁紶骞惰涓烘垚鍔燂紝fundId={}",
+                    serviceFund == null ? null : serviceFund.getId());
+            return true;
+        }
+        try {
+            return doSendData(serviceFund);
+        } catch (Throwable t) {
+            log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷紓甯革紝瀹℃壒涓嶇敓鏁堬紝fundId={}",
+                    serviceFund == null ? null : serviceFund.getId(), t);
+            return false;
+        }
+    }
+
+    private Boolean doSendData(ServiceFund serviceFund) {
+        // 2026-10-09锛氭帴浣� addFundSharedInfo 鐨勫け璐ヤ俊鍙凤紙闄勪欢涓婁紶澶辫触鏃跺畠浼氬洖婊氬垎浜〃骞惰繑鍥� false锛�
+        Boolean sharedOk = addFundSharedInfo(serviceFund.getId());
+        if (sharedOk == null || !sharedOk) {
+            log.error("璐圭敤鎶ラ攢鍗曚笂浼犲け璐ワ細鍒嗕韩琛�/闄勪欢鐜妭澶辫触锛屽鎵逛笉鐢熸晥锛宖undId={}", serviceFund.getId());
+            return false;
+        }
         List<ServiceFundShared> fundShareInfos = serviceFundSharedMapper.getFundShareInfoById(serviceFund.getId());
         if (CollectionUtils.isEmpty(fundShareInfos)) return false;
 
@@ -643,7 +759,7 @@
 
         map.put("data", data);
         String strRes = null;
-        if (!active.equals("druid")) {
+        if (isUploadOaEnabled()) {
             //濡傛灉鏄湰鍦扮幆澧冿紝灏变笉璋冭繖涓簡
             String token = getToken();
             JSONObject json1 = JSONObject.parseObject(token);
@@ -683,9 +799,28 @@
             }
         }
         log.error("------------------strRes鐨勫�间负锛歿}", strRes);
-        JSONObject jsonObject = JSONObject.parseObject(strRes);
+        if (strRes == null || strRes.trim().isEmpty()) {
+            // 鍖婚櫌鍗忓弸绯荤粺鏃犺繑鍥烇紙瓒呮椂/寮傚父/鏈厤缃級锛氭帹閫佸け璐ワ紝鐢辫皟鐢ㄦ柟鍥炴粴鏁翠釜瀹℃壒
+            log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷け璐ワ細鎺ュ彛鏃犺繑鍥炲唴瀹癸紝fundId={}", serviceFund.getId());
+            return false;
+        }
+        JSONObject jsonObject = null;
+        try {
+            jsonObject = JSONObject.parseObject(strRes);
+        } catch (Exception e) {
+            log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷け璐ワ細杩斿洖鍐呭鏃犳硶瑙f瀽锛宖undId={}锛宻trRes={}",
+                    serviceFund.getId(), strRes, e);
+            return false;
+        }
+        if (jsonObject == null) {
+            log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷け璐ワ細杩斿洖鍐呭涓虹┖锛宖undId={}锛宻trRes={}",
+                    serviceFund.getId(), strRes);
+            return false;
+        }
         String code = jsonObject.getString("code");
-        if (!code.equals("0")) {
+        if (code == null || !"0".equals(code)) {
+            log.error("璐圭敤瀹℃壒鍗曚笂浼犲尰闄㈠崗鍙嬬郴缁熷け璐ワ細code={}锛宖undId={}锛宻trRes={}",
+                    code, serviceFund.getId(), strRes);
             return false;
         }
 
@@ -718,7 +853,9 @@
             }
             map.put("鍙戠エ璇嗗埆", null);
             map.put("璇嗗埆浜�", null);
-            map.put("绋庨", serviceFunddetailShared.getTaxamount());
+            // 鏄庣粏鈥滅◣棰濃�濇寜鈥滄墸绋庡悎璁♀�濆彛寰勶細鍔冲姟涓◣ + 澧炲�肩◣ + 鍩庡缓绋庯紝
+            // 涓庝富琛ㄢ�滅◣棰濆悎璁♀�濓紙PretaxCost 鈭� TaxedCost锛夊榻愶紱v1 鍘嗗彶鏁版嵁澧炲�肩◣/鍩庡缓绋庝负 0锛屽彇鍊间笌鏀归�犲墠涓�鑷淬��
+            map.put("绋庨", totalTaxOf(serviceFunddetailShared));
             long qtuuid = IdGeneratorUtils.nextId();
             map.put("鍏朵粬闄勪欢", "");
             if (StringUtils.isNotEmpty(annexfiles)) {
@@ -763,6 +900,23 @@
         return allMap;
     }
 
+    /**
+     * 鏄庣粏涓婁紶鍗忓弸鐨勨�滅◣棰濃�� = 鍔冲姟涓◣ + 澧炲�肩◣ + 鍩庡缓绋庯紙鎵g◣鍚堣鍙e緞锛夈��
+     * <p>
+     * 鑳屾櫙锛�2026-11 鏂板澧炲�肩◣銆佸煄寤虹◣鍚庯紝涓昏〃鈥滅◣棰濆悎璁♀�濆彇 `PretaxCost 鈭� TaxedCost`锛�
+     * 澶╃劧鍖呭惈杩欎袱椤癸紱鑻ユ槑缁嗕粛鍙彂鍔冲姟涓◣锛岃嚧杩滈噷鈥滅◣棰濆悎璁� 鈮� 鏄庣粏绋庨涔嬪拰鈥濓紙宸鍊肩◣+鍩庡缓绋庯級銆�
+     * v1 鍘嗗彶鏁版嵁鐨勫鍊肩◣/鍩庡缓绋庡潎涓� 0锛屽彇鍊间笌鏀归�犲墠瀹屽叏涓�鑷淬��
+     */
+    private static BigDecimal totalTaxOf(ServiceFunddetailShared detail) {
+        if (detail == null) {
+            return BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP);
+        }
+        BigDecimal tax = detail.getTaxamount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getTaxamount());
+        BigDecimal vat = detail.getVatAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getVatAmount());
+        BigDecimal city = detail.getCityTaxAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getCityTaxAmount());
+        return tax.add(vat).add(city).setScale(2, BigDecimal.ROUND_HALF_UP);
+    }
+
 
     private Map<String, Object> getformmain_0831(ServiceFund serviceFund) {
         ServiceFundflow serviceFundflow = new ServiceFundflow();
@@ -782,16 +936,17 @@
         formmain_0831.put("璐㈠姟瀹℃壒", null);
         formmain_0831.put("璐㈠姟閮ㄨ礋璐d汉瀹℃壒", getLastApprovalInfo(serviceFundflows, serviceFund.getFinancedirector()));
 
-//        formmain_0831.put("鍔炲叕瀹や富浠诲鎵�", "鍔炲叕瀹や富浠诲鎵�", "瀹℃壒浜猴細鍛ㄨ偛鎴� & 瀹℃壒鏃堕棿锛�" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " & 瀹℃壒缁撴灉锛氶�氳繃");
+//        formmain_0831.put("鍔炲叕瀹や富浠诲鎵�", "鍔炲叕瀹や富浠诲鎵�", "瀹℃壒浜猴細鍚村織寮� & 瀹℃壒鏃堕棿锛�" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " & 瀹℃壒缁撴灉锛氶�氳繃");
         if (serviceFund.getBackflowlevel() == 3)
-            formmain_0831.put("鍔炲叕瀹や富浠诲鎵�", "瀹℃壒浜猴細鍛ㄨ偛鎴� & 瀹℃壒鏃堕棿锛�" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " & 瀹℃壒缁撴灉锛氶�氳繃");
-        else formmain_0831.put("鍔炲叕瀹や富浠诲鎵�", getLastApprovalInfo(serviceFundflows, "鍛ㄨ偛鎴�"));
+            formmain_0831.put("鍔炲叕瀹や富浠诲鎵�", "瀹℃壒浜猴細鍚村織寮� & 瀹℃壒鏃堕棿锛�" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " & 瀹℃壒缁撴灉锛氶�氳繃");
+        else formmain_0831.put("鍔炲叕瀹や富浠诲鎵�", getLastApprovalInfo(serviceFundflows, "鍚村織寮�"));
 
         formmain_0831.put("涓氬姟鍓櫌闀垮鎵�", serviceFund.getBusvicepresident());
         formmain_0831.put("璐㈠姟鍓櫌闀垮鎵�", serviceFund.getFinvicepresident());
         formmain_0831.put("涓績璐熻矗浜哄鎵�", serviceFund.getOpochecker());
         formmain_0831.put("鏀粯鏂瑰紡", serviceFund.getZffs());
-        formmain_0831.put("缁勯暱", getLastApprovalInfo(serviceFundflows, serviceFund.getManagername()));
+        String lastApprovalInfo = getLastApprovalInfo(serviceFundflows, serviceFund.getManagername());
+        formmain_0831.put("缁勯暱", lastApprovalInfo.contains("鍚村織寮�") ? null : lastApprovalInfo);
         formmain_0831.put("瀹℃壒浜哄憳", StringUtils.isEmpty(getLastApprovalInfo(serviceFundflows, serviceFund.getFinancechecher())) ? "闄堟厱鍗�" : getLastApprovalInfo(serviceFundflows, serviceFund.getFinancechecher()));
         formmain_0831.put("鏀粯鏃ユ湡", serviceFund.getRiqi());
         formmain_0831.put("璇嗗埆浜�-浣滃簾", null);
@@ -883,13 +1038,12 @@
             serviceFunddetailShareds.get(i).setId(null);
             //鏁版嵁鍙戦�佺粰璐㈠姟
             try {
-                if (!active.equals("druid")) uploadOAFileAndUpdateDb(serviceFunddetailShareds.get(i));
+                if (isUploadOaEnabled()) uploadOAFileAndUpdateDb(serviceFunddetailShareds.get(i));
             } catch (Exception e) {
-                e.printStackTrace();
-                log.error("Exception涓叆鍙傜殑ID涓猴細{},寮傚父淇℃伅涓� 锛� {}", id, e.getMessage());
+                log.error("璐圭敤闄勪欢涓婁紶鍖婚櫌鍗忓弸绯荤粺澶辫触锛氬崟鎹甶d={}锛堟湰娆℃姤閿�鍗曚笂浼犳暣浣撳け璐ワ紝瀹℃壒涓嶇敓鏁堬級", id, e);
                 if (id != null) {
                     Boolean aBoolean = sharedService.delfundsharedInfoById(null, id);
-                    log.error("fund2鍒嗕韩琛ㄩ噷鐨勬暟鎹槸鍚﹀垹闄ゆ垚鍔燂細{}", aBoolean);
+                    log.error("宸插洖婊氬垎浜〃鏁版嵁锛歿}", aBoolean);
                 }
                 return false;
             }
@@ -1419,8 +1573,23 @@
     }
 
     @Override
+    public ExpertFeeCheckResult validateExpertFee(ServiceFundVO serviceFundVO) {
+        return expertFeeValidateService.validateBeforeSave(serviceFundVO);
+    }
+
+    @Override
     @Transactional(rollbackFor = Exception.class)
     public Long addOrUpdateNew(ServiceFundVO serviceFundVO) {
+        // 涓撳鍔冲姟璐癸細淇濆瓨鍓嶆牎楠� 9 鏉¤垂鐢ㄦ帶鍒惰鍒欙紙鍚屼竴妗堜緥绱锛�
+        ExpertFeeCheckResult expertFeeResult = expertFeeValidateService.validateBeforeSave(serviceFundVO);
+        if (expertFeeResult.hasError()) {
+            throw new BaseException(expertFeeResult.errorMessage());
+        }
+        if (expertFeeResult.hasWarning()) {
+            // 瑙勫垯 5銆�6 浠呮彁绀猴紝涓嶉樆鏂繚瀛橈紱鍓嶇鍗曠嫭鍙栫敤鎻愮ず鏂囨
+            log.warn("涓撳鍔冲姟璐逛繚瀛樻牎楠屾彁绀猴細{}", expertFeeResult.warningMessage());
+        }
+
         Long id = null;
         //灏嗘暟鎹繚瀛樺埌fund琛�
         serviceFundVO.setUploadStates(0);
@@ -1433,6 +1602,28 @@
 
             // 淇濆瓨璇︽儏鏁版嵁
             for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetails) {
+                // 2026-10-15锛氶檮浠舵枃浠跺悕瑙勮寖浜屾鏍¢獙锛堜笌鍓嶇 fileNameCheck 鍚屽彛寰勶紱鍙牎楠屾湰娆″彉鏇寸殑闄勪欢锛屽巻鍙查檮浠舵斁琛岋級
+                java.util.Set<String> existingNames = new java.util.HashSet<>();
+                if (serviceFunddetailVO.getId() != null) {
+                    ServiceFunddetail oldDetail = serviceFunddetailMapper.selectById(serviceFunddetailVO.getId());
+                    if (oldDetail != null) {
+                        existingNames.addAll(com.ruoyi.project.common.AttachmentNameValidator
+                                .collectNames(oldDetail.getInvoicefiles()));
+                        existingNames.addAll(com.ruoyi.project.common.AttachmentNameValidator
+                                .collectNames(oldDetail.getAnnexfiles()));
+                    }
+                }
+                String invoiceJson = CollectionUtils.isEmpty(serviceFunddetailVO.getInvoicefilesList())
+                        ? serviceFunddetailVO.getInvoicefiles()
+                        : JSON.toJSONString(serviceFunddetailVO.getInvoicefilesList());
+                String annexJson = CollectionUtils.isEmpty(serviceFunddetailVO.getAnnexfilesList())
+                        ? serviceFunddetailVO.getAnnexfiles()
+                        : JSON.toJSONString(serviceFunddetailVO.getAnnexfilesList());
+                String nameError = com.ruoyi.project.common.AttachmentNameValidator
+                        .checkJsonListForUpdate(existingNames, invoiceJson, annexJson);
+                if (nameError != null) {
+                    throw new BaseException("闄勪欢鏂囦欢鍚嶄笉绗﹀悎瑕佹眰锛屾棤娉曚繚瀛橈細" + nameError);
+                }
                 //鍘绘帀韬唤璇佺殑棣栧熬绌烘牸
                 if (StringUtils.isNotEmpty(serviceFunddetailVO.getIdcardno())) {
                     serviceFunddetailVO.setIdcardno(serviceFunddetailVO.getIdcardno().trim());
@@ -1482,10 +1673,9 @@
             return null;
         }
 
-        //鎬荤◣鍓�
-        Double pretaxcosts = 0.00;
-        //鎬荤◣鍚�
-        Double taxedcosts = 0.00;
+        //鎬荤◣鍓嶃�佹�荤◣鍚庯紙閲戦绱姞鐢� BigDecimal锛岄伩鍏嶆诞鐐瑰熬宸級
+        BigDecimal pretaxcosts = BigDecimal.ZERO;
+        BigDecimal taxedcosts = BigDecimal.ZERO;
         for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetails) {
             serviceFunddetailVO.setFundid(id);
 
@@ -1494,13 +1684,18 @@
             if (!performance.isEmpty()) {
                 Double amount = performance.get("amount");
                 Double taxedamount = performance.get("taxedamount");
-                pretaxcosts = pretaxcosts + amount;
-                taxedcosts = taxedcosts + taxedamount;
+                if (amount != null) {
+                    pretaxcosts = pretaxcosts.add(BigDecimal.valueOf(amount));
+                }
+                if (taxedamount != null) {
+                    taxedcosts = taxedcosts.add(BigDecimal.valueOf(taxedamount));
+                }
             }
-            serviceFundVO.setPretaxcost(pretaxcosts);
-            serviceFundVO.setTaxedcost(taxedcosts);
-            updateById(serviceFundVO);
         }
+        // 鍚堣鍦ㄥ惊鐜粨鏉熷悗缁熶竴鍥炲啓锛屽師鏉ュ啓鍦ㄥ惊鐜唴浼氭瘡琛岄兘 UPDATE 涓�娆★紝涓斾腑闂村�艰鍙嶅瑕嗙洊
+        serviceFundVO.setPretaxcost(pretaxcosts.doubleValue());
+        serviceFundVO.setTaxedcost(taxedcosts.doubleValue());
+        updateById(serviceFundVO);
         Map map = new HashMap();
         map.put("fundId", id);
         return map;
@@ -1529,10 +1724,23 @@
             //閫氳繃鍙楃泭浜哄悕绉帮紝灏嗙◣鍓嶃�佺◣鍚庣殑鍊肩浉鍔�
             Map<String, Double> sumAmount = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, Collectors.summingDouble(ServiceFunddetail::getAmount)));
             Map<String, Double> sumTaxdAmount = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, Collectors.summingDouble(ServiceFunddetail::getTaxedamount)));
+            // 鏂板鍙e緞锛氬鍊肩◣銆佸煄寤虹◣銆佸姵鍔$◣鍓嶃�佸姵鍔′釜绋庢寜鍙楃泭浜哄悎璁�
+            Map<String, Double> sumVat = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname,
+                    Collectors.summingDouble(d -> d.getVatAmount() == null ? 0.0 : d.getVatAmount())));
+            Map<String, Double> sumCityTax = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname,
+                    Collectors.summingDouble(d -> d.getCityTaxAmount() == null ? 0.0 : d.getCityTaxAmount())));
+            Map<String, Double> sumLaborPretax = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname,
+                    Collectors.summingDouble(d -> d.getLaborPretaxAmount() == null ? 0.0 : d.getLaborPretaxAmount())));
+            Map<String, Double> sumTax = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname,
+                    Collectors.summingDouble(d -> d.getTaxamount() == null ? 0.0 : d.getTaxamount())));
 
             for (String key : sumAmount.keySet()) {
                 ServiceFunddetailExcel serviceFunddetailExcel = new ServiceFunddetailExcel();
                 serviceFunddetailExcel.setAmount(sumAmount.getOrDefault(key, 0.0));
+                serviceFunddetailExcel.setVatAmount(sumVat.getOrDefault(key, 0.0));
+                serviceFunddetailExcel.setCityTaxAmount(sumCityTax.getOrDefault(key, 0.0));
+                serviceFunddetailExcel.setLaborPretaxAmount(sumLaborPretax.getOrDefault(key, 0.0));
+                serviceFunddetailExcel.setTaxamount(sumTax.getOrDefault(key, 0.0));
                 serviceFunddetailExcel.setTaxedamount(sumTaxdAmount.getOrDefault(key, 0.0));
                 for (ServiceFunddetail serviceFunddetail2 : serviceFunddetails) {
                     if (serviceFunddetail2.getBeneficiaryname().equals(key)) {
@@ -1628,10 +1836,13 @@
         String filePath = RuoYiConfig.getDownloadPath() + ajaxResult.get("msg");
 
         List<VExpertfeeDonor> list2 = vExpertfeeDonorMapper.selectVExpertfeeDonorList2(faxId);
+        // 鎵撳嵃妯℃澘瑙嗗浘涓嶅惈鈥滃鍊肩◣ / 鍩庡缓绋� / 鍔冲姟绋庡墠鈥濓紝鎸� fund_tax_id 浠庢槑缁嗚〃姹囨�诲悗鍥炲~
+        fillDonorTaxAmounts(list2, faxId);
         ExcelUtil<VExpertfeeDonor> util2 = new ExcelUtil<VExpertfeeDonor>(VExpertfeeDonor.class);
         AjaxResult ajaxResult2 = util2.exportExcel(list2, "VExpertfeeDonor");
 
         List<VExpertfeeExpert> list3 = vExpertfeeExpertMapper.selectVExpertfeeExpertListByFaxId(faxId);
+        fillExpertTaxAmounts(list3, faxId);
         ExcelUtil<VExpertfeeExpert> util3 = new ExcelUtil<VExpertfeeExpert>(VExpertfeeExpert.class);
         AjaxResult ajaxResult3 = util3.exportExcel(list3, "vExpertfeeExpert");
 
@@ -1642,14 +1853,155 @@
 
 
         String name = "涓撳璐规眹鎬诲崟" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xlsx";
+        // mergeExcel 鍐呴儴浼氬啓鏂囦欢銆佹牎楠岀粨鏋滐紝骞跺湪 finally 閲屾竻鐞� 3 涓复鏃� sheet 鏂囦欢
         mergeExcel(list1, RuoYiConfig.getDownloadPath() + name);
-        for (String path : list1) {
-            new File(RuoYiConfig.getDownloadPath() + path).delete();
-        }
         Map<String, Object> map = new HashMap<>();
         map.put("downloadUrl", "/profile/download/" + name);
         map.put("downloadName", name);
         return map;
+    }
+
+    /**
+     * 涓撳璐规眹鎬诲崟鎵撳嵃锛堜笓瀹舵槑缁� sheet锛夛細鍥炲~澧炲�肩◣ / 鍩庡缓绋� / 鍔冲姟绋庡墠锛屽苟鎶婅鍥剧殑銆屾墸绋庨噾棰濄�嶆媶鍥炲姵鍔′釜绋庛��
+     * <p>
+     * 鍙e緞璇存槑锛�
+     * <ul>
+     *   <li>瑙嗗浘 {@code v_expertfee_expert} 鐨� {@code TaxAmount} 宸叉敼涓�
+     *       <b>澧炲�肩◣ + 鍩庡缓绋� + 鍔冲姟涓◣</b>锛�2026-11-12 涓氬姟鏂逛慨鏀癸級锛岃�屾墦鍗拌鍒嗗埆灞曠ず锛�
+     *       鍥犳 {@code 鍔冲姟涓◣ = TaxAmount 鈭� 澧炲�肩◣ 鈭� 鍩庡缓绋巬锛�</li>
+     *   <li>澧炲�肩◣/鍩庡缓绋�/鍔冲姟绋庡墠 瑙嗗浘鏈崟鐙彁渚涳紝鎸� <b>涓庤鍥剧浉鍚岀殑鍒嗙粍</b>
+     *       锛堝彈鐩婁汉 + 璇佷欢鍙� + 鍗″彿 + 寮�鎴疯 + 鍗曚綅锛変粠 {@code service_funddetail} 姹囨�诲悗鍖归厤鍥炲~锛�</li>
+     *   <li>銆屽悎璁°�嶈鎸夊悇琛岀殑鍊肩疮鍔狅紙涓嶄緷璧栬鍥� UNION 鐨勫悎璁″垪锛夈��</li>
+     * </ul>
+     */
+    private void fillExpertTaxAmounts(List<VExpertfeeExpert> rows, Integer fundTaxId) {
+        if (CollectionUtils.isEmpty(rows)) {
+            return;
+        }
+        Map<String, FundTaxAmountSum> sumMap = toSumMap(serviceFundMapper.selectTaxSumByBeneficiary(fundTaxId.longValue()));
+        BigDecimal vatTotal = BigDecimal.ZERO;
+        BigDecimal cityTotal = BigDecimal.ZERO;
+        BigDecimal laborTotal = BigDecimal.ZERO;
+        BigDecimal laborTaxTotal = BigDecimal.ZERO;
+        for (VExpertfeeExpert row : rows) {
+            if (isTotalRow(row.getBeneficiaryname())) {
+                continue;
+            }
+            FundTaxAmountSum s = sumMap.get(expertGroupKey(row));
+            BigDecimal vat = s == null ? BigDecimal.ZERO : nvl(s.getVatAmount());
+            BigDecimal city = s == null ? BigDecimal.ZERO : nvl(s.getCityTaxAmount());
+            BigDecimal labor = s == null ? BigDecimal.ZERO : nvl(s.getLaborPretaxAmount());
+            // 瑙嗗浘鐨勬墸绋庨噾棰濆惈澧炲�肩◣銆佸煄寤虹◣锛岃繖閲屾媶鍥炲姵鍔′釜绋�
+            BigDecimal laborTax = nvl(row.getTaxamount()).subtract(vat).subtract(city);
+            row.setVatAmount(vat);
+            row.setCityTaxAmount(city);
+            row.setLaborPretaxAmount(labor);
+            row.setTaxamount(laborTax);
+            vatTotal = vatTotal.add(vat);
+            cityTotal = cityTotal.add(city);
+            laborTotal = laborTotal.add(labor);
+            laborTaxTotal = laborTaxTotal.add(laborTax);
+        }
+        for (VExpertfeeExpert row : rows) {
+            if (isTotalRow(row.getBeneficiaryname())) {
+                row.setVatAmount(vatTotal);
+                row.setCityTaxAmount(cityTotal);
+                row.setLaborPretaxAmount(laborTotal);
+                row.setTaxamount(laborTaxTotal);
+            }
+        }
+    }
+
+    /**
+     * 涓撳璐规眹鎬诲崟鎵撳嵃锛堟崘鐚�� sheet锛夛細鍚� {@link #fillExpertTaxAmounts}锛屽垎缁勪负銆屾崘鐚�� + 妗堜緥ID銆嶃��
+     */
+    private void fillDonorTaxAmounts(List<VExpertfeeDonor> rows, Integer fundTaxId) {
+        if (CollectionUtils.isEmpty(rows)) {
+            return;
+        }
+        Map<String, FundTaxAmountSum> sumMap = toSumMap(serviceFundMapper.selectTaxSumByDonor(fundTaxId.longValue()));
+        BigDecimal vatTotal = BigDecimal.ZERO;
+        BigDecimal cityTotal = BigDecimal.ZERO;
+        BigDecimal laborTotal = BigDecimal.ZERO;
+        BigDecimal laborTaxTotal = BigDecimal.ZERO;
+        for (VExpertfeeDonor row : rows) {
+            if (isTotalRow(row.getDonorname())) {
+                continue;
+            }
+            FundTaxAmountSum s = sumMap.get(donorGroupKey(row.getDonorname(), row.getInfoid()));
+            BigDecimal vat = s == null ? BigDecimal.ZERO : nvl(s.getVatAmount());
+            BigDecimal city = s == null ? BigDecimal.ZERO : nvl(s.getCityTaxAmount());
+            BigDecimal labor = s == null ? BigDecimal.ZERO : nvl(s.getLaborPretaxAmount());
+            BigDecimal laborTax = nvl(row.getTaxamount()).subtract(vat).subtract(city);
+            row.setVatAmount(vat);
+            row.setCityTaxAmount(city);
+            row.setLaborPretaxAmount(labor);
+            row.setTaxamount(laborTax);
+            vatTotal = vatTotal.add(vat);
+            cityTotal = cityTotal.add(city);
+            laborTotal = laborTotal.add(labor);
+            laborTaxTotal = laborTaxTotal.add(laborTax);
+        }
+        for (VExpertfeeDonor row : rows) {
+            if (isTotalRow(row.getDonorname())) {
+                row.setVatAmount(vatTotal);
+                row.setCityTaxAmount(cityTotal);
+                row.setLaborPretaxAmount(laborTotal);
+                row.setTaxamount(laborTaxTotal);
+            }
+        }
+    }
+
+    private static Map<String, FundTaxAmountSum> toSumMap(List<FundTaxAmountSum> sums) {
+        Map<String, FundTaxAmountSum> map = new HashMap<>();
+        if (!CollectionUtils.isEmpty(sums)) {
+            for (FundTaxAmountSum s : sums) {
+                map.put(s.getGroupKey(), s);
+            }
+        }
+        return map;
+    }
+
+    /**
+     * 涓撳鏄庣粏鍒嗙粍閿紝蹇呴』涓庤鍥� {@code v_expertfee_expert} 鐨� GROUP BY 瀹屽叏涓�鑷达細
+     * BeneficiaryName + IDCardNo + BankCardNo + DepositBank + UnitName銆�
+     */
+    private static String expertGroupKey(VExpertfeeExpert row) {
+        return joinKey(row.getBeneficiaryname(), row.getIdcardno(), row.getBankcardno(),
+                row.getDepositbank(), row.getUnitname());
+    }
+
+    /**
+     * 鎹愮尞鑰呭垎缁勯敭锛屼笌瑙嗗浘 {@code v_expertfee_donor} 鐨� GROUP BY 涓�鑷达細DonorName + InfoID銆�
+     */
+    private static String donorGroupKey(String donorname, Long infoid) {
+        return joinKey(donorname, infoid == null ? "" : String.valueOf(infoid));
+    }
+
+    /**
+     * 鐢� "|" 鎷兼帴鍒嗙粍閿紱null 缁熶竴鎸夌┖涓插鐞嗭紙涓� SQL 鐨� IFNULL(x,'') 瀵归綈锛�
+     */
+    private static String joinKey(Object... parts) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < parts.length; i++) {
+            if (i > 0) {
+                sb.append('|');
+            }
+            Object p = parts[i];
+            sb.append(p == null ? "" : String.valueOf(p).trim());
+        }
+        return sb.toString();
+    }
+
+    /**
+     * 鎵撳嵃閲岀殑銆屽悎璁°�嶈
+     */
+    private static boolean isTotalRow(String name) {
+        return name != null && "鍚堣".equals(name.trim());
+    }
+
+    private static BigDecimal nvl(BigDecimal value) {
+        return value == null ? BigDecimal.ZERO : value;
     }
 
 
@@ -1715,10 +2067,18 @@
                 log.info("filePath鐨勪慨鏀�:{}", filePath);
                 String url = rbDetailFile.getUrl();
                 //file鐢ㄧ殑鏄粷瀵逛綅缃�
-                String substring = url.substring(url.indexOf("/profile/upload") + "/profile/upload".length());
+                // 2026-10-09锛氶檮浠跺湴鍧�瑙f瀽鍔犲浐锛岄伩鍏� url 寮傚父/鏂囦欢缂哄け鏃舵姏 NPE 瀵艰嚧鐪嬩笉鍒板け璐ュ師鍥�
+                int profileIdx = url == null ? -1 : url.indexOf("/profile/upload");
+                if (profileIdx < 0) {
+                    throw new ServiceException("闄勪欢鍦板潃鏍煎紡涓嶆纭紙缂哄皯 /profile/upload锛夛紝鏃犳硶涓婁紶鍗忓弸锛�" + url);
+                }
+                String substring = url.substring(profileIdx + "/profile/upload".length());
 //            String strFile = rbDetailFile.getUrl().replace(filePath, "/profile/upload");
                 System.out.println("fund鏈嶅姟鐨刦ilePath + substring: " + filePath + substring);
                 File filetest = new File(filePath + substring);
+                if (!filetest.exists()) {
+                    throw new ServiceException("闄勪欢鏂囦欢鍦ㄦ湇鍔″櫒涓婁笉瀛樺湪锛屾棤娉曚笂浼犲崗鍙嬶細" + filetest.getAbsolutePath());
+                }
 
                 String struploadResult = HttpClientKit.sendPostWithFile(filetest, strFUrl);
                 log.info("绗笁鏂逛紶鍥炵殑鏁版嵁: {}", struploadResult);
@@ -1766,41 +2126,115 @@
         return id;
     }
 
+    /**
+     * 鎶� 3 涓� sheet 鐨勪复鏃跺鍑烘枃浠跺悎骞舵垚涓�涓�屼笓瀹惰垂姹囨�诲崟銆嶃��
+     * <p>
+     * 淇鐐癸紙2026-11-12锛夛細
+     * <ol>
+     *   <li>鍘熷疄鐜扮敤 {@code cell.getStringCellValue()} 澶嶅埗鍗曞厓鏍硷紝閬囧埌鏁板瓧鍗曞厓鏍间細鎶�
+     *       {@code IllegalStateException: Cannot get a STRING value from a NUMERIC cell}锛�
+     *       鑰屽灞� catch 鎶婂紓甯稿悶鎺� 鈫� 鎺ュ彛浠嶈繑鍥炰笅杞藉湴鍧�锛屼絾鍚堝苟鏂囦欢娌$敓鎴愶紝鍓嶇涓嬭浇 404锛�</li>
+     *   <li>鍘熷疄鐜版病鏈夊叧闂緭鍏�/杈撳嚭娴侊紝Windows 涓婁复鏃舵枃浠惰閿佸畾锛屽垹涓嶆帀锛堟畫鐣� *_vExpertfee*.xlsx锛夛紱</li>
+     *   <li>澶辫触鏃朵笉鍐嶉潤榛橈紝鎶涗笟鍔″紓甯歌鍓嶇鐪嬪埌鐪熷疄鍘熷洜銆�</li>
+     * </ol>
+     */
     public void mergeExcel(List<String> files, String outputFile) {
-        try {
-            Workbook resultWorkbook = new XSSFWorkbook();
+        File outFile = new File(outputFile);
+        try (Workbook resultWorkbook = new XSSFWorkbook()) {
+            // 琛ㄥご涓庢暟鎹袱绉嶆牱寮忥紝閬垮厤姣忎釜鍗曞厓鏍奸兘鏂板缓鏍峰紡锛堝師瀹炵幇姣忔牸涓�涓牱寮忥紝鏂囦欢浼氬彉澶э級
+            CellStyle headerStyle = createMergeCellStyle(resultWorkbook, true);
+            CellStyle bodyStyle = createMergeCellStyle(resultWorkbook, false);
             for (String file : files) {
-                InputStream is1 = new FileInputStream(RuoYiConfig.getDownloadPath() + file);
-                Workbook workbook1 = new XSSFWorkbook(is1);
-                Sheet sheet1 = workbook1.getSheetAt(0);
-                // 澶嶅埗绗竴涓枃浠剁殑Sheet
-                Sheet newSheet1 = resultWorkbook.createSheet(file.substring(0, file.indexOf(".")));
-                for (Row row : sheet1) {
-                    Row newRow = newSheet1.createRow(row.getRowNum());
-                    int columns = row.getLastCellNum();
-                    for (int i = 0; i < columns; i++) {
-                        newSheet1.setColumnWidth(i, 5000);
-                        Cell cell = row.getCell(i);
-                        Cell newCell = newRow.createCell(cell.getColumnIndex());
-                        newCell.setCellValue(cell.getStringCellValue());
-                        // 鍒涘缓鍗曞厓鏍兼牱寮�
-                        CellStyle style = resultWorkbook.createCellStyle();
-                        style.setAlignment(HorizontalAlignment.CENTER); // 姘村钩灞呬腑
-                        style.setVerticalAlignment(VerticalAlignment.CENTER); // 鍨傜洿灞呬腑
-                        if (row.getRowNum() == 0) {
-                            // 璁剧疆绗竴琛岃儗鏅壊
-                            style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
-                            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                File srcFile = new File(RuoYiConfig.getDownloadPath() + file);
+                try (InputStream is1 = new FileInputStream(srcFile);
+                     Workbook workbook1 = new XSSFWorkbook(is1)) {
+                    Sheet sheet1 = workbook1.getSheetAt(0);
+                    String sheetName = file.contains(".") ? file.substring(0, file.indexOf(".")) : file;
+                    Sheet newSheet = resultWorkbook.createSheet(sheetName);
+                    for (Row row : sheet1) {
+                        Row newRow = newSheet.createRow(row.getRowNum());
+                        short columns = row.getLastCellNum();
+                        for (int i = 0; i < columns; i++) {
+                            newSheet.setColumnWidth(i, 5000);
+                            Cell newCell = newRow.createCell(i);
+                            copyCellValue(row.getCell(i), newCell);
+                            newCell.setCellStyle(row.getRowNum() == 0 ? headerStyle : bodyStyle);
                         }
-
-                        newCell.setCellStyle(style);
                     }
                 }
             }
-            FileOutputStream out = new FileOutputStream(outputFile);
-            resultWorkbook.write(out);
+            // 鍏堝啓涓存椂鏂囦欢鍐嶆敼鍚嶏紝閬垮厤涓嬭浇鍒板啓浜嗕竴鍗婄殑鏂囦欢
+            File tmpFile = new File(outputFile + ".tmp");
+            try (FileOutputStream out = new FileOutputStream(tmpFile)) {
+                resultWorkbook.write(out);
+            }
+            if (!tmpFile.renameTo(outFile) && !tmpFile.equals(outFile)) {
+                // rename 澶辫触锛堢洰鏍囪鍗犵敤绛夛級鏃堕��鍖栦负鐩存帴鍐欑洰鏍囨枃浠�
+                try (FileOutputStream out = new FileOutputStream(outFile)) {
+                    resultWorkbook.write(out);
+                }
+                tmpFile.delete();
+            }
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("鐢熸垚涓撳璐规眹鎬诲崟澶辫触锛宱utputFile={}", outputFile, e);
+            throw new ServiceException("鐢熸垚涓撳璐规眹鎬诲崟澶辫触锛�" + e.getMessage());
+        } finally {
+            // 鍚堝苟瀹屾垚鍚庢竻鐞嗕复鏃� sheet 鏂囦欢锛堝け璐ユ椂涔熷皾璇曟竻鐞嗭紝閬垮厤娈嬬暀锛�
+            for (String file : files) {
+                File tmp = new File(RuoYiConfig.getDownloadPath() + file);
+                if (tmp.exists() && !tmp.delete()) {
+                    log.warn("涓存椂瀵煎嚭鏂囦欢鏈兘鍒犻櫎锛歿}", tmp.getAbsolutePath());
+                }
+            }
+        }
+        if (!outFile.exists() || outFile.length() == 0) {
+            throw new ServiceException("鐢熸垚涓撳璐规眹鎬诲崟澶辫触锛氭枃浠舵湭鐢熸垚");
+        }
+    }
+
+    /**
+     * 鍚堝苟鐢ㄧ殑鍗曞厓鏍兼牱寮忥紙琛ㄥご鐏板簳銆佹鏂囩櫧搴曪級锛岀粺涓�灞呬腑
+     */
+    private static CellStyle createMergeCellStyle(Workbook workbook, boolean header) {
+        CellStyle style = workbook.createCellStyle();
+        style.setAlignment(HorizontalAlignment.CENTER);
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+        if (header) {
+            style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
+            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        }
+        return style;
+    }
+
+    /**
+     * 鎸夊崟鍏冩牸瀹為檯绫诲瀷澶嶅埗鍊硷細鏁板瓧鎸夋暟瀛椼�佹棩鏈熸寜鏃ユ湡銆佸叕寮忔寜鍏紡锛岀┖鍗曞厓鏍间繚鎸佷负绌恒��
+     * 鍘熷疄鐜板彧鏀寔瀛楃涓插崟鍏冩牸锛岄亣鍒伴噾棰濓紙鏁板瓧锛夊氨鎶涘紓甯搞��
+     */
+    private static void copyCellValue(Cell source, Cell target) {
+        if (source == null) {
+            target.setBlank();
+            return;
+        }
+        switch (source.getCellType()) {
+            case STRING:
+                target.setCellValue(source.getStringCellValue());
+                break;
+            case NUMERIC:
+                if (DateUtil.isCellDateFormatted(source)) {
+                    target.setCellValue(source.getDateCellValue());
+                } else {
+                    target.setCellValue(source.getNumericCellValue());
+                }
+                break;
+            case BOOLEAN:
+                target.setCellValue(source.getBooleanCellValue());
+                break;
+            case FORMULA:
+                target.setCellFormula(source.getCellFormula());
+                break;
+            default:
+                target.setBlank();
+                break;
         }
     }
 
@@ -1817,7 +2251,8 @@
     }
 
 
-    public void sendMeg(ServiceProcessVO serviceProcessVO, String phone) {
+    public void sendMeg(ServiceProcessVO serviceProcessVO, String phone,
+                        List<ConcurrentHashMap<String, Object>> contentList) {
         //璁板綍鎿嶄綔璁板綍
         ServiceFundflow serviceFundflow = new ServiceFundflow();
 
@@ -1835,18 +2270,15 @@
         serviceFundflow.setApplytype(serviceProcessVO.getApplytype());
         serviceFundflow.setFundid(StringUtils.isNotEmpty(serviceProcessVO.getBackCode()) ? Long.valueOf(serviceProcessVO.getBackCode()) : null);
         fundflowService.save(serviceFundflow);
-
-        ArrayList<ConcurrentHashMap<String, Object>> contentList = new ArrayList<>();
-        ConcurrentHashMap map = new ConcurrentHashMap();
-        map.put("瀹℃壒浜猴細", serviceProcessVO.getCheckusername());
-        map.put("瀹℃壒鏃堕棿锛�", serviceProcessVO.getCheckTime());
-        map.put("鎰忚锛�", serviceProcessVO.getFlowcontent());
-        contentList.add(map);
-        DingTalkReqVo dingTalkReqVo = new DingTalkReqVo();
-        dingTalkReqVo.setTitle("璐㈠姟绯荤粺淇℃伅");
-        dingTalkReqVo.setNumber(phone);
-        dingTalkReqVo.setContents(contentList);
-        log.info("閽夐拤鍙戦�佹秷鎭�:{}", dingTalkReqVo);
-        dingTalkService.sendNotification(dingTalkReqVo);
+        try {
+            DingTalkReqVo dingTalkReqVo = new DingTalkReqVo();
+            dingTalkReqVo.setTitle(FundNotifyMessageBuilder.TITLE);
+            dingTalkReqVo.setNumber(phone);
+            dingTalkReqVo.setContents(contentList);
+            log.info("閽夐拤鍙戦�佹秷鎭�:{}", dingTalkReqVo);
+            dingTalkService.sendNotification(dingTalkReqVo);
+        } catch (Exception e) {
+            log.error("鎶ラ攢瀹℃壒閽夐拤娑堟伅鍙戦�佸け璐ワ紝涓嶅奖鍝嶄富娴佺▼", e);
+        }
     }
 }

--
Gitblit v1.9.3