@ApiOperation(value = "货品列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "goodsname", value = "字典数据类型编号", required = false, dataType = "String", paramType = "query"),
})
@RequestMapping(value="/goodslist",method=RequestMethod.GET)
public Object GoodsList(PgQuery pgq,String goodsname){
String condition="";
if ( StrUtils.hasText(goodsname)) {
condition += " and goodsname = '" + goodsname + "'";
}
String dwcode = getzhutiuser().getDwcode();
String sql = "select * from t_goods"
+ " where nvl(scbj,'0')='0'"
+ " and dwcode='"+dwcode+"' "
+ " and parentcode='0'"
+condition
+" order by goodscode asc";
PagedList<ext_goods> pagedListData = jdbcDao.getPagedListData(ext_goods.class, sql, pgq);
//最高节点的集合
List<ext_goods> rows = pagedListData.getRows();
//准备存放所有子节点的集合
List<ext_goods> all = new ArrayList<ext_goods>();
if(!CollectionUtils.isEmpty(rows)){
for(ext_goods ext_goods:rows){
//当前最高节点的所有子节点
List<ext_goods> all2 = t_goodsDal.getAll(ext_goods,dwcode);
if(!CollectionUtils.isEmpty(all2)){
all.addAll(all2);
}
}
}
//最高节点+所有子节点
rows.addAll(all);
//按goodscode排序
List<ext_goods> collect = rows.stream().sorted(Comparator.comparing(ext_goods::getGoodscode)).collect(Collectors.toList());
pagedListData.setRows(collect);
return pagedListData;
}
public List<ext_goods> getAll(ext_goods ext_goodsparent,String dwcode) {
List<ext_goods> rows = new ArrayList<ext_goods>();
//当前节点所有子节点
List<ext_goods> li = this.selectChildren(ext_goodsparent.getGoodscode(),dwcode);
if(!CollectionUtils.isEmpty(li)){
rows.addAll(li);
}
//节点组装
this.save(ext_goodsparent, li,dwcode,rows);
return rows;
}
//查询当前节点所有子节点
private List<ext_goods> selectChildren(String code,String dwcode) {
String sql="select * from t_goods where parentcode='"+code+"' and dwcode='"+dwcode+"' and nvl(scbj,'0')='0'";
List<ext_goods> list = jdbcDao.queryListForSql(sql, ext_goods.class);
return list;
}
// 节点保存
private void save(ext_goods ext_goodsparent, List<ext_goods> li,String dwcode,List<ext_goods> rows) {
if (!CollectionUtils.isEmpty(li)) {
for (int i = 0, l = li.size(); i < l; i++) {
//当前子节点的子节点
List<ext_goods> list = this.selectChildren(li.get(i).getGoodscode(),dwcode);
if(!CollectionUtils.isEmpty(list)){
rows.addAll(list);
}
save(li.get(i), list,dwcode,rows);// 递归,实现无限层级
}
}
}