Parcourir la source

停水公告新增2个类型的查询条件

王苗苗 il y a 4 mois
Parent
commit
48b92f8a19

+ 57 - 0
slibra-admin/src/main/java/com/slibra/web/controller/business/FileDownloadController.java

@@ -9,6 +9,8 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.List;
@@ -85,4 +87,59 @@ public class FileDownloadController {
             }
         }
     }
+
+    // 互联网上文件的URL
+    private static final String REMOTE_FILE_URL = "https://static.fuxicarbon.com/userupload/ttt.wav";
+
+    // 缓存下载文件的临时目录(确保这个目录存在并且应用有写入权限)
+    private static final String TEMP_DIR = "/Users/wangmiaomiao/Downloads/";
+
+    // 缓存文件的文件名(可以从URL中解析出来,或者根据需求设置)
+//    private static final String CACHED_FILE_NAME = "downloaded_file.zip";
+    private static final String CACHED_FILE_NAME = "ttt.wav";
+
+    @GetMapping("/downloadHttpUrl")
+    public ResponseEntity<InputStreamResource> downloadFile() throws IOException {
+        File cachedFile = new File(TEMP_DIR + CACHED_FILE_NAME);
+
+        // 如果文件不存在,则从互联网上下载
+        if (!cachedFile.exists()) {
+            File tempDir = new File(TEMP_DIR);
+            if (!tempDir.exists()) {
+                tempDir.mkdirs();
+            }
+            downloadFileFromInternet(REMOTE_FILE_URL, cachedFile);
+        }
+
+        // 设置HTTP响应头
+        HttpHeaders headers = new HttpHeaders();
+        headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + CACHED_FILE_NAME + "\"");
+        headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
+        headers.setContentLength(cachedFile.length());
+
+        // 返回文件内容作为响应体
+        InputStream inputStream = Files.newInputStream(cachedFile.toPath());
+        InputStreamResource resource = new InputStreamResource(inputStream);
+
+        return ResponseEntity.ok()
+                .headers(headers)
+                .body(resource);
+    }
+
+    private void downloadFileFromInternet(String fileURL, File destination) throws IOException {
+        URL url = new URL(fileURL);
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        connection.setRequestMethod("GET");
+
+        try (InputStream inputStream = connection.getInputStream();
+             FileOutputStream outputStream = new FileOutputStream(destination)) {
+
+            byte[] buffer = new byte[4096];
+            int bytesRead;
+            while ((bytesRead = inputStream.read(buffer)) != -1) {
+                outputStream.write(buffer, 0, bytesRead);
+            }
+        }
+    }
+
 }

+ 1 - 1
slibra-system/src/main/java/com/slibra/business/domain/TCutOffWater.java

@@ -63,7 +63,7 @@ public class TCutOffWater extends BaseEntity
     private String neighbourhoodName;
 
     //停水状态
-    private int status;//0未知 1待停水  2停水中  3已恢复
+    private Integer status;//0未知 1待停水  2停水中  3已恢复
 
     //绑定的小区-泵站信息列表
     private List<CutOffExtraRes> extraResList;

+ 16 - 1
slibra-system/src/main/resources/mapper/business/TCutOffWaterMapper.xml

@@ -32,6 +32,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
             <if test="pumpingStationNeighborhoodBuildingId != null  and pumpingStationNeighborhoodBuildingId != ''"> and pumping_station_neighborhood_building_id = #{pumpingStationNeighborhoodBuildingId}</if>
             <if test="revision != null "> and revision = #{revision}</if>
+             <!-- 2024年11月29日14:46:09 查询条件需要增加 小区名称 和 停水状态 -->
+            <if test="neighbourhoodName != null "> and id in (	SELECT
+                cut_off_water_id
+                FROM
+                t_cut_off_water_extra
+                WHERE
+                del_flag = 0
+                AND neighborhood_id = ( SELECT ID FROM t_neighborhood WHERE del_flag = 0 AND `name` LIKE concat('%', #{neighbourhoodName}, '%') ))</if>
+            <if test="status != null ">
+             <choose>
+                 <when test="status == 1">and now() &lt; time_begin </when>
+                 <when test="status == 2">and (now() &gt;= time_begin and (time_end is null or now() &lt;= time_end))</when>
+                 <when test="status == 3">and now() &gt; time_end</when>
+             </choose>
+             </if>
         </where>
         and del_flag = 0 order by id desc
     </select>
@@ -139,7 +154,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         INNER JOIN t_neighborhood c ON c.id = b.neighborhood_id
         AND c.del_flag = 0
         WHERE c.`name` LIKE concat('%', #{asrText}, '%')
-        AND NOW() &gt;= time_begin AND (time_end is NULL or NOW() &lt; time_end)
+        AND NOW() &gt;= time_begin AND (time_end is NULL or NOW() &lt;= time_end)
     </select>
     
     <select id="selectgetExtraListByPumpingStationId" resultType="com.slibra.business.res.CutOffExtraRes">