xiaoyong931011
2022-07-08 bd4ab82f2e0c485f36a254e3cbf72f21dabfd628
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/MessageBoardServiceImpl.java
@@ -5,6 +5,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.AdminAddMessageDto;
import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto;
@@ -70,16 +71,13 @@
    @Override
    public Result addMessage(HttpServletRequest request, AdminAddMessageDto adminAddMessageDto) {
        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);
        String title = adminAddMessageDto.getTitle();
        String remark = adminAddMessageDto.getRemark();
        if(StrUtil.isEmpty(title) && StrUtil.isEmpty(remark)){
            return Result.fail("请输入留言");
        }
        MessageBoardEntity messageBoardEntity = new MessageBoardEntity();
        messageBoardEntity.setName(adminAddMessageDto.getName());
@@ -95,4 +93,18 @@
        this.baseMapper.insert(messageBoardEntity);
        return Result.ok("留言成功");
    }
    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;
    }
}