| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private GetLook getLook; |
| | | |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | private StructureItemParameterMapper structureItemParameterMapper; |
| | | |
| | | @Autowired |
| | | private DataConfigService dataConfigService; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectDeviceParameter(Page page, DeviceDto itemParameter) { |
| | |
| | | return deviceMapper.deleteById(id); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public int upDeviceParameter(Device itemParameter) { |
| | | // 删除数采集配置数据 |
| | | dataConfigService.deleteDataConfig(); |
| | | return deviceMapper.updateById(itemParameter); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Device> selectDeviceByCategory(String category) { |
| | | return deviceMapper.selectList(Wrappers.<Device>lambdaQuery().eq(Device::getLargeCategory, category).eq(Device::getDeviceStatus, 0)); |
| | | public List<Device> selectDeviceByCategory(String inspectionItem, String inspectionItemSubclass) { |
| | | Integer id; |
| | | try { |
| | | if (ObjectUtils.isEmpty(inspectionItemSubclass)) { |
| | | id = structureItemParameterMapper.selectOne(Wrappers.<StructureItemParameter>lambdaQuery() |
| | | .eq(StructureItemParameter::getInspectionItem, inspectionItem) |
| | | .last("limit 1").select(StructureItemParameter::getId)).getId(); |
| | | }else { |
| | | id = structureItemParameterMapper.selectOne(Wrappers.<StructureItemParameter>lambdaQuery() |
| | | .eq(StructureItemParameter::getInspectionItem, inspectionItem) |
| | | .eq(StructureItemParameter::getInspectionItemSubclass, inspectionItemSubclass) |
| | | .last("limit 1").select(StructureItemParameter::getId)).getId(); |
| | | } |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | List<Device> devices = deviceMapper.selectList(Wrappers.<Device>lambdaQuery() |
| | | .eq(Device::getDeviceStatus, 0) |
| | | .isNotNull(Device::getInsProductIds)); |
| | | List<Device> devices2 = new ArrayList<>(); |
| | | for (Device device : devices) { |
| | | String[] ids = device.getInsProductIds().split(","); |
| | | for (String i : ids) { |
| | | if (i.equals(id + "")) { |
| | | devices2.add(device); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return devices2; |
| | | } |
| | | |
| | | @Override |
| | | 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) { |
| | | // 防止回环地址变为IPv6 |
| | | 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<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); |
| | | }); |
| | | 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); |
| | | } |
| | | } |
| | | |