| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminAddBarDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminNavigationBarDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminUpdateBarDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.NavigationBarEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.NavigationBarMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.UserRoleMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.INavigationBarService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminNavigationBarVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeBarInfoVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class NavigationBarServiceImpl extends ServiceImpl<NavigationBarMapper, NavigationBarEntity> implements INavigationBarService { |
| | | |
| | | @Resource |
| | | private NavigationBarMapper navigationBarMapper; |
| | | |
| | | @Override |
| | | public Result getBarInPage(AdminNavigationBarDto adminNavigationBarDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | Page<AdminNavigationBarVo> page = new Page<>(adminNavigationBarDto.getPageNum(), adminNavigationBarDto.getPageSize()); |
| | | NavigationBarEntity navigationBarEntity = new NavigationBarEntity(); |
| | | navigationBarEntity.setParentId(NavigationBarEntity.PARENTID_DEFAULT); |
| | | IPage<AdminNavigationBarVo> list = this.baseMapper.selectAdminNavigationBarVoInPage(page,navigationBarEntity); |
| | | navigationBarEntity.setCompanyId(companyId); |
| | | IPage<AdminNavigationBarVo> list = navigationBarMapper.selectAdminNavigationBarVoInPage(page,navigationBarEntity); |
| | | List<AdminNavigationBarVo> records = list.getRecords(); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(AdminNavigationBarVo adminNavigationBarVo : records){ |
| | | Long id = adminNavigationBarVo.getId(); |
| | | QueryWrapper<NavigationBarEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("parent_id",id); |
| | | List<NavigationBarEntity> navigationBarEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | List<NavigationBarEntity> navigationBarEntities = navigationBarMapper.selectList(objectQueryWrapper); |
| | | List<AdminNavigationBarVo> adminNavigationBarVoChilds = new ArrayList<>(); |
| | | if(CollUtil.isNotEmpty(navigationBarEntities)){ |
| | | for(NavigationBarEntity navigationBarEntityChild : navigationBarEntities){ |
| | |
| | | child.setId(navigationBarEntityChild.getId()); |
| | | child.setBarName(navigationBarEntityChild.getBarName()); |
| | | child.setLinkUrl(navigationBarEntityChild.getLinkUrl()); |
| | | child.setDescribe(navigationBarEntityChild.getDescribe()); |
| | | child.setRemark(navigationBarEntityChild.getRemark()); |
| | | child.setPic(navigationBarEntityChild.getPic()); |
| | | child.setOrderNum(navigationBarEntityChild.getOrderNum()); |
| | | adminNavigationBarVoChilds.add(child); |
| | |
| | | @Override |
| | | @Transactional |
| | | public Result addBar(AdminAddBarDto adminAddBarDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | NavigationBarEntity navigationBarEntity = new NavigationBarEntity(); |
| | | navigationBarEntity.setCompanyId(companyId); |
| | | String barName = adminAddBarDto.getBarName(); |
| | | if(StrUtil.isEmpty(barName)){ |
| | | return Result.fail("请输入导航栏标题"); |
| | | } |
| | | navigationBarEntity.setBarName(barName); |
| | | Long parentId = adminAddBarDto.getParentId(); |
| | | if(ObjectUtil.isEmpty(parentId)){ |
| | |
| | | navigationBarEntity.setParentId(parentId); |
| | | } |
| | | String linkUrl = adminAddBarDto.getLinkUrl(); |
| | | if(StrUtil.isNotEmpty(linkUrl)){ |
| | | navigationBarEntity.setLinkUrl(linkUrl); |
| | | } |
| | | Integer orderNum = adminAddBarDto.getOrderNum(); |
| | | if(ObjectUtil.isNotEmpty(orderNum)){ |
| | | navigationBarEntity.setOrderNum(orderNum); |
| | | } |
| | | String pic = adminAddBarDto.getPic(); |
| | | if(StrUtil.isNotEmpty(pic)){ |
| | | navigationBarEntity.setPic(pic); |
| | | } |
| | | String describe = adminAddBarDto.getDescribe(); |
| | | if(StrUtil.isNotEmpty(describe)){ |
| | | navigationBarEntity.setDescribe(describe); |
| | | } |
| | | this.baseMapper.insert(navigationBarEntity); |
| | | String remark = adminAddBarDto.getRemark(); |
| | | navigationBarEntity.setRemark(remark); |
| | | navigationBarMapper.insert(navigationBarEntity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result deleteBar(Long id) { |
| | | NavigationBarEntity navigationBarEntity = this.baseMapper.selectById(id); |
| | | NavigationBarEntity navigationBarEntity = navigationBarMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(navigationBarEntity)){ |
| | | return Result.fail("导航栏不存在"); |
| | | } |
| | | QueryWrapper<NavigationBarEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("parent_id",id); |
| | | List<NavigationBarEntity> navigationBarEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | List<NavigationBarEntity> navigationBarEntities = navigationBarMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(navigationBarEntities)){ |
| | | return Result.fail("请先清空它的二级导航栏"); |
| | | } |
| | | this.baseMapper.deleteById(id); |
| | | navigationBarMapper.deleteById(id); |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result seeBarInfo(Long id) { |
| | | NavigationBarEntity navigationBarEntity = this.baseMapper.selectById(id); |
| | | NavigationBarEntity navigationBarEntity = navigationBarMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(navigationBarEntity)){ |
| | | return Result.fail("导航栏不存在"); |
| | | } |
| | |
| | | adminSeeBarInfoVo.setId(navigationBarEntity.getId()); |
| | | adminSeeBarInfoVo.setBarName(navigationBarEntity.getBarName()); |
| | | adminSeeBarInfoVo.setLinkUrl(navigationBarEntity.getLinkUrl()); |
| | | adminSeeBarInfoVo.setDescribe(navigationBarEntity.getDescribe()); |
| | | adminSeeBarInfoVo.setRemark(navigationBarEntity.getRemark()); |
| | | adminSeeBarInfoVo.setOrderNum(navigationBarEntity.getOrderNum()); |
| | | adminSeeBarInfoVo.setPic(navigationBarEntity.getPic()); |
| | | adminSeeBarInfoVo.setParentId(navigationBarEntity.getParentId()); |
| | |
| | | if(ObjectUtil.isEmpty(id)){ |
| | | return Result.fail("导航栏不存在"); |
| | | } |
| | | NavigationBarEntity navigationBarEntity = this.baseMapper.selectById(id); |
| | | NavigationBarEntity navigationBarEntity = navigationBarMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(navigationBarEntity)){ |
| | | return Result.fail("导航栏不存在"); |
| | | } |
| | | String barName = adminUpdateMenuDto.getBarName(); |
| | | if(StrUtil.isEmpty(barName)){ |
| | | return Result.fail("请输入导航栏标题"); |
| | | } |
| | | navigationBarEntity.setBarName(barName); |
| | | Long parentId = adminUpdateMenuDto.getParentId(); |
| | | if(ObjectUtil.isEmpty(parentId)){ |
| | |
| | | navigationBarEntity.setParentId(parentId); |
| | | } |
| | | String linkUrl = adminUpdateMenuDto.getLinkUrl(); |
| | | if(StrUtil.isNotEmpty(linkUrl)){ |
| | | navigationBarEntity.setLinkUrl(linkUrl); |
| | | } |
| | | Integer orderNum = adminUpdateMenuDto.getOrderNum(); |
| | | if(ObjectUtil.isNotEmpty(orderNum)){ |
| | | navigationBarEntity.setOrderNum(orderNum); |
| | | } |
| | | String pic = adminUpdateMenuDto.getPic(); |
| | | if(StrUtil.isNotEmpty(pic)){ |
| | | navigationBarEntity.setPic(pic); |
| | | } |
| | | String describe = adminUpdateMenuDto.getDescribe(); |
| | | if(StrUtil.isNotEmpty(describe)){ |
| | | navigationBarEntity.setDescribe(describe); |
| | | } |
| | | this.baseMapper.updateById(navigationBarEntity); |
| | | String remark = adminUpdateMenuDto.getRemark(); |
| | | navigationBarEntity.setRemark(remark); |
| | | navigationBarMapper.updateById(navigationBarEntity); |
| | | return Result.ok("更新成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result getBarInList() { |
| | | List<AdminNavigationBarVo> records = this.baseMapper.selectAdminNavigationBarVoByParentId(NavigationBarEntity.PARENTID_DEFAULT); |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | List<AdminNavigationBarVo> records = navigationBarMapper.selectAdminNavigationBarVoByParentId(NavigationBarEntity.PARENTID_DEFAULT,companyId); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(AdminNavigationBarVo adminNavigationBarVo : records){ |
| | | Long id = adminNavigationBarVo.getId(); |
| | | QueryWrapper<NavigationBarEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("parent_id",id); |
| | | List<NavigationBarEntity> navigationBarEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | List<NavigationBarEntity> navigationBarEntities = navigationBarMapper.selectListByParentId(id,companyId); |
| | | List<AdminNavigationBarVo> adminNavigationBarVoChilds = new ArrayList<>(); |
| | | if(CollUtil.isNotEmpty(navigationBarEntities)){ |
| | | for(NavigationBarEntity navigationBarEntityChild : navigationBarEntities){ |
| | |
| | | child.setId(navigationBarEntityChild.getId()); |
| | | child.setBarName(navigationBarEntityChild.getBarName()); |
| | | child.setLinkUrl(navigationBarEntityChild.getLinkUrl()); |
| | | child.setDescribe(navigationBarEntityChild.getDescribe()); |
| | | child.setRemark(navigationBarEntityChild.getRemark()); |
| | | child.setPic(navigationBarEntityChild.getPic()); |
| | | child.setOrderNum(navigationBarEntityChild.getOrderNum()); |
| | | adminNavigationBarVoChilds.add(child); |
| | |
| | | } |
| | | return Result.ok(records); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result delObjs(AdminDeleteDto adminDeleteDto) { |
| | | String ids = adminDeleteDto.getIds(); |
| | | if(StrUtil.isNotEmpty(ids)){ |
| | | String[] barIds = ids.split(StringPool.COMMA); |
| | | for(String barIdStr : barIds){ |
| | | Long barId = Long.valueOf(barIdStr); |
| | | QueryWrapper<NavigationBarEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("parent_id",barId); |
| | | navigationBarMapper.delete(objectQueryWrapper); |
| | | |
| | | navigationBarMapper.deleteById(barId); |
| | | } |
| | | } |
| | | return Result.ok("删除成功"); |
| | | } |
| | | } |