sunshine
2024-11-05 0d71954001d47e92683a508f43ea31c3bf822ffb
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
package com.nova.sankuai.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nova.sankuai.domain.dto.MechanismDto;
import com.nova.sankuai.domain.entity.ChannelMechanismConfig;
import com.nova.sankuai.infra.mapper.ChannelMechanismConfigMapper;
import com.nova.sankuai.service.IChannelMechanismConfigService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author weikangdi
 * @create 2022/3/31
 */
@AllArgsConstructor
@Service
public class ChannelMechanismConfigServiceImpl extends ServiceImpl<ChannelMechanismConfigMapper, ChannelMechanismConfig> implements IChannelMechanismConfigService {
 
    private final ChannelMechanismConfigMapper channelMechanismConfigMapper;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateConfig(MechanismDto mechanismDto) {
        channelMechanismConfigMapper.removeByMechanismId(mechanismDto.getId());
        if (mechanismDto.getChannelIds() != null && mechanismDto.getChannelIds().size() > 0) {
            List<Long> channelIds = mechanismDto.getChannelIds().stream().distinct().collect(Collectors.toList());
            channelMechanismConfigMapper.updateConfig(channelIds, mechanismDto.getId());
        }
    }
 
    @Override
    public List<Long> getChannelsByMechanismId(Long mechanismId) {
        List<Long> result = channelMechanismConfigMapper.getChannelsByMechanismId(mechanismId);
        return result;
    }
}