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 2e792a8a0..aca78ae5a 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 @@ -12,6 +12,8 @@ import com.wuzhen.framework.shiro.util.AuthorizationUtils; import com.wuzhen.system.domain.ActiveInfo; import com.wuzhen.system.service.IActiveInfoService; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; @@ -19,10 +21,7 @@ import org.springframework.ui.ModelMap; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletRequest; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.List; @@ -35,6 +34,9 @@ import java.util.List; @RequestMapping("/active/info") public class ActiveInfoController extends BaseController { + + private static final Logger logger = LoggerFactory.getLogger(ActiveInfoController.class); + private String prefix = "active/info"; @Autowired @@ -99,34 +101,10 @@ public class ActiveInfoController extends BaseController @ResponseBody public AjaxResult addSave(@Validated ActiveInfo activeInfo) { - MultipartFile[] files = activeInfo.getActivePic(); - MultipartFile file = files[0]; - // 获取上传文件名 - String filename = files[0].getOriginalFilename(); - if (!"".equals(filename)){ - - // 定义上传文件保存路径 - String path = RuoYiConfig.getLPUploadPath(); - // 新建文件 - 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(lp+filename); - } - + logger.info(activeInfo.toString()); activeInfo.setCreateBy(getLoginName()); AuthorizationUtils.clearAllCachedAuthorizationInfo(); return toAjax(activeInfoService.insertActive(activeInfo)); - } /** @@ -207,35 +185,7 @@ public class ActiveInfoController extends BaseController return toAjax(activeInfoService.updateActive(activeInfo)); } -// /** -// * 角色分配数据权限 -// */ -// @GetMapping("/authDataScope/{roleId}") -// public String authDataScope(@PathVariable("roleId") Long roleId, ModelMap mmap) -// { -// mmap.put("role", roleService.selectRoleById(roleId)); -// return prefix + "/dataScope"; -// } -// /** -// * 保存角色分配数据权限 -// */ -// @RequiresPermissions("system:role:edit") -// @Log(title = "角色管理", businessType = BusinessType.UPDATE) -// @PostMapping("/authDataScope") -// @ResponseBody -// public AjaxResult authDataScopeSave(SysRole role) -// { -// roleService.checkRoleAllowed(role); -// roleService.checkRoleDataScope(role.getRoleId()); -// role.setUpdateBy(getLoginName()); -// if (roleService.authDataScope(role) > 0) -// { -// setSysUser(userService.selectUserById(getUserId())); -// return success(); -// } -// return error(); -// } @RequiresPermissions("active:info:remove") @Log(title = "活动管理", businessType = BusinessType.DELETE) @@ -246,34 +196,7 @@ public class ActiveInfoController extends BaseController return toAjax(activeInfoService.deleteActiveByIds(ids)); } - /** -// * 校验角色名称 -// */ -// @PostMapping("/checkRoleNameUnique") -// @ResponseBody -// public String checkRoleNameUnique(SysRole role) -// { -// return roleService.checkRoleNameUnique(role); -// } -// -// /** -// * 校验角色权限 -// */ -// @PostMapping("/checkRoleKeyUnique") -// @ResponseBody -// public String checkRoleKeyUnique(SysRole role) -// { -// return roleService.checkRoleKeyUnique(role); -// } -// -// /** -// * 选择菜单树 -// */ -// @GetMapping("/selectMenuTree") -// public String selectMenuTree() -// { -// return prefix + "/tree"; -// } + /** * 状态修改 @@ -287,157 +210,7 @@ public class ActiveInfoController extends BaseController return toAjax(activeInfoService.updateActive(activeInfo)); } -// /** -// * 分配用户 -// */ -// @RequiresPermissions("system:role:edit") -// @GetMapping("/authUser/{roleId}") -// public String authUser(@PathVariable("roleId") Long roleId, ModelMap mmap) -// { -// mmap.put("role", roleService.selectRoleById(roleId)); -// return prefix + "/authUser"; -// } -// /** -// * 查询已分配用户角色列表 -// */ -// @RequiresPermissions("system:role:list") -// @PostMapping("/authUser/allocatedList") -// @ResponseBody -// public TableDataInfo allocatedList(SysUser user) -// { -// startPage(); -// List list = userService.selectAllocatedList(user); -// return getDataTable(list); -// } - -// /** -// * 取消授权 -// */ -// @RequiresPermissions("system:role:edit") -// @Log(title = "角色管理", businessType = BusinessType.GRANT) -// @PostMapping("/authUser/cancel") -// @ResponseBody -// public AjaxResult cancelAuthUser(SysUserRole userRole) -// { -// return toAjax(roleService.deleteAuthUser(userRole)); -// } - - /** - * 批量取消授权 - */ -// @RequiresPermissions("system:role:edit") -// @Log(title = "角色管理", businessType = BusinessType.GRANT) -// @PostMapping("/authUser/cancelAll") -// @ResponseBody -// public AjaxResult cancelAuthUserAll(Long roleId, String userIds) -// { -// return toAjax(roleService.deleteAuthUsers(roleId, userIds)); -// } - -// /** -// * 选择用户 -// */ -// @GetMapping("/authUser/selectUser/{roleId}") -// public String selectUser(@PathVariable("roleId") Long roleId, ModelMap mmap) -// { -// mmap.put("role", roleService.selectRoleById(roleId)); -// return prefix + "/selectUser"; -// } - -// /** -// * 查询未分配用户角色列表 -// */ -// @RequiresPermissions("system:role:list") -// @PostMapping("/authUser/unallocatedList") -// @ResponseBody -// public TableDataInfo unallocatedList(SysUser user) -// { -// startPage(); -// List list = userService.selectUnallocatedList(user); -// return getDataTable(list); -// } - -// /** -// * 批量选择用户授权 -// */ -// @RequiresPermissions("system:role:edit") -// @Log(title = "角色管理", businessType = BusinessType.GRANT) -// @PostMapping("/authUser/selectAll") -// @ResponseBody -// public AjaxResult selectAuthUserAll(Long roleId, String userIds) -// { -// roleService.checkRoleDataScope(roleId); -// return toAjax(roleService.insertAuthUsers(roleId, userIds)); -// } - - - - public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception { - File targetFile = new File(filePath); - if (!targetFile.exists()) { - targetFile.mkdirs(); - } - FileOutputStream out = new FileOutputStream(filePath+"/"+ fileName); - out.write(file); - out.flush(); - out.close(); - } - - //处理文件上传 - @ResponseBody //返回json数据 - @RequestMapping(value = "upload", method = RequestMethod.POST) - public JSONObject uploadImg( @RequestPart("myFile") MultipartFile[] files) { - JSONObject jo = new JSONObject();//实例化json数据 - String fileNameArr[] =null; - if (files==null||files.length==0) { - jo.put("success", 0); - jo.put("fileName",new String[]{}); - }else { - fileNameArr=new String[files.length]; - } - for ( int i =0 ;i files) throws Exception + public AjaxResult uploadFilesLp(List files) throws Exception { try { // 上传文件路径 - String filePath = RuoYiConfig.getUploadPath(); + String filePath = RuoYiConfig.getLPUploadPath(); + 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()); + } + 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)); + return ajax; + } + catch (Exception e) + { + return AjaxResult.error(e.getMessage()); + } + } + + + /** + * 通用上传请求(多个) + */ + @PostMapping("/uploadsFp") + @ResponseBody + public AjaxResult uploadFilesFp(List files) throws Exception + { + try + { + // 上传文件路径 + String filePath = RuoYiConfig.getFPUploadPath(); List urls = new ArrayList(); List fileNames = new ArrayList(); List newFileNames = new ArrayList(); 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 5e34cf552..1e1f630da 100644 --- a/zt-admin/src/main/resources/templates/active/info/add.html +++ b/zt-admin/src/main/resources/templates/active/info/add.html @@ -4,10 +4,13 @@ + +
+
@@ -38,25 +41,13 @@
+
+
- - - -

- - - -
- -
-
- - - - - +
+
@@ -111,6 +102,7 @@ + + 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 ec3ae7853..af78e7ce6 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 @@ -122,7 +122,10 @@ public class FileUploadUtils */ public static final String extractFilename(MultipartFile file) { - return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), +// 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)); } 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 c1e64c7c2..1b87a5a19 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 @@ -56,10 +56,32 @@ public class ActiveInfo extends BaseEntity { @Excel(name = "活动类型") private String activeType; + + public String getLpFilesName() { + return lpFilesName; + } + + public void setLpFilesName(String lpFilesName) { + this.lpFilesName = lpFilesName; + } + /** - * 活动图片 + * 活动列表 */ - private MultipartFile[] activePic; + private String lpFilesName; + + public String getFpFilesName() { + return fpFilesName; + } + + public void setFpFilesName(String fpFilesName) { + this.fpFilesName = fpFilesName; + } + + /** + * 首页列表 + */ + private String fpFilesName; @@ -202,13 +224,13 @@ public class ActiveInfo extends BaseEntity { this.activeType = activeType; } - public MultipartFile[] getActivePic() { - return activePic; - } - - public void setActivePic(MultipartFile[] activePic) { - this.activePic = activePic; - } +// public MultipartFile[] getActivePic() { +// return activePic; +// } +// +// public void setActivePic(MultipartFile[] activePic) { +// this.activePic = activePic; +// } public String getStatus() { return status; @@ -247,11 +269,13 @@ public class ActiveInfo extends BaseEntity { .append("activeStartDate", getActiveStartDate()) .append("activeEndDate", getActiveEndDate()) .append("activeType", getActiveType()) - .append("activePic", getActivePic()) .append("createBy", getCreateBy()) .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) .append("updateTime", getUpdateTime()) + .append("fpFilesName", getFpFilesName()) + .append("lpFilesName", getLpFilesName()) + .append("remark", getRemark()) .append("address", getAddress()) .toString(); diff --git a/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml b/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml index bfcffe3b9..dc5204364 100644 --- a/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml +++ b/zt-system/src/main/resources/mapper/system/ActiveInfoMapper.xml @@ -23,6 +23,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -123,7 +125,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" remark, create_by, address, - is_enroll + lp_files_name, + fp_files_name, + is_enroll, create_time )values( #{activeTitle}, @@ -136,6 +140,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{remark}, #{createBy}, #{address}, + #{lpFilesName}, + #{fpFilesName}, #{isEnroll}, sysdate() )