计算目录下的书签数量
This commit is contained in:
parent
d655b29ffd
commit
ae6d354b6f
ruoyi-admin/src/main/java/com/ruoyi/web
ruoyi-yunbookmark/src/main
java/com/ruoyi/bookmark
domain
mapper
service/impl
resources/mapper/bookmark
@ -155,12 +155,7 @@ public class SqBookmarkController extends BaseController
|
||||
{
|
||||
SysUser sysUser=getAuthUser();
|
||||
sqBookmark.setUserid(sysUser.getUserId());
|
||||
try {
|
||||
sqBookmark.setUrls(ImportHtml.Urlutils(new URL(sqBookmark.getUrl())));
|
||||
} catch (MalformedURLException e) {
|
||||
logger.info(sysUser.getUserId()+"新增书签 获取网址的 主机信息 报错"+new Date());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return toAjax(sqBookmarkService.insertSqBookmark(sqBookmark));
|
||||
}
|
||||
|
||||
|
@ -134,11 +134,11 @@ public class SqMenuController extends BaseController
|
||||
sqMenuService.updateSqMenu(sqMenu);
|
||||
// ================修改后===================
|
||||
if (parentFlag){
|
||||
String menuus = sqMenuService.addMenuUplinkSeries(menu.getMenuId());
|
||||
sqMenuService.updateSqMenu(new SqMenu(sqMenu.getMenuId(),menuus));
|
||||
String menuUplinkSeries = sqMenuService.addMenuUplinkSeries(sqMenu.getMenuId());
|
||||
sqMenuService.updateSqMenu(new SqMenu(sqMenu.getMenuId(),menuUplinkSeries));
|
||||
}
|
||||
//添加所有上级目录的书签数量
|
||||
sqMenuService.addMenuByCountAndMenuUplinkSeries(menu.getMenuId());
|
||||
// sqMenuService.addMenuByCountAndMenuUplinkSeries(menu.getMenuId());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ -171,8 +171,8 @@ public class SqMenuController extends BaseController
|
||||
//删除
|
||||
sqMenuService.deleteSqMenuById(menuId,sysUser.getUserId());
|
||||
//批量减少上级所有目录的书签数量
|
||||
sqMenu.setMenuId(menuId);
|
||||
sqMenuService.reduceMenuByCountAndMenuUplinkSeries(sqMenu);
|
||||
// sqMenu.setMenuId(menuId);
|
||||
// sqMenuService.reduceMenuByCountAndMenuUplinkSeries(sqMenu);
|
||||
//修改目录下的所有书签状态为 删除状态
|
||||
sqBookmarkService.updateSqBookmarkBymenuId(menuId);
|
||||
return toAjax(1);
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
import com.ruoyi.bookmark.domain.SqBookmark;
|
||||
import com.ruoyi.bookmark.domain.SqMenu;
|
||||
import com.ruoyi.bookmark.mapper.SqBookmarkMapper;
|
||||
import com.ruoyi.bookmark.mapper.SqMenuMapper;
|
||||
import org.apache.velocity.runtime.directive.Foreach;
|
||||
import org.junit.Test;
|
||||
@ -14,10 +17,12 @@ import java.util.List;
|
||||
* @Date: 2021/02/14 20:41
|
||||
* 功能描述:
|
||||
*/
|
||||
public class SqMenu extends BaseSpringBootTest{
|
||||
public class SqMenuTest extends BaseSpringBootTest{
|
||||
|
||||
@Autowired
|
||||
SqMenuMapper sqMenuMapper;
|
||||
@Autowired
|
||||
SqBookmarkMapper sqBookmarkMapper;
|
||||
@Test
|
||||
public void addMenuUplinkSeries() {
|
||||
|
||||
@ -46,4 +51,28 @@ public class SqMenu extends BaseSpringBootTest{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量计算新的目录下书签数量
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@Test
|
||||
public void test2() {
|
||||
SqMenu sqMenu2 = new SqMenu();
|
||||
sqMenu2.setUserId(1L);
|
||||
List<SqMenu> sqs = sqMenuMapper.select(sqMenu2);
|
||||
for (SqMenu s : sqs) {
|
||||
int count = sqBookmarkMapper.countBookMakeByMenuId(s.getMenuId());
|
||||
SqMenu sqMenu = new SqMenu();
|
||||
sqMenu.setMenuId(s.getMenuId());
|
||||
sqMenu.setBookmarkCount(count);
|
||||
sqMenuMapper.updateSqMenu(sqMenu);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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"/>
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user