dobe_comic8/main/java/shkd/repc/resm/opplugin/PushOASupplierOPPlugin.java

182 lines
9.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package shkd.repc.resm.opplugin;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.validate.ErrorLevel;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import shkd.repc.recon.opplugin.TestOPPlugin;
import shkd.utils.OAUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static shkd.utils.OAUtils.pushOASupplier;
/**
* 推送OA供应商
*/
public class PushOASupplierOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(PushOASupplierOPPlugin.class);
public static final String RESM_OFFICIAL_SUPPLIER = "resm_official_supplier";//正式供应商
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e){
super.afterExecuteOperationTransaction(e);
//todo:定时任务推送所有供应商 变更审核操作之后推送供应商
String operationKey = e.getOperationKey();
if ("audit".equals(operationKey)) {
for (DynamicObject dataEntity : e.getDataEntities()) {
String name = dataEntity.getDynamicObjectType().getName();
String supplierName = "";
DynamicObject supplier = null;
if ("resm_change_supplier".equals(name)) {
supplierName = dataEntity.getDynamicObject("supplier").getString("name");
supplier = dataEntity.getDynamicObject("supplier");
}else {
supplierName = dataEntity.getString("name");
supplier = dataEntity;
}
//获取token
String oaToken = OAUtils.getOaToken(supplierName);
if (StringUtils.isNotEmpty(oaToken) && null != supplier) {
pushOASupplier(oaToken,supplier);
}
//处理联系人分录中的开通账号的人员名称更新到主表字段上面 yxl 20241120
handleContactPerson(supplier);
}
}
}
/**
* 组装供应商入参
*/
public static JSONObject assembleBody(long supplierID){
JSONObject customerBody = null;
//获取正式供应商
QFilter q = new QFilter("id", QCP.equals, supplierID);
// QFilter q = new QFilter("number", QCP.equals, "111");//成都筑垒建筑工程有限公司
DynamicObject official_supplier = BusinessDataServiceHelper.loadSingle(RESM_OFFICIAL_SUPPLIER, new QFilter[]{q});
if (null != official_supplier) {
String code = official_supplier.getString("qeug_oacode");
String name = official_supplier.getString("name");
String taxpayerid = official_supplier.getString("tx_register_no");//纳税人识别号
String societycreditcode = official_supplier.getString("societycreditcode");//统一社会信用代码
String artificialpersoncard = official_supplier.getString("artificialpersoncard");//法人代表身份证号码
String persontype = official_supplier.getString("persontype");//法人类型
String shortname = official_supplier.getString("simplename");
String legalbody = official_supplier.getString("artificialperson");
Date createTime = official_supplier.getDate("createtime");
Date updateTime = official_supplier.getDate("modifytime");
Object createtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(createTime);
Object updatetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(updateTime);
//接口请求体
customerBody = new JSONObject();
customerBody.put("code", code);//"客户编码传递OA回执的code如果没有则为空OA判断新增后返回code",
customerBody.put("name", name);//"客户名称",
//PERSONAL 个人
if ("PERSONAL".equals(persontype)) {
customerBody.put("taxpayerid", artificialpersoncard);//"纳税人登记号/身份证号 唯一值不可变",
}else {
customerBody.put("taxpayerid", societycreditcode);//"纳税人登记号/身份证号 唯一值不可变",
}
customerBody.put("shortname", shortname);//"客户简称",
customerBody.put("custprop", "0");//"客户类型默认0",
customerBody.put("enablestate", "2");//"客户状态默认2",
customerBody.put("pk_custclass", "02");//"客户基本分类默认02",
customerBody.put("legalbody", legalbody);// "法人",
customerBody.put("createTime", createtime);// "创建时间例如2024-06-02 17:27:10",
customerBody.put("updateTime", updatetime);//"更新时间例如2024-06-02 17:27:10",
customerBody.put("def1", "租赁客户");//"客商类别:默认租赁客户",
JSONArray custBankaccMapBody = new JSONArray();
//银行信息
DynamicObjectCollection entry_banks = official_supplier.getDynamicObjectCollection("entry_bank");
for (DynamicObject entry_bank : entry_banks) {
JSONObject custBankaccBody = new JSONObject();
custBankaccBody.put("accnum", entry_bank.getString("bankaccount"));//"银行账号",
DynamicObject bank = entry_bank.getDynamicObject("bank");
if (null != bank) {
// "开户行名称:例如招商银行股份有限公司上海分行外高桥支行龙江支行"
custBankaccBody.put("pk_bankdoc", bank.getString("name"));
DynamicObject city = bank.getDynamicObject("city");
if (null != city) {
//"城市"
custBankaccBody.put("city", city.getString("name"));
}
}
custBankaccBody.put("accname", entry_bank.getString("accountname"));//"银行账号名称",
custBankaccBody.put("pk_banktype", "");//todo:"银行类别:例如招商银行",
// String persontype = entry_bank.getString("persontype");//法人类型
//法人企业 LEGALENTERPRISE
//非法人企业 UNINCORPORATED
//非企业单位 NONENTERPRISE
//个人 PERSONAL
if (!"PERSONAL".equals(persontype)) {
custBankaccBody.put("psnOrCompany", "3397730183813155472");// "个人或公司公司3397730183813155472/个人:-7676950454987503991"
}else {
custBankaccBody.put("psnOrCompany", "-7676950454987503991");
}
custBankaccMapBody.add(custBankaccBody);
}
//无银行信息
if (entry_banks.isEmpty()) {
JSONObject custBankaccBody = new JSONObject();
custBankaccBody.put("accnum","");//"银行账号",
custBankaccBody.put("pk_bankdoc", "");// "开户行名称:例如招商银行股份有限公司上海分行外高桥支行龙江支行"
custBankaccBody.put("city","");//"城市"
custBankaccBody.put("accname","");//"银行账号名称",
custBankaccBody.put("pk_banktype", "");//todo:"银行类别:例如招商银行",
custBankaccBody.put("psnOrCompany", "3397730183813155472");// "个人或公司公司3397730183813155472/个人:-7676950454987503991"
custBankaccMapBody.add(custBankaccBody);
}
customerBody.put("bankacc", custBankaccMapBody);
}
return customerBody;
}
private void handleContactPerson(DynamicObject supplier){
// 获取正式供应商
QFilter q = new QFilter("id", QCP.equals, supplier.getPkValue());
DynamicObject officialSupplier = BusinessDataServiceHelper.loadSingle(RESM_OFFICIAL_SUPPLIER, new QFilter[]{q});
DynamicObjectCollection lxrcoll = officialSupplier.getDynamicObjectCollection("entry_linkman");
DynamicObject lxrinfo = null;
String lxrmc = null;
for (int i = 0; i < lxrcoll.size(); i++) {
lxrinfo = lxrcoll.get(i);
if(lxrinfo.getBoolean("isopenaccount")){
lxrmc = lxrinfo.getString("contactperson");
break;
}
}
if(lxrmc != null){
officialSupplier.set("qeug_supplierperson", lxrmc);//开通账号人员
SaveServiceHelper.save(new DynamicObject[]{officialSupplier});
}
}
}