Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

zhangyao 2 сар өмнө
parent
commit
0cf6efcb16

BIN
com.awspaas.user.apps.donenow_ctt/com.awspaas.user.apps.donenow_ctt.jar


+ 147 - 16
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/controller/contractApproveController.java

@@ -1464,16 +1464,16 @@ public class contractApproveController {
 
     @Mapping("com.awspaas.user.apps.donenow_ctt.updateAgentCommissionById")
     public ResponseObject updateAgentCommissionById(UserContext uc,
-                                                     String ids,
-                                                     String commissionPayId,
-                                                     String agent,
-                                                     String ACCOUNT_PAY_DATE,
-                                                     BigDecimal totalPayAmount, // 前端传递的“总支付金额”
-                                                     String payer,
-                                                     String remark,
-                                                     String invoiceTypeId,
-                                                     String agentInvoiceNo,
-                                                     String invoiceFile) throws SQLException {
+                                                    String ids,
+                                                    String commissionPayId,
+                                                    String agent,
+                                                    String ACCOUNT_PAY_DATE,
+                                                    BigDecimal totalPayAmount, // 前端传递的“总支付金额”
+                                                    String payer,
+                                                    String remark,
+                                                    String invoiceTypeId,
+                                                    String agentInvoiceNo,
+                                                    String invoiceFile) throws SQLException {
         Connection connUpdate = null;
         try {
             // 1. 参数校验
@@ -1535,7 +1535,7 @@ public class contractApproveController {
 
             int updateCount = 0;
 
-            // 5. 循环按比例分配并更新
+            // 5. 循环按比例分配并更新 BO_EU_DNCTT_COMMISSION_PERIOD_AGENT 表
             for (String id : idArr) {
                 if (!idPeriodAmountMap.containsKey(id)) {
                     System.out.println("跳过未查询到周期金额的ID:" + id);
@@ -1554,7 +1554,7 @@ public class contractApproveController {
                 updateSql.append("COMMISSION_PAY_ID = ?, ");
                 updateSql.append("AGENT = ?, ");
                 updateSql.append("ACCOUNT_PAY_DATE = ?, ");
-                updateSql.append("PAY_AMOUNT =  ?, "); // 核心:累加更新
+                updateSql.append("PAY_AMOUNT =  ?, "); // 核心:更新单周期分配金额
                 updateSql.append("PAYER = ?, ");
                 updateParams.add(commissionPayId.trim());
                 updateParams.add(agent);
@@ -1594,7 +1594,15 @@ public class contractApproveController {
                 }
             }
 
-            // 6. 提交事务
+            // 新增:更新 BO_EU_DNCTT_COMMISSION_PAY 表的 PAY_AMOUNT 字段
+            String updatePayTableSql = "UPDATE BO_EU_DNCTT_COMMISSION_PAY SET PAY_AMOUNT = ? WHERE ID = ?";
+            List<Object> payTableParams = new ArrayList<>();
+            payTableParams.add(totalPayAmount); // 设置总支付金额
+            payTableParams.add(commissionPayId.trim()); // 按 commissionPayId 定位记录
+            int payTableAffectedRows = DBSql.update(connUpdate, updatePayTableSql, payTableParams.toArray());
+            System.out.println("更新 BO_EU_DNCTT_COMMISSION_PAY 表影响行数:" + payTableAffectedRows);
+
+            // 6. 提交事务(所有更新在同一事务中提交)
             connUpdate.commit();
 
             // 7. 返回结果
@@ -1603,14 +1611,15 @@ public class contractApproveController {
             result.put("updateCount", updateCount);
             result.put("totalPayAmount", totalPayAmount);
             result.put("totalPeriodAmount", totalPeriodAmount);
-            result.put("message", "按比例分配更新完成,共更新" + updateCount + "条记录");
+            result.put("payTableAffectedRows", payTableAffectedRows); // 新增:返回目标表更新行数
+            result.put("message", "按比例分配及目标表更新完成,共更新" + updateCount + "条周期记录,目标表更新" + payTableAffectedRows + "条记录");
 
             ResponseObject responseObject = ResponseObject.newOkResponse();
             responseObject.setData(result);
             return responseObject;
 
         } catch (SQLException e) {
-            // 异常回滚
+            // 异常回滚(所有更新一同回滚)
             if (connUpdate != null && !connUpdate.isClosed()) {
                 try {
                     connUpdate.rollback();
@@ -1628,6 +1637,128 @@ public class contractApproveController {
         }
     }
 
+    @Mapping("com.awspaas.user.apps.donenow_ctt.updateInvoiceReceiveAmountByBindId")
+    public ResponseObject updateInvoiceReceiveAmountByBindId(UserContext uc,
+                                                             String bindid, // 前端传递:用于定位明细记录的bindid
+                                                             BigDecimal totalReceiveAmount // 前端传递:总收款金额(用于按比例分配)
+    ) throws SQLException {
+        Connection connUpdate = null;
+        try {
+            // 1. 参数校验
+            if (StringUtils.isBlank(bindid)) {
+                return ResponseObject.newErrResponse("bindid不能为空");
+            }
+            if (totalReceiveAmount == null || totalReceiveAmount.compareTo(BigDecimal.ZERO) <= 0) {
+                return ResponseObject.newErrResponse("总收款金额不能为空且需大于0");
+            }
+
+            // 2. 查询bindid关联的明细记录(核心修改:查询字段改为INVOICE_AMOUNT)
+            String querySql = "SELECT ID, INVOICE_AMOUNT FROM BO_EU_DNCTT_INVOICE_PLAN_DETAIL WHERE BINDID = ?";
+            List<Object> queryParams = new ArrayList<>();
+            queryParams.add(bindid.trim());
+            List<RowMap> detailList = DBSql.getMaps(querySql, queryParams.toArray());
+
+            // 3. 预处理:统计总发票金额 + 校验数据(变量名同步改为发票金额相关)
+            Map<String, BigDecimal> idInvoiceAmountMap = new HashMap<>(); // 原idBaseAmountMap → 改为发票金额映射
+            BigDecimal totalInvoiceAmount = BigDecimal.ZERO; // 原totalBaseAmount → 改为总发票金额(比例计算基数)
+            for (RowMap row : detailList) {
+                String id = row.getString("ID");
+                // 处理发票金额:从INVOICE_AMOUNT字段获取(核心修改)
+                String invoiceAmountStr = row.getString("INVOICE_AMOUNT");
+                BigDecimal invoiceAmount = null;
+                if (invoiceAmountStr != null && !invoiceAmountStr.trim().isEmpty()) {
+                    try {
+                        invoiceAmount = new BigDecimal(invoiceAmountStr.trim());
+                    } catch (NumberFormatException e) {
+                        System.out.println("发票金额格式错误,ID:" + id + ",值:" + invoiceAmountStr); // 日志同步修改
+                        continue;
+                    }
+                }
+                if (invoiceAmount == null || invoiceAmount.compareTo(BigDecimal.ZERO) <= 0) {
+                    System.out.println("发票金额非法(空或<=0),ID:" + id); // 日志同步修改
+                    continue;
+                }
+                idInvoiceAmountMap.put(id, invoiceAmount);
+                totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
+            }
+
+            // 校验总发票金额(避免除零,提示信息同步修改)
+            if (totalInvoiceAmount.compareTo(BigDecimal.ZERO) <= 0) {
+                Map<String, Object> result = new HashMap<>();
+                result.put("totalMatched", detailList.size());
+                result.put("updateCount", 0);
+                result.put("message", "bindid关联明细的总发票金额为0,无法计算比例"); // 提示信息修改
+                ResponseObject responseObject = ResponseObject.newOkResponse();
+                responseObject.setData(result);
+                return responseObject;
+            }
+
+            // 4. 初始化事务连接
+            connUpdate = DBSql.open();
+            connUpdate.setAutoCommit(false);
+
+            int updateCount = 0;
+
+            // 5. 循环按比例分配并更新 RECEIVE_AMOUNT 字段(使用总发票金额计算比例)
+            for (String id : idInvoiceAmountMap.keySet()) {
+                // 按比例计算:使用发票金额作为基数(变量名同步修改)
+                BigDecimal invoiceAmount = idInvoiceAmountMap.get(id);
+                BigDecimal ratio = invoiceAmount.divide(totalInvoiceAmount, 6, BigDecimal.ROUND_HALF_UP);
+                BigDecimal allocatedReceiveAmount = totalReceiveAmount.multiply(ratio).setScale(2, BigDecimal.ROUND_HALF_UP);
+
+                // 构建更新SQL(仅更新RECEIVE_AMOUNT)
+                StringBuilder updateSql = new StringBuilder("UPDATE BO_EU_DNCTT_INVOICE_PLAN_DETAIL SET ");
+                List<Object> updateParams = new ArrayList<>();
+
+                updateSql.append("RECEIVE_AMOUNT = ?, ");
+                updateParams.add(allocatedReceiveAmount);
+
+                // 移除多余逗号
+                if (updateSql.charAt(updateSql.length() - 2) == ',') {
+                    updateSql.setLength(updateSql.length() - 2);
+                }
+                updateSql.append(" WHERE ID = ?");
+                updateParams.add(id.trim());
+
+                // 执行更新
+                int affectedRows = DBSql.update(connUpdate, updateSql.toString(), updateParams.toArray());
+                if (affectedRows > 0) {
+                    updateCount++;
+                }
+            }
+
+            // 6. 提交事务
+            connUpdate.commit();
+
+            // 7. 返回结果(字段同步改为总发票金额)
+            Map<String, Object> result = new HashMap<>();
+            result.put("totalMatched", detailList.size());
+            result.put("updateCount", updateCount);
+            result.put("totalReceiveAmount", totalReceiveAmount);
+            result.put("totalInvoiceAmount", totalInvoiceAmount); // 原totalBaseAmount → 改为totalInvoiceAmount
+            result.put("message", "按比例更新RECEIVE_AMOUNT完成,共更新" + updateCount + "条明细记录");
+
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+            return responseObject;
+
+        } catch (SQLException e) {
+            if (connUpdate != null && !connUpdate.isClosed()) {
+                try {
+                    connUpdate.rollback();
+                } catch (SQLException ex) {
+                    ex.printStackTrace();
+                }
+            }
+            e.printStackTrace();
+            return ResponseObject.newErrResponse("更新RECEIVE_AMOUNT失败:" + e.getMessage());
+        } finally {
+            if (connUpdate != null && !connUpdate.isClosed()) {
+                DBSql.close(connUpdate);
+            }
+        }
+    }
+
     /**
      * 佣金审批
      * @param uc
@@ -1792,7 +1923,7 @@ public class contractApproveController {
                     "c.ID AS c_id  " +
                     "FROM BO_EU_DNCTT_COMMISSION_IMPORT a " +
                     "JOIN BO_EU_DNCTT_COMMISSION b " +
-                    "ON a.ACCOUNT_USER_NO = b.NEW_ACCOUNT AND a.DEVICE_ID = b.DEVICE_ID AND a.RULE_NO = b.RULE_NO " +
+                    "ON a.ACCOUNT_USER_NO = b.NEW_ACCOUNT AND a.DEVICE_ID = b.DEVICE_ID" +
                     "JOIN BO_EU_DNCTT_COMMISSION_PERIOD c " +
                     "ON a.ZB_FEE_DATE = c.ZB_FEE_DATE AND b.bindid = c.bindid " +
                     "WHERE a.ZB_FEE_DATE = ?";

+ 20 - 12
com.awspaas.user.apps.donenow_ivt/src/com/awspaas/user/apps/donenow_ivt/controller/caiController.java

@@ -22,27 +22,35 @@ public class caiController {
 
     @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryCai")
     public ResponseObject queryOrderByOrderId(UserContext uc, String orderId) {
-
         if (StringUtils.isBlank(orderId)) {
             return ResponseObject.newErrResponse("订单ID不能为空");
         }
 
+        String sql = "select COST_TOTAL, ORDER_ID from bo_eu_dnivt_order_product where ORDER_ID = ?";
+        List<RowMap> rowMaps = DBSql.getMaps(sql, new Object[]{orderId});
+        System.out.println("采购项查询结果数量:" + (rowMaps != null ? rowMaps.size() : 0));
 
-        String sql = "select UNIT_COST_ADD_TAX, ORDER_ID from bo_eu_dnivt_order_product where ORDER_ID = ?";
-        RowMap map = DBSql.getMap(sql, new Object[]{orderId});
-
-
-        if (map == null) {
-            return ResponseObject.newErrResponse("未找到ORDER_ID为【" + orderId + "】的采购项");
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        if (rowMaps != null && !rowMaps.isEmpty()) {
+            for (RowMap row : rowMaps) {
+                Map<String, Object> orderItem = new HashMap<>();
+                orderItem.put("COST_TOTAL", row.getDouble("COST_TOTAL"));
+                orderItem.put("ORDER_ID", row.getString("ORDER_ID"));
+                resultList.add(orderItem);
+                System.out.println("已添加采购项数据:" + orderItem);
+            }
+        } else {
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.put("message", "未找到ORDER_ID为【" + orderId + "】的采购项,可尝试检查订单ID或新建");
+            responseObject.setData(Collections.emptyList());
+            System.out.println("未查询到采购项数据,ORDER_ID:" + orderId);
+            return responseObject;
         }
 
-        Map<String, Object> result = new HashMap<>();
-        result.put("UNIT_COST_ADD_TAX", map.getString("UNIT_COST_ADD_TAX"));
-        result.put("ORDER_ID", map.getString("ORDER_ID"));
+        System.out.println("采购项查询最终结果总数:" + resultList.size());
 
         ResponseObject responseObject = ResponseObject.newOkResponse();
-        responseObject.setData(result);
-
+        responseObject.setData(resultList);
         return responseObject;
     }
     @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryCount")