parent
							
								
									388587b5e1
								
							
						
					
					
						commit
						b54ec78b91
					
				|  | @ -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"); | ||||
|                     } | ||||
| 
 | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -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; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -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 { | ||||
|  | @ -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<String, Object> params = new HashMap<>(); | ||||
|         Map<String, Object> dataParam = new HashMap<>(); | ||||
|         Map<String, Object> datajson = new HashMap<>(); | ||||
| 
 | ||||
|         //header | ||||
|         Map<String, Object> 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<String, Object>[] arr = new Map[1]; | ||||
|         arr[0] = dataParam; | ||||
| 
 | ||||
|         datajson.put("header", header); | ||||
|         datajson.put("data", arr); | ||||
| 
 | ||||
|         //装填参数 | ||||
|         List<BasicNameValuePair> 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(); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue