Search in sources :

Example 6 with UserInfoBO

use of com.ch999.haha.admin.document.redis.UserInfoBO in project haha by hahafreeasair666.

the class UserComponent method updateUserAvatar.

public Boolean updateUserAvatar(Integer userId, MultipartFile file) {
    Imgs imgs = imgService.uploadImg(file);
    if (imgs == null) {
        return false;
    } else {
        UserInfo userInfo = new UserInfo(userId);
        userInfo.setPicPath(imgs.getImgUrl());
        userInfoService.updateById(userInfo);
        UserInfo userInfo1 = userInfoService.selectById(userId);
        UserInfoBO one = userInfoBORepository.findOne(userId);
        one.setUserInfo(userInfo1);
        userInfoBORepository.save(one);
        return true;
    }
}
Also used : Imgs(com.ch999.haha.admin.entity.Imgs) UserInfo(com.ch999.haha.admin.entity.UserInfo) UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 7 with UserInfoBO

use of com.ch999.haha.admin.document.redis.UserInfoBO in project haha by hahafreeasair666.

the class UserInfoApi method followOrCancel.

/**
 * 关注和取关
 *
 * @param userId
 * @return
 */
@PostMapping("/followOrCancel/v1")
public Result<String> followOrCancel(Integer userId, Boolean isFollow) {
    UserInfoBO loginUser = userComponent.getLoginUser();
    if (loginUser.getId() == null) {
        return Result.unlogin("unLogin", "请登陆后再操作", null);
    }
    if (userId == null) {
        return Result.error("error", "请选择要关注或者取关的人");
    }
    if (userId.equals(loginUser.getId())) {
        return Result.error("error", "不能自己关注自己");
    }
    Boolean aBoolean = userFansService.followOrCancel(loginUser.getId(), userId, isFollow);
    if (aBoolean == null) {
        return Result.error("error", "要关注或取关的用户不存在");
    } else if (aBoolean) {
        return Result.success();
    }
    if (isFollow == null || isFollow) {
        return Result.error("error", "你已经关注他了无需重复关注");
    }
    return Result.error("error", "你未关注他无法取消关注");
}
Also used : UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 8 with UserInfoBO

use of com.ch999.haha.admin.document.redis.UserInfoBO in project haha by hahafreeasair666.

the class UserInfoApi method cancelAdoption.

// 取消收养请求
@PostMapping("/cancelAdoption/v1")
public Result<String> cancelAdoption(Integer adoptionId) {
    UserInfoBO loginUser = userComponent.getLoginUser();
    if (loginUser.getId() == null) {
        return Result.unlogin("unLogin", "请登陆后再查看信息", null);
    }
    if (adoptionId == null) {
        return Result.error("error", "请选择要取消的收养请求");
    }
    Boolean aBoolean = adoptionRequestService.cancelAdoptionRequest(loginUser.getId(), adoptionId);
    if (!aBoolean) {
        return Result.error("error", "取消失败");
    }
    return Result.success();
}
Also used : UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 9 with UserInfoBO

use of com.ch999.haha.admin.document.redis.UserInfoBO in project haha by hahafreeasair666.

the class UserInfoApi method updateAvatar.

/**
 * 修改用户信息
 *
 * @param type             要修改的类型有{avatar,name,mobile,description,pwd}
 * @param userInfoUpdateVO
 * @return
 */
@PostMapping("/updateUserInfo/{type}/v1")
public Result<String> updateAvatar(@PathVariable("type") String type, UserInfoUpdateVO userInfoUpdateVO, HttpServletResponse httpResponse) {
    // 设置ajax跨域可访问
    httpResponse.addHeader("Access-Control-Allow-Origin", "*");
    UserInfoBO loginUser = userComponent.getLoginUser();
    if (loginUser.getId() == null) {
        return Result.error("unLogin", "请登录后再进行操作");
    }
    UserInfo userInfo = new UserInfo(loginUser.getId());
    userInfo.setPicPath(userInfoBORepository.findOne(loginUser.getId()).getUserInfo().getPicPath());
    switch(type) {
        case "avatar":
            if (userInfoUpdateVO.getFile() == null) {
                return Result.error("null", "请选择图片");
            }
            if (userComponent.updateUserAvatar(loginUser.getId(), userInfoUpdateVO.getFile())) {
                return Result.success();
            }
            return Result.error("error", "头像更改失败");
        case "name":
            if (StringUtils.isBlank(userInfoUpdateVO.getName())) {
                return Result.error("null", "用户名不能为空");
            } else if (!userInfoUpdateVO.getName().equals(loginUser.getUserInfo().getUsername()) && !userComponent.checkCanUse(type, userInfoUpdateVO.getName())) {
                return Result.error("null", "昵称修改失败该昵称已被占用");
            }
            userInfo.setUsername(userInfoUpdateVO.getName());
            break;
        case "description":
            if (StringUtils.isBlank(userInfoUpdateVO.getDescription())) {
                return Result.error("null", "个性签名不能为空");
            }
            userInfo.setAutograph(userInfoUpdateVO.getDescription());
            break;
        case "mobile":
            if (StringUtils.isBlank(userInfoUpdateVO.getMobile())) {
                return Result.error("null", "请输入要修改的手机号码");
            } else if (!userInfoUpdateVO.getMobile().matches(Phone.CK)) {
                return Result.error("error", "请输入正确的的电话号码");
            } else if (!userInfoUpdateVO.getMobile().equals(loginUser.getUserInfo().getMobile()) && !userComponent.checkCanUse(type, userInfoUpdateVO.getMobile())) {
                return Result.error("error", "手机号修改失败该号码已被占用");
            }
            userInfo.setMobile(userInfoUpdateVO.getMobile());
            break;
        case "pwd":
            if (StringUtils.isBlank(userInfoUpdateVO.getOldPwd())) {
                return Result.error("null", "请输入原密码");
            } else if (!userInfoService.selectById(loginUser.getId()).getPwd().equals(userInfoUpdateVO.getOldPwd())) {
                return Result.error("error", "原密码输入错误,密码修改失败");
            } else if (StringUtils.isBlank(userInfoUpdateVO.getNewPwd1()) || StringUtils.isBlank(userInfoUpdateVO.getNewPwd2()) || !userInfoUpdateVO.getNewPwd2().equals(userInfoUpdateVO.getNewPwd1())) {
                return Result.error("error", "新密码未输入或两次密码输入不一致,密码修改失败");
            }
            userInfo.setPwd(userInfoUpdateVO.getNewPwd1());
            break;
        default:
            return Result.error("error", "不支持该类型的修改");
    }
    // 修改数据库
    userInfoService.updateById(userInfo);
    UserInfo userInfo1 = userInfoService.selectById(loginUser.getId());
    // 修改缓存
    UserInfoBO one = userInfoBORepository.findOne(loginUser.getId());
    if (one != null) {
        one.setUserInfo(userInfo1);
    } else {
        one = new UserInfoBO(loginUser.getId(), userInfo1);
    }
    userInfoBORepository.save(one);
    return Result.success();
}
Also used : UserInfo(com.ch999.haha.admin.entity.UserInfo) UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 10 with UserInfoBO

use of com.ch999.haha.admin.document.redis.UserInfoBO in project haha by hahafreeasair666.

the class CreditComponent method updateUserCredit.

/**
 * 对用户信用积分进行增减
 *
 * @param userId
 * @param number
 * @param isIncrease
 */
private void updateUserCredit(Integer userId, Integer number, Boolean isIncrease) {
    UserInfoBO one = userInfoBORepository.findOne(userId);
    Integer creditNum;
    if (isIncrease) {
        creditNum = (int) one.getCreditInfo().get("creditNum") + number;
    } else {
        creditNum = (int) one.getCreditInfo().get("creditNum") - number;
    }
    one.getCreditInfo().put("creditNum", creditNum);
    one.getCreditInfo().put("updateTime", new Date());
    userInfoBORepository.save(one);
}
Also used : UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO) Date(java.util.Date)

Aggregations

UserInfoBO (com.ch999.haha.admin.document.redis.UserInfoBO)12 UserInfo (com.ch999.haha.admin.entity.UserInfo)4 UserCenterInfoCountVO (com.ch999.haha.admin.vo.mappervo.UserCenterInfoCountVO)2 EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)1 Imgs (com.ch999.haha.admin.entity.Imgs)1 UserFans (com.ch999.haha.admin.entity.UserFans)1 MyCenterVO (com.ch999.haha.admin.vo.MyCenterVO)1 OtherCenterVO (com.ch999.haha.admin.vo.OtherCenterVO)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1