| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | |
| | | return deviceMapper.deleteById(id); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public int upDeviceParameter(Device itemParameter) { |
| | | // 删除数采集配置数据 |
| | | dataConfigService.deleteDataConfig(); |
| | | return deviceMapper.updateById(itemParameter); |
| | | } |
| | | |
| | |
| | | String[] ids = device.getInsProductIds().split(","); |
| | | for (String i : ids) { |
| | | if (i.equals(id + "")) { |
| | | if (ObjectUtils.isEmpty(device.getFileType()) || ObjectUtils.isEmpty(device.getCollectUrl())) { |
| | | device.setIsItADataAcquisitionDevice(false); |
| | | } else { |
| | | device.setIsItADataAcquisitionDevice(true); |
| | | } |
| | | devices2.add(device); |
| | | break; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public Result<?> dataAcquisition(HttpServletRequest request, Integer id, String entrustCode, String sampleCode) { |
| | | String ipAddress = request.getRemoteAddr(); |
| | | // 防止回环地址变为IPv6 |
| | | String ip = ipAddress.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ipAddress; |
| | | String ip = DataAcquisition.getIp(request); |
| | | List<Device> device = baseMapper.selectList(Wrappers.<Device>lambdaQuery() |
| | | .eq(Device::getIp, ip)); |
| | | if(device.size() > 1) { |
| | | String str = ""; |
| | | for (Device device1 : device) { |
| | | str += device1.getDeviceName() + ","; |
| | | } |
| | | throw new ErrorException("IP:" + ip + "配置了设备多个设备:" + str + ",无法进行数采!"); |
| | | } |
| | | if (ObjectUtils.isEmpty(device)) { |
| | | throw new ErrorException("未给该IP:" + ip + "配置设备,无法进行数采!"); |
| | | } |
| | | List<String> inspectionItemSubclass = baseMapper.getInspectionItemSubclass(id); |
| | | Map<String, String> hashMap = new HashMap<>(); |
| | | device.forEach(i -> { |
| | | if (ObjectUtils.isEmpty(i.getFileType()) || ObjectUtils.isEmpty(i.getCollectUrl())) { |
| | | throw new ErrorException("未给该:" + i.getDeviceName() + "设备配置采集路径或文件后缀!"); |
| | | } |
| | | List<DataConfig> list = dataConfigService.list(Wrappers.<DataConfig>lambdaQuery() |
| | | .eq(DataConfig::getDeviceId, i.getId()) |
| | | .in(DataConfig::getInsProductItem, inspectionItemSubclass) |
| | | .orderBy(false, false, DataConfig::getId)); |
| | | hashMap.putAll(DataAcquisition.dataAcquisitionEntrance(request, list, i, entrustCode, sampleCode, ip)); |
| | | List<Map<String, Object>> inspectionItemSubclass = baseMapper.getInspectionItemSubclass(id); |
| | | if (ObjectUtils.isEmpty(device.get(0).getFileType()) || ObjectUtils.isEmpty(device.get(0).getCollectUrl())) { |
| | | throw new ErrorException("未给该:" + device.get(0).getDeviceName() + "设备配置采集路径或文件后缀!"); |
| | | } |
| | | List<DataConfig> list1 = new ArrayList<>(); |
| | | inspectionItemSubclass.forEach(i -> { |
| | | List<DataConfig> list = dataConfigService.list(Wrappers.<DataConfig>lambdaQuery() |
| | | .eq(DataConfig::getDeviceId, device.get(0).getId()) |
| | | .eq(DataConfig::getInspectionItem, i.get("inspection_item")) |
| | | .eq(DataConfig::getInspectionItemSubclass, i.get("inspection_item_subclass")) |
| | | .orderBy(false, false, DataConfig::getId)); |
| | | list1.addAll(list); |
| | | }); |
| | | String frequency = DataAcquisition.createFrequency(entrustCode, sampleCode); |
| | | hashMap.put("frequency", frequency); |
| | | return Result.success(hashMap); |
| | | Map<String, String> map = DataAcquisition.dataAcquisitionEntrance(list1, device.get(0), entrustCode, sampleCode, ip); |
| | | if (ObjectUtils.isNotEmpty(map)) { |
| | | String frequency = DataAcquisition.createFrequency(entrustCode, sampleCode); |
| | | map.put("frequency", frequency); |
| | | } |
| | | return Result.success(map); |
| | | } |
| | | } |