| | |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminColumnDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminUpdateColumnDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.ArticleEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.ColumnEntity; |
| | | 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.ArticleMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.ColumnMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.IColumnService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminColumnVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeColumnInfoVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class ColumnServiceImpl extends ServiceImpl<ColumnMapper, ColumnEntity> implements IColumnService { |
| | | |
| | | @Autowired |
| | | private ArticleMapper articleMapper; |
| | | |
| | | @Override |
| | | public Result getColumnInPage(AdminColumnDto adminColumnDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | |
| | | String columnCode = adminAddColumnDto.getColumnCode(); |
| | | QueryWrapper<ColumnEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("column_code",columnCode); |
| | | if(UserEntity.USER_BELONG_TOP != companyId){ |
| | | objectQueryWrapper.eq("company_id",companyId); |
| | | } |
| | | List<ColumnEntity> columnEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(columnEntities)){ |
| | | return Result.fail("栏目编码不能重复"); |
| | |
| | | }else{ |
| | | columnEntity.setParentId(parentId); |
| | | } |
| | | |
| | | columnEntity.setListTemplate(adminAddColumnDto.getListTemplate()); |
| | | columnEntity.setArticleTemplate(adminAddColumnDto.getArticleTemplate()); |
| | | columnEntity.setType(adminAddColumnDto.getType()); |
| | | columnEntity.setTargetType(adminAddColumnDto.getTargetType()); |
| | | columnEntity.setTargetUrl(adminAddColumnDto.getTargetUrl()); |
| | | columnEntity.setIsNav(adminAddColumnDto.getIsNav()); |
| | | this.baseMapper.insert(columnEntity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | adminSeeColumnInfoVo.setParentId(columnEntity.getParentId()); |
| | | adminSeeColumnInfoVo.setOrderNum(columnEntity.getOrderNum()); |
| | | adminSeeColumnInfoVo.setPic(columnEntity.getPic()); |
| | | adminSeeColumnInfoVo.setListTemplate(columnEntity.getListTemplate()); |
| | | adminSeeColumnInfoVo.setArticleTemplate(columnEntity.getArticleTemplate()); |
| | | adminSeeColumnInfoVo.setIsNav(columnEntity.getIsNav()); |
| | | adminSeeColumnInfoVo.setType(columnEntity.getType()); |
| | | adminSeeColumnInfoVo.setTargetType(columnEntity.getTargetType()); |
| | | if (columnEntity.getType() == 2) { |
| | | if (columnEntity.getTargetType() == 1) { |
| | | ArticleEntity articleEntity = articleMapper.selectById(Long.parseLong(columnEntity.getTargetUrl())); |
| | | adminSeeColumnInfoVo.setTargetName(articleEntity.getTitle()); |
| | | } else if (columnEntity.getTargetType() == 2) { |
| | | ColumnEntity column = this.baseMapper.selectById(Long.parseLong(columnEntity.getTargetUrl())); |
| | | adminSeeColumnInfoVo.setTargetName(column.getColumnName()); |
| | | } |
| | | } |
| | | adminSeeColumnInfoVo.setTargetUrl(columnEntity.getTargetUrl()); |
| | | return Result.ok(adminSeeColumnInfoVo); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result updateColumn(AdminUpdateColumnDto adminUpdateColumnDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | Long id = adminUpdateColumnDto.getId(); |
| | | if(ObjectUtil.isEmpty(id)){ |
| | | return Result.fail("栏目不存在"); |
| | |
| | | String columnCode = adminUpdateColumnDto.getColumnCode(); |
| | | QueryWrapper<ColumnEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("column_code",columnCode); |
| | | if(UserEntity.USER_BELONG_TOP != companyId){ |
| | | objectQueryWrapper.eq("company_id",companyId); |
| | | } |
| | | List<ColumnEntity> columnEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(columnEntities) && columnEntities.size() > 1){ |
| | | return Result.fail("栏目编码不能重复"); |
| | |
| | | }else{ |
| | | columnEntity.setParentId(parentId); |
| | | } |
| | | |
| | | columnEntity.setListTemplate(adminUpdateColumnDto.getListTemplate()); |
| | | columnEntity.setArticleTemplate(adminUpdateColumnDto.getArticleTemplate()); |
| | | columnEntity.setType(adminUpdateColumnDto.getType()); |
| | | columnEntity.setTargetType(adminUpdateColumnDto.getTargetType()); |
| | | columnEntity.setTargetUrl(adminUpdateColumnDto.getTargetUrl()); |
| | | columnEntity.setIsNav(adminUpdateColumnDto.getIsNav()); |
| | | this.baseMapper.updateById(columnEntity); |
| | | return Result.ok("更新成功"); |
| | | } |