金蝶Kis云代码实现

news/2024/9/30 1:41:29

1、金蝶认证(获取到token)也就是code,获取业务接口网关和auth_data,请求头
RequestHeader类

package com.api.xic.jd.tool;
import net.sf.json.JSONObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class RequestHeader {//通过header头传递access_token获取数据public static JSONObject httpDoPost(String serverURL, JSONObject parm, Map<String, String> header) throws IOException {StringBuffer sbf = new StringBuffer();String strRead = null;URL url = new URL(serverURL);HttpURLConnection connection = (HttpURLConnection)url.openConnection();connection.setRequestMethod("POST");//请求post方式connection.setDoInput(true);connection.setDoOutput(true);//header内的的参数在这里set。||connection.setRequestProperty("健, "值");connection.setRequestProperty("Content-Type", "application/json");if (header != null) {Iterator it = header.entrySet().iterator();while(it.hasNext()) {Map.Entry<String, String> entry = (Map.Entry)it.next();connection.setRequestProperty((String)entry.getKey(), (String)entry.getValue());}}connection.connect();OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(),"UTF-8");writer.write(parm.toString());writer.flush();InputStream is = connection.getInputStream();BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));while ((strRead = reader.readLine()) != null) {sbf.append(strRead);}reader.close();connection.disconnect();String results = sbf.toString();JSONObject jsonObject = JSONObject.fromObject(results);return jsonObject;}public static JSONObject getCoke(JSONObject parm) throws Exception {long timestamp =InterfaceToolAPI.shijianchuo();String urll = InvokeAPI.Sxscks("RZcode") + InvokeAPI.client_id + "&client_secret=" + InvokeAPI.client_secret;//通过code获取到token和sessionJSONObject jsonObject = null;try {jsonObject = httpPosyauthdata(urll,String.valueOf(timestamp), parm);} catch (Exception e) {e.printStackTrace();}JSONObject data = jsonObject.getJSONObject("data");return data;}//获取到token和sessiontoken和auth_data和gw_router_addrpublic static JSONObject gettoken(String acctnumber,String session_id,String access_token) throws Exception {
//        JSONObject coke = getCoke();
//        String access_token = coke.getString("access_token");//全局都要用
//        String session_id = coke.getString("session_id");String urls =InvokeAPI.Sxscks("YWwg") + access_token;JSONObject json2 = new JSONObject();json2.put("session_id", session_id);json2.put("pid", InvokeAPI.pid);json2.put("acctnumber", acctnumber);json2.put("icrmid", InvokeAPI.icrmid);long timestamp =InterfaceToolAPI.shijianchuo();JSONObject de = httpPosyauthdata(urls, String.valueOf(timestamp), json2);JSONObject authData = de.getJSONObject("data");String auth_data = authData.getString("auth_data");String gw_router_addr = authData.getString("gw_router_addr");JSONObject extend_data = authData.getJSONObject("extend_data");String refresh_auth_data_token = extend_data.getString("refresh_auth_data_token");JSONObject json= new JSONObject();json.put("access_token",access_token);json.put("auth_data",auth_data);json.put("gw_router_addr",gw_router_addr);json.put("refresh_auth_data_token",refresh_auth_data_token);return json;}//通用认证调用接口工具类public static JSONObject httpPosyauthdata(String serverURL, String shijiancuo, JSONObject parm) throws Exception {//headersMap<String, String> map = new HashMap<>();map.put("KIS-State", "1");map.put("KIS-Timestamp", shijiancuo);map.put("KIS-TraceID", "270962");JSONObject jsonObject =httpDoPost(serverURL, parm, map);return jsonObject;}//实际获取接口工具类public static JSONObject httpPosysjhq(JSONObject data,String serverURL, String shijiancuo, JSONObject parm) throws Exception {String auth_data = data.getString("auth_data");String gw_router_addr = data.getString("gw_router_addr");//headersMap<String, String> map = new HashMap<>();map.put("KIS-State", "1");//请求随机数map.put("KIS-Timestamp", shijiancuo);//时间戳map.put("KIS-TraceID", "270962");//客户终端请求轨迹idmap.put("KIS-AuthData", auth_data);//map.put("KIS-Ver", "1.0");//接口版本号map.put("X-GW-Router-Addr", gw_router_addr);//JSONObject jsonObject = httpDoPost(serverURL, parm, map);return jsonObject;}}

存放金蝶kis的接口

package com.api.xic.jd.tool;
import java.util.HashMap;
import java.util.Map;
//金蝶kis的接口
public class InvokeAPI {private static Map<String, String> map = new HashMap<String, String>();public final static String client_id = "270962";public final static String client_secret = "f4950271dc9e061b33de5d4f2ca851e7";public final static String pid = "16010091586cab90f3eeb764ceab5eef";//固定public final static String icrmid = "2c9223b083cc0f130183e4c32be01544";//固定static {//金蝶认证(获取到token)codemap.put("RZcode","https://api.kingdee.com/koas/oauth2/access_token?client_id=");//获取业务接口网关和auth_datamap.put("YWwg","https://api.kingdee.com/koas/user/get_service_gateway?access_token=");//销售出库单//批量查询销售出库单map.put("Sxscks","https://api.kingdee.com/koas/app007104/api/salesdelivery/list?access_token=");//查询销售出库单详情()map.put("Sxsck","https://api.kingdee.com/koas/app007104/api/salesdelivery/getdetail?access_token=");//新增销售出库单map.put("Axsck", "https://api.kingdee.com/koas/app007104/api/salesdelivery/create?access_token=");//修改销售出库单map.put("Uxsck","https://api.kingdee.com/koas/app007104/api/salesdelivery/update?access_token=");//删除销售出库单map.put("Dxsck","https://api.kingdee.com/koas/app007104/api/salesdelivery/delete?access_token=");//批量查询即时库存map.put("Sjskcs","https://api.kingdee.com/koas/APP007104/api/ICInventory/List?access_token=");//查询物料基础资料详情map.put("Swlxx","https://api.kingdee.com/koas/APP006992/api/Material/GetDetail?access_token=");//批量查询物料基础资料map.put("Swlxxs","https://api.kingdee.com/koas/APP006992/api/Material/List?access_token=");//获取仓库列表信息map.put("CKlbxx","https://api.kingdee.com/koas/APP006992/api/Stock/List?access_token=");//查询金蝶人员信息(工号)map.put("CKlbxx","https://api.kingdee.com/koas/APP006992/api/Employee/GetDetail?access_token=");//查询金蝶客户名称(客户id)map.put("KHMCXX","https://api.kingdee.com/koas/APP006992/api/Customer/GetDetail?access_token=");}public static String Sxscks(String key) throws Exception {String sUrl = map.get(key);return sUrl;}
}

日期时间相关类

package com.api.xic.jd.tool;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class DataTool {//获取当天时间public String getNowTime(String dateformat){Date now = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");String hehe = dateFormat.format(now);return hehe;}//获取两个日期之间的所有日期public List<LocalDate> getDatesBetween(LocalDate startDate, LocalDate endDate) {List<LocalDate> dates = new ArrayList<>();long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate);for (int i = 0; i <= numOfDaysBetween; i++) {LocalDate date = startDate.plusDays(i);dates.add(date);}return dates;}
}

封装金蝶相关操作类型(减少重复代码)

package com.api.xic.jd.tool;
import net.sf.json.JSONObject;
//接口查询
public class InterfaceToolAPI {//时间戳public static long shijianchuo(){long djcData3 = System.currentTimeMillis() / 1000;//循环时间戳return djcData3;}public final static long interval = 1000;//获取批量查询的总页数public  int Selectpages(int page, JSONObject data, String url) throws Exception {JSONObject json2 = new JSONObject();json2.put("CurrentPage", String.valueOf(page));//当前页json2.put("ItemsOfPage", "100");//一页大小Thread.sleep(interval);long shijianchuo = shijianchuo();JSONObject jsonObject = RequestHeader.httpPosysjhq(data,url, String.valueOf(shijianchuo), json2);int pages=jsonObject.getJSONObject("data").getInt("TotalPages");return pages;}//获取批量查询数据public  JSONObject SelectData(int ii,JSONObject data,String url) throws Exception {JSONObject json2 = new JSONObject();json2.put("CurrentPage",ii);//当前页json2.put("ItemsOfPage", "100");//一页大小Thread.sleep(interval);long shijianchuo = shijianchuo();JSONObject jsonObject = RequestHeader.httpPosysjhq(data,url, String.valueOf(shijianchuo), json2);return jsonObject;}//根据主键查询数据public JSONObject selectConditionId(JSONObject data,String url,int zid) throws Exception {JSONObject json = new JSONObject();json.put("ItemId",zid);//金蝶产品idThread.sleep(interval);long shijianchuo = shijianchuo();JSONObject jsonObject = RequestHeader.httpPosysjhq(data,url, String.valueOf(shijianchuo), json);return jsonObject;}}

销售出库代码

package com.api.xic.jd.jdapi;
import com.api.xic.jd.tool.DataTool;
import com.api.xic.jd.tool.InterfaceToolAPI;
import com.api.xic.jd.tool.InvokeAPI;
import com.weaver.general.TimeUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
//同步金蝶销售出库的数据
public class HttpBatchQuery {//批量查询销售出库public static int wlf(JSONObject data, int page, int ztid, LocalDate startDate, LocalDate endDate) throws Exception {DataTool tool = new DataTool();List<LocalDate> datesBetween = tool.getDatesBetween(startDate, endDate);int jdid = 0, FItemID, Fauxqty, ii, count, j, anInt, FSupplyID, FInterID, ryid = 0, bmid=0, i, x, size, size1,departmentid = 0,FPosterID;String mxbsql, insertsql, formmodeid = "241", nowDate = TimeUtil.getCurrentDateString(), nowTime = TimeUtil.getOnlyCurrentTimeString(), sql, url2;String sub2, rq, ny, fSettleDate, localTime, sqlString, url3, rydm4, FNumber, wldm, xhmc,rydm;JSONObject da2, de4, json,de3;JSONArray jsonObj, entryjson;double FConsignPrice, FConsignAmount;DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");InterfaceToolAPI interfaceTool = new InterfaceToolAPI();String access_token = data.getString("access_token");String url = InvokeAPI.Sxscks("Sxscks") + access_token;int pages = interfaceTool.Selectpages(page, data, url);RecordSet rs = new RecordSet(), recordSet = new RecordSet();outer:for (i = 0; i <= pages; i++) {//根据总页数循环ii = i + 1;url2 = InvokeAPI.Sxscks("Sxscks") + access_token;da2 = interfaceTool.SelectData(ii, data, url2);jsonObj = da2.getJSONObject("data").getJSONArray("List");// 计数count = 0;size = jsonObj.size();for (j = 0; j < size; j++) {//根据循环的当前页去循环里面的页数UUID uuid = UUID.randomUUID();//主键count++;if (count < 100) {fSettleDate = jsonObj.getJSONObject(j).getJSONObject("Head").getString("Fdate");FPosterID = jsonObj.getJSONObject(j).getJSONObject("Head").getInt("FPosterID");if (fSettleDate != null) {sub2 = fSettleDate.substring(0, 4); // 截取rq = fSettleDate.substring(0, 10); // 截取ny = fSettleDate.substring(0, 7); // 截取for (LocalDate localDate : datesBetween) {localTime = df.format(localDate);if (rq.equals(localTime)) {anInt = jsonObj.getJSONObject(j).getJSONObject("Head").getInt("FEmpID");//业务员FSupplyID = jsonObj.getJSONObject(j).getJSONObject("Head").getInt("FSupplyID");//购货单位FInterID = jsonObj.getJSONObject(j).getJSONObject("Head").getInt("FInterID");//出庫IDsqlString = "select jdid from uf_xsckbdsj where jdid=" + FInterID;recordSet.execute(sqlString);if (recordSet.next()) {jdid = recordSet.getInt("jdid");}if (jdid != FInterID) {//根据人员编号查询金蝶人员url3 = InvokeAPI.Sxscks("Swlxx") + access_token;de3 = interfaceTool.selectConditionId(data, url3, anInt);rydm = de3.getJSONObject("data").getString("FNumber");if (rydm != null) {//根据人员编号查询在oa查询人员idRecordSet res = new RecordSet();String sqlry = "select id,departmentid from HrmResource where workcode='" + rydm + "'";res.execute(sqlry);if (res.next()) {ryid = res.getInt("id");//人员iddepartmentid = res.getInt("departmentid");//部门id}}//根据客户id查询金蝶客户名称url3 = InvokeAPI.Sxscks("KHMCXX") + access_token;de4 = interfaceTool.selectConditionId(data, url3, FSupplyID);rydm4 = de4.getJSONObject("data").getString("FName");//客户名称FNumber = de4.getJSONObject("data").getString("FNumber");//客户代码if (FNumber.equals("XIC0001") || FNumber.equals("XIC0002") || FNumber.equals("XIC0003")) {continue;} else if (!FNumber.equals("XIC0001") || !FNumber.equals("XIC0002") || !FNumber.equals("XIC0003")) {    //客户不等于芯车和新富强try {insertsql = String.format("insert into uf_xsckbdsj" +"(ztmc,xsry,xsbm,khmc,khdm,xsckrq,jdid,xsny,formmodeid,modedatacreater,modedatacreatertype," +"modedatacreatedate,modedatacreatetime,MODEUUID)" +"VALUES" +"('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", ztid, ryid, departmentid, rydm4, FNumber, rq, FInterID,ny,formmodeid, 1, 0, nowDate, nowTime, uuid);rs.execute(insertsql);// System.out.println(insertsql);} catch (Exception e) {//System.out.println("主表插入失败");}//产品循环entryjson = jsonObj.getJSONObject(j).getJSONArray("Entry");size1 = entryjson.size();for (x = 0; x < size1; x++) {FItemID = entryjson.getJSONObject(x).getInt("FItemID");//产品代码//根据产品id查询产品名称url3 = InvokeAPI.Sxscks("Swlxx") + access_token;json = interfaceTool.selectConditionId(data, url3, FItemID);wldm = json.getJSONObject("data").getString("FNumber");//物料代码xhmc = json.getJSONObject("data").getString("FName");//型号名称FConsignPrice = entryjson.getJSONObject(x).getDouble("FConsignPrice");//销售单价FConsignAmount = entryjson.getJSONObject(x).getDouble("FConsignAmount");//销售金额Fauxqty = entryjson.getJSONObject(x).getInt("Fauxqty");//实发数量if(FConsignAmount<0){FConsignAmount=0.00;}//插入明细表try {//插入完成查询最大idsql = "select max(id) as id from uf_xsckbdsj";rs.execute(sql);int zuihouId = 0;if (rs.next()) {zuihouId = rs.getInt("id");}mxbsql = String.format("insert into uf_xsckbdsj_dt1" +"(xhmc,wldm,xssl,xsdj,xsjefds,mainid)" +"VALUES" +"('%s','%s','%s','%s','%s','%s')", xhmc, wldm, Fauxqty, FConsignPrice, FConsignAmount, zuihouId);rs.execute(mxbsql);// System.out.println(mxbsql);} catch (Exception e) {// System.out.println("插入明细表出错");}}}}}}}} else {continue outer;}}continue;}return pages;}
}

同步金蝶库存的数据

package com.api.xic.jd.jdapi;import com.api.xic.jd.tool.InterfaceToolAPI;
import com.api.xic.jd.tool.InvokeAPI;
import com.weaver.general.TimeUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import java.util.*;
//同步金蝶库存的数据
public class HttpHDInventory {//同步金蝶库存的数据public int wlf(JSONObject data, int page, int ztmczs) throws Exception {String access_token = data.getString("access_token");//全局都要用InterfaceToolAPI interfaceTool = new InterfaceToolAPI();RecordSet rs = new RecordSet(),rs2 = new RecordSet(),res = new RecordSet();String url = InvokeAPI.Sxscks("Sjskcs") + access_token;int pages = interfaceTool.Selectpages(page, data, url);int ckid = 0, ii, i, count = 0, j, FMaterialID, FBUQty, FStockID, size;String formmodeid = "238", url2, sql2, url3, wldm, xhmc, sqlry, wudm = null, mxbsql;JSONObject da2, jsonObject;JSONArray jsonObj;String nowDate = TimeUtil.getCurrentDateString(),nowTime = TimeUtil.getOnlyCurrentTimeString();List<Map<String, Object>> list = new ArrayList<>(),list2 = new ArrayList<>();Map<String, Object> map,map2;outer:for (i = 0; i <= pages; i++) {//根据总页数循环ii = i + 1;url2 = InvokeAPI.Sxscks("Sjskcs") + access_token;da2 = interfaceTool.SelectData(ii, data, url2);jsonObj = da2.getJSONObject("data").getJSONArray("List");size = jsonObj.size();for (j = 0; j < size; j++) {//根据循环的当前页去循环里面的页数count++;if (count < 100) {map2=new HashMap<>();FMaterialID = jsonObj.getJSONObject(j).getInt("FMaterialID");//物料idFBUQty = jsonObj.getJSONObject(j).getInt("FBUQty");//基本单位数量FStockID = jsonObj.getJSONObject(j).getInt("FStockID");//仓库内码map2.put("FMaterialID",FMaterialID);map2.put("FBUQty",FBUQty);map2.put("FStockID",FStockID);list2.add(map2);}else {continue outer;}}continue;}for (Map<String, Object> bean : list2) {FMaterialID =(int) bean.get("FMaterialID");FStockID =(int) bean.get("FStockID");FBUQty =(int) bean.get("FBUQty");//根据产品id查询产品名称url3 = InvokeAPI.Sxscks("Swlxx") + access_token;jsonObject = interfaceTool.selectConditionId(data, url3, FMaterialID);wldm = jsonObject.getJSONObject("data").getString("FNumber");//物料代码xhmc = jsonObject.getJSONObject("data").getString("FName");//型号名称//根据仓库内码id查询仓库sql2 = "select id from uf_ck where cknmjdid=" + FStockID;rs2.execute(sql2);if (rs2.next()) {ckid = rs2.getInt("id");}if (!wldm.equals("") || wldm != "") {//根据物料代码去查询oa的物料数据sqlry = "select wldm,id from uf_wlkcsj where wldm='" + wldm + "'";res.execute(sqlry);if (res.next()) {wudm = res.getString("wldm");//物料代码//wlid=res.getInt("id");//物料代码}if (!wldm.equals(wudm)) {//插入明细表try {map = new HashMap<>();map.put("wldm", wldm);map.put("FBUQty", FBUQty);map.put("xhmc", xhmc);map.put("ckid", ckid);map.put("nowDate", nowDate);map.put("nowTime", nowTime);list.add(map);} catch (Exception e) {e.printStackTrace();}}}}for (Map<String, Object> bean : list) {FBUQty = (int) bean.get("FBUQty");wldm = (String) bean.get("wldm");xhmc = (String) bean.get("xhmc");ckid = (int) bean.get("ckid");nowDate = (String) bean.get("nowDate");nowTime = (String) bean.get("nowTime");UUID uuid = UUID.randomUUID();//主键mxbsql = String.format("insert into uf_wlkcsj" +"(ztmc,wldm,kcsl,cpxh,ck,formmodeid,modedatacreater,modedatacreatertype," +"modedatacreatedate,modedatacreatetime,MODEUUID)" +"VALUES" +"('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", ztmczs, wldm, FBUQty, xhmc, ckid, formmodeid, 1, 0, nowDate, nowTime, uuid);rs.execute(mxbsql);//System.out.println(mxbsql);}return pages;}
}

同步更新金蝶物料的数据

package com.api.xic.jd.jdapi;import com.api.xic.jd.tool.InterfaceToolAPI;
import com.api.xic.jd.tool.InvokeAPI;
import com.weaver.general.TimeUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import java.text.NumberFormat;
import java.util.*;
//同步更新金蝶物料的数据
public class HttpJDmaterial {private Logger log = LoggerFactory.getLogger(getClass());//同步金蝶物料的数据public int wlf(JSONObject data, int page, int ztmczs) throws Exception {String access_token = data.getString("access_token");//全局都要用InterfaceToolAPI interfaceTool = new InterfaceToolAPI();RecordSet rs = new RecordSet(), res = new RecordSet();String url = InvokeAPI.Sxscks("Swlxxs") + access_token;int pages = interfaceTool.Selectpages(page, data, url);String str = null, xjjs, yj30s, yj90s, yj60s, nowTime = TimeUtil.getOnlyCurrentTimeString(), nowDate = TimeUtil.getCurrentDateString(), formmodeid = "54", url2, sqlry;String FNumber, wudm = null, fName, FFullName, url3, FOrderPrice, sqlupdate, mxbsql;int i, ii, j, count, FItemID;JSONObject da2, jsonObject;JSONArray data1;double FOrderPrice2, xjj = 0.0000, yj30 = 0.0000, yj60 = 0.0000, yj90 = 0.0000;NumberFormat nf = NumberFormat.getNumberInstance();nf.setMaximumFractionDigits(4); // 设置最大小数位数为4outer:for (i = 0; i < pages; i++) {//根据总页数循环ii = i + 1;url2 = InvokeAPI.Sxscks("Swlxxs") + access_token;da2 = interfaceTool.SelectData(ii, data, url2);data1 = da2.getJSONObject("data").getJSONArray("List");// 计数count = 0;for (j = 0; j < data1.size(); j++) {//根据循环的当前页去循环里面的页数UUID uuid = UUID.randomUUID();//主键count++;if (count < 100) {FItemID = data1.getJSONObject(j).getInt("FItemID");//物料idFNumber = data1.getJSONObject(j).getString("FNumber");//物料id//根据产品id查询产品名称if (!FNumber.equals("") || FNumber != "") {//根据物料代码去查询oa的物料数据sqlry = "select wldm from uf_xhcjbxx where wldm='" + FNumber + "'";res.execute(sqlry);if (res.next()) {wudm = res.getString("wldm");//物料代码}url3 = InvokeAPI.Sxscks("Swlxx") + access_token;jsonObject = interfaceTool.selectConditionId(data, url3, FItemID);fName = jsonObject.getJSONObject("data").getString("FName");//产品型号名称FFullName = jsonObject.getJSONObject("data").getString("FFullName");//物料全名FOrderPrice = jsonObject.getJSONObject("data").getString("FOrderPrice");//采购单价boolean contains = FFullName.contains("_");if (contains) {str = FFullName.substring(0, FFullName.lastIndexOf("_"));} else if (contains == false) {str = FFullName;}if (FOrderPrice.equals("null")) {if (!FNumber.equals(wudm)) {mxbsql = String.format("insert into uf_xhcjbxx" +"(sccj,ppmc,cpxh,cgj,wldm,xjj,yj30t,yj60t,yj90t,ztmc,formmodeid,modedatacreater,modedatacreatertype," +"modedatacreatedate,modedatacreatetime,MODEUUID)" +"VALUES" +"('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",str, str, fName, FOrderPrice, FNumber, xjj, yj30, yj60, yj90, ztmczs, formmodeid, 1, 0, nowDate, nowTime, uuid);rs.execute(mxbsql);log.info(mxbsql);}} else if (!FOrderPrice.equals("null")) {FOrderPrice2 = Double.valueOf(FOrderPrice);xjj = FOrderPrice2 / 0.95;//销售单价yj30 = FOrderPrice2 / 0.92;yj60 = FOrderPrice2 / 0.90;yj90 = FOrderPrice2 / 0.85;// 格式化并输出xjjs = nf.format(xjj);yj30s = nf.format(yj30);yj60s = nf.format(yj60);yj90s = nf.format(yj90);if (FNumber.equals(wudm)) {//相等修改采购价sqlupdate = "update uf_xhcjbxx set cgj=" + FOrderPrice2 + ",xjj=" + xjjs + ",yj30t=" + yj30s + ",yj60t=" + yj60s + ",yj90t=" + yj90s + ",ztmc=0 where wldm='" + wudm + "'";rs.execute(sqlupdate);log.info(sqlupdate);// System.out.println(sqlupdate);} else if (!FNumber.equals(wudm)) {mxbsql = String.format("insert into uf_xhcjbxx" +"(sccj,ppmc,cpxh,cgj,wldm,xjj,yj30t,yj60t,yj90t,ztmc,formmodeid,modedatacreater,modedatacreatertype," +"modedatacreatedate,modedatacreatetime,MODEUUID)" +"VALUES" +"('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",str, str, fName, FOrderPrice2, FNumber, xjjs, yj30s, yj60s, yj90s, ztmczs, formmodeid, 1, 0, nowDate, nowTime, uuid);rs.execute(mxbsql);log.info(mxbsql);}}}} else {continue outer;}}continue;}return pages;}
}

仓库数据同步

package com.api.xic.jd.jdapi;import com.api.xic.jd.tool.InterfaceToolAPI;
import com.api.xic.jd.tool.InvokeAPI;
import com.engine.board.web.DashboardAction;
import com.weaver.general.TimeUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.opensaml.xml.signature.J;
import weaver.conn.RecordSet;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;import java.util.Iterator;
import java.util.UUID;//仓库数据同步
public class WarehouseApi {private Logger log = LoggerFactory.getLogger(getClass());//同步金蝶仓库的数据public int wlf(JSONObject data, int page, int ztmczs) throws Exception {String access_token = data.getString("access_token");//全局都要用InterfaceToolAPI interfaceTool = new InterfaceToolAPI();RecordSet rs = new RecordSet(), res = new RecordSet();String url = InvokeAPI.Sxscks("CKlbxx") + access_token;JSONObject da2;JSONArray jsonObj;int i = 0, ii, count, j, FItemID, cknmjdid = 0;int pages = interfaceTool.Selectpages(page, data, url);//泛微建模标准字段String formmodeid = "263", url2, FName, FNumber, sqlry, mxbsql;//模块idString nowDate = TimeUtil.getCurrentDateString();String nowTime = TimeUtil.getOnlyCurrentTimeString();outer:for (i = 0; i <= pages; i++) {//根据总页数循环ii = i + 1;url2 = InvokeAPI.Sxscks("CKlbxx") + access_token;da2 = interfaceTool.SelectData(ii, data, url2);jsonObj = da2.getJSONObject("data").getJSONArray("List");count = 0;UUID uuid = UUID.randomUUID();//主键for (j = 0; j < jsonObj.size(); j++) {//根据循环的当前页去循环里面的页数count++;if (count < 100) {FName = jsonObj.getJSONObject(j).getString("FName");//仓库名称FNumber = jsonObj.getJSONObject(j).getString("FNumber");//	仓库代码FItemID = jsonObj.getJSONObject(j).getInt("FItemID");//仓库内码if (FItemID != 0) {//根据物料代码去查询oa的物料数据sqlry = "select cknmjdid from uf_ck where cknmjdid=" + FItemID;res.execute(sqlry);if (res.next()) {cknmjdid = res.getInt("cknmjdid");//仓库内码}if (FItemID != cknmjdid) {try {mxbsql = String.format("insert into uf_ck" +"(ckmc,ckdm,cknmjdid,formmodeid,modedatacreater,modedatacreatertype," +"modedatacreatedate,modedatacreatetime,MODEUUID)" +"VALUES" +"('%s','%s','%s','%s','%s','%s','%s','%s','%s')", FName, FNumber, FItemID, formmodeid, 1, 0, nowDate, nowTime, uuid);rs.execute(mxbsql);log.info(mxbsql);} catch (Exception e) {log.info("插入失败");}}}} else {continue outer;}}continue;}return pages;}}

执行流程

package com.api.xic.jd.action;import com.api.xic.jd.jdapi.*;import com.api.xic.jd.tool.RequestHeader;
import com.oneWorld.ecology.workflow.utils.ActionUtils;
import lombok.SneakyThrows;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;//同步数据流程
public class SalesoutboundAction2 implements Action {@SneakyThrows@Overridepublic String execute(RequestInfo requestInfo) {String retVal = SUCCESS;//返回流程打印//主表字段ActionUtils actionUtils = new ActionUtils();Map<String, String> mapMain = actionUtils.getMainData(requestInfo);String czlx = actionUtils.getMapValue(mapMain, "czsjlx");//操作类型String code = actionUtils.getMapValue(mapMain, "code");//codeString zt = actionUtils.getMapValue(mapMain, "zt");//codeString access_token ,ztid,session_id,startDate,endDate;startDate = actionUtils.getMapValue(mapMain, "ksrq");//开始日期endDate = actionUtils.getMapValue(mapMain, "jsrq");//结束日期RecordSet recordSet = new RecordSet();String sql = "select * from uf_ztxx where id in (" + zt + ")";recordSet.execute(sql);int ztmczs = 0,lx,wlf,i;JSONObject json = new JSONObject(),data,jsonObject5;json.put("code", code);JSONObject coke = RequestHeader.getCoke(json);DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");LocalDate endDate2,startDate2;WarehouseApi warehouseApi = new WarehouseApi();HttpHDInventory2 httpHDInventory = new HttpHDInventory2();HttpJDmaterial httpJDmaterial = new HttpJDmaterial();String[] czlxs=czlx.split(",");while (recordSet.next()) {ztid = recordSet.getString("ztid");ztmczs = recordSet.getInt("ztmczs");if (coke != null && !coke.isNullObject()) {access_token = coke.getString("access_token");//全局都要用session_id = coke.getString("session_id");for(i=0;i<czlxs.length;i++){lx = Integer.valueOf(czlxs[i]);switch(lx){case 0:endDate2 = LocalDate.parse(endDate, df);startDate2 = LocalDate.parse(startDate, df);data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_data// System.out.println("數量" + i);//HttpBatchQuery httpBatchQuery=new HttpBatchQuery();HttpBatchQuery.wlf(data, 1, ztmczs, startDate2, endDate2);//调用批查询销售出库的接口//System.out.println("销售出库" + jsonObject5);break;case 1://同步更新金蝶物料的数据data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_datahttpJDmaterial.wlf(data, 1,ztmczs);break;case 2://同步金蝶库存的数据data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_datahttpHDInventory.wlf(data, 1,ztmczs);break;case 3://同步金蝶仓库的数据data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_datawarehouseApi.wlf(data, 1,ztmczs);break;}}}}return retVal;}
}

执行建模

package com.api.xic.jd.action;import com.api.xic.jd.jdapi.HttpBatchQuery;
import com.api.xic.jd.jdapi.HttpHDInventory2;
import com.api.xic.jd.jdapi.HttpJDmaterial;
import com.api.xic.jd.jdapi.WarehouseApi;
import com.api.xic.jd.tool.RequestHeader;
import com.oneWorld.ecology.workflow.utils.ActionUtils;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCode;
import weaver.soa.workflow.request.RequestInfo;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;public class SalesoutboundExpand extends AbstractModeExpandJavaCode {@Overridepublic void doModeExpand(Map<String, Object> param) {Map<String, String> result = new HashMap<String, String>();try {RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");if (requestInfo != null) {//获取到台账里面的数据if (requestInfo != null) {//主表字段ActionUtils actionUtils = new ActionUtils();Map<String, String> mapMain = actionUtils.getMainData(requestInfo);String czlx = actionUtils.getMapValue(mapMain, "czsjlx");//操作类型String code = actionUtils.getMapValue(mapMain, "code");//codeString zt = actionUtils.getMapValue(mapMain, "zt");//codeString access_token, ztid, session_id, startDate, endDate;startDate = actionUtils.getMapValue(mapMain, "ksrq");//开始日期endDate = actionUtils.getMapValue(mapMain, "jsrq");//结束日期RecordSet recordSet = new RecordSet();String sql = "select * from uf_ztxx where id in (" + zt + ")";recordSet.execute(sql);int ztmczs, lx,i;JSONObject json = new JSONObject(), data, jsonObject5;json.put("code", code);JSONObject coke = RequestHeader.getCoke(json);DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");LocalDate endDate2, startDate2;long timestamp;WarehouseApi warehouseApi = new WarehouseApi();HttpHDInventory2 httpHDInventory = new HttpHDInventory2();HttpJDmaterial httpJDmaterial = new HttpJDmaterial();String[] czlxs = czlx.split(",");while (recordSet.next()) {ztid = recordSet.getString("ztid");ztmczs = recordSet.getInt("ztmczs");if (coke != null && !coke.isNullObject()) {access_token = coke.getString("access_token");//全局都要用session_id = coke.getString("session_id");for (i = 0; i < czlxs.length; i++) {lx = Integer.valueOf(czlxs[i]);switch (lx) {case 0:endDate2 = LocalDate.parse(endDate, df);startDate2 = LocalDate.parse(startDate, df);data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_data// System.out.println("數量" + i);HttpBatchQuery.wlf(data, 1, ztmczs, startDate2, endDate2);//调用批查询销售出库的接口//System.out.println("销售出库" + jsonObject5);break;case 1://同步更新金蝶物料的数据data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_datahttpJDmaterial.wlf(data, 1, ztmczs);break;case 2://同步金蝶库存的数据data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_datahttpHDInventory.wlf(data, 1, ztmczs);break;case 3://同步金蝶仓库的数据data = RequestHeader.gettoken(ztid, session_id, access_token);//获取到token和sessiontoken和auth_datawarehouseApi.wlf(data, 1, ztmczs);break;}}}}}}} catch (Exception e) {result.put("errmsg", "自定义出错信息");result.put("flag", "false");}}
}


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/29924.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

qt实现窗口B始终显示在窗口A上,且上层窗口在电脑任务栏不显示缩图

场景:窗口A上面始终显示窗口B(透明背景) /*****************************************/ 首先,在主窗口即底部窗口重写changeEvent QtGuiApplication1::QtGuiApplication1(QWidget *parent) : QWidget(parent) , m_pQtGuiClass(nullptr) {ui.setupUi(this);setWindowFlags(Q…

微信开发者工具请求接口 Provisional headers are shown

前情最近全权负责公司小程序项目的开发,使用的uniapp技术栈。 坑在和服务端联调的时候发现,接口pending很久,而且时不时的报Provisional headers are shown,而且出现的概率很大方法尝试?有可能是浏览器插件拦截了,把有可能推荐的插件全停了也没有用 有可能是防火墙拦截了…

时序图

时序图时序图1. 参考资料 2. 基础 3. 符号3.1. 斜线形式的上升沿、下降沿 3.2. Either or 信号 3.3. 波形省略3.2.1. 虚线 3.2.2. 波浪号3.4. 地址&数据表示4. 实例-WT588F语音芯片时序图4.1. 了解背景 4.2. 分析 4.3. 列逻辑 4.4. 根据逻辑写代码(伪代码)5. 总结 others…

移动端定位打卡

签到按钮脚本 Mobile_NS.getCurrPosition(function(result){var lngdangq = result["lng"];var lathoum = result["lat"];var minDistance = null;//alert("addr"+addr);var dkzt = $f("dkzt").val();//alert(dkzt);if(dkzt==0){//$f(…

3秒修复老照片,一键智能变高清!

你肯定有一些年代久远的老照片,以及网络下载的图片或视频,不够高清还非常模糊,如果能一键修复成高清就好了!现在推荐一款神奇的Real-ESRGAN镜像,可以将模糊老照片和视频修复成高清晰,动动手分分钟帮你一键焕新!操作指南这就马上附上!你肯定有一些年代久远的老照片,以及…

使用pyautogui向下滚动条到底

使用pyautogui向下滚动条到底 一、pyautogui简介 pyautogui是一个用于模拟鼠标和键盘操作的Python模块,它可以用来自动化执行一些重复性的任务,提高工作效率。在这篇文章中,将学习如何使用pyautogui模块来实现向下滚动条到底的功能。 二、安装pyautogui模块 在使用pyautogui…

EC11的中断实验——NVICEXTI

本文隶属于《GD32 示波器项目软件部分重难点及相关疑问解决》 4-EC11的中断实验——NVIC&EXTI 4-1 实验目标以及原理图 GD32E230外部中断EXTI(中断/事件控制器)包括21个相互独立的边沿检测电路并且能够向处理器内核产生中断请求或唤醒事件。EXTI有三种触发类型:上升沿触…

使用stable diffusion设计logo的提示词

使用stable diffusion设计logo的提示词 Stable Diffusion是一种基于图像处理和机器学习的算法,可以用于生成各种类型的图像,包括Logo设计。本文将介绍如何使用Stable Diffusion来设计Logo,并提供一些提示词以帮助读者更好地理解和应用这种技术。 1.了解Stable Diffusion的基…