Helius
2022-07-11 a508775d5c69e61e605c8f00fc18e70279444869
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/ColumnServiceImpl.java
@@ -6,6 +6,7 @@
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.modules.system.dto.AdminAddColumnDto;
import com.xcong.farmer.cms.modules.system.dto.AdminColumnDto;
@@ -123,7 +124,7 @@
        columnEntity.setIsNav(adminAddColumnDto.getIsNav());
        columnEntity.setContentType(adminAddColumnDto.getContentType());
        this.baseMapper.insert(columnEntity);
        return Result.ok("添加成功");
        return Result.ok("添加成功", columnEntity.getId());
    }
    @Override
@@ -163,14 +164,21 @@
        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(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(companyEntity.getWebAddress() + column.getPath());
            }
        } else {
            adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + 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;
    }
}