xuhy
2024-12-11 5be07b1a021f596b003eac001f4cb77416ae6c7b
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package com.ruoyi.web.controller.api;
import java.time.LocalDate;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.BasePage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.query.AppUserQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.query.ConsultationQuery;
import com.ruoyi.web.controller.query.InformationQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
 
/**
 * <p>
 * 咨询列表 前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/t-consultation")
public class TConsultationController {
 
    @Resource
    private TConsultationService informationService;
    @Resource
    private TRegionService regionService;
    @Resource
    private TTechnicalTitleService tTechnicalTitleService;
    @Resource
    private TTitleMajorService majorService;
    @Resource
    private RedisCache redisCache;
    @Resource
    private TokenService tokenService;
    @Resource
    private TConsultationClassificationService consultationClassificationService;
 
    @ApiOperation(value = "通过省名查询下级城市",tags = {"后台-咨询管理-咨询列表","web-咨询查询"})
    @PostMapping(value = "/getcity")
    public R<List<TRegion>> getcity(@RequestParam String provinceName) {
        List<TRegion> list = regionService.lambdaQuery().eq(TRegion::getProvinceName, provinceName).eq(TRegion::getIsOpen, 1).list();
        return R.ok(list);
 
    }
    @Resource
    private TAppUserService appUserService;
 
 
    //新增咨询
    @ApiOperation(value = "添加",tags = "后台-咨询管理-咨询列表")
    @PostMapping(value = "/add")
    public R add(@Validated @RequestBody TConsultation information) {
        informationService.save(information);
        AppUserQuery appUserQuery = new AppUserQuery();
 
        appUserQuery.setMajorId1(information.getMajorId());
        appUserQuery.setTitleId1(information.getTitleId());
        appUserQuery.setRegionId1(Long.valueOf(information.getRegionId()));
        appUserQuery.setLevelId1(information.getLevel());
 
 
        List<Long> newIds = appUserService.getNewIds(appUserQuery);
        for (Long newId : newIds) {
            redisCache.setCacheObject("ALLERT:"+newId,information.getClassificationId());
        }
        return R.ok();
    }
    //修改咨询
    @ApiOperation(value = "修改",tags = "后台-咨询管理-咨询列表")
    @PostMapping(value = "/edit")
    public R edit(@RequestBody TConsultation information) {
        informationService.updateById(information);
        AppUserQuery appUserQuery = new AppUserQuery();
 
        appUserQuery.setMajorId1(information.getMajorId());
        appUserQuery.setTitleId1(information.getTitleId());
        appUserQuery.setRegionId1(Long.valueOf(information.getRegionId()));
        appUserQuery.setLevelId1(information.getLevel());
 
 
        List<Long> newIds = appUserService.getNewIds(appUserQuery);
        for (Long newId : newIds) {
            redisCache.setCacheObject("ALLERT:"+newId,information.getClassificationId());
        }
        return R.ok();
    }
 
    @Resource
    private TConsultationMessageService messageService;
    //删除咨询
    @ApiOperation(value = "删除",tags = "后台-咨询管理-咨询列表")
    @PostMapping(value = "/deleteByIds")
    public R deleteByIds(String ids) {
        informationService.removeByIds(Arrays.asList(ids.split(",")));
        messageService.remove(Wrappers.lambdaQuery(TConsultationMessage.class).in(TConsultationMessage::getConsultationId,Arrays.asList(ids.split(","))));
        return R.ok();
    }
    //查询咨询
    @ApiOperation(value = "查询",tags = {"后台-咨询管理-咨询列表","web-咨询查询"})
    @PostMapping(value = "/list")
    public R<Page<TConsultation>> list(@RequestBody ConsultationQuery informationQuery) {
        Long userId = tokenService.getLoginUser().getUserId();
 
        Page<TConsultation> page = informationService.lambdaQuery()
                .like(!StringUtils.isEmpty(informationQuery.getClassificationName()), TConsultation::getClassificationName, informationQuery.getClassificationName())
                .eq(informationQuery.getRegionId() != null, TConsultation::getRegionId, informationQuery.getRegionId())
                .eq(informationQuery.getTechnicalId() != null, TConsultation::getTitleId, informationQuery.getTechnicalId())
                .eq(informationQuery.getClassificationId() != null, TConsultation::getClassificationId, informationQuery.getClassificationId())
                .eq(informationQuery.getMajorId() != null, TConsultation::getMajorId, informationQuery.getMajorId())
                .eq(informationQuery.getLevel() != null, TConsultation::getLevel, informationQuery.getLevel())
                .orderByDesc(TConsultation::getClassificationSort)
                .orderByDesc(TConsultation::getPubTime)
                .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize()));
 
        Set<Long> cacheSet = redisCache.getCacheSet("Consultation:" + userId);
 
        for (TConsultation record : page.getRecords()) {
            TRegion byId = regionService.getById(record.getRegionId());
            record.setRegionName(byId.getProvinceName()+"-"+byId.getName());
            TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTitleId());
            TTitleMajor byId2 = majorService.getById(record.getMajorId());
            record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName());
            TConsultationClassification byId3 = consultationClassificationService.getById(record.getClassificationId());
            record.setTConsultationClassificationName(byId3.getConsultationName());
            if (cacheSet!=null){
                if (cacheSet.contains(record.getId())){
                    record.setIsCollect(1);
                }else {
                    record.setIsCollect(0);
                }
            }else {
                record.setIsCollect(0);
            }
        }
        return R.ok(page);
    }
    @Resource
    private TLevelService levelService;
 
    @ApiOperation(value = "详情",tags = {"后台-咨询管理-咨询列表","web-咨询查询"})
    @PostMapping(value = "/detail")
    public R<TConsultation> detail(@RequestParam Long id ) {
        TConsultation byId = informationService.getById(id);
        byId.setWatchNum(byId.getWatchNum()+1);
        informationService.updateById(byId);
        TTechnicalTitle byId1 = tTechnicalTitleService.getById(byId.getTitleId());
        byId.setTechnicalName(byId1.getTitileName());
        TTitleMajor byId2 = majorService.getById(byId.getMajorId());
        byId.setMajorName(byId2.getMajorName());
        TLevel byId3 = levelService.getById(byId.getLevel());
        byId.setLevelName(byId3.getName());
        TRegion byId4 = regionService.getById(byId.getRegionId());
        byId.setTRegion(byId4);
        return R.ok(byId);
    }
 
 
    @ApiOperation(value = "观看",tags = {"web-咨询查询"})
    @PostMapping(value = "/watch")
    public R watch(@RequestParam Long id ) {
        TConsultation byId = informationService.getById(id);
        byId.setWatchNum(byId.getWatchNum()+1);
        informationService.updateById(byId);
        return R.ok();
 
    }
 
 
    @ApiOperation(value = "留言",tags = {"web-咨询查询"})
    @PostMapping(value = "/message")
    public R message(@RequestBody TConsultationMessage message) {
        Long userId = tokenService.getLoginUser().getUserId();
 
 
        message.setUserId(userId);
        messageService.save(message);
        return R.ok();
 
    }
 
 
    @ApiOperation(value = "收藏咨询",tags = {"web-个人中心"})
    @PostMapping(value = "/info/list")
    public R<Page<TConsultation>> infolist(@RequestBody BasePage basePage) {
 
        Long userId = tokenService.getLoginUser().getUserId();
        Set<Long> cacheSet = redisCache.getCacheSet("Consultation:" + userId);
        if (!cacheSet.isEmpty()) {
 
            Page<TConsultation> page = informationService.lambdaQuery().in(TConsultation::getId, cacheSet).page(Page.of(basePage.getPageNum(), basePage.getPageSize()));
            return R.ok(page);
        }else {
            return R.ok(new Page<>());
        }
    }
 
 
    @ApiOperation(value = "咨询",tags = {"web-个人中心"})
    @PostMapping(value = "/collect/is")
    public R collectis(@RequestParam Long consultationId) {
 
        Long userId = tokenService.getLoginUser().getUserId();
        Set<Long> cacheSet = redisCache.getCacheSet("Consultation:" + userId);
        if (cacheSet.contains(consultationId)){
            return R.ok(true);
        }else {
            return R.ok(false);
        }
    }
 
 
}