完成用户书签管理的CRUD
This commit is contained in:
@ -79,4 +79,5 @@ public interface SqBookmarkMapper extends MyMapper<SqBookmark>
|
||||
* @return 结果
|
||||
*/
|
||||
public void updateSqBookmarkBymenuId(Long menuId);
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import com.ruoyi.bookmark.domain.SqBookmarkTag;
|
||||
import com.ruoyi.bookmark.domain.SqTag;
|
||||
import com.ruoyi.common.mybatisMapper.MyMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 书签_标签Mapper接口
|
||||
@ -16,6 +17,15 @@ public interface SqTagMapper extends MyMapper<SqTag>
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通过标签名字查看是否存在
|
||||
*
|
||||
* @param name
|
||||
* @return 书签_标签集合
|
||||
*/
|
||||
public List<SqTag> selectCountByName(String name);
|
||||
/**
|
||||
* 查询书签_标签
|
||||
*
|
||||
@ -63,4 +73,15 @@ public interface SqTagMapper extends MyMapper<SqTag>
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSqTagByIds(Long[] ids);
|
||||
|
||||
|
||||
/**
|
||||
* 批量修改对应书签的 标签
|
||||
*
|
||||
* @param tagId 修改前引用的ID
|
||||
* @param toTagId 修改标签后引用的ID
|
||||
* @param userId 修改前引用的ID
|
||||
* @return 结果
|
||||
*/
|
||||
int updateBookmarkTagIdByTagId(@Param("tagId")Long tagId, @Param("toTagId")Long toTagId, @Param("userId")Long userId);
|
||||
}
|
||||
|
@ -89,4 +89,22 @@ public interface SqUserTagMapper extends MyMapper<SqUserTag>
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSqUserTagByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除标签管理信息
|
||||
*
|
||||
* @param ids 书签标签ID串
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int userRemoveByid(@Param("ids")Long[] ids, @Param("userId")Long userId);
|
||||
|
||||
/**
|
||||
* 通过标签名字查看是否存在
|
||||
*
|
||||
* @param name String
|
||||
* @param userId Long
|
||||
* @return 数量
|
||||
*/
|
||||
public int selectCountByName(@Param("name")String name,@Param("userId")Long userId);
|
||||
}
|
||||
|
@ -91,4 +91,38 @@ public interface ISqUserTagService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSqUserTagById(Long id);
|
||||
|
||||
/**
|
||||
* 删除标签管理信息
|
||||
*
|
||||
* @param ids 书签标签ID串
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int userRemoveByid(Long[] ids, Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 用户添加标签
|
||||
*
|
||||
* @param sqUserTag
|
||||
* @return int
|
||||
*/
|
||||
int insertSqUserTagAdd(SqUserTag sqUserTag);
|
||||
|
||||
/**
|
||||
* 用户修改标签
|
||||
*
|
||||
* @param sqUserTag
|
||||
* @return int
|
||||
*/
|
||||
int updateSqUserTagEdit(SqUserTag sqUserTag);
|
||||
/**
|
||||
* 查询用户 是否已经有此标签
|
||||
*
|
||||
* @param name
|
||||
* @param userId
|
||||
* @return int
|
||||
*/
|
||||
int selectCountByName(String name,Long userId);
|
||||
}
|
||||
|
@ -3,7 +3,14 @@ package com.ruoyi.bookmark.service.impl;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.github.wujun234.uid.UidGenerator;
|
||||
import com.ruoyi.bookmark.domain.SqTag;
|
||||
import com.ruoyi.bookmark.mapper.SqBookmarkMapper;
|
||||
import com.ruoyi.bookmark.mapper.SqTagMapper;
|
||||
import com.ruoyi.common.utils.YunConstant;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.bookmark.mapper.SqUserTagMapper;
|
||||
@ -21,9 +28,16 @@ import javax.annotation.Resource;
|
||||
@Service
|
||||
public class SqUserTagServiceImpl implements ISqUserTagService
|
||||
{
|
||||
public final static Logger logger = LoggerFactory.getLogger(SqUserTagServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private SqUserTagMapper sqUserTagMapper;
|
||||
|
||||
@Autowired
|
||||
private SqTagMapper sqTagMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -139,4 +153,98 @@ public class SqUserTagServiceImpl implements ISqUserTagService
|
||||
{
|
||||
return sqUserTagMapper.deleteSqUserTagById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签管理信息
|
||||
*
|
||||
* @param ids 书签标签ID串
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int userRemoveByid(Long[] ids, Long userId) {
|
||||
return sqUserTagMapper.userRemoveByid(ids,userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Description 用户添加标签
|
||||
* @Author wanghao
|
||||
* @Date 2020/09/16 20:00
|
||||
* @Param [sqUserTag]
|
||||
* @Return int
|
||||
* @Exception
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public int insertSqUserTagAdd(SqUserTag sqUserTag) {
|
||||
|
||||
List<SqTag> sqtag = sqTagMapper.selectCountByName(sqUserTag.getTagName());
|
||||
if (sqtag!=null&&!sqtag.isEmpty()){
|
||||
sqUserTag.setTagId(sqtag.get(0).getId());
|
||||
sqUserTag.setTagName(sqtag.get(0).getName());
|
||||
sqUserTag.setIcount(1);
|
||||
}else {
|
||||
SqTag sqTag=new SqTag();
|
||||
sqTag.setName(sqUserTag.getTagName());
|
||||
sqTag.setIcount(1);
|
||||
sqTag.setUserId(sqUserTag.getUserId());
|
||||
sqTag.setTagType(YunConstant.KEY_TAGS_PERSON);
|
||||
sqTag.setStatus(0);
|
||||
sqTag.setCreateTime(DateUtil.date(System.currentTimeMillis()));
|
||||
sqTagMapper.insertSqTag(sqTag);
|
||||
//创建新的标签后
|
||||
logger.debug("创建新标签ID:"+sqTag.getId()+"name:"+sqUserTag.getTagName());
|
||||
sqUserTag.setTagId(sqTag.getId());
|
||||
sqUserTag.setTagName(sqUserTag.getTagName());
|
||||
sqUserTag.setIcount(1);
|
||||
}
|
||||
return sqUserTagMapper.insertSqUserTag(sqUserTag);
|
||||
}
|
||||
|
||||
/**
|
||||
*用户修改书签
|
||||
*
|
||||
* @param sqUserTag
|
||||
* @return int
|
||||
*/
|
||||
@Override
|
||||
public int updateSqUserTagEdit(SqUserTag sqUserTag) {
|
||||
//修改前的tagid
|
||||
Long tagId =sqUserTag.getTagId();
|
||||
logger.debug("修改前的tagid:"+tagId);
|
||||
|
||||
List<SqTag> sqtag = sqTagMapper.selectCountByName(sqUserTag.getTagName());
|
||||
if (sqtag!=null&&!sqtag.isEmpty()){
|
||||
sqUserTag.setTagId(sqtag.get(0).getId());
|
||||
logger.debug("修改后的tagid:"+sqtag.get(0).getId());
|
||||
}else {
|
||||
SqTag sqTag=new SqTag();
|
||||
sqTag.setName(sqUserTag.getTagName());
|
||||
sqTag.setIcount(1);
|
||||
sqTag.setUserId(sqUserTag.getUserId());
|
||||
sqTag.setTagType(YunConstant.KEY_TAGS_PERSON);
|
||||
sqTag.setStatus(0);
|
||||
sqTag.setCreateTime(DateUtil.date(System.currentTimeMillis()));
|
||||
sqTagMapper.insertSqTag(sqTag);
|
||||
logger.debug("修改后的tagid:"+sqTag.getId());
|
||||
sqUserTag.setTagId(sqTag.getId());
|
||||
}
|
||||
//修改在正在使用该标签的 对应引用书签
|
||||
sqTagMapper.updateBookmarkTagIdByTagId(tagId,sqUserTag.getTagId(),sqUserTag.getUserId());
|
||||
|
||||
return sqUserTagMapper.updateSqUserTag(sqUserTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过标签名字查看是否存在
|
||||
*
|
||||
* @param name String
|
||||
* @param userId Long
|
||||
* @return 数量
|
||||
*/
|
||||
@Override
|
||||
public int selectCountByName(String name, Long userId) {
|
||||
return sqUserTagMapper.selectCountByName(name,userId);
|
||||
}
|
||||
}
|
||||
|
@ -83,4 +83,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="selectCountByName" parameterType="String" resultMap="SqTagResult">
|
||||
select id,name from sq_tag where name=#{name}
|
||||
</select>
|
||||
|
||||
<update id="updateBookmarkTagIdByTagId" parameterType="Long" >
|
||||
UPDATE sq_bookmark as a,sq_bookmark_tag as b SET b.tag_id = #{toTagId} WHERE a.bookmark_id=b.bookmark_id and a.userid=#{userId} and b.tag_id=#{tagId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tagId != null">tag_id = #{tagId},</if>
|
||||
<if test="icount != null">icount = #{icount},</if>
|
||||
<if test="iorder != null">iorder = #{iorder},</if>
|
||||
<if test="tagName != null">tagName = #{tagName},</if>
|
||||
<if test="tagName != null">tag_name = #{tagName},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@ -74,6 +74,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="userRemoveByid" parameterType="String">
|
||||
delete from sq_user_tag where id in
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
and user_id=#{userId}
|
||||
</delete>
|
||||
|
||||
<select id="selectSqUserTagByUserId" parameterType="Long" resultType="java.util.Map">
|
||||
SELECT u.id,u.user_id as userId,u.tag_id as tagId ,u.icount,u.iorder,t.name
|
||||
from sq_user_tag AS u,sq_tag as t
|
||||
@ -92,7 +100,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
|
||||
<update id="updateCountAdd" >
|
||||
<foreach item="tagId" collection="tags" separator=";" >
|
||||
update sq_user_tag set icount=icount+1 WHERE user_id=#{userId} and tag_id = #{tagId}
|
||||
@ -100,4 +107,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectCountByName" parameterType="SqUserTag" resultType="int">
|
||||
select count(*) from sq_tag where name=#{name} and user_id=#{userId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user