From 25dc1c9acf07b38cc59986982fa5b404acfe55fe Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Mon, 1 Jun 2020 06:53:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=85=81=E8=AE=B8=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B4=BB=E5=8A=A8=E5=9B=BE=E7=89=87=202.?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E7=94=A8=E6=88=B7=E6=9B=B4=E6=96=B0=E5=A4=B4?= =?UTF-8?q?=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../share/help/controller/ManagerController.java | 4 ++-- .../share/help/controller/UserController.java | 2 +- .../java/com/share/help/dao/ActivityMapper.java | 2 +- .../java/com/share/help/form/UpdateUserForm.java | 11 +++++++++++ .../help/form/manager/UpdateActivityForm.java | 12 ++++++++++++ .../com/share/help/service/ManagerService.java | 16 +++++++++++++++- .../java/com/share/help/service/UserService.java | 11 ++++++++++- src/main/resources/mapping/ActivityMapper.xml | 5 ++++- .../com/share/help/HelpApplicationTests.java | 2 +- 9 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/share/help/controller/ManagerController.java b/src/main/java/com/share/help/controller/ManagerController.java index ee7cf69..58e8ac6 100644 --- a/src/main/java/com/share/help/controller/ManagerController.java +++ b/src/main/java/com/share/help/controller/ManagerController.java @@ -114,7 +114,7 @@ public class ManagerController { * @param updateUserForm 更新用户表单 * @return 返回更新结果 */ - @PostMapping(Constants.MANAGER_INTERFACE_UPDATE_USER) + @PutMapping(Constants.MANAGER_INTERFACE_UPDATE_USER) public JSONResponse update(UpdateUserForm updateUserForm){ if(updateUserForm.getUserId()!=null){ return userService.update(updateUserForm); @@ -143,7 +143,7 @@ public class ManagerController { * @param activityId 活动id * @return 返回更新结果 */ - @PostMapping(Constants.MANAGER_INTERFACE_UPDATE_ACTIVITY) + @PutMapping(Constants.MANAGER_INTERFACE_UPDATE_ACTIVITY) public JSONResponse updateActivity(UpdateActivityForm updateActivityForm,@PathVariable Long activityId){ if(activityId!=null){ updateActivityForm.setActivityId(activityId); diff --git a/src/main/java/com/share/help/controller/UserController.java b/src/main/java/com/share/help/controller/UserController.java index e4de816..b4360fc 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -103,7 +103,7 @@ public class UserController { * @param userId 用户id * @return 返回更新结果 */ - @PostMapping(Constants.USER_INTERFACE_UPDATE) + @PutMapping(Constants.USER_INTERFACE_UPDATE) public JSONResponse update(UpdateUserForm updateUserForm,@CookieValue(Constants.USER_COOKIE) String userId){ if(userId!=null){ updateUserForm.setUserId(userId); diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index bb25eac..fd10c7e 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -72,7 +72,7 @@ public interface ActivityMapper { Page> countActivity(@Param("pageSize") Integer pageSize); //修改活动信息 - boolean updateActivity(@Param("activityId") Long activityId,@Param("title") String title,@Param("content") String content); + boolean updateActivity(@Param("activityId") Long activityId, @Param("title") String title, @Param("content") String content,@Param("imageName") String imageName); //查询活跃用户 List queryActiveUser(@Param("userId") String userId,@Param("serviceAddress") String serviceAddress); diff --git a/src/main/java/com/share/help/form/UpdateUserForm.java b/src/main/java/com/share/help/form/UpdateUserForm.java index 0dd4941..2d12001 100644 --- a/src/main/java/com/share/help/form/UpdateUserForm.java +++ b/src/main/java/com/share/help/form/UpdateUserForm.java @@ -1,5 +1,7 @@ package com.share.help.form; +import org.springframework.web.multipart.MultipartFile; + public class UpdateUserForm { private String userId; private String name; @@ -13,6 +15,15 @@ public class UpdateUserForm { private String email; private String info; + private MultipartFile activityImgFile; + + public MultipartFile getActivityImgFile() { + return activityImgFile; + } + + public void setActivityImgFile(MultipartFile activityImgFile) { + this.activityImgFile = activityImgFile; + } public String getUserId() { return userId; diff --git a/src/main/java/com/share/help/form/manager/UpdateActivityForm.java b/src/main/java/com/share/help/form/manager/UpdateActivityForm.java index ebd2645..d0d2b23 100644 --- a/src/main/java/com/share/help/form/manager/UpdateActivityForm.java +++ b/src/main/java/com/share/help/form/manager/UpdateActivityForm.java @@ -1,5 +1,7 @@ package com.share.help.form.manager; +import org.springframework.web.multipart.MultipartFile; + /** * 管理员修改活动信息表单 */ @@ -10,6 +12,16 @@ public class UpdateActivityForm { private String content; + private MultipartFile activityImgFile; + + public MultipartFile getActivityImgFile() { + return activityImgFile; + } + + public void setActivityImgFile(MultipartFile activityImgFile) { + this.activityImgFile = activityImgFile; + } + public Long getActivityId() { return activityId; } diff --git a/src/main/java/com/share/help/service/ManagerService.java b/src/main/java/com/share/help/service/ManagerService.java index 5966197..f4f0db0 100644 --- a/src/main/java/com/share/help/service/ManagerService.java +++ b/src/main/java/com/share/help/service/ManagerService.java @@ -41,6 +41,9 @@ public class ManagerService { @Autowired private ActivityMapper activityMapper; + @Autowired + private ImageService imageService; + /** * 登录 * @param managerLoginForm 登录表单 @@ -153,7 +156,18 @@ public class ManagerService { * @return 返回更新结果 */ public JSONResponse updateActivity(UpdateActivityForm updateActivityForm) { - if(activityMapper.updateActivity(updateActivityForm.getActivityId(),updateActivityForm.getTitle(),updateActivityForm.getContent())){ + + String imageName = null; + if(updateActivityForm.getActivityImgFile()!=null) { + //保存活动背景图 + imageName = imageService.saveImg(updateActivityForm.getActivityImgFile()); + if (imageName == null) { + logger.error("活动背景图保存失败"); + return new JSONResponse<>(DefaultRes.fail, Result.FAIL); + } + } + + if(activityMapper.updateActivity(updateActivityForm.getActivityId(),updateActivityForm.getTitle(),updateActivityForm.getContent(),imageName)){ return new JSONResponse<>(DefaultRes.ok,Result.OK); }else{ return new JSONResponse<>(DefaultRes.fail,Result.FAIL); diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index 6901682..9b86388 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -149,7 +149,6 @@ public class UserService{ UserEntity userEntity=new UserEntity(); userEntity.setUserId(updateUserForm.getUserId()); userEntity.setName(updateUserForm.getName()); - userEntity.setHeadImg(updateUserForm.getHeadImg()); userEntity.setAddress(updateUserForm.getAddress()); userEntity.setServiceAddress(updateUserForm.getServiceAddress()); userEntity.setUserType(updateUserForm.getUserType()); @@ -159,6 +158,16 @@ public class UserService{ userEntity.setAge(updateUserForm.getAge()); userEntity.setSex(updateUserForm.getSex()); + if(updateUserForm.getActivityImgFile()!=null) { + //保存头像 + String imageName = imageService.saveImg(updateUserForm.getActivityImgFile()); + if (imageName == null) { + logger.error("更新头像失败"); + return new JSONResponse<>(DefaultRes.fail, Result.FAIL); + } + userEntity.setHeadImg(imageName); + } + if(userMapper.update(userEntity)){ return new JSONResponse<>(DefaultRes.ok,Result.OK); }else{ diff --git a/src/main/resources/mapping/ActivityMapper.xml b/src/main/resources/mapping/ActivityMapper.xml index fee2066..b38f6e8 100644 --- a/src/main/resources/mapping/ActivityMapper.xml +++ b/src/main/resources/mapping/ActivityMapper.xml @@ -124,7 +124,10 @@ and activity_id not in(select activity_id from activity_history) order by seek_ title=#{title}, - content=#{content} + content=#{content}, + + + activity_img=#{imageName} where activity_id=#{activityId} diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 67010da..9ec50bd 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -312,7 +312,7 @@ class HelpApplicationTests { //更新活动信息 @Test public void testUpdateActivity(){ - Assertions.assertTrue(activityMapper.updateActivity(66L,"44","")); + Assertions.assertTrue(activityMapper.updateActivity(66L,"44","", imageName)); } @Test