From 6874e05291603568ab41fdcbcaac1dba2dca96fc Mon Sep 17 00:00:00 2001 From: chenfeng <214759371@qq.com> Date: Wed, 9 Apr 2025 17:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=AF=E5=8C=BA=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YbsjyAppletsAppointmentController.java | 104 ++++++++++++++++++ .../dao/YbsjyAppointmentRecordMapper.xml | 1 + .../html/back/yuyueList/statistics.html | 8 +- 3 files changed, 109 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cjy/back/ybsjAppointment/controller/YbsjyAppletsAppointmentController.java b/src/main/java/com/cjy/back/ybsjAppointment/controller/YbsjyAppletsAppointmentController.java index 3e587ee..6c95824 100644 --- a/src/main/java/com/cjy/back/ybsjAppointment/controller/YbsjyAppletsAppointmentController.java +++ b/src/main/java/com/cjy/back/ybsjAppointment/controller/YbsjyAppletsAppointmentController.java @@ -1,10 +1,14 @@ package com.cjy.back.ybsjAppointment.controller; + import com.cjy.back.ybsjAppointment.entity.vo.GetAppointmentRecordVO; import com.cjy.back.ybsjAppointment.entity.vo.ReservationNowVO; import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentRecordService; import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentSettingService; import com.cjy.util.ServerResponse; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.jupiter.api.extension.MediaType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; @@ -12,8 +16,17 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import sun.net.www.http.HttpClient; + +import java.io.OutputStream; +import java.net.HttpURLConnection; import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; /** * @author liangjiawei @@ -135,4 +148,95 @@ public class YbsjyAppletsAppointmentController { return ServerResponse.createBySuccess(ybsjyAppointmentRecordService.selectPop()); } + + @RequestMapping("/getAccessToken") + public ServerResponse getAccessToken(String appId, String appSecret) throws IOException { + // 目标 URL + URL url = new URL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret); + // 打开连接 + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + + // 设置请求方法 + conn.setRequestMethod("GET"); + + // 设置请求头 + conn.setRequestProperty("Content-Type", "application/json"); + + // 获取响应 + int responseCode = conn.getResponseCode(); + System.out.println("Response Code: " + responseCode); + + BufferedReader in = new BufferedReader( + new InputStreamReader(conn.getInputStream())); + String inputLine; + StringBuilder response = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // 输出响应内容 + return ServerResponse.createBySuccess(response); + } + + // public static String uploadImage(String accessToken, File imageFile) throws IOException { +// String url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=" + accessToken + "&type=image"; +// OkHttpClient client = new OkHttpClient(); +// RequestBody body = new MultipartBody.Builder() +// .setType(MultipartBody.FORM) +// .addFormDataPart("media", imageFile.getName(), +// RequestBody.create(imageFile, MediaType.parse("image/*"))) +// .build(); +// Request request = new Request.Builder().url(url).post(body).build(); +// try (Response response = client.newCall(request).execute()) { +// JSONObject result = new JSONObject(response.body().string()); +// return result.getString("media_id"); // 返回永久素材ID +// } +// } + @RequestMapping("/createDraft") + public ServerResponse createDraft(String accessToken, String title, String content, String thumbMediaId) throws IOException { + String url = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=" + accessToken; + + // 构建请求体 + JSONObject article = new JSONObject(); + article.put("title", title); + article.put("content", content); + article.put("thumb_media_id", thumbMediaId); + article.put("need_open_comment", 0); + + JSONArray articles = new JSONArray(); + articles.put(article); + JSONObject requestBody = new JSONObject().put("articles", articles); + + // 创建连接 + HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setDoOutput(true); + + // 发送请求 + try (OutputStream os = conn.getOutputStream()) { + os.write(requestBody.toString().getBytes("UTF-8")); + } + + // 处理响应 + int responseCode = conn.getResponseCode(); + if (responseCode != HttpURLConnection.HTTP_OK) { + throw new IOException("HTTP error code: " + responseCode); + } + + try (BufferedReader br = new BufferedReader( + new InputStreamReader(conn.getInputStream(), "UTF-8"))) { + StringBuilder response = new StringBuilder(); + String line; + while ((line = br.readLine()) != null) { + response.append(line); + } + JSONObject result = new JSONObject(response.toString()); + return result.getString("media_id"); + } finally { + conn.disconnect(); + } + } } diff --git a/src/main/java/com/cjy/back/ybsjAppointment/dao/YbsjyAppointmentRecordMapper.xml b/src/main/java/com/cjy/back/ybsjAppointment/dao/YbsjyAppointmentRecordMapper.xml index feea249..86a31da 100644 --- a/src/main/java/com/cjy/back/ybsjAppointment/dao/YbsjyAppointmentRecordMapper.xml +++ b/src/main/java/com/cjy/back/ybsjAppointment/dao/YbsjyAppointmentRecordMapper.xml @@ -424,6 +424,7 @@ SUM( CASE WHEN write_off = 0 THEN 1 ELSE 0 END ) AS unverified, SUM( CASE WHEN write_off = 1 THEN 1 ELSE 0 END ) AS verified, SUM( CASE WHEN write_off = 3 THEN 1 ELSE 0 END ) AS cancel, + SUM( CASE WHEN expired_state = 1 THEN 1 ELSE 0 END ) AS hasExpired, COUNT( * ) AS altogether FROM ybsj_appointment_people_info a diff --git a/src/main/webapp/html/back/yuyueList/statistics.html b/src/main/webapp/html/back/yuyueList/statistics.html index c070a01..efb0ceb 100644 --- a/src/main/webapp/html/back/yuyueList/statistics.html +++ b/src/main/webapp/html/back/yuyueList/statistics.html @@ -84,7 +84,7 @@ {field:'altogether', title:'预约人数', align:'center'}, {field:'verified', title:'核销人数', align:'center'}, {field:'cancel', title:'取消人数', align:'center'}, - {field:'cancel', title:'过期人数', align:'center'}, + {field:'hasExpired', title:'过期人数', align:'center'}, {field:'guid', hide:true, width:0} ] ], id : 'tableId', @@ -98,7 +98,7 @@ altogether: 0, verified: 0, cancel: 0, - expired: 0 + hasExpired: 0 }; // 计算各列总和 @@ -106,7 +106,7 @@ totalData.altogether += item.altogether || 0; totalData.verified += item.verified || 0; totalData.cancel += item.cancel || 0; - totalData.expired += item.cancel || 0; + totalData.hasExpired += item.hasExpired || 0; }); // 添加合计行 @@ -118,7 +118,7 @@ '' + totalData.altogether + '' + '' + totalData.verified + '' + '' + totalData.cancel + '' + - '' + totalData.expired + '' + + '' + totalData.hasExpired + '' + '' + // 隐藏列留空 '' );