接口优化调整
This commit is contained in:
parent
94438626f6
commit
e4fc50883e
|
|
@ -15,7 +15,7 @@ import java.net.URLEncoder;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class JHSSOAuthHandler implements ThirdSSOAuthHandler {
|
public class JHSSOAuthHandler implements ThirdSSOAuthHandler {
|
||||||
private static final String ssologinUrl = "https://ip/login.html";
|
private static final String ssologinUrl = "https://www.baidu.com";
|
||||||
private static final String client_id = "id";//应用注册ID 由认证系统提供
|
private static final String client_id = "id";//应用注册ID 由认证系统提供
|
||||||
private static final String client_secret = "secret";//应用注册密码 由认证系统提供
|
private static final String client_secret = "secret";//应用注册密码 由认证系统提供
|
||||||
|
|
||||||
|
|
@ -67,6 +67,9 @@ public class JHSSOAuthHandler implements ThirdSSOAuthHandler {
|
||||||
private String getWorkerNumber(HttpServletRequest hsrequest){
|
private String getWorkerNumber(HttpServletRequest hsrequest){
|
||||||
//第二步:SSO认证系统会携带临时code浏览器重定向至应用方回调地址,直接从请求中获取code
|
//第二步:SSO认证系统会携带临时code浏览器重定向至应用方回调地址,直接从请求中获取code
|
||||||
String tempCode = hsrequest.getParameter("code");
|
String tempCode = hsrequest.getParameter("code");
|
||||||
|
if(StringUtils.isEmpty(tempCode)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
//第三步:根据SSO颁发的code获取accessToken post请求 参数拼接在url上
|
//第三步:根据SSO颁发的code获取accessToken post请求 参数拼接在url上
|
||||||
StringBuffer ssoURL = new StringBuffer();
|
StringBuffer ssoURL = new StringBuffer();
|
||||||
ssoURL.append(ssologinUrl);
|
ssoURL.append(ssologinUrl);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
package shjh.jhzj7.fi.fi.utils;
|
package shjh.jhzj7.fi.fi.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import kd.bos.context.RequestContext;
|
import kd.bos.context.RequestContext;
|
||||||
import kd.bos.dataentity.entity.DynamicObject;
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.isc.util.script.encoding.Hash;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
|
||||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
|
|
||||||
public class EsbUtils {
|
public class EsbUtils {
|
||||||
//esb-人员、行政组织、成本中心、客商、会计科目、利润中心、客户组5接口工具类
|
//esb-人员、行政组织、成本中心、客商、会计科目、利润中心、客户组5接口工具类
|
||||||
|
|
@ -21,6 +26,7 @@ public class EsbUtils {
|
||||||
public static final Long CUSTOMERSTATUS = 1122390034075371520l;//客户状态 默认合格
|
public static final Long CUSTOMERSTATUS = 1122390034075371520l;//客户状态 默认合格
|
||||||
|
|
||||||
public static final Long ACCTABLE = 1318154893474663424L;//科目表
|
public static final Long ACCTABLE = 1318154893474663424L;//科目表
|
||||||
|
private static final String orgName = "bos_org";//系统库 表名 t_org_org
|
||||||
|
|
||||||
public static boolean isEmpty(String value) {
|
public static boolean isEmpty(String value) {
|
||||||
return value == null || value.trim().length() <= 0;
|
return value == null || value.trim().length() <= 0;
|
||||||
|
|
@ -31,6 +37,102 @@ public class EsbUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//处理分配
|
||||||
|
public static void handleAssign(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
|
JSONObject json_body;
|
||||||
|
String compnum;
|
||||||
|
String cusnumber = "";
|
||||||
|
DynamicObject compinfo;
|
||||||
|
List<Long> dataList = new ArrayList<>();
|
||||||
|
List<Long> orgList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < companysJson.size(); i++) {
|
||||||
|
json_body = companysJson.getJSONObject(i);
|
||||||
|
if(i == 0){
|
||||||
|
//初始化
|
||||||
|
cusnumber = json_body.getString("code");//客户-供应商编号
|
||||||
|
}
|
||||||
|
compnum = json_body.getString("companynum");//公司编号
|
||||||
|
if(EsbUtils.isEmpty(compnum) || "0".equals(json_body.getString("companystatus"))){
|
||||||
|
//公司编号为空 或者 公司层面使用状态-禁用的 不处理
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//还原公司id
|
||||||
|
compinfo = BusinessDataServiceHelper.loadSingleFromCache(orgName,"id,number",new QFilter[]{new QFilter("number","=",compnum)});
|
||||||
|
if(compinfo == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(cusnumber.equals(json_body.getString("code"))){
|
||||||
|
//还是同一个客户
|
||||||
|
orgList.add(compinfo.getLong("id"));
|
||||||
|
}else{
|
||||||
|
//另一个客户,先处理上一个客户的分配
|
||||||
|
if(!orgList.isEmpty()){
|
||||||
|
dataList.clear();
|
||||||
|
dataList.add(cusids.get(cusnumber));
|
||||||
|
BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
||||||
|
//处理完成后,清空组织列表
|
||||||
|
orgList.clear();
|
||||||
|
orgList.add(compinfo.getLong("id"));
|
||||||
|
}
|
||||||
|
cusnumber = json_body.getString("code");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//考虑最后一个客户的分配情况
|
||||||
|
if(!orgList.isEmpty()){
|
||||||
|
dataList.clear();
|
||||||
|
dataList.add(cusids.get(cusnumber));
|
||||||
|
BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//处理取消分配
|
||||||
|
public static void handleUnAssign(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
|
JSONObject json_body;
|
||||||
|
String compnum;
|
||||||
|
String cusnumber = "";
|
||||||
|
DynamicObject compinfo;
|
||||||
|
Set<Long> dataList = new HashSet<>();
|
||||||
|
Set<Long> orgList = new HashSet<>();
|
||||||
|
for (int i = 0; i < companysJson.size(); i++) {
|
||||||
|
json_body = companysJson.getJSONObject(i);
|
||||||
|
if(i == 0){
|
||||||
|
//初始化
|
||||||
|
cusnumber = json_body.getString("code");//客户-供应商编号
|
||||||
|
}
|
||||||
|
compnum = json_body.getString("companynum");//公司编号
|
||||||
|
if(EsbUtils.isEmpty(compnum) || "1".equals(json_body.getString("companystatus"))){
|
||||||
|
//公司编号为空 或者 公司层面使用状态-启用的 不处理
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//还原公司id
|
||||||
|
compinfo = BusinessDataServiceHelper.loadSingleFromCache(orgName,"id,number",new QFilter[]{new QFilter("number","=",compnum)});
|
||||||
|
if(compinfo == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(cusnumber.equals(json_body.getString("code"))){
|
||||||
|
//还是同一个客户
|
||||||
|
orgList.add(compinfo.getLong("id"));
|
||||||
|
}else{
|
||||||
|
//另一个客户,先处理上一个客户的取消分配
|
||||||
|
if(!orgList.isEmpty()){
|
||||||
|
dataList.clear();
|
||||||
|
dataList.add(cusids.get(cusnumber));
|
||||||
|
BaseDataServiceHelper.cancelAssign(entityName,dataList,orgList);
|
||||||
|
//处理完成后,清空组织列表
|
||||||
|
orgList.clear();
|
||||||
|
orgList.add(compinfo.getLong("id"));
|
||||||
|
}
|
||||||
|
cusnumber = json_body.getString("code");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//考虑最后一个客户的取消分配情况
|
||||||
|
if(!orgList.isEmpty()){
|
||||||
|
dataList.clear();
|
||||||
|
dataList.add(cusids.get(cusnumber));
|
||||||
|
BaseDataServiceHelper.cancelAssign(entityName,dataList,orgList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getDateString(Date billDate){
|
public static String getDateString(Date billDate){
|
||||||
//将传入的日期类型格式化为字符串,如果传入日期为空,则返回当前时间
|
//将传入的日期类型格式化为字符串,如果传入日期为空,则返回当前时间
|
||||||
//创建一个SimpleDateFormat对象,定义目标日期格式
|
//创建一个SimpleDateFormat对象,定义目标日期格式
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.drew.lang.annotations.NotNull;
|
||||||
import kd.bos.api.client.ApiResult;
|
import kd.bos.api.client.ApiResult;
|
||||||
import kd.bos.context.RequestContext;
|
import kd.bos.context.RequestContext;
|
||||||
import kd.bos.dataentity.entity.DynamicObject;
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
import kd.bos.logging.Log;
|
import kd.bos.logging.Log;
|
||||||
import kd.bos.logging.LogFactory;
|
import kd.bos.logging.LogFactory;
|
||||||
import kd.bos.openapi.common.custom.annotation.ApiController;
|
import kd.bos.openapi.common.custom.annotation.ApiController;
|
||||||
|
|
@ -16,7 +17,6 @@ import kd.bos.openapi.common.custom.annotation.ApiRequestBody;
|
||||||
import kd.bos.openapi.common.result.CustomApiResult;
|
import kd.bos.openapi.common.result.CustomApiResult;
|
||||||
import kd.bos.orm.query.QFilter;
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
import kd.bos.servicehelper.operation.DeleteServiceHelper;
|
|
||||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
||||||
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||||
|
|
@ -24,6 +24,8 @@ import shjh.jhzj7.fi.fi.webapi.model.CustomerModel;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@ApiController(value = "CustomerControler",desc = "客户接口,自定义插件")
|
@ApiController(value = "CustomerControler",desc = "客户接口,自定义插件")
|
||||||
public class CustomerControler {
|
public class CustomerControler {
|
||||||
|
|
@ -31,6 +33,7 @@ public class CustomerControler {
|
||||||
|
|
||||||
private static final String cusTypeName = "bd_customergroup";//系统库 表名 t_bd_customergroup
|
private static final String cusTypeName = "bd_customergroup";//系统库 表名 t_bd_customergroup
|
||||||
private static final String gdName = "bd_customergroupdetail";//系统库 客户分组 表名 t_bd_customergroupdetail
|
private static final String gdName = "bd_customergroupdetail";//系统库 客户分组 表名 t_bd_customergroupdetail
|
||||||
|
private static final String bebankName = "bd_bebank";//系统库 行名行号 表名 t_bd_bebank
|
||||||
private static final Log log = LogFactory.getLog(CustomerControler.class);
|
private static final Log log = LogFactory.getLog(CustomerControler.class);
|
||||||
private static final String apimenthod = "/customer_sync";
|
private static final String apimenthod = "/customer_sync";
|
||||||
|
|
||||||
|
|
@ -41,7 +44,7 @@ public class CustomerControler {
|
||||||
@ApiPostMapping(value = apimenthod, desc = "客户接口")
|
@ApiPostMapping(value = apimenthod, desc = "客户接口")
|
||||||
public CustomApiResult<ApiResult> customer_sync (@NotNull @Valid @ApiRequestBody(value="入参json格式") CustomerModel bizParam) {
|
public CustomApiResult<ApiResult> customer_sync (@NotNull @Valid @ApiRequestBody(value="入参json格式") CustomerModel bizParam) {
|
||||||
|
|
||||||
JSONObject json_obj = null;
|
JSONObject json_obj;
|
||||||
try{
|
try{
|
||||||
//解析入参,如果格式不正确,日志记录,并反馈esb
|
//解析入参,如果格式不正确,日志记录,并反馈esb
|
||||||
json_obj = (JSONObject) JSON.toJSON(bizParam);
|
json_obj = (JSONObject) JSON.toJSON(bizParam);
|
||||||
|
|
@ -53,7 +56,10 @@ public class CustomerControler {
|
||||||
}
|
}
|
||||||
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
||||||
JSONObject itemInfo;//返回值明细对象
|
JSONObject itemInfo;//返回值明细对象
|
||||||
JSONArray detailsJson = json_obj.getJSONArray("items");
|
JSONArray detailsJson = json_obj.getJSONArray("items");//客户基本信息
|
||||||
|
JSONArray banksJson = json_obj.getJSONArray("banks");//客户银行
|
||||||
|
JSONArray companysJson = json_obj.getJSONArray("companys");//客户所属公司
|
||||||
|
JSONArray customerfivesJson = json_obj.getJSONArray("customerfives");//客户组5
|
||||||
String cusnumber;
|
String cusnumber;
|
||||||
String cusname;
|
String cusname;
|
||||||
String taxno;
|
String taxno;
|
||||||
|
|
@ -64,6 +70,7 @@ public class CustomerControler {
|
||||||
JSONObject json_body;
|
JSONObject json_body;
|
||||||
Long currentSupId;
|
Long currentSupId;
|
||||||
DynamicObject suppliergroupdetail;
|
DynamicObject suppliergroupdetail;
|
||||||
|
Map<String, Long> cusids = new HashMap<>();//客户编号和ID对应关系
|
||||||
|
|
||||||
for (int i = 0; i < detailsJson.size(); i++) {
|
for (int i = 0; i < detailsJson.size(); i++) {
|
||||||
json_body = detailsJson.getJSONObject(i);
|
json_body = detailsJson.getJSONObject(i);
|
||||||
|
|
@ -72,7 +79,7 @@ public class CustomerControler {
|
||||||
taxno = json_body.getString("taxno");
|
taxno = json_body.getString("taxno");
|
||||||
type = json_body.getString("type");
|
type = json_body.getString("type");
|
||||||
|
|
||||||
if(EsbUtils.isEmpty(cusnumber) || EsbUtils.isEmpty(cusname) || EsbUtils.isEmpty(taxno) || EsbUtils.isEmpty(type)){
|
if(EsbUtils.isEmpty(cusnumber) || EsbUtils.isEmpty(cusname) || EsbUtils.isEmpty(type)){
|
||||||
log.error(String.format("客户接口入参为空异常:%s", json_body.toJSONString()));
|
log.error(String.format("客户接口入参为空异常:%s", json_body.toJSONString()));
|
||||||
itemInfo = new JSONObject();
|
itemInfo = new JSONObject();
|
||||||
itemInfo.put("code",cusnumber);
|
itemInfo.put("code",cusnumber);
|
||||||
|
|
@ -80,17 +87,18 @@ public class CustomerControler {
|
||||||
itemsJson.add(itemInfo);
|
itemsJson.add(itemInfo);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
custype = BusinessDataServiceHelper.loadSingleFromCache(cusTypeName,"id,number",new QFilter[]{new QFilter("number","=",type)});
|
|
||||||
if(custype == null){
|
|
||||||
log.error(String.format("客户分类未匹配:%s", json_body.toJSONString()));
|
|
||||||
itemInfo = new JSONObject();
|
|
||||||
itemInfo.put("code",cusnumber);
|
|
||||||
itemInfo.put("error","客户分类未匹配");
|
|
||||||
itemsJson.add(itemInfo);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
currentCus = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",cusnumber)});
|
currentCus = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",cusnumber)});
|
||||||
if(currentCus == null){
|
if(currentCus == null){
|
||||||
|
//判断客户分类
|
||||||
|
custype = BusinessDataServiceHelper.loadSingleFromCache(cusTypeName,"id,number",new QFilter[]{new QFilter("number","=",type)});
|
||||||
|
if(custype == null){
|
||||||
|
log.error(String.format("客户分类未匹配:%s", json_body.toJSONString()));
|
||||||
|
itemInfo = new JSONObject();
|
||||||
|
itemInfo.put("code",cusnumber);
|
||||||
|
itemInfo.put("error","客户分类未匹配");
|
||||||
|
itemsJson.add(itemInfo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//根据编号找不到客户,则新增
|
//根据编号找不到客户,则新增
|
||||||
currentCus = BusinessDataServiceHelper.newDynamicObject(entityName);
|
currentCus = BusinessDataServiceHelper.newDynamicObject(entityName);
|
||||||
currentCus.set("number",cusnumber);
|
currentCus.set("number",cusnumber);
|
||||||
|
|
@ -103,27 +111,44 @@ public class CustomerControler {
|
||||||
currentCus.set("bizfunction",",1,2,3,4,");//业务职能 默认全选
|
currentCus.set("bizfunction",",1,2,3,4,");//业务职能 默认全选
|
||||||
currentCus.set("createorg", JhzjUtils.GROUPID);//创建组织 默认为集团
|
currentCus.set("createorg", JhzjUtils.GROUPID);//创建组织 默认为集团
|
||||||
currentCus.set("org", JhzjUtils.GROUPID);//管理组织 默认为集团
|
currentCus.set("org", JhzjUtils.GROUPID);//管理组织 默认为集团
|
||||||
currentCus.set("ctrlstrategy","1");//控制策略 默认逐级分配
|
currentCus.set("ctrlstrategy","1");//控制策略 默认逐级分配1 自由分配2
|
||||||
currentCus.set("group",custype.getLong("id"));//客户分组
|
currentCus.set("group",custype.getLong("id"));//客户分组
|
||||||
currentCus.set("bitindex",1);//位图
|
currentCus.set("bitindex",1);//位图
|
||||||
currentCus.set("customerstatus",EsbUtils.CUSTOMERSTATUS);//客户状态
|
currentCus.set("customerstatus",EsbUtils.CUSTOMERSTATUS);//客户状态
|
||||||
|
currentCus.set("name",cusname);//客户名称
|
||||||
|
currentCus.set("tx_register_no",taxno);//税务登记号
|
||||||
|
currentCus.set("societycreditcode",taxno);//统一社会信用代码
|
||||||
|
currentCus.set("linkman",json_body.getString("contacts"));//联系人
|
||||||
|
currentCus.set("bizpartner_phone",json_body.getString("telnum"));//联系电话
|
||||||
|
//处理银行-新增-员工类客户不需要处理
|
||||||
|
if(!"06".equals(type)){
|
||||||
|
handleBank(banksJson,currentCus.getDynamicObjectCollection("entry_bank"),cusnumber);
|
||||||
|
}
|
||||||
|
currentSupId = ((DynamicObject) SaveServiceHelper.save(new DynamicObject[]{currentCus})[0]).getLong("id");
|
||||||
|
//处理分类
|
||||||
|
suppliergroupdetail = BusinessDataServiceHelper.newDynamicObject(gdName);
|
||||||
|
suppliergroupdetail.set("createorg",JhzjUtils.GROUPID);//创建组织
|
||||||
|
suppliergroupdetail.set("standard",EsbUtils.CUSTOMERSTAND);//客户分类标准
|
||||||
|
suppliergroupdetail.set("group",custype.getLong("id"));//具体分类
|
||||||
|
suppliergroupdetail.set("customer",currentSupId);//客户
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{suppliergroupdetail});
|
||||||
|
//保存成功后,处理masterid字段,不然不能进行分配动作
|
||||||
|
}else{
|
||||||
|
currentSupId = currentCus.getLong("id");
|
||||||
|
currentCus.set("masterid",currentSupId);
|
||||||
|
currentCus.set("name",cusname);//客户名称
|
||||||
|
currentCus.set("tx_register_no",taxno);//税务登记号
|
||||||
|
currentCus.set("societycreditcode",taxno);//统一社会信用代码
|
||||||
|
currentCus.set("linkman",json_body.getString("contacts"));//联系人
|
||||||
|
currentCus.set("bizpartner_phone",json_body.getString("telnum"));//联系电话
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{currentCus});
|
||||||
}
|
}
|
||||||
currentCus.set("name",cusname);//客户名称
|
cusids.put(cusnumber,currentSupId);
|
||||||
currentCus.set("tx_register_no",taxno);//税务登记号
|
|
||||||
currentCus.set("societycreditcode",taxno);//统一社会信用代码
|
|
||||||
currentCus.set("linkman",json_body.getString("contacts"));//联系人
|
|
||||||
currentCus.set("bizpartner_phone",json_body.getString("telnum"));//联系电话
|
|
||||||
|
|
||||||
currentSupId = ((DynamicObject) SaveServiceHelper.save(new DynamicObject[]{currentCus})[0]).getLong("id");
|
|
||||||
//处理分类
|
|
||||||
DeleteServiceHelper.delete(gdName,new QFilter[]{new QFilter("customer","=",currentSupId)});
|
|
||||||
suppliergroupdetail = BusinessDataServiceHelper.newDynamicObject(gdName);
|
|
||||||
suppliergroupdetail.set("createorg",JhzjUtils.GROUPID);//创建组织
|
|
||||||
suppliergroupdetail.set("standard",EsbUtils.CUSTOMERSTAND);//客户分类标准
|
|
||||||
suppliergroupdetail.set("group",custype.getLong("id"));//具体分类
|
|
||||||
suppliergroupdetail.set("customer",currentSupId);//客户
|
|
||||||
SaveServiceHelper.save(new DynamicObject[]{suppliergroupdetail});
|
|
||||||
}
|
}
|
||||||
|
//处理客户分配
|
||||||
|
EsbUtils.handleAssign(companysJson, cusids, entityName);
|
||||||
|
//处理客户取消分配
|
||||||
|
EsbUtils.handleUnAssign(companysJson, cusids, entityName);
|
||||||
|
|
||||||
if(itemsJson.isEmpty()){
|
if(itemsJson.isEmpty()){
|
||||||
EsbUtils.saveLog(apimenthod,"ESB",json_obj.toString(),null,true,"API");
|
EsbUtils.saveLog(apimenthod,"ESB",json_obj.toString(),null,true,"API");
|
||||||
|
|
@ -133,4 +158,28 @@ public class CustomerControler {
|
||||||
return CustomApiResult.fail("400","接口处理异常"+itemsJson.toJSONString());
|
return CustomApiResult.fail("400","接口处理异常"+itemsJson.toJSONString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleBank(JSONArray banksJson,DynamicObjectCollection doc_bank,String cusnumber){
|
||||||
|
JSONObject json_body;
|
||||||
|
DynamicObject bankinfo;
|
||||||
|
DynamicObject bebankinfo;
|
||||||
|
for (int i = 0; i < banksJson.size(); i++) {
|
||||||
|
json_body = banksJson.getJSONObject(i);
|
||||||
|
if(cusnumber.equals(json_body.getString("code"))){
|
||||||
|
bankinfo = doc_bank.addNew();
|
||||||
|
bankinfo.set("bankaccount",json_body.getString("banknumber"));//银行账号
|
||||||
|
bankinfo.set("accountname",json_body.getString("acctname"));//账户名称
|
||||||
|
//根据详细分机银行 查找对应的行名行号
|
||||||
|
bebankinfo = BusinessDataServiceHelper.loadSingleFromCache(bebankName,"id,name",new QFilter[]{new QFilter("name","=",json_body.getString("bankname"))});
|
||||||
|
if(bebankinfo != null){
|
||||||
|
bankinfo.set("bank",bebankinfo.getLong("id"));//开户银行-行名行号 根据入参查找
|
||||||
|
}
|
||||||
|
bankinfo.set("currency", JhzjUtils.CNY);//币别 默认人民币
|
||||||
|
// bankinfo.set("isdefault_bank",1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!doc_bank.isEmpty()){
|
||||||
|
doc_bank.get(0).set("isdefault_bank",1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.drew.lang.annotations.NotNull;
|
import com.drew.lang.annotations.NotNull;
|
||||||
import kd.bos.api.client.ApiResult;
|
import kd.bos.api.client.ApiResult;
|
||||||
import kd.bos.dataentity.entity.DynamicObject;
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
import kd.bos.logging.Log;
|
import kd.bos.logging.Log;
|
||||||
import kd.bos.logging.LogFactory;
|
import kd.bos.logging.LogFactory;
|
||||||
import kd.bos.openapi.common.custom.annotation.ApiController;
|
import kd.bos.openapi.common.custom.annotation.ApiController;
|
||||||
|
|
@ -15,9 +16,12 @@ import kd.bos.openapi.common.custom.annotation.ApiRequestBody;
|
||||||
import kd.bos.openapi.common.result.CustomApiResult;
|
import kd.bos.openapi.common.result.CustomApiResult;
|
||||||
import kd.bos.orm.query.QFilter;
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.permission.model.UserParam;
|
import kd.bos.permission.model.UserParam;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
import kd.bos.servicehelper.QueryServiceHelper;
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
||||||
|
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||||
import shjh.jhzj7.fi.fi.webapi.model.PersonModel;
|
import shjh.jhzj7.fi.fi.webapi.model.PersonModel;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
@ -32,6 +36,9 @@ public class PersonControler implements Serializable {
|
||||||
private static final String entityName = "bos_user";//系统库 表名 t_sec_user
|
private static final String entityName = "bos_user";//系统库 表名 t_sec_user
|
||||||
private static final String orgName = "bos_org";//系统库 表名 t_org_org
|
private static final String orgName = "bos_org";//系统库 表名 t_org_org
|
||||||
private static final String ccName = "bos_costcenter";//系统库 表名 t_bas_costcenter
|
private static final String ccName = "bos_costcenter";//系统库 表名 t_bas_costcenter
|
||||||
|
|
||||||
|
private static final String cusEntityName = "bd_customer";//系统库 表名 T_BD_Customer
|
||||||
|
private static final String bebankName = "bd_bebank";//系统库 行名行号 表名 t_bd_bebank
|
||||||
private static final Log log = LogFactory.getLog(PersonControler.class);
|
private static final Log log = LogFactory.getLog(PersonControler.class);
|
||||||
private static final String apimenthod = "/person_sync";
|
private static final String apimenthod = "/person_sync";
|
||||||
|
|
||||||
|
|
@ -90,7 +97,7 @@ public class PersonControler implements Serializable {
|
||||||
for (int i = 0; i < detailsJson.size(); i++) {
|
for (int i = 0; i < detailsJson.size(); i++) {
|
||||||
json_body = detailsJson.getJSONObject(i);
|
json_body = detailsJson.getJSONObject(i);
|
||||||
number = json_body.getString("code");//工号,作为唯一值
|
number = json_body.getString("code");//工号,作为唯一值
|
||||||
name = json_body.getString("hrisname");
|
name = json_body.getString("hrisName");
|
||||||
email = json_body.getString("email");
|
email = json_body.getString("email");
|
||||||
phone = json_body.getString("phone1");
|
phone = json_body.getString("phone1");
|
||||||
deptid = json_body.getString("keyDeptDoc");//部门编号
|
deptid = json_body.getString("keyDeptDoc");//部门编号
|
||||||
|
|
@ -192,18 +199,18 @@ public class PersonControler implements Serializable {
|
||||||
UserServiceHelper.add(addList);
|
UserServiceHelper.add(addList);
|
||||||
//判断执行结果
|
//判断执行结果
|
||||||
for (UserParam result : addList) {
|
for (UserParam result : addList) {
|
||||||
itemInfo = new JSONObject();
|
|
||||||
itemInfo.put("code",result.getDataMap().get("number"));
|
|
||||||
itemsJson.add(itemInfo);
|
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
handleResult = String.format("人员新增异常:%s", result.getMsg());
|
handleResult = String.format("人员新增异常:%s", result.getMsg());
|
||||||
log.error(handleResult);
|
log.error(handleResult);
|
||||||
|
itemInfo = new JSONObject();
|
||||||
|
itemInfo.put("code",result.getDataMap().get("number"));
|
||||||
itemInfo.put("error",handleResult);
|
itemInfo.put("error",handleResult);
|
||||||
|
itemsJson.add(itemInfo);
|
||||||
}else{
|
}else{
|
||||||
// itemInfo.put("status","1");
|
// itemInfo.put("status","1");
|
||||||
// itemInfo.put("message","");
|
// itemInfo.put("message","");
|
||||||
//更新人员对应客户的银行信息
|
//更新人员对应客户的银行信息
|
||||||
|
handlePersonForCustomer(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -212,18 +219,18 @@ public class PersonControler implements Serializable {
|
||||||
UserServiceHelper.update(updateList);
|
UserServiceHelper.update(updateList);
|
||||||
//判断执行结果
|
//判断执行结果
|
||||||
for (UserParam result : updateList) {
|
for (UserParam result : updateList) {
|
||||||
itemInfo = new JSONObject();
|
|
||||||
itemInfo.put("code",result.getDataMap().get("number"));
|
|
||||||
itemsJson.add(itemInfo);
|
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
handleResult = String.format("人员修改异常:%s", result.getMsg());
|
handleResult = String.format("人员修改异常:%s", result.getMsg());
|
||||||
log.error(handleResult);
|
log.error(handleResult);
|
||||||
|
itemInfo = new JSONObject();
|
||||||
|
itemInfo.put("code",result.getDataMap().get("number"));
|
||||||
itemInfo.put("error",handleResult);
|
itemInfo.put("error",handleResult);
|
||||||
|
itemsJson.add(itemInfo);
|
||||||
}else{
|
}else{
|
||||||
// itemInfo.put("status","1");
|
// itemInfo.put("status","1");
|
||||||
// itemInfo.put("message","");
|
// itemInfo.put("message","");
|
||||||
//更新人员对应客户的银行信息
|
//更新人员对应客户的银行信息
|
||||||
|
handlePersonForCustomer(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,4 +247,33 @@ public class PersonControler implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handlePersonForCustomer(UserParam ups){
|
||||||
|
String cusnumber = (String) ups.getDataMap().get("number");//客户编号-即是 人员的编号
|
||||||
|
DynamicObject currentCus = BusinessDataServiceHelper.loadSingle(cusEntityName,new QFilter[]{new QFilter("number","=",cusnumber)});
|
||||||
|
if(currentCus != null){
|
||||||
|
String cusname = (String) ups.getDataMap().get("name");//姓名
|
||||||
|
String skyh = (String) ups.getDataMap().get("shjh_skyh");//收款银行
|
||||||
|
String xxyh = (String) ups.getDataMap().get("shjh_xxyh");//详细分机银行
|
||||||
|
String acctnum = (String) ups.getDataMap().get("shjh_acctnum");//收款账号
|
||||||
|
DynamicObjectCollection doc_bank = currentCus.getDynamicObjectCollection("entry_bank");
|
||||||
|
DynamicObject bankinfo;
|
||||||
|
if(doc_bank.isEmpty()){
|
||||||
|
bankinfo = doc_bank.addNew();
|
||||||
|
}else{
|
||||||
|
bankinfo = doc_bank.get(0);
|
||||||
|
}
|
||||||
|
bankinfo.set("bankaccount",acctnum);//银行账号
|
||||||
|
bankinfo.set("accountname",cusname);//账户名称
|
||||||
|
//根据详细分机银行 查找对应的行名行号
|
||||||
|
DynamicObject bebankinfo = BusinessDataServiceHelper.loadSingleFromCache(bebankName,"id,name",new QFilter[]{new QFilter("name","=",xxyh)});
|
||||||
|
if(bebankinfo != null){
|
||||||
|
bankinfo.set("bank",bebankinfo.getLong("id"));//开户银行-行名行号 根据入参查找
|
||||||
|
}
|
||||||
|
bankinfo.set("currency", JhzjUtils.CNY);//币别 默认人民币
|
||||||
|
bankinfo.set("isdefault_bank",1);
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{currentCus});
|
||||||
|
}
|
||||||
|
//客户还未生成,需要在客户生成时,从人员处获取银行账号
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import kd.bos.openapi.common.custom.annotation.ApiRequestBody;
|
||||||
import kd.bos.openapi.common.result.CustomApiResult;
|
import kd.bos.openapi.common.result.CustomApiResult;
|
||||||
import kd.bos.orm.query.QFilter;
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
|
|
||||||
import kd.bos.servicehelper.operation.DeleteServiceHelper;
|
import kd.bos.servicehelper.operation.DeleteServiceHelper;
|
||||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
import shjh.jhzj7.fi.fi.utils.EsbUtils;
|
||||||
|
|
@ -25,9 +24,7 @@ import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||||
import shjh.jhzj7.fi.fi.webapi.model.SupplierModel;
|
import shjh.jhzj7.fi.fi.webapi.model.SupplierModel;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ApiController(value = "SupplierControler",desc = "供应商接口,自定义插件")
|
@ApiController(value = "SupplierControler",desc = "供应商接口,自定义插件")
|
||||||
public class SupplierControler {
|
public class SupplierControler {
|
||||||
|
|
@ -60,6 +57,8 @@ public class SupplierControler {
|
||||||
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
||||||
JSONObject itemInfo;//返回值明细对象
|
JSONObject itemInfo;//返回值明细对象
|
||||||
JSONArray detailsJson = json_obj.getJSONArray("items");
|
JSONArray detailsJson = json_obj.getJSONArray("items");
|
||||||
|
JSONArray banksJson = json_obj.getJSONArray("banks");//供应商银行
|
||||||
|
JSONArray companysJson = json_obj.getJSONArray("companys");//供应商所属公司
|
||||||
String supnumber;
|
String supnumber;
|
||||||
String supname;
|
String supname;
|
||||||
String taxno;
|
String taxno;
|
||||||
|
|
@ -67,18 +66,16 @@ public class SupplierControler {
|
||||||
String bankcode;
|
String bankcode;
|
||||||
DynamicObject currentSup;
|
DynamicObject currentSup;
|
||||||
DynamicObject suptype;
|
DynamicObject suptype;
|
||||||
List<Long> dataList = new ArrayList<>();
|
|
||||||
List<Long> orgList = new ArrayList<>();
|
|
||||||
JSONObject json_body;
|
JSONObject json_body;
|
||||||
// DynamicObjectCollection doc_type;
|
// DynamicObjectCollection doc_type;
|
||||||
DynamicObjectCollection doc_bank;
|
DynamicObjectCollection doc_bank;
|
||||||
DynamicObject bankinfo;
|
DynamicObject bankinfo;
|
||||||
DynamicObject bebankinfo;
|
DynamicObject bebankinfo;
|
||||||
JSONArray detailsBankJson;
|
|
||||||
JSONObject json_bank;
|
JSONObject json_bank;
|
||||||
Long currentSupId;
|
Long currentSupId;
|
||||||
DynamicObject suppliergroupdetail;
|
DynamicObject suppliergroupdetail;
|
||||||
DynamicObject parterInfo;
|
// DynamicObject parterInfo;
|
||||||
|
Map<String, Long> cusids = new HashMap<>();//供应商编号和ID对应关系
|
||||||
for (int i = 0; i < detailsJson.size(); i++) {
|
for (int i = 0; i < detailsJson.size(); i++) {
|
||||||
json_body = detailsJson.getJSONObject(i);
|
json_body = detailsJson.getJSONObject(i);
|
||||||
supnumber = json_body.getString("code");
|
supnumber = json_body.getString("code");
|
||||||
|
|
@ -137,9 +134,11 @@ public class SupplierControler {
|
||||||
//处理银行信息-分表
|
//处理银行信息-分表
|
||||||
doc_bank = currentSup.getDynamicObjectCollection("entry_bank");
|
doc_bank = currentSup.getDynamicObjectCollection("entry_bank");
|
||||||
doc_bank.clear();
|
doc_bank.clear();
|
||||||
detailsBankJson = json_body.getJSONArray("banks");
|
for (int j = 0; j < banksJson.size(); j++) {
|
||||||
for (int j = 0; j < detailsBankJson.size(); j++) {
|
json_bank = banksJson.getJSONObject(j);
|
||||||
json_bank = detailsBankJson.getJSONObject(j);
|
if(!supnumber.equals(json_bank.getString("code"))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
bankcode = json_bank.getString("bankcode");
|
bankcode = json_bank.getString("bankcode");
|
||||||
if(EsbUtils.isEmpty(bankcode)){
|
if(EsbUtils.isEmpty(bankcode)){
|
||||||
log.error(String.format("供应商行名行号为空异常:%s", json_bank.toJSONString()));
|
log.error(String.format("供应商行名行号为空异常:%s", json_bank.toJSONString()));
|
||||||
|
|
@ -169,11 +168,8 @@ public class SupplierControler {
|
||||||
bankinfo.set("isdefault_bank",1);
|
bankinfo.set("isdefault_bank",1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//处理所属公司-分表
|
|
||||||
dataList.clear();
|
|
||||||
//保存供应商
|
//保存供应商
|
||||||
currentSupId = ((DynamicObject)SaveServiceHelper.save(new DynamicObject[]{currentSup})[0]).getLong("id");
|
currentSupId = ((DynamicObject)SaveServiceHelper.save(new DynamicObject[]{currentSup})[0]).getLong("id");
|
||||||
// OperationServiceHelper.executeOperate("save",entityName,new DynamicObject[]{currentSup}, OperateOption.create());
|
|
||||||
//处理分类
|
//处理分类
|
||||||
DeleteServiceHelper.delete(gdName,new QFilter[]{new QFilter("supplier","=",currentSupId)});
|
DeleteServiceHelper.delete(gdName,new QFilter[]{new QFilter("supplier","=",currentSupId)});
|
||||||
suppliergroupdetail = BusinessDataServiceHelper.newDynamicObject(gdName);
|
suppliergroupdetail = BusinessDataServiceHelper.newDynamicObject(gdName);
|
||||||
|
|
@ -182,10 +178,7 @@ public class SupplierControler {
|
||||||
suppliergroupdetail.set("group",suptype.getLong("id"));//具体分类
|
suppliergroupdetail.set("group",suptype.getLong("id"));//具体分类
|
||||||
suppliergroupdetail.set("supplier",currentSupId);//供应商
|
suppliergroupdetail.set("supplier",currentSupId);//供应商
|
||||||
SaveServiceHelper.save(new DynamicObject[]{suppliergroupdetail});
|
SaveServiceHelper.save(new DynamicObject[]{suppliergroupdetail});
|
||||||
// dataList.add(currentSupId);
|
cusids.put(supnumber,currentSupId);
|
||||||
// orgList.clear();
|
|
||||||
// orgList.add(2116792428491973632l);//C005
|
|
||||||
// orgList.add(2116753963226241024l);//C001
|
|
||||||
//处理商务伙伴,先判断是否已经生成了伙伴,没有则新增一个伙伴
|
//处理商务伙伴,先判断是否已经生成了伙伴,没有则新增一个伙伴
|
||||||
// parterInfo = BusinessDataServiceHelper.loadSingle(parterName,new QFilter[]{new QFilter("number","=",supnumber)});
|
// parterInfo = BusinessDataServiceHelper.loadSingle(parterName,new QFilter[]{new QFilter("number","=",supnumber)});
|
||||||
// if(parterInfo == null){
|
// if(parterInfo == null){
|
||||||
|
|
@ -203,11 +196,13 @@ public class SupplierControler {
|
||||||
// SaveServiceHelper.save(new DynamicObject[]{parterInfo});
|
// SaveServiceHelper.save(new DynamicObject[]{parterInfo});
|
||||||
// //将伙伴的id更新到供应商上面
|
// //将伙伴的id更新到供应商上面
|
||||||
// }
|
// }
|
||||||
//保存成功后处理供应商分配至具体公司,需要注意,如果供应商取消了某个公司,是否会以最新分配为准
|
|
||||||
// BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
|
||||||
//取消分配接口 cancelAssign
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//处理供应商分配
|
||||||
|
EsbUtils.handleAssign(companysJson, cusids, entityName);
|
||||||
|
//处理供应商取消分配
|
||||||
|
EsbUtils.handleUnAssign(companysJson, cusids, entityName);
|
||||||
|
|
||||||
if(itemsJson.isEmpty()){
|
if(itemsJson.isEmpty()){
|
||||||
EsbUtils.saveLog(apimenthod,"ESB",json_obj.toString(),null,true,"API");
|
EsbUtils.saveLog(apimenthod,"ESB",json_obj.toString(),null,true,"API");
|
||||||
return CustomApiResult.success(null);
|
return CustomApiResult.success(null);
|
||||||
|
|
@ -216,4 +211,5 @@ public class SupplierControler {
|
||||||
return CustomApiResult.fail("400","接口处理异常"+itemsJson.toJSONString());
|
return CustomApiResult.fail("400","接口处理异常"+itemsJson.toJSONString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue