1.允许管理员更新活动图片

2.允许用户更新头像
master
pan 5 years ago
parent 1fc0b98ae9
commit 25dc1c9acf
  1. 4
      src/main/java/com/share/help/controller/ManagerController.java
  2. 2
      src/main/java/com/share/help/controller/UserController.java
  3. 2
      src/main/java/com/share/help/dao/ActivityMapper.java
  4. 11
      src/main/java/com/share/help/form/UpdateUserForm.java
  5. 12
      src/main/java/com/share/help/form/manager/UpdateActivityForm.java
  6. 16
      src/main/java/com/share/help/service/ManagerService.java
  7. 11
      src/main/java/com/share/help/service/UserService.java
  8. 5
      src/main/resources/mapping/ActivityMapper.xml
  9. 2
      src/test/java/com/share/help/HelpApplicationTests.java

@ -114,7 +114,7 @@ public class ManagerController {
* @param updateUserForm 更新用户表单 * @param updateUserForm 更新用户表单
* @return 返回更新结果 * @return 返回更新结果
*/ */
@PostMapping(Constants.MANAGER_INTERFACE_UPDATE_USER) @PutMapping(Constants.MANAGER_INTERFACE_UPDATE_USER)
public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm){ public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm){
if(updateUserForm.getUserId()!=null){ if(updateUserForm.getUserId()!=null){
return userService.update(updateUserForm); return userService.update(updateUserForm);
@ -143,7 +143,7 @@ public class ManagerController {
* @param activityId 活动id * @param activityId 活动id
* @return 返回更新结果 * @return 返回更新结果
*/ */
@PostMapping(Constants.MANAGER_INTERFACE_UPDATE_ACTIVITY) @PutMapping(Constants.MANAGER_INTERFACE_UPDATE_ACTIVITY)
public JSONResponse<DefaultRes,Void> updateActivity(UpdateActivityForm updateActivityForm,@PathVariable Long activityId){ public JSONResponse<DefaultRes,Void> updateActivity(UpdateActivityForm updateActivityForm,@PathVariable Long activityId){
if(activityId!=null){ if(activityId!=null){
updateActivityForm.setActivityId(activityId); updateActivityForm.setActivityId(activityId);

@ -103,7 +103,7 @@ public class UserController {
* @param userId 用户id * @param userId 用户id
* @return 返回更新结果 * @return 返回更新结果
*/ */
@PostMapping(Constants.USER_INTERFACE_UPDATE) @PutMapping(Constants.USER_INTERFACE_UPDATE)
public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm,@CookieValue(Constants.USER_COOKIE) String userId){ public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(userId!=null){ if(userId!=null){
updateUserForm.setUserId(userId); updateUserForm.setUserId(userId);

@ -72,7 +72,7 @@ public interface ActivityMapper {
Page<List<ManagerActivityRes>> countActivity(@Param("pageSize") Integer pageSize); Page<List<ManagerActivityRes>> 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<ActiveUserRes> queryActiveUser(@Param("userId") String userId,@Param("serviceAddress") String serviceAddress); List<ActiveUserRes> queryActiveUser(@Param("userId") String userId,@Param("serviceAddress") String serviceAddress);

@ -1,5 +1,7 @@
package com.share.help.form; package com.share.help.form;
import org.springframework.web.multipart.MultipartFile;
public class UpdateUserForm { public class UpdateUserForm {
private String userId; private String userId;
private String name; private String name;
@ -13,6 +15,15 @@ public class UpdateUserForm {
private String email; private String email;
private String info; private String info;
private MultipartFile activityImgFile;
public MultipartFile getActivityImgFile() {
return activityImgFile;
}
public void setActivityImgFile(MultipartFile activityImgFile) {
this.activityImgFile = activityImgFile;
}
public String getUserId() { public String getUserId() {
return userId; return userId;

@ -1,5 +1,7 @@
package com.share.help.form.manager; package com.share.help.form.manager;
import org.springframework.web.multipart.MultipartFile;
/** /**
* 管理员修改活动信息表单 * 管理员修改活动信息表单
*/ */
@ -10,6 +12,16 @@ public class UpdateActivityForm {
private String content; private String content;
private MultipartFile activityImgFile;
public MultipartFile getActivityImgFile() {
return activityImgFile;
}
public void setActivityImgFile(MultipartFile activityImgFile) {
this.activityImgFile = activityImgFile;
}
public Long getActivityId() { public Long getActivityId() {
return activityId; return activityId;
} }

@ -41,6 +41,9 @@ public class ManagerService {
@Autowired @Autowired
private ActivityMapper activityMapper; private ActivityMapper activityMapper;
@Autowired
private ImageService imageService;
/** /**
* 登录 * 登录
* @param managerLoginForm 登录表单 * @param managerLoginForm 登录表单
@ -153,7 +156,18 @@ public class ManagerService {
* @return 返回更新结果 * @return 返回更新结果
*/ */
public JSONResponse<DefaultRes, Void> updateActivity(UpdateActivityForm updateActivityForm) { public JSONResponse<DefaultRes, Void> 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); return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{ }else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);

@ -149,7 +149,6 @@ public class UserService{
UserEntity userEntity=new UserEntity(); UserEntity userEntity=new UserEntity();
userEntity.setUserId(updateUserForm.getUserId()); userEntity.setUserId(updateUserForm.getUserId());
userEntity.setName(updateUserForm.getName()); userEntity.setName(updateUserForm.getName());
userEntity.setHeadImg(updateUserForm.getHeadImg());
userEntity.setAddress(updateUserForm.getAddress()); userEntity.setAddress(updateUserForm.getAddress());
userEntity.setServiceAddress(updateUserForm.getServiceAddress()); userEntity.setServiceAddress(updateUserForm.getServiceAddress());
userEntity.setUserType(updateUserForm.getUserType()); userEntity.setUserType(updateUserForm.getUserType());
@ -159,6 +158,16 @@ public class UserService{
userEntity.setAge(updateUserForm.getAge()); userEntity.setAge(updateUserForm.getAge());
userEntity.setSex(updateUserForm.getSex()); 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)){ if(userMapper.update(userEntity)){
return new JSONResponse<>(DefaultRes.ok,Result.OK); return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{ }else{

@ -124,7 +124,10 @@ and activity_id not in(select activity_id from activity_history) order by seek_
title=#{title}, title=#{title},
</if> </if>
<if test="content!=null and content!=''"> <if test="content!=null and content!=''">
content=#{content} content=#{content},
</if>
<if test="imageName!=null and imageName!=''">
activity_img=#{imageName}
</if> </if>
</set> </set>
where activity_id=#{activityId} where activity_id=#{activityId}

@ -312,7 +312,7 @@ class HelpApplicationTests {
//更新活动信息 //更新活动信息
@Test @Test
public void testUpdateActivity(){ public void testUpdateActivity(){
Assertions.assertTrue(activityMapper.updateActivity(66L,"44","")); Assertions.assertTrue(activityMapper.updateActivity(66L,"44","", imageName));
} }
@Test @Test

Loading…
Cancel
Save