Helius
2022-07-11 a508775d5c69e61e605c8f00fc18e70279444869
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
package com.xcong.farmer.cms.modules.system.service.Impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.farmer.cms.common.response.Result;
import com.xcong.farmer.cms.conversion.WebSettingConversion;
import com.xcong.farmer.cms.modules.system.dto.SetWebSettingDto;
import com.xcong.farmer.cms.modules.system.entity.UserEntity;
import com.xcong.farmer.cms.modules.system.entity.WebSettingEntity;
import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper;
import com.xcong.farmer.cms.modules.system.service.IWebSettingService;
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;
 
@Service
@Slf4j
public class WebSettingServiceImpl extends ServiceImpl<WebSetMapper, WebSettingEntity> implements IWebSettingService {
    @Override
    public Result getWebSetting() {
        Long companyId = LoginUserUtil.getCompanyId();
        WebSettingEntity webSetting = this.baseMapper.selectByCompanyId(companyId);
        if (webSetting == null) {
            webSetting = new WebSettingEntity();
        }
 
        AdminSeeWebSetInfoVo adminSeeWebSetInfoVo = WebSettingConversion.INSTANCE.entityToVo(webSetting);
        return Result.ok(adminSeeWebSetInfoVo);
    }
 
    @Override
    public Result setWebSetting(SetWebSettingDto setWebSettingDto) {
        Long companyId = LoginUserUtil.getCompanyId();
 
        WebSettingEntity webSetting = WebSettingConversion.INSTANCE.dtoToEntity(setWebSettingDto);
        webSetting.setCompanyId(companyId);
        if (setWebSettingDto.getId() == null) {
            WebSettingEntity hasExist = this.baseMapper.selectByCompanyId(companyId);
            if (hasExist != null) {
                webSetting.setId(hasExist.getId());
                this.baseMapper.updateById(webSetting);
            } else {
                this.baseMapper.insert(webSetting);
            }
        } else {
            this.baseMapper.updateById(webSetting);
        }
        return Result.ok("保存成功");
    }
}