bug--修复个人中心修改头像错误、素材分组问题、以及上传文件问题

This commit is contained in:
taochengbo
2020-05-25 23:47:54 +08:00
parent d57f89b03d
commit f3f0b248cf
7 changed files with 31 additions and 20 deletions

View File

@ -15,4 +15,7 @@ import co.yixiang.annotation.Query;
*/
@Data
public class YxMaterialQueryCriteria{
@Query
private String groupId;
}

View File

@ -46,7 +46,7 @@ public class User implements Serializable {
/** 用户头像 */
@TableField(exist = false)
private UserAvatar userAvatar;
private String avatar;
/** 用户角色 */
@TableField(exist = false)

View File

@ -46,13 +46,6 @@ public class UserAvatar implements Serializable {
@TableField(fill= FieldFill.INSERT)
private Timestamp createTime;
public UserAvatar(UserAvatar userAvatar,String realName, String path, String size) {
this.id = ObjectUtil.isNotEmpty(userAvatar) ? userAvatar.getId() : null;
this.realName = realName;
this.path = path;
this.size = size;
}
public void copy(UserAvatar source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));

View File

@ -137,8 +137,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, User> imp
*/
@Override
public UserDto findByName(String userName) {
User user = this.getOne(new QueryWrapper<User>().lambda()
.eq(User::getUsername,userName));
User user = userMapper.findByName(userName);
//用户所属岗位
user.setJob(jobService.getById(user.getJobId()));
//用户所属部门
@ -164,18 +163,23 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, User> imp
*/
@Override
public void updateAvatar(MultipartFile multipartFile) {
User user = this.getOne(new QueryWrapper<User>().eq("username",SecurityUtils.getUsername()));
UserAvatar userAvatar = user.getUserAvatar();
User user = this.getOne(new QueryWrapper<User>().lambda()
.eq(User::getUsername,SecurityUtils.getUsername()));
UserAvatar userAvatar = userAvatarService.getOne(new QueryWrapper<UserAvatar>().lambda()
.eq(UserAvatar::getId,user.getId()));
String oldPath = "";
if(userAvatar != null){
oldPath = userAvatar.getPath();
}
File file = FileUtil.upload(multipartFile, avatar);
assert file != null;
UserAvatar saveUserAvatar = new UserAvatar(userAvatar,file.getName(), file.getPath(), FileUtil.getSize(multipartFile.getSize()));
userAvatarService.save(saveUserAvatar);
user.setUserAvatar(saveUserAvatar);
this.save(user);
//UserAvatar saveUserAvatar = new UserAvatar(userAvatar,file.getName(), file.getPath(), FileUtil.getSize(multipartFile.getSize()));
userAvatar.setRealName(file.getName());
userAvatar.setPath(file.getPath());
userAvatar.setSize(FileUtil.getSize(multipartFile.getSize()));
userAvatarService.saveOrUpdate(userAvatar);
user.setAvatarId(userAvatar.getId());
this.saveOrUpdate(user);
if(StringUtils.isNotBlank(oldPath)){
FileUtil.del(oldPath);
}

View File

@ -12,6 +12,7 @@ import co.yixiang.common.mapper.CoreMapper;
import co.yixiang.modules.system.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
@ -42,4 +43,12 @@ public interface SysUserMapper extends CoreMapper<User> {
@Update("update `user` set email = #{email} where username = #{username}")
void updateEmail(@Param("email") String email, @Param("username") String username);
/**
* 根据用户名查询用户信息
* @param userName 用户名
*/
@Select("SELECT u.id,u.nick_name,u.sex,u.dept_id,u.enabled,u.create_time,u.phone,u.email,u.job_id ,u.`password` ,u.username,ua.real_name avatar FROM `user` " +
" u LEFT JOIN user_avatar ua ON u.avatar_id = ua.id WHERE u.username = #{username}")
User findByName(String userName);
}

View File

@ -19,6 +19,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
@ -56,8 +58,8 @@ public class LocalStorageController {
@Log("新增文件")
@ApiOperation("新增文件")
@PreAuthorize("@el.check('admin','localStorage:add')")
public ResponseEntity<Object> create(@Validated @RequestBody LocalStorage resources){
return new ResponseEntity<>(localStorageService.save(resources),HttpStatus.CREATED);
public ResponseEntity<Object> create(@RequestParam String name, @RequestParam("file") MultipartFile file){
return new ResponseEntity<>(localStorageService.create(name,file),HttpStatus.CREATED);
}
@PutMapping
@ -65,7 +67,7 @@ public class LocalStorageController {
@ApiOperation("修改文件")
@PreAuthorize("@el.check('admin','localStorage:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody LocalStorage resources){
localStorageService.updateById(resources);
localStorageService.saveOrUpdate(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

View File

@ -101,7 +101,7 @@ public class LocalStorageServiceImpl extends BaseServiceImpl<LocalStorageMapper,
SecurityUtils.getUsername()
);
return generator.convert(localStorage,LocalStorageDto.class);
return generator.convert(this.save(localStorage),LocalStorageDto.class);
}catch (Exception e){
FileUtil.del(file);
throw e;