字段顺序排序

master
lulicheng 8 months ago
parent afd23cdf12
commit 9881269076

@ -10,6 +10,7 @@ import com.ipsplm.service.simulation.ISimulationAnalysisService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.*; import java.util.*;
/** /**
@ -157,20 +158,28 @@ public class SimulationAnalysisServiceImpl implements ISimulationAnalysisService
*/ */
public List<OeeVO> beanToKeyValue(List oeeList) { public List<OeeVO> beanToKeyValue(List oeeList) {
List<OeeVO> oeeVOList = new ArrayList<>(); List<OeeVO> oeeVOList = new ArrayList<>();
//通过反射获取字段
Class<?> clazz = oeeList.get(0).getClass();
Field[] fields = clazz.getDeclaredFields();
for (Object object : oeeList) { for (Object object : oeeList) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(object); JSONObject jsonObject = (JSONObject) JSON.toJSON(object);
Object status = jsonObject.get("status"); Object status = jsonObject.get("status");
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
OeeVO oeeVO = new OeeVO(); // 按字段顺序处理
Object value = entry.getValue(); for (Field field : fields) {
String key = entry.getKey(); String key = field.getName();
if ("flag".equals(key) || "id".equals(key) || "status".equals(key)) { if ("flag".equals(key) || "id".equals(key) || "status".equals(key)) {
continue; continue;
} }
oeeVO.setName(key);
oeeVO.setValue(value); if (jsonObject.containsKey(key)) {
oeeVO.setStatus(status); OeeVO oeeVO = new OeeVO();
oeeVOList.add(oeeVO); oeeVO.setName(key);
oeeVO.setValue(jsonObject.get(key));
oeeVO.setStatus(status);
oeeVOList.add(oeeVO);
}
} }
} }
return oeeVOList; return oeeVOList;

Loading…
Cancel
Save