bug--修复个人中心修改头像错误、素材分组问题、以及上传文件问题
This commit is contained in:
@ -15,4 +15,7 @@ import co.yixiang.annotation.Query;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class YxMaterialQueryCriteria{
|
public class YxMaterialQueryCriteria{
|
||||||
|
|
||||||
|
@Query
|
||||||
|
private String groupId;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class User implements Serializable {
|
|||||||
|
|
||||||
/** 用户头像 */
|
/** 用户头像 */
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private UserAvatar userAvatar;
|
private String avatar;
|
||||||
|
|
||||||
/** 用户角色 */
|
/** 用户角色 */
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
|
@ -46,13 +46,6 @@ public class UserAvatar implements Serializable {
|
|||||||
@TableField(fill= FieldFill.INSERT)
|
@TableField(fill= FieldFill.INSERT)
|
||||||
private Timestamp createTime;
|
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){
|
public void copy(UserAvatar source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
@ -137,8 +137,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, User> imp
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserDto findByName(String userName) {
|
public UserDto findByName(String userName) {
|
||||||
User user = this.getOne(new QueryWrapper<User>().lambda()
|
User user = userMapper.findByName(userName);
|
||||||
.eq(User::getUsername,userName));
|
|
||||||
//用户所属岗位
|
//用户所属岗位
|
||||||
user.setJob(jobService.getById(user.getJobId()));
|
user.setJob(jobService.getById(user.getJobId()));
|
||||||
//用户所属部门
|
//用户所属部门
|
||||||
@ -164,18 +163,23 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, User> imp
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void updateAvatar(MultipartFile multipartFile) {
|
public void updateAvatar(MultipartFile multipartFile) {
|
||||||
User user = this.getOne(new QueryWrapper<User>().eq("username",SecurityUtils.getUsername()));
|
User user = this.getOne(new QueryWrapper<User>().lambda()
|
||||||
UserAvatar userAvatar = user.getUserAvatar();
|
.eq(User::getUsername,SecurityUtils.getUsername()));
|
||||||
|
UserAvatar userAvatar = userAvatarService.getOne(new QueryWrapper<UserAvatar>().lambda()
|
||||||
|
.eq(UserAvatar::getId,user.getId()));
|
||||||
String oldPath = "";
|
String oldPath = "";
|
||||||
if(userAvatar != null){
|
if(userAvatar != null){
|
||||||
oldPath = userAvatar.getPath();
|
oldPath = userAvatar.getPath();
|
||||||
}
|
}
|
||||||
File file = FileUtil.upload(multipartFile, avatar);
|
File file = FileUtil.upload(multipartFile, avatar);
|
||||||
assert file != null;
|
assert file != null;
|
||||||
UserAvatar saveUserAvatar = new UserAvatar(userAvatar,file.getName(), file.getPath(), FileUtil.getSize(multipartFile.getSize()));
|
//UserAvatar saveUserAvatar = new UserAvatar(userAvatar,file.getName(), file.getPath(), FileUtil.getSize(multipartFile.getSize()));
|
||||||
userAvatarService.save(saveUserAvatar);
|
userAvatar.setRealName(file.getName());
|
||||||
user.setUserAvatar(saveUserAvatar);
|
userAvatar.setPath(file.getPath());
|
||||||
this.save(user);
|
userAvatar.setSize(FileUtil.getSize(multipartFile.getSize()));
|
||||||
|
userAvatarService.saveOrUpdate(userAvatar);
|
||||||
|
user.setAvatarId(userAvatar.getId());
|
||||||
|
this.saveOrUpdate(user);
|
||||||
if(StringUtils.isNotBlank(oldPath)){
|
if(StringUtils.isNotBlank(oldPath)){
|
||||||
FileUtil.del(oldPath);
|
FileUtil.del(oldPath);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import co.yixiang.common.mapper.CoreMapper;
|
|||||||
import co.yixiang.modules.system.domain.User;
|
import co.yixiang.modules.system.domain.User;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@ -42,4 +43,12 @@ public interface SysUserMapper extends CoreMapper<User> {
|
|||||||
@Update("update `user` set email = #{email} where username = #{username}")
|
@Update("update `user` set email = #{email} where username = #{username}")
|
||||||
void updateEmail(@Param("email") String email, @Param("username") String 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@ -56,8 +58,8 @@ public class LocalStorageController {
|
|||||||
@Log("新增文件")
|
@Log("新增文件")
|
||||||
@ApiOperation("新增文件")
|
@ApiOperation("新增文件")
|
||||||
@PreAuthorize("@el.check('admin','localStorage:add')")
|
@PreAuthorize("@el.check('admin','localStorage:add')")
|
||||||
public ResponseEntity<Object> create(@Validated @RequestBody LocalStorage resources){
|
public ResponseEntity<Object> create(@RequestParam String name, @RequestParam("file") MultipartFile file){
|
||||||
return new ResponseEntity<>(localStorageService.save(resources),HttpStatus.CREATED);
|
return new ResponseEntity<>(localStorageService.create(name,file),HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ -65,7 +67,7 @@ public class LocalStorageController {
|
|||||||
@ApiOperation("修改文件")
|
@ApiOperation("修改文件")
|
||||||
@PreAuthorize("@el.check('admin','localStorage:edit')")
|
@PreAuthorize("@el.check('admin','localStorage:edit')")
|
||||||
public ResponseEntity<Object> update(@Validated @RequestBody LocalStorage resources){
|
public ResponseEntity<Object> update(@Validated @RequestBody LocalStorage resources){
|
||||||
localStorageService.updateById(resources);
|
localStorageService.saveOrUpdate(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ public class LocalStorageServiceImpl extends BaseServiceImpl<LocalStorageMapper,
|
|||||||
SecurityUtils.getUsername()
|
SecurityUtils.getUsername()
|
||||||
);
|
);
|
||||||
|
|
||||||
return generator.convert(localStorage,LocalStorageDto.class);
|
return generator.convert(this.save(localStorage),LocalStorageDto.class);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
FileUtil.del(file);
|
FileUtil.del(file);
|
||||||
throw e;
|
throw e;
|
||||||
|
Reference in New Issue
Block a user