OA工具类,推送OA供应商,发票逻辑,回写接口

This commit is contained in:
weiyunlong 2024-09-14 13:59:21 +08:00
parent d563681bac
commit 35454f31b3
5 changed files with 524 additions and 54 deletions

View File

@ -13,14 +13,17 @@ import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.StringUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* @author weiyunlong
* @date Created 2024/8/30 14:22
* @description合同签署流程回调接口(e签宝接口文档 3.6.2.1)
* 合同签署流程回调接口(e签宝接口文档 3.6.2.1)
*/
@ -33,6 +36,7 @@ public class SignTechnologCallbackController implements Serializable {
CustomApiResult customApiResult = new CustomApiResult();
JSONObject jsonObject = JSONObject.parseObject(str);
//回调通知数据体
JSONObject callBackProcessVO = (JSONObject)jsonObject.get("callBackProcessVO");
if (null != callBackProcessVO) {

View File

@ -3,27 +3,42 @@ package shkd.repc.recon.formplugin;
import com.grapecity.documents.excel.D;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.cache.CacheFactory;
import kd.bos.cache.TempFileCache;
import kd.bos.coderule.api.CodeRuleInfo;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.fileservice.FileServiceFactory;
import kd.bos.form.CloseCallBack;
import kd.bos.form.ShowType;
import kd.bos.form.control.Control;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentDto;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import java.math.BigDecimal;
import java.io.*;
import java.util.List;
import java.util.Map;
/**
* 付款申请单表单插件
* qeug_recon_payreqbill_ext
* 付款申请单 || 费用登记单 插件
* 发票识别,发票验真验重
* qeug_recon_payreqbill_ext && qeug_recon_connotextb_ext
*/
public class ReconPayreqFormPlugin extends AbstractFormPlugin {
@ -31,13 +46,14 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
public void afterDoOperation(AfterDoOperationEventArgs args) {
super.afterDoOperation(args);
DynamicObject dataEntity = this.getView().getModel().getDataEntity();
String billtype = dataEntity.getDynamicObjectType().getName();
String operateKey = args.getOperateKey();
switch (operateKey){
//发票识别
case "qeug_invoicedistinguish":
DynamicObject dataEntity = this.getView().getModel().getDataEntity();
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments("recon_payreqbill",
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(billtype,
dataEntity.getPkValue(), "qeug_attachmentpanelap");
if (attachments.size() <= 0) {
this.getView().showTipNotification("请先上传发票附件");
@ -53,8 +69,29 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
boolean b = true;
//成功--新增分录行
if (b) {
for (Map<String, Object> fileMap : attachments) {
AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(fileMap.get("attPkId"));
String fileUrl = attachmentDto.getResourcePath();
try {
FileInputStream in = new FileInputStream(fileUrl);
Workbook workbook = WorkbookFactory.create(in);
Sheet sheet = workbook.getSheetAt(0);
for (int j = 1; j < 5; j++) {
Row row = sheet.getRow(j);
String billno = row.getCell(0).toString();
}
System.out.println("");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//发票信息分录
for (int i = 0; i < attachments.size(); i++) {
invoiceentry.addNew();
//todo:模仿标品新增字段,为接口返回数据反写分录做准备
this.getModel().setValue("qeug_invoicecode", "FKHM-0904-0001",i);//发票代码
@ -65,6 +102,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
}
this.getView().updateView("invoiceentry");
this.getView().showSuccessNotification("发票识别成功");
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
}else {
//失败--提示失败信息
this.getView().showTipNotification("发票识别失败:请上传有效发票");
@ -74,13 +112,25 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
case "qeug_invoicecheck":
//todo: 发票验真验重接口
// 根据接口情况打包分录数据去OA验真验重---遍历调取接口还是汇总集合调取接口
//发票信息分录
DynamicObjectCollection invoiceens = this.getView().getModel().getEntryEntity("invoiceentry");
if (invoiceens.size() == 0) {
this.getView().showTipNotification("请先进行发票识别后,再进行验真验重");
return;
}
boolean bb = true;
//成功--新增分录行
if (bb) {
this.getView().showSuccessNotification("发票验真验重接口");
//验真验重接口调通--生成发票登记单据(recon_invoicebill)
DynamicObject recon_invoicebill1 = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill");
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("2031274535679975424", "recon_invoicebill");
//todo 遍历发票信息明细,批量生成发票登记单(再次点击发票验真验重,只选择未完成验真验重的数据)
for (DynamicObject invoiceen : invoiceens) {
String qeug_invoicestatus = invoiceen.getString("qeug_invoicestatus");//验真/--状态
//未完成
if ("0".equals(qeug_invoicestatus)) {
DynamicObject recon_invoicebill = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill");
// DynamicObject recon_invoicebill1 = BusinessDataServiceHelper.loadSingle("2031274535679975424", "recon_invoicebill");
recon_invoicebill.set("billstatus","A");//单据状态
//所属组织
DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, "DOBE")});
@ -88,8 +138,8 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
recon_invoicebill.set("org",org);
}
//发票号码 invoiceno
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());//----编码规则待维护
recon_invoicebill.set("invoiceno","FKHM-0904-0001");//----编码规则待维护
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());
recon_invoicebill.set("invoiceno",invoiceen.getString("qeug_invoiceno"));//分录中的发票号码//todo----编码规则待维护
//发票编码
recon_invoicebill.set("billno","测试数据勿删!!");//----编码规则待维护
@ -126,20 +176,59 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
// SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
}
}
System.out.println("");
}
}
}else {
//失败--提示失败信息
this.getView().showTipNotification("发票验真验重失败:请检查发票明细信息是否正确");
}
break;
case "deleteinvoiceentry":
//用户在删除发票明细时如果当前发票已经生成发票登记单一并删除掉
//
//付款申请单发票信息明细删除行后进行保存
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
this.getView().showSuccessNotification("同步删除发票登记成功");
break;
default:
break;
}
}
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate source = (FormOperate) args.getSource();
String operateKey = source.getOperateKey();
switch (operateKey) {
//发票识别
case "deleteinvoiceentry":
//用户在删除发票明细时如果当前发票已经生成发票登记单一并删除掉
//删除后--未保存前,遍历发票信息分录 删除满足(明细"发票号码" == 发票登记单头"发票号码")的发票登记单
//获得"发票信息明细"选中行
EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry");
int[] selectRows = assetsentry.getSelectRows();
if (selectRows.length > 0) {
for (int i = 0; i < selectRows.length; i++) {
int selectRow = selectRows[i];
String qeug_invoiceno = (String)this.getModel().getValue("qeug_invoiceno",selectRow);//分录中的发票号码
QFilter q = new QFilter("invoiceno", QCP.equals, qeug_invoiceno);
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", new QFilter[]{q});
if (null != recon_invoicebill) {
int recon_invoicebill1 = DeleteServiceHelper.delete("recon_invoicebill", new QFilter[]{q});
//失败
if (1 != recon_invoicebill1) {
this.getView().showTipNotification("删除失败:请检查发票登记单的单据状态");
args.setCancel(true);
return;
}
}
}
}
break;
default:
break;
}
}
}
// CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule("recon_invoicebill", recon_invoicebill, null);

View File

@ -6,6 +6,8 @@ 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.framework.lifecycle.Service;
import kd.bos.framework.lifecycle.SystemServiceConfig;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.util.HttpClientUtils;
@ -15,6 +17,7 @@ import org.apache.commons.net.util.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -32,8 +35,161 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
for (DynamicObject dataEntity : e.getDataEntities()) {
// String url = System.getProperty("efms.infcompany.url.ip");
// logger.info("url");
Service[] allServices = SystemServiceConfig.getAllServices();
//获取token
String oaToken = OAUtils.getOaToken();
if (StringUtils.isNotEmpty(oaToken)) {
//ICS新增/更新OA客户租户接口
String customerUrl = "http://172.31.254.240:9090/seeyon/rest/ats/type/customer";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", oaToken);
//组装请求体
// DynamicObject supplier = dataEntity.getDynamicObject("supplier");
// if (null != supplier) {
// JSONObject customerBody = assembleBody(OAUtils.l(supplier.getPkValue()));
JSONObject customerBody = assembleBody(OAUtils.l(dataEntity.getPkValue()));
if (null != customerBody) {
String customerPostjson = null;
try {
customerPostjson = HttpClientUtils.postjson(customerUrl, customerHeader, customerBody.toJSONString());
logger.info("ICS新增/更新OA客户租户接口返回结果\n{}", customerPostjson);
} catch (Exception ex) {
logger.info(String.format("ICS新增/更新OA客户租户接口异常%s", ex.getMessage()));
throw new RuntimeException(ex);
}
}
// }
}
}
}
}
/**
* 组装供应商入参
*/
private 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("number");
String name = official_supplier.getString("name");
String taxpayerid = official_supplier.getString("tx_register_no");
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);//"客户名称",
customerBody.put("taxpayerid", taxpayerid);//"纳税人登记号/身份证号 唯一值不可变",
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.size() == 0) {
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 static String byte2Hex(byte[] bytes){
StringBuffer stringBuffer = new StringBuffer();
String temp = null;
for(int i=0 ; i < bytes.length; i++) {
temp = Integer.toHexString(bytes[i] & 0xFF);
//1得到一位的进行补0操作
if (temp.length() == 1) {
stringBuffer.append("0");
}
stringBuffer.append(temp);
}
return stringBuffer.toString();
}
public static String calculateHMACSHA256(String key, String message) {
try {
Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
mac.init(secretKeySpec);
byte[] hmac = mac.doFinal(message.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : hmac) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
// String[] split = encodeStr.split("=", 4);
// String s = split[0];
/*
---------------------生成上传文件链接----------------------------
*/

View File

@ -0,0 +1,146 @@
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.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import shkd.repc.recon.opplugin.TestOPPlugin;
import shkd.utils.OAUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 推送OA供应商
*/
public class PushOASupplierOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(PushOASupplierOPPlugin.class);
private static final String RESM_OFFICIAL_SUPPLIER = "resm_official_supplier";//正式供应商
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e){
super.afterExecuteOperationTransaction(e);
String operationKey = e.getOperationKey();
if ("pushoasupplier".equals(operationKey)) {
for (DynamicObject dataEntity : e.getDataEntities()) {
//String url = System.getProperty("efms.infcompany.url.ip");
//logger.info("url");
//获取token
String oaToken = OAUtils.getOaToken();
if (StringUtils.isNotEmpty(oaToken)) {
//ICS新增/更新OA客户租户接口
String customerUrl = "http://172.31.254.240:9090/seeyon/rest/ats/type/customer";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", oaToken);
//组装请求体
DynamicObject supplier = dataEntity.getDynamicObject("supplier");
if (null != supplier) {
JSONObject customerBody = assembleBody(OAUtils.l(supplier.getPkValue()));
if (null != customerBody) {
String customerPostjson = null;
try {
customerPostjson = HttpClientUtils.postjson(customerUrl, customerHeader, customerBody.toJSONString());
logger.info("ICS新增/更新OA客户租户接口返回结果\n{}", customerPostjson);
} catch (Exception ex) {
logger.info(String.format("ICS新增/更新OA客户租户接口异常%s", ex.getMessage()));
throw new RuntimeException(ex);
}
}
}
}
}
}
}
/**
* 组装供应商入参
*/
private 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("number");
String name = official_supplier.getString("name");
String taxpayerid = official_supplier.getString("tx_register_no");
String shortname = official_supplier.getString("simplename");
String legalbody = official_supplier.getString("artificialperson");
Date createTime = official_supplier.getDate("createtime");
Date updateTime = official_supplier.getDate("modifytime");
//接口请求体
customerBody = new JSONObject();
customerBody.put("code", code);//"客户编码传递OA回执的code如果没有则为空OA判断新增后返回code",
customerBody.put("name", name);//"客户名称",
customerBody.put("taxpayerid", taxpayerid);//"纳税人登记号/身份证号 唯一值不可变",
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);
}
customerBody.put("bankacc", custBankaccMapBody);
}
return customerBody;
}
}

View File

@ -0,0 +1,75 @@
package shkd.utils;
import com.alibaba.fastjson.JSONObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import java.util.Date;
/**
* @author weiyunlong
* @date Created 2024/9/11 16:02
* @description致远OA集成工具类
*/
public class OAUtils {
private static final Log logger = LogFactory.getLog(OAUtils.class);
//致远服务前获取token接口
public static String getOaToken(){
//String url = System.getProperty("efms.infcompany.url.ip");
//logger.info("url");
//致远服务前获取token接口
String userName = "ICSTest";
String password = "8f72e360-268e-41ba-9886-af9a802e4de3";
String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token";
//接口请求体
JSONObject linkBody = new JSONObject();
linkBody.put("userName", userName);
linkBody.put("password", password);
String token = "";
try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString());
logger.info("获取OaToken接口返回结果\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
token = jsonObject.getString("id");
}
return token;
} catch (Exception e) {
logger.info(String.format("获取OaToken接口异常%s", e.getMessage()));
throw new RuntimeException(e);
}
}
/**
* model值转Long
*/
public static long l(Object value) {
if (value == null) {
return 0L;
} else if (value instanceof Long) {
return (Long)value;
} else if (value instanceof Number) {
return ((Number)value).longValue();
} else if (value instanceof Boolean) {
return ((Boolean)value).booleanValue() ? 1L : 0L;
} else if (value instanceof Date) {
return ((Date)value).getTime();
} else {
String s = value.toString().trim();
if (s.length() == 0) {
return 0L;
} else {
return Long.parseLong(s);
}
}
}
}