jinpengyong
2024-02-29 b8e97933ddcffb65754a82b9993e3a37097cc2d2
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
package com.moral.api.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.Device;
import com.moral.api.entity.HandDevice;
import com.moral.api.pojo.query.handdevice.HandDevicePageCond;
import com.moral.api.service.DeviceService;
import com.moral.api.service.HandDeviceService;
import com.moral.api.service.SpecialDeviceService;
import com.moral.api.utils.EasyExcelUtils;
import com.moral.api.utils.NoModelWriteData;
import com.moral.constant.PageResult;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
/**
 * Description //todo
 *
 * @author swb
 * @ClassName HandDeviceController
 * @date 2024.02.27 10:21
 */
 
@Slf4j
@Api(tags = {"手持设备"})
@RestController
@RequestMapping("/hand")
public class HandDeviceController {
 
    @Autowired
    private HandDeviceService handDeviceService;
 
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private SpecialDeviceService specialDeviceService;
 
    @PostMapping("/page")
    @ApiOperation("分页")
    public ResultMessage page(@Valid @RequestBody HandDevicePageCond handDevicePageCond){
        Page<HandDevice> page = handDeviceService.page(handDevicePageCond);
        PageResult<HandDevice> rsList = new PageResult<>(page);
        rsList.setList(page.getRecords());
        return ResultMessage.ok(rsList);
    }
 
    @GetMapping("/check")
    @ApiOperation("查询手持设备")
    public  ResultMessage select(){
        List<Device> check = handDeviceService.check();
        return ResultMessage.ok(check);
    }
 
    @GetMapping("/id")
    @ApiOperation("根据mac查询设备")
    public  ResultMessage query(String mac){
        HandDevice handDevice = handDeviceService.query(mac);
        return ResultMessage.ok(handDevice);
    }
 
    @PostMapping("/update")
    @ApiOperation("修改手持设备")
    public  ResultMessage update(@RequestBody Device device){
        if (device.getId() == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
     /*   if (device.getMac() != null) {
            //判断mac是否已存在,普通设备表和特殊设备表都要判断
            QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
 
            QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
            specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
            if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
                return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
            }
        }*/
        handDeviceService.update(device);
        return ResultMessage.ok();
    }
 
    @GetMapping("/details")
    @ApiOperation("详情")
    public  ResultMessage details(String mac,String startTime,String endTime,String type){
        List<Map<String, Object>> details = handDeviceService.details(mac, startTime, endTime,type);
        return ResultMessage.ok(details);
    }
 
    @GetMapping("/unitExel")
    @ApiOperation("导出")
    public  void exel(HttpServletResponse response, HttpServletRequest request){
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        List<Map<String, Object>> details = handDeviceService.detailsExecl(params);
        if (CollectionUtils.isEmpty(details)) {
            return;
        }
        Map<String, Object> map = details.get(0);
        List<String> list = new ArrayList<>();
        for (String key : map.keySet()) {
            list.add(key);
        }
        String[] s2 = new String[list.size()];
        list.toArray(s2);
        NoModelWriteData d = new NoModelWriteData();
        d.setFileName("数据导出");
        d.setHeadMap(s2);
        d.setDataStrMap(s2);
        d.setDataList(details);
        try {
            EasyExcelUtils easyExcelUtils = new EasyExcelUtils();
            easyExcelUtils.noModleWrite(d, response);
        } catch (Exception e) {
            int i = 0;
        }
    }
 
}