記錄對接老系統(Struts+Spring+JdbcTemplate)傳單下發接口的全流程:新系統(SpringMVC+MyBatis)通過 HTTP POST 調用,老系統服務層處理業務邏輯,涉及數據庫批量增刪改、JSON 名片數據替換、Jsoup 靜態 HTML 重寫、文件復制上傳雲存儲。
public String postTelentService(String url, String params) throws IOException {
URL u = new URL(url);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setDoOutput(true); conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.connect();
try (DataOutputStream out = new DataOutputStream(conn.getOutputStream())) {
out.writeBytes(params);
out.flush();
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) sb.append(line).append("\n");
return new String(sb.toString().getBytes("GBK"), "UTF-8");
}
}
String url = "https://" + Config.getMkpUrl() + "/marketa/remotePassFlyers.do";
String params = "userId=" + userId + "&maId=" + maId + "&flyerId=" + flyerId
+ "&userIds=" + userIds + "&assUserIds=" + assUserIds;
String result = postTelentService(url, params);
public String remotePassFlyers() {
Integer userId = Integer.parseInt(request.getParameter("userId"));
Integer maId = Integer.parseInt(request.getParameter("maId"));
Integer flyerId = Integer.parseInt(request.getParameter("flyerId"));
String userIds = request.getParameter("userIds");
String assUserIds = request.getParameter("assUserIds");
marketaService.passFlyerToUsers(userId, maId, flyerId, userIds, assUserIds);
return SUCCESS;
}
d_flyer 主表與 d_flyer_detail 子表(動態 SQL 多表 UPDATE)。d_flyer,同步 INSERT 子表詳情。refreshNameCard 替換名片 JSON,調用 uploadShareFlyerHtmlFile 生成靜態 HTML 並上傳。| 方法 | 功能 |
|---|---|
getInvitedUserInfos | 左連接查詢用戶與傳單關聯,返回 user_id + flyer_id |
getSharedFlyerDetaiInfo | 多表連接獲取傳單詳情(名片字段:email/mobile/qq/weixin/realname/job) |
castArrayToString | 數組/集合轉逗號分隔字符串,用於 SQL IN 子句 |
getPassFlyerSql(type) | 根據類型返回 5 種動態 SQL(更新主表/子表、插入主表/子表、批量複製) |
refreshNameCard | Gson 解析 JSON content,定位 wd_u_name=bio 節點,替換 realname/qq/tell/email/phone/weixin/job/company |
replaceCardInfo | 按字段名從用戶信息 Map 取值覆蓋,缺失保留原值 |
updateDetailContent | 更新 d_flyer_detail.content 字段 |
uploadShareFlyerHtmlFile | 復制模板 HTML → Jsoup 解析替換 data-key 屬性元素文本 → 寫回文件 → 上傳雲存儲 |
reloadCardHtml | Jsoup 選擇 [data-key=realname/qq/tell/...] 設置文本,輸出 HTML |
jsonToMap/objToJson。{
"widgets": [
{"wd_u_name":"title", "value":"...", "color":"#000", "fontSize":"25px", ...},
{"wd_u_name":"feedback", "btnLabel":"搶購", "items":[{"name":"name",...}, ...]},
{"wd_u_name":"bio", "company":"...", "job":"...", "realname":"...", "qq":"", "tell":"...", ...}
],
"meta": {"color":"#fedac2", "bgImg":"/flyer/images/flyerimg/flyer_bg_6.jpg", ...}
}