package com.xcong.farmer.cms.modules.system.service.Impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.farmer.cms.common.response.Result; import com.xcong.farmer.cms.modules.system.dto.AdminUpdateWebSetDto; import com.xcong.farmer.cms.modules.system.entity.UserEntity; import com.xcong.farmer.cms.modules.system.entity.WebSetEntity; import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper; import com.xcong.farmer.cms.modules.system.service.IWebSetService; import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; import com.xcong.farmer.cms.modules.system.vo.AdminSeeWebSetInfoVo; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.collection.CollUtil; @Service @Slf4j public class WebSetServiceImpl extends ServiceImpl implements IWebSetService { @Override public Result seeWebSetInfo() { UserEntity userlogin = LoginUserUtil.getLoginUser(); long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); AdminSeeWebSetInfoVo adminSeeWebSetInfoVo = new AdminSeeWebSetInfoVo(); QueryWrapper objectQueryWrapper = new QueryWrapper<>(); objectQueryWrapper.eq("company_id",companyId); List webSetEntities = this.baseMapper.selectList(objectQueryWrapper); if(CollUtil.isNotEmpty(webSetEntities)){ WebSetEntity webSetEntity = webSetEntities.get(0); adminSeeWebSetInfoVo.setId(webSetEntity.getId()); adminSeeWebSetInfoVo.setWebTitle(webSetEntity.getWebTitle()); adminSeeWebSetInfoVo.setWebKeyword(webSetEntity.getWebKeyword()); adminSeeWebSetInfoVo.setWebRemark(webSetEntity.getWebRemark()); adminSeeWebSetInfoVo.setWebPic(webSetEntity.getWebPic()); } return Result.ok(adminSeeWebSetInfoVo); } @Override public Result updateWebSet(AdminUpdateWebSetDto adminUpdateWebSetDto) { UserEntity userlogin = LoginUserUtil.getLoginUser(); long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); String webTitle = adminUpdateWebSetDto.getWebTitle(); String webKeyword = adminUpdateWebSetDto.getWebKeyword(); Long id = adminUpdateWebSetDto.getId() == null ? 0L : adminUpdateWebSetDto.getId(); QueryWrapper objectQueryWrapper = new QueryWrapper<>(); objectQueryWrapper.eq("company_id",companyId); WebSetEntity webSetEntity = this.baseMapper.selectOne(objectQueryWrapper); if(ObjectUtil.isEmpty(webSetEntity)){ WebSetEntity webSetEntityAdd = new WebSetEntity(); webSetEntityAdd.setWebTitle(webTitle); webSetEntityAdd.setWebKeyword(webKeyword); String webRemark = adminUpdateWebSetDto.getWebRemark(); if(StrUtil.isNotEmpty(webRemark)){ webSetEntityAdd.setWebRemark(webRemark); } String webPic = adminUpdateWebSetDto.getWebPic(); if(StrUtil.isNotEmpty(webPic)){ webSetEntityAdd.setWebPic(webPic); } webSetEntityAdd.setCompanyId(companyId); this.baseMapper.insert(webSetEntityAdd); return Result.ok("保存成功"); } webSetEntity.setWebTitle(webTitle); webSetEntity.setWebKeyword(webKeyword); String webRemark = adminUpdateWebSetDto.getWebRemark(); webSetEntity.setWebRemark(webRemark); String webPic = adminUpdateWebSetDto.getWebPic(); webSetEntity.setWebPic(webPic); this.baseMapper.updateById(webSetEntity); return Result.ok("保存成功"); } }