| | |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.DeviceDto; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.DeviceMapper; |
| | | import com.yuanchu.mom.mapper.StructureItemParameterMapper; |
| | | import com.yuanchu.mom.pojo.DataConfig; |
| | | import com.yuanchu.mom.pojo.Device; |
| | | import com.yuanchu.mom.pojo.StructureItemParameter; |
| | | import com.yuanchu.mom.service.DataConfigService; |
| | | import com.yuanchu.mom.service.DeviceService; |
| | | import com.yuanchu.mom.utils.DataAcquisition; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | private StructureItemParameterMapper structureItemParameterMapper; |
| | | |
| | | @Autowired |
| | | private DataConfigService dataConfigService; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectDeviceParameter(Page page, DeviceDto itemParameter) { |
| | |
| | | public Device selectDeviceByCode(String code) { |
| | | return deviceMapper.selectOne(Wrappers.<Device>lambdaQuery().eq(Device::getFactoryNo, code).last("limit 1")); |
| | | } |
| | | } |
| | | |
| | | @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; |
| | | List<Device> device = baseMapper.selectList(Wrappers.<Device>lambdaQuery() |
| | | .eq(Device::getIp, ip)); |
| | | 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)); |
| | | }); |
| | | String frequency = DataAcquisition.createFrequency(entrustCode, sampleCode); |
| | | hashMap.put("frequency", frequency); |
| | | return Result.success(hashMap); |
| | | } |
| | | } |