diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxMaterialQueryCriteria.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxMaterialQueryCriteria.java index 574928fc..9f33bf25 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxMaterialQueryCriteria.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxMaterialQueryCriteria.java @@ -15,4 +15,7 @@ import co.yixiang.annotation.Query; */ @Data public class YxMaterialQueryCriteria{ + + @Query + private String groupId; } diff --git a/yshop-system/src/main/java/co/yixiang/modules/system/domain/User.java b/yshop-system/src/main/java/co/yixiang/modules/system/domain/User.java index 46ff2278..33b908c4 100644 --- a/yshop-system/src/main/java/co/yixiang/modules/system/domain/User.java +++ b/yshop-system/src/main/java/co/yixiang/modules/system/domain/User.java @@ -46,7 +46,7 @@ public class User implements Serializable { /** 用户头像 */ @TableField(exist = false) - private UserAvatar userAvatar; + private String avatar; /** 用户角色 */ @TableField(exist = false) diff --git a/yshop-system/src/main/java/co/yixiang/modules/system/domain/UserAvatar.java b/yshop-system/src/main/java/co/yixiang/modules/system/domain/UserAvatar.java index 7b249364..f5c8f46c 100644 --- a/yshop-system/src/main/java/co/yixiang/modules/system/domain/UserAvatar.java +++ b/yshop-system/src/main/java/co/yixiang/modules/system/domain/UserAvatar.java @@ -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)); diff --git a/yshop-system/src/main/java/co/yixiang/modules/system/service/impl/SysUserServiceImpl.java b/yshop-system/src/main/java/co/yixiang/modules/system/service/impl/SysUserServiceImpl.java index c7fb68f1..916f9048 100644 --- a/yshop-system/src/main/java/co/yixiang/modules/system/service/impl/SysUserServiceImpl.java +++ b/yshop-system/src/main/java/co/yixiang/modules/system/service/impl/SysUserServiceImpl.java @@ -137,8 +137,7 @@ public class SysUserServiceImpl extends BaseServiceImpl imp */ @Override public UserDto findByName(String userName) { - User user = this.getOne(new QueryWrapper().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 imp */ @Override public void updateAvatar(MultipartFile multipartFile) { - User user = this.getOne(new QueryWrapper().eq("username",SecurityUtils.getUsername())); - UserAvatar userAvatar = user.getUserAvatar(); + User user = this.getOne(new QueryWrapper().lambda() + .eq(User::getUsername,SecurityUtils.getUsername())); + UserAvatar userAvatar = userAvatarService.getOne(new QueryWrapper().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); } diff --git a/yshop-system/src/main/java/co/yixiang/modules/system/service/mapper/SysUserMapper.java b/yshop-system/src/main/java/co/yixiang/modules/system/service/mapper/SysUserMapper.java index c0269626..9baea40d 100644 --- a/yshop-system/src/main/java/co/yixiang/modules/system/service/mapper/SysUserMapper.java +++ b/yshop-system/src/main/java/co/yixiang/modules/system/service/mapper/SysUserMapper.java @@ -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 { @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); + } diff --git a/yshop-tools/src/main/java/co/yixiang/tools/rest/LocalStorageController.java b/yshop-tools/src/main/java/co/yixiang/tools/rest/LocalStorageController.java index 4d9641fb..e1fe7383 100644 --- a/yshop-tools/src/main/java/co/yixiang/tools/rest/LocalStorageController.java +++ b/yshop-tools/src/main/java/co/yixiang/tools/rest/LocalStorageController.java @@ -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 create(@Validated @RequestBody LocalStorage resources){ - return new ResponseEntity<>(localStorageService.save(resources),HttpStatus.CREATED); + public ResponseEntity 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 update(@Validated @RequestBody LocalStorage resources){ - localStorageService.updateById(resources); + localStorageService.saveOrUpdate(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/yshop-tools/src/main/java/co/yixiang/tools/service/impl/LocalStorageServiceImpl.java b/yshop-tools/src/main/java/co/yixiang/tools/service/impl/LocalStorageServiceImpl.java index a62997c8..93920bb7 100644 --- a/yshop-tools/src/main/java/co/yixiang/tools/service/impl/LocalStorageServiceImpl.java +++ b/yshop-tools/src/main/java/co/yixiang/tools/service/impl/LocalStorageServiceImpl.java @@ -101,7 +101,7 @@ public class LocalStorageServiceImpl extends BaseServiceImpl