13693261870
2025-07-02 6708810c4de34dfb9513061432d656f91d56ee3a
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package com.ruoyi.web.controller.manage;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fuzhou.domain.DpEquipment;
import com.ruoyi.fuzhou.domain.ReceiveSlmValueFinal;
import com.ruoyi.fuzhou.domain.ReceiveWaterValue;
import com.ruoyi.fuzhou.domain.vo.DpEquipmentVO;
import com.ruoyi.fuzhou.service.EquipmentService;
import com.ruoyi.fuzhou.service.ReceiveWaterValueService;
import com.ruoyi.manage.domain.DmBerth;
import com.ruoyi.manage.service.DpBerthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
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.manage.domain.DmHarbor;
import com.ruoyi.manage.service.IDmHarborService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
/**
 * 港口信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/dp/harbor")
@Tag(name = "大屏--港口管理")
public class DmHarborController extends BaseController
{
    @Autowired
    private IDmHarborService dmHarborService;
    @Autowired
    private DpBerthService dpBerthService;
    @Resource
    private EquipmentService dpEquipmentService;
    @Resource
    private ReceiveWaterValueService receiveWaterValueService;
 
    /**
     * 查询港口信息列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询港口信息列表")
    public TableDataInfo list(DmHarbor dmHarbor)
    {
 
       return dmHarborService.getList(dmHarbor);
    }
 
    /**
     * 查询所有港口信息列表
     */
    @GetMapping("/listAll")
    @Operation(summary = "查询所有港口信息列表")
    public AjaxResult listAll()
    {
        return AjaxResult.success(dmHarborService.list());
    }
 
    /**
     * 查询所有港口信息列表
     */
    @GetMapping("/getListAll")
    @Operation(summary = "查询所有港口信息")
    public AjaxResult getListAll()
    {
        //获取用户信息根据部门ID查询港口信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long deptId = loginUser.getDeptId();
        if(deptId.equals(100L)){
            return AjaxResult.success(dmHarborService.list());
        }
        if(deptId.equals(4001L)){
            deptId = 101L;
        }
        if(deptId.equals(4002L)){
            deptId = 4000L;
        }
        QueryWrapper<DmHarbor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("DEPT_ID",deptId);
        return AjaxResult.success(dmHarborService.list(queryWrapper));
    }
 
    /**
     * 查询港口及其泊位详情
     */
    @GetMapping("/getHarborBerth")
    @Operation(summary = "查询港口及其泊位详情")
    public AjaxResult getHarborBerth()
    {
        //获取用户信息根据部门ID查询港口信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long deptId = loginUser.getDeptId();
        List<DmHarbor> reslist = new ArrayList<>();
        if(deptId.equals(100L)){
            List<DmHarbor> list = dmHarborService.list();
            for (DmHarbor dmHarbor : list){
                LambdaQueryWrapper<DmBerth> berthQueryWrapper = new LambdaQueryWrapper<>();
                berthQueryWrapper.eq(DmBerth::getHarborId,dmHarbor.getPkId()).notIn(DmBerth::getName,"园区").orderByAsc(DmBerth::getOrderNum);
                List<DmBerth> dmBerths = dpBerthService.list(berthQueryWrapper);
                dmHarbor.setDmBerthList(dmBerths);
                reslist.add(dmHarbor);
            }
            return AjaxResult.success(reslist);
        }else {
            if(deptId.equals(4001L)){
                deptId = 101L;
            }
            QueryWrapper<DmHarbor> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("DEPT_ID",deptId);
            List<DmHarbor> list = dmHarborService.list(queryWrapper);
            for (DmHarbor dmHarbor : list){
                LambdaQueryWrapper<DmBerth> QueryWrapper = new LambdaQueryWrapper<>();
                QueryWrapper.eq(DmBerth::getHarborId,dmHarbor.getPkId()).notIn(DmBerth::getName,"园区").orderByAsc(DmBerth::getOrderNum);
                List<DmBerth> dmBerths = dpBerthService.list(QueryWrapper);
                dmHarbor.setDmBerthList(dmBerths);
                reslist.add(dmHarbor);
            }
            return AjaxResult.success(reslist);
        }
    }
 
    /**
     * 查询港口水深数据列表
     */
    @GetMapping("/getWaterDepthList")
    @Operation(summary = "查询港口水深数据列表")
    public AjaxResult getWaterDepthList() {
        //获取用户信息根据部门ID查询港口信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long deptId = loginUser.getDeptId();
        List<DpEquipmentVO> resList = new ArrayList<>();
        if(deptId.equals(100L)){
            List<DmHarbor> list = dmHarborService.list();
            return AjaxResult.success(getWaterDepth(list));
        }else {
            if(deptId.equals(4001L)){
                deptId = 101L;
            }
            QueryWrapper<DmHarbor> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("DEPT_ID",deptId);
            List<DmHarbor> list = dmHarborService.list(queryWrapper);
            return AjaxResult.success(getWaterDepth(list));
        }
    }
 
    /**
     * 查询港口水深数据列表
     */
    @GetMapping("/getWaterListByIds")
    @Operation(summary = "通过设备id查询水深数据列表")
    public AjaxResult getWaterListByIds(String ids) {
 
        LocalDate today=LocalDate.now();
        LocalDateTime startOfDay=today.atStartOfDay();
        LocalDateTime endOfDay=today.plusDays(1).atStartOfDay().minusSeconds(1);
 
 
        List<ReceiveWaterValue> result=receiveWaterValueService.list(new LambdaQueryWrapper<ReceiveWaterValue>() {{
            in(ReceiveWaterValue::getDeviceName,ids.split(","))
            .ge(ReceiveWaterValue::getCreateTime,startOfDay)
            .le(ReceiveWaterValue::getCreateTime,endOfDay);
        }});
 
        List<Map<String,Object>>res=new ArrayList<>();
        String[] idArray=ids.split(",");
        for (int i = 0; i < idArray.length; i++){
            Map<String,Object> map=new HashMap<>();
            map.put("id",idArray[i]);
            List<ReceiveWaterValue> ds=new ArrayList<>();
            for (int k = 0; k < result.size(); k++) {
                ReceiveWaterValue data=result.get(k);
                if(data.getDeviceName().equals(idArray[i])){
                    ds.add(data);
                }
            }
            map.put("data",ds);
            res.add(map);
        }
 
        return AjaxResult.success(res);
    }
 
    private JSONArray getWaterDepth(List<DmHarbor> list){
        List<DpEquipmentVO> resList = new ArrayList<>();
        for (DmHarbor dmHarbor : list){
            List<DpEquipmentVO> dpEquipmentVOS = dpEquipmentService.getListByWhId(dmHarbor.getPkId().intValue());
            for (DpEquipmentVO dpEquipmentVO : dpEquipmentVOS){
                if(dpEquipmentVO.getEquipmentTypeId()==7){
                    ReceiveWaterValue waterValue = receiveWaterValueService.getOne(new LambdaQueryWrapper<ReceiveWaterValue>() {{
                        eq(ReceiveWaterValue::getDeviceName, String.valueOf(dpEquipmentVO.getId()))
                                .orderByDesc(ReceiveWaterValue::getCreateTime).last("LIMIT 1");
                    }});
                    if(waterValue!=null){
                        dpEquipmentVO.setFieldName(waterValue.getWaterDeep());
                        resList.add(dpEquipmentVO);
                    }
                }
            }
        }
        JSONArray jsonArray = new JSONArray();
        for (DpEquipmentVO dpEquipmentVO : resList){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("equName",dpEquipmentVO.getEquName());
            jsonObject.put("waterDeep",dpEquipmentVO.getFieldName());
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }
 
 
    /**
     * 导出港口信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:harbor:export')")
//    @Log(title = "港口信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, DmHarbor2 dmHarbor)
//    {
//        List<DmHarbor2> list = dmHarborService.selectDmHarborList(dmHarbor);
//        ExcelUtil<DmHarbor2> util = new ExcelUtil<DmHarbor2>(DmHarbor2.class);
//        util.exportExcel(response, list, "港口信息数据");
//    }
 
    /**
     * 获取港口信息详细信息
     */
    @GetMapping("/{pkId}")
    @Operation(summary = "获取港口信息详细信息")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(dmHarborService.getById(pkId));
    }
 
    /**
     * 新增港口信息
     */
    @Operation(summary = "新增港口信息")
    @PostMapping
    public AjaxResult add(@RequestBody DmHarbor dmHarbor)
    {
        return toAjax(dmHarborService.save(dmHarbor));
    }
 
    /**
     * 修改港口信息
     */
    @Operation(summary = "修改港口信息")
    @PutMapping
    public AjaxResult edit(@RequestBody DmHarbor dmHarbor)
    {
        return toAjax(dmHarborService.updateById(dmHarbor));
    }
 
    /**
     * 删除港口信息
     */
    @Operation(summary = "删除港口信息")
    @DeleteMapping("/{pkId}")
    public AjaxResult remove(@PathVariable Long pkId)
    {
        return toAjax(dmHarborService.removeById(pkId));
    }
}