package com.moral.service.impl; import com.moral.entity.OrganizationSensorUnit; import com.moral.entity.Sensor; import com.moral.entity.SensorUnit; import com.moral.mapper.OrganizationSensorUnitMapper; import com.moral.mapper.SensorMapper; import com.moral.service.OrganizationSensorUnitService; import org.springframework.data.annotation.Transient; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; @Service public class OrganizationSensorUnitServiceImpl implements OrganizationSensorUnitService{ @Resource OrganizationSensorUnitMapper osuMapper; @Resource SensorMapper sensorMapper; /** * 获取所有传感器单位对应关系 * @param organizationId * @return */ @Override public List queryAllByOrgId(Integer organizationId) { // 获取当前组织下所有传感器 List sensorList = sensorMapper.selectByOrgId(organizationId); // 获取单位组织对应关系拉出单位数据 List organizationSensorUnits = osuMapper.selectByOrgId(organizationId); List returnList = new ArrayList<>(); for (int index=0;index queryByOrgId(Integer organizationId) { return osuMapper.selectByOrgId(organizationId); } @Override @Transient public void addsOrModifys(List osuList) { osuList.forEach( item -> { if(item.getId() != null) { if(item.getSensorUnitId() == null) { osuMapper.deleteByPrimaryKey(item); }else { osuMapper.updateByPrimaryKeySelective(item); } }else{ item.setCreateTime(new Date()); osuMapper.insertSelective(item); } } ); } }