Java源码示例:com.baomidou.mybatisplus.mapper.Wrapper
示例1
@Override
public void delMenuContainSubMenus(Long menuId) {
Menu menu = menuMapper.selectById(menuId);
//删除当前菜单
delMenu(menuId);
//删除所有子菜单
Wrapper<Menu> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pcodes", "%[" + menu.getCode() + "]%");
List<Menu> menus = menuMapper.selectList(wrapper);
for (Menu temp : menus) {
delMenu(temp.getId());
}
}
示例2
/**
* 根据字典名称和字典中的值获取对应的名称
*/
@Override
public String getDictsByName(String name, Integer val) {
Dict temp = new Dict();
temp.setName(name);
Dict dict = dictMapper.selectOne(temp);
if (dict == null) {
return "";
} else {
Wrapper<Dict> wrapper = new EntityWrapper<>();
wrapper = wrapper.eq("pid", dict.getId());
List<Dict> dicts = dictMapper.selectList(wrapper);
for (Dict item : dicts) {
if (item.getNum() != null && item.getNum().equals(val)) {
return item.getName();
}
}
return "";
}
}
示例3
/**
* 获取子部门id
*/
@Override
public List<Integer> getSubDeptId(Integer deptid) {
Wrapper<Dept> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pids", "%[" + deptid + "]%");
List<Dept> depts = this.deptMapper.selectList(wrapper);
ArrayList<Integer> deptids = new ArrayList<>();
if(depts != null && depts.size() > 0){
for (Dept dept : depts) {
deptids.add(dept.getId());
}
}
return deptids;
}
示例4
@Override
@Transactional
public void delMenuContainSubMenus(Long menuId) {
Menu menu = menuMapper.selectById(menuId);
//删除当前菜单
delMenu(menuId);
//删除所有子菜单
Wrapper<Menu> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pcodes", "%[" + menu.getCode() + "]%");
List<Menu> menus = menuMapper.selectList(wrapper);
for (Menu temp : menus) {
delMenu(temp.getId());
}
}
示例5
/**
* 根据字典名称和字典中的值获取对应的名称
*/
@Override
public String getDictsByName(String name, Integer val) {
Dict temp = new Dict();
temp.setName(name);
Dict dict = dictMapper.selectOne(temp);
if (dict == null) {
return "";
} else {
Wrapper<Dict> wrapper = new EntityWrapper<>();
wrapper = wrapper.eq("pid", dict.getId());
List<Dict> dicts = dictMapper.selectList(wrapper);
for (Dict item : dicts) {
if (item.getNum() != null && item.getNum().equals(val)) {
return item.getName();
}
}
return "";
}
}
示例6
/**
* 获取子部门id
*/
@Override
public List<Integer> getSubDeptId(Integer deptid) {
Wrapper<Dept> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pids", "%[" + deptid + "]%");
List<Dept> depts = this.deptMapper.selectList(wrapper);
ArrayList<Integer> deptids = new ArrayList<>();
if (depts != null && depts.size() > 0) {
for (Dept dept : depts) {
deptids.add(dept.getId());
}
}
return deptids;
}
示例7
@Override
public Page<AdminDTO> list(String name, Integer page, Integer limit, Long adminId) throws ServiceException {
Wrapper<AdminDO> wrapper = new EntityWrapper<AdminDO>();
if (!StringUtils.isEmpty(name)) {
wrapper.like("username", name);
}
wrapper.orderBy("id", false);
Integer count = adminMapper.selectCount(wrapper);
List<AdminDO> adminDOS = adminMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
List<AdminDTO> adminDTOS = new ArrayList<AdminDTO>(adminDOS.size());
for (AdminDO adminDO : adminDOS) {
AdminDTO adminDTO = new AdminDTO();
BeanUtils.copyProperties(adminDO, adminDTO);
adminDTO.setRoleIds(JSONObject.parseArray(adminDO.getRoleIds(), Long.class));
adminDTO.setPassword(null);
adminDTOS.add(adminDTO);
}
return new Page<>(adminDTOS, page, limit, count);
}
示例8
@Override
public Page<AdvertisementDO> queryAdvertisement(Long adminId, Integer adType, Integer pageNo, Integer limit, Integer status) throws ServiceException {
Wrapper<AdvertisementDO> wrapper = new EntityWrapper<AdvertisementDO>();
if (adType != null) {
wrapper.eq("ad_type", adType);
}
if (status != null) {
wrapper.eq("status", status);
}
List<AdvertisementDO> advertisementDOList = advertisementMapper.selectPage(new RowBounds(limit *(pageNo - 1), limit),wrapper);
Integer count = advertisementMapper.selectCount(wrapper);
Page<AdvertisementDO> page = new Page<>(advertisementDOList,pageNo, limit,count);
return page;
}
示例9
@Override
public PageResult<User> list(int pageNum, int pageSize, boolean showDelete, String column, String value) {
Wrapper<User> wrapper = new EntityWrapper<>();
if (StringUtil.isNotBlank(column)) {
wrapper.like(column, value);
}
if (!showDelete) { // 不显示锁定的用户
wrapper.eq("state", 0);
}
Page<User> userPage = new Page<>(pageNum, pageSize);
List<User> userList = userMapper.selectPage(userPage, wrapper.orderBy("create_time", true));
if (userList != null && userList.size() > 0) {
// 查询user的角色
List<UserRole> userRoles = userRoleMapper.selectByUserIds(getUserIds(userList));
for (User one : userList) {
List<Role> tempURs = new ArrayList<>();
for (UserRole ur : userRoles) {
if (one.getUserId().equals(ur.getUserId())) {
tempURs.add(new Role(ur.getRoleId(), ur.getRoleName()));
}
}
one.setRoles(tempURs);
}
}
return new PageResult<>(userPage.getTotal(), userList);
}
示例10
@Override
public void deleteDept(Integer deptId) {
Dept dept = deptMapper.selectById(deptId);
Wrapper<Dept> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pids", "%[" + dept.getId() + "]%");
List<Dept> subDepts = deptMapper.selectList(wrapper);
for (Dept temp : subDepts) {
temp.deleteById();
}
dept.deleteById();
}
示例11
@Override
public void delteDict(Integer dictId) {
//删除这个字典的子词典
Wrapper<Dict> dictEntityWrapper = new EntityWrapper<>();
dictEntityWrapper = dictEntityWrapper.eq("pid", dictId);
dictMapper.delete(dictEntityWrapper);
//删除这个词典
dictMapper.deleteById(dictId);
}
示例12
private Menu getParentMenu(String code) {
Wrapper<Menu> wrapper = new EntityWrapper<Menu>();
wrapper = wrapper.eq("code", code);
List<Menu> menus = menuMapper.selectList(wrapper);
if (menus == null || menus.size() == 0) {
return new Menu();
} else {
return menus.get(0);
}
}
示例13
@Override
@Transactional
public void deleteDept(Integer deptId) {
Dept dept = deptMapper.selectById(deptId);
Wrapper<Dept> wrapper = new EntityWrapper<>();
wrapper = wrapper.like("pids", "%[" + dept.getId() + "]%");
List<Dept> subDepts = deptMapper.selectList(wrapper);
for (Dept temp : subDepts) {
temp.deleteById();
}
dept.deleteById();
}
示例14
@Override
@Transactional
public void delteDict(Integer dictId) {
//删除这个字典的子词典
Wrapper<Dict> dictEntityWrapper = new EntityWrapper<>();
dictEntityWrapper = dictEntityWrapper.eq("pid", dictId);
dictMapper.delete(dictEntityWrapper);
//删除这个词典
dictMapper.deleteById(dictId);
}
示例15
@Override
public Page<RoleDO> list(String name, Integer page, Integer limit, Long adminId) throws ServiceException {
Wrapper<RoleDO> wrapper = new EntityWrapper<RoleDO>();
if (!StringUtils.isEmpty(name)) {
wrapper.like("name", name);
}
List<RoleDO> roleDOS = roleMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
Integer count = roleMapper.selectCount(wrapper);
return new Page<RoleDO>(roleDOS, page, limit, count);
}
示例16
@Override
public Page<OrderDO> list(Integer pageNo, Integer pageSize, Integer status, String orderNo, Long adminId) throws ServiceException {
Wrapper<OrderDO> wrapper = new EntityWrapper<OrderDO>();
wrapper.orderBy("id", false);
if (!StringUtils.isEmpty(orderNo)) {
wrapper.eq("order_no", orderNo);
}
if (status != null) {
wrapper.eq("status", status);
}
List<OrderDO> orderDOS = orderMapper.selectPage(new RowBounds((pageNo - 1) * pageSize, pageSize), wrapper);
Integer count = orderMapper.selectCount(wrapper);
return new Page<OrderDO>(orderDOS, pageNo, pageSize, count);
}
示例17
public OrderDO checkOrderExist(String orderNo, Long userId) throws ServiceException {
Wrapper<OrderDO> wrapper = new EntityWrapper<OrderDO>().eq("order_no", orderNo);
if (userId != null) {
wrapper.eq("user_id", userId);
}
List<OrderDO> orderDOS = orderMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(orderDOS)) {
throw new AppServiceException(ExceptionDefinition.ORDER_NOT_EXIST);
}
return orderDOS.get(0);
}
示例18
public OrderDTO getOrderDetail(Long orderId, Long userId) throws ServiceException {
Wrapper<OrderDO> wrapper = new EntityWrapper<OrderDO>()
.eq("id", orderId);
if (userId != null) {
wrapper.eq("user_id", userId);
}
List<OrderDO> orderDOS = orderMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(orderDOS)) {
throw new AppServiceException(ExceptionDefinition.ORDER_NOT_EXIST);
}
OrderDTO orderDTO = new OrderDTO();
BeanUtils.copyProperties(orderDOS.get(0), orderDTO);
orderDTO.setSkuList(orderSkuMapper.selectList(new EntityWrapper<OrderSkuDO>().eq("order_id", orderId)));
return orderDTO;
}
示例19
@Override
public List<AdvertisementDO> getActiveAd(Integer adType) throws ServiceException {
List<AdvertisementDO> advertisementDOList
= cacheComponent.getObjList(ADVERTISEMENT_NAME + adType, AdvertisementDO.class);
if (CollectionUtils.isEmpty(advertisementDOList)) {
Wrapper<AdvertisementDO> wrapper = new EntityWrapper<AdvertisementDO>()
.eq("status", StatusType.ACTIVE.getCode());
if (adType != null) {
wrapper.eq("ad_type", adType);
}
advertisementDOList = advertisementMapper.selectList(wrapper);
cacheComponent.putObj(ADVERTISEMENT_NAME + adType, advertisementDOList, 100);
}
return advertisementDOList;
}
示例20
@Override
public List<Role> list(boolean showDelete) {
Wrapper wrapper = new EntityWrapper();
if (!showDelete) {
wrapper.eq("is_delete", 0);
}
return roleMapper.selectList(wrapper.orderBy("create_time", true));
}
示例21
@Override
public void enable(Long id) {
Wrapper<Dict> wrapper = this.newEntityWrapper();
wrapper.eq("id", id);
wrapper.eq("enable", CommonConstant.COMMON_NO);
Dict dict = new Dict();
dict.setEnable(CommonConstant.COMMON_YES);
Boolean result = this.update(dict, wrapper);
Assert.isTrue(result, "数据字典已启用");
}
示例22
@Override
public void disable(Long id) {
Wrapper<Dict> wrapper = this.newEntityWrapper();
wrapper.eq("id", id);
wrapper.eq("enable", CommonConstant.COMMON_YES);
Dict dict = new Dict();
dict.setEnable(CommonConstant.COMMON_NO);
Boolean result = this.update(dict, wrapper);
Assert.isTrue(result, "数据字典已禁用");
}
示例23
@Override
public boolean exists(Long resourceId, Long roleId) {
Wrapper<SysAuthority> wrapper = new EntityWrapper<SysAuthority>();
wrapper.eq("sys_resource_id", resourceId);
wrapper.eq("sys_role_id", roleId);
return CollectionUtils.isEmpty(this.selectList(wrapper));
}
示例24
@Override
public void delete(Long resourceId, Long roleId) {
this.validateRole(roleId);
Wrapper<SysAuthority> wrapper = new EntityWrapper<SysAuthority>();
wrapper.eq("sys_resource_id", resourceId);
wrapper.eq("sys_role_id", roleId);
SysAuthority authority = this.selectOne(wrapper);
if (authority != null) {
this.deleteById(authority.getId());
}
}
示例25
private boolean notExists(SysAuthorize authorize) {
Wrapper<SysAuthorize> wrapper = new EntityWrapper<SysAuthorize>();
wrapper.eq("authorize_target", authorize.getAuthorizeTarget());
wrapper.eq("sys_role_id", authorize.getSysRoleId());
wrapper.eq("authorize_type", authorize.getAuthorizeType());
return CollectionUtils.isEmpty(this.selectList(wrapper));
}
示例26
@Override
public void delete(Long userId, Long roleId) {
this.validateRole(roleId);
Wrapper<SysAuthorize> wrapper = new EntityWrapper<SysAuthorize>();
wrapper.eq("authorize_target", userId);
wrapper.eq("sys_role_id", roleId);
SysAuthorize authority = this.selectOne(wrapper);
if (authority != null) {
this.deleteById(authority.getId());
}
}
示例27
/**
* 检查是否有重复属性的数据
*
* @param property
* @param value
* @param excludeId
* @return
*/
public boolean checkProperty(String property, Object value, Long excludeId) {
if (value == null || StringUtils.isEmpty(String.valueOf(value))) {
return true;
}
List<SysUser> users = null;
Wrapper<SysUser> wrapper = new EntityWrapper<SysUser>();
wrapper.eq(property, value);
if (excludeId != null) {
wrapper.ne("id", excludeId);
}
users = this.mapper.selectList(wrapper);
return (users.size() == 0);
}
示例28
public Page<SpuDTO> getGoodsPage(Integer pageNo, Integer pageSize, Long categoryId, String orderBy, Boolean isAsc, String title) throws ServiceException {
Wrapper<SpuDO> wrapper = new EntityWrapper<SpuDO>();
if (!StringUtils.isEmpty(title)) {
wrapper.like("title", title);
} else {
//若关键字为空,尝试从缓存取列表
Page objFromCache = cacheComponent.getObj(CA_SPU_PAGE_PREFIX + categoryId + "_" + pageNo + "_" + pageSize + "_" + orderBy + "_" + isAsc, Page.class);
if (objFromCache != null) {
return objFromCache;
}
}
if(orderBy != null && isAsc != null){
wrapper.orderBy(orderBy, isAsc);
}
if (categoryId != null && categoryId != 0L) {
List<CategoryDO> childrenList = categoryMapper.selectList(new EntityWrapper<CategoryDO>().eq("parent_id", categoryId));
if (CollectionUtils.isEmpty(childrenList)) {
//目标节点为叶子节点,即三级类目
wrapper.eq("category_id", categoryId);
} else {
//目标节点存在子节点
LinkedList<Long> childrenIds = new LinkedList<>();
CategoryDO categoryDO = categoryMapper.selectById(categoryId);
// 检验传入类目是一级还是二级类目
if (categoryDO.getParentId() != 0L) {
//二级分类
childrenList.forEach(item -> {
childrenIds.add(item.getId());
});
} else {
//一级分类
childrenList.forEach(item -> {
List<CategoryDO> leafList = categoryMapper.selectList(new EntityWrapper<CategoryDO>().eq("parent_id", item.getId()));
if (!CollectionUtils.isEmpty(leafList)) {
leafList.forEach(leafItem -> {
childrenIds.add(leafItem.getId());
});
}
});
}
wrapper.in("category_id", childrenIds);
}
}
wrapper.eq("status", SpuStatusType.SELLING.getCode());
wrapper.setSqlSelect(baseColumns);
List<SpuDO> spuDOS = spuMapper.selectPage(new RowBounds((pageNo - 1) * pageSize, pageSize), wrapper);
//组装SPU
List<SpuDTO> spuDTOList = new ArrayList<>();
spuDOS.forEach(item -> {
SpuDTO spuDTO = new SpuDTO();
BeanUtils.copyProperties(item, spuDTO);
Map<String, String> hashAll = cacheComponent.getHashAll(CA_SPU_SALES_HASH);
if (hashAll != null) {
String salesStr = hashAll.get("S" + item.getId());
if (!StringUtils.isEmpty(salesStr)) {
spuDTO.setSales(new Integer(salesStr));
}
}
spuDTOList.add(spuDTO);
});
Integer count = spuMapper.selectCount(wrapper);
Page<SpuDTO> page = new Page<>(spuDTOList, pageNo, pageSize, count);
if (StringUtils.isEmpty(title)) {
//若关键字为空,制作缓存
cacheComponent.putObj(CA_SPU_PAGE_PREFIX + categoryId + "_" + pageNo + "_" + pageSize + "_" + orderBy + "_" + isAsc, page, Const.CACHE_ONE_DAY);
}
return page;
}
示例29
/**
* {@inheritDoc}
*/
@Override
public T selectOne(Wrapper<T> entity) {
List<T> list = mapper.selectList(entity);
return CollectionUtils.isEmpty(list) ? null : list.get(0);
}
示例30
/**
* {@inheritDoc}
*/
@Override
public List<T> selectList(Wrapper<T> entity) {
return mapper.selectList(entity);
}