fix
Helius
2022-08-19 fce8e677dd4f4b7b34c01f481c17d19fcf4465cb
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
package com.xcong.farmer.cms.modules.system.service.Impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.farmer.cms.common.exception.GlobalException;
import com.xcong.farmer.cms.modules.system.conversion.CmsGroupInfoConversion;
import com.xcong.farmer.cms.modules.system.dto.AddGroupInfoDto;
import com.xcong.farmer.cms.modules.system.dto.ModifyGroupInfoDto;
import com.xcong.farmer.cms.modules.system.entity.CmsGroupInfoEntity;
import com.xcong.farmer.cms.modules.system.entity.UserEntity;
import com.xcong.farmer.cms.modules.system.mapper.CmsGroupInfoMapper;
import com.xcong.farmer.cms.modules.system.service.ICmsGroupInfoService;
import com.xcong.farmer.cms.modules.system.util.LoginUserUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.Objects;
 
/**
 * @author wzy
 * @date 2022-08-19
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class CmsGroupInfoServiceImpl  extends ServiceImpl<CmsGroupInfoMapper, CmsGroupInfoEntity> implements ICmsGroupInfoService {
 
 
    @Override
    public void add(AddGroupInfoDto addGroupInfoDto) {
        UserEntity user = LoginUserUtil.getLoginUser();
 
        CmsGroupInfoEntity hasExist = this.baseMapper.selectByCode(addGroupInfoDto.getCode(), user.getCompanyId());
        if (hasExist != null) {
            throw new GlobalException("分组编码已存在");
        }
 
        CmsGroupInfoEntity groupInfo = CmsGroupInfoConversion.INSTANCE.addDtoToEntity(addGroupInfoDto);
        groupInfo.setCreateBy(user.getNickname());
        groupInfo.setUpdateBy(user.getNickname());
        groupInfo.setCompanyId(user.getCompanyId());
        this.baseMapper.insert(groupInfo);
    }
 
    @Override
    public void modify(ModifyGroupInfoDto modifyGroupInfoDto) {
        UserEntity user = LoginUserUtil.getLoginUser();
 
        CmsGroupInfoEntity hasExist = this.baseMapper.selectByCode(modifyGroupInfoDto.getCode(), user.getCompanyId());
        if (hasExist != null && !Objects.equals(hasExist.getId(), modifyGroupInfoDto.getId())) {
            throw new GlobalException("分组编码已存在");
        }
 
        CmsGroupInfoEntity groupInfo = CmsGroupInfoConversion.INSTANCE.modifyDtoToEntity(modifyGroupInfoDto);
        groupInfo.setUpdateBy(user.getNickname());
        this.baseMapper.updateById(groupInfo);
    }
}