puzhibing
2023-05-30 6d05cda0141cbd42a9b8810e539f5dcd8df506f0
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.dao.TBroadcastMapper;
import com.stylefeng.guns.modular.system.enums.StatusEnum;
import com.stylefeng.guns.modular.system.model.TBroadcast;
import com.stylefeng.guns.modular.system.model.TCommercial;
import com.stylefeng.guns.modular.system.dao.TCommercialMapper;
import com.stylefeng.guns.modular.system.service.ITCommercialService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 广告 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2023-03-16
 */
@Service
public class TCommercialServiceImpl extends ServiceImpl<TCommercialMapper, TCommercial> implements ITCommercialService {
 
    @Autowired
    private TCommercialMapper tCommercialMapper;
 
    @Override
    public Boolean isExit(Integer id,Integer onOffLine) {
        List<TCommercial> list = tCommercialMapper.selectList(new EntityWrapper<TCommercial>()
                .eq("type", 1)
                .eq("onOffLine", onOffLine)
                .ne("status", StatusEnum.DELETE.getCode()));
        if (Objects.nonNull(id)) {
            if(!CollectionUtils.isEmpty(list)){
                List<Integer> ids = list.stream().map(TCommercial::getId).collect(Collectors.toList());
                // 修改
                TCommercial tCommercial = tCommercialMapper.selectById(id);
                return Objects.nonNull(tCommercial) && !ids.contains(id) && list.size() > 3;
            }else {
                return false;
            }
        } else {
            // 新增
            return list.size() > 3;
        }
    }
}