From 2f2be1c25ae0c330a3612a692512916512e5d78e Mon Sep 17 00:00:00 2001 From: zhengzheng <18918765049@163.com> Date: Wed, 4 May 2022 22:29:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 10 +- .../main/java/com/wuzhen/ZtApplication.java | 13 +++ .../controller/busi/ActiveInfoController.java | 62 ++++++------ .../controller/common/CommonController.java | 27 ++---- .../com/wuzhen/web/core/config/WebConfig.java | 13 +++ zt-admin/src/main/resources/application.yml | 4 + .../resources/templates/active/info/add.html | 2 +- .../resources/templates/active/info/edit.html | 65 ++++++++++--- .../templates/active/info/first.html | 95 +++++++++---------- .../resources/templates/demo/form/upload.html | 2 + .../common/utils/file/FileUploadUtils.java | 6 +- .../com/wuzhen/common/utils/uuid/Seq.java | 2 +- .../com/wuzhen/system/domain/ActiveInfo.java | 17 +++- .../mapper/system/ActiveInfoMapper.xml | 4 +- 14 files changed, 198 insertions(+), 124 deletions(-) diff --git a/pom.xml b/pom.xml index 5622fe28f..5e60ad523 100644 --- a/pom.xml +++ b/pom.xml @@ -178,11 +178,11 @@ - - com.wuzhen - zt-quartz - ${ruoyi.version} - + + + + + diff --git a/zt-admin/src/main/java/com/wuzhen/ZtApplication.java b/zt-admin/src/main/java/com/wuzhen/ZtApplication.java index f8f1d5ab8..be1a06da6 100644 --- a/zt-admin/src/main/java/com/wuzhen/ZtApplication.java +++ b/zt-admin/src/main/java/com/wuzhen/ZtApplication.java @@ -4,8 +4,12 @@ import com.wuzhen.common.config.RuoYiConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.util.UrlPathHelper; + +import java.nio.charset.StandardCharsets; /** * 启动程序 @@ -44,4 +48,13 @@ public class ZtApplication implements WebMvcConfigurer // registry.addResourceHandler("/**").addResourceLocations("file:" + RuoYiConfig.getProfile()); } + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + UrlPathHelper urlPathHelper=new UrlPathHelper(); + urlPathHelper.setUrlDecode(false); + urlPathHelper.setDefaultEncoding(StandardCharsets.UTF_8.name()); + configurer.setUrlPathHelper(urlPathHelper); + } + + } \ No newline at end of file diff --git a/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java b/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java index b7e3cf285..71c187161 100644 --- a/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java +++ b/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java @@ -7,6 +7,9 @@ import com.wuzhen.common.core.controller.BaseController; import com.wuzhen.common.core.domain.AjaxResult; import com.wuzhen.common.core.page.TableDataInfo; import com.wuzhen.common.enums.BusinessType; +import com.wuzhen.common.utils.StringUtils; +import com.wuzhen.common.utils.file.FileUploadUtils; +import com.wuzhen.common.utils.file.FileUtils; import com.wuzhen.common.utils.poi.ExcelUtil; import com.wuzhen.framework.shiro.util.AuthorizationUtils; import com.wuzhen.system.domain.ActiveInfo; @@ -106,8 +109,7 @@ public class ActiveInfoController extends BaseController logger.info(activeInfo.toString()); activeInfo.setCreateBy(getLoginName()); AuthorizationUtils.clearAllCachedAuthorizationInfo(); -// toAjax(activeInfoService.insertActive(activeInfo)) - return toAjax(2); + return toAjax(activeInfoService.insertActive(activeInfo)); } /** @@ -140,13 +142,17 @@ public class ActiveInfoController extends BaseController } /** - * 修改活动 + * 修改首页 */ @RequiresPermissions("active:info:edit") @GetMapping("/first/{id}") public String first(@PathVariable("id") Long id, ModelMap mmap) + { - mmap.put("active", activeInfoService.selectActiveById(id)); + ActiveInfo activeInfo = activeInfoService.selectActiveById(id); + + activeInfo.setListFpNames("http://localhost:18000/profile/upload/fp/"+activeInfo.getFpFilesName()); + mmap.put("active", activeInfo); return prefix + "/first"; } @@ -160,29 +166,30 @@ public class ActiveInfoController extends BaseController @ResponseBody public AjaxResult firstSave(@Validated ActiveInfo activeInfo) { - MultipartFile file = activeInfo.getActiveFirstPic(); - // 获取上传文件名 - String filename = file.getOriginalFilename(); - if (!"".equals(filename)){ - - // 定义上传文件保存路径 - String path = RuoYiConfig.getFPUploadPath(); - // 新建文件 - File filepath = new File(path, filename); - // 判断路径是否存在,如果不存在就创建一个 - if (!filepath.getParentFile().exists()) { - filepath.getParentFile().mkdirs(); - } - String picUrl = path + File.separator + filename; - try { - // 写入文件 - file.transferTo(new File(picUrl)); - } catch (IOException e) { - e.printStackTrace(); - } - activeInfo.setActiveFirstPicUrl(fp+filename); - activeInfo.setIsFristPage("1"); - } +// MultipartFile file = activeInfo.getActiveFirstPic(); +// // 获取上传文件名 +// String filename = file.getOriginalFilename(); +// if (!"".equals(filename)){ +// +// // 定义上传文件保存路径 +// String path = RuoYiConfig.getFPUploadPath(); +// // 新建文件 +// File filepath = new File(path, filename); +// // 判断路径是否存在,如果不存在就创建一个 +// if (!filepath.getParentFile().exists()) { +// filepath.getParentFile().mkdirs(); +// } +// String picUrl = path + File.separator + filename; +// try { +// // 写入文件 +// file.transferTo(new File(picUrl)); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// activeInfo.setActiveFirstPicUrl(fp+filename); +// activeInfo.setIsFristPage("1"); +// } + activeInfo.setIsFristPage("1"); activeInfo.setUpdateBy(getLoginName()); AuthorizationUtils.clearAllCachedAuthorizationInfo(); return toAjax(activeInfoService.saveFistPage(activeInfo)); @@ -232,5 +239,4 @@ public class ActiveInfoController extends BaseController - } \ No newline at end of file diff --git a/zt-admin/src/main/java/com/wuzhen/web/controller/common/CommonController.java b/zt-admin/src/main/java/com/wuzhen/web/controller/common/CommonController.java index 42a518e17..4b0c99c0c 100644 --- a/zt-admin/src/main/java/com/wuzhen/web/controller/common/CommonController.java +++ b/zt-admin/src/main/java/com/wuzhen/web/controller/common/CommonController.java @@ -141,31 +141,20 @@ public class CommonController */ @PostMapping("/uploadsFp") @ResponseBody - public AjaxResult uploadFilesFp(List files) throws Exception + public AjaxResult uploadFilesFp(MultipartFile file) throws Exception { try { // 上传文件路径 String filePath = RuoYiConfig.getFPUploadPath(); - List urls = new ArrayList(); - List fileNames = new ArrayList(); - List newFileNames = new ArrayList(); - List originalFilenames = new ArrayList(); - for (MultipartFile file : files) - { - // 上传并返回新文件名称 - String fileName = FileUploadUtils.upload(filePath, file); - String url = serverConfig.getUrl() + fileName; - urls.add(url); - fileNames.add(fileName); - newFileNames.add(FileUtils.getName(fileName)); - originalFilenames.add(file.getOriginalFilename()); - } + // 上传并返回新文件名称 + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; AjaxResult ajax = AjaxResult.success(); - ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); - ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); - ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); - ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); + ajax.put("url", url); + ajax.put("fileName", fileName); + ajax.put("newFileName", FileUtils.getName(fileName)); + ajax.put("originalFilename", file.getOriginalFilename()); return ajax; } catch (Exception e) diff --git a/zt-admin/src/main/java/com/wuzhen/web/core/config/WebConfig.java b/zt-admin/src/main/java/com/wuzhen/web/core/config/WebConfig.java index c741bc27c..7d4b521ec 100644 --- a/zt-admin/src/main/java/com/wuzhen/web/core/config/WebConfig.java +++ b/zt-admin/src/main/java/com/wuzhen/web/core/config/WebConfig.java @@ -3,8 +3,12 @@ package com.wuzhen.web.core.config; import com.wuzhen.common.config.RuoYiConfig; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.util.UrlPathHelper; + +import java.nio.charset.StandardCharsets; @Configuration public class WebConfig implements WebMvcConfigurer { @@ -31,4 +35,13 @@ public class WebConfig implements WebMvcConfigurer { // registry.addResourceHandler("/**").addResourceLocations("file:" + RuoYiConfig.getProfile()); } + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + UrlPathHelper urlPathHelper=new UrlPathHelper(); + urlPathHelper.setUrlDecode(false); + urlPathHelper.setDefaultEncoding(StandardCharsets.UTF_8.name()); + configurer.setUrlPathHelper(urlPathHelper); + } + + } diff --git a/zt-admin/src/main/resources/application.yml b/zt-admin/src/main/resources/application.yml index 3bdf5fc15..aab2e9efb 100644 --- a/zt-admin/src/main/resources/application.yml +++ b/zt-admin/src/main/resources/application.yml @@ -74,6 +74,9 @@ spring: restart: # 热部署开关 enabled: true + mvc: + pathmatch: + matching-strategy: ant-path-matcher # MyBatis mybatis: @@ -143,3 +146,4 @@ swagger: # 是否开启swagger enabled: true + diff --git a/zt-admin/src/main/resources/templates/active/info/add.html b/zt-admin/src/main/resources/templates/active/info/add.html index 8c8156a2f..3476a309c 100644 --- a/zt-admin/src/main/resources/templates/active/info/add.html +++ b/zt-admin/src/main/resources/templates/active/info/add.html @@ -166,13 +166,13 @@ var list = []; var res = []; var r_val = rsp.newFileNames; - res.push(r_val); var list = value.split(','); list.forEach(function (item) { if ((item !== r_val) && (item !=='') ) { res.push(item); } }) + res.push(r_val); console.log('end:', res); $("#lpFilesName").val(res); var c = $("#lpFilesName").val(); diff --git a/zt-admin/src/main/resources/templates/active/info/edit.html b/zt-admin/src/main/resources/templates/active/info/edit.html index 4c2db923a..5106f9ab3 100644 --- a/zt-admin/src/main/resources/templates/active/info/edit.html +++ b/zt-admin/src/main/resources/templates/active/info/edit.html @@ -9,8 +9,8 @@
- - + +
@@ -121,7 +121,7 @@ var activeEndDate = $("input[name='activeEndDate']").val(); var activeType = $("select[name='activeType']").val(); var isEnroll = $("select[name='isEnroll']").val(); - var activePic = $("input[name='activePic']").val(); + var lpFilesName = $("input[name='lpFilesName']").val(); var status = $("select[name='status']").val(); var remark = $("input[name='remark']").val(); var address =$("textarea[name='address']").val(); @@ -138,7 +138,7 @@ "activeEndDate": activeEndDate, "activeType": activeType, "isEnroll": isEnroll, - "activePic": activePic, + "lpFilesName": lpFilesName, "status": status, "remark": remark }, @@ -165,6 +165,7 @@ if (initialList != null && initialList.length) { for (var i = 0; i < initialList.length; i++) { previewJson[i] = initialList[i].filepath; + //alert(initialList[i].filepath); //组装图片配置 var tjson = { type: getFileTypeFromUrl(initialList[i].filepath), @@ -179,6 +180,9 @@ } } // 多图上传 + var cacheImgs = {}; + var g_value = $("#lpFilesName").val() || ''; + var g_list = g_value.split(','); $("#multipleFile").fileinput({ uploadUrl: ctx + 'common/uploadsLp',//上传路径 fileActionSettings: { @@ -199,14 +203,25 @@ }).on('filebatchuploadsuccess', function (event, data, previewId, index) { var rsp = data.response; }).on('fileuploaded', function (event, data, previewId, index) { - var resultObj = data.response; - console.log(resultObj); - if (resultObj != null && resultObj.code == 0) { - $("#" + previewId).append(""); - $.modal.msgSuccess("上传成功"); - } else { - $.modal.msgError("上传失败"); - } + + cacheImgs[previewId] = data.response.newFileNames; + var rsp = data.response; + var value = $("#lpFilesName").val() || ''; + var list = []; + var res = []; + var r_val = rsp.newFileNames; + var list = value.split(','); + list.forEach(function (item) { + if ((item !== r_val) && (item !=='') ) { + res.push(item); + } + }) + res.push(r_val); + console.log('end:', res); + $("#lpFilesName").val(res); + var c = $("#lpFilesName").val(); + console.log('fileuploaded: c:', c); + }).on('filebatchselected', function (event, files) { $(this).fileinput("upload");//这里会根据uploadAsync值自动去执行对应的回调函 }).on('filebatchuploaderror', function (event, data, msg) { @@ -230,8 +245,33 @@ $.modal.msgSuccess("移除成功-1"); }).on('filebeforedelete', function (event, key) { $.modal.msgSuccess("移除成功-2"); + console.log('filebeforedelete',event,key); + var value = $("#lpFilesName").val() || ''; + var list = value.split(','); + var res = []; + for (var i = 0; i < list.length; i++) { + if(list[i]!==g_list[key]){ + res.push(list[i]); + } + } + $("#lpFilesName").val(res); + var f = $("#lpFilesName").val(); + console.log('filesuccessremove: f:', f); }).on('filesuccessremove', function (event, data, previewId, index) { $.modal.msgSuccess("移除成功-3"); + var urls = cacheImgs[data]; + delete cacheImgs[data]; + var value = $("#lpFilesName").val() || ''; + var list = value.split(','); + var res = []; + list.forEach(function (item) { + if ((item !== urls) && (item !=='')) { + res.push(item); + } + }) + $("#lpFilesName").val(res); + var d = $("#lpFilesName").val(); + console.log('filesuccessremove: d:', d); }); } @@ -243,7 +283,6 @@ }); function getFileTypeFromUrl(url) { - console.log('getFileTypeFromUrl', url); if (url.endsWith('gif') || url.endsWith('jpg') || url.endsWith('jpeg') || url.endsWith('png')) { return 'image'; } diff --git a/zt-admin/src/main/resources/templates/active/info/first.html b/zt-admin/src/main/resources/templates/active/info/first.html index 4c8400d62..76e743f70 100644 --- a/zt-admin/src/main/resources/templates/active/info/first.html +++ b/zt-admin/src/main/resources/templates/active/info/first.html @@ -4,11 +4,14 @@ +
+ +
@@ -17,13 +20,10 @@
- -
- - - + +
+
-
@@ -32,61 +32,19 @@ + diff --git a/zt-admin/src/main/resources/templates/demo/form/upload.html b/zt-admin/src/main/resources/templates/demo/form/upload.html index 9b8b4a25e..ac348ad0f 100644 --- a/zt-admin/src/main/resources/templates/demo/form/upload.html +++ b/zt-admin/src/main/resources/templates/demo/form/upload.html @@ -70,6 +70,8 @@ $("input[name='" + event.currentTarget.id + "']").val('') }) }); + + diff --git a/zt-common/src/main/java/com/wuzhen/common/utils/file/FileUploadUtils.java b/zt-common/src/main/java/com/wuzhen/common/utils/file/FileUploadUtils.java index af78e7ce6..ed448881d 100644 --- a/zt-common/src/main/java/com/wuzhen/common/utils/file/FileUploadUtils.java +++ b/zt-common/src/main/java/com/wuzhen/common/utils/file/FileUploadUtils.java @@ -117,6 +117,8 @@ public class FileUploadUtils return getPathFileName(baseDir, fileName); } + + /** * 编码文件名 */ @@ -125,8 +127,8 @@ public class FileUploadUtils // return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), // FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); - return StringUtils.format("{}_{}.{}", - FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); + return StringUtils.format("{}.{}", + Seq.getId(Seq.uploadSeqType), getExtension(file)); } public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException diff --git a/zt-common/src/main/java/com/wuzhen/common/utils/uuid/Seq.java b/zt-common/src/main/java/com/wuzhen/common/utils/uuid/Seq.java index 4d50bec80..2f6e076f2 100644 --- a/zt-common/src/main/java/com/wuzhen/common/utils/uuid/Seq.java +++ b/zt-common/src/main/java/com/wuzhen/common/utils/uuid/Seq.java @@ -46,7 +46,7 @@ public class Seq { atomicInt = uploadSeq; } - return getId(atomicInt, 3); + return getId(atomicInt, 5); } /** diff --git a/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java b/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java index 71bef198e..e1983fa02 100644 --- a/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java +++ b/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java @@ -73,6 +73,8 @@ public class ActiveInfo extends BaseEntity { */ private String lpFilesName; + private String fpFilesName; + public String getListLpNames() { return listLpNames; @@ -84,6 +86,16 @@ public class ActiveInfo extends BaseEntity { private String listLpNames ; + public String getListFpNames() { + return listFpNames; + } + + public void setListFpNames(String listFpNames) { + this.listFpNames = listFpNames; + } + + private String listFpNames ; + public String getFpFilesName() { return fpFilesName; @@ -93,10 +105,7 @@ public class ActiveInfo extends BaseEntity { this.fpFilesName = fpFilesName; } - /** - * 首页列表 - */ - private String fpFilesName; + diff --git a/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml b/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml index c51738b6a..ed5ab7202 100644 --- a/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml +++ b/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml @@ -29,7 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select r.id, r.active_title, r.active_desc,r.active_start_date,r.active_end_date, r.active_pic_url, r.active_frist_pic_url,r.is_frist_page, r.active_type, r.status, r.del_flag, r.create_time, r.remark, r.address,r.is_enroll,lp_files_name + select r.id, r.active_title, r.active_desc,r.active_start_date,r.active_end_date, r.active_pic_url, r.active_frist_pic_url,r.is_frist_page, r.active_type, r.status, r.del_flag, r.create_time, r.remark, r.address,r.is_enroll,lp_files_name,fp_files_name from active_info r @@ -95,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" remark = #{remark}, update_by = #{updateBy}, address = #{address}, + lp_files_name = #{lpFilesName}, is_enroll = #{isEnroll}, update_time = sysdate() @@ -106,6 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update active_info active_frist_pic_url = #{activeFirstPicUrl}, + fp_files_name = #{fpFilesName}, is_frist_page = #{isFristPage}, update_by = #{updateBy}, update_time = sysdate()