kaiyu
2021-09-14 0aed1c0e6a91207c15fa34f49a7dfa9b6e2b64c5
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
package com.moral.api.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.moral.api.entity.GovMonitorPoint;
import com.moral.api.mapper.GovMonitorPointMapper;
import com.moral.api.service.GovMonitorPointService;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
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.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import java.util.List;
import java.util.Map;
 
/**
 * @program: screen
 * @description: 政府站点
 * @author: lizijie
 * @create: 2021-09-09 11:31
 **/
@Slf4j
@Api(tags = {"政府站点"})
@RestController
@RequestMapping("/govMonitorPoint")
public class GovMonitorPoionController {
 
    @Resource
    private GovMonitorPointService govMonitorPointService;
 
    @Resource
    private GovMonitorPointMapper govMonitorPointMapper;
 
    @RequestMapping(value = "getGovMonitorPointByCondition", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getSpecialDeviceByCondition(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Map<String, Object> resultMap = govMonitorPointService.getDataByCondition(parameters);
        if (!resultMap.containsKey("code")) {
            return ResultMessage.ok(resultMap);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()), resultMap.get("msg").toString());
    }
 
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage insert(@RequestBody GovMonitorPoint govMonitorPoint) {
        String guid = govMonitorPoint.getGuid();
        String name = govMonitorPoint.getName();
        double longitude = govMonitorPoint.getLongitude();
        double latitude = govMonitorPoint.getLatitude();
        String station_level = govMonitorPoint.getStationLevel();
        if (ObjectUtils.isEmpty(guid) && ObjectUtils.isEmpty(name) && ObjectUtils.isEmpty(longitude) && ObjectUtils.isEmpty(latitude) && ObjectUtils.isEmpty(station_level)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>();
        wrapper_govMonitorPoint.eq("is_delete", Constants.NOT_DELETE);
        wrapper_govMonitorPoint.eq("guid", guid).or().eq("name", name);
        List<GovMonitorPoint> govMonitorPoints = govMonitorPointMapper.selectList(wrapper_govMonitorPoint);
        if (govMonitorPoints.size() > 0) {
            return ResultMessage.fail(ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getCode(), ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getMsg());
        }
        govMonitorPointService.insert(govMonitorPoint);
        return ResultMessage.ok();
    }
 
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage update(@RequestBody GovMonitorPoint govMonitorPoint) {
        int id = govMonitorPoint.getId();
        if (ObjectUtils.isEmpty(id)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>();
        wrapper_govMonitorPoint.eq("is_delete", Constants.NOT_DELETE);
        wrapper_govMonitorPoint.eq("id", id);
        List<GovMonitorPoint> govMonitorPoints = govMonitorPointMapper.selectList(wrapper_govMonitorPoint);
        if (govMonitorPoints.size() == 0) {
            return ResultMessage.fail(ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getCode(), ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getMsg());
        }
        govMonitorPointService.update(govMonitorPoint);
        return ResultMessage.ok();
    }
 
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage delete(@RequestBody Map map) {
        int id = Integer.parseInt(map.get("id").toString());
        if (ObjectUtils.isEmpty(id)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>();
        wrapper_govMonitorPoint.eq("is_delete", Constants.NOT_DELETE);
        wrapper_govMonitorPoint.eq("id", id);
        List<GovMonitorPoint> govMonitorPoints = govMonitorPointMapper.selectList(wrapper_govMonitorPoint);
        if (govMonitorPoints.size() == 0) {
            return ResultMessage.fail(ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getCode(), ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getMsg());
        }
        govMonitorPointService.delete(id);
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "获取该区域下所有国控/省控/县控站点", notes = "获取该区域下所有国控/省控/县控站点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @GetMapping("govMonitorPoints")
    public ResultMessage selectGovMonitorPoints(String regionCode) {
        List<Map<String, Object>> response = govMonitorPointService.selectGovMonitorPoints(regionCode);
        return ResultMessage.ok(response);
    }
}