fix
Helius
2022-07-11 02b6979e6e7680c85ed0911109d182c9a235162f
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java
@@ -6,7 +6,9 @@
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;
@@ -40,6 +42,8 @@
    private ArticleMapper articleMapper;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private CmsProperties cmsProperties;
    @Override
    public Result getColumnInPage(AdminColumnDto adminColumnDto) {
@@ -167,10 +171,14 @@
            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);
@@ -201,7 +209,13 @@
        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();
@@ -211,6 +225,11 @@
            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());
@@ -227,6 +246,7 @@
        columnEntity.setTargetUrl(adminUpdateColumnDto.getTargetUrl());
        columnEntity.setIsNav(adminUpdateColumnDto.getIsNav());
        columnEntity.setContentType(adminUpdateColumnDto.getContentType());
        columnEntity.setReleaseState(2);
        this.baseMapper.updateById(columnEntity);
        return Result.ok("更新成功");
    }
@@ -282,17 +302,8 @@
    @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){
@@ -316,4 +327,18 @@
        }
        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;
    }
}