| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.contants.AppContants; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.configurations.properties.CmsProperties; |
| | | import com.xcong.farmer.cms.conversion.ColumnConversion; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminAddColumnDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminColumnDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; |
| | |
| | | private ArticleMapper articleMapper; |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | @Autowired |
| | | private CmsProperties cmsProperties; |
| | | |
| | | @Override |
| | | public Result getColumnInPage(AdminColumnDto adminColumnDto) { |
| | |
| | | adminSeeColumnInfoVo.setType(columnEntity.getType()); |
| | | adminSeeColumnInfoVo.setTargetType(columnEntity.getTargetType()); |
| | | adminSeeColumnInfoVo.setContentType(columnEntity.getContentType()); |
| | | |
| | | CompanyEntity companyEntity = companyMapper.selectById(LoginUserUtil.getCompanyId()); |
| | | |
| | | if (columnEntity.getType() == 2) { |
| | | if (columnEntity.getTargetType() == 1) { |
| | | ArticleEntity articleEntity = articleMapper.selectById(Long.parseLong(columnEntity.getTargetUrl())); |
| | | adminSeeColumnInfoVo.setTargetName(articleEntity.getTitle()); |
| | | adminSeeColumnInfoVo.setUrl(cmsProperties.getBaseUrl() + columnEntity.getPath() + "/" + columnEntity.getTargetUrl() + ".html"); |
| | | adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + columnEntity.getPath() + "/" + columnEntity.getTargetUrl() + ".html"); |
| | | } else if (columnEntity.getTargetType() == 2) { |
| | | ColumnEntity column = this.baseMapper.selectByCodeAndCompanyId(columnEntity.getTargetUrl(), LoginUserUtil.getCompanyId()); |
| | | adminSeeColumnInfoVo.setTargetName(column.getColumnName()); |
| | | adminSeeColumnInfoVo.setUrl(cmsProperties.getBaseUrl() + column.getPath()); |
| | | adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + column.getPath()); |
| | | } |
| | | } else { |
| | | adminSeeColumnInfoVo.setUrl(cmsProperties.getBaseUrl() + columnEntity.getPath()); |
| | | adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + columnEntity.getPath()); |
| | | } |
| | | 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("栏目不存在"); |
| | | } |
| | | ColumnEntity columnEntity = this.baseMapper.selectById(id); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | ColumnEntity columnEntity = this.baseMapper.selectById(adminUpdateColumnDto.getId()); |
| | | if(ObjectUtil.isEmpty(columnEntity)){ |
| | | return Result.fail("栏目不存在"); |
| | | } |
| | | String columnName = adminUpdateColumnDto.getColumnName(); |
| | | columnEntity.setColumnName(columnName); |
| | | |
| | | 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("栏目编码不能重复"); |
| | | } |
| | | columnEntity.setColumnCode(columnCode); |
| | | String remark = adminUpdateColumnDto.getRemark(); |
| | | columnEntity.setRemark(remark); |
| | | String pic = adminUpdateColumnDto.getPic(); |
| | | columnEntity.setPic(pic); |
| | | Integer orderNum = adminUpdateColumnDto.getOrderNum(); |
| | | if(ObjectUtil.isNotEmpty(orderNum)){ |
| | | columnEntity.setOrderNum(orderNum); |
| | | } |
| | | Long parentId = adminUpdateColumnDto.getParentId(); |
| | | if(ObjectUtil.isEmpty(parentId)){ |
| | | columnEntity.setParentId(ColumnEntity.PARENTID_DEFAULT); |
| | | columnEntity.setPath("/" + columnEntity.getColumnCode()); |
| | | }else{ |
| | | columnEntity.setParentId(parentId); |
| | | ColumnEntity parent = this.baseMapper.selectById(parentId); |
| | | columnEntity.setPath(parent.getPath() + "/" + columnEntity.getColumnCode()); |
| | | ColumnEntity updateEntity = ColumnConversion.INSTANCE.updateDtoToEntity(adminUpdateColumnDto); |
| | | |
| | | if (!columnEntity.getColumnCode().equals(columnCode)) { |
| | | ColumnEntity hasExist = this.baseMapper.selectByCodeAndCompanyId(columnCode, companyId); |
| | | if (ObjectUtil.isNotEmpty(hasExist)) { |
| | | return Result.fail("栏目编码不能重复"); |
| | | } |
| | | } |
| | | |
| | | columnEntity.setListTemplate(adminUpdateColumnDto.getListTemplate()); |
| | | columnEntity.setArticleTemplate(adminUpdateColumnDto.getArticleTemplate()); |
| | | columnEntity.setType(adminUpdateColumnDto.getType()); |
| | | columnEntity.setTargetType(adminUpdateColumnDto.getTargetType()); |
| | | columnEntity.setTargetUrl(adminUpdateColumnDto.getTargetUrl()); |
| | | columnEntity.setIsNav(adminUpdateColumnDto.getIsNav()); |
| | | columnEntity.setContentType(adminUpdateColumnDto.getContentType()); |
| | | this.baseMapper.updateById(columnEntity); |
| | | Long parentId = adminUpdateColumnDto.getParentId(); |
| | | if(ObjectUtil.isEmpty(parentId)){ |
| | | updateEntity.setParentId(ColumnEntity.PARENTID_DEFAULT); |
| | | updateEntity.setPath("/" + updateEntity.getColumnCode()); |
| | | }else{ |
| | | updateEntity.setParentId(parentId); |
| | | ColumnEntity parent = this.baseMapper.selectById(parentId); |
| | | updateEntity.setPath(parent.getPath() + "/" + updateEntity.getColumnCode()); |
| | | } |
| | | |
| | | // 若编码进行了修改且该栏目为父栏目,则需要同步修改子栏目的path。 |
| | | if (!columnEntity.getColumnCode().equals(columnCode)) { |
| | | if ("-1".equals(columnEntity.getBeforeColumnCode())) { |
| | | updateEntity.setBeforeColumnCode(columnEntity.getColumnCode()); |
| | | } |
| | | |
| | | if (updateEntity.getParentId() == 0L) { |
| | | List<ColumnEntity> childColumn = this.baseMapper.selectColumnByParentId(columnEntity.getId(), companyId, 2); |
| | | if (CollUtil.isNotEmpty(childColumn)) { |
| | | for (ColumnEntity child : childColumn) { |
| | | child.setPath(updateEntity.getPath() + "/" + child.getColumnCode()); |
| | | this.baseMapper.updateById(child); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 栏目修改时,需判断父级ID及栏目编码的修改。若栏目父级ID修改了,则需记录原父级ID,在发布时,需连同原父级栏目同时编译 |
| | | if (!columnEntity.getParentId().equals(updateEntity.getParentId()) && columnEntity.getBeforeParentId() == -1) { |
| | | updateEntity.setBeforeParentId(columnEntity.getParentId()); |
| | | } |
| | | |
| | | this.baseMapper.updateById(updateEntity); |
| | | return Result.ok("更新成功"); |
| | | } |
| | | |