Commit 68b5bca0 authored by 廖旭伟's avatar 廖旭伟

行业增加树形结构返回接口

parent dd7a4232
package com.mortals.xhx.module.certificate.model.vo; package com.mortals.xhx.module.certificate.model.vo;
import com.mortals.framework.model.BaseEntityLong; import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.certificate.model.CertificateIndustryEntity; import com.mortals.xhx.module.certificate.model.CertificateIndustryEntity;
import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -9,6 +11,7 @@ import java.util.List; ...@@ -9,6 +11,7 @@ import java.util.List;
* @author zxfei * @author zxfei
* @date 2022-10-14 * @date 2022-10-14
*/ */
@Data
public class CertificateIndustryVo extends BaseEntityLong { public class CertificateIndustryVo extends BaseEntityLong {
List<CertificateIndustryEntity> childIndustry;
} }
\ No newline at end of file
...@@ -36,4 +36,12 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert ...@@ -36,4 +36,12 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert
throw new AppException("行业名称重复"); throw new AppException("行业名称重复");
} }
} }
@Override
protected void saveBefore(CertificateIndustryEntity entity, Context context) throws AppException {
super.saveBefore(entity,context);
if(entity.getParentId()==null){
entity.setParentId(-1l);
}
}
} }
\ No newline at end of file
package com.mortals.xhx.module.certificate.web; package com.mortals.xhx.module.certificate.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.annotation.DataPermission; import com.mortals.xhx.annotation.DataPermission;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.certificate.model.CertificateIndustryEntity; import com.mortals.xhx.module.certificate.model.CertificateIndustryEntity;
import com.mortals.xhx.module.certificate.service.CertificateIndustryService; import com.mortals.xhx.module.certificate.service.CertificateIndustryService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collector;
import java.util.stream.Collectors;
/** /**
* *
* 行业目录 * 行业目录
...@@ -40,4 +52,54 @@ public class CertificateIndustryController extends BaseCRUDJsonBodyMappingContro ...@@ -40,4 +52,54 @@ public class CertificateIndustryController extends BaseCRUDJsonBodyMappingContro
public Rest<Object> list(CertificateIndustryEntity query) { public Rest<Object> list(CertificateIndustryEntity query) {
return super.list(query); return super.list(query);
} }
@PostMapping({"treeList"})
@UnAuth
public Rest<Object> treeList(@RequestBody CertificateIndustryEntity query) {
Rest<Object> ret = new Rest();
Map<String, Object> model = new HashMap();
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
int code;
try {
List<CertificateIndustryEntity> result = this.getService().find(query, context);
if(CollectionUtils.isNotEmpty(result)){
List<CertificateIndustryEntity> collect = result.stream().filter(t -> t.getParentId() == -1).map(
m -> {
m.setChildIndustry(getChildren(m, result));
return m;
}
).collect(Collectors.toList());
model.put("data", collect);
}else {
model.put("data", result);
}
code = this.doListAfter(query, (Map)model, context);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var9) {
code = -1;
this.doException(this.request, busiDesc, model, var9);
}
this.init(model, context);
ret.setCode(code);
ret.setData(model);
ret.setDict(model.get("dict"));
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
private static List<CertificateIndustryEntity> getChildren(CertificateIndustryEntity root, List<CertificateIndustryEntity> all) {
List<CertificateIndustryEntity> children = all.stream().filter(t -> {
return Objects.equals(t.getParentId(), root.getId());
}).map(
m -> {
m.setChildIndustry(getChildren(m, all));
return m;
}
).collect(Collectors.toList());
return children;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment