zhangnaisong
2023-10-06 f8ca81e96bcb9a9a05531d606f1dd67953c7a976
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
package com.ruoyi.plan.controller;
 
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletResponse;
 
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.plan.domain.ArdEplan;
import com.ruoyi.plan.service.IArdEplanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
/**
 * 应急预案Controller
 * 
 * @author ard
 * @date 2023-10-05
 */
@RestController
@RequestMapping("/plan/eplan")
@Api(tags = "应急预案")
public class ArdEplanController extends BaseController
{
    @Autowired
    private IArdEplanService ardEplanService;
 
    @Autowired
    private ISysUserService userService;
 
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
    /**
     * 查询应急预案列表
     */
    /*@PreAuthorize("@ss.hasPermi('plan:eplan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArdEplan ardEplan)
    {
        startPage();
        List<ArdEplan> list = ardEplanService.selectArdEplanList(ardEplan);
        return getDataTable(list);
    }*/
    @PreAuthorize("@ss.hasPermi('plan:eplan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArdEplan ardEplan)
    {
        startPage();
        List<ArdEplan> list = ardEplanService.selectArdEplanList(ardEplan);
        for(ArdEplan para : list){
            String info = para.getInfo();
            String[] infoArr = info.split(";");
            List<Map<String,String>> infoList = new ArrayList();
            for(String str : infoArr){
                Map<String,String> infoMap = new HashMap();
                infoMap.put("longitude",str.split(",")[0]);
                infoMap.put("latitude",str.split(",")[1]);
                infoMap.put("altitude",str.split(",")[2]);
                infoMap.put("text",str.split(",")[3]);
                infoList.add(infoMap);
            }
            para.setInfoList(infoList);
        }
        return getDataTable(list);
    }
 
 
    /**
     * 导出应急预案列表
     */
    /*@PreAuthorize("@ss.hasPermi('plan:eplan:export')")
    @Log(title = "应急预案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArdEplan ardEplan)
    {
        List<ArdEplan> list = ardEplanService.selectArdEplanList(ardEplan);
        ExcelUtil<ArdEplan> util = new ExcelUtil<ArdEplan>(ArdEplan.class);
        util.exportExcel(response, list, "应急预案数据");
    }*/
 
    /**
     * 获取应急预案详细信息
     */
    /*@PreAuthorize("@ss.hasPermi('plan:eplan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ardEplanService.selectArdEplanById(id));
    }*/
    @PreAuthorize("@ss.hasPermi('plan:eplan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        ArdEplan result = ardEplanService.selectArdEplanById(id);
        Map<String,Object> map = new HashMap();
        map.put("id",result.getId());
        map.put("name",result.getName());
        map.put("time",result.getTime());
        String info = result.getInfo();
        String[] infoArr = info.split(";");
        List<Map<String,String>> infoList = new ArrayList();
        for(String str : infoArr){
            Map<String,String> infoMap = new HashMap();
            infoMap.put("longitude",str.split(",")[0]);
            infoMap.put("latitude",str.split(",")[1]);
            infoMap.put("altitude",str.split(",")[2]);
            infoMap.put("text",str.split(",")[3]);
            infoList.add(infoMap);
        }
        map.put("obj",infoList);
        map.put("userId",result.getUserId());
        map.put("deptId",result.getDeptId());
        map.put("createBy",result.getCreateBy());
        return success(map);
    }
 
    /**
     * 新增应急预案
     */
    /*@PreAuthorize("@ss.hasPermi('plan:eplan:add')")
    @Log(title = "应急预案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArdEplan ardEplan)
    {
        return toAjax(ardEplanService.insertArdEplan(ardEplan));
    }*/
 
    @PreAuthorize("@ss.hasPermi('plan:eplan:add')")
    @Log(title = "应急预案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Map<String,Object> para)
    {
        ArdEplan ardEplan = new ArdEplan();
        String id = IdUtils.simpleUUID();
        ardEplan.setId(id);
        ardEplan.setName((String) para.get("name"));
        Date date = new Date();
        ardEplan.setTime(sdf.format(date));
        String info = "";
        if(para.get("obj") == null){
            return toAjax(0);
        }else{
            if(((List<Map<String,String>>)para.get("obj")).size() == 0){
                return toAjax(0);
            }
        }
        for(Map<String,String> map : (List<Map<String,String>>)para.get("obj")){
            info = info+map.get("longitude")+","+map.get("latitude")+","+map.get("altitude")+","+map.get("text")+";";
        }
        info = info.substring(0,info.length() - 1);
        ardEplan.setInfo(info);
        String userId = SecurityUtils.getUserId();
        ardEplan.setUserId(userId);
        ardEplan.setDeptId(String.valueOf((Integer) para.get("deptId")));
        SysUser sysUser = userService.selectUserById(userId);
        ardEplan.setCreateBy(sysUser.getUserName());
        ardEplan.setCreateTime(date);
        return toAjax(ardEplanService.insertArdEplan(ardEplan));
    }
 
    /**
     * 修改应急预案
     */
    /*@PreAuthorize("@ss.hasPermi('plan:eplan:edit')")
    @Log(title = "应急预案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArdEplan ardEplan)
    {
        return toAjax(ardEplanService.updateArdEplan(ardEplan));
    }*/
 
    @PreAuthorize("@ss.hasPermi('plan:eplan:edit')")
    @Log(title = "应急预案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Map<String,Object> para)
    {
        ArdEplan result = ardEplanService.selectArdEplanById((String) para.get("id"));
        if(!result.getDeptId().equals(String.valueOf((Integer) para.get("deptId")))){
            return toAjax(0);//非本部门预案无法更改
        }
        ArdEplan ardEplan = new ArdEplan();
        ardEplan.setId((String) para.get("id"));
        ardEplan.setName((String) para.get("name"));
        Date date = new Date();
        ardEplan.setTime(sdf.format(date));
        String info = "";
        if(para.get("obj") == null){
            return toAjax(0);
        }else{
            if(((List<Map<String,String>>)para.get("obj")).size() == 0){
                return toAjax(0);
            }
        }
        for(Map<String,String> map : (List<Map<String,String>>)para.get("obj")){
            info = info+map.get("longitude")+","+map.get("latitude")+","+map.get("altitude")+","+map.get("text")+";";
        }
        info = info.substring(0,info.length() - 1);
        ardEplan.setInfo(info);
        String userId = SecurityUtils.getUserId();
        ardEplan.setUserId(userId);
        ardEplan.setDeptId(String.valueOf((Integer) para.get("deptId")));
        SysUser sysUser = userService.selectUserById(userId);
        ardEplan.setCreateBy(sysUser.getUserName());
        ardEplan.setCreateTime(date);
        return toAjax(ardEplanService.updateArdEplan(ardEplan));
    }
 
    /**
     * 删除应急预案
     */
    @PreAuthorize("@ss.hasPermi('plan:eplan:remove')")
    @Log(title = "应急预案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        ArdEplan result = ardEplanService.selectArdEplanById(ids[0]);
        String userId = SecurityUtils.getUserId();
        SysUser sysUser = userService.selectUserById(userId);
        if(!result.getDeptId().equals(String.valueOf(sysUser.getDeptId()))){
            return toAjax(0);//非本部门预案无法删除
        }
        return toAjax(ardEplanService.deleteArdEplanByIds(ids));
    }
}