客商和科目的分配和反分配优化
This commit is contained in:
parent
5232a4b1ac
commit
b38efbc98f
|
|
@ -40,27 +40,8 @@ public class CustomerInitOperation extends AbstractOperationServicePlugIn implem
|
||||||
String eok = e.getOperationKey();
|
String eok = e.getOperationKey();
|
||||||
if("customerinit".equals(eok)){
|
if("customerinit".equals(eok)){
|
||||||
DynamicObject[] dos = e.getDataEntities();
|
DynamicObject[] dos = e.getDataEntities();
|
||||||
DynamicObject pzinfo = BusinessDataServiceHelper.loadSingle(dos[0].getPkValue(), dos[0].getDataEntityType().getName());
|
|
||||||
JSONObject json_obj;
|
JSONObject json_obj;
|
||||||
try{
|
|
||||||
//解析入参,如果格式不正确,日志记录,并反馈esb
|
|
||||||
json_obj = JSONObject.parseObject(pzinfo.getString("shjh_inputs_tag"));
|
|
||||||
}catch (JSONException e1) {
|
|
||||||
String jsonResult = String.format("客户接口入参异常:%s", e1.getMessage());
|
|
||||||
log.error(jsonResult);
|
|
||||||
addErrorInfo(pzinfo,"接口入参异常"+jsonResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
|
||||||
JSONObject itemInfo;//返回值明细对象
|
JSONObject itemInfo;//返回值明细对象
|
||||||
JSONArray detailsJson = json_obj.getJSONArray("items");//客户基本信息
|
|
||||||
if(detailsJson == null){
|
|
||||||
addErrorInfo(pzinfo,"未识别到items参数");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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;
|
||||||
|
|
@ -70,7 +51,27 @@ public class CustomerInitOperation extends AbstractOperationServicePlugIn implem
|
||||||
JSONObject json_body;
|
JSONObject json_body;
|
||||||
Long currentSupId;
|
Long currentSupId;
|
||||||
DynamicObject custgroupdetail;
|
DynamicObject custgroupdetail;
|
||||||
|
for (DynamicObject pzinfo : dos) {
|
||||||
|
pzinfo = BusinessDataServiceHelper.loadSingle(pzinfo.getPkValue(), pzinfo.getDataEntityType().getName());
|
||||||
|
try{
|
||||||
|
//解析入参,如果格式不正确,日志记录,并反馈esb
|
||||||
|
json_obj = JSONObject.parseObject(pzinfo.getString("shjh_inputs_tag"));
|
||||||
|
}catch (JSONException e1) {
|
||||||
|
String jsonResult = String.format("客户接口入参异常:%s", e1.getMessage());
|
||||||
|
log.error(jsonResult);
|
||||||
|
addErrorInfo(pzinfo,"接口入参异常"+jsonResult);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray detailsJson = json_obj.getJSONArray("items");//客户基本信息
|
||||||
|
if(detailsJson == null){
|
||||||
|
addErrorInfo(pzinfo,"未识别到items参数");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray banksJson = json_obj.getJSONArray("banks");//客户银行
|
||||||
|
JSONArray companysJson = json_obj.getJSONArray("companys");//客户所属公司
|
||||||
|
JSONArray customerfivesJson = json_obj.getJSONArray("customerfives");//客户组5
|
||||||
Map<String, Long> cusids = new HashMap<>();//客户编号和ID对应关系
|
Map<String, Long> cusids = new HashMap<>();//客户编号和ID对应关系
|
||||||
|
JSONArray itemsJson = new JSONArray();//返回值明细集合
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -172,6 +173,7 @@ public class CustomerInitOperation extends AbstractOperationServicePlugIn implem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleFive(JSONArray customerfivesJson, DynamicObjectCollection doc_five, String cusnumber){
|
private void handleFive(JSONArray customerfivesJson, DynamicObjectCollection doc_five, String cusnumber){
|
||||||
if(customerfivesJson == null){
|
if(customerfivesJson == null){
|
||||||
|
|
|
||||||
|
|
@ -183,10 +183,6 @@ public class SupplierInitOperation extends AbstractOperationServicePlugIn implem
|
||||||
SaveServiceHelper.save(new DynamicObject[]{currentSup});
|
SaveServiceHelper.save(new DynamicObject[]{currentSup});
|
||||||
// OperationServiceHelper.executeOperate("save", entityName, new DynamicObject[]{currentSup}, OperateOption.create());
|
// OperationServiceHelper.executeOperate("save", entityName, new DynamicObject[]{currentSup}, OperateOption.create());
|
||||||
cusids.put(supnumber,currentSup.getLong("id"));
|
cusids.put(supnumber,currentSup.getLong("id"));
|
||||||
//先拿1000个供应商试试
|
|
||||||
if(i == 1000){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理供应商分配
|
//处理供应商分配
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,17 @@ public class EsbUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取当前核算组织的编号和id对应关系
|
||||||
|
public static Map<String, Long> getOrgNumberIds(){
|
||||||
|
Map<String, Long> orgids = new HashMap<>();
|
||||||
|
DynamicObject[] orginfos = BusinessDataServiceHelper.load(orgName,"id,number",
|
||||||
|
new QFilter[]{new QFilter("fisaccounting","=",1)});
|
||||||
|
for (DynamicObject orginfo : orginfos) {
|
||||||
|
orgids.put(orginfo.getString("number"),orginfo.getLong("id"));
|
||||||
|
}
|
||||||
|
return orgids;
|
||||||
|
}
|
||||||
|
|
||||||
//处理科目初始化时的分配
|
//处理科目初始化时的分配
|
||||||
public static void handleAssignInit(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
public static void handleAssignInit(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
if(companysJson == null || cusids.isEmpty()){
|
if(companysJson == null || cusids.isEmpty()){
|
||||||
|
|
@ -52,72 +63,50 @@ public class EsbUtils {
|
||||||
}
|
}
|
||||||
JSONObject json_body;
|
JSONObject json_body;
|
||||||
String compnum;
|
String compnum;
|
||||||
String cusnumber = "";//当前编号
|
String cusnumber;//当前科目编号
|
||||||
String firstnumber = "firstnumber";//初始化编号
|
Long compinfoid;
|
||||||
Long curid;//当前数据id
|
|
||||||
DynamicObject compinfo;
|
|
||||||
List<Long> dataList = new ArrayList<>();
|
List<Long> dataList = new ArrayList<>();
|
||||||
List<Long> orgList = new ArrayList<>();
|
List<Long> orgList = new ArrayList<>();
|
||||||
|
Map<String, Long> orgids = getOrgNumberIds();
|
||||||
|
for (Map.Entry<String,Long> entry : cusids.entrySet()) {
|
||||||
|
orgList.clear();
|
||||||
for (int i = 0; i < companysJson.size(); i++) {
|
for (int i = 0; i < companysJson.size(); i++) {
|
||||||
json_body = companysJson.getJSONObject(i);
|
json_body = companysJson.getJSONObject(i);
|
||||||
cusnumber = json_body.getString("shjh_ccode");//客户-供应商编号
|
cusnumber = json_body.getString("shjh_ccode");//科目编号
|
||||||
compnum = json_body.getString("shjh_companynum");//公司编号
|
compnum = json_body.getString("shjh_companynum");//公司编号
|
||||||
if(EsbUtils.isEmpty(cusnumber) || EsbUtils.isEmpty(compnum) || "0".equals(json_body.getString("shjh_companystatus"))){
|
if(EsbUtils.isEmpty(cusnumber) || EsbUtils.isEmpty(compnum) || "0".equals(json_body.getString("shjh_companystatus"))){
|
||||||
//公司编号为空 或者 公司层面使用状态-禁用的 不处理
|
//公司编号为空 或者 公司层面使用状态-禁用的 不处理
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//还原公司id
|
//还原公司id
|
||||||
compinfo = BusinessDataServiceHelper.loadSingleFromCache(orgName,"id,number",new QFilter[]{new QFilter("number","=",compnum)});
|
compinfoid = orgids.get(compnum);
|
||||||
if(compinfo == null){
|
if(compinfoid == null){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if("firstnumber".equals(firstnumber)){
|
if(cusnumber.equals(entry.getKey())){
|
||||||
//初始化,改变初始化值
|
orgList.add(compinfoid);
|
||||||
firstnumber = cusnumber;
|
|
||||||
orgList.add(compinfo.getLong("id"));
|
|
||||||
}else if(firstnumber.equals(cusnumber)){
|
|
||||||
//还是同一个客户
|
|
||||||
orgList.add(compinfo.getLong("id"));
|
|
||||||
}else{
|
|
||||||
//另一个客户,先处理上一个客户的分配
|
|
||||||
if(!orgList.isEmpty()){
|
|
||||||
curid = cusids.get(cusnumber);
|
|
||||||
if(curid == null){
|
|
||||||
//当前编号对应的id不存在,即上一个数据没有保存成功 不处理分配,上一个组织数据清空,增加当前组织
|
|
||||||
orgList.clear();
|
|
||||||
orgList.add(compinfo.getLong("id"));
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!orgList.isEmpty()) {
|
||||||
dataList.clear();
|
dataList.clear();
|
||||||
dataList.add(curid);
|
dataList.add(entry.getValue());
|
||||||
BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
||||||
//处理完成后,清空组织列表
|
|
||||||
orgList.clear();
|
|
||||||
orgList.add(compinfo.getLong("id"));
|
|
||||||
}
|
}
|
||||||
firstnumber = cusnumber;
|
|
||||||
orgList.add(compinfo.getLong("id"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
curid = cusids.get(cusnumber);
|
|
||||||
//考虑最后一个客户的分配情况
|
|
||||||
if(!orgList.isEmpty() && curid != null){
|
|
||||||
dataList.clear();
|
|
||||||
dataList.add(curid);
|
|
||||||
BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleUnAssignNew(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
public static void handleUnAssignNew(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
|
//处理客商 科目分分配
|
||||||
if(companysJson == null || cusids.isEmpty()){
|
if(companysJson == null || cusids.isEmpty()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String cusnumber;
|
String cusnumber;
|
||||||
String compnum;
|
String compnum;
|
||||||
JSONObject json_body;
|
JSONObject json_body;
|
||||||
DynamicObject compinfo;
|
Long compinfoid;
|
||||||
Set<Long> dataList = new HashSet<>(1);
|
Set<Long> dataList = new HashSet<>(1);
|
||||||
Set<Long> orgList = new HashSet<>();
|
Set<Long> orgList = new HashSet<>();
|
||||||
|
Map<String, Long> orgids = getOrgNumberIds();
|
||||||
for (Map.Entry<String,Long> entry : cusids.entrySet()) {
|
for (Map.Entry<String,Long> entry : cusids.entrySet()) {
|
||||||
orgList.clear();
|
orgList.clear();
|
||||||
for (int i = 0; i < companysJson.size(); i++) {
|
for (int i = 0; i < companysJson.size(); i++) {
|
||||||
|
|
@ -129,33 +118,34 @@ public class EsbUtils {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//还原公司id
|
//还原公司id
|
||||||
compinfo = BusinessDataServiceHelper.loadSingleFromCache(orgName,"id,number",new QFilter[]{new QFilter("number","=",compnum)});
|
compinfoid = orgids.get(compnum);
|
||||||
if(compinfo == null){
|
if(compinfoid == null){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(cusnumber.equals(entry.getKey())){
|
if(cusnumber.equals(entry.getKey())){
|
||||||
orgList.add(compinfo.getLong("id"));
|
orgList.add(compinfoid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!orgList.isEmpty()){
|
if(!orgList.isEmpty()){
|
||||||
dataList.clear();
|
dataList.clear();
|
||||||
dataList.add(entry.getValue());
|
dataList.add(entry.getValue());
|
||||||
// BaseDataServiceHelper.batchAssignWithDetail(entityName,JhzjUtils.GROUPID,dataList,orgList);
|
|
||||||
BaseDataServiceHelper.cancelAssign(entityName,dataList,orgList);
|
BaseDataServiceHelper.cancelAssign(entityName,dataList,orgList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleAssignNew(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
public static void handleAssignNew(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
|
//处理客商 科目分配
|
||||||
if(companysJson == null || cusids.isEmpty()){
|
if(companysJson == null || cusids.isEmpty()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String cusnumber;
|
String cusnumber;
|
||||||
String compnum;
|
String compnum;
|
||||||
JSONObject json_body;
|
JSONObject json_body;
|
||||||
DynamicObject compinfo;
|
Long compinfoid;
|
||||||
List<Long> dataList = new ArrayList<>(1);
|
List<Long> dataList = new ArrayList<>(1);
|
||||||
List<Long> orgList = new ArrayList<>();
|
List<Long> orgList = new ArrayList<>();
|
||||||
|
Map<String, Long> orgids = getOrgNumberIds();
|
||||||
for (Map.Entry<String,Long> entry : cusids.entrySet()) {
|
for (Map.Entry<String,Long> entry : cusids.entrySet()) {
|
||||||
orgList.clear();
|
orgList.clear();
|
||||||
for (int i = 0; i < companysJson.size(); i++) {
|
for (int i = 0; i < companysJson.size(); i++) {
|
||||||
|
|
@ -167,12 +157,12 @@ public class EsbUtils {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//还原公司id
|
//还原公司id
|
||||||
compinfo = BusinessDataServiceHelper.loadSingleFromCache(orgName,"id,number",new QFilter[]{new QFilter("number","=",compnum)});
|
compinfoid = orgids.get(compnum);
|
||||||
if(compinfo == null){
|
if(compinfoid == null){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(cusnumber.equals(entry.getKey())){
|
if(cusnumber.equals(entry.getKey())){
|
||||||
orgList.add(compinfo.getLong("id"));
|
orgList.add(compinfoid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!orgList.isEmpty()){
|
if(!orgList.isEmpty()){
|
||||||
|
|
@ -183,7 +173,7 @@ public class EsbUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理分配
|
//处理分配-方法弃用
|
||||||
public static void handleAssign(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
public static void handleAssign(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
if(companysJson == null || cusids.isEmpty()){
|
if(companysJson == null || cusids.isEmpty()){
|
||||||
return;
|
return;
|
||||||
|
|
@ -246,7 +236,7 @@ public class EsbUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理取消分配
|
//处理取消分配-方法弃用
|
||||||
public static void handleUnAssign(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
public static void handleUnAssign(JSONArray companysJson, Map<String, Long> cusids, String entityName) {
|
||||||
if(companysJson == null || cusids.isEmpty()){
|
if(companysJson == null || cusids.isEmpty()){
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -193,8 +193,8 @@ public class AspAccountControler {
|
||||||
//处理科目在每个公司生成
|
//处理科目在每个公司生成
|
||||||
Map<String, DynamicObject> companyAcctMaps = handleAccountCompany(accountMaps,companysJson);
|
Map<String, DynamicObject> companyAcctMaps = handleAccountCompany(accountMaps,companysJson);
|
||||||
//处理科目分配和反分配
|
//处理科目分配和反分配
|
||||||
EsbUtils.handleAssign(companysJson, acctids, entityName);
|
EsbUtils.handleAssignNew(companysJson, acctids, entityName);
|
||||||
EsbUtils.handleUnAssign(companysJson, acctids, entityName);
|
EsbUtils.handleUnAssignNew(companysJson, acctids, entityName);
|
||||||
//处理每个公司下科目的核算维度和禁用状态
|
//处理每个公司下科目的核算维度和禁用状态
|
||||||
JSONArray asstacttypesJson = json_obj.getJSONArray("asstacttypes");
|
JSONArray asstacttypesJson = json_obj.getJSONArray("asstacttypes");
|
||||||
if(asstacttypesJson != null){
|
if(asstacttypesJson != null){
|
||||||
|
|
|
||||||
|
|
@ -165,9 +165,9 @@ public class CustomerControler {
|
||||||
cusids.put(cusnumber,currentSupId);
|
cusids.put(cusnumber,currentSupId);
|
||||||
}
|
}
|
||||||
//处理客户分配
|
//处理客户分配
|
||||||
EsbUtils.handleAssign(companysJson, cusids, entityName);
|
EsbUtils.handleAssignNew(companysJson, cusids, entityName);
|
||||||
//处理客户取消分配
|
//处理客户取消分配
|
||||||
EsbUtils.handleUnAssign(companysJson, cusids, entityName);
|
EsbUtils.handleUnAssignNew(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");
|
||||||
|
|
|
||||||
|
|
@ -228,9 +228,9 @@ public class SupplierControler {
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理供应商分配
|
//处理供应商分配
|
||||||
EsbUtils.handleAssign(companysJson, cusids, entityName);
|
EsbUtils.handleAssignNew(companysJson, cusids, entityName);
|
||||||
//处理供应商取消分配
|
//处理供应商取消分配
|
||||||
EsbUtils.handleUnAssign(companysJson, cusids, entityName);
|
EsbUtils.handleUnAssignNew(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");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue