|
@@ -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
|
|
|
+ ) {
|
|
|
+
|
|
|
+ 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());
|
|
|
+ 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();
|
|
|
+
|
|
|
+ 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");
|
|
|
+ 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());
|
|
|
+
|
|
|
+
|
|
|
+ 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");
|
|
|
+ Object fileUid = map2.get("uid");
|
|
|
+
|
|
|
+ AttachmentServiceHelper.remove(formId, pkId, fileUid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|