计算目录下的书签数量

This commit is contained in:
WangHao
2021-02-15 15:33:49 +08:00
parent d655b29ffd
commit ae6d354b6f
9 changed files with 89 additions and 34 deletions

View File

@ -88,8 +88,19 @@ public class SqBookmark
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@Transient
private Long parentId;
private List<Map<String,Object>> sqTags;
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public List<Map<String, Object>> getSqTags() {
return sqTags;

View File

@ -85,4 +85,12 @@ public interface SqBookmarkMapper extends MyMapper<SqBookmark>
* @return 结果
*/
public List<SqBookmark> selectByUseridList(Long userId);
/**
* 根据MenuId查询当前目录下 有多少书签数量
*
* @param menuId
* @return 结果
*/
public int countBookMakeByMenuId(Long menuId);
}

View File

@ -111,11 +111,23 @@ public class SqBookmarkServiceImpl implements ISqBookmarkService
@Override
public int insertSqBookmark(SqBookmark sqBookmark)
{
//获取官网urls
try {
sqBookmark.setUrls(ImportHtml.Urlutils(new URL(sqBookmark.getUrl())));
} catch (MalformedURLException e) {
logger.info("用户ID:"+sqBookmark.getUserid()+",新增书签"+sqBookmark.getUrl()+"获取网址的 主机信息 报错 -"+new Date());
}
if(null==sqBookmark.getDescription()||"".equals(sqBookmark.getDescription())){
sqBookmark.setDescription(sqBookmark.getTitle());
}
//转换传入的父级ID
sqBookmark.setMenuId(sqBookmark.getParentId());
int i= sqBookmarkMapper.insertSqBookmark(sqBookmark);
//给对应目录 +1
sqMenuMapper.updateCountAdd(new Long[]{sqBookmark.getMenuId()},1);
int i= sqBookmarkMapper.insertSqBookmark(sqBookmark);
//传入的标签
List<Map<String, Object>> listmap = sqBookmark.getSqTags();
if (listmap==null||listmap.isEmpty()||listmap.size()==0){
@ -151,11 +163,6 @@ public class SqBookmarkServiceImpl implements ISqBookmarkService
bookamrktag.setTagId(tag.getKey());
sqBookmarkTagMapper.insertSqBookmarkTag(bookamrktag);
}
//给对应目录 +1
Long[] menuIds= new Long[1];
menuIds[0]=sqBookmark.getMenuId();
sqMenuMapper.updateCountAdd(menuIds,1);
return i;
}
@ -171,6 +178,8 @@ public class SqBookmarkServiceImpl implements ISqBookmarkService
// String deletetag = "";
// //新增的书签ID
// String addtag = "";
//未修改前的信息
SqBookmark sqbm=sqBookmarkMapper.selectSqBookmarkById(sqBookmark.getBookmarkId());
//传入的标签
int i =sqBookmarkMapper.updateSqBookmark(sqBookmark);
List<Map<String, Object>> listmap = sqBookmark.getSqTags();
@ -178,6 +187,14 @@ public class SqBookmarkServiceImpl implements ISqBookmarkService
return i;
}
//是否移动目录
if (!sqbm.getMenuId().toString().equals(sqBookmark.getMenuId().toString())){
//给原目录 -1
sqMenuMapper.updateCountReduce(new Long[]{sqBookmark.getMenuId()},1);
//新目录 +1
sqMenuMapper.updateCountAdd(new Long[]{sqBookmark.getMenuId()},1);
}
//给文章添加标签
@ -281,14 +298,8 @@ public class SqBookmarkServiceImpl implements ISqBookmarkService
@Override
public int selectByMenuIdCount(Long menuId)
{
SqBookmark sqBookmark=new SqBookmark();
sqBookmark.setMenuId(menuId);
List<SqBookmark> sqBookmarks=sqBookmarkMapper.select(sqBookmark);
if (sqBookmarks!=null&&!sqBookmarks.isEmpty()){
return sqBookmarks.size();
}else {
return 0;
}
return sqBookmarkMapper.countBookMakeByMenuId(menuId);
}
/**

View File

@ -132,12 +132,7 @@ public class SqMenuServiceImpl implements ISqMenuService
int i = sqMenuMapper.insertSqMenu(sqMenu);
//更新新的目录串
if (i!=0){
String menuUplinkSeries ="";
if("0".equals(parentId)){
menuUplinkSeries = ","+sqMenu.getMenuId()+",";
}else{
menuUplinkSeries = addMenuUplinkSeries(sqMenu.getMenuId());
}
String menuUplinkSeries = addMenuUplinkSeries(sqMenu.getMenuId());
sqMenuMapper.updateSqMenu(new SqMenu(sqMenu.getMenuId(),menuUplinkSeries));
}
return i;
@ -216,6 +211,10 @@ public class SqMenuServiceImpl implements ISqMenuService
StringBuilder menuus=new StringBuilder();
SqMenu sqMenu = sqMenuMapper.selectSqMenuById(menuId);
Long parentId = sqMenu.getParentId();
//顶级目录
if("0".equals(parentId.toString())){
return ","+sqMenu.getMenuId()+",";
}
//所有的上级目录ID
List<Long> list= new ArrayList<>();
list.add(menuId);

View File

@ -126,7 +126,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where userid = #{userId} and idelete = 0 order by create_time desc
</select>
<select id="countBookMakeByMenuId" parameterType="Long" resultType="java.lang.Integer">
select count(*) FROM sq_bookmark where menu_id =#{menuId}
</select>
<select id="selectBymenuIdUserID" parameterType="SqBookmark" resultMap="SqBookmarkResult">
<include refid="selectSqBookmarkVo"/>

View File

@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select menu_id from sq_menu where menu_uplink_series like '#{menuUplinkSeries}%'
<if test="menuId != null "> and menu_id != #{menuId}</if>
</select>
<select id="countByMenuUplinkSeriesAndMenu" parameterType="java.lang.Integer">
<select id="countByMenuUplinkSeriesAndMenu" resultType="java.lang.Integer">
select sum(bookmark_count) from sq_menu where menu_uplink_series like '#{menuUplinkSeries}%'
<if test="menuId != null "> and menu_id != #{menuId}</if>
</select>