/**
* 获取属性名数组
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* */
private static String[] getFiledName(Object o) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
Field[] fields=o.getClass().getDeclaredFields();
String[] fieldNames=new String[fields.length];
for(int i=0;i<fields.length;i++){
// System.out.println(fields[i].getName());
String type = fields[i].getGenericType().toString();
// System.out.println(type);
Method m = o.getClass().getMethod("get" + fields[i].getName());
// 调用getter方法获取属性值
// if (m.invoke(o) != null) {
// System.out.println("属性值为:" + m.invoke(o));
// } else {
// System.out.println("属性值为:空");
// }
if(type.equals("class java.lang.Float")||fields[i].getName().equals("EMPLOY_NUM")) {
fieldNames[i]=fields[i].getName()+":"+m.invoke(o);
}
}
return fieldNames;
}
public List<PaRpt> convertTotalProfitRpt(List<TotalProfitRpt> rpts,String RPT_TYPE) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
if(rpts.size()>0) {
List<PaRpt> paRptList = new ArrayList<PaRpt>();
for(TotalProfitRpt rpt :rpts) {
List<PaRpt> paRpts = splitTotalProfitRpt(rpt,RPT_TYPE);
paRptList.addAll(paRpts);
}
return paRptList;
}else {
return null;
}
}
/**
*对象切割
*/
public List<PaRpt> splitTotalProfitRpt(TotalProfitRpt rpt,String RPT_TYPE) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
List<PaRpt> paRpts = new ArrayList<PaRpt>();
String [] files = getFiledName(rpt);
for (int i = 0; i < files.length; i++) {
PaRpt p= new PaRpt();
p.setCOMPANY_ID(rpt.getCOMPANY_ID());
p.setCOUNTRY_CODE(rpt.getCOUNTRY_CODE());
p.setBRANCH_NO(rpt.getBRANCH_NO());
p.setDISTRICT_NO(rpt.getDISTRICT_NO());
p.setFPERIOD(rpt.getFPERIOD());
p.setRPT_TYPE(RPT_TYPE);
if(!NullUtil.isNull(files[i])) {
p.setITEM_NO(files[i].split(":")[0]);
p.setFVALUE(Float.valueOf(files[i].split(":")[1]));
paRpts.add(p);
}
}
return paRpts;
}