cjl
2023-11-15 d117d3af15dddc4f07baffa8b5bf6b727c05de7c
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
package com.moral.api.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.alibaba.fastjson.JSONObject;
import com.moral.api.entity.Supervision;
import com.moral.api.service.SupervisionService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@RestController
@RequestMapping("/supervision")
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = {"督办单模块"})
public class SupervisionController {
 
    @Autowired
    private SupervisionService supervisionService;
 
    @PostMapping("add")
    public ResultMessage add(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
        Supervision supervision = JSONObject.parseObject(JSONObject.toJSONString(params), Supervision.class);
        Map<String, Object> response = supervisionService.add(files, supervision);
        if (!response.isEmpty()) {
            return ResultMessage.fail(Integer.parseInt(response.get("code").toString()), response.get("msg").toString());
        }
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "分页督办单列表", notes = "分页督办单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "organizationId", value = "组织id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "cityCode", value = "地区码", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "start", value = "开始时间", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "end", value = "结束时间", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int")
    })
    @GetMapping("select")
    public ResultMessage select(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("cityCode") && !params.containsKey("organizationId")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
 
        Map<String, Object> result = supervisionService.selectSupervisions(params);
        return ResultMessage.ok(result);
    }
 
    @ApiOperation(value = "修改督办单", notes = "修改督办单")
    @PostMapping("update")
    public ResultMessage update(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
        Supervision supervision = JSONObject.parseObject(JSONObject.toJSONString(params), Supervision.class);
        Map<String, Object> response = supervisionService.updateSupervision(files, supervision);
        if (!response.isEmpty()) {
            return ResultMessage.fail(Integer.parseInt(response.get("code").toString()), response.get("msg").toString());
        }
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "删除督办单", notes = "删除督办单")
    @GetMapping("delete")
    public ResultMessage delete(Integer supervisionId) {
        if (ObjectUtils.isEmpty(supervisionId)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        supervisionService.deleteSupervision(supervisionId);
        return ResultMessage.ok();
    }
 
}