|
@@ -1,10 +1,12 @@
|
|
|
package nckd.jimin.jyyy.fi.webapi;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
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.dataentity.entity.DynamicObjectCollection;
|
|
|
import kd.bos.entity.BillEntityType;
|
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
|
import kd.bos.id.ID;
|
|
@@ -24,6 +26,9 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -59,9 +64,46 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
public CustomApiResult<Boolean> saveContract(@ApiParam("单据信息") Map<String, Object> billData
|
|
|
,@ApiParam("附件面板") Map<String, List<Map<String,Object>>> allAttachmentsData
|
|
|
) {
|
|
|
+ // 接口返回结果
|
|
|
+ CustomApiResult<Boolean> result = new CustomApiResult<>();
|
|
|
+ // 0)数据校验
|
|
|
+ if(!"1".equals(billData.get("fcontracttype"))) { // 合同类型
|
|
|
+ result.setMessage("合同类型不是1,星瀚不接收");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String fapplierid = (String)billData.get("fapplierid");// fapplierid 经办人:员工编码_名称
|
|
|
+ String gonghao = fapplierid.split("_")[0]; // 提取员工工号
|
|
|
+ DynamicObject applicatuser = BusinessDataServiceHelper.loadSingle("bos_user","id,name,number",new QFilter[]{new QFilter("number",QCP.equals,gonghao)});
|
|
|
+
|
|
|
+ String fcontractcode = (String)billData.get("fcontractcode"); // 合同号(原始)
|
|
|
+ String fcontractcodenew = (String)billData.get("fcontractcodenew"); // 合同号(最新)
|
|
|
+ String fcontractname = (String)billData.get("fcontractname"); // 合同名称
|
|
|
+ String fdescription = (String)billData.get("fdescription"); // 合同说明
|
|
|
+
|
|
|
+ String fbizdate = (String)billData.get("fbizdate"); // 申请日期
|
|
|
+ String fsigndate = (String)billData.get("fsigndate"); // 签订日期
|
|
|
+ String fstartdate = (String)billData.get("fstartdate"); // 起始日期
|
|
|
+ String fenddate = (String)billData.get("fenddate"); // 截止日期
|
|
|
+
|
|
|
+ String contractcurrency = (String)billData.get("contractcurrency"); // 币种
|
|
|
+
|
|
|
+ // 甲方纳税号
|
|
|
+ String fjiafangxinyongcode = (String)billData.get("fjiafangxinyongcode"); // 甲方统一社会信用代码
|
|
|
+
|
|
|
+ String fjiafangcontactperson = (String)billData.get("fjiafangcontactperson"); // 甲方联系人
|
|
|
+
|
|
|
+ // 签约方:乙方集合
|
|
|
+ JSONArray contractpartyAry = (JSONArray) billData.get("contractparty");
|
|
|
+
|
|
|
+ // 付款计划集合
|
|
|
+ JSONArray fukuanplanAry = (JSONArray) billData.get("fukuanplan");
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
// 1)单据组装
|
|
|
String entityNumber = "er_contractbill";
|
|
|
- QFilter qFilter = new QFilter("billno", QCP.equals,billData.get("billno"));
|
|
|
+ QFilter qFilter = new QFilter("contractcode", QCP.equals,fcontractcode); // 合同号(原始)
|
|
|
DynamicObject dynamicObject = null;
|
|
|
if(QueryServiceHelper.exists(entityNumber,new QFilter[]{qFilter})){
|
|
|
// 存在
|
|
@@ -70,8 +112,8 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
// 不存在,创建对象
|
|
|
dynamicObject = BusinessDataServiceHelper.newDynamicObject(entityNumber); // 单据标识
|
|
|
dynamicObject.set("id", ID.genLongId()); // 创建id值
|
|
|
- DynamicObject user = BusinessDataServiceHelper.loadSingle(2044172821214535680L, "bos_user");
|
|
|
- dynamicObject.set("creator",user); // 创建人
|
|
|
+
|
|
|
+ dynamicObject.set("creator",applicatuser); // 创建人
|
|
|
dynamicObject.set("createtime",new Date()); // 创建时间
|
|
|
}
|
|
|
long pkid = dynamicObject.getLong("id");
|
|
@@ -80,40 +122,135 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
String appId = dataEntityType.getAppId(); // 获取单据的应用id
|
|
|
|
|
|
dynamicObject.set("billno",billData.get("billno")); // 单据编号
|
|
|
- dynamicObject.set("billstatus","A"); // 单据状态
|
|
|
+ dynamicObject.set("billstatus","A"); // 单据状态, A-暂存,E-审核通过
|
|
|
//单据其他业务字段赋值
|
|
|
- DynamicObject company = BusinessDataServiceHelper.loadSingle(2047903393485171712L, "bos_org");
|
|
|
+ // 甲方:ftaxregnum 纳税识别号
|
|
|
+ DynamicObject company = BusinessDataServiceHelper.loadSingle("bos_org","id,name",new QFilter[]{new QFilter("ftaxregnum",QCP.equals,fjiafangxinyongcode)});
|
|
|
dynamicObject.set("company",company); // 公司
|
|
|
- DynamicObject stdbilltype = BusinessDataServiceHelper.loadSingle(1421795442374670336L, "bos_billtype");
|
|
|
+
|
|
|
+ DynamicObject stdbilltype = BusinessDataServiceHelper.loadSingle("bos_billtype","id,name",new QFilter[]{new QFilter("number",QCP.equals,"er_contractbill_BT_S")});
|
|
|
dynamicObject.set("stdbilltype",stdbilltype); // 单据类型:基础资料 合同台账
|
|
|
+
|
|
|
dynamicObject.set("detailtype","biztype_applybill"); //(影响列表记录显示) 单据类型:biztype_applybill 合同台账 ,biztype_changebill 合同变更,biztype_stopbill 合同终止
|
|
|
- DynamicObject contracttype = BusinessDataServiceHelper.loadSingle(2067611114828487680L, "pmct_conttype");
|
|
|
+
|
|
|
+ DynamicObject contracttype = BusinessDataServiceHelper.loadSingle("pmct_conttype","id,name",new QFilter[]{new QFilter("number",QCP.equals,"FYHT")});
|
|
|
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("contractcode",fcontractcode); // 合同号
|
|
|
+ dynamicObject.set("contractname",fcontractname); // 合同名称
|
|
|
+
|
|
|
+ dynamicObject.set("costcompany",company); // 核算组织
|
|
|
+ try {
|
|
|
+ dynamicObject.set("signdate",sdf.parse(fsigndate)); // 签订日期
|
|
|
+ dynamicObject.set("startdate",sdf.parse(fstartdate)); // 起始日期
|
|
|
+ dynamicObject.set("enddate",sdf.parse(fenddate)); // 截止日期
|
|
|
+// dynamicObject.set("changedate",sdf.parse(fstartdate)); // 变更日期
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
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("description",fdescription); // 合同说明
|
|
|
+// dynamicObject.set("nckd_is_important_contrac","true"); // 是否重要合同
|
|
|
+ dynamicObject.set("partbtype","bd_supplier"); // 乙方类型(隐藏字段)
|
|
|
|
|
|
- dynamicObject.set("modifier",user); // 修改人
|
|
|
+ dynamicObject.set("iscurrency",true); // 默认设置多币种
|
|
|
+
|
|
|
+ DynamicObject bizhong = BusinessDataServiceHelper.loadSingle("bd_currency","id,name",new QFilter[]{new QFilter("number",QCP.equals,contractcurrency)});
|
|
|
+ dynamicObject.set("contractcurrency",bizhong); // 币种
|
|
|
+
|
|
|
+ DynamicObject CNY = BusinessDataServiceHelper.loadSingle("bd_currency","id,name",new QFilter[]{new QFilter("number",QCP.equals,"CNY")});
|
|
|
+
|
|
|
+ // orgcur 原币,cur 目标币(指定人民币),effectdate 生效日期
|
|
|
+ DynamicObject[] huilvAry = BusinessDataServiceHelper.load("bd_exrate_tree","id,orgcur,cur,excval,effectdate",
|
|
|
+ new QFilter[]{new QFilter("orgcur",QCP.equals,bizhong.getLong("id"))
|
|
|
+ .and("cur",QCP.equals,CNY.getLong("id"))
|
|
|
+ .and("enable",QCP.equals,CNY.getLong("id"))},"effectdate desc");
|
|
|
+
|
|
|
+ BigDecimal huilv = new BigDecimal(0);
|
|
|
+ if(huilvAry.length > 0) {
|
|
|
+ huilv = huilvAry[0].getBigDecimal("excval"); // 直接汇率值
|
|
|
+ }
|
|
|
+ dynamicObject.set("changerate",huilv); // 汇率(需根据币别查询最新汇率)
|
|
|
+
|
|
|
+ dynamicObject.set("org",company);// 经办人部门
|
|
|
+ dynamicObject.set("costdept",company);// 费用承担部门
|
|
|
+ dynamicObject.set("applier",applicatuser); // 经办人
|
|
|
+ dynamicObject.set("modifier",applicatuser); // 修改人
|
|
|
dynamicObject.set("modifytime",new Date()); // 修改时间
|
|
|
- dynamicObject.set("org",costcompany);// 经办人部门
|
|
|
- dynamicObject.set("costdept",costcompany);// 费用承担部门
|
|
|
+
|
|
|
+ // 1.2)签约方分录
|
|
|
+ DynamicObjectCollection newColl = dynamicObject.getDynamicObjectCollection("contractpartyentry"); // 单据体标识
|
|
|
+ newColl.clear();
|
|
|
+ // 甲方
|
|
|
+ DynamicObject newEntry = new DynamicObject(newColl.getDynamicObjectType());
|
|
|
+ newEntry.set("signcontract", "0"); // 签约方,甲方-0,乙方-1,其他方-2
|
|
|
+ newEntry.set("partytype", "bos_org"); // 签约方类型:bos_org 公司,bd_supplier 供应商,bd_customer 客户
|
|
|
+ newEntry.set("contractparty", company); // 签约方名称
|
|
|
+ newEntry.set("contactperson", fjiafangcontactperson); // 联系人,文本
|
|
|
+ newColl.add(newEntry);
|
|
|
+ // 乙方
|
|
|
+ for (Object item : contractpartyAry) {
|
|
|
+ JSONObject jsb = (JSONObject)item;
|
|
|
+ String fxinyongcode = jsb.getString("fxinyongcode"); // 统一社会信用代码
|
|
|
+ String fcontactperson = jsb.getString("fcontactperson"); // 乙方联系人
|
|
|
+ DynamicObject newEntry2 = new DynamicObject(newColl.getDynamicObjectType());
|
|
|
+ newEntry2.set("signcontract", "1"); // 签约方,甲方-0,乙方-1,其他方-2
|
|
|
+ newEntry2.set("partytype", "bd_supplier"); // 签约方类型:bos_org 公司,bd_supplier 供应商,bd_customer 客户
|
|
|
+ DynamicObject supplier = BusinessDataServiceHelper.loadSingle("bd_supplier","id,name",new QFilter[]{new QFilter("societycreditcode",QCP.equals,fxinyongcode)});
|
|
|
+ newEntry2.set("contractparty", supplier); // 签约方名称
|
|
|
+ newEntry2.set("contactperson", fcontactperson); // 联系人,文本
|
|
|
+ newColl.add(newEntry2);
|
|
|
+ }
|
|
|
+ dynamicObject.set("contractpartyentry", newColl); // 签约方分录
|
|
|
+
|
|
|
+ // 1.3)付款计划分录
|
|
|
+ DynamicObjectCollection plannewColl = dynamicObject.getDynamicObjectCollection("expenseentryentity"); // 单据体标识
|
|
|
+ plannewColl.clear();
|
|
|
+ BigDecimal hetongjinetotalfist = new BigDecimal(0); // 合同总额(初始)
|
|
|
+ for (Object item : fukuanplanAry) {
|
|
|
+ JSONObject jsb = (JSONObject)item;
|
|
|
+ String fpayterms = jsb.getString("fpayterms"); // 付款条件
|
|
|
+ BigDecimal fexpapplyamount = jsb.getBigDecimal("fexpapplyamount"); // 含税金额
|
|
|
+ String std_project = jsb.getString("fprojectid"); // 项目
|
|
|
+
|
|
|
+ DynamicObject newEntry3 = new DynamicObject(plannewColl.getDynamicObjectType());
|
|
|
+ DynamicObject fukuantype = BusinessDataServiceHelper.loadSingle("cas_paymentbilltype","id,name",new QFilter[]{new QFilter("number",QCP.equals,"201")});
|
|
|
+ newEntry3.set("paymenttypeid",fukuantype); // 付款类型
|
|
|
+ newEntry3.set("payterms",fpayterms); // 付款条件
|
|
|
+ try {
|
|
|
+ newEntry3.set("happendate",sdf.parse("2999-12-31")); // 预计付款日期
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ newEntry3.set("entrycostdept",company); // 费用承担部门
|
|
|
+ newEntry3.set("entrycostcompany",company); // 费用承担公司
|
|
|
+ // 固定值
|
|
|
+ DynamicObject feiyongproject = BusinessDataServiceHelper.loadSingle("er_expenseitemedit","id,name",new QFilter[]{new QFilter("number",QCP.equals,"FYXM0001")});
|
|
|
+ newEntry3.set("expenseitem",feiyongproject); // 费用项目
|
|
|
+ newEntry3.set("expenseamount",fexpapplyamount); // 含税金额
|
|
|
+ newEntry3.set("orientryamount",fexpapplyamount); // 不含税金额
|
|
|
+ hetongjinetotalfist = hetongjinetotalfist.add(fexpapplyamount);
|
|
|
+
|
|
|
+ newEntry3.set("exchangerate",huilv); // 汇率
|
|
|
+
|
|
|
+ DynamicObject project = BusinessDataServiceHelper.loadSingle("bd_project","id,name",new QFilter[]{new QFilter("number",QCP.equals,std_project)});
|
|
|
+ newEntry3.set("std_project",project); // 项目
|
|
|
+
|
|
|
+ newEntry3.set("entrycurrency",bizhong); // 分录币别(和头表一致)
|
|
|
+
|
|
|
+ plannewColl.add(newEntry3);
|
|
|
+ }
|
|
|
+ dynamicObject.set("expenseentryentity", plannewColl); // 付款计划分录
|
|
|
+
|
|
|
+ dynamicObject.set("contractamount", hetongjinetotalfist); // 合同总额(初始)
|
|
|
+ dynamicObject.set("oriapplyamount", hetongjinetotalfist); // 合同总额(变更后)
|
|
|
+ dynamicObject.set("originalamount", hetongjinetotalfist); // 合同总额(不含税)
|
|
|
+ dynamicObject.set("orinotpayamount", hetongjinetotalfist); // 未付金额
|
|
|
|
|
|
// 先单据保存
|
|
|
OperationResult opResult = SaveServiceHelper.saveOperate(entityNumber, new DynamicObject[]{dynamicObject}, OperateOption.create());
|
|
|
- CustomApiResult<Boolean> result = new CustomApiResult<>();
|
|
|
- result.setData(opResult.isSuccess());
|
|
|
|
|
|
- // 3)删除历史附件
|
|
|
+ // 2)删除历史附件
|
|
|
List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments(entityNumber, dynamicObject.getPkValue(),"attachmentpanel");
|
|
|
if (atts.size() > 0) {
|
|
|
// 获取全部附件
|
|
@@ -129,7 +266,7 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 4)附件保存入库
|
|
|
+ // 3)附件保存入库
|
|
|
Map<String, Object> attachmentInfos = new HashMap<>();
|
|
|
for (Map.Entry<String, List<Map<String,Object>>> entry : allAttachmentsData.entrySet()) {
|
|
|
if ("attachmentpanel".equals(entry.getKey())) {
|
|
@@ -155,6 +292,7 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
|
|
|
AttachmentServiceHelper.saveTempAttachments(entityNumber, pkid, appId, attachmentInfos);
|
|
|
|
|
|
+ result.setMessage("成功");
|
|
|
return result;
|
|
|
}
|
|
|
|