青羊经侦大队-数据平台
baizonghao
2023-05-19 1c3f11dfd7493a4c4a8d41e2499477840bcc070c
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
package com.example.jz.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.jz.modle.R;
import com.example.jz.modle.dto.AddReportDto;
import com.example.jz.modle.dto.ReportParamDto;
import com.example.jz.modle.entity.GroupUser;
import com.example.jz.modle.entity.Message;
import com.example.jz.modle.entity.Report;
import com.example.jz.modle.entity.User;
import com.example.jz.modle.vo.NewCauseVo;
import com.example.jz.modle.vo.ReportListVo;
import com.example.jz.modle.vo.ReportVXVO;
import com.example.jz.service.GroupUserService;
import com.example.jz.service.MessageService;
import com.example.jz.service.ReportService;
import com.example.jz.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.Map;
 
/**
 * 报案表(Report)表控制层
 *
 * @author 安瑾然
 * @since 2022-07-13 11:52:58
 */
@RestController
@RequestMapping("report")
@Api(value = "案件区-案件人员", tags = "案件区-案件人员")
public class ReportController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private ReportService reportService;
    @Resource
    GroupUserService groupUserService;
    @Resource
    MessageService messageService;
    @Autowired
    UserService userService;
 
    /**
     * 分页查询所有数据
     *
     * @param page           分页对象
     * @param reportParamDto 查询实体
     * @return 所有数据
     */
    @GetMapping
    @ApiOperation(value = "分页查询所有数据")
    public R<IPage<ReportListVo>> selectAll(Page<ReportListVo> page, ReportParamDto reportParamDto) {
        return R.ok(reportService.getPage(page, reportParamDto));
    }
 
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public R<ReportListVo> selectOne(@PathVariable Serializable id) {
        return R.ok(reportService.getReportListVoById(id));
    }
 
    @GetMapping("/rejectReport/{id}")
    @ApiOperation(value = "修改驳回后接口")
    public  R<ReportVXVO> getOne(@PathVariable Integer id){
        ReportVXVO res = reportService.getRejectReportById(id);
        return R.ok(res);
    }
 
    @GetMapping("/rejectCauseList")
    public R<NewCauseVo> rejectCauseList(@RequestParam Integer id){
        NewCauseVo res = reportService.rejectCauseList(id);
        return R.ok(res);
    }
 
 
    /**
     * 报案
     *
     * @param addReportDto 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation(value = "报案")
    public R<Boolean> insert(@RequestBody AddReportDto addReportDto) {
        return R.ok(reportService.addReport(addReportDto));
    }
 
    /**
     * 审核通过并且关联案件id
     *
     * @param report 实体对象
     * @return 修改结果
     */
    @PostMapping("/audit")
    @ApiOperation(value = "审核通过")
    public R<Boolean> audit(@RequestBody Report report) {
        return R.ok(reportService.audit(report));
    }
 
    @PostMapping("/reject")
    @ApiOperation(value = "驳回")
    public R<Boolean> reject(@RequestBody Map map) {
        return R.ok(reportService.reject((Integer) map.get("id"), (String) map.get("reason")));
    }
 
    @ApiOperation(httpMethod = "PUT", value = "案件台-报案人员-编辑")
    @PutMapping("/updateReport")
    @ApiResponse(message = "执行成功", code = 200)
    @Transactional(rollbackFor = Exception.class)
    public R updateReport(@RequestBody AddReportDto report) {
        Integer causeId = report.getCauseId();
        if(causeId==null){
            return R.failed("关联案件不能为空");
        }
        int imgIndexFirst = report.getPic().indexOf("/img");
        int imgIndexEnd = report.getPic().length();
        if(report.getPic().indexOf("?") != -1){
            imgIndexEnd = report.getPic().indexOf("?");
        }
        String pic = report.getPic().substring(imgIndexFirst + 5, imgIndexEnd);
        report.setPic(pic);
        reportService.updateById(report);
        Report one = reportService.getOne(new LambdaQueryWrapper<Report>().eq(Report::getId, report.getId()));
        User user = new User();
        user.setRealName(report.getReporterName());
        user.setUserIdcard(report.getIdcard());
        user.setUserMobile(report.getMobile());
        user.setPic(pic);
        user.setId(one.getUserId());
        userService.updateById(user);
        return R.ok();
    }
 
    @ApiOperation(httpMethod = "DELETE", value = "案件台-报案人员-退群")
    @DeleteMapping("/leaveGroup")
    @ApiResponse(message = "执行成功", code = 200)
    public R leaveGroup(@RequestParam(value = "id") Integer id, @RequestParam(value = "groupId") Integer groupId) {
        reportService.leaveGroup(id, groupId);
        return R.ok();
    }
 
    @ApiOperation(httpMethod = "DELETE", value = "案件台-报案人员-删除")
    @DeleteMapping("/deleteReporter")
    @ApiResponse(message = "执行成功", code = 200)
    public R deleteReporter(@RequestParam(value = "id") Integer id) {
        groupUserService.remove(new LambdaQueryWrapper<GroupUser>().eq(GroupUser::getUserId, id));
        messageService.remove(new LambdaQueryWrapper<Message>().eq(Message::getUserId, id));
        reportService.removeById(id);
        return R.ok();
    }
 
    @ApiOperation(httpMethod = "POST", value = "案件台-案件录入-报案人员-报案人元导入")
    @PostMapping("/reporterUpload")
    @ApiResponse(message = "执行成功", code = 200)
    @SneakyThrows
    public R uploadReporter(@RequestParam(value = "multipartFile") MultipartFile multipartFile, Integer causeId) {
        reportService.loadFileReport(multipartFile,causeId);
        return R.ok();
    }
 
//    @ApiOperation(httpMethod = "POST", value = "案件台-报案人员-报案材料导出")
//    @PostMapping("/exportReporter")
//    @ApiResponse(message = "执行成功", code = 200)
//    public void exportReport(@RequestParam(value = "id") Integer id, HttpServletResponse response) {
//        reportService.exportReporter(id, response);
//    }
}