From b54ec78b91ede8b2dcc959a88bc6ef5633ae50b6 Mon Sep 17 00:00:00 2001 From: "tanfengling@x-ri.com" <123456> Date: Mon, 13 Oct 2025 15:49:19 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B7=A5=E5=85=B7=E7=B1=BB=E3=80=91?= =?UTF-8?q?=E6=B3=9B=E5=BE=AE=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E5=90=8E=E7=BB=AD=E5=8D=95=E7=8B=AC=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=88=96=E8=80=85=E7=94=9F=E6=88=90=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=8C=89=E9=92=AE=20=E3=80=90=E4=BB=93=E5=BA=93=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E3=80=91=E5=AE=A1=E6=A0=B8=E6=88=90=E5=8A=9F=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E4=BB=93=E5=BA=93=E6=8E=A8=E9=80=81=E6=B3=9B=E5=BE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/operate/sys/WarehouseAuditOp.java | 39 ++++ lc123/cloud/app/plugin/trd/FWImpl.java | 52 +++++ .../{TrdInterfaceImpl.java => TtxImpl.java} | 6 +- .../app/plugin/utils/FWRestfulUtils.java | 180 ++++++++++++++++++ 4 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 lc123/cloud/app/plugin/operate/sys/WarehouseAuditOp.java create mode 100644 lc123/cloud/app/plugin/trd/FWImpl.java rename lc123/cloud/app/plugin/trd/{TrdInterfaceImpl.java => TtxImpl.java} (90%) create mode 100644 lc123/cloud/app/plugin/utils/FWRestfulUtils.java diff --git a/lc123/cloud/app/plugin/operate/sys/WarehouseAuditOp.java b/lc123/cloud/app/plugin/operate/sys/WarehouseAuditOp.java new file mode 100644 index 0000000..4e7ecd6 --- /dev/null +++ b/lc123/cloud/app/plugin/operate/sys/WarehouseAuditOp.java @@ -0,0 +1,39 @@ +package tqq9.lc123.cloud.app.plugin.operate.sys; + +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.operate.result.OperationResult; +import kd.bos.entity.plugin.AbstractOperationServicePlugIn; +import kd.bos.entity.plugin.args.AfterOperationArgs; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.imsc.dmw.utils.StringUtils; +import tqq9.lc123.cloud.app.plugin.trd.FWImpl; + +public class WarehouseAuditOp extends AbstractOperationServicePlugIn { + + @Override + public void afterExecuteOperationTransaction(AfterOperationArgs e) { + super.afterExecuteOperationTransaction(e); + OperationResult operationResult = this.getOperationResult(); + if(operationResult.isSuccess()){ + DynamicObject[] dataEntities = e.getDataEntities(); + for (DynamicObject dataEntity : dataEntities) { + dataEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), dataEntity.getDynamicObjectType().getName()); + String resultStr = FWImpl.syncWH(dataEntity); + if(StringUtils.isNotBlank(resultStr)){ + JSONObject resultJson = JSONObject.parseObject(resultStr); + String status = resultJson.getString("status"); + if("1".equals(status)){ + + }else{ + String msg = resultJson.getString("result"); + } + + } + } + } + + } + + +} diff --git a/lc123/cloud/app/plugin/trd/FWImpl.java b/lc123/cloud/app/plugin/trd/FWImpl.java new file mode 100644 index 0000000..4357fa5 --- /dev/null +++ b/lc123/cloud/app/plugin/trd/FWImpl.java @@ -0,0 +1,52 @@ +package tqq9.lc123.cloud.app.plugin.trd; + +import com.alibaba.fastjson.JSONObject; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import tqq9.lc123.cloud.app.plugin.utils.FWRestfulUtils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 泛微接口实现,用于后续单独推送的功能实现 + */ +public class FWImpl { + + /** + * 推送仓库 + * @param dataEntity + * @return + */ + public static String syncWH(DynamicObject dataEntity) { + String number = dataEntity.getString("number"); + String name = dataEntity.getString("name"); + Date ceatetime = dataEntity.getDate("createtime"); + DynamicObject group = dataEntity.getDynamicObject("group");//分组:实物-1,虚拟-0 + String enable = dataEntity.getString("enable");//使用状态:可用-1,禁用-0 + DynamicObject tqq9_dept = dataEntity.getDynamicObject("tqq9_dept");//部门 + // TODO 根据部门获取泛微的部门ID + + + DynamicObject creator = dataEntity.getDynamicObject("creator");//创建人 + creator = BusinessDataServiceHelper.loadSingle(creator.getPkValue(), creator.getDynamicObjectType().getName()); + String tqq9_fwuserid = creator.getString("tqq9_fwuserid"); + tqq9_fwuserid = "363"; + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String cjsj = sdf.format(ceatetime); + + JSONObject mainTable = new JSONObject(); + mainTable.put("ckbm", number); + mainTable.put("ckmc", name); + mainTable.put("cjsj", cjsj); + mainTable.put("zt", Integer.valueOf(enable)); + mainTable.put("cclx", Integer.valueOf(group.getString("number"))); + mainTable.put("bmbm", "5g5be27147e2ff9d"); + + FWRestfulUtils fwRestfulUtils = new FWRestfulUtils(); + String resultStr = fwRestfulUtils.doAction("api/cube/restful/interface/saveOrUpdateModeData/CK", mainTable, tqq9_fwuserid); + return resultStr; + } + +} diff --git a/lc123/cloud/app/plugin/trd/TrdInterfaceImpl.java b/lc123/cloud/app/plugin/trd/TtxImpl.java similarity index 90% rename from lc123/cloud/app/plugin/trd/TrdInterfaceImpl.java rename to lc123/cloud/app/plugin/trd/TtxImpl.java index 1fcea34..f914e64 100644 --- a/lc123/cloud/app/plugin/trd/TrdInterfaceImpl.java +++ b/lc123/cloud/app/plugin/trd/TtxImpl.java @@ -12,11 +12,11 @@ import java.util.HashMap; import java.util.Map; /** - * 第三方接口调用 + * 通天晓接口实现 */ -public class TrdInterfaceImpl { +public class TtxImpl { - private static final Log logger = LogFactory.getLog(TrdInterfaceImpl.class); + private static final Log logger = LogFactory.getLog(TtxImpl.class); //调用通天晓接口 public static JSONObject ttxImpl(String method, String param) throws IOException { diff --git a/lc123/cloud/app/plugin/utils/FWRestfulUtils.java b/lc123/cloud/app/plugin/utils/FWRestfulUtils.java new file mode 100644 index 0000000..118aaa9 --- /dev/null +++ b/lc123/cloud/app/plugin/utils/FWRestfulUtils.java @@ -0,0 +1,180 @@ +package tqq9.lc123.cloud.app.plugin.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import okhttp3.*; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Timestamp; +import java.util.*; + +public class FWRestfulUtils { + + /** + *restful接口调用案例 + *以getModeDataPageList为例 + */ + public String doAction(String url, JSONObject mainTable, String fwuserid){ + String thirdConfigByNumber = ConfigUtils.getThirdConfigByNumber("FW_Main_URL");//获取泛微接口ip、端口号 + String systemid = ConfigUtils.getThirdConfigByNumber("FW_systemid");//获取泛微接口授权用户名、系统标识 + String d_password = ConfigUtils.getThirdConfigByNumber("FW_password");//获取泛微接口授权密码 + + CloseableHttpResponse response;// 响应类, + CloseableHttpClient httpClient = HttpClients.createDefault(); + + //restful接口url + HttpPost httpPost = new HttpPost(thirdConfigByNumber + url); + + //当前日期 + String currentDate = getCurrentDate(); + //当前时间 + String currentTime = getCurrentTime(); + //获取时间戳 + String currentTimeTamp = getTimestamp(); + + Map params = new HashMap<>(); + Map dataParam = new HashMap<>(); + Map datajson = new HashMap<>(); + + //header + Map header = new HashMap<>(); + header.put("systemid", systemid); + header.put("currentDateTime", currentTimeTamp); + String md5Source = systemid + d_password + currentTimeTamp; + String md5OfStr = getMD5Str(md5Source).toLowerCase(); + //Md5是:系统标识+密码+时间戳 并且md5加密的结果 + header.put("Md5",md5OfStr); + + //封装pageinfo +// JSONObject pageInfo = new JSONObject(); +// pageInfo.put("pageNo", 1); +// pageInfo.put("pageSize", 10); +// dataParam.put("pageInfo",pageInfo); + + //封装mainTable参数 + dataParam.put("mainTable",mainTable); + + //封装operationinfo参数 + JSONObject operationinfo = new JSONObject(); + operationinfo.put("operator", fwuserid); + dataParam.put("operationinfo",operationinfo); + + System.out.println("===请求参数dataparam==="+dataParam); + params.put("data",dataParam); + Map[] arr = new Map[1]; + arr[0] = dataParam; + + datajson.put("header", header); + datajson.put("data", arr); + + //装填参数 + List list = new ArrayList<>(); + list.add(new BasicNameValuePair("datajson", JSON.toJSONString(datajson))); + + try{ + httpPost.addHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8"); + httpPost.setEntity(new UrlEncodedFormEntity(list, "UTF-8")); + response = httpClient.execute(httpPost); + if (response != null && response.getEntity() != null) { + //返回信息 + String resulString = EntityUtils.toString(response.getEntity()); + System.out.println("成功"+ resulString); + return resulString; + }else{ + System.out.println("获取数据失败,请查看日志"+currentDate+" "+currentTime); + } + }catch (Exception e){ + System.out.println("请求失败"+currentDate+" "+currentTime+"====errormsg:"+e.getMessage()); + } + return null; + + } + + public String getMD5Str(String plainText){ + //定义一个字节数组 + byte[] secretBytes = null; + try { + // 生成一个MD5加密计算摘要 + MessageDigest md = MessageDigest.getInstance("MD5"); + //对字符串进行加密 + md.update(plainText.getBytes()); + //获得加密后的数据 + secretBytes = md.digest(); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("没有md5这个算法!"); +// throw new RuntimeException(SystemEnv.getHtmlLabelName(517545,userLanguage)); + } + //将加密后的数据转换为16进制数字 + String md5code = new BigInteger(1, secretBytes).toString(16); + // 如果生成数字未满32位,需要前面补0 + // 不能把变量放到循环条件,值改变之后会导致条件变化。如果生成30位 只能生成31位md5 + int tempIndex = 32 - md5code.length(); + for (int i = 0; i < tempIndex; i++) { + md5code = "0" + md5code; + } + return md5code; + } + + public static String getCurrentTime() { + Date newdate = new Date(); + long datetime = newdate.getTime(); + Timestamp timestamp = new Timestamp(datetime); + String currenttime = (timestamp.toString()).substring(11, 13) + ":" + (timestamp.toString()).substring(14, 16) + ":" + + (timestamp.toString()).substring(17, 19); + return currenttime; + } + + public static String getCurrentDate() { + Date newdate = new Date(); + long datetime = newdate.getTime(); + Timestamp timestamp = new Timestamp(datetime); + String currentdate = (timestamp.toString()).substring(0, 4) + "-" + (timestamp.toString()).substring(5, 7) + "-" + + (timestamp.toString()).substring(8, 10); + return currentdate; + } + + /** + * 获取当前日期时间。 YYYY-MM-DD HH:MM:SS + * @return 当前日期时间 + */ + public static String getCurDateTime() { + Date newdate = new Date(); + long datetime = newdate.getTime(); + Timestamp timestamp = new Timestamp(datetime); + return (timestamp.toString()).substring(0, 19); + } + + /** + * 获取时间戳 格式如:19990101235959 + * @return + */ + public static String getTimestamp(){ + return getCurDateTime().replace("-", "").replace(":", "").replace(" ", ""); + } + + public static int getIntValue(String v, int def) { + try { + return Integer.parseInt(v); + } catch (Exception ex) { + return def; + } + } + + + public static String null2String(Object s) { + return s == null ? "" : s.toString(); + + } +}