|  |  | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; | 
 |  |  | import com.moral.api.entity.Device; | 
 |  |  | import com.moral.api.entity.OrganizationLayout; | 
 |  |  | import com.moral.api.mapper.DeviceMapper; | 
 |  |  | import com.moral.api.mapper.OrganizationLayoutMapper; | 
 |  |  | import com.moral.api.service.OrganizationLayoutService; | 
 |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
 |  |  | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletRequest; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Autowired(required = false) | 
 |  |  |     private OrganizationLayoutMapper organizationLayoutMapper; | 
 |  |  |  | 
 |  |  |     @Autowired(required = false) | 
 |  |  |     private DeviceMapper deviceMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private LogUtils logUtils; | 
 |  |  | 
 |  |  |                 content = content +organizationLayout.getId()+" "; | 
 |  |  |             } | 
 |  |  |             content = content+";"; | 
 |  |  |             logUtils.saveOperationForManage(request,content,Constants.INSERT_OPERATE_TYPE); | 
 |  |  |             logUtils.saveOperationForManage(request,content,Constants.DELETE_OPERATE_TYPE); | 
 |  |  |         } | 
 |  |  |         if (!ObjectUtils.isEmpty(list) && list.size()>0){ | 
 |  |  |             organizationLayoutMapper.insertList(list); | 
 |  |  | 
 |  |  |             logUtils.saveOperationForManage(request,contentInsert,Constants.INSERT_OPERATE_TYPE); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional | 
 |  |  |     @Override | 
 |  |  |     public Map<String, Object> getLayoutByMac(String mac) { | 
 |  |  |         QueryWrapper<Device> wrapper_device = new QueryWrapper<>(); | 
 |  |  |         wrapper_device.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         wrapper_device.eq("mac",mac); | 
 |  |  |         Device device = deviceMapper.selectOne(wrapper_device); | 
 |  |  |         if (ObjectUtils.isEmpty(device)){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         int organizationId = device.getOrganizationId(); | 
 |  |  |         int versionId = device.getDeviceVersionId(); | 
 |  |  |         QueryWrapper<OrganizationLayout> wrapper_organizationLayout = new QueryWrapper<>(); | 
 |  |  |         wrapper_organizationLayout.eq("organization_id",organizationId); | 
 |  |  |         wrapper_organizationLayout.eq("version_id",versionId); | 
 |  |  |         wrapper_organizationLayout.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         List<OrganizationLayout> organizationLayouts = organizationLayoutMapper.selectList(wrapper_organizationLayout); | 
 |  |  |         if (ObjectUtils.isEmpty(organizationLayouts) || organizationLayouts.size()==0){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         Map<String, Object> resultMap = new HashMap<>(); | 
 |  |  |         List<OrganizationLayout> chartSensorKeyList = new ArrayList<>(); | 
 |  |  |         List<OrganizationLayout> coreMonitorItemsList = new ArrayList<>(); | 
 |  |  |         List<OrganizationLayout> defaultMonitorItemsList = new ArrayList<>(); | 
 |  |  |         List<OrganizationLayout> fixedMonitorItemsList = new ArrayList<>(); | 
 |  |  |         for (OrganizationLayout organizationgLayout:organizationLayouts) { | 
 |  |  |             if (organizationgLayout.getPosition().equals("chartSensorKey")){ | 
 |  |  |                 chartSensorKeyList.add(organizationgLayout); | 
 |  |  |             } | 
 |  |  |             if (organizationgLayout.getPosition().equals("coreMonitorItems")){ | 
 |  |  |                 coreMonitorItemsList.add(organizationgLayout); | 
 |  |  |             } | 
 |  |  |             if (organizationgLayout.getPosition().equals("defaultMonitorItems")){ | 
 |  |  |                 defaultMonitorItemsList.add(organizationgLayout); | 
 |  |  |             } | 
 |  |  |             if (organizationgLayout.getPosition().equals("fixedMonitorItems")){ | 
 |  |  |                 fixedMonitorItemsList.add(organizationgLayout); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         chartSensorKeyList = sort(chartSensorKeyList); | 
 |  |  |         coreMonitorItemsList = sort(coreMonitorItemsList); | 
 |  |  |         defaultMonitorItemsList = sort(defaultMonitorItemsList); | 
 |  |  |         fixedMonitorItemsList = sort(fixedMonitorItemsList); | 
 |  |  |         resultMap.put("chartSensorKey",chartSensorKeyList); | 
 |  |  |         resultMap.put("coreMonitorItems",coreMonitorItemsList); | 
 |  |  |         resultMap.put("defaultMonitorItems",defaultMonitorItemsList); | 
 |  |  |         resultMap.put("fixedMonitorItems",fixedMonitorItemsList); | 
 |  |  |         return resultMap; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private List<OrganizationLayout> sort(List<OrganizationLayout> list){ | 
 |  |  |         if (list.size() < 0){ | 
 |  |  |             return list; | 
 |  |  |         } | 
 |  |  |         OrganizationLayout temp = null; | 
 |  |  |         int j; | 
 |  |  |         for (int i = 1; i<list.size(); i++){ | 
 |  |  |             temp = list.get(i); | 
 |  |  |             for (j=i-1; j>=0; j--){ | 
 |  |  |                 if (list.get(j).getPositionIndex()>temp.getPositionIndex()){ | 
 |  |  |                     list.set(j+1,list.get(j)); | 
 |  |  |                 }else { | 
 |  |  |                     break; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             System.out.println(list.get(0)); | 
 |  |  |             list.set(j+1,temp); | 
 |  |  |         } | 
 |  |  |         return list; | 
 |  |  |     } | 
 |  |  | } |