Commit 4b0b99365e3959113db7405ca5d063e94107f6ef
1 parent
2dcf6ac7
浦东公交调度系统-人员停用提示(功能)修正
1、修改home.html,限制显示8条信息,添加下载所有信息文件按钮功能 2、添加MyStringUtils.java,判定字符串是否中文 3、修正vehicleDataSyncController.java,修改下载文件中文名字的问题
Showing
6 changed files
with
80 additions
and
9 deletions
src/main/java/com/bsth/controller/schedule/core/legacy/EmployeeConfigInfoController.java
| @@ -14,7 +14,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | @@ -14,7 +14,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | ||
| 14 | import org.springframework.web.bind.annotation.*; | 14 | import org.springframework.web.bind.annotation.*; |
| 15 | 15 | ||
| 16 | import javax.servlet.http.HttpServletRequest; | 16 | import javax.servlet.http.HttpServletRequest; |
| 17 | +import javax.servlet.http.HttpServletResponse; | ||
| 17 | import javax.servlet.http.HttpSession; | 18 | import javax.servlet.http.HttpSession; |
| 19 | +import java.io.OutputStream; | ||
| 20 | +import java.io.PrintWriter; | ||
| 21 | +import java.net.URLEncoder; | ||
| 18 | import java.util.HashMap; | 22 | import java.util.HashMap; |
| 19 | import java.util.List; | 23 | import java.util.List; |
| 20 | import java.util.Map; | 24 | import java.util.Map; |
| @@ -71,7 +75,29 @@ public class EmployeeConfigInfoController extends BController<EmployeeConfigInfo | @@ -71,7 +75,29 @@ public class EmployeeConfigInfoController extends BController<EmployeeConfigInfo | ||
| 71 | } | 75 | } |
| 72 | 76 | ||
| 73 | return rtn; | 77 | return rtn; |
| 78 | + } | ||
| 79 | + @GetMapping(value = "/validate_get_destroy_info/download") | ||
| 80 | + public void exportValidateGetDestroyInfo( | ||
| 81 | + HttpServletRequest request, | ||
| 82 | + HttpServletResponse response) throws Exception { | ||
| 83 | + // 流输出导出文件 | ||
| 84 | + response.setHeader("content-type", "application/octet-stream"); | ||
| 85 | + response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("人员配置停用信息.txt", "UTF-8")); | ||
| 86 | + response.setContentType("application/octet-stream"); | ||
| 87 | + | ||
| 88 | + try ( | ||
| 89 | + OutputStream os = response.getOutputStream(); | ||
| 90 | + PrintWriter printWriter = new PrintWriter(os); | ||
| 91 | + ) { | ||
| 92 | + HttpSession session = request.getSession(); | ||
| 93 | + List<CompanyAuthority> cmyAuths = (List<CompanyAuthority>) session.getAttribute(Constants.COMPANY_AUTHORITYS); | ||
| 94 | + List<String> infos = this.employeeConfigInfoService.validate_get_destroy_info(cmyAuths); | ||
| 95 | + for (String info : infos) { | ||
| 96 | + printWriter.println(info); | ||
| 97 | + } | ||
| 98 | + printWriter.flush(); | ||
| 74 | 99 | ||
| 100 | + } | ||
| 75 | } | 101 | } |
| 76 | 102 | ||
| 77 | @RequestMapping(value = "/validate_jsy_destroy", method = RequestMethod.GET) | 103 | @RequestMapping(value = "/validate_jsy_destroy", method = RequestMethod.GET) |
src/main/java/com/bsth/controller/schedule/datasync/VehicleDataSyncController.java
| @@ -6,11 +6,13 @@ import com.bsth.controller.schedule.datasync.request.VehicleDataSyncTaskRequest; | @@ -6,11 +6,13 @@ import com.bsth.controller.schedule.datasync.request.VehicleDataSyncTaskRequest; | ||
| 6 | import com.bsth.entity.schedule.datasync.VehicleDataSyncTask; | 6 | import com.bsth.entity.schedule.datasync.VehicleDataSyncTask; |
| 7 | import com.bsth.entity.schedule.datasync.VehicleDataSyncTaskTypeEnum; | 7 | import com.bsth.entity.schedule.datasync.VehicleDataSyncTaskTypeEnum; |
| 8 | import com.bsth.service.schedule.datasync.VehicleDataSyncTaskService; | 8 | import com.bsth.service.schedule.datasync.VehicleDataSyncTaskService; |
| 9 | +import com.bsth.service.schedule.utils.MyStringUtils; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.web.bind.annotation.*; | 11 | import org.springframework.web.bind.annotation.*; |
| 11 | 12 | ||
| 12 | import javax.servlet.http.HttpServletResponse; | 13 | import javax.servlet.http.HttpServletResponse; |
| 13 | import java.io.*; | 14 | import java.io.*; |
| 15 | +import java.net.URLEncoder; | ||
| 14 | import java.util.Date; | 16 | import java.util.Date; |
| 15 | 17 | ||
| 16 | @RestController | 18 | @RestController |
| @@ -116,7 +118,12 @@ public class VehicleDataSyncController extends BController<VehicleDataSyncTask, | @@ -116,7 +118,12 @@ public class VehicleDataSyncController extends BController<VehicleDataSyncTask, | ||
| 116 | private void responseStreamFile(HttpServletResponse response, File file) throws IOException { | 118 | private void responseStreamFile(HttpServletResponse response, File file) throws IOException { |
| 117 | // 流输出导出文件 | 119 | // 流输出导出文件 |
| 118 | response.setHeader("content-type", "application/octet-stream"); | 120 | response.setHeader("content-type", "application/octet-stream"); |
| 119 | - response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); | 121 | + String fileName = file.getName(); |
| 122 | + if (MyStringUtils.isContainChinese(fileName)) { | ||
| 123 | + response.setHeader("Content-Disposition", "attachment; filename*=" + URLEncoder.encode(fileName, "UTF-8")); | ||
| 124 | + } else { | ||
| 125 | + response.setHeader("Content-Disposition", "attachment; filename=" + fileName); | ||
| 126 | + } | ||
| 120 | response.setContentType("application/octet-stream"); | 127 | response.setContentType("application/octet-stream"); |
| 121 | 128 | ||
| 122 | try ( | 129 | try ( |
src/main/java/com/bsth/service/schedule/utils/MyStringUtils.java
0 → 100644
| 1 | +package com.bsth.service.schedule.utils; | ||
| 2 | + | ||
| 3 | +import org.springframework.util.Assert; | ||
| 4 | + | ||
| 5 | +import java.util.regex.Matcher; | ||
| 6 | +import java.util.regex.Pattern; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 字符串工具类。 | ||
| 10 | + */ | ||
| 11 | +public class MyStringUtils { | ||
| 12 | + /** | ||
| 13 | + * 字符串是否包含中文 | ||
| 14 | + * | ||
| 15 | + * @param str 待校验字符串 | ||
| 16 | + * @return true 包含中文字符 false 不包含中文字符 | ||
| 17 | + */ | ||
| 18 | + public static boolean isContainChinese(String str) { | ||
| 19 | + Assert.hasText(str, "字符串为空!"); | ||
| 20 | + | ||
| 21 | + Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]"); | ||
| 22 | + Matcher m = p.matcher(str); | ||
| 23 | + if (m.find()) { | ||
| 24 | + return true; | ||
| 25 | + } | ||
| 26 | + return false; | ||
| 27 | + } | ||
| 28 | +} |
src/main/resources/static/pages/home.html
| @@ -83,15 +83,25 @@ | @@ -83,15 +83,25 @@ | ||
| 83 | success: function(rs) { | 83 | success: function(rs) { |
| 84 | if (rs && rs.status === "SUCCESS") { | 84 | if (rs && rs.status === "SUCCESS") { |
| 85 | if (rs.data && rs.data.length && rs.data.length > 0) { | 85 | if (rs.data && rs.data.length && rs.data.length > 0) { |
| 86 | + var text = ""; | ||
| 87 | + if (rs.data.length > 8) { | ||
| 88 | + text = "部分停用信息如下:</br>" + rs.data.slice(0, 8).join("</br>"); | ||
| 89 | + } else { | ||
| 90 | + text = "所有停用信息如下:</br>" + rs.data.join("</br>"); | ||
| 91 | + } | ||
| 86 | swal({ | 92 | swal({ |
| 87 | title: "人员配置停用信息", | 93 | title: "人员配置停用信息", |
| 88 | - text: rs.data.join("</br>"), | 94 | + text: text, |
| 89 | html: true, | 95 | html: true, |
| 90 | type: "warning", | 96 | type: "warning", |
| 91 | showCancelButton: true, | 97 | showCancelButton: true, |
| 92 | - confirmButtonColor: "RED", | ||
| 93 | - confirmButtonText: "是", | ||
| 94 | - cancelButtonText: "取消" | 98 | + cancelButtonText: "关闭", |
| 99 | + confirmButtonColor: "#3598dc", | ||
| 100 | + confirmButtonText: "下载所有停用信息", | ||
| 101 | + closeOnConfirm: false | ||
| 102 | + | ||
| 103 | + }, function() { | ||
| 104 | + window.location.href = "/eci/validate_get_destroy_info/download"; | ||
| 95 | }); | 105 | }); |
| 96 | } | 106 | } |
| 97 | } | 107 | } |
src/main/resources/static/pages/scheduleApp/module/basicInfo/vehicleDataSyncManage/service.js
| @@ -49,11 +49,11 @@ angular.module('ScheduleApp').factory( | @@ -49,11 +49,11 @@ angular.module('ScheduleApp').factory( | ||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | // console.log(headers("Content-Disposition")); | 51 | // console.log(headers("Content-Disposition")); |
| 52 | - // 获取文件名 | 52 | + // 获取文件名,后台根据是否还有中文名字,返回filename=ascii编码的文件名 或 filename*=unicode编码的文件名 |
| 53 | var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1]; | 53 | var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1]; |
| 54 | var fileNameUnicode = headers("Content-Disposition").split("filename*=")[1]; | 54 | var fileNameUnicode = headers("Content-Disposition").split("filename*=")[1]; |
| 55 | if (fileNameUnicode) {//当存在 filename* 时,取filename* 并进行解码(为了解决中文乱码问题) | 55 | if (fileNameUnicode) {//当存在 filename* 时,取filename* 并进行解码(为了解决中文乱码问题) |
| 56 | - fileName = decodeURIComponent(fileNameUnicode.split("''")[1]); | 56 | + fileName = decodeURIComponent(fileNameUnicode); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | return {fileData : data, fileName: fileName}; | 59 | return {fileData : data, fileName: fileName}; |
src/main/resources/static/pages/scheduleApp/module/common/prj-common-globalservice.js
| @@ -235,11 +235,11 @@ angular.module('ScheduleApp').factory( | @@ -235,11 +235,11 @@ angular.module('ScheduleApp').factory( | ||
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | // console.log(headers("Content-Disposition")); | 237 | // console.log(headers("Content-Disposition")); |
| 238 | - // 获取文件名 | 238 | + // 获取文件名,后台根据是否还有中文名字,返回filename=ascii编码的文件名 或 filename*=unicode编码的文件名 |
| 239 | var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1]; | 239 | var fileName = headers("Content-Disposition").split(";")[1].split("filename=")[1]; |
| 240 | var fileNameUnicode = headers("Content-Disposition").split("filename*=")[1]; | 240 | var fileNameUnicode = headers("Content-Disposition").split("filename*=")[1]; |
| 241 | if (fileNameUnicode) {//当存在 filename* 时,取filename* 并进行解码(为了解决中文乱码问题) | 241 | if (fileNameUnicode) {//当存在 filename* 时,取filename* 并进行解码(为了解决中文乱码问题) |
| 242 | - fileName = decodeURIComponent(fileNameUnicode.split("''")[1]); | 242 | + fileName = decodeURIComponent(fileNameUnicode); |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | return {fileData : data, fileName: fileName}; | 245 | return {fileData : data, fileName: fileName}; |