|  |  | 
 |  |  | 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.contants.AppContants; | 
 |  |  | import com.xcong.farmer.cms.common.response.Result; | 
 |  |  | import com.xcong.farmer.cms.configurations.properties.CmsProperties; | 
 |  |  | 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) { | 
 |  |  | 
 |  |  |             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"); | 
 |  |  |             } else if (columnEntity.getTargetType() == 2) { | 
 |  |  |                 ColumnEntity column = this.baseMapper.selectByCodeAndCompanyId(columnEntity.getTargetUrl(), LoginUserUtil.getCompanyId()); | 
 |  |  |                 adminSeeColumnInfoVo.setTargetName(column.getColumnName()); | 
 |  |  |                 adminSeeColumnInfoVo.setUrl(cmsProperties.getBaseUrl() + column.getPath()); | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             adminSeeColumnInfoVo.setUrl(cmsProperties.getBaseUrl() + columnEntity.getPath()); | 
 |  |  |         } | 
 |  |  |         adminSeeColumnInfoVo.setTargetUrl(columnEntity.getTargetUrl()); | 
 |  |  |         return Result.ok(adminSeeColumnInfoVo); | 
 |  |  | 
 |  |  |         if(CollUtil.isNotEmpty(columnEntities) && columnEntities.size() > 1){ | 
 |  |  |             return Result.fail("栏目编码不能重复"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 判断是否编辑了栏目编码且此时栏目处于已发布的状态,然后保存之前的编码。因为如果是未发布状态,多次保存的话,容易覆盖真正的最开始的栏目编码 | 
 |  |  |         if (!columnEntity.getColumnCode().equals(columnCode) && columnEntity.getReleaseState() == 1) { | 
 |  |  |             columnEntity.setBeforeColumnCode(columnCode); | 
 |  |  |         } | 
 |  |  |         columnEntity.setColumnCode(columnCode); | 
 |  |  |  | 
 |  |  |         String remark = adminUpdateColumnDto.getRemark(); | 
 |  |  |             columnEntity.setRemark(remark); | 
 |  |  |         String pic = adminUpdateColumnDto.getPic(); | 
 |  |  | 
 |  |  |             columnEntity.setOrderNum(orderNum); | 
 |  |  |         } | 
 |  |  |         Long parentId = adminUpdateColumnDto.getParentId(); | 
 |  |  |         // 同栏目编码 | 
 |  |  |         if (!columnEntity.getParentId().equals(parentId) && columnEntity.getReleaseState() == 1) { | 
 |  |  |             columnEntity.setBeforeParentId(columnEntity.getParentId()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if(ObjectUtil.isEmpty(parentId)){ | 
 |  |  |             columnEntity.setParentId(ColumnEntity.PARENTID_DEFAULT); | 
 |  |  |             columnEntity.setPath("/" + columnEntity.getColumnCode()); | 
 |  |  | 
 |  |  |         columnEntity.setTargetUrl(adminUpdateColumnDto.getTargetUrl()); | 
 |  |  |         columnEntity.setIsNav(adminUpdateColumnDto.getIsNav()); | 
 |  |  |         columnEntity.setContentType(adminUpdateColumnDto.getContentType()); | 
 |  |  |         columnEntity.setReleaseState(2); | 
 |  |  |         this.baseMapper.updateById(columnEntity); | 
 |  |  |         return Result.ok("更新成功"); | 
 |  |  |     } | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Result getWebColumnInList(HttpServletRequest request) { | 
 |  |  |         StringBuffer requestURL = request.getRequestURL(); | 
 |  |  |         List<CompanyEntity> companyEntities = companyMapper.selectList(new QueryWrapper<>()); | 
 |  |  |         Long companyId = 0L; | 
 |  |  |         if(CollUtil.isNotEmpty(companyEntities)){ | 
 |  |  |             for(CompanyEntity companyEntity : companyEntities){ | 
 |  |  |                 boolean contains = StrUtil.contains(requestURL, companyEntity.getWebAddress()); | 
 |  |  |                 if(contains){ | 
 |  |  |                     companyId = companyEntity.getId(); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         String website = request.getHeader(AppContants.WEBSITE_HEADER); | 
 |  |  |         Long companyId = getCompanyIdFromWebsite(website); | 
 |  |  |         List<WebColumnVo> records = this.baseMapper.selectWebColumnInListByParentId(ColumnEntity.PARENTID_DEFAULT,companyId); | 
 |  |  |         if(CollUtil.isNotEmpty(records)){ | 
 |  |  |             for(WebColumnVo webColumnVo : records){ | 
 |  |  | 
 |  |  |         } | 
 |  |  |         return Result.ok(records); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private Long getCompanyIdFromWebsite(String website){ | 
 |  |  |         List<CompanyEntity> companyEntities = companyMapper.selectList(new QueryWrapper<>()); | 
 |  |  |         Long companyId = 0L; | 
 |  |  |         if(CollUtil.isNotEmpty(companyEntities)){ | 
 |  |  |             for(CompanyEntity companyEntity : companyEntities){ | 
 |  |  |                 boolean contains = StrUtil.contains(companyEntity.getWebAddress(), website); | 
 |  |  |                 if(contains){ | 
 |  |  |                     companyId = companyEntity.getId(); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return companyId; | 
 |  |  |     } | 
 |  |  | } |