添加流量计设备实时数据相关接口以及定时任务,统计流量计设备在线数量等

This commit is contained in:
蒾酒
2024-12-30 02:54:13 +08:00
parent 3aac79e169
commit b590dfa9fa
20 changed files with 855 additions and 28 deletions

View File

@ -35,6 +35,7 @@ import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -61,7 +62,7 @@ public class DeviceController extends BaseController {
private DeviceMapper deviceMapper;
@Autowired
private IDeviceDetailService deviceDetailService;
// @Lazy
@Lazy
@Autowired
private IMqttMessagePublish messagePublish;

View File

@ -88,9 +88,15 @@ public class DeviceReportInfoController extends BaseController
List<DeviceReportInfo> list = deviceReportInfoService.selectDeviceReportInfoList(deviceReportInfo);
AtomicInteger onLineTotal= new AtomicInteger();
list.forEach(d->{
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("neixiang_device_online_status:" + 147 + ":" + d.getSerialNumber())))
{
onLineTotal.getAndIncrement();
if(d.getType()==1){
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("neixiang_device_online_status:" + 147 + ":" + d.getSerialNumber())))
{
onLineTotal.getAndIncrement();
}
} else if ( d.getType()==2) {
if(d.getOnLine()==1){
onLineTotal.getAndIncrement();
}
}
});
Map<String,Object> resp=new HashMap<>();

View File

@ -0,0 +1,107 @@
package com.fastbee.data.controller.userRecharge;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.iot.domain.NgFlowDeviceData;
import com.fastbee.iot.service.INgFlowDeviceDataService;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.common.core.page.TableDataInfo;
/**
* 流量计设备数据Controller
*
* @author kerwincui
* @date 2024-12-30
*/
@RestController
@RequestMapping("/rechargecard/flow/data")
@Api(tags = "流量计设备数据")
public class NgFlowDeviceDataController extends BaseController
{
@Autowired
private INgFlowDeviceDataService ngFlowDeviceDataService;
/**
* 查询流量计设备数据列表
*/
// @PreAuthorize("@ss.hasPermi('rechargecard:data:list')")
@GetMapping("/list")
@ApiOperation("查询流量计设备数据列表")
public TableDataInfo list(NgFlowDeviceData ngFlowDeviceData)
{
startPage();
List<NgFlowDeviceData> list = ngFlowDeviceDataService.selectNgFlowDeviceDataList(ngFlowDeviceData);
return getDataTable(list);
}
/**
* 导出流量计设备数据列表
*/
@ApiOperation("导出流量计设备数据列表")
// @PreAuthorize("@ss.hasPermi('rechargecard:data:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, NgFlowDeviceData ngFlowDeviceData)
{
List<NgFlowDeviceData> list = ngFlowDeviceDataService.selectNgFlowDeviceDataList(ngFlowDeviceData);
ExcelUtil<NgFlowDeviceData> util = new ExcelUtil<NgFlowDeviceData>(NgFlowDeviceData.class);
util.exportExcel(response, list, "流量计设备数据数据");
}
/**
* 获取流量计设备数据详细信息
*/
// @PreAuthorize("@ss.hasPermi('rechargecard:data:query')")
@GetMapping(value = "/{id}")
@ApiOperation("获取流量计设备数据详细信息")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(ngFlowDeviceDataService.selectNgFlowDeviceDataById(id));
}
/**
* 新增流量计设备数据
*/
// @PreAuthorize("@ss.hasPermi('rechargecard:data:add')")
@PostMapping
@ApiOperation("新增流量计设备数据")
public AjaxResult add(@RequestBody NgFlowDeviceData ngFlowDeviceData)
{
return toAjax(ngFlowDeviceDataService.insertNgFlowDeviceData(ngFlowDeviceData));
}
/**
* 修改流量计设备数据
*/
// @PreAuthorize("@ss.hasPermi('rechargecard:data:edit')")
@PutMapping
@ApiOperation("修改流量计设备数据")
public AjaxResult edit(@RequestBody NgFlowDeviceData ngFlowDeviceData)
{
return toAjax(ngFlowDeviceDataService.updateNgFlowDeviceData(ngFlowDeviceData));
}
/**
* 删除流量计设备数据
*/
// @PreAuthorize("@ss.hasPermi('rechargecard:data:remove')")
@DeleteMapping("/{ids}")
@ApiOperation("删除流量计设备数据")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(ngFlowDeviceDataService.deleteNgFlowDeviceDataByIds(ids));
}
}

View File

@ -50,8 +50,8 @@ public class NgUserRechargeRecordsController extends BaseController
startPage();
List<NgUserRechargeRecords> list = ngUserRechargeRecordsService.selectNgUserRechargeRecordsList(ngUserRechargeRecords);
//按照充值时间由近到远排序
list.sort(Comparator.comparing(NgUserRechargeRecords::getRechargeTime).reversed());
System.err.println("充值list = " + list);
// list.sort(Comparator.comparing(NgUserRechargeRecords::getRechargeTime).reversed());
// System.err.println("充值list = " + list);
return getDataTable(list);
}

View File

@ -12,8 +12,11 @@ import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* @author mijiupro
*/
@Component("zhanLianBaseService1")
public class ZhanLianBaseService {
public class ZhanLianBaseService1 {
@Autowired
private ZhanLianAuthorizationService authorizationService;
@ -28,7 +31,7 @@ public class ZhanLianBaseService {
*/
public JSONObject baseRequest(Map<String,Object> body){
String jsonStr = JSONUtil.toJsonStr(body);
String respStr = HttpUtil.post(authorizationService.getAuthEndpoint(), jsonStr);
String respStr = HttpUtil.post(new ZhanLianAuthorizationService().getAuthEndpoint(), jsonStr);
JSONObject resp = JSONUtil.parseObj(respStr);
System.err.println(resp);
if(!resp.get("code").toString().equals("200")){
@ -56,6 +59,19 @@ public class ZhanLianBaseService {
return baseRequest(body);
}
/**
* 请求设备统计数据
* @return 统计数据
*/
private JSONObject requestDeviceCount() {
HashMap<String, Object> body = new HashMap<>();
body.put("method","get");
body.put("path","/api/v1/product/device/statistics");
Map<String,Object> params=new HashMap<>();
body.put("params",params);
return baseRequest(body);
}
/**
@ -85,29 +101,29 @@ public class ZhanLianBaseService {
//属性key
String key = propertyMap.get("key").toString();
//属性值
Object value1 = JSONUtil.parseObj(p).get("value");
String value1 = JSONUtil.parseObj(p).getStr("value");
String value="" ;
if(value1!=null){
value = value1.toString();
value = value1;
}
//TODO 属性值历史数据是否需要
Object list = JSONUtil.parseObj(p).get("list");
// Object list = JSONUtil.parseObj(p).get("list");
//建立属性-值映射关系
propertiesMap.put(key,value);
});
//在线状态
propertiesMap.put("status",status.toString());
//设备id
propertiesMap.put("deviceId",deviceId);
//上报时间
propertiesMap.put("realTime",time);
return propertiesMap;
}
public BigDecimal toBigDecimalValue(String str) {
if (str == null|| str.isEmpty()) {
return null;
@ -121,4 +137,9 @@ public class ZhanLianBaseService {
return Long.parseLong(str);
}
public static void main(String[] args) {
ZhanLianBaseService1 zhanLianBaseService = new ZhanLianBaseService1();
Map<String, String> deviceRealTimeData = zhanLianBaseService.getDeviceRealTimeData("3849");
System.err.println(deviceRealTimeData);
}
}

View File

@ -2,9 +2,7 @@ package com.fastbee.data.controller.userRecharge.zhanLian;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.fastbee.common.core.domain.AjaxResultPro;
import com.fastbee.rechargecard.domain.NgUserRechargeRecords;
import com.fastbee.rechargecard.domain.NgWaterPumpUsageRecords;
import com.fastbee.rechargecard.mapper.NgWaterPumpUsageRecordsMapper;
import io.swagger.annotations.Api;
@ -12,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Comparator;
@ -29,7 +26,7 @@ import java.util.Map;
public class ZhanLianFlowDeviceDataController {
@Autowired
private ZhanLianBaseService zhanLianBaseService;
private ZhanLianBaseService1 zhanLianBaseService;
@Autowired
private NgWaterPumpUsageRecordsMapper ngWaterPumpUsageRecordsMapper;

View File

@ -44,6 +44,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -61,6 +62,7 @@ public class DeviceMessageServiceImpl implements IDeviceMessageService {
@Resource
private ModbusEncoder modbusMessageEncoder;
@Resource
@Lazy
private IDeviceService deviceService;
@Resource
private TopicsUtils topicsUtils;