0210测试提交

This commit is contained in:
yuxueliang0813 2025-02-10 11:13:02 +08:00
parent c4f594a16f
commit 7524f090de
4 changed files with 153 additions and 229 deletions

View File

@ -26,8 +26,7 @@ public class JHSSOAuthHandler implements ThirdSSOAuthHandler {
//backUrl 系统已构建好回调地址二开无需处理
//实现用户没有登录的时候跳转认证中心的登录地址
//第一步认证中心的登录地址注意拼接参数和回调地址转义,注意正式地址切换
System.getProperty("domain.contextUrl");
// backUrl = "http://172.20.42.104:8881/ierp/auth/callbackTrdSSO.do?tenantNo=jahwa-uatenv&sandboxNo=2102993326188790784";
// backUrl = "http://172.20.42.104:8881/iserp/auth/callbackTrdSSO.do?tenantNo=jahwa-uatenv&sandboxNo=2102993326188790784";
callBackUrl = backUrl;
StringBuffer ssoURL = new StringBuffer();
ssoURL.append(ssologinUrl);
@ -57,7 +56,7 @@ public class JHSSOAuthHandler implements ThirdSSOAuthHandler {
result.setSucess(false);
//将用户的认证凭据传输到认证系统进行认证从而实现对认证凭据进行识别和获取用户信息request包含请求的认证凭据
String numOrName = getWorkerNumberOrUseName(hsrequest);//此逻辑需二开实现
if(numOrName != null){
if(StringUtils.isNotEmpty(numOrName)){
//当前返回类型手机用户名邮箱工号
// result.setUserType(UserProperType.WorkerNumber);
result.setUserType(UserProperType.UserName);

View File

@ -24,7 +24,7 @@ public class TestSupplierListPlugin extends AbstractListPlugin {
break;
}
}
lqs.add(new QFilter("createorg.id","=",2116753963226241024l));
lqs.add(new QFilter("createorg.id","=",2116762463713107968l));
lqs.size();
}

View File

@ -27,6 +27,8 @@ import shjh.jhzj7.fi.fi.webapi.model.AccountModel;
import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ApiController(value = "AspAccountControler",desc = "会计科目接口,自定义插件")
public class AspAccountControler {
@ -35,9 +37,13 @@ public class AspAccountControler {
private static final String acctTypeName = "bd_accounttype";//科目类型
private static final String hswdName = "bd_asstacttype";//系统库 核算维度 表名t_bas_flex_property
private static final String orgName = "bos_org";//业务单元
private static final String bbName = "bd_currency";//币别
private static final Log log = LogFactory.getLog(AspAccountControler.class);
private static final String apimenthod = "/account_sync";
private static final Map<String, DynamicObject> mapObject = new HashMap<>();//公司对象集合
private static final Map<String, DynamicObject> hsxmMaps = new HashMap<>();//核算维度对象集合
/**
* @param bizParam 入参json格式数据
* @return 自定义返回值
@ -57,14 +63,15 @@ public class AspAccountControler {
}
JSONArray itemsJson = new JSONArray();//返回值明细集合
JSONObject itemInfo;//返回值明细对象
JSONArray detailsJson = json_obj.getJSONArray("items");
//根据科目基本信息得到科目编号和JSONObject
Map<String, JSONObject> baseMaps = getBaseMap(json_obj.getJSONArray("items"));
JSONArray companysJson = json_obj.getJSONArray("companys");
String number;//科目编号
String name;//科目名称
// String isleaf;//是否叶子节点
// String level;//层级
// String yefx;//余额方向 借1 -1
// String acctsx;//科目金额类属性 现金银行现金等价物
String hswd;//核算维度 基础资料
String bbhs;//币别核算 不核算外币 核算所有外币 指定核算币别需要指定币别ISO
String acctType;//科目类型 资产负债类 损益类
String descurrencynum;//指定币别编号
@ -72,19 +79,27 @@ public class AspAccountControler {
DynamicObject acctInfo;
DynamicObject acctTypeInfo;
DynamicObject parentAcctInfo;
DynamicObject hswdInfo;
DynamicObject checkitementryInfo;
JSONObject company_body;
JSONObject json_body;
String companynum;
DynamicObjectCollection docbb;
DynamicObject bbInfo;
String bbiso;
Map<String, DynamicObject> accountMaps = new HashMap<>();//将科目编号与对象关联
for (int i = 0; i < detailsJson.size(); i++) {
json_body = detailsJson.getJSONObject(i);
number = json_body.getString("code");
for (int i = 0; i < companysJson.size(); i++) {
company_body = companysJson.getJSONObject(i);
number = company_body.getString("code");
json_body = baseMaps.get(number);
if(json_body == null){
continue;
}
companynum = company_body.getString("companynum");//公司编号
name = json_body.getString("name");
acctType = json_body.getString("type");
hswd = json_body.getString("hswd");
bbhs = json_body.getString("acctcurrency");
descurrencynum = json_body.getString("descurrencynum");
if(EsbUtils.isEmpty(number) || EsbUtils.isEmpty(name) || EsbUtils.isEmpty(acctType) || EsbUtils.isEmpty(bbhs)){
if(EsbUtils.isEmpty(number) || EsbUtils.isEmpty(name) || EsbUtils.isEmpty(acctType) || EsbUtils.isEmpty(bbhs) || EsbUtils.isEmpty(companynum)){
log.error(String.format("会计科目接口入参为空异常:%s", json_body.toJSONString()));
itemInfo = new JSONObject();
itemInfo.put("code",number);
@ -100,56 +115,39 @@ public class AspAccountControler {
itemsJson.add(itemInfo);
continue;
}
//根据科目编号查找科目是否已存在
//根据科目编号和公司编号查找对应科目是否已存在
acctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",number),
new QFilter("createorg.id","=",2116753963226241024l)});
new QFilter("createorg.number","=", companynum)});
// acctInfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",number)});
if(acctInfo != null){
//处理科目更新逻辑此时能修改哪些字段名称 币别核算 核算维度 是否可用
if("0".equals(json_body.getString("status"))){
if("0".equals(company_body.getString("companystatus")) || "0".equals(json_body.getString("status"))){
acctInfo.set("enable", 0);//科目禁用处理
}
// acctInfo.set("ctrlstrategy", "7");
acctInfo.set("pltype", getSY(acctType));
// acctInfo.set("pltype", getSY(acctType));
acctInfo.set("name", name);
acctInfo.set("fullname", name);
acctInfo.set("acctcurrency", bbhs);
// acctInfo.set("useorg", 2116762463713107968l);//核算组织
//如果是指定核算币别
if("descurrency".equals(bbhs)){
//处理具体币别分录数据根据逗号进行分割
DynamicObjectCollection doc = acctInfo.getDynamicObjectCollection("currencyentry");
doc.clear();
docbb = acctInfo.getDynamicObjectCollection("currencyentry");
docbb.clear();
String[] dess = descurrencynum.split(",");
String bbiso;
DynamicObject bbinfo;
for (int j = 0; j < dess.length; j++) {
bbiso = dess[j];
bbinfo = BusinessDataServiceHelper.loadSingleFromCache("bd_currency",new QFilter[]{new QFilter("number","=",bbiso)});
if(bbinfo != null){
doc.addNew().set("currency",bbinfo.getLong("id"));
bbInfo = BusinessDataServiceHelper.loadSingleFromCache(bbName,new QFilter[]{new QFilter("number","=",bbiso)});
if(bbInfo != null){
docbb.addNew().set("currency",bbInfo.getLong("id"));
}
}
}
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
}else{
//不存在做新增 根据实体名称创建动态对象
acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
// acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid上正式时注意此ID
acctInfo.set("accounttable", 2125524820924832768l);//科目表fid上正式时注意此ID
acctInfo.set("number", number);
acctInfo.set("name", name);
//处理父级科目
parentAcctInfo = getParentAcct(number);
acctInfo.set("longnumber", number);
acctInfo.set("fullname", name);
// acctInfo.set("parent", parentAcctInfo.getLong("id"));
//创建组织
// acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
// acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
acctInfo.set("createorg", 2116753963226241024l);//创建组织
acctInfo.set("org", 2116753963226241024l);//管理组织
//科目类型
acctTypeInfo = BusinessDataServiceHelper.loadSingleFromCache(acctTypeName,new QFilter[]{new QFilter("number","=",acctType)});
if(acctTypeInfo != null){
acctInfo.set("accounttype", acctTypeInfo.getLong("id"));
}else{
if(acctTypeInfo == null){
log.error(String.format("科目类型在金蝶中找不到:%s", acctType));
itemInfo = new JSONObject();
itemInfo.put("code",number);
@ -157,44 +155,44 @@ public class AspAccountControler {
itemsJson.add(itemInfo);
continue;
}
//核算维度
if(!EsbUtils.isEmpty(hswd)){
hswdInfo = BusinessDataServiceHelper.loadSingleFromCache(hswdName,new QFilter[]{new QFilter("number","=",hswd)});
if(hswdInfo != null){
checkitementryInfo = acctInfo.getDynamicObjectCollection("checkitementry").addNew();
checkitementryInfo.set("asstactitem",hswdInfo.getLong("id"));
// if(Boolean.valueOf(isleaf)){
// checkitementryInfo.set("isrequire", true);//必录
// checkitementryInfo.set("isdetail", true);//明细
// }else{
// checkitementryInfo.set("isrequire", false);//必录
// checkitementryInfo.set("isdetail", false);//明细
// }
acctInfo.set("isassist", true);//主表的isassist是否包含核算项目为是
}else{
log.error(String.format("核算维度在金蝶中找不到:%s", hswd));
itemInfo = new JSONObject();
itemInfo.put("code",number);
itemInfo.put("error","核算维度在金蝶中找不到");
itemsJson.add(itemInfo);
continue;
}
hsorgInfo = getOrgInfo(companynum);
if(hsorgInfo == null){
log.error(String.format("公司编号在金蝶中未找到对应组织:%s", companynum));
itemInfo = new JSONObject();
itemInfo.put("code",number);
itemInfo.put("error","公司编号在金蝶中未找到对应组织:"+companynum);
itemsJson.add(itemInfo);
continue;
}
//不存在做新增 根据实体名称创建动态对象
acctInfo = BusinessDataServiceHelper.newDynamicObject(entityName);
acctInfo.set("accounttable", EsbUtils.ACCTABLE);//科目表fid上正式时注意此ID
acctInfo.set("number", number);
acctInfo.set("name", name);
//处理父级科目
// parentAcctInfo = getParentAcct(number);
acctInfo.set("longnumber", number);
acctInfo.set("fullname", name);
// acctInfo.set("parent", parentAcctInfo.getLong("id"));
//创建组织
// acctInfo.set("createorg", JhzjUtils.GROUPID);//创建组织
// acctInfo.set("org", JhzjUtils.GROUPID);//管理组织
acctInfo.set("createorg", hsorgInfo.getLong("id"));//创建组织
acctInfo.set("org", hsorgInfo.getLong("id"));//管理组织
//科目类型
acctInfo.set("accounttype", acctTypeInfo.getLong("id"));
//币别核算--外币核算类型
acctInfo.set("acctcurrency", bbhs);//不核算外币nocurrency 指定核算币别descurrency 核算所有币别allcurrency
//如果是指定核算币别
if("descurrency".equals(bbhs)){
//处理具体币别分录数据根据逗号进行分割
DynamicObjectCollection doc = acctInfo.getDynamicObjectCollection("currencyentry");
doc.clear();
docbb = acctInfo.getDynamicObjectCollection("currencyentry");
String[] dess = descurrencynum.split(",");
String bbiso;
DynamicObject bbinfo;
for (int j = 0; j < dess.length; j++) {
bbiso = dess[j];
bbinfo = BusinessDataServiceHelper.loadSingleFromCache(hswdName,new QFilter[]{new QFilter("number","=",bbiso)});
if(bbinfo != null){
doc.addNew().set("currency",bbinfo.getLong("id"));
bbInfo = BusinessDataServiceHelper.loadSingleFromCache(bbName,new QFilter[]{new QFilter("number","=",bbiso)});
if(bbInfo != null){
docbb.addNew().set("currency",bbInfo.getLong("id"));
}
}
}
@ -225,6 +223,59 @@ public class AspAccountControler {
//保存数据直接保存入库不走操作校验
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
}
accountMaps.put(number+companynum,acctInfo);
}
//处理核算维度
JSONArray asstacttypesJson = json_obj.getJSONArray("asstacttypes");
String hsxm;//核算维度名称 基础资料
DynamicObject hsxmInfo;//核算维度对象
DynamicObjectCollection dochswd;
DynamicObject checkitementryInfo = null;
for (int i = 0; i < asstacttypesJson.size(); i++) {
json_body = asstacttypesJson.getJSONObject(i);
hsxm = json_body.getString("asstactname");
if(EsbUtils.isEmpty(hsxm)){
continue;
}
number = json_body.getString("code");
companynum = json_body.getString("companynum");
//根据科目核算维度中的科目编号和公司编号获取对应科目对象不存在的不处理
acctInfo = accountMaps.get(number+companynum);
if(acctInfo == null){
continue;
}
hsxmInfo = getHsxmInfo(hsxm);
if(hsxmInfo == null){
log.error(String.format("核算维度在金蝶中找不到:%s", hsxm));
itemInfo = new JSONObject();
itemInfo.put("code",number);
itemInfo.put("error","核算维度在金蝶中找不到"+hsxm);
itemsJson.add(itemInfo);
continue;
}
//判断当前科目是否存在此核算维度不存在则新增存在则判断是否必录
dochswd = acctInfo.getDynamicObjectCollection("checkitementry");
for (int j = 0; j < dochswd.size(); j++) {
checkitementryInfo = dochswd.get(j);
if(hsxmInfo.getLong("id") == checkitementryInfo.getDynamicObject("asstactitem").getLong("id")){
break;
}
checkitementryInfo = null;
}
if(checkitementryInfo == null){
checkitementryInfo = dochswd.addNew();
checkitementryInfo.set("asstactitem",hsxmInfo.getLong("id"));
checkitementryInfo.set("isdetail", true);//明细
}
if("1".equals(json_body.getString("isneed"))){
checkitementryInfo.set("isrequire", true);//必录
}else{
checkitementryInfo.set("isrequire", false);//必录
}
acctInfo.set("isassist", true);//主表的isassist是否包含核算项目为是
SaveServiceHelper.save(new DynamicObject[]{acctInfo});
accountMaps.put(number+companynum,acctInfo);
}
if(itemsJson.isEmpty()){
@ -236,6 +287,36 @@ public class AspAccountControler {
}
}
private DynamicObject getHsxmInfo(String hsxmname){
//核算维度对象集合
DynamicObject orginfo = hsxmMaps.get(hsxmname);
if(orginfo == null){
orginfo = BusinessDataServiceHelper.loadSingleFromCache(hswdName,new QFilter[]{new QFilter("name","=",hsxmname)});
mapObject.put(hsxmname,orginfo);
}
return orginfo;
}
private DynamicObject getOrgInfo(String companynum){
//公司对象集合
DynamicObject orginfo = mapObject.get(companynum);
if(orginfo == null){
orginfo = BusinessDataServiceHelper.loadSingleFromCache(orgName,new QFilter[]{new QFilter("number","=",companynum)});
mapObject.put(companynum,orginfo);
}
return orginfo;
}
private Map<String, JSONObject> getBaseMap(JSONArray detailsJson){
Map<String, JSONObject> baseMaps = new HashMap<>();
JSONObject json_body;
for (int i = 0; i < detailsJson.size(); i++) {
json_body = detailsJson.getJSONObject(i);
baseMaps.put(json_body.getString("code"),json_body);
}
return baseMaps;
}
private DynamicObject getParentAcct(String number){
//sap科目编号为10位且没有层级关系金蝶按照4-6分两级自行处理
String parentNumber = number.substring(0,4);

View File

@ -1,156 +0,0 @@
package shjh.jhzj7.fi.fi.webapi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.drew.lang.annotations.NotNull;
import kd.bos.api.client.ApiResult;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
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.ApiPostMapping;
import kd.bos.openapi.common.custom.annotation.ApiRequestBody;
import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import shjh.jhzj7.fi.fi.utils.EsbUtils;
import shjh.jhzj7.fi.fi.webapi.model.CostCenterModel;
import javax.validation.Valid;
import java.util.Comparator;
@ApiController(value = "CCControler",desc = "成本中心接口,测试代码,不用提交")
public class CCControler {
private static final String entityName = "bos_costcenter";//系统库 表名 t_bas_costcenter
private static final String orgEntName = "bos_org";//系统库 表名 t_org_org
private static final String apimenthod = "/costcenter_sync";
private static final Log log = LogFactory.getLog(CCControler.class);
/**
* @param bizParam 入参json格式数据
* @return 自定义返回值
*/
@ApiPostMapping(value = apimenthod, desc = "成本中心接口")
public CustomApiResult<ApiResult> costcenter_sync (@NotNull @Valid @ApiRequestBody(value="入参json格式") CostCenterModel bizParam) {
// if(EsbUtils.isEmpty(data)){
// return CustomApiResult.fail("400","接口入参为空");
// }
JSONObject json_obj = null;
try{
//解析入参如果格式不正确日志记录并反馈esb
json_obj = (JSONObject) JSON.toJSON(bizParam);
}catch (JSONException e) {
String jsonResult = String.format("成本中心接口入参异常:%s", e.getMessage());
log.error(jsonResult);
EsbUtils.saveLog(apimenthod,"ESB",bizParam.toString(),jsonResult,false,"API");
return CustomApiResult.fail("400","接口入参异常");
}
// String batchId = json_body.getString("batchId");//批数据的唯一标识
// JSONObject json_result = new JSONObject();//返回值主对象
// json_result.put("batchId",batchId);
JSONArray itemsJson = new JSONArray();//返回值明细集合
JSONObject itemInfo = null;//返回值明细对象
JSONArray detailsJson = json_obj.getJSONArray("items");
//处理入参的排序按照ccLevel正序
detailsJson.sort(Comparator.comparingInt(json -> ((JSONObject) json).getIntValue("ccLevel")));
String orgNumber = null;
String orgName = null;
String ccLevel = null;
String parentCode = null;
String typeNum = null;
String company = null;
DynamicObject parentOrg = null;
DynamicObject currentOrg = null;
DynamicObject companyInfo = null;
JSONObject json_body = null;
for (int i = 0; i < detailsJson.size(); i++) {
json_body = detailsJson.getJSONObject(i);
orgNumber = json_body.getString("code");//成本中心编号
orgName = json_body.getString("ccname");//成本中心名称
ccLevel = json_body.getString("ccLevel");//层级
parentCode = json_body.getString("parentCode");//父级编号
typeNum = json_body.getString("typeNum");//类型编号
company = json_body.getString("company");//所属公司编号
if(EsbUtils.isEmpty(orgNumber) || EsbUtils.isEmpty(orgName) || EsbUtils.isEmpty(typeNum) || EsbUtils.isEmpty(ccLevel) ||
(Integer.parseInt(ccLevel)>1 && EsbUtils.isEmpty(parentCode)) || EsbUtils.isEmpty(company)){
log.error(String.format("成本中心入参为空异常:%s", json_body.toJSONString()));
itemInfo = new JSONObject();
itemInfo.put("code",orgNumber);
itemInfo.put("error","入参值为空");
itemsJson.add(itemInfo);
continue;
}
//处理上级组织
parentOrg = QueryServiceHelper.queryOne(entityName,"id,number,longnumber,fullname",new QFilter[]{new QFilter("number","=",parentCode)});
if(parentOrg == null && Integer.parseInt(ccLevel)>1){
log.error(String.format("根据父级成本中心编号未在金蝶中找到对应组织:%s", parentCode));
itemInfo = new JSONObject();
itemInfo.put("code",orgNumber);
itemInfo.put("error","根据父级成本中心编号未在金蝶中找到对应组织");
itemsJson.add(itemInfo);
continue;
}
currentOrg = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",orgNumber)});
if(currentOrg == null){
//根据编号找不到成本中心则新增
currentOrg = BusinessDataServiceHelper.newDynamicObject(entityName);
currentOrg.set("number",orgNumber);
//处理所属公司
companyInfo = QueryServiceHelper.queryOne(orgEntName,"id,number",new QFilter[]{new QFilter("number","=",company)});
if(companyInfo == null){
log.error(String.format("根据所属公司编号未在金蝶中找到对应公司:%s", company));
itemInfo = new JSONObject();
itemInfo.put("code",orgNumber);
itemInfo.put("error","根据所属公司编号未在金蝶中找到对应公司");
itemsJson.add(itemInfo);
continue;
}
currentOrg.set("accountorg",companyInfo.getLong("id"));
currentOrg.set("addtype","manual");//新增方式默认手工新增
currentOrg.set("status","C");//数据状态
currentOrg.set("creator", RequestContext.get().getCurrUserId());//创建人
currentOrg.set("isleaf",true);//默认为叶子
currentOrg.set("enable",1);//默认可用
}
currentOrg.set("name",orgName);
currentOrg.set("orgduty",typeNum);//类型
currentOrg.set("level",ccLevel);//层级
currentOrg.set("shjh_comids",json_body.getString("other_company"));//跨公司ID
//处理长编号和长名称
currentOrg.set("longnumber",orgNumber);
currentOrg.set("fullname",orgName);
if(parentOrg != null){
currentOrg.set("longnumber",parentOrg.getString("longnumber")+orgNumber);
currentOrg.set("fullname",parentOrg.getString("fullname")+orgName);
currentOrg.set("parent",parentOrg.getLong("id"));//父级
}
//处理禁用组织
if("0".equals(json_body.getString("status"))){
currentOrg.set("enable",0);
}
SaveServiceHelper.save(new DynamicObject[]{currentOrg});
// itemInfo = new JSONObject();
// itemInfo.put("pkId",orgNumber);
// itemInfo.put("status","1");
// itemInfo.put("message","");
// itemsJson.add(itemInfo);
}
//返回最终处理结果,如果上述有单个组织处理失败则总体状态overallStatus是何值
// json_result.put("overallStatus","1");
// json_result.put("items",itemsJson);
if(itemsJson.isEmpty()){
EsbUtils.saveLog(apimenthod,"ESB",json_obj.toString(),null,true,"API");
return CustomApiResult.success(null);
}else{
EsbUtils.saveLog(apimenthod,"ESB",json_obj.toString(),itemsJson.toJSONString(),false,"API");
return CustomApiResult.fail("400","接口处理异常"+itemsJson.toJSONString());
}
}
}