|
|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
*/ |
|
|
|
|
package org.springblade.desk.quality.controller; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
|
@ -26,6 +27,8 @@ import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.desk.basic.util.ExcelExtUtil; |
|
|
|
|
import org.springblade.desk.device.pojo.entity.EquipmentEntity; |
|
|
|
|
import org.springblade.desk.device.service.IEquipmentService; |
|
|
|
|
import org.springblade.desk.quality.constant.QAModuleConst; |
|
|
|
|
import org.springblade.desk.quality.excel.IotHardnessExcel; |
|
|
|
|
import org.springblade.desk.quality.pojo.entity.IotHardness; |
|
|
|
|
@ -33,10 +36,14 @@ import org.springblade.desk.quality.pojo.vo.IotHardnessVO; |
|
|
|
|
import org.springblade.desk.quality.service.IIotHardnessService; |
|
|
|
|
import org.springblade.desk.quality.wrapper.IotHardnessWrapper; |
|
|
|
|
import org.springblade.system.feign.IUserClient; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import java.net.InetAddress; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
@ -62,6 +69,9 @@ public class IotHardnessController extends BladeController { |
|
|
|
|
@Resource |
|
|
|
|
private IUserClient iUserClient; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IEquipmentService equipmentService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* [IOT硬度] 详情 |
|
|
|
|
*/ |
|
|
|
|
@ -94,6 +104,129 @@ public class IotHardnessController extends BladeController { |
|
|
|
|
return R.data(pagesVO); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/queryHardnessData") |
|
|
|
|
public R queryHardnessData() throws Exception { |
|
|
|
|
InetAddress inetAddress = InetAddress.getLocalHost(); |
|
|
|
|
String ip = inetAddress.getHostAddress(); |
|
|
|
|
// ip = "127.0.0.1";
|
|
|
|
|
|
|
|
|
|
QueryWrapper<EquipmentEntity> qw = new QueryWrapper<>(); |
|
|
|
|
qw.eq("DEVICE_IP",ip); |
|
|
|
|
EquipmentEntity card = equipmentService.getOne(qw); |
|
|
|
|
//根据ip查询设备
|
|
|
|
|
if (card == null) { |
|
|
|
|
return R.fail(-2, "ip未找到对应的测量仪设备!" + ip); |
|
|
|
|
} |
|
|
|
|
String deviceCode = card.getDeviceCode(); |
|
|
|
|
log.info("找到设备,设备编码: {}", deviceCode); |
|
|
|
|
|
|
|
|
|
// 首次查询:无时间标记,设置初始标记为当前时间
|
|
|
|
|
// if (timeMarker == null) {
|
|
|
|
|
// timeMarker = new Date();
|
|
|
|
|
// log.info("首次查询,初始时间标记: {}", timeMarker);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 调用服务层方法查询未读数据
|
|
|
|
|
// 修改服务层方法,使其根据设备编码和未读状态查询
|
|
|
|
|
|
|
|
|
|
QueryWrapper<IotHardness> qwhard = new QueryWrapper<>(); |
|
|
|
|
qwhard.eq("EQUIPMENT_ID",card.getId()); |
|
|
|
|
// qwhard.eq("FLAG_READ",0);
|
|
|
|
|
qwhard.orderByDesc("CREATE_TIME"); |
|
|
|
|
List<IotHardness> qcHardnessIotList = service.list(qwhard); |
|
|
|
|
|
|
|
|
|
// 记录查询到的数据数量
|
|
|
|
|
if (qcHardnessIotList != null) { |
|
|
|
|
log.info("查询到 {} 条硬度数据", qcHardnessIotList.size()); |
|
|
|
|
} else { |
|
|
|
|
log.info("未查询到硬度数据"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
boolean hasNewData = qcHardnessIotList != null && !qcHardnessIotList.isEmpty(); |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
List<JSONObject> resultList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
if (hasNewData) { |
|
|
|
|
log.info("设备[{}]查询到 {} 条新数据", deviceCode, qcHardnessIotList.size()); |
|
|
|
|
for (IotHardness iot : qcHardnessIotList) { |
|
|
|
|
if(null != iot.getData()){ |
|
|
|
|
resultList.add(JSONObject.parseObject(iot.getData())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
iot.setFlagRead(1L); |
|
|
|
|
service.updateById(iot); |
|
|
|
|
} |
|
|
|
|
// 查到数据后,重置标记(返回null,前端下次请求不带标记)
|
|
|
|
|
// timeMarker = null;
|
|
|
|
|
} else { |
|
|
|
|
log.info("设备[{}]未查询到新数据", deviceCode); |
|
|
|
|
} |
|
|
|
|
return R.data(resultList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private R getHardnessData(JSONObject data, HttpServletRequest request) throws Exception { |
|
|
|
|
// LoginInfo loginUser = ControllerUtils.getCurLoginInfo(request);
|
|
|
|
|
// String ip = loginUser.getLoginIp();
|
|
|
|
|
|
|
|
|
|
InetAddress inetAddress = InetAddress.getLocalHost(); |
|
|
|
|
String ip = inetAddress.getHostAddress(); |
|
|
|
|
// ip = "127.0.0.1";
|
|
|
|
|
|
|
|
|
|
QueryWrapper<EquipmentEntity> qw = new QueryWrapper<>(); |
|
|
|
|
qw.eq("DEVICE_IP",ip); |
|
|
|
|
EquipmentEntity card = equipmentService.getOne(qw); |
|
|
|
|
//根据ip查询设备
|
|
|
|
|
if (card == null) { |
|
|
|
|
return R.fail(-2, "ip未找到对应的测量仪设备!" + ip); |
|
|
|
|
} |
|
|
|
|
String deviceCode = card.getDeviceCode(); |
|
|
|
|
log.info("找到设备,设备编码: {}", deviceCode); |
|
|
|
|
|
|
|
|
|
// 首次查询:无时间标记,设置初始标记为当前时间
|
|
|
|
|
// if (timeMarker == null) {
|
|
|
|
|
// timeMarker = new Date();
|
|
|
|
|
// log.info("首次查询,初始时间标记: {}", timeMarker);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 调用服务层方法查询未读数据
|
|
|
|
|
// 修改服务层方法,使其根据设备编码和未读状态查询
|
|
|
|
|
|
|
|
|
|
QueryWrapper<IotHardness> qwhard = new QueryWrapper<>(); |
|
|
|
|
qwhard.eq("EQUIPMENT_ID",card.getId()); |
|
|
|
|
// qwhard.eq("FLAG_READ",0);
|
|
|
|
|
qwhard.orderByDesc("CREATE_TIME"); |
|
|
|
|
List<IotHardness> qcHardnessIotList = service.list(qwhard); |
|
|
|
|
|
|
|
|
|
// 记录查询到的数据数量
|
|
|
|
|
if (qcHardnessIotList != null) { |
|
|
|
|
log.info("查询到 {} 条硬度数据", qcHardnessIotList.size()); |
|
|
|
|
} else { |
|
|
|
|
log.info("未查询到硬度数据"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
boolean hasNewData = qcHardnessIotList != null && !qcHardnessIotList.isEmpty(); |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
List<JSONObject> resultList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
if (hasNewData) { |
|
|
|
|
log.info("设备[{}]查询到 {} 条新数据", deviceCode, qcHardnessIotList.size()); |
|
|
|
|
for (IotHardness iot : qcHardnessIotList) { |
|
|
|
|
if(null != iot.getData()){ |
|
|
|
|
resultList.add(JSONObject.parseObject(iot.getData())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
iot.setFlagRead(1L); |
|
|
|
|
service.updateById(iot); |
|
|
|
|
} |
|
|
|
|
// 查到数据后,重置标记(返回null,前端下次请求不带标记)
|
|
|
|
|
// timeMarker = null;
|
|
|
|
|
} else { |
|
|
|
|
log.info("设备[{}]未查询到新数据", deviceCode); |
|
|
|
|
} |
|
|
|
|
return R.data(resultList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/getDataFirst") |
|
|
|
|
@ApiOperationSupport(order = 20) |
|
|
|
|
|