重构目录功能 添加目录串
This commit is contained in:
@ -40,6 +40,11 @@ public class SqMenu
|
||||
@Column(name = "menu_url")
|
||||
private String menuUrl;
|
||||
|
||||
/** 目录串 */
|
||||
@Excel(name = "目录串")
|
||||
@Column(name = "menu_uplink_series")
|
||||
private String menuUplinkSeries;
|
||||
|
||||
/** 菜单图标 */
|
||||
@Excel(name = "菜单图标")
|
||||
@Column(name = "menu_order")
|
||||
@ -69,6 +74,14 @@ public class SqMenu
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
public String getMenuUplinkSeries() {
|
||||
return menuUplinkSeries;
|
||||
}
|
||||
|
||||
public void setMenuUplinkSeries(String menuUplinkSeries) {
|
||||
this.menuUplinkSeries = menuUplinkSeries;
|
||||
}
|
||||
|
||||
public Integer getBookmarkCount() {
|
||||
return bookmarkCount;
|
||||
}
|
||||
@ -169,6 +182,7 @@ public class SqMenu
|
||||
.append("bookmarkCount", getBookmarkCount())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("menuUplinkSeries", getMenuUplinkSeries())
|
||||
.toString();
|
||||
}
|
||||
public SqMenu(){
|
||||
@ -181,4 +195,9 @@ public class SqMenu
|
||||
this.parentId = parentId;
|
||||
this.menuIcon = menuIcon;
|
||||
}
|
||||
|
||||
public SqMenu( Long menuId,String menuUplinkSeries) {
|
||||
this.menuId = menuId;
|
||||
this.menuUplinkSeries = menuUplinkSeries;
|
||||
}
|
||||
}
|
||||
|
@ -100,4 +100,30 @@ public interface SqMenuMapper extends MyMapper<SqMenu>
|
||||
* @return
|
||||
*/
|
||||
public void addMenu(@Param("userId")Long userID, @Param("title")String title, @Param("parentId")Long parentId);
|
||||
|
||||
/**
|
||||
* 查询空目录串的目录
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public List<SqMenu> selectbymenuUplinkSeries();
|
||||
|
||||
/**
|
||||
* 根据目录串查询下级的所有menuid
|
||||
*
|
||||
* @param menuUplinkSeries 目录串
|
||||
* @param menuId 为null表示不包含menuid
|
||||
* @return
|
||||
*/
|
||||
public List<SqMenu> listByMenuUplinkSeriesAndMenu(@Param("menuUplinkSeries")String menuUplinkSeries, @Param("menuId")Long menuId);
|
||||
|
||||
/**
|
||||
* 根据目录串查询下级的所有书签数量
|
||||
*
|
||||
* @param menuUplinkSeries 目录串
|
||||
* @param menuId 为null表示不包含menuid
|
||||
* @return
|
||||
*/
|
||||
public int countByMenuUplinkSeriesAndMenu(@Param("menuUplinkSeries")String menuUplinkSeries, @Param("menuId")Long menuId);
|
||||
}
|
||||
|
@ -125,4 +125,44 @@ public interface ISqMenuService
|
||||
* @return
|
||||
*/
|
||||
public Long noRepetition(String state, Long userID, Long time);
|
||||
|
||||
|
||||
/**
|
||||
* 根据menuId 生成向上目录串
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public String addMenuUplinkSeries(Long menuId);
|
||||
|
||||
/**
|
||||
* 根据目录串查询下级的所有menuid
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public List<SqMenu> listByMenuUplinkSeriesAndMenu(String menuUplinkSeries,Long menuId);
|
||||
/**
|
||||
* 根据目录串查询下级的所有书签数量
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public int countByMenuUplinkSeriesAndMenu(String menuUplinkSeries, Long menuId);
|
||||
|
||||
/**
|
||||
* 批量添加上级 目录的书签数量
|
||||
*
|
||||
* @param menuId
|
||||
* @return
|
||||
*/
|
||||
void addMenuByCountAndMenuUplinkSeries(Long menuId);
|
||||
|
||||
/**
|
||||
* 批量减少上级 目录的书签数量
|
||||
*
|
||||
* @param sqMenu
|
||||
* @return
|
||||
*/
|
||||
void reduceMenuByCountAndMenuUplinkSeries(SqMenu sqMenu);
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.ruoyi.bookmark.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
import com.ruoyi.common.core.redis.RedisUtil;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.bookmark.mapper.SqMenuMapper;
|
||||
@ -122,8 +127,20 @@ public class SqMenuServiceImpl implements ISqMenuService
|
||||
@Override
|
||||
public int insertSqMenu(SqMenu sqMenu)
|
||||
{
|
||||
sqMenu.setCreateTime(DateUtils.getNowDate());
|
||||
return sqMenuMapper.insertSqMenu(sqMenu);
|
||||
sqMenu.setCreateTime(DateUtils.getNowDate());
|
||||
String parentId=sqMenu.getParentId().toString();
|
||||
int i = sqMenuMapper.insertSqMenu(sqMenu);
|
||||
//更新新的目录串
|
||||
if (i!=0){
|
||||
String menuUplinkSeries ="";
|
||||
if("0".equals(parentId)){
|
||||
menuUplinkSeries = ","+sqMenu.getMenuId()+",";
|
||||
}else{
|
||||
menuUplinkSeries = addMenuUplinkSeries(sqMenu.getMenuId());
|
||||
}
|
||||
sqMenuMapper.updateSqMenu(new SqMenu(sqMenu.getMenuId(),menuUplinkSeries));
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,6 +205,34 @@ public class SqMenuServiceImpl implements ISqMenuService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*根据目录 生成向上目录串
|
||||
*
|
||||
* @param menuId
|
||||
* @return java.lang.String
|
||||
*/
|
||||
@Override
|
||||
public String addMenuUplinkSeries(Long menuId) {
|
||||
StringBuilder menuus=new StringBuilder();
|
||||
SqMenu sqMenu = sqMenuMapper.selectSqMenuById(menuId);
|
||||
Long parentId = sqMenu.getParentId();
|
||||
//所有的上级目录ID
|
||||
List<Long> list= new ArrayList<>();
|
||||
list.add(menuId);
|
||||
while (parentId.intValue()!=0){
|
||||
sqMenu = sqMenuMapper.selectSqMenuById(parentId);
|
||||
list.add(sqMenu.getMenuId());
|
||||
parentId=sqMenu.getParentId();
|
||||
}
|
||||
//倒序
|
||||
for (int i=list.size();i>0;i--){
|
||||
menuus.append(",").append(list.get(i-1));
|
||||
}
|
||||
menuus.append(",");
|
||||
return menuus.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量减少目录下书签数量
|
||||
@ -212,4 +257,42 @@ public class SqMenuServiceImpl implements ISqMenuService
|
||||
public int updateCountAdd(Long[] menuIds,int icount){
|
||||
return sqMenuMapper.updateCountAdd(menuIds,icount);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SqMenu> listByMenuUplinkSeriesAndMenu(String menuUplinkSeries, Long menuId) {
|
||||
return sqMenuMapper.listByMenuUplinkSeriesAndMenu(menuUplinkSeries,menuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countByMenuUplinkSeriesAndMenu(String menuUplinkSeries, Long menuId) {
|
||||
return sqMenuMapper.countByMenuUplinkSeriesAndMenu(menuUplinkSeries,menuId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addMenuByCountAndMenuUplinkSeries(Long menuId) {
|
||||
//修改 需要查最新目录串
|
||||
SqMenu sqMenu = sqMenuMapper.selectSqMenuById(menuId);
|
||||
if (!sqMenu.getParentId().toString().equals("0")){
|
||||
//所有的上级ID
|
||||
String[] arrayMenuID = sqMenu.getMenuUplinkSeries().replace(menuId+",","").split(",");
|
||||
Long[] strArrNum = (Long[]) ConvertUtils.convert(arrayMenuID,Long.class);
|
||||
//所有上级 添加书签数量
|
||||
sqMenuMapper.updateCountAdd(strArrNum,sqMenu.getBookmarkCount());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reduceMenuByCountAndMenuUplinkSeries(SqMenu sqMenu) {
|
||||
if (!sqMenu.getParentId().toString().equals("0")){
|
||||
//所有的上级ID
|
||||
String[] arrayMenuID = sqMenu.getMenuUplinkSeries().replace(sqMenu.getMenuId()+",","").split(",");
|
||||
//转换
|
||||
Long[] strArrNum = (Long[]) ConvertUtils.convert(arrayMenuID,Long.class);
|
||||
//所有上级 减少书签数量
|
||||
sqMenuMapper.updateCountReduce(strArrNum,sqMenu.getBookmarkCount());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,10 +15,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="bookmarkCount" column="bookmark_count" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="menuUplinkSeries" column="menu_uplink_series" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSqMenuVo">
|
||||
select menu_id, user_id, menu_name, menu_url, menu_icon, parent_id, menu_order,bookmark_count,create_time,update_time from sq_menu
|
||||
select menu_id, user_id, menu_name, menu_url, menu_icon, parent_id, menu_order,bookmark_count,create_time,update_time,menu_uplink_series from sq_menu
|
||||
</sql>
|
||||
|
||||
<select id="selectSqMenuList" parameterType="SqMenu" resultMap="SqMenuResult">
|
||||
@ -34,6 +35,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
order BY menu_order ASC
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectbymenuUplinkSeries" resultMap="SqMenuResult">
|
||||
select menu_id,user_id from sq_menu where menu_uplink_series is null
|
||||
</select>
|
||||
<select id="listByMenuUplinkSeriesAndMenu" resultMap="SqMenuResult">
|
||||
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 sum(bookmark_count) from sq_menu where menu_uplink_series like '#{menuUplinkSeries}%'
|
||||
<if test="menuId != null "> and menu_id != #{menuId}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectSqMenuById" parameterType="Long" resultMap="SqMenuResult">
|
||||
<include refid="selectSqMenuVo"/>
|
||||
@ -75,6 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="menuOrder != null">menu_order = #{menuOrder},</if>
|
||||
<if test="bookmarkCount != null">bookmark_count = #{bookmarkCount},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="menuUplinkSeries != null">menu_uplink_series = #{menuUplinkSeries},</if>
|
||||
</trim>
|
||||
where menu_id = #{menuId}
|
||||
</update>
|
||||
|
Reference in New Issue
Block a user