xiaoyong931011
2022-06-15 6c82b0f944a0d3547659db5ec1f640a9ec7d3fd3
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<WebSetMapper, WebSetEntity> 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<WebSetEntity> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("company_id",companyId);
        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) {
        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<WebSetEntity> 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();
        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("保存成功");
    }
}