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
94
95
96
97
98
99
100
101
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.moral.api.entity.Rectify;
import com.moral.api.service.RectifyService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@Slf4j
@Api(tags = {"企业整顿"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("rectify")
public class RectifyController {
 
    @Autowired
    private RectifyService rectifyService;
 
    @PostMapping("addRectify")
    public ResultMessage addRectify(@RequestBody Rectify rectify) {
        if (rectify.getCityCode() == null || rectify.getCityName() == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        int count = rectifyService.addRectify(rectify);
        if (count > 0) {
            return ResultMessage.ok();
        }
        return ResultMessage.fail();
    }
 
 
    @ApiOperation(value = "分页整顿清单", notes = "分页整顿清单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityCode", value = "城市编码", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "time", value = "时间,例:2022", 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("queryRectify")
    public ResultMessage queryRectify(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (params.get("cityCode") == null || params.get("time") == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> response = rectifyService.queryRectifyByCityCode(params);
        return ResultMessage.ok(response);
    }
 
    @GetMapping("exportRectify")
    public ResultMessage exportRectify(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (params.get("cityCode") == null || params.get("time") == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Rectify> rectifies = rectifyService.exportRectifyByCityCode(params);
        return ResultMessage.ok(rectifies);
    }
 
    @PostMapping("updateRectify")
    public ResultMessage updateRectify(@RequestBody Rectify rectify) {
        if (rectify.getId() == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        int count = rectifyService.updateRectify(rectify);
        if (count > 0) {
            return ResultMessage.ok();
        }
        return ResultMessage.fail();
    }
 
    @GetMapping("deleteRectify")
    public ResultMessage deleteRectify(Integer id) {
        if (id == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        int count = rectifyService.deleteRectify(id);
        if (count > 0) {
            return ResultMessage.ok();
        }
        return ResultMessage.fail();
    }
}