You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.3 KiB
Java
80 lines
2.3 KiB
Java
package com.ibeetl.jlw.service;
|
|
|
|
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
import com.ibeetl.jlw.dao.AttributeDao;
|
|
import com.ibeetl.jlw.entity.Attribute;
|
|
import org.beetl.sql.core.SqlId;
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Attribute Service
|
|
*/
|
|
|
|
@Service
|
|
@Transactional
|
|
public class AttributeService extends CoreBaseService<Attribute>{
|
|
|
|
@Autowired private AttributeDao attributeDao;
|
|
|
|
public PageQuery<Attribute>queryByCondition(PageQuery query){
|
|
PageQuery ret = attributeDao.queryByCondition(query);
|
|
queryListAfter(ret.getList());
|
|
return ret;
|
|
}
|
|
|
|
public void deleteAttribute(String ids){
|
|
try {
|
|
attributeDao.deleteAttributeByIds(ids);
|
|
} catch (Exception e) {
|
|
throw new PlatformException("批量删除Attribute失败", e);
|
|
}
|
|
}
|
|
|
|
public List<Attribute> getValues (Object paras){
|
|
return sqlManager.select(SqlId.of("jlw.attribute.getAttributeValues"),Attribute.class,paras);
|
|
}
|
|
|
|
static Integer childrenCount = 0;
|
|
|
|
public Attribute getTreeById(Long attributeId){
|
|
childrenCount = 0;
|
|
Attribute attribute = attributeDao.single(attributeId);
|
|
getByParentAttributeId(attribute, attribute.getAttributeId(),0);
|
|
attribute.set("childrenCount",childrenCount);
|
|
return attribute;
|
|
}
|
|
|
|
|
|
|
|
public void getByParentAttributeId(Attribute attribute,Long attributeId,Integer n){
|
|
Attribute a = new Attribute();
|
|
a.set("parentAttributeId",attributeId);
|
|
List<Attribute> attributeList = getValues(a);
|
|
if(null != attributeList && attributeList.size()>0) {
|
|
attribute.set("children", attributeList);
|
|
n++;
|
|
for (int i = 0; i < attributeList.size(); i++) {
|
|
getByParentAttributeId(attributeList.get(i), attributeList.get(i).getAttributeId(),n);
|
|
}
|
|
if(n>childrenCount){
|
|
childrenCount = n;
|
|
}
|
|
}else {
|
|
attribute.set("children", new ArrayList<Attribute>());
|
|
}
|
|
|
|
}
|
|
} |