diff --git a/null/upload/2022/03/20/微信图片_20220301134917_20220320113629A001.jpg b/null/upload/2022/03/20/微信图片_20220301134917_20220320113629A001.jpg new file mode 100644 index 000000000..cdbc7662c Binary files /dev/null and b/null/upload/2022/03/20/微信图片_20220301134917_20220320113629A001.jpg differ diff --git a/null/upload/2022/03/20/微信图片_20220301134917_20220320113655A002.jpg b/null/upload/2022/03/20/微信图片_20220301134917_20220320113655A002.jpg new file mode 100644 index 000000000..cdbc7662c Binary files /dev/null and b/null/upload/2022/03/20/微信图片_20220301134917_20220320113655A002.jpg differ 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 4239ac409..f4c023cd6 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 @@ -1,6 +1,7 @@ package com.wuzhen.web.controller.busi; import com.wuzhen.common.annotation.Log; +import com.wuzhen.common.config.RuoYiConfig; import com.wuzhen.common.core.controller.BaseController; import com.wuzhen.common.core.domain.AjaxResult; import com.wuzhen.common.core.page.TableDataInfo; @@ -15,6 +16,10 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; import java.util.List; /** @@ -79,14 +84,29 @@ public class ActiveInfoController extends BaseController @ResponseBody public AjaxResult addSave(@Validated ActiveInfo activeInfo) { -// if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(activeInfoService.checkNameUnique(role))) -// { -// return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); -// } -// else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) -// { -// return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); -// } + MultipartFile file = activeInfo.getActivePic(); + // 获取上传文件名 + String filename = file.getOriginalFilename(); + if (!"".equals(filename)){ + + // 定义上传文件保存路径 + String path = RuoYiConfig.getUploadPath(); + // 新建文件 + 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.setActivePicUrl(picUrl); + } + activeInfo.setCreateBy(getLoginName()); AuthorizationUtils.clearAllCachedAuthorizationInfo(); return toAjax(activeInfoService.insertActive(activeInfo)); 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 277ff963a..bf1358ebd 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 @@ -28,7 +28,7 @@ import com.wuzhen.common.utils.file.FileUtils; * @author zhengzheng */ @Controller -@RequestMapping("/common") +@RequestMapping("/common/upload") public class CommonController { private static final Logger log = LoggerFactory.getLogger(CommonController.class); diff --git a/zt-admin/src/main/resources/application.yml b/zt-admin/src/main/resources/application.yml index d47893636..bc8f2cd9f 100644 --- a/zt-admin/src/main/resources/application.yml +++ b/zt-admin/src/main/resources/application.yml @@ -1,5 +1,5 @@ # 项目相关配置 -ruoyi: +wuzhen: # 名称 name: 乌镇展厅小程序 # 版本 @@ -7,7 +7,7 @@ ruoyi: # 版权年份 copyrightYear: 2022 # 实例演示开关 - demoEnabled: true + demoEnabled: false # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) profile: D:/ruoyi/uploadPath # 获取ip地址开关 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 fd4fa45c7..a24c67761 100644 --- a/zt-admin/src/main/resources/templates/active/info/add.html +++ b/zt-admin/src/main/resources/templates/active/info/add.html @@ -7,7 +7,7 @@
-
+
@@ -33,8 +33,11 @@
- + + +
+
@@ -93,28 +96,30 @@ } function add() { - var activeTitle = $("input[name='activeTitle']").val(); - var activeDesc =$("textarea[name='activeDesc']").val(); - var activeType = $("select[name='activeType']").val(); - var activePic = $("input[name='activePic']").val(); - var activeStartDate = $("input[name='activeStartDate']").val(); - var activeEndDate = $("input[name='activeEndDate']").val(); - var status = $("input[id='status']").is(':checked') == true ? 0 : 1; - var remark = $("input[name='remark']").val(); + + + + + + + + + + var formData = new FormData($("#form-role-add")[0]) + formData.append('activePic', activePic); + + + + + + $.ajax({ - cache : true, + cache: false, + contentType: false, + processData: false, type : "POST", url : ctx + "active/info/add", - data : { - "activeTitle": activeTitle, - "activeDesc": activeDesc, - "activeType": activeType, - "activePic": activePic, - "activeStartDate": activeStartDate, - "activeEndDate": activeEndDate, - "status": status, - "remark": remark - }, + data : formData, async : false, error : function(request) { $.modal.alertError("系统错误"); 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 0ab4b12ef..262a7bdbd 100644 --- a/zt-admin/src/main/resources/templates/active/info/edit.html +++ b/zt-admin/src/main/resources/templates/active/info/edit.html @@ -59,7 +59,7 @@
- +
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 65f943c48..7904ddb11 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 @@ -6,6 +6,7 @@ import com.wuzhen.common.annotation.Excel.ColumnType; import com.wuzhen.common.core.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import org.springframework.web.multipart.MultipartFile; /** * 活动信息 active_info @@ -59,7 +60,15 @@ public class ActiveInfo extends BaseEntity { * 活动图片 */ @Excel(name = "活动图片") - private String activePic; + private MultipartFile activePic; + + + + /** + * 活动图片地址 + */ + @Excel(name = "活动图片地址") + private String activePicUrl; /** * 推荐人编号 @@ -126,11 +135,11 @@ public class ActiveInfo extends BaseEntity { this.activeType = activeType; } - public String getActivePic() { + public MultipartFile getActivePic() { return activePic; } - public void setActivePic(String activePic) { + public void setActivePic(MultipartFile activePic) { this.activePic = activePic; } @@ -142,6 +151,15 @@ public class ActiveInfo extends BaseEntity { this.status = status; } + + public String getActivePicUrl() { + return activePicUrl; + } + + public void setActivePicUrl(String activePicUrl) { + this.activePicUrl = activePicUrl; + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) diff --git a/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml b/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml index fd12cac72..cff82d4e0 100644 --- a/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml +++ b/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml @@ -11,7 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -23,7 +23,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, r.active_type, r.status, r.del_flag, r.create_time, r.remark + select r.id, r.active_title, r.active_desc,r.active_start_date,r.active_end_date, r.active_pic_url, r.active_type, r.status, r.del_flag, r.create_time, r.remark from active_info r @@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" active_start_date = #{activeStartDate}, active_end_date = #{activeEndDate}, status = #{status}, - active_pic = #{activePic}, + active_pic = #{active_pic_url}, active_type = #{activeType}, remark = #{remark}, update_by = #{updateBy}, @@ -100,7 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" active_start_date, active_end_date, active_type, - active_pic, + active_pic_url, status, remark, create_by, @@ -111,7 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{activeStartDate}, #{activeEndDate}, #{activeType}, - #{activePic}, + #{activePicUrl}, #{status}, #{remark}, #{createBy},