fei.wang
2025-04-18 8c63366bfaa0b5f6e0db00abbabe0e770fc0d8dc
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.hxzkmonitor.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxzkmonitor.mapper.TbCompanyMapper;
import com.hxzkmonitor.mapper.TbUserMapper;
import com.hxzkmonitor.pojo.TbCompany;
import com.hxzkmonitor.pojo.TbGuangbo;
import com.hxzkmonitor.mapper.TbGuangboMapper;
import com.hxzkmonitor.pojo.TbUser;
import com.hxzkmonitor.service.TbGuangboService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangfei
 * @since 2025-04-09
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TbGuangboServiceImpl extends ServiceImpl<TbGuangboMapper, TbGuangbo> implements TbGuangboService {
 
 
    private final TbUserMapper tbUserMapper;
 
    private final TbCompanyMapper tbCompanyMapper;
 
 
    @Override
    public List<TbGuangbo> getallguangbo(String username, String phone) {
        QueryWrapper queryWrapperu = new QueryWrapper<>();
        queryWrapperu.eq("username",username);
        queryWrapperu.eq("adminphone",phone);
        TbUser tbUser=  tbUserMapper.selectOne(queryWrapperu);
        QueryWrapper<TbGuangbo> queryWrapper = new QueryWrapper<>();
        if (!Objects.equals(tbUser.getRole(), "超级管理员")){
            queryWrapper.eq("company",tbUser.getCsname());
        }
        System.out.println(tbUser.getCaname());
        List<TbGuangbo> guangbos = baseMapper.selectList(queryWrapper);
//        queryWrapper.eq("type",1);
//        queryWrapper.orderByDesc("jxtime");
//        queryWrapper.last("LIMIT 20");
        return baseMapper.selectList(queryWrapper);
 
    }
 
 
 
    @Override
    public IPage<TbGuangbo> searchGuangbo(Page page, String keyword) {
        QueryWrapper<TbGuangbo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tagid", keyword);
        queryWrapper.orderByDesc("addtime");
        IPage<TbGuangbo> ip = baseMapper.selectPage(page, queryWrapper);
        return ip;
    }
 
    @Override
    public Integer delGuangbo(Integer id) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        return baseMapper.delete(queryWrapper);
    }
 
    @Override
    public Integer addorupGuangbo(TbGuangbo tbGuangbo) {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        tbGuangbo.setAddtime(formatter.format(date));
        if (tbGuangbo.getId() != null) {
            return baseMapper.updateById(tbGuangbo);
        } else {
            return baseMapper.insert(tbGuangbo);
        }
    }
 
    @Override
    public IPage<TbGuangbo> getGuangboPage(Page page) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("addtime");
        IPage<TbGuangbo> GuangboPage = baseMapper.selectPage(page, queryWrapper);
 
        for (int i = 0; i < GuangboPage.getRecords().size(); i++) {
            QueryWrapper queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("id", GuangboPage.getRecords().get(i).getCompany());
            TbCompany tbCompany = tbCompanyMapper.selectOne(queryWrapper1);
            if (tbCompany != null) {
                GuangboPage.getRecords().get(i).setCompanyname(tbCompany.getCompanyname());
            }
            }
        return GuangboPage;
    }
 
    @Override
    public List<String> getGuangbo(String query) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.like("tagid", query);
        List<TbGuangbo> voicetips = baseMapper.selectList(queryWrapper);
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < voicetips.size(); i++) {
            strings.add(voicetips.get(i).getTagid());
        }
 
        return strings;
    }
 
 
    @Override
    public List<String> getGuangbofive() {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("addtime");
        queryWrapper.last("LIMIT 5");
        List<TbGuangbo> voicetips = baseMapper.selectList(queryWrapper);
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < voicetips.size(); i++) {
            strings.add(voicetips.get(i).getTagid());
        }
 
        return strings;
    }
}