Commit 2827b329 authored by 赵啸非's avatar 赵啸非

添加水印图片

parent 8cecaf4c
package com.mortals.xhx.module.certificate.model; package com.mortals.xhx.module.certificate.model;
import java.lang.reflect.Type;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import com.mortals.xhx.module.certificate.model.vo.CertificateIndustryVo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -24,6 +31,11 @@ public class CertificateIndustryTreeSelect implements Serializable { ...@@ -24,6 +31,11 @@ public class CertificateIndustryTreeSelect implements Serializable {
*/ */
private Long id; private Long id;
/**
* 父节点ID
*/
private Long parentId;
/** /**
* 节点名称 * 节点名称
*/ */
...@@ -35,12 +47,134 @@ public class CertificateIndustryTreeSelect implements Serializable { ...@@ -35,12 +47,134 @@ public class CertificateIndustryTreeSelect implements Serializable {
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<CertificateIndustryTreeSelect> children; private List<CertificateIndustryTreeSelect> children;
public CertificateIndustryTreeSelect() {
}
public CertificateIndustryTreeSelect(CertificateIndustryEntity entity) { public CertificateIndustryTreeSelect(CertificateIndustryEntity entity) {
this.id = entity.getId(); this.id = entity.getId();
this.parentId = entity.getParentId();
this.label = entity.getIndustryName(); this.label = entity.getIndustryName();
if(!ObjectUtils.isEmpty(entity.getChildren())){ if(!ObjectUtils.isEmpty(entity.getChildren())){
this.children = entity.getChildren().stream().map(CertificateIndustryTreeSelect::new).collect(Collectors.toList()); this.children = entity.getChildren().stream().map(CertificateIndustryTreeSelect::new).collect(Collectors.toList());
} }
} }
// 反序列化器
public class Deserializer implements ObjectDeserializer {
@Override
public CertificateIndustryTreeSelect deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
CertificateIndustryTreeSelect node = new CertificateIndustryTreeSelect();
JSONObject jsonObject = parser.parseObject();
node.setId(jsonObject.getLong("id"));
node.setLabel(jsonObject.getString("label"));
JSONArray jsonArray = jsonObject.getJSONArray("children");
List<CertificateIndustryTreeSelect> children = new ArrayList<>();
if(!ObjectUtils.isEmpty(jsonArray)){
for (int i = 0; i < jsonArray.size(); i++) {
CertificateIndustryTreeSelect child = JSON.parseObject(jsonArray.getJSONObject(i).toJSONString(), CertificateIndustryTreeSelect.class);
children.add(child);
}
}
node.setChildren(children);
return node;
}
@Override
public int getFastMatchToken() {
return JSONToken.LBRACE;
}
}
public static void main(String[] args) {
String json="{\n" +
" \"children\": [\n" +
" {\n" +
" \"children\": [\n" +
" {\n" +
" \"id\": 10,\n" +
" \"label\": \"小餐馆\"\n" +
" },\n" +
" {\n" +
" \"id\": 11,\n" +
" \"label\": \"奶茶店\"\n" +
" },\n" +
" {\n" +
" \"id\": 14,\n" +
" \"label\": \"咖啡店\"\n" +
" }\n" +
" ],\n" +
" \"id\": 1,\n" +
" \"label\": \"餐饮类\"\n" +
" },\n" +
" {\n" +
" \"children\": [\n" +
" {\n" +
" \"id\": 16,\n" +
" \"label\": \"超市\"\n" +
" },\n" +
" {\n" +
" \"id\": 17,\n" +
" \"label\": \"便利店\"\n" +
" }\n" +
" ],\n" +
" \"id\": 15,\n" +
" \"label\": \"购物类\"\n" +
" },\n" +
" {\n" +
" \"children\": [\n" +
" {\n" +
" \"id\": 19,\n" +
" \"label\": \"茶楼\"\n" +
" },\n" +
" {\n" +
" \"id\": 20,\n" +
" \"label\": \"酒吧\"\n" +
" },\n" +
" {\n" +
" \"id\": 21,\n" +
" \"label\": \"游艺厅\"\n" +
" },\n" +
" {\n" +
" \"id\": 22,\n" +
" \"label\": \"电玩城\"\n" +
" },\n" +
" {\n" +
" \"id\": 23,\n" +
" \"label\": \"KTV\"\n" +
" },\n" +
" {\n" +
" \"id\": 24,\n" +
" \"label\": \"洗浴场所\"\n" +
" },\n" +
" {\n" +
" \"id\": 25,\n" +
" \"label\": \"网吧\"\n" +
" },\n" +
" {\n" +
" \"id\": 26,\n" +
" \"label\": \"游乐场\"\n" +
" },\n" +
" {\n" +
" \"id\": 27,\n" +
" \"label\": \"电影院\"\n" +
" }\n" +
" ],\n" +
" \"id\": 18,\n" +
" \"label\": \"娱乐类\"\n" +
" }\n" +
" ],\n" +
" \"id\": -1,\n" +
" \"label\": \"全部行业\"\n" +
"}";
CertificateIndustryTreeSelect certificateIndustryTreeSelect = JSONObject.parseObject(json, CertificateIndustryTreeSelect.class);
System.out.println(JSONObject.toJSONString(certificateIndustryTreeSelect));
}
} }
\ No newline at end of file
...@@ -25,15 +25,6 @@ public interface CertificateIndustryService extends ICRUDService<CertificateIndu ...@@ -25,15 +25,6 @@ public interface CertificateIndustryService extends ICRUDService<CertificateIndu
boolean hasChildByCertificateIndustryId(Long certificateIndustryId); boolean hasChildByCertificateIndustryId(Long certificateIndustryId);
/**
* 查询行业目录数据
*
* @param certificateIndustry 行业目录
* @return 行业目录集合
*/
List<CertificateIndustryEntity> selectCertificateIndustryList(CertificateIndustryEntity certificateIndustry);
/** /**
* 构建前端所需要下拉树结构 * 构建前端所需要下拉树结构
* *
...@@ -52,11 +43,13 @@ public interface CertificateIndustryService extends ICRUDService<CertificateIndu ...@@ -52,11 +43,13 @@ public interface CertificateIndustryService extends ICRUDService<CertificateIndu
List<CertificateIndustryTreeSelect> getListByParentId(Long parentId, Context context); List<CertificateIndustryTreeSelect> getListByParentId(Long parentId, Context context);
/** /**
* 根据父id获取所有子节点id * 根据父id查询子节点
*
* @param parentId * @param parentId
* @param context * @param context
* @return * @return
*/ */
List<Long> getAllListByParentId(Long parentId, Context context); List<CertificateIndustryTreeSelect> getAllListByParentId(Long parentId, Context context);
} }
\ No newline at end of file
...@@ -100,10 +100,6 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert ...@@ -100,10 +100,6 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert
return list.size() > 0 ? true : false; return list.size() > 0 ? true : false;
} }
@Override
public List<CertificateIndustryEntity> selectCertificateIndustryList(CertificateIndustryEntity certificateIndustry) {
return this.find(new CertificateIndustryQuery());
}
@Override @Override
public List<CertificateIndustryTreeSelect> buildCertificateIndustryTreeSelect(List<CertificateIndustryEntity> list) { public List<CertificateIndustryTreeSelect> buildCertificateIndustryTreeSelect(List<CertificateIndustryEntity> list) {
...@@ -118,12 +114,9 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert ...@@ -118,12 +114,9 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert
returnList.add(certificateIndustryEntity); returnList.add(certificateIndustryEntity);
} }
} }
if (returnList.isEmpty()) { if (returnList.isEmpty()) {
returnList = list; returnList = list;
} }
return returnList.stream().map(CertificateIndustryTreeSelect::new).collect(Collectors.toList()); return returnList.stream().map(CertificateIndustryTreeSelect::new).collect(Collectors.toList());
} }
...@@ -166,23 +159,29 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert ...@@ -166,23 +159,29 @@ public class CertificateIndustryServiceImpl extends AbstractCRUDServiceImpl<Cert
if (ObjectUtils.isEmpty(parentId)) { if (ObjectUtils.isEmpty(parentId)) {
parentId = -1L; parentId = -1L;
} }
List<CertificateIndustryTreeSelect> collect = this.find(new CertificateIndustryQuery().parentId(parentId), context) List<CertificateIndustryTreeSelect> collect = this.find(new CertificateIndustryQuery().parentId(parentId), context)
.stream().map(item -> new CertificateIndustryTreeSelect(item)) .stream().map(item -> new CertificateIndustryTreeSelect(item))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (parentId == -1L) {
return collect;
}
return collect; return collect;
} }
@Override @Override
public List<Long> getAllListByParentId(Long parentId, Context context) { public List<CertificateIndustryTreeSelect> getAllListByParentId(Long parentId, Context context) {
List<CertificateIndustryEntity> list = this.find(new CertificateIndustryQuery());
List<CertificateIndustryEntity> list = this.find(new CertificateIndustryQuery().parentId(parentId)); List<CertificateIndustryEntity> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(CertificateIndustryEntity::getId).collect(Collectors.toList());
if (!tempList.contains(parentId)) {
CertificateIndustryEntity certificateIndustryEntity = this.get(parentId, context);
recursionFn(list, certificateIndustryEntity);
returnList.add(certificateIndustryEntity);
}
return null; if (returnList.isEmpty()) {
returnList = list;
}
return returnList.stream().map(CertificateIndustryTreeSelect::new).collect(Collectors.toList());
} }
} }
\ 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