liujie
2026-03-12 9c89c3c9333a84c66999b3fbae1ae63c432a600d
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
package com.ruoyi.web.controller.api;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.StoryListQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.ClientDashboardQuery;
import com.ruoyi.system.vo.ClientDashboardVO;
import com.ruoyi.system.vo.ScreenUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
 
/**
 * 数据统计面板 前端控制器
 *
 * @author xiaochen
 * @since 2025-12-23
 */
@RestController
@RequestMapping("/dashboard-statistics")
@Api(tags = "首页")
@RequiredArgsConstructor(onConstructor_ = @Lazy)
public class DashboardStatisticsController {
 
 
    @Autowired
    private TokenService tokenService;
 
    @Autowired
    private ClientService clientService;
 
    @Autowired
    private ClientParamService clientParamService;
 
    @Autowired
    private ProjectService projectService;
 
    @Autowired
    private AccidentBriefService accidentBriefService;
 
    @Autowired
    private AccidentClassificationService accidentClassificationService;
 
 
    @ApiOperation("获取当前登录信息")
    @GetMapping("/getLoginInfo")
    public R<ScreenUserVo> getLoginInfo(Integer type, Integer id) {
        ScreenUserVo screenUserVo = new ScreenUserVo();
        screenUserVo.setType(type);
        if(type!=null && id !=null){
 
            if(type==1){
                Client client = clientService.getById(id);
                if(client==null){
                    return R.fail("委托方不存在");
                }
                ClientParam param = clientParamService.getOne(new LambdaQueryWrapper<ClientParam>().eq(ClientParam::getClientId, client.getId()));
                if(param!=null){
                    screenUserVo.setLogo(param.getLogo());
                    screenUserVo.setName(param.getName());
                    screenUserVo.setPermissionClient(param.getPermissionClient());
                    screenUserVo.setPermissionProject(param.getPermissionProject());
                    screenUserVo.setCommentType(param.getCommentType());
                    screenUserVo.setSafetyId(param.getSafetyId());
                    String name = clientParamService.getTemplateName(param.getSafetyId());
                    screenUserVo.setSafetyName(name);
 
                    screenUserVo.setDeviceTemplateId(param.getDeviceTemplateId());
                    screenUserVo.setDeviceTemplateName(clientParamService.getTemplateName(param.getDeviceTemplateId()));
 
                    screenUserVo.setBigHiddenDanger(param.getBigHiddenDanger());
                    screenUserVo.setGeneralHiddenDanger(param.getGeneralHiddenDanger());
                }
            }else if(type==2){
                Project project = projectService.getById(id);
                if(project==null){
                    return R.fail("项目不存在");
                }
                Client client = clientService.getById(project.getClientId());
                ClientParam param = clientParamService.getOne(new LambdaQueryWrapper<ClientParam>().eq(ClientParam::getClientId, client.getId()));
                if(param!=null){
                    screenUserVo.setCommentType(param.getCommentType());
                    screenUserVo.setSafetyId(param.getSafetyId());
                    String name = clientParamService.getTemplateName(param.getSafetyId());
                    screenUserVo.setSafetyName(name);
                    screenUserVo.setDeviceTemplateId(param.getDeviceTemplateId());
                    String name1 = clientParamService.getTemplateName(param.getDeviceTemplateId());
                    screenUserVo.setDeviceTemplateName(name1);
                    screenUserVo.setBigHiddenDanger(param.getBigHiddenDanger());
                    screenUserVo.setGeneralHiddenDanger(param.getGeneralHiddenDanger());
                }
                screenUserVo.setName(project.getName());
                screenUserVo.setPermissionProject(project.getPermission());
            }
 
        }
        return R.ok(screenUserVo);
 
    }
 
 
 
 
    @ApiOperation(value = "获取故事简讯列表",response = AccidentBrief.class)
    @PostMapping("/getStoryPage")
    public R<Page<AccidentBrief>> getStoryPage(@RequestBody StoryListQuery query) {
        Page<AccidentBrief> page = new Page<>(query.getPageNum(), query.getPageSize());
        List<AccidentClassification> list = accidentClassificationService.list(new LambdaQueryWrapper<AccidentClassification>().eq(AccidentClassification::getDeleted, false));
        LambdaQueryWrapper<AccidentBrief> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AccidentBrief::getState,1);
        wrapper.eq(AccidentBrief::getDeleted,false);
        if(query.getCity()!=null && !query.getCity().isEmpty()){
            wrapper.eq(AccidentBrief::getCity, query.getCity());
        }
        if(query.getProvince()!=null && !query.getProvince().isEmpty()){
            wrapper.eq(AccidentBrief::getProvince, query.getProvince());
        }
        if(query.getArea()!=null && !query.getArea().isEmpty()){
            wrapper.eq(AccidentBrief::getArea, query.getArea());
        }
 
        if(query.getClassifyId()!=null){
            wrapper.eq(AccidentBrief::getClassifyId, query.getClassifyId());
        }
        if(query.getTime()!=null && !query.getTime().isEmpty()){
            String sTime = query.getTime().split(" - ")[0]+" 00:00:00";
            String eTime = query.getTime().split(" - ")[1]+" 23:59:59";
            wrapper.between(AccidentBrief::getTime,sTime,eTime);
        }
        if(query.getContent()!=null && !query.getContent().isEmpty()){
            wrapper.like(AccidentBrief::getContent, query.getContent());
        }
        wrapper.orderByDesc(AccidentBrief::getTime);
        Page<AccidentBrief> accidentBriefPage = accidentBriefService.page(page, wrapper);
        accidentBriefPage.getRecords().forEach(item->{
            item.setClassifyName(list.stream().filter(classify->classify.getId().equals(item.getClassifyId())).findFirst().get().getName());
        });
        return R.ok(accidentBriefPage);
    }
 
 
 
    @ApiOperation(value = "获取故事简讯列表-不分页",response = AccidentBrief.class)
    @PostMapping("/getStoryList")
    public R<List<AccidentBrief>> getStoryList(@RequestBody StoryListQuery query) {
        List<AccidentClassification> list = accidentClassificationService.list(new LambdaQueryWrapper<AccidentClassification>().eq(AccidentClassification::getDeleted, false));
        LambdaQueryWrapper<AccidentBrief> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AccidentBrief::getState,1);
        if(query.getCity()!=null && !query.getCity().isEmpty()){
            wrapper.eq(AccidentBrief::getCity, query.getCity());
        }
        if(query.getClassifyId()!=null){
            wrapper.eq(AccidentBrief::getClassifyId, query.getClassifyId());
        }
        if(query.getTime()!=null && !query.getTime().isEmpty()){
            String sTime = query.getTime().split(" - ")[0]+" 00:00:00";
            String eTime = query.getTime().split(" - ")[1]+" 23:59:59";
            wrapper.between(AccidentBrief::getTime,sTime,eTime);
        }
        if(query.getContent()!=null && !query.getContent().isEmpty()){
            wrapper.like(AccidentBrief::getContent, query.getContent());
        }
        wrapper.orderByDesc(AccidentBrief::getTime);
        List<AccidentBrief> accidentBriefPage = accidentBriefService.list( wrapper);
        accidentBriefPage.forEach(item->{
            item.setClassifyName(list.stream().filter(classify -> classify.getId().equals(item.getClassifyId())).findFirst().orElse(new AccidentClassification()).getName());
        });
        return R.ok(accidentBriefPage);
    }
 
 
    @ApiOperation(value = "获取故事简讯详情",response = AccidentBrief.class)
    @GetMapping("/getStoryDetail/{id}")
    public R<AccidentBrief> getStoryDetail(@PathVariable Integer id) {
        AccidentBrief accidentBrief = accidentBriefService.getById(id);
        return R.ok(accidentBrief);
    }
 
    @ApiOperation(value = "获取故事简讯详情分类",response = AccidentClassification.class)
    @GetMapping("/getStoryClassify")
    public R<List<AccidentClassification>> getStoryClassify() {
        List<AccidentClassification> list = accidentClassificationService.list(new LambdaQueryWrapper<AccidentClassification>().eq(AccidentClassification::getDeleted, false));
        return R.ok(list);
    }
 
    /**
     * 获取委托方大屏首页统计数据
     *
     * @param query 查询参数
     * @return 统计数据
     */
    @PostMapping("/index")
    @ApiOperation(value = "获取委托方大屏首页统计数据",tags = {"委托方端"})
    public R<ClientDashboardVO> index(@RequestBody ClientDashboardQuery query) {
        ClientDashboardVO dashboard = clientService.getClientDashboard(query);
        return R.ok(dashboard);
    }
    
 
 
 
 
 
 
}