public List findApprList(Map param) {
List<Map<String, Object>> _resultList = Lists.newArrayList();
List<Map<String, Object>> _aprvList = reportMDAO.selectApprList(param);
// 결재라인보기
if ("Y".equals(param.get("isMulti")))
{
for (Map<String, Object> _item : _aprvList)
{
_item.put("no" , 1);
_item.put("aprv_rqst_usr" , _item.get("usr_nm_01"));
_item.put("aprv_line_01" , _item.get("usr_nm_02"));
_item.put("aprv_line_02" , _item.get("usr_nm_03"));
_item.put("aprv_line_03" , _item.get("usr_nm_04"));
_item.put("aprv_line_04" , _item.get("usr_nm_05"));
_item.put("aprv_line_05" , _item.get("usr_nm_06"));
_item.put("aprv_line_06" , _item.get("usr_nm_07"));
_item.put("aprv_line_07" , _item.get("usr_nm_08"));
_item.put("aprv_line_08" , _item.get("usr_nm_09"));
_item.put("aprv_line_09" , _item.get("usr_nm_10"));
_item.put("aprv_line_10" , _item.get("usr_nm_11"));
_resultList.add(_item);
Map<String, Object> _item2 = Maps.newHashMap();
_item2.putAll(_item);
_item2.put("no" , 2);
_item2.put("aprv_rqst_usr" , _item.get("aprvemp_posnm_01"));
_item2.put("aprv_line_01" , _item.get("aprvemp_posnm_02"));
_item2.put("aprv_line_02" , _item.get("aprvemp_posnm_03"));
_item2.put("aprv_line_03" , _item.get("aprvemp_posnm_04"));
_item2.put("aprv_line_04" , _item.get("aprvemp_posnm_05"));
_item2.put("aprv_line_05" , _item.get("aprvemp_posnm_06"));
_item2.put("aprv_line_06" , _item.get("aprvemp_posnm_07"));
_item2.put("aprv_line_07" , _item.get("aprvemp_posnm_08"));
_item2.put("aprv_line_08" , _item.get("aprvemp_posnm_09"));
_item2.put("aprv_line_09" , _item.get("aprvemp_posnm_10"));
_item2.put("aprv_line_10" , _item.get("aprvemp_posnm_11"));
_resultList.add(_item2);
Map<String, Object> _item3 = Maps.newHashMap();
_item3.putAll(_item);
_item3.put("no" , 3);
_item3.put("aprv_rqst_usr" , _item.get("aprv_dt_01"));
_item3.put("aprv_line_01" , _item.get("aprv_dt_02"));
_item3.put("aprv_line_02" , _item.get("aprv_dt_03"));
_item3.put("aprv_line_03" , _item.get("aprv_dt_04"));
_item3.put("aprv_line_04" , _item.get("aprv_dt_05"));
_item3.put("aprv_line_05" , _item.get("aprv_dt_06"));
_item3.put("aprv_line_06" , _item.get("aprv_dt_07"));
_item3.put("aprv_line_07" , _item.get("aprv_dt_08"));
_item3.put("aprv_line_08" , _item.get("aprv_dt_09"));
_item3.put("aprv_line_09" , _item.get("aprv_dt_10"));
_item3.put("aprv_line_10" , _item.get("aprv_dt_11"));
_resultList.add(_item3);
}
Collections.sort(_resultList, new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> obj1, Map<String, Object> obj2) {
return ComparisonChain.start().compare(Integer.parseInt(String.valueOf(obj1.get("rownum_"))), Integer.parseInt(String.valueOf(obj2.get("rownum_"))))
.compare(Integer.parseInt(String.valueOf(obj1.get("no"))), Integer.parseInt(String.valueOf(obj2.get("no")))).result();
}
});
}
else
{
_resultList = _aprvList;
}
return _resultList;
}
* 다중조건 정렬
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
...
Map<String, Object> resultMap = Maps.newHashMap();
Map<String, Object> _rfq = Maps.newHashMap();
List<Map<String, Object>> _prList = Lists.newArrayList();
Map<String, Object> _pr = Maps.newHashMap();
List<Map<String, Object>> _prLcsList = Lists.newArrayList();
Map<String, Object> _cntr = Maps.newHashMap();
List<Map<String, Object>> _prItemList = Lists.newArrayList();
String rfq_no = (String)param.get("rfq_no");
_prList = (List<Map<String, Object>>)param.get("prList");
// 집행예산 금액이 큰 순서로 정렬하되 금액이 같다면 PR No.가 큰 순서로 정렬한다.
Collections.sort(_prList, new Comparator<Map<String, Object>>()
{
@Override
public int compare(Map<String, Object> obj1, Map<String, Object> obj2)
{
BigDecimal _amt1 = obj1.get("ebdg_amt") == null ? BigDecimal.ZERO : new BigDecimal(obj1.get("ebdg_amt").toString());
BigDecimal _amt2 = obj2.get("ebdg_amt") == null ? BigDecimal.ZERO : new BigDecimal(obj2.get("ebdg_amt").toString());
return ComparisonChain.start().compare(_amt2, _amt1).compare(String.valueOf(obj2.get("pr_no")), String.valueOf(obj1.get("pr_no"))).result();
}
});
System.out.println(String.format("%0" + 100 + "d", 0).replace("0", "-"));
for (Map<String, Object> _item : _prList)
{
System.out.println(String.format("%10s, %10s", _item.get("ebdg_amt"), _item.get("pr_no")));
}
System.out.println(String.format("%0" + 100 + "d", 0).replace("0", "-"));
----------------------------------------------------------------------------------------------------
1000, 0090090116
1000, 0090090114
10, 0090090113
0, 0090090112
----------------------------------------------------------------------------------------------------
https://howtodoinjava.com/java/sort/groupby-sort-multiple-comparators/