Kaynağa Gözat

工单修改

HULEI 3 ay önce
ebeveyn
işleme
1a12f010e8

BIN
com.awspaas.user.apps.donenow_tst/lib/com.awspaas.user.apps.donenow_tst.jar


+ 215 - 0
com.awspaas.user.apps.donenow_tst/src/com/awspaas/user/apps/donenow_tst/controller/testController.java

@@ -1,16 +1,20 @@
 package com.awspaas.user.apps.donenow_ivt.controller;
 
+import com.actionsoft.bpms.commons.database.RowMap;
 import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
 import com.actionsoft.bpms.server.bind.annotation.Controller;
 import com.actionsoft.bpms.server.bind.annotation.Mapping;
 import com.actionsoft.bpms.server.UserContext;
 import com.actionsoft.bpms.bo.engine.BO;
+import com.actionsoft.bpms.util.DBSql;
 import com.actionsoft.sdk.local.SDK;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Controller
@@ -144,4 +148,215 @@ public class testController {
             return ResponseObject.newErrResponse("状态更新失败:" + e.getMessage());
         }
     }
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryAccount")
+    public ResponseObject queryAccountByAccountId(UserContext uc, String accountId) {
+
+        if (StringUtils.isBlank(accountId)) {
+            return ResponseObject.newErrResponse("账户ID不能为空");
+        }
+
+        // 1. 查询账户基本信息(包含DISTRICT_ID)
+        String accountSql = "select ADDRESS, DISTRICT_ID from BO_EU_DNCRM_ACCOUNT where id = ?";
+        RowMap accountMap = DBSql.getMap(accountSql, new Object[]{accountId});
+
+        if (accountMap == null) {
+            return ResponseObject.newErrResponse("未找到ID为【" + accountId + "】的账户信息");
+        }
+
+        // 2. 根据DISTRICT_ID查询地区名称
+        String districtId = accountMap.getString("DISTRICT_ID");
+        String districtName = "";
+        if (StringUtils.isNotBlank(districtId)) {
+            String dictSql = "select CNNAME from bo_act_dict_kv_item where ITEMNO = ? and DICTKEY = 'GB.ADDR'";
+            RowMap dictMap = DBSql.getMap(dictSql, new Object[]{districtId});
+            districtName = dictMap != null ? dictMap.getString("CNNAME") : "";
+        }
+
+        // 3. 封装结果(包含原始地区ID和查询到的地区名称)
+        Map<String, Object> result = new HashMap<>();
+        result.put("ADDRESS", accountMap.getString("ADDRESS"));
+        result.put("DISTRICT_ID", districtId);
+        result.put("DISTRICT_NAME", districtName); // 新增地区名称字段
+
+        ResponseObject responseObject = ResponseObject.newOkResponse();
+        responseObject.setData(result);
+
+        return responseObject;
+    }
+
+
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryTaskCount")
+    public ResponseObject queryTaskCountByAccountId(UserContext uc, String accountId) {
+
+        if (StringUtils.isBlank(accountId)) {
+            return ResponseObject.newErrResponse("账户ID不能为空");
+        }
+
+        String sql = "select count(*) as task_count from BO_EU_DNSDK_TASK where account_id = ? and type_id=1809";
+        RowMap map = DBSql.getMap(sql, new Object[]{accountId});
+
+        int taskCount = map.getInt("task_count");
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("task_count", taskCount);
+        result.put("account_id", accountId);
+
+        ResponseObject responseObject = ResponseObject.newOkResponse();
+        responseObject.setData(result);
+
+        return responseObject;
+    }
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryTaskCountByContactId") public ResponseObject queryTaskCountByContactId(UserContext uc, String contactId) {
+        if (StringUtils.isBlank (contactId)) {
+            return ResponseObject.newErrResponse ("联系人 ID 不能为空");
+        }
+
+        String sql = "select count(*) as task_count from BO_EU_DNSDK_TASK where contact_id = ? and type_id=1809";
+        RowMap map = DBSql.getMap(sql, new Object[]{contactId});
+
+        int taskCount = map.getInt("task_count");
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("task_count", taskCount);
+        result.put("contact_id", contactId);
+
+        ResponseObject responseObject = ResponseObject.newOkResponse();
+        responseObject.setData(result);
+
+        return responseObject;
+    }
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryTaskCountByProductId")
+    public ResponseObject queryTaskCountByProductId(UserContext uc, String installedProductId) {
+
+        if (StringUtils.isBlank(installedProductId)) {
+            return ResponseObject.newErrResponse("配置项ID不能为空");
+        }
+
+        String sql = "select count(*) as task_count from BO_EU_DNSDK_TASK where INSTALLED_PRODUCT_ID = ?";
+        RowMap map = DBSql.getMap(sql, new Object[]{installedProductId});
+
+        int taskCount = map.getInt("task_count");
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("task_count", taskCount);
+        result.put("installed_product_id", installedProductId);
+
+        ResponseObject responseObject = ResponseObject.newOkResponse();
+        responseObject.setData(result);
+
+        return responseObject;
+    }
+
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryProductInfoByBindid")
+    public ResponseObject queryProductInfoByBindid(UserContext uc, String bindid) {
+        // 参数校验
+        if (StringUtils.isBlank(bindid)) {
+            return ResponseObject.newErrResponse("bindid不能为空");
+        }
+
+        // 1. 查询产品基础信息
+        String productSql = "SELECT " +
+                "LOCATION, " +
+                "CONTACT_ID, " +
+                "START_DATE, " +
+                "THROUGH_DATE, " +
+                "VENDOR_ACCOUNT_ID " +
+                "FROM BO_EU_DNCRM_INSTALLED_PRODUCT " +
+                "WHERE bindid = ?";
+        RowMap productMap = DBSql.getMap(productSql, new Object[]{bindid});
+
+        if (productMap == null) {
+            return ResponseObject.newErrResponse("未找到bindid为【" + bindid + "】的产品数据");
+        }
+
+        // 2. 计算保修期(保持原有逻辑)
+        Date startDate = productMap.getDate("START_DATE");
+        Date throughDate = productMap.getDate("THROUGH_DATE");
+        long warrantyDays = 0;
+        String warrantyDesc = "";
+
+        if (startDate == null || throughDate == null) {
+            warrantyDesc = "日期信息不完整";
+        } else if (throughDate.before(startDate)) {
+            warrantyDesc = "日期范围异常";
+        } else {
+            warrantyDays = (throughDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000);
+            warrantyDesc = warrantyDays + "天";
+        }
+
+        // 3. 查询联系人名称(与之前逻辑一致)
+        String contactId = productMap.getString("CONTACT_ID");
+        String contactName = "";
+        if (StringUtils.isNotBlank(contactId)) {
+            String contactSql = "SELECT NAME FROM BO_EU_DNCRM_CONTACT WHERE id = ?";
+            RowMap contactMap = DBSql.getMap(contactSql, new Object[]{contactId});
+            contactName = contactMap != null ? contactMap.getString("NAME") : "未知联系人";
+        }
+
+        // 4. 新增:查询供应商名称(与联系人逻辑相同)
+        String vendorAccountId = productMap.getString("VENDOR_ACCOUNT_ID");
+        String vendorName = "";
+        if (StringUtils.isNotBlank(vendorAccountId)) {
+            String vendorSql = "SELECT NAME FROM bo_eu_dncrm_account WHERE id = ?";
+            RowMap vendorMap = DBSql.getMap(vendorSql, new Object[]{vendorAccountId});
+            vendorName = vendorMap != null ? vendorMap.getString("NAME") : "未知供应商";
+        }
+
+        // 5. 封装结果(包含联系人和供应商名称)
+        Map<String, Object> result = new HashMap<>();
+        result.put("LOCATION", productMap.getString("LOCATION"));
+        result.put("CONTACT_ID", contactId);
+        result.put("CONTACT_NAME", contactName); // 联系人名称
+        result.put("VENDOR_ACCOUNT_ID", vendorAccountId);
+        result.put("VENDOR_NAME", vendorName);   // 新增:供应商名称
+        result.put("WARRANTY_DAYS", warrantyDays);
+        result.put("WARRANTY_DESC", warrantyDesc);
+
+        ResponseObject responseObject = ResponseObject.newOkResponse();
+        responseObject.setData(result);
+
+        return responseObject;
+    }
+
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ivt.queryHoursWorkedByTaskId")
+    public ResponseObject queryHoursWorkedByTaskId(UserContext uc, String taskId) {
+
+        if (StringUtils.isBlank(taskId)) {
+            return ResponseObject.newErrResponse("任务ID不能为空");
+        }
+
+        // 使用 SUM 函数直接在 SQL 中计算总工时
+        String sql = "SELECT SUM(hours_worked) AS total_hours FROM BO_EU_DNSDK_WORK_ENTRY WHERE task_id = ?";
+        RowMap map = DBSql.getMap(sql, new Object[]{taskId});
+
+        // 处理总工时获取,若为null或非数值类型则设为0.0
+        double totalHours;
+        if (map != null) {
+            Object hoursObj = map.get("total_hours");
+            if (hoursObj != null && hoursObj instanceof Number) {
+                totalHours = ((Number) hoursObj).doubleValue();
+            } else {
+                totalHours = 0.0;
+            }
+        } else {
+            totalHours = 0.0;
+        }
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("total_hours", totalHours);
+        result.put("task_id", taskId);
+
+        ResponseObject responseObject = ResponseObject.newOkResponse();
+        responseObject.setData(result);
+
+        return responseObject;
+    }
+
+
 }