diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java index 079283e3d..961de15e5 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/common/CommonController.java @@ -22,6 +22,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.net.URLDecoder; import java.util.concurrent.TimeUnit; /** @@ -46,12 +47,18 @@ public class CommonController { * @param delete 是否删除 */ @GetMapping("common/download") - public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { + public void fileDownload(String fileName, Boolean delete, String downFileName,HttpServletResponse response, HttpServletRequest request) { try { + if(StringUtils.isEmpty(fileName)){ + return; + } + //解码 + fileName = URLDecoder.decode(fileName, "UTF-8"); + downFileName = StringUtils.isEmpty(downFileName) ? null : URLDecoder.decode(downFileName, "UTF-8"); if (!FileUtils.isValidFilename(fileName)) { throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); } - String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); + String realFileName = (downFileName != null && downFileName.length() <= 200) ? downFileName : System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String filePath = RuoYiConfig.getDownloadPath() + fileName; response.setCharacterEncoding("utf-8"); diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java index aa6b9ae1d..8170cd5db 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysCustomerHealthyServiceImpl.java @@ -38,6 +38,8 @@ public class SysCustomerHealthyServiceImpl implements ISysCustomerHealthyService @Autowired private ISysCustomerService sysCustomerService; + public static final String reportDownFileNameFormat = "%s超重%s斤%s"; + /** * 查询客户健康 * @@ -164,8 +166,10 @@ public class SysCustomerHealthyServiceImpl implements ISysCustomerHealthyService //查询客户健康信息 SysCustomerHealthy sysCustomerHealthy = selectSysCustomerHealthyById(healthyDetailRequest.getId()); if(sysCustomerHealthy != null){ - ajaxResult = PdfUtils.generatePdfFile(templatePath, filePath, getReportData(sysCustomerHealthy, healthyDetailRequest)); + Map reportData = getReportData(sysCustomerHealthy, healthyDetailRequest); + ajaxResult = PdfUtils.generatePdfFile(templatePath, filePath, reportData); ajaxResult.put("path", fileName); + ajaxResult.put("downReportFileName", reportData.get("downReportFileName")+".pdf"); } return ajaxResult; } @@ -235,6 +239,11 @@ public class SysCustomerHealthyServiceImpl implements ISysCustomerHealthyService } data.put("company","深圳胜唐体控有限公司"); data.put("date", DateUtils.getDate()); + + //文件下载时的名称,名字+超重几斤+病史体征 + String sign = StringUtils.isEmpty(healthyDetailRequest.getPhysicalSigns()) ? "" : healthyDetailRequest.getPhysicalSigns().replace(",","").replace(",","").replace("/", ""); + String downReportFileName = String.format(reportDownFileNameFormat, healthyDetailRequest.getName(), nutritionalCalories.getOverWeight() > 0 ? nutritionalCalories.getOverWeight().toString() : "0", sign); + data.put("downReportFileName", downReportFileName); return data; } diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml index cb72bfb52..98cae17fc 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserInfoMapper.xml @@ -36,14 +36,13 @@