完成用户书签管理的CRUD
This commit is contained in:
parent
cf70bbc008
commit
b1d475f867
@ -45,6 +45,7 @@ public class CaptchaController
|
|||||||
@GetMapping("/captchaImage")
|
@GetMapping("/captchaImage")
|
||||||
public AjaxResult getCode(HttpServletResponse response) throws IOException
|
public AjaxResult getCode(HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
String uuid = IdUtils.simpleUUID();
|
String uuid = IdUtils.simpleUUID();
|
||||||
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
||||||
|
@ -39,7 +39,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
|||||||
@RequestMapping("/bookmark/bookmark")
|
@RequestMapping("/bookmark/bookmark")
|
||||||
public class SqBookmarkController extends BaseController
|
public class SqBookmarkController extends BaseController
|
||||||
{
|
{
|
||||||
public static Logger logger = LoggerFactory.getLogger(SqBookmarkController.class);
|
public final static Logger logger = LoggerFactory.getLogger(SqBookmarkController.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISqBookmarkService sqBookmarkService;
|
private ISqBookmarkService sqBookmarkService;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.ruoyi.web.controller.yunbookmark;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -36,17 +37,71 @@ public class SqUserTagController extends BaseController
|
|||||||
private ISqUserTagService sqUserTagService;
|
private ISqUserTagService sqUserTagService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用戶标签
|
* 用戶获取标签
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@GetMapping(value = "/selectTagByUserID/{userId}")
|
@GetMapping(value = "/selectTagByUserID")
|
||||||
public AjaxResult selectSqUserTagByUserId(@PathVariable("userId") Long userId)
|
public AjaxResult selectSqUserTagByUserId()
|
||||||
{
|
{
|
||||||
List<Map<String,Object>> map = sqUserTagService.selectSqUserTagByUserId(userId);
|
SysUser sysUser=getAuthUser();
|
||||||
|
startPage();
|
||||||
|
List<Map<String,Object>> map = sqUserTagService.selectSqUserTagByUserId(sysUser.getUserId());
|
||||||
return AjaxResult.success(map);
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户删除标签
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:tag:remove')")
|
||||||
|
@Log(title = "标签管理", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/userRemoveByid/{ids}")
|
||||||
|
public AjaxResult userRemoveByid(@PathVariable Long[] ids)
|
||||||
|
{
|
||||||
|
SysUser sysUser=getAuthUser();
|
||||||
|
return toAjax(sqUserTagService.userRemoveByid(ids,sysUser.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户新增标签
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:tag:add')")
|
||||||
|
@Log(title = "标签管理", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping(value = "/SqUserTagAdd")
|
||||||
|
public AjaxResult SqUserTagAdd(@RequestBody SqUserTag sqUserTag) {
|
||||||
|
SysUser sysUser = getAuthUser();
|
||||||
|
sqUserTag.setUserId(sysUser.getUserId());
|
||||||
|
//检测标签是否已经存在
|
||||||
|
int i = sqUserTagService.selectCountByName(sqUserTag.getTagName(), sysUser.getUserId());
|
||||||
|
if (i > 0) {
|
||||||
|
return AjaxResult.error("新增标签'" + sqUserTag.getTagName() + "'失败,该标签已存在");
|
||||||
|
}
|
||||||
|
return toAjax(sqUserTagService.insertSqUserTagAdd(sqUserTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户修改标签
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:tag:edit')")
|
||||||
|
@Log(title = "标签管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping(value = "/SqUserTagEdit")
|
||||||
|
public AjaxResult SqUserTagEdit(@RequestBody SqUserTag sqUserTag) {
|
||||||
|
SysUser sysUser = getAuthUser();
|
||||||
|
//检测操作的是否自己的标签
|
||||||
|
SqUserTag tag = sqUserTagService.selectSqUserTagById(sqUserTag.getId());
|
||||||
|
if (!tag.getUserId().equals(sysUser.getUserId())) {
|
||||||
|
return AjaxResult.error("修改失败,检测到异常操作已被系统记录!");
|
||||||
|
}
|
||||||
|
//检测标签是否已经存在
|
||||||
|
int i = sqUserTagService.selectCountByName(sqUserTag.getTagName(), sysUser.getUserId());
|
||||||
|
if (i > 0) {
|
||||||
|
return AjaxResult.error("修改标签【" +tag.getTagName()+"】为【"+ sqUserTag.getTagName() + "】失败,标签【"+sqUserTag.getTagName()+"】已存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
//做一次数据初始化 防止用户传入的 注入的数据
|
||||||
|
tag.setTagName(sqUserTag.getTagName());
|
||||||
|
tag.setIorder(sqUserTag.getIorder());
|
||||||
|
return toAjax(sqUserTagService.updateSqUserTagEdit(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Auther: Wang
|
||||||
|
* @Date: 2020/09/16 20:29
|
||||||
|
* 功能描述: 常用常量
|
||||||
|
*/
|
||||||
|
public class YunConstant {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统标签
|
||||||
|
*/
|
||||||
|
public static final String KEY_TAGS_SYSTEM="S";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户标签
|
||||||
|
*/
|
||||||
|
public static final String KEY_TAGS_PERSON="P";
|
||||||
|
|
||||||
|
}
|
@ -79,4 +79,5 @@ public interface SqBookmarkMapper extends MyMapper<SqBookmark>
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public void updateSqBookmarkBymenuId(Long menuId);
|
public void updateSqBookmarkBymenuId(Long menuId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import com.ruoyi.bookmark.domain.SqBookmarkTag;
|
import com.ruoyi.bookmark.domain.SqBookmarkTag;
|
||||||
import com.ruoyi.bookmark.domain.SqTag;
|
import com.ruoyi.bookmark.domain.SqTag;
|
||||||
import com.ruoyi.common.mybatisMapper.MyMapper;
|
import com.ruoyi.common.mybatisMapper.MyMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 书签_标签Mapper接口
|
* 书签_标签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 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteSqTagByIds(Long[] ids);
|
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 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteSqUserTagByIds(Long[] ids);
|
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 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteSqUserTagById(Long id);
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.github.wujun234.uid.UidGenerator;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.bookmark.mapper.SqUserTagMapper;
|
import com.ruoyi.bookmark.mapper.SqUserTagMapper;
|
||||||
@ -21,9 +28,16 @@ import javax.annotation.Resource;
|
|||||||
@Service
|
@Service
|
||||||
public class SqUserTagServiceImpl implements ISqUserTagService
|
public class SqUserTagServiceImpl implements ISqUserTagService
|
||||||
{
|
{
|
||||||
|
public final static Logger logger = LoggerFactory.getLogger(SqUserTagServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SqUserTagMapper sqUserTagMapper;
|
private SqUserTagMapper sqUserTagMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SqTagMapper sqTagMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -139,4 +153,98 @@ public class SqUserTagServiceImpl implements ISqUserTagService
|
|||||||
{
|
{
|
||||||
return sqUserTagMapper.deleteSqUserTagById(id);
|
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>
|
</foreach>
|
||||||
</delete>
|
</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>
|
</mapper>
|
||||||
|
@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="tagId != null">tag_id = #{tagId},</if>
|
<if test="tagId != null">tag_id = #{tagId},</if>
|
||||||
<if test="icount != null">icount = #{icount},</if>
|
<if test="icount != null">icount = #{icount},</if>
|
||||||
<if test="iorder != null">iorder = #{iorder},</if>
|
<if test="iorder != null">iorder = #{iorder},</if>
|
||||||
<if test="tagName != null">tagName = #{tagName},</if>
|
<if test="tagName != null">tag_name = #{tagName},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
@ -74,6 +74,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</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 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
|
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
|
from sq_user_tag AS u,sq_tag as t
|
||||||
@ -92,7 +100,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<update id="updateCountAdd" >
|
<update id="updateCountAdd" >
|
||||||
<foreach item="tagId" collection="tags" separator=";" >
|
<foreach item="tagId" collection="tags" separator=";" >
|
||||||
update sq_user_tag set icount=icount+1 WHERE user_id=#{userId} and tag_id = #{tagId}
|
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>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectCountByName" parameterType="SqUserTag" resultType="int">
|
||||||
|
select count(*) from sq_tag where name=#{name} and user_id=#{userId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user