|
@@ -69,51 +69,104 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
) {
|
|
|
// 接口返回结果
|
|
|
CustomApiResult<Boolean> result = new CustomApiResult<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
// 0)数据校验
|
|
|
- if(!"1".equals(billData.get("contracttype"))) { // 合同类型
|
|
|
- result.setMessage("合同类型不是1,星瀚不接收");
|
|
|
+ // 合同类型
|
|
|
+ if(!"1".equals(billData.get("contracttype"))) {
|
|
|
+ result.setMessage("合同类型不是1,星瀚不接收"); // 返回状态还是成功的,只是不接收
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // fapplierid 经办人:员工编码_名称 ,由根据人员信息带出主职的公司、部门、职位、手机
|
|
|
+ String fapplierid = (String)billData.get("applierid");
|
|
|
+ if (StringUtils.isEmpty(fapplierid)) {
|
|
|
+ result.setMessage("经办人fapplierid未传值");
|
|
|
+ result.setStatus(false);
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
- String fapplierid = (String)billData.get("applierid");// fapplierid 经办人:员工编码_名称
|
|
|
String gonghao = fapplierid.split("_")[0]; // 提取员工工号
|
|
|
- DynamicObject applicatuser = BusinessDataServiceHelper.loadSingle("bos_user","id,name,number",new QFilter[]{new QFilter("number",QCP.equals,gonghao)});
|
|
|
+ DynamicObject applicatuser = BusinessDataServiceHelper.loadSingle("bos_user","id,name,number,phone",new QFilter[]{new QFilter("number",QCP.equals,gonghao)});
|
|
|
+ if (applicatuser == null) {
|
|
|
+ result.setMessage("经办人工号未在星瀚系统出现");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 合同号(原始)
|
|
|
+ String fcontractcode = (String)billData.get("contractcode");
|
|
|
+ if (StringUtils.isEmpty(fapplierid)) {
|
|
|
+ result.setMessage("经办人fapplierid未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- String fcontractcode = (String)billData.get("contractcode"); // 合同号(原始)
|
|
|
String nckd_contractcodenew = (String)billData.get("nckd_contractcodenew"); // 合同号(最新)
|
|
|
String fcontractname = (String)billData.get("contractname"); // 合同名称
|
|
|
String fdescription = (String)billData.get("description"); // 合同说明
|
|
|
+ if (StringUtils.isEmpty(fdescription)) {
|
|
|
+ result.setMessage("合同说明description未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- String fbizdate = (String)billData.get("bizdate"); // 申请日期
|
|
|
String fsigndate = (String)billData.get("signdate"); // 签订日期
|
|
|
+ if (StringUtils.isEmpty(fsigndate)) {
|
|
|
+ result.setMessage("签订日期fsigndate未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ String fbizdate = (String)billData.get("bizdate"); // 申请日期
|
|
|
String fstartdate = (String)billData.get("startdate"); // 起始日期
|
|
|
String fenddate = (String)billData.get("enddate"); // 截止日期
|
|
|
|
|
|
String contractcurrency = (String)billData.get("contractcurrency"); // 币种
|
|
|
-
|
|
|
+ if (StringUtils.isEmpty(contractcurrency)) {
|
|
|
+ result.setMessage("币种contractcurrency未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
String projectower = (String)billData.get("projectower"); // 合同干系人
|
|
|
-
|
|
|
+ if (StringUtils.isEmpty(projectower)) {
|
|
|
+ result.setMessage("合同干系人projectower未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
// 甲方纳税号
|
|
|
String fjiafangxinyongcode = (String)billData.get("jiafangxinyongcode"); // 甲方统一社会信用代码
|
|
|
+ if (StringUtils.isEmpty(fjiafangxinyongcode)) {
|
|
|
+ result.setMessage("甲方统一社会信用代码jiafangxinyongcode未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
String fjiafangcontactperson = (String)billData.get("jiafangcontactperson"); // 甲方联系人
|
|
|
-
|
|
|
+ if (StringUtils.isEmpty(fjiafangcontactperson)) {
|
|
|
+ result.setMessage("甲方联系人fjiafangcontactperson未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 合同来源
|
|
|
+ String nckd_sources = (String)billData.get("nckd_sources");
|
|
|
+ if (StringUtils.isEmpty(nckd_sources)) {
|
|
|
+ result.setMessage("合同来源nckd_sources未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
// 签约方:乙方集合
|
|
|
JSONArray contractpartyAry = (JSONArray) billData.get("contractparty");
|
|
|
+ if (contractpartyAry == null || contractpartyAry.size() == 0) {
|
|
|
+ result.setMessage("签约方contractparty未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
// 付款计划集合
|
|
|
JSONArray fukuanplanAry = (JSONArray) billData.get("fukuanplan");
|
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
-
|
|
|
- String nckd_sources = (String)billData.get("nckd_sources"); // 合同来源
|
|
|
-
|
|
|
// 1)单据组装
|
|
|
- String entityNumber = "er_contractbill";
|
|
|
+ String entityNumber = "er_contractbill"; // 合同台账单 单据标识
|
|
|
QFilter qFilter = new QFilter("contractcode", QCP.equals,fcontractcode); // 合同号(原始)
|
|
|
DynamicObject dynamicObject = null;
|
|
|
if(QueryServiceHelper.exists(entityNumber,new QFilter[]{qFilter})){
|
|
|
- // 存在
|
|
|
+ // 合同台账的合同号(原始)已存在
|
|
|
dynamicObject = BusinessDataServiceHelper.loadSingle(entityNumber,new QFilter[]{qFilter});
|
|
|
String contractcodenewhistory = dynamicObject.getString("nckd_contractcodenew");// 合同号(最新)
|
|
|
if (!StringUtils.isEmpty(nckd_contractcodenew)) {
|
|
@@ -129,7 +182,7 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- // 不存在,创建对象
|
|
|
+ // 不存在,创建新对象
|
|
|
dynamicObject = BusinessDataServiceHelper.newDynamicObject(entityNumber); // 单据标识
|
|
|
dynamicObject.set("id", ID.genLongId()); // 创建id值
|
|
|
|
|
@@ -141,8 +194,9 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
BillEntityType dataEntityType = (BillEntityType) dynamicObject.getDataEntityType();
|
|
|
String appId = dataEntityType.getAppId(); // 获取单据的应用id
|
|
|
|
|
|
- dynamicObject.set("billstatus","A"); // 单据状态, A-暂存,E-审核通过
|
|
|
+ dynamicObject.set("billstatus","E"); // 单据状态, A-暂存,E-审核通过
|
|
|
//单据其他业务字段赋值
|
|
|
+ dynamicObject.set("tel",applicatuser.getString("phone"));// 联系方式,申请人手机号
|
|
|
// 甲方:ftaxregnum 纳税识别号
|
|
|
DynamicObject company = BusinessDataServiceHelper.loadSingle("bos_org","id,name",new QFilter[]{new QFilter("uniformsocialcreditcode",QCP.equals,fjiafangxinyongcode)});
|
|
|
dynamicObject.set("company",company); // 公司
|
|
@@ -160,16 +214,30 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
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)); // 变更日期
|
|
|
+ if (StringUtils.isEmpty(fbizdate)) {
|
|
|
+ dynamicObject.set("bizdate",sdf.parse(fsigndate)); // 申请日期,无值取签订日期
|
|
|
+ } else {
|
|
|
+ dynamicObject.set("bizdate",sdf.parse(fbizdate)); // 申请日期
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(fstartdate)) {
|
|
|
+ dynamicObject.set("startdate",sdf.parse(fsigndate)); // 起始日期,无值取签订日期
|
|
|
+ } else {
|
|
|
+ dynamicObject.set("startdate",sdf.parse(fstartdate)); // 起始日期
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(fenddate)) {
|
|
|
+ dynamicObject.set("enddate",sdf.parse(fsigndate)); // 截止日期,无值取签订日期
|
|
|
+ } else {
|
|
|
+ dynamicObject.set("enddate",sdf.parse(fenddate)); // 截止日期
|
|
|
+ }
|
|
|
} catch (ParseException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
dynamicObject.set("changedate",new Date()); // 变更日期
|
|
|
dynamicObject.set("description",fdescription); // 合同说明
|
|
|
-// dynamicObject.set("nckd_is_important_contrac","true"); // 是否重要合同
|
|
|
dynamicObject.set("partbtype","bd_supplier"); // 乙方类型(隐藏字段)
|
|
|
|
|
|
dynamicObject.set("iscurrency",true); // 默认设置多币种
|
|
@@ -223,7 +291,7 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
// 甲方
|
|
|
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("partytype", "bos_org"); // 默认公司,签约方类型:bos_org 公司,bd_supplier 供应商,bd_customer 客户
|
|
|
newEntry.set("contractparty", company); // 签约方名称
|
|
|
newEntry.set("contactperson", fjiafangcontactperson); // 联系人,文本
|
|
|
newColl.add(newEntry);
|
|
@@ -231,13 +299,33 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
for (Object item : contractpartyAry) {
|
|
|
JSONObject jsb = (JSONObject)item;
|
|
|
String signcontract = jsb.getString("signcontract"); // 签约方:乙方:1,其他方:2
|
|
|
+ if (StringUtils.isEmpty(signcontract)) {
|
|
|
+ result.setMessage("乙方签约方signcontract未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
String fxinyongcode = jsb.getString("xinyongcode"); // 统一社会信用代码
|
|
|
+ if (StringUtils.isEmpty(fxinyongcode)) {
|
|
|
+ result.setMessage("乙方统一社会信用代码xinyongcode未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
String fcontactperson = jsb.getString("contactperson"); // 乙方联系人
|
|
|
+ if (StringUtils.isEmpty(fcontactperson)) {
|
|
|
+ result.setMessage("乙方联系人contactperson未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
DynamicObject newEntry2 = new DynamicObject(newColl.getDynamicObjectType());
|
|
|
newEntry2.set("signcontract", signcontract); // 签约方,甲方-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); // 签约方名称
|
|
|
+ if (supplier == null) {
|
|
|
+ result.setMessage("乙方统一社会信用代码" + fxinyongcode + "未在星瀚供应商中查询到");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ newEntry2.set("contractparty", supplier); // 签约方名称(基础资料对象)
|
|
|
newEntry2.set("contactperson", fcontactperson); // 联系人,文本
|
|
|
newColl.add(newEntry2);
|
|
|
}
|
|
@@ -250,8 +338,17 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
for (Object item : fukuanplanAry) {
|
|
|
JSONObject jsb = (JSONObject)item;
|
|
|
String fpayterms = jsb.getString("payterms"); // 付款条件
|
|
|
+ if (StringUtils.isEmpty(fpayterms)) {
|
|
|
+ result.setMessage("付款条件payterms未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
BigDecimal fexpapplyamount = jsb.getBigDecimal("expapplyamount"); // 含税金额
|
|
|
- String std_project = jsb.getString("projectid"); // 项目
|
|
|
+ if (fexpapplyamount == null) {
|
|
|
+ result.setMessage("含税金额expapplyamount未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
DynamicObject newEntry3 = new DynamicObject(plannewColl.getDynamicObjectType());
|
|
|
DynamicObject fukuantype = BusinessDataServiceHelper.loadSingle("cas_paymentbilltype","id,name",new QFilter[]{new QFilter("number",QCP.equals,"201")});
|
|
@@ -272,9 +369,10 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
hetongjinetotalfist = hetongjinetotalfist.add(fexpapplyamount);
|
|
|
|
|
|
newEntry3.set("exchangerate",huilv); // 汇率
|
|
|
-
|
|
|
+ // 项目
|
|
|
+ String std_project = jsb.getString("projectid");
|
|
|
DynamicObject project = BusinessDataServiceHelper.loadSingle("bd_project","id,name",new QFilter[]{new QFilter("number",QCP.equals,std_project)});
|
|
|
- newEntry3.set("std_project",project); // 项目
|
|
|
+ newEntry3.set("std_project",project);
|
|
|
|
|
|
newEntry3.set("entrycurrency",bizhong); // 分录币别(和头表一致)
|
|
|
|
|
@@ -326,30 +424,38 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
}
|
|
|
|
|
|
// 3)附件保存入库
|
|
|
- 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);
|
|
|
+ if (allAttachmentsData != null) {
|
|
|
+ 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"));
|
|
|
+ if (StringUtils.isEmpty((String)map.get("tempurl"))) {
|
|
|
+ result.setMessage("文件服务器临时路径tempurl未传值");
|
|
|
+ result.setStatus(false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ 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);
|
|
|
}
|
|
|
- attachmentInfos.put("attachmentpanel",attachments);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- AttachmentServiceHelper.saveTempAttachments(entityNumber, pkid, appId, attachmentInfos);
|
|
|
+ AttachmentServiceHelper.saveTempAttachments(entityNumber, pkid, appId, attachmentInfos);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
result.setMessage("成功");
|
|
|
return result;
|