无关风月
14 小时以前 25b19e60e004290531f61fdf608d1adb5e531903
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.ruoyi.web.controller.api;
 
 
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TAppealAuditDTO;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.InsepectorListQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.system.AppealDetailVO;
import com.ruoyi.system.vo.system.AppealListVO;
import com.ruoyi.web.controller.tool.EmailUtils;
import com.ruoyi.web.controller.tool.MsgUtils;
import com.tencentcloudapi.es.v20180416.models.TaskDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 任务申诉 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-05-28
 */
@Api(tags = "任务申诉")
@RestController
@RequestMapping("/t-appeal")
public class TAppealController {
    @Resource
    private TTaskCleanService taskCleanService;
 
 
 
 
    @Resource
    private TLocationTypeService locationTypeService;
    @Resource
    private TLocationService locationService;
 
    @Resource
    private TTaskDetailService tTaskDetailService;
    @Resource
    private TProjectDeptService projectDeptService;
    @Resource
    private TDeptService deptService;
    @Resource
    private ISysUserService sysUserService;
 
    @Resource
    private TokenService tokenService;
 
    @Resource
    private TAppealService appealService;
    @ApiOperation(value = "申诉记录分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<AppealListVO>> pageList(@RequestBody InsepectorListQuery query) {
        List<SysUser> sysUsers = sysUserService.selectAllList();
        List<TLocation> locationList = locationService.list();
        if (StringUtils.hasLength(query.getDeptName())){
            List<TProjectDept> list = projectDeptService.lambdaQuery().like(TProjectDept::getProjectName, query.getDeptName()).list();
            List<String> listIds = projectDeptService.lambdaQuery().like(TProjectDept::getProjectName, query.getDeptName()).list()
                    .stream().map(TProjectDept::getId).collect(Collectors.toList());
            for (TProjectDept tProjectDept : list) {
                if (tProjectDept.getParentId().equals("0")){
                    List<String> collect = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, tProjectDept.getId()).list()
                            .stream().map(TProjectDept::getId).collect(Collectors.toList());
                    listIds.addAll(collect);
                }
            }
            List<String> deptIds = deptService.lambdaQuery().like(TDept::getDeptName, query.getDeptName()).list()
                    .stream().map(TDept::getId).collect(Collectors.toList());
            listIds.addAll(deptIds);
            if (listIds.isEmpty()){
                listIds.add("0");
            }
            query.setPatrolInspectorIds(sysUsers.stream().filter(e->listIds.contains(e.getDeptId())).map(SysUser::getUserId)
                    .collect(Collectors.toList()));
            if (StringUtils.hasLength(query.getPhonenumber())){
                List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser ->
                        sysUser.getPhonenumber().equals(query.getPhonenumber())
                                && listIds.contains(sysUser.getDeptId())
                ).map(SysUser::getUserId).collect(Collectors.toList());
                if (patrolInspectorIds.isEmpty()){
                    return R.ok(new PageInfo<>());
                }
                query.setPatrolInspectorIds(patrolInspectorIds);
            }
        }
        if (StringUtils.hasLength(query.getPhonenumber())){
            List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser ->
                    sysUser.getPhonenumber().equals(query.getPhonenumber())
            ).map(SysUser::getUserId).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(query.getPatrolInspectorIds())){
                // 取交集
                patrolInspectorIds = patrolInspectorIds.stream().filter(query.getPatrolInspectorIds()::contains).collect(Collectors.toList());
            }
            query.setPatrolInspectorIds(patrolInspectorIds);
            if (patrolInspectorIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }
        }
        if (query.getClearStatus()!=null){
            List<String> collect = tTaskDetailService.lambdaQuery().eq(TTaskDetail::getClearStatus, query.getClearStatus())
                    .eq(TTaskDetail::getHandleType,1)
                    .groupBy(TTaskDetail::getTaskId)
                    .orderByDesc(BaseModel::getCreateTime)
                    .list().stream().map(TTaskDetail::getTaskId).collect(Collectors.toList());
 
            query.setTaskIds(collect);
            if (collect.isEmpty()){
                return R.ok(new PageInfo<>());
            }
        }
        if (query.getLocationType()!=null){
            List<String> collect = locationList.stream().filter(e -> e.getLocationType().equals(query.getLocationType())).map(TLocation::getId)
                    .collect(Collectors.toList());
            if (collect.isEmpty()){
                return R.ok(new PageInfo<>());
            }
            query.setLocationIds(collect);
        }
        if (StringUtils.hasLength(query.getLocationName())){
            List<String> collect = locationList.stream().filter(e -> e.getLocationName().contains(query.getLocationName())).map(TLocation::getId)
                    .collect(Collectors.toList());
            if (collect.isEmpty()){
                query.setLocationIds(collect);
                return R.ok(new PageInfo<>());
            }else{
                if (query.getLocationIds()!=null){
                    collect = collect.stream().filter(query.getLocationIds()::contains).collect(Collectors.toList());
                    if (collect.isEmpty()){
                        return R.ok(new PageInfo<>());
                    }
                }
                query.setLocationIds(collect);
            }
        }
        return R.ok(appealService.pageList(query));
    }
    @Log(title = "批量删除申诉记录", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除申诉记录")
    @DeleteMapping(value = "/deleteByIds")
    public R<Boolean> deleteByIds(@RequestParam String ids) {
        String[] split = ids.split(",");
        appealService.removeBatchByIds(Arrays.asList(split));
        return R.ok();
    }
    @Log(title = "删除申诉记录", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除申诉记录")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        appealService.removeById(id);
        return R.ok();
    }
    @ApiOperation(value = "详情申诉记录")
    @GetMapping(value = "/detail")
    public R<AppealDetailVO> detail(@RequestParam String id) {
        AppealDetailVO appealDetailVO = new AppealDetailVO();
        TAppeal appeal = appealService.getById(id);
        BeanUtils.copyProperties(appeal,appealDetailVO);
        TTask byId = taskCleanService.getById(appeal.getTaskId());
        TLocation byId1 = locationService.getById(byId.getLocationId());
        TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
        appealDetailVO.setLocationAddress(byId1.getLocationAddress());
        appealDetailVO.setLocationIcon(byId2.getLocationIcon());
        appealDetailVO.setLocationName(byId2.getLocationName());
        appealDetailVO.setTaskId(byId.getId());
        if (appeal.getAuditPerson()!=null){
            SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appeal.getAuditPerson()));
            if (sysUser!=null){
                appealDetailVO.setAuditPersonName(sysUser.getUserName());
            }
        }
        appealDetailVO.setTaskName(byId.getTaskName());
        appealDetailVO.setTaskCode(byId.getTaskCode());
        return R.ok(appealDetailVO);
    }
    @Resource
    private TNoticeService noticeService;
    @Resource
    private MsgUtils msgUtils;
    @Resource
    private TNoticeSetService noticeSetService;
    @Resource
    private TDictDataService dictDataService;
    @Log(title = "审核申诉记录", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "审核申诉记录")
    @PostMapping(value = "/audit")
    public R<Boolean> audit(@RequestBody @Valid TAppealAuditDTO dto) throws Exception {
        List<SysUser> sysUsers = sysUserService.selectAllList();
        TAppeal appeal = appealService.getById(dto.getId());
        SysUser sysUser = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(dto.getAppealPerson())))
                .findFirst().orElse(null);
        dto.setStatus(dto.getStatus());
        dto.setAuditPerson(tokenService.getLoginUser().getUserId()+"");
        dto.setAuditTime(LocalDateTime.now());
        TTask task = taskCleanService.getById(appeal.getTaskId());
        TLocation location = locationService.getById(task.getLocationId());
        TNotice tNotice = new TNotice();
        tNotice.setUserId(appeal.getAppealPerson());
        tNotice.setStatus(1);
        tNotice.setDataId(dto.getId());
        dto.setAuditTime(LocalDateTime.now());
        TTaskDetail taskDetail = new TTaskDetail();
        taskDetail.setTaskId(appeal.getTaskId());
        Long count = tTaskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, appeal.getTaskId())
                .eq(TTaskDetail::getHandleType, 1).count();
        TNoticeSet noticeSet = noticeSetService.lambdaQuery().eq(TNoticeSet::getType, 2).last("limit 1")
                .one();
        // 邮箱
        TDictData email = dictDataService.lambdaQuery().eq(TDictData::getDataType,4).one();
        // 授权码
        TDictData code = dictDataService.lambdaQuery().eq(TDictData::getDataType,5).one();
        if (dto.getStatus()==2){
            taskDetail.setClearStatus(1);
            taskDetail.setAuditTime(LocalDateTime.now());
            taskDetail.setAuditPerson(tokenService.getLoginUser().getUserId()+"");
            taskDetail.setAuditStatus(1);
            taskDetail.setAuditRemark(dto.getAuditRemark());
            taskDetail.setHandleType(5);
            taskDetail.setAppealId(dto.getId());
            // 通过
            TTask byId = taskCleanService.getById(dto.getTaskId());
            if (count>1){
                byId.setStatus(5);
            }else{
                byId.setStatus(6);
 
            }
 
            taskCleanService.updateById(byId);
            tNotice.setNoticeType(5);
            tNotice.setNoticeContent("【"+location.getLocationName()+"】任务申诉通过");
            if (sysUser!=null){
                switch (noticeSet.getNoticeType()) {
                    case 1:
                        msgUtils.sendMsg3(sysUser.getPhonenumber(),location.getLocationName(),"通过");
                        break;
                    case 2:
                        if (StringUtils.hasLength(email.getDataContent())&&StringUtils.hasLength(code.getDataContent())){
                            EmailUtils.sendEmail(sysUser.getEmail(),email.getDataContent(),code.getDataContent(),"【"+location.getLocationName()+"】任务申诉通过");
                        }
                        break;
                    case 3:
                        break;
                }
            }
        }else{
            taskDetail.setClearStatus(2);
            taskDetail.setAuditTime(LocalDateTime.now());
            taskDetail.setAuditPerson(tokenService.getLoginUser().getUserId()+"");
            taskDetail.setAuditStatus(2);
            taskDetail.setAuditRemark(dto.getAuditRemark());
            taskDetail.setHandleType(6);
            taskDetail.setAppealId(dto.getId());
            tNotice.setNoticeType(4);
            tNotice.setNoticeContent("【"+location.getLocationName()+"】任务申诉驳回");
            if (sysUser!=null){
                switch (noticeSet.getNoticeType()) {
                    case 1:
                        msgUtils.sendMsg3(sysUser.getPhonenumber(),location.getLocationName(),"通过");
                        break;
                    case 2:
                        if (StringUtils.hasLength(email.getDataContent())&&StringUtils.hasLength(code.getDataContent())){
                            EmailUtils.sendEmail(sysUser.getEmail(),email.getDataContent(),code.getDataContent(),"【"+location.getLocationName()+"】任务申诉驳回");
                        }
                        break;
                    case 3:
                        break;
                }
            }
        }
        noticeService.save(tNotice);
        dto.setAuditPerson(tokenService.getLoginUser().getUserId()+"");
        appealService.updateById(dto);
        tTaskDetailService.save(taskDetail);
        return R.ok();
    }
}