New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.config.Interceptor.UserHelper; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.HandDevice; |
| | | import com.moral.api.entity.HistoryFiveMinutely; |
| | | import com.moral.api.entity.HistoryHourly; |
| | | import com.moral.api.entity.HistoryMinutely; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.mapper.HandDeviceMapper; |
| | | import com.moral.api.pojo.query.handdevice.HandDevicePageCond; |
| | | import com.moral.api.pojo.vo.user.QxUser; |
| | | import com.moral.api.service.DeviceService; |
| | | import com.moral.api.service.HandDeviceService; |
| | | import com.moral.api.service.HistoryFiveMinutelyService; |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Description //todo |
| | | * |
| | | * @author swb |
| | | * @ClassName HandDeviceServiceImpl |
| | | * @date 2024.02.27 10:25 |
| | | */ |
| | | @Service |
| | | public class HandDeviceServiceImpl extends ServiceImpl<HandDeviceMapper, HandDevice> implements HandDeviceService { |
| | | |
| | | |
| | | @Autowired |
| | | private HandDeviceMapper handDeviceMapper; |
| | | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | @Autowired |
| | | private HistoryHourlyService historyHourlyService; |
| | | |
| | | |
| | | @Autowired |
| | | private HistoryFiveMinutelyService historyFiveMinutelyService; |
| | | |
| | | /** |
| | | * 分页 |
| | | * |
| | | * @param handDevicePageCond |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Page<HandDevice> page(HandDevicePageCond handDevicePageCond) { |
| | | |
| | | Page<HandDevice> page = handDeviceMapper.Page(handDevicePageCond.getPage().convertPage(), |
| | | handDevicePageCond.getMac(), |
| | | handDevicePageCond.getName(), |
| | | handDevicePageCond.getStartTime(), |
| | | handDevicePageCond.getEndTime()); |
| | | return page; |
| | | } |
| | | |
| | | /** |
| | | * 查询手持设备 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Device> check() { |
| | | LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.select(Device::getMac,Device::getName,Device::getId); |
| | | wrapper.eq(Device::getMonitorPointId,123); |
| | | wrapper.eq(Device::getIsDelete,Constants.NOT_DELETE); |
| | | wrapper.orderByAsc(Device::getCreateTime); |
| | | List<Device> devices = deviceMapper.selectList(wrapper); |
| | | return devices; |
| | | } |
| | | |
| | | /** |
| | | * 修改手持设备 |
| | | * |
| | | * @param handDevice |
| | | * @return |
| | | */ |
| | | @Override |
| | | public HandDevice update(HandDevice handDevice) { |
| | | QxUser currentUser = UserHelper.getCurrentUser(); |
| | | String state = handDevice.getState(); |
| | | if (state.equals("0")){ |
| | | HandDevice handDevice1 = getHand(handDevice); |
| | | handDevice1.setCreateName(currentUser.getUserName()); |
| | | handDeviceMapper.insert(handDevice1); |
| | | return handDevice1; |
| | | }else { |
| | | handDevice.setEndTime(new Date()); |
| | | handDevice.setState("0"); |
| | | handDevice.setUpdateName(currentUser.getUserName()); |
| | | handDeviceMapper.updateById(handDevice); |
| | | return handDevice; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public HandDevice query(String mac) { |
| | | QueryWrapper<HandDevice> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("mac",mac); |
| | | queryWrapper.orderByDesc("create_time"); |
| | | List<HandDevice> handDevices = handDeviceMapper.selectList(queryWrapper); |
| | | HandDevice handDevice; |
| | | if (ObjectUtils.isEmpty(handDevices)){ |
| | | handDevice = new HandDevice(); |
| | | Device deviceByMac = deviceService.getDeviceByMac(mac); |
| | | handDevice.setName(deviceByMac.getName()); |
| | | handDevice.setMac(deviceByMac.getMac()); |
| | | handDevice.setState("0"); |
| | | }else { |
| | | handDevice = handDevices.get(0); |
| | | } |
| | | return handDevice; |
| | | } |
| | | |
| | | /** |
| | | * 详情 |
| | | * |
| | | * @param mac |
| | | * @param startTime |
| | | * @param endTime |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> details(String mac, String startTime, String endTime,String type) { |
| | | Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_EN); |
| | | Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_mm_EN); |
| | | List<Map<String, Object>> rsMap = new ArrayList<>(); |
| | | if (ObjectUtils.isEmpty(endTime)){ |
| | | endDate = new Date(); |
| | | |
| | | } |
| | | if (type.equals("hour")){ |
| | | List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); |
| | | for (HistoryHourly historyHourly : valueByMacAndTime) { |
| | | String value = historyHourly.getValue(); |
| | | Map map = JSON.parseObject(value, Map.class); |
| | | map.put("time",DateUtils.dateToDateString(historyHourly.getTime())); |
| | | map.put("a21001",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); |
| | | map.put("a21028",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); |
| | | rsMap.add(map); |
| | | } |
| | | }else if (type.equals("minute")){ |
| | | List<HistoryMinutely> historyMinutelys = historyHourlyService.getHistoryMinutely(mac, startDate, endDate); |
| | | for (HistoryMinutely historyMinutely : historyMinutelys) { |
| | | String value = historyMinutely.getValue(); |
| | | Map map = JSON.parseObject(value, Map.class); |
| | | map.put("time",DateUtils.dateToDateString(historyMinutely.getTime())); |
| | | map.put("a21001",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); |
| | | map.put("a21028",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); |
| | | rsMap.add(map); |
| | | } |
| | | }else if (type.equals("minutely")){ |
| | | List<HistoryFiveMinutely> historyFiveMinutelies = historyFiveMinutelyService.queryFiveMinutely(mac, startDate, endDate); |
| | | for (HistoryFiveMinutely historyFiveMinutely : historyFiveMinutelies) { |
| | | String value = historyFiveMinutely.getValue(); |
| | | Map map = JSON.parseObject(value, Map.class); |
| | | map.put("time",DateUtils.dateToDateString(historyFiveMinutely.getTime())); |
| | | map.put("a21001",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); |
| | | map.put("a21028",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); |
| | | map.put("a31001",ObjectUtils.isEmpty(map.get("a31001"))?0:map.get("a31001")); |
| | | rsMap.add(map); |
| | | } |
| | | } |
| | | return rsMap; |
| | | } |
| | | |
| | | /** |
| | | * 导出 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> detailsExecl(Map<String, Object> params) { |
| | | String type = params.get("type").toString(); |
| | | String mac = params.get("mac").toString(); |
| | | Object endTime = params.get("endTime"); |
| | | Date startDate = DateUtils.getDate(params.get("startTime").toString(),DateUtils.yyyy_MM_dd_HH_mm_EN); |
| | | Date endDate; |
| | | List<Map<String, Object>> rsMap = new ArrayList<>(); |
| | | if (ObjectUtils.isEmpty(endTime)){ |
| | | endDate = new Date(); |
| | | }else { |
| | | endDate = DateUtils.getDate(endTime.toString(),DateUtils.yyyy_MM_dd_HH_mm_EN); |
| | | } |
| | | if (type.equals("hour")){ |
| | | List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); |
| | | for (HistoryHourly historyHourly : valueByMacAndTime) { |
| | | LinkedHashMap<String, Object> map1 = new LinkedHashMap<>(); |
| | | String value = historyHourly.getValue(); |
| | | Map map = JSON.parseObject(value, Map.class); |
| | | map1.put("时间",DateUtils.dateToDateString(historyHourly.getTime())); |
| | | map1.put("pm25",ObjectUtils.isEmpty(map.get("a34004"))?0:map.get("a34004")); |
| | | map1.put("pm10",ObjectUtils.isEmpty(map.get("a34002"))?0:map.get("a34002")); |
| | | map1.put("二氧化氮",ObjectUtils.isEmpty(map.get("a21004"))?0:map.get("a21004")); |
| | | map1.put("二氧化硫",ObjectUtils.isEmpty(map.get("a21026"))?0:map.get("a21026")); |
| | | map1.put("一氧化碳",ObjectUtils.isEmpty(map.get("a21005"))?0:map.get("a21005")); |
| | | map1.put("气压",ObjectUtils.isEmpty(map.get("a01006"))?0:map.get("a01006")); |
| | | map1.put("温度",ObjectUtils.isEmpty(map.get("a01001"))?0:map.get("a01001")); |
| | | map1.put("湿度",ObjectUtils.isEmpty(map.get("a01002"))?0:map.get("a01002")); |
| | | map1.put("tvoc",ObjectUtils.isEmpty(map.get("a99054"))?0:map.get("a99054")); |
| | | map1.put("甲醛",ObjectUtils.isEmpty(map.get("a31001"))?0:map.get("a31001")); |
| | | map1.put("硫化氢",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); |
| | | map1.put("氨气",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); |
| | | rsMap.add(map1); |
| | | } |
| | | }else { |
| | | List<HistoryFiveMinutely> historyFiveMinutelies = historyFiveMinutelyService.queryFiveMinutely(mac, startDate, endDate); |
| | | for (HistoryFiveMinutely historyFiveMinutely : historyFiveMinutelies) { |
| | | LinkedHashMap<String, Object> map1 = new LinkedHashMap<>(); |
| | | String value = historyFiveMinutely.getValue(); |
| | | Map map = JSON.parseObject(value, Map.class); |
| | | map1.put("时间",DateUtils.dateToDateString(historyFiveMinutely.getTime())); |
| | | map1.put("pm25",ObjectUtils.isEmpty(map.get("a34004"))?0:map.get("a34004")); |
| | | map1.put("pm10",ObjectUtils.isEmpty(map.get("a34002"))?0:map.get("a34002")); |
| | | map1.put("二氧化氮",ObjectUtils.isEmpty(map.get("a21004"))?0:map.get("a21004")); |
| | | map1.put("二氧化硫",ObjectUtils.isEmpty(map.get("a21026"))?0:map.get("a21026")); |
| | | map1.put("一氧化碳",ObjectUtils.isEmpty(map.get("a21005"))?0:map.get("a21005")); |
| | | map1.put("气压",ObjectUtils.isEmpty(map.get("a01006"))?0:map.get("a01006")); |
| | | map1.put("温度",ObjectUtils.isEmpty(map.get("a01001"))?0:map.get("a01001")); |
| | | map1.put("湿度",ObjectUtils.isEmpty(map.get("a01002"))?0:map.get("a01002")); |
| | | map1.put("tvoc",ObjectUtils.isEmpty(map.get("a99054"))?0:map.get("a99054")); |
| | | map1.put("甲醛",ObjectUtils.isEmpty(map.get("a31001"))?0:map.get("a31001")); |
| | | map1.put("硫化氢",ObjectUtils.isEmpty(map.get("a21028"))?0:map.get("a21028")); |
| | | map1.put("氨气",ObjectUtils.isEmpty(map.get("a21001"))?0:map.get("a21001")); |
| | | rsMap.add(map1); |
| | | } |
| | | } |
| | | return rsMap; |
| | | } |
| | | |
| | | |
| | | private HandDevice getHand(HandDevice handDevice){ |
| | | HandDevice rsHandDevice = new HandDevice(); |
| | | rsHandDevice.setName(handDevice.getName()); |
| | | rsHandDevice.setMac(handDevice.getMac()); |
| | | rsHandDevice.setAddress(handDevice.getAddress()); |
| | | rsHandDevice.setLatitude(handDevice.getLatitude()); |
| | | rsHandDevice.setLongitude(handDevice.getLongitude()); |
| | | rsHandDevice.setIsDelete(Constants.NOT_DELETE); |
| | | rsHandDevice.setStartTime(new Date()); |
| | | rsHandDevice.setUpdateTime(new Date()); |
| | | rsHandDevice.setCreateTime(new Date()); |
| | | rsHandDevice.setState("1"); |
| | | return rsHandDevice; |
| | | } |
| | | |
| | | |
| | | } |