瀏覽代碼

星瀚合同台账单接口发布

chengchaohua 4 天之前
父節點
當前提交
7cea4623e1

+ 161 - 0
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/webapi/ContractbillApiPlugin.java

@@ -0,0 +1,161 @@
+package nckd.jimin.jyyy.fi.webapi;
+
+import com.alibaba.fastjson.JSONObject;
+import kd.bos.cache.CacheFactory;
+import kd.bos.cache.TempFileCache;
+import kd.bos.dataentity.OperateOption;
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.BillEntityType;
+import kd.bos.entity.operate.result.OperationResult;
+import kd.bos.id.ID;
+import kd.bos.openapi.common.custom.annotation.ApiController;
+import kd.bos.openapi.common.custom.annotation.ApiMapping;
+import kd.bos.openapi.common.custom.annotation.ApiParam;
+import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
+import kd.bos.openapi.common.result.CustomApiResult;
+import kd.bos.openapi.common.result.OpenApiFile;
+import kd.bos.orm.query.QCP;
+import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.AttachmentServiceHelper;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.QueryServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * 提供给合同系统的新增/更新接口,对应星瀚合同台账单er_contractbill
+ * api编码:contract/uploadFileTemp (不用,用标品的uploadFile.do)
+ * api编码:contract/saveContract
+ *
+ * @author chengchaohua
+ * @since 2025/05/06
+ */
+@ApiController(value = "hetong", desc = "合同台账单接口")
+@ApiMapping("/contract")
+public class ContractbillApiPlugin implements Serializable {
+    private static final Logger log = LoggerFactory.getLogger(ContractbillApiPlugin.class);
+
+    @ApiPostMapping("/uploadFileTemp")
+    public CustomApiResult<Map<String,Object>> uploadFileTemp(@ApiParam(value = "文件流",required = true) OpenApiFile file) {
+        byte[] fileData = file.getFileData();
+        String fileName = file.getFileName();
+        Map<String,Object> map = new HashMap<>();
+        TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache();
+        String tempUrl = cache.saveAsFullUrl(fileName, fileData,3600);
+        CustomApiResult<Map<String,Object>> customApiResult = new CustomApiResult<>();
+        map.put("tempurl",tempUrl);
+        map.put("fileName",fileName);
+        map.put("size",file.getFileData().length);
+        customApiResult.setData(map);
+        return customApiResult;
+    }
+
+
+    @ApiPostMapping(value = "/saveContract", desc = "保存合同台账单")
+    public CustomApiResult<Boolean> saveContract(@ApiParam("单据信息") Map<String, Object> billData
+            ,@ApiParam("附件面板") Map<String, List<Map<String,Object>>> allAttachmentsData
+    ) {
+        // 1)单据组装
+        String entityNumber = "er_contractbill";
+        QFilter qFilter = new QFilter("billno", QCP.equals,billData.get("billno"));
+        DynamicObject dynamicObject = null;
+        if(QueryServiceHelper.exists(entityNumber,new QFilter[]{qFilter})){
+            // 存在
+            dynamicObject = BusinessDataServiceHelper.loadSingle(entityNumber,new QFilter[]{qFilter});
+        }else {
+            // 不存在,创建对象
+            dynamicObject = BusinessDataServiceHelper.newDynamicObject(entityNumber); // 单据标识
+            dynamicObject.set("id", ID.genLongId()); // 创建id值
+            DynamicObject user = BusinessDataServiceHelper.loadSingle(2044172821214535680L, "bos_user");
+            dynamicObject.set("creator",user); // 创建人
+            dynamicObject.set("createtime",new Date()); // 创建时间
+        }
+        long pkid = dynamicObject.getLong("id");
+
+        BillEntityType dataEntityType = (BillEntityType) dynamicObject.getDataEntityType();
+        String appId = dataEntityType.getAppId(); // 获取单据的应用id
+
+        dynamicObject.set("billno",billData.get("billno")); // 单据编号
+        dynamicObject.set("billstatus","A"); // 单据状态
+        //单据其他业务字段赋值
+        DynamicObject company = BusinessDataServiceHelper.loadSingle(2047903393485171712L, "bos_org");
+        dynamicObject.set("company",company); // 公司
+        DynamicObject stdbilltype = BusinessDataServiceHelper.loadSingle(1421795442374670336L, "bos_billtype");
+        dynamicObject.set("stdbilltype",stdbilltype); // 单据类型:基础资料 合同台账
+        dynamicObject.set("detailtype","biztype_applybill"); //(影响列表记录显示) 单据类型:biztype_applybill 合同台账 ,biztype_changebill 合同变更,biztype_stopbill 合同终止
+        DynamicObject contracttype = BusinessDataServiceHelper.loadSingle(2067611114828487680L, "pmct_conttype");
+        dynamicObject.set("contracttype",contracttype); // 合同类型
+        dynamicObject.set("contractcode","test001"); // 合同号
+        dynamicObject.set("contractname","test001测试"); // 合同名称
+
+        DynamicObject costcompany = BusinessDataServiceHelper.loadSingle(2047903393485171712L, "bos_org");
+        dynamicObject.set("costcompany",costcompany); // 核算组织
+        dynamicObject.set("signdate",new Date()); // 签订日期
+        dynamicObject.set("startdate",new Date()); // 起始日期
+        dynamicObject.set("enddate",new Date()); // 截止日期
+        dynamicObject.set("changedate",new Date()); // 变更日期
+        dynamicObject.set("description","1111");  // 合同说明
+        dynamicObject.set("nckd_is_important_contrac","true"); // 是否重要合同
+        dynamicObject.set("partbtype","bd_supplier"); // 乙方类型
+        DynamicObject user = BusinessDataServiceHelper.loadSingle(2044172821214535680L, "bos_user");
+
+        dynamicObject.set("modifier",user); // 修改人
+        dynamicObject.set("modifytime",new Date()); // 修改时间
+        dynamicObject.set("org",costcompany);// 经办人部门
+        dynamicObject.set("costdept",costcompany);// 费用承担部门
+
+        // 先单据保存
+        OperationResult opResult = SaveServiceHelper.saveOperate(entityNumber, new DynamicObject[]{dynamicObject}, OperateOption.create());
+        CustomApiResult<Boolean> result = new CustomApiResult<>();
+        result.setData(opResult.isSuccess());
+
+        // 3)删除历史附件
+       List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments(entityNumber, dynamicObject.getPkValue(),"attachmentpanel");
+        if (atts.size() > 0) {
+            // 获取全部附件
+            Iterator<Map<String, Object>> iterator = atts.iterator();
+            // 遍历所有附件
+            while (iterator.hasNext()) {
+                Map map2 = iterator.next();
+                String formId = map2.get("entityNum").toString();
+                Object pkId = map2.get("billPkId"); // 单据id
+                Object fileUid = map2.get("uid");
+                //从数据库中删除上一次保存的附件
+                AttachmentServiceHelper.remove(formId, pkId, fileUid);
+            }
+        }
+
+        // 4)附件保存入库
+        Map<String, Object> attachmentInfos = new HashMap<>();
+        for (Map.Entry<String, List<Map<String,Object>>> entry : allAttachmentsData.entrySet()) {
+            if ("attachmentpanel".equals(entry.getKey())) {
+                // 取‘附件面板’的附件集合
+                List<Map<String, Object>> fileList = entry.getValue();
+                List<Map<String, Object>> attachments = new ArrayList<>();
+                for (int i= 0; i < fileList.size(); i++) {
+                    Map<String, Object> map = fileList.get(i);
+                    StringBuffer uid = new StringBuffer();
+                    uid.append("rc-upload-").append(new Date().getTime()).append("-");
+                    Map<String,Object> attachmentInfo = new HashMap<>();
+                    attachmentInfo.put("entityNumber", entityNumber);
+                    attachmentInfo.put("name", map.get("fileName"));
+                    attachmentInfo.put("url", map.get("tempurl"));
+                    attachmentInfo.put("size", map.get("size"));
+                    attachmentInfo.put("status", map.get("status"));
+                    attachmentInfo.put("uid", uid.toString() + i);
+                    attachments.add(attachmentInfo);
+                }
+                attachmentInfos.put("attachmentpanel",attachments);
+            }
+        }
+
+        AttachmentServiceHelper.saveTempAttachments(entityNumber, pkid, appId, attachmentInfos);
+
+        return result;
+    }
+
+}