Search in sources :

Example 1 with User

use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.

the class BizArticleServiceImpl method doPraise.

/**
 * 文章点赞
 *
 * @param id
 */
@Override
@RedisCache(flush = true)
public void doPraise(Long id) {
    String ip = IpUtil.getRealIp(RequestHolder.getRequest());
    String key = ip + "_doPraise_" + id;
    ValueOperations<String, Object> operations = redisTemplate.opsForValue();
    if (redisTemplate.hasKey(key)) {
        throw new ZhydArticleException("一个小时只能点赞一次哈,感谢支持~~");
    }
    User user = SessionUtil.getUser();
    BizArticleLove love = new BizArticleLove();
    if (null != user) {
        love.setUserId(user.getId());
    }
    love.setArticleId(id);
    love.setUserIp(IpUtil.getRealIp(RequestHolder.getRequest()));
    love.setLoveTime(new Date());
    love.setCreateTime(new Date());
    love.setUpdateTime(new Date());
    bizArticleLoveMapper.insert(love);
    operations.set(key, id, 1, TimeUnit.HOURS);
}
Also used : ZhydArticleException(com.zyd.blog.framework.exception.ZhydArticleException) User(com.zyd.blog.business.entity.User) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Example 2 with User

use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.

the class BizCommentServiceImpl method commentForAdmin.

/**
 * admin发表评论
 *
 * @param comment
 * @return
 */
@Override
@RedisCache(flush = true)
public void commentForAdmin(Comment comment) throws ZhydCommentException {
    Map config = configService.getConfigs();
    User user = SessionUtil.getUser();
    comment.setQq(user.getQq());
    comment.setEmail(user.getEmail());
    comment.setNickname(user.getNickname());
    comment.setAvatar(user.getAvatar());
    comment.setUrl((String) config.get(ConfigKeyEnum.SITE_URL.getKey()));
    comment.setUserId(user.getId());
    comment.setStatus(CommentStatusEnum.APPROVED.toString());
    comment.setPid(comment.getId());
    comment.setId(null);
    this.comment(comment);
}
Also used : User(com.zyd.blog.business.entity.User) RedisCache(com.zyd.blog.business.annotation.RedisCache)

Example 3 with User

use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.

the class BizCommentServiceImpl method setCurrentLoginUserInfo.

/**
 * 保存当前登录用户的信息
 *
 * @param comment
 */
private void setCurrentLoginUserInfo(Comment comment) {
    User loginUser = SessionUtil.getUser();
    comment.setNickname(HtmlUtil.html2Text(loginUser.getNickname()));
    comment.setQq(HtmlUtil.html2Text(loginUser.getQq()));
    comment.setAvatar(HtmlUtil.html2Text(loginUser.getAvatar()));
    comment.setEmail(HtmlUtil.html2Text(loginUser.getEmail()));
    comment.setUrl(HtmlUtil.html2Text(loginUser.getBlog()));
    comment.setUserId(loginUser.getId());
}
Also used : User(com.zyd.blog.business.entity.User)

Example 4 with User

use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.

the class SysLogServiceImpl method asyncSaveSystemLog.

@Async
@Override
public void asyncSaveSystemLog(PlatformEnum platform, String bussinessName) {
    String ua = RequestUtil.getUa();
    Log sysLog = new Log();
    sysLog.setLogLevel(LogLevelEnum.INFO);
    sysLog.setType(platform.equals(PlatformEnum.WEB) ? LogTypeEnum.VISIT : LogTypeEnum.SYSTEM);
    sysLog.setIp(RequestUtil.getIp());
    sysLog.setReferer(RequestUtil.getReferer());
    sysLog.setRequestUrl(RequestUtil.getRequestUrl());
    sysLog.setUa(ua);
    sysLog.setSpiderType(WebSpiderUtils.parseUa(ua));
    sysLog.setParams(JSONObject.toJSONString(RequestUtil.getParametersMap()));
    User user = SessionUtil.getUser();
    if (user != null) {
        sysLog.setUserId(user.getId());
        sysLog.setContent(String.format("用户: [%s] | 操作: %s", user.getUsername(), bussinessName));
    } else {
        sysLog.setContent(String.format("访客: [%s] | 操作: %s", sysLog.getIp(), bussinessName));
    }
    try {
        UserAgent agent = UserAgent.parseUserAgentString(ua);
        sysLog.setBrowser(agent.getBrowser().getName());
        sysLog.setOs(agent.getOperatingSystem().getName());
        this.insert(sysLog);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : User(com.zyd.blog.business.entity.User) SysLog(com.zyd.blog.persistence.beans.SysLog) Log(com.zyd.blog.business.entity.Log) UserAgent(eu.bitwalker.useragentutils.UserAgent) Async(org.springframework.scheduling.annotation.Async)

Example 5 with User

use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.

the class SysUserServiceImpl method listByRoleId.

/**
 * 通过角色Id获取用户列表
 *
 * @param roleId
 * @return
 */
@Override
public List<User> listByRoleId(Long roleId) {
    List<SysUser> sysUsers = sysUserMapper.listByRoleId(roleId);
    if (CollectionUtils.isEmpty(sysUsers)) {
        return null;
    }
    List<User> users = new ArrayList<>();
    for (SysUser su : sysUsers) {
        su.setUserType(new User(su).getUserTypeDescEnum().toString());
        users.add(new User(su));
    }
    return users;
}
Also used : SysUser(com.zyd.blog.persistence.beans.SysUser) User(com.zyd.blog.business.entity.User) SysUser(com.zyd.blog.persistence.beans.SysUser) ArrayList(java.util.ArrayList)

Aggregations

User (com.zyd.blog.business.entity.User)24 SysUser (com.zyd.blog.persistence.beans.SysUser)8 ArrayList (java.util.ArrayList)4 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)3 ZhydException (com.zyd.blog.framework.exception.ZhydException)3 JapUser (com.fujieid.jap.core.JapUser)2 RedisCache (com.zyd.blog.business.annotation.RedisCache)2 Article (com.zyd.blog.business.entity.Article)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 JapConfig (com.fujieid.jap.core.config.JapConfig)1 JapResponse (com.fujieid.jap.core.result.JapResponse)1 SocialStrategy (com.fujieid.jap.social.SocialStrategy)1 PageInfo (com.github.pagehelper.PageInfo)1 File (com.zyd.blog.business.entity.File)1 Log (com.zyd.blog.business.entity.Log)1 Resources (com.zyd.blog.business.entity.Resources)1 Role (com.zyd.blog.business.entity.Role)1 SocialConfig (com.zyd.blog.business.entity.SocialConfig)1 Tags (com.zyd.blog.business.entity.Tags)1