xiaoyong931011
2022-06-02 d04c117fdebce55aaa97bc0c44181948d1e2150c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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.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.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<WebSetMapper, WebSetEntity> implements IWebSetService {
    @Override
    public Result seeWebSetInfo() {
        AdminSeeWebSetInfoVo adminSeeWebSetInfoVo = new AdminSeeWebSetInfoVo();
        List<WebSetEntity> webSetEntities = this.baseMapper.selectList(new QueryWrapper<>());
        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) {
        Long id = adminUpdateWebSetDto.getId() == null ? 0L : adminUpdateWebSetDto.getId();
        WebSetEntity webSetEntity = this.baseMapper.selectById(id);
        if(ObjectUtil.isEmpty(webSetEntity)){
            return Result.fail("网页设置不存在");
        }
        String webTitle = adminUpdateWebSetDto.getWebTitle();
        if(StrUtil.isEmpty(webTitle)){
            return Result.fail("请输入网页标题");
        }
        webSetEntity.setWebTitle(webTitle);
        String webKeyword = adminUpdateWebSetDto.getWebKeyword();
        if(StrUtil.isEmpty(webKeyword)){
            return Result.fail("请输入网页关键字");
        }
        webSetEntity.setWebKeyword(webKeyword);
        String webRemark = adminUpdateWebSetDto.getWebRemark();
        if(StrUtil.isNotEmpty(webRemark)){
            webSetEntity.setWebRemark(webRemark);
        }
        String webPic = adminUpdateWebSetDto.getWebPic();
        if(StrUtil.isNotEmpty(webPic)){
            webSetEntity.setWebPic(webPic);
        }
        this.baseMapper.updateById(webSetEntity);
        return Result.ok("保存成功");
    }
}