关注模块
This commit is contained in:
parent
e0b7fb7086
commit
34663c01b8
|
|
@ -0,0 +1,81 @@
|
|||
package com.ruoyi.web.controller.app;
|
||||
|
||||
import com.ruoyi.common.core.domain.Result;
|
||||
import com.ruoyi.system.domain.TbUserFollow;
|
||||
import com.ruoyi.system.service.ITbUserFollowService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>用户关注</p>
|
||||
* @author clunt
|
||||
*/
|
||||
|
||||
@Api(tags = "App*关注列表")
|
||||
@RestController
|
||||
@RequestMapping(value = "/app/follow")
|
||||
public class TbUserFollowAppController {
|
||||
|
||||
@Autowired
|
||||
private ITbUserFollowService tbUserFollowService;
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "关注用户", httpMethod = "POST")
|
||||
public Result<String> addSave(@RequestBody TbUserFollow tbUserFollow)
|
||||
{
|
||||
// 判断用户是否也关注自己
|
||||
TbUserFollow followUser = tbUserFollowService.lambdaQuery()
|
||||
.eq(TbUserFollow::getFollowUserId, tbUserFollow.getUserId())
|
||||
.eq(TbUserFollow::getUserId, tbUserFollow.getFollowUserId())
|
||||
.one();
|
||||
if(followUser != null){
|
||||
followUser.setFollowTogether(1L);
|
||||
tbUserFollowService.updateById(followUser);
|
||||
|
||||
tbUserFollow.setFollowTogether(1L);
|
||||
}
|
||||
// 更新目标用户为已关注自己
|
||||
int effectiveRows = tbUserFollowService.insertTbUserFollow(tbUserFollow);
|
||||
if(effectiveRows > 0){
|
||||
return Result.success("关注成功");
|
||||
}else {
|
||||
return Result.error("关注失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/getFollowByUserId")
|
||||
@ApiOperation(value = "查询我关注的用户", httpMethod = "POST")
|
||||
public Result<List<TbUserFollow>> getFollowByUserId(@RequestBody TbUserFollow tbUserFollow)
|
||||
{
|
||||
return Result.success(tbUserFollowService.selectTbUserFollowList(tbUserFollow));
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/getFollowByFollowUserId")
|
||||
@ApiOperation(value = "查询关注我的用户", httpMethod = "POST")
|
||||
public Result<List<TbUserFollow>> getFollowByFollowUserId(@RequestBody TbUserFollow tbUserFollow)
|
||||
{
|
||||
return Result.success(tbUserFollowService.selectTbUserFollowList(tbUserFollow));
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/getTogetherFollowByUserId")
|
||||
@ApiOperation(value = "查询互相关注的用户", httpMethod = "POST")
|
||||
public Result<List<TbUserFollow>> getTogetherFollowByUserId(@RequestBody TbUserFollow tbUserFollow)
|
||||
{
|
||||
tbUserFollow.setFollowTogether(1L);
|
||||
return Result.success(tbUserFollowService.selectTbUserFollowList(tbUserFollow));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.system.domain.TbUserFollow;
|
||||
import com.ruoyi.system.service.ITbUserFollowService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 用户关注列Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2023-12-13
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/system/follow")
|
||||
public class TbUserFollowController extends BaseController
|
||||
{
|
||||
private String prefix = "system/follow";
|
||||
|
||||
@Autowired
|
||||
private ITbUserFollowService tbUserFollowService;
|
||||
|
||||
@RequiresPermissions("system:follow:view")
|
||||
@GetMapping()
|
||||
public String follow()
|
||||
{
|
||||
return prefix + "/follow";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户关注列列表
|
||||
*/
|
||||
@RequiresPermissions("system:follow:list")
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public TableDataInfo list(TbUserFollow tbUserFollow)
|
||||
{
|
||||
startPage();
|
||||
List<TbUserFollow> list = tbUserFollowService.selectTbUserFollowList(tbUserFollow);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出用户关注列列表
|
||||
*/
|
||||
@RequiresPermissions("system:follow:export")
|
||||
@Log(title = "用户关注列", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ResponseBody
|
||||
public AjaxResult export(TbUserFollow tbUserFollow)
|
||||
{
|
||||
List<TbUserFollow> list = tbUserFollowService.selectTbUserFollowList(tbUserFollow);
|
||||
ExcelUtil<TbUserFollow> util = new ExcelUtil<TbUserFollow>(TbUserFollow.class);
|
||||
return util.exportExcel(list, "用户关注列数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户关注列
|
||||
*/
|
||||
@GetMapping("/add")
|
||||
public String add()
|
||||
{
|
||||
return prefix + "/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存用户关注列
|
||||
*/
|
||||
@RequiresPermissions("system:follow:add")
|
||||
@Log(title = "用户关注列", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public AjaxResult addSave(TbUserFollow tbUserFollow)
|
||||
{
|
||||
return toAjax(tbUserFollowService.insertTbUserFollow(tbUserFollow));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户关注列
|
||||
*/
|
||||
@RequiresPermissions("system:follow:edit")
|
||||
@GetMapping("/edit/{id}")
|
||||
public String edit(@PathVariable("id") Long id, ModelMap mmap)
|
||||
{
|
||||
TbUserFollow tbUserFollow = tbUserFollowService.selectTbUserFollowById(id);
|
||||
mmap.put("tbUserFollow", tbUserFollow);
|
||||
return prefix + "/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存用户关注列
|
||||
*/
|
||||
@RequiresPermissions("system:follow:edit")
|
||||
@Log(title = "用户关注列", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
@ResponseBody
|
||||
public AjaxResult editSave(TbUserFollow tbUserFollow)
|
||||
{
|
||||
return toAjax(tbUserFollowService.updateTbUserFollow(tbUserFollow));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户关注列
|
||||
*/
|
||||
@RequiresPermissions("system:follow:remove")
|
||||
@Log(title = "用户关注列", businessType = BusinessType.DELETE)
|
||||
@PostMapping( "/remove")
|
||||
@ResponseBody
|
||||
public AjaxResult remove(String ids)
|
||||
{
|
||||
return toAjax(tbUserFollowService.deleteTbUserFollowByIds(ids));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 用户关注列对象 tb_user_follow
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2023-12-13
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "App*关注用户实体")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "tb_user_follow")
|
||||
public class TbUserFollow extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键id */
|
||||
private Long id;
|
||||
|
||||
/** 用户id */
|
||||
@Excel(name = "用户id")
|
||||
@ApiModelProperty(value = "当前用户id")
|
||||
private Long userId;
|
||||
|
||||
/** 关注的用户id */
|
||||
@Excel(name = "关注的用户id")
|
||||
@ApiModelProperty(value = "关注目标用户id")
|
||||
private Long followUserId;
|
||||
|
||||
/** 互相关注 0.单方关注 1.互相关注 */
|
||||
@Excel(name = "互相关注 0.单方关注 1.互相关注")
|
||||
@ApiModelProperty(value = "互相关注 0.单方关注 1.互相关注,查询使用,关注无需入参")
|
||||
private Long followTogether;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.TbUserFollow;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 用户关注列Mapper接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2023-12-13
|
||||
*/
|
||||
public interface TbUserFollowMapper extends BaseMapper<TbUserFollow>
|
||||
{
|
||||
/**
|
||||
* 查询用户关注列
|
||||
*
|
||||
* @param id 用户关注列主键
|
||||
* @return 用户关注列
|
||||
*/
|
||||
public TbUserFollow selectTbUserFollowById(Long id);
|
||||
|
||||
/**
|
||||
* 查询用户关注列列表
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 用户关注列集合
|
||||
*/
|
||||
public List<TbUserFollow> selectTbUserFollowList(TbUserFollow tbUserFollow);
|
||||
|
||||
/**
|
||||
* 新增用户关注列
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertTbUserFollow(TbUserFollow tbUserFollow);
|
||||
|
||||
/**
|
||||
* 修改用户关注列
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateTbUserFollow(TbUserFollow tbUserFollow);
|
||||
|
||||
/**
|
||||
* 删除用户关注列
|
||||
*
|
||||
* @param id 用户关注列主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteTbUserFollowById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除用户关注列
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteTbUserFollowByIds(String[] ids);
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.TbUserFollow;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 用户关注列Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2023-12-13
|
||||
*/
|
||||
public interface ITbUserFollowService extends IService<TbUserFollow>
|
||||
{
|
||||
/**
|
||||
* 查询用户关注列
|
||||
*
|
||||
* @param id 用户关注列主键
|
||||
* @return 用户关注列
|
||||
*/
|
||||
public TbUserFollow selectTbUserFollowById(Long id);
|
||||
|
||||
/**
|
||||
* 查询用户关注列列表
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 用户关注列集合
|
||||
*/
|
||||
public List<TbUserFollow> selectTbUserFollowList(TbUserFollow tbUserFollow);
|
||||
|
||||
/**
|
||||
* 新增用户关注列
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertTbUserFollow(TbUserFollow tbUserFollow);
|
||||
|
||||
/**
|
||||
* 修改用户关注列
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateTbUserFollow(TbUserFollow tbUserFollow);
|
||||
|
||||
/**
|
||||
* 批量删除用户关注列
|
||||
*
|
||||
* @param ids 需要删除的用户关注列主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteTbUserFollowByIds(String ids);
|
||||
|
||||
/**
|
||||
* 删除用户关注列信息
|
||||
*
|
||||
* @param id 用户关注列主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteTbUserFollowById(Long id);
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.TbUserFollowMapper;
|
||||
import com.ruoyi.system.domain.TbUserFollow;
|
||||
import com.ruoyi.system.service.ITbUserFollowService;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
/**
|
||||
* 用户关注列Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2023-12-13
|
||||
*/
|
||||
@Service
|
||||
public class TbUserFollowServiceImpl extends ServiceImpl<TbUserFollowMapper, TbUserFollow> implements ITbUserFollowService
|
||||
{
|
||||
@Autowired
|
||||
private TbUserFollowMapper tbUserFollowMapper;
|
||||
|
||||
/**
|
||||
* 查询用户关注列
|
||||
*
|
||||
* @param id 用户关注列主键
|
||||
* @return 用户关注列
|
||||
*/
|
||||
@Override
|
||||
public TbUserFollow selectTbUserFollowById(Long id)
|
||||
{
|
||||
return tbUserFollowMapper.selectTbUserFollowById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户关注列列表
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 用户关注列
|
||||
*/
|
||||
@Override
|
||||
public List<TbUserFollow> selectTbUserFollowList(TbUserFollow tbUserFollow)
|
||||
{
|
||||
return tbUserFollowMapper.selectTbUserFollowList(tbUserFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户关注列
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertTbUserFollow(TbUserFollow tbUserFollow)
|
||||
{
|
||||
tbUserFollow.setCreateTime(DateUtils.getNowDate());
|
||||
return tbUserFollowMapper.insertTbUserFollow(tbUserFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户关注列
|
||||
*
|
||||
* @param tbUserFollow 用户关注列
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateTbUserFollow(TbUserFollow tbUserFollow)
|
||||
{
|
||||
tbUserFollow.setUpdateTime(DateUtils.getNowDate());
|
||||
return tbUserFollowMapper.updateTbUserFollow(tbUserFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户关注列
|
||||
*
|
||||
* @param ids 需要删除的用户关注列主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteTbUserFollowByIds(String ids)
|
||||
{
|
||||
return tbUserFollowMapper.deleteTbUserFollowByIds(Convert.toStrArray(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户关注列信息
|
||||
*
|
||||
* @param id 用户关注列主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteTbUserFollowById(Long id)
|
||||
{
|
||||
return tbUserFollowMapper.deleteTbUserFollowById(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.system.mapper.TbUserFollowMapper">
|
||||
|
||||
<resultMap type="TbUserFollow" id="TbUserFollowResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="followUserId" column="follow_user_id" />
|
||||
<result property="followTogether" column="follow_together" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectTbUserFollowVo">
|
||||
select id, user_id, follow_user_id, follow_together, create_time, update_time, remark from tb_user_follow
|
||||
</sql>
|
||||
|
||||
<select id="selectTbUserFollowList" parameterType="TbUserFollow" resultMap="TbUserFollowResult">
|
||||
<include refid="selectTbUserFollowVo"/>
|
||||
<where>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="followUserId != null "> and follow_user_id = #{followUserId}</if>
|
||||
<if test="followTogether != null "> and follow_together = #{followTogether}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectTbUserFollowById" parameterType="Long" resultMap="TbUserFollowResult">
|
||||
<include refid="selectTbUserFollowVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertTbUserFollow" parameterType="TbUserFollow" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tb_user_follow
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="followUserId != null">follow_user_id,</if>
|
||||
<if test="followTogether != null">follow_together,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="followUserId != null">#{followUserId},</if>
|
||||
<if test="followTogether != null">#{followTogether},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateTbUserFollow" parameterType="TbUserFollow">
|
||||
update tb_user_follow
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="followUserId != null">follow_user_id = #{followUserId},</if>
|
||||
<if test="followTogether != null">follow_together = #{followTogether},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteTbUserFollowById" parameterType="Long">
|
||||
delete from tb_user_follow where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTbUserFollowByIds" parameterType="String">
|
||||
delete from tb_user_follow where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue