Commit 5b9c7b12 by fengshuonan

适配sql server,改掉所有pids like语句

parent d5e51511
......@@ -300,9 +300,8 @@ public class ConstantFactory implements IConstantFactory {
@Override
public List<Long> getSubDeptId(Long deptId) {
QueryWrapper<Dept> wrapper = new QueryWrapper<>();
wrapper = wrapper.like("PIDS", "%[" + deptId + "]%");
List<Dept> depts = this.deptMapper.selectList(wrapper);
List<Dept> depts = this.deptMapper.likePids(deptId);
ArrayList<Long> deptids = new ArrayList<>();
......
/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.stylefeng.guns.core.common.constant.state;
import lombok.Getter;
/**
* 公共状态
*
* @author fengshuonan
* @Date 2017年1月22日 下午12:14:59
*/
@Getter
public enum CommonStatus {
ENABLE("ENABLE", "启用"),
DISABLE("DISABLE", "禁用");
String code;
String message;
CommonStatus(String code, String message) {
this.code = code;
this.message = message;
}
public static String getDescription(String status) {
if (status == null) {
return "";
} else {
for (CommonStatus s : CommonStatus.values()) {
if (s.getCode().equals(status)) {
return s.getMessage();
}
}
return "";
}
}
}
......@@ -34,4 +34,9 @@ public interface DeptMapper extends BaseMapper<Dept> {
* 获取所有部门树列表
*/
List<TreeviewNode> treeviewNodes();
/**
* where pids like ''
*/
List<Dept> likePids(Long deptId);
}
......@@ -21,4 +21,8 @@ public interface DictMapper extends BaseMapper<Dict> {
*/
List<ZTreeNode> dictTree(Long dictTypeId);
/**
* where parentIds like ''
*/
List<Dict> likeParentIds(Long dictId);
}
......@@ -87,5 +87,12 @@ public interface MenuMapper extends BaseMapper<Menu> {
*/
List<Map<String, Object>> selectMenuTree(@Param("condition") String condition, @Param("level") String level);
/**
* 获取pcodes like某个code的菜单列表
*
* @author fengshuonan
* @Date 2019/3/31 15:51
*/
List<Menu> getMenusLikePcodes(@Param("code") String code);
}
......@@ -52,4 +52,13 @@
select DEPT_ID AS tags, PID as parentId, SIMPLE_NAME as text from sys_dept
</select>
<select id="likePids" resultType="cn.stylefeng.guns.modular.system.entity.Dept">
select
<include refid="Base_Column_List"/>
from sys_dept
<where>
PIDS LIKE CONCAT('%$[',#{deptId},'$]%') escape '$'
</where>
</select>
</mapper>
......@@ -32,7 +32,16 @@
ELSE
'false'
END
) as open from sys_dict where DICT_TYPE_ID = #{dictTypeId}
) as 'open' from sys_dict where DICT_TYPE_ID = #{dictTypeId}
</select>
<select id="likeParentIds" resultType="cn.stylefeng.guns.modular.system.entity.Dict">
select
<include refid="Base_Column_List"></include>
from sys_dict as base
<where>
PARENT_IDS LIKE CONCAT('%$[',#{dictId},'$]%') escape '$'
</where>
</select>
</mapper>
......@@ -107,7 +107,7 @@
ELSE
'true'
END
) as `checked`
) as 'checked'
FROM
sys_menu m1
LEFT JOIN
......@@ -195,4 +195,14 @@
</if>
</select>
<select id="getMenusLikePcodes" resultType="cn.stylefeng.guns.modular.system.entity.Menu">
select
<include refid="Base_Column_List"></include>
from sys_menu
<where>
PCODES LIKE CONCAT('%$[',#{code},'$]%') escape '$'
</where>
</select>
</mapper>
......@@ -45,7 +45,7 @@
SELECT
r.ROLE_ID as id,
PID as pId,
NAME AS `name`,
NAME AS 'name',
(
CASE
WHEN (PID = 0 OR PID IS NULL) THEN
......
......@@ -8,7 +8,6 @@ import cn.stylefeng.guns.modular.system.entity.Dept;
import cn.stylefeng.guns.modular.system.mapper.DeptMapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
......@@ -81,9 +80,8 @@ public class DeptService extends ServiceImpl<DeptMapper, Dept> {
Dept dept = deptMapper.selectById(deptId);
//根据like查询删除所有级联的部门
QueryWrapper<Dept> wrapper = new QueryWrapper<>();
wrapper = wrapper.like("PIDS", "%[" + dept.getDeptId() + "]%");
List<Dept> subDepts = deptMapper.selectList(wrapper);
List<Dept> subDepts = deptMapper.likePids(dept.getDeptId());
for (Dept temp : subDepts) {
this.removeById(temp.getDeptId());
}
......
package cn.stylefeng.guns.modular.system.service;
import cn.stylefeng.guns.core.common.constant.state.CommonStatus;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.core.common.node.ZTreeNode;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
......@@ -54,6 +55,9 @@ public class DictService extends ServiceImpl<DictMapper, Dict> {
//设置pids
dictSetPids(entity);
//设置状态
entity.setStatus(CommonStatus.ENABLE.getCode());
this.save(entity);
}
......@@ -241,9 +245,8 @@ public class DictService extends ServiceImpl<DictMapper, Dict> {
}
private List<Long> getSubIds(Long dictId) {
QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
dictQueryWrapper.like("PARENT_IDS", "%[" + dictId + "]%");
List<Dict> list = this.list(dictQueryWrapper);
List<Dict> list = this.baseMapper.likeParentIds(dictId);
ArrayList<Long> longs = new ArrayList<>();
for (Dict dict : list) {
......
package cn.stylefeng.guns.modular.system.service;
import cn.stylefeng.guns.core.common.constant.state.CommonStatus;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.core.common.page.LayuiPageInfo;
......@@ -46,6 +47,10 @@ public class DictTypeService extends ServiceImpl<DictTypeMapper, DictType> {
}
DictType entity = getEntity(param);
//设置状态
entity.setStatus(CommonStatus.ENABLE.getCode());
this.save(entity);
}
......
......@@ -109,9 +109,7 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> {
@Transactional(rollbackFor = Exception.class)
public void updateSubMenuLevels(Menu oldMenu, Menu newMenu) {
QueryWrapper<Menu> wrapper = new QueryWrapper<>();
wrapper = wrapper.like("PCODES", "%[" + oldMenu.getCode() + "]%");
List<Menu> menus = menuMapper.selectList(wrapper);
List<Menu> menus = menuMapper.getMenusLikePcodes(oldMenu.getCode());
for (Menu menu : menus) {
......@@ -166,9 +164,8 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> {
delMenu(menuId);
//删除所有子菜单
QueryWrapper<Menu> wrapper = new QueryWrapper<>();
wrapper = wrapper.like("PCODES", "%[" + menu.getCode() + "]%");
List<Menu> menus = menuMapper.selectList(wrapper);
List<Menu> menus = menuMapper.getMenusLikePcodes(menu.getCode());
for (Menu temp : menus) {
delMenu(temp.getMenuId());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment