liujie
2025-07-04 f332c00b763dcc0417492bd46244e9c56428a368
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package com.panzhihua.westcommittee.api;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.west.SystemUserVo;
import com.panzhihua.westcommittee.annotation.DistributedLock;
import com.panzhihua.westcommittee.annotation.SysLog;
import com.panzhihua.westcommittee.model.dto.*;
import com.panzhihua.westcommittee.model.entity.Complaint;
import com.panzhihua.westcommittee.model.entity.ComplaintComment;
import com.panzhihua.westcommittee.model.entity.Department;
import com.panzhihua.westcommittee.model.entity.SystemUser;
import com.panzhihua.westcommittee.model.vo.ComplaintVO;
import com.panzhihua.westcommittee.model.vo.DispatchVO;
import com.panzhihua.westcommittee.service.IComplaintCommentService;
import com.panzhihua.westcommittee.service.IComplaintService;
import com.panzhihua.westcommittee.service.IDepartmentService;
import com.panzhihua.westcommittee.service.ISystemUserService;
import com.panzhihua.westcommittee.warpper.MgtComplaintQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import static cn.hutool.core.util.ObjectUtil.isNull;
 
/**
 * @author mitao
 * @date 2025/3/14
 */
@Api(tags = {"西区纪委后台-诉求管理"})
@RequestMapping("/complaint")
@RestController
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class MgtComplaintController extends BaseController {
    private final IComplaintService complaintService;
    private final ISystemUserService systemUserService;
    private final IDepartmentService departmentService;
    private final IComplaintCommentService complaintCommentService;
 
    @PostMapping("/save")
    @ApiOperation(value = "录入诉求")
    @DistributedLock(lockName = "complaint_serial_number_lock")
    public R<?> save(@Valid @RequestBody Complaint complaint) {
        complaintService.saveComplaintAdmin(complaint, getLoginUserInfoWest());
        return R.ok();
    }
 
    @GetMapping("/getAllocationList")
    @ApiOperation(value = "获取分配派单位列表")
    public R<List<DispatchVO>> getAllocationList() {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        SystemUser systemUser = systemUserService.getById(loginUserInfoWest.getId());
        if(systemUser.getSystemRoleId()!=1){
            return R.fail("非管理员,无权限");
        }
        List<DispatchVO> dispatchVOList = new ArrayList<>();
        Integer oneDepartmentId = systemUser.getOneDepartmentId();
        Department byId = departmentService.getById(oneDepartmentId);
        LambdaQueryWrapper<Department> eq = new LambdaQueryWrapper<Department>().eq(Department::getTier, byId.getTier());
 
        if(byId.getTier()==2){
            eq.eq(Department::getDistrictsCode, byId.getDistrictsCode());
        }
        if(byId.getTier()==3){
            eq.eq(Department::getStreetId, byId.getStreetId());
        }
        if(byId.getTier()==4){
            eq.eq(Department::getCommunityId, byId.getCommunityId());
        }
 
        List<Department> list1 = departmentService.list(eq);
        for (Department department : list1) {
            DispatchVO dispatchVO = new DispatchVO();
            dispatchVO.setId(department.getId().toString());
            dispatchVO.setName(department.getName());
            dispatchVOList.add(dispatchVO);
        }
        return R.ok(dispatchVOList);
    }
 
 
 
    @PostMapping("/assignComplain")
    @ApiOperation(value = "分配诉求")
    public R<?> assignComplain(@Valid@RequestBody AssignComplainDto dto) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.assignComplain(loginUserInfoVO,dto.getComplainId(),dto.getDeptId(),dto.getRemark(),dto.getProblemType());
        return R.ok();
    }
 
 
 
    @ApiOperation("诉求列表")
    @PostMapping("/page")
    public R<Page<ComplaintVO>> pageList(@RequestBody MgtComplaintQuery query) {
        SystemUserVo loginUserInfo = getLoginUserInfoWest();
        return R.ok(complaintService.pageList(query,loginUserInfo));
    }
 
 
 
 
//    @ApiOperation("诉求详情")
//    @GetMapping("/detail/{id}")
//    public R<ComplaintVO> detail(@ApiParam(name = "id", value = "诉求id", required = true) @PathVariable("id") Long id) {
//        return R.ok(complaintService.getDetailMgt(id));
//    }
    @ApiOperation("导出")
    @PostMapping("/export")
    @SysLog(operatorCategory = "诉求导出",operId = 9)
    public void export(@RequestBody MgtComplaintQuery query) {
        SystemUserVo loginUserInfo = getLoginUserInfoWest();
        try {
            complaintService.export(query,loginUserInfo);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
 
 
    @PostMapping("/update-progress")
    @ApiOperation("办理进度修改2.0.1")
    public R<?> updateProgress(@Valid @RequestBody ComplaintProcessUpdateDto dto) {
        complaintService.updateProgress(dto);
        return R.ok();
    }
 
    @DeleteMapping("del-progress/{id}")
    @ApiOperation("办理进度删除2.0.1")
    public R<?> delProgress(@ApiParam(name = "id", value = "办理进度id", required = true) @PathVariable("id") Long id) {
        complaintService.delProgress(id);
        return R.ok();
    }
 
 
    @ApiOperation("社区问题单、问题处理单、协调通知单 下载")
    @GetMapping("/download-file/{id}/{type}")
    @SysLog(operatorCategory = "单导出",operId = 10)
    public  R<?> communityProblem(@ApiParam(name = "id", value = "诉求id", required = true) @PathVariable("id") Long id,
                                 @ApiParam(name = "type", value = "类型:1:社区问题单 2:问题处理单 3:协调通知单", required = true) @PathVariable("type") Integer type) {
        try {
            String name = complaintService.downloadFile(id, type, getLoginUserInfoWest());
            return R.ok(name);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
 
    @ApiOperation("诉求详情")
    @GetMapping("/detail/{id}")
    public R<ComplaintVO> detail(@PathVariable("id") Long id) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        return R.ok(complaintService.detail(id,loginUserInfoVO));
    }
 
 
    @PostMapping("/save-process")
    @ApiOperation("办理进度录入")
    public R<?> saveProcess(@Valid @RequestBody ComplaintProcessDTO dto){
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        complaintService.saveProcess(dto,loginUserInfoVO);
        return R.ok();
    }
 
    @PostMapping("/save-result")
    @ApiOperation("办理结果录入")
    public R<?> saveResult(@RequestBody ComplaintCompletionDTO dto){
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.saveResult(dto,loginUserInfoVO);
        return R.ok();
    }
 
 
    /**
     * 问题上报
     */
    @PostMapping("/report")
    @ApiOperation(value = "问题上报")
    public R<?> report(@RequestBody ComplaintReportDTO complaintReportDTO) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.saveReport(complaintReportDTO, loginUserInfoVO);
        return R.ok();
    }
 
 
    /**
     * 延期申请
     */
    @PostMapping("/saveDelay")
    @ApiOperation(value = "延期申请")
    public R<?> saveDelay(@Valid @RequestBody ComplaintDelayDTO dto){
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.saveDelay(dto, loginUserInfoVO);
        return R.ok();
    }
 
    /**
     * 延期审核
     */
    @PostMapping("/delayAudit")
    @ApiOperation(value = "延期审核")
    public R<?> delayAudit(@RequestBody ComplaintDelayAuditDTO dto) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.delayAudit(dto, loginUserInfoVO);
        return R.ok();
    }
 
    /**
     * 上报审核
     */
    @PostMapping("/reportAudit")
    @ApiOperation(value = "问题上报审核并指派")
    public R<?> reportAudit(@RequestBody ComplaintReporAuditDTO dto) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.reportAudit(dto, loginUserInfoVO);
        return R.ok();
    }
 
 
    @PostMapping("/setProblemType")
    @ApiOperation(value = "分配问题类型")
    public R<?> assignComplain(@Valid @RequestBody SetProblemTypeDto dto) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        // 判断是否管理员
        complaintService.setProblemType(loginUserInfoVO,dto);
        return R.ok();
    }
 
 
    /**
     * 评价诉求
     * @param complaintComment
     * @return
     */
    @PostMapping("/commentComplaint")
    @ApiOperation(value = "评价诉求")
    public R<?> commentComplaint(@RequestBody ComplaintComment complaintComment){
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        int count = complaintCommentService.count(new LambdaQueryWrapper<ComplaintComment>().eq(ComplaintComment::getComplaintId, complaintComment.getComplaintId())
                .eq(ComplaintComment::getDelFlag, 0));
        if(0 != count){
            return R.fail("不能重复评价");
        }
        Long userId = loginUserInfoVO.getUserId();
        complaintComment.setUserId(userId);
        complaintComment.setCreateTime(new Date());
        complaintComment.setCreateBy(userId);
        complaintComment.setUpdateBy(userId);
        complaintComment.setUpdateTime(new Date());
        complaintComment.setDelFlag(0);
        complaintCommentService.save(complaintComment);
        Complaint complaint = complaintService.getById(complaintComment.getComplaintId());
        complaint.setStatus(8);
        complaint.setCommentRate(complaintComment.getRate());
        complaintService.updateById(complaint);
        // 不满意 重新生成诉求
        if(complaintComment.getRate()==0){
            // 获取当前日期(年月日)
            String datePrefix = new SimpleDateFormat("yyyyMMdd").format(new Date());
 
            // 查询当前日期的最大流水号
            Complaint lastComplaint = complaintService.getOne(new LambdaQueryWrapper<Complaint>()
                    .likeRight(Complaint::getSerialNumber, datePrefix) // 查询以当前日期开头的流水号
                    .orderByDesc(Complaint::getSerialNumber)
                    .last("limit 1"));
 
            String serialNumber;
            if (isNull(lastComplaint)) {
                // 如果当天没有记录,从 0001 开始
                serialNumber = datePrefix + "0001";
            } else {
                // 获取当前日期的最大流水号,并递增
                String lastSerialNumber = lastComplaint.getSerialNumber();
                int num = Integer.parseInt(lastSerialNumber.substring(lastSerialNumber.length() - 4)); // 提取后4位数字
                serialNumber = datePrefix + String.format("%04d", num + 1); // 递增并格式化为4位
            }
            Complaint complaint1 = new Complaint();
            BeanUtils.copyProperties(complaint,complaint1);
            complaint1.setStatus(0);
            complaint1.setSerialNumber(serialNumber);
            complaint1.setAssignStatus(0);
            complaint1.setCreateTime(new Date());
            complaint1.setId(null);
            complaint1.setCompletionTime(null);
            complaint1.setCompletionUserId(null);
            complaint1.setCompletionUsername(null);
            complaint1.setCompletionUserPhone(null);
            complaint1.setCompletionImages(null);
            complaint1.setCompletionUserLevel(null);
            complaint1.setCompletionDescription(null);
            complaint1.setCompletionVideos(null);
            complaint1.setCompletionOtherDescription(null);
            complaint1.setRemark(null);
            complaint1.setNowLevelTime(new Date());
            complaint1.setNowLevelSms(0);
            complaint1.setRedispatch(1);
            complaintService.save(complaint1);
        }
 
        return R.ok();
    }
 
 
    /**
     * 上报撤回
     */
    @PostMapping("/revoke")
    @ApiOperation(value = "诉求上报撤回")
    public R<?> reportWithdraw(@RequestBody ComplaintReportWithdrawDTO dto) {
        SystemUserVo loginUserInfoWest = getLoginUserInfoWest();
        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
        loginUserInfoVO.setPhone(loginUserInfoWest.getPhone());
        loginUserInfoVO.setUserId(Long.valueOf(loginUserInfoWest.getId()));
        complaintService.reportWithdraw(dto, loginUserInfoVO);
        return R.ok();
    }
 
 
}