| 
					
				 | 
			
			
				@@ -1,5 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package fi.er.webService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import fi.cas.opplugin.TypeUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -8,18 +9,20 @@ import kd.bos.dataentity.OperateOption; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.dataentity.entity.DynamicObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.dataentity.entity.DynamicObjectCollection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.entity.operate.result.OperationResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import kd.bos.logging.Log; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import kd.bos.logging.LogFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 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.orm.query.QFilter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.servicehelper.BusinessDataServiceHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.servicehelper.operation.SaveServiceHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import kd.bos.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import nckd.jimin.jyyy.fi.common.NstcApiReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.Serializable; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @author zf 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,15 +33,17 @@ import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     protected static final Long DEFAULT_ORG_ID = 100000L; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final Log logger = LogFactory.getLog(SaveAccountApi.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @description 行名行号同步接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return CustomApiResult 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApiPostMapping(value = "/save", desc = "同步银行账户") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public CustomApiResultForMy<List<AccountSynReturnModel>> saveAccount (@ApiParam(value = "九恒星银行账户") JSONArray data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public CustomApiResult<JSONObject> saveAccount (@ApiParam(value = "九恒星银行账户") JSONArray data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         StringBuilder resultString = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<AccountSynReturnModel> returnList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Boolean result = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         DynamicObject rmbinfo = BusinessDataServiceHelper.loadSingleFromCache(1L,"bd_currency"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -56,18 +61,32 @@ public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         DynamicObject defaulttypecodeinfo =BusinessDataServiceHelper.loadSingleFromCache("bd_bankcgsetting",new QFilter[]{typecodeFilter}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONArray dataArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //循环传入的数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (int i = 0; i < data.size(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             JSONObject eobject = data.getJSONObject(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            AccountSynReturnModel contractSynReturnModel = syncAccount(eobject,rmbinfo,defaultjrjgtypeinfo,defaultgj,defaulttypecodeinfo,defaultOrg,user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ("500".equals(contractSynReturnModel.getCode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                result = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                NstcApiReturnModel contractSynReturnModel = syncAccount(eobject, rmbinfo, defaultjrjgtypeinfo, defaultgj, defaulttypecodeinfo, defaultOrg, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ("500".equals(contractSynReturnModel.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                dataArray.add(JSONObject.parseObject(JSON.toJSONString(contractSynReturnModel))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.error("保存银行账号失败:{}", e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                NstcApiReturnModel returnModel = new NstcApiReturnModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                returnModel.setNumber(eobject.get("bankAccountNumber")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                returnModel.setName(eobject.get("acctName")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                returnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                returnModel.setMessage("保存银行账号失败: " + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                dataArray.add(JSONObject.parseObject(JSON.toJSONString(returnModel))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            returnList.add(contractSynReturnModel); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return result == true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ? CustomApiResultForMy.success2(returnList) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                : CustomApiResultForMy.fail(returnList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return returnResult("200", "S", "接口调用成功,同步结果请查看responseData参数", dataArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -75,8 +94,8 @@ public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @description 保存行名行号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param jsonObject 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private AccountSynReturnModel syncAccount(JSONObject jsonObject,DynamicObject rmbinfo, DynamicObject defaultjrjgtypeinfo,DynamicObject defaultgj,DynamicObject defaulttypecodeinfo, DynamicObject defaultOrg,DynamicObject user) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        AccountSynReturnModel contractSynReturnModel = new AccountSynReturnModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private NstcApiReturnModel syncAccount(JSONObject jsonObject,DynamicObject rmbinfo, DynamicObject defaultjrjgtypeinfo,DynamicObject defaultgj,DynamicObject defaulttypecodeinfo, DynamicObject defaultOrg,DynamicObject user) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        NstcApiReturnModel contractSynReturnModel = new NstcApiReturnModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date curDate = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String number = jsonObject.get("bankAccountNumber")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String name = jsonObject.get("acctName")+""; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -113,15 +132,21 @@ public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(jsonObject.get("accountBankType") == null || jsonObject.getJSONObject("accountBankType").get("alias") == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            contractSynReturnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            contractSynReturnModel.setMessage("开户行参数(bank)为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //账户类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String acctstyle = jsonObject.get("acctstyle")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String acctstyle = jsonObject.getJSONObject("accountBankType").getString("alias"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ("".equals(acctstyle)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setMessage("账户类型不能为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //opendate开户日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String opendate = jsonObject.get("opendate")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String opendate = jsonObject.get("openDate")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ("".equals(opendate)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setMessage("开户日期不能为空"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -129,8 +154,13 @@ public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(jsonObject.get("bank") == null || jsonObject.getJSONObject("bank").get("id") == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            contractSynReturnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            contractSynReturnModel.setMessage("开户行参数(bank)为空"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //开户行行号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String banknumber = jsonObject.get("bank")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String banknumber = jsonObject.getJSONObject("bank").getString("id"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ("".equals(banknumber)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setMessage("开户行行号不能为空"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -144,6 +174,7 @@ public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setMessage("开户行行号"+banknumber+"不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //通过开户行行号找到金融机构,没有就新增一个 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         QFilter jrjgqFilter = new QFilter("bebank.number","=",banknumber); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         DynamicObject jrjginfo =BusinessDataServiceHelper.loadSingleFromCache("bd_finorginfo",new QFilter[]{jrjgqFilter}); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -265,10 +296,47 @@ public class SaveAccountApi implements Serializable { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 contractSynReturnModel.setMessage(err.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            StringBuilder errMsg = new StringBuilder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(StringUtils.isNotEmpty(result.getMessage())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                errMsg.append(result.getMessage() + ";"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (result.getSuccessPkIds().size() <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (int i = 0; i < result.getAllErrorOrValidateInfo().size(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    String message = result.getAllErrorOrValidateInfo().get(i).getMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    errMsg.append("/").append(message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             contractSynReturnModel.setCode("500"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            contractSynReturnModel.setMessage("保存失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            contractSynReturnModel.setMessage("保存失败" + errMsg.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return contractSynReturnModel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 自定义返回data对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param code  编码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param message  错误信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return   CustomApiResult  返回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public CustomApiResult<JSONObject> returnResult(String code, String status, String message, JSONArray dataArrary){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject reslutData = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONArray responseData = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        JSONObject dataJSON = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dataJSON.put("data", dataArrary); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        responseData.add(dataJSON); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        reslutData.put("code", code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        reslutData.put("status", status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        reslutData.put("message", message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        reslutData.put("responseData", responseData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return CustomApiResult.success(reslutData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |