Commit e944a784 authored by 赵啸非's avatar 赵啸非

添加事项同步数据

parent cf1dd547
...@@ -133,9 +133,7 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE ...@@ -133,9 +133,7 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
public List<AreaTreeSelect> buildAreaTreeSelect(List<AreaEntity> list) { public List<AreaTreeSelect> buildAreaTreeSelect(List<AreaEntity> list) {
List<AreaEntity> returnList = new ArrayList<>(); List<AreaEntity> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(AreaEntity::getId).collect(Collectors.toList()); List<Long> tempList = list.stream().map(AreaEntity::getId).collect(Collectors.toList());
for (AreaEntity areaEntity : list) {
for (Iterator<AreaEntity> iterator = list.iterator(); iterator.hasNext(); ) {
AreaEntity areaEntity = iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点 // 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(areaEntity.getPid())) { if (!tempList.contains(areaEntity.getPid())) {
recursionFn(list, areaEntity); recursionFn(list, areaEntity);
...@@ -164,7 +162,7 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE ...@@ -164,7 +162,7 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
if (!ObjectUtils.isEmpty(areaEntity)) { if (!ObjectUtils.isEmpty(areaEntity)) {
//查询当前区域是否有站点。 //查询当前区域是否有站点。
List<AreaTreeSelect> collect1 = siteService.find(new SiteQuery().areaCode(areaEntity.getAreaCode())) List<AreaTreeSelect> collect1 = siteService.find(new SiteQuery().areaCode(areaEntity.getAreaCode()))
.stream().map(site ->new AreaTreeSelect(site)).collect(Collectors.toList()); .stream().map(site -> new AreaTreeSelect(site)).collect(Collectors.toList());
collect.addAll(collect1); collect.addAll(collect1);
} }
...@@ -186,13 +184,6 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE ...@@ -186,13 +184,6 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
} }
} }
/**
* 判断是否有子节点
*/
private boolean hasChild(List<AreaEntity> list, AreaEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
}
/** /**
* 得到子节点列表 * 得到子节点列表
*/ */
...@@ -205,4 +196,13 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE ...@@ -205,4 +196,13 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
}).filter(f -> f != null).collect(Collectors.toList()); }).filter(f -> f != null).collect(Collectors.toList());
} }
/**
* 判断是否有子节点
*/
private boolean hasChild(List<AreaEntity> list, AreaEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
}
} }
\ No newline at end of file
package com.mortals.xhx.module.site.service; package com.mortals.xhx.module.site.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import com.mortals.xhx.module.site.model.SiteEntity; import com.mortals.xhx.module.site.model.SiteEntity;
import com.mortals.xhx.module.site.model.SiteTreeSelect;
import java.util.List;
import java.util.Map;
/** /**
* SiteService * SiteService
* * <p>
* 站点 service接口 * 站点 service接口
* *
* @author zxfei * @author zxfei
* @date 2022-01-12 * @date 2022-01-12
*/ */
public interface SiteService extends ICRUDService<SiteEntity,Long>{ public interface SiteService extends ICRUDService<SiteEntity, Long> {
/**
* 区域站点树
*
* @param context
* @return
*/
List<SiteTreeSelect> siteTree(Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.site.service.impl; package com.mortals.xhx.module.site.service.impl;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.xhx.module.area.model.AreaEntity; import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import com.mortals.xhx.module.area.service.AreaService; import com.mortals.xhx.module.area.service.AreaService;
import com.mortals.xhx.module.site.model.SiteQuery; import com.mortals.xhx.module.site.model.SiteQuery;
import com.mortals.xhx.module.site.model.SiteTreeSelect;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
...@@ -12,15 +16,19 @@ import com.mortals.xhx.module.site.model.SiteEntity; ...@@ -12,15 +16,19 @@ import com.mortals.xhx.module.site.model.SiteEntity;
import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* SiteService * SiteService
* 站点 service实现 * 站点 service实现
* *
* @author zxfei * @author zxfei
* @date 2022-01-12 * @date 2022-01-12
*/ */
@Service("siteService") @Service("siteService")
public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity, Long> implements SiteService { public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity, Long> implements SiteService {
@Autowired @Autowired
...@@ -28,11 +36,11 @@ public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity ...@@ -28,11 +36,11 @@ public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity
@Override @Override
protected void validData(SiteEntity entity, Context context) throws AppException { protected void validData(SiteEntity entity, Context context) throws AppException {
if(ObjectUtils.isEmpty(entity.getAreaCode())){ if (ObjectUtils.isEmpty(entity.getAreaCode())) {
throw new AppException("区域编码不能为空!"); throw new AppException("区域编码不能为空!");
} }
AreaEntity areaEntity = areaService.getCache(entity.getAreaCode()); AreaEntity areaEntity = areaService.getCache(entity.getAreaCode());
if(ObjectUtils.isEmpty(areaEntity)){ if (ObjectUtils.isEmpty(areaEntity)) {
throw new AppException(String.format("区域不存在!区域编码:%s", entity.getAreaCode())); throw new AppException(String.format("区域不存在!区域编码:%s", entity.getAreaCode()));
} }
super.validData(entity, context); super.validData(entity, context);
...@@ -41,7 +49,89 @@ public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity ...@@ -41,7 +49,89 @@ public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity
@Override @Override
protected void saveBefore(SiteEntity entity, Context context) throws AppException { protected void saveBefore(SiteEntity entity, Context context) throws AppException {
List<SiteEntity> siteEntities = this.find(new SiteQuery().areaCode(entity.getAreaCode())); List<SiteEntity> siteEntities = this.find(new SiteQuery().areaCode(entity.getAreaCode()));
entity.setSiteCode(entity.getAreaCode()+"#"+(siteEntities.size()+1)); entity.setSiteCode(entity.getAreaCode() + "#" + (siteEntities.size() + 1));
super.saveBefore(entity, context); super.saveBefore(entity, context);
} }
@Override
public List<SiteTreeSelect> siteTree(Context context) {
Map<String, AreaEntity> areaMap = new HashMap<>();
//查询所有已配置的站点
List<SiteEntity> siteList = this.find(new SiteQuery());
Map<String, SiteEntity> siteMap = this.find(new SiteQuery()).stream().collect(Collectors.toMap(x -> x.getSiteCode(), y -> y, (o, n) -> n));
//遍历过滤站点树
for (SiteEntity siteEntity : siteList) {
String areaCode = siteEntity.getAreaCode();
AreaEntity areaEntity = areaService.getExtCache(areaCode);
//根据区域添加父节点
if (!ObjectUtils.isEmpty(areaEntity) && !ObjectUtils.isEmpty(areaEntity.getPid())) {
//递归查找父节点并添加
areaMap.put(areaEntity.getAreaCode(), areaEntity);
recursionFn(areaMap, areaEntity);
}
}
return buildSiteTreeSelect(areaMap, siteMap);
}
public List<SiteTreeSelect> buildSiteTreeSelect(Map<String, AreaEntity> areaMap, Map<String, SiteEntity> siteMap) {
List<AreaEntity> list = areaMap.values().stream().collect(Collectors.toList());
List<AreaEntity> returnList = new ArrayList<>();
List<String> tempList = list.stream().map(AreaEntity::getIid).collect(Collectors.toList());
for (AreaEntity areaEntity : list) {
//查询当前区域列表中最顶级的节点 并构建树
if (!tempList.contains(areaEntity.getPid())) {
recursion(list, areaEntity);
returnList.add(areaEntity);
}
}
if (returnList.isEmpty()) {
returnList = list;
}
return returnList.stream().map(item ->
new SiteTreeSelect(item, siteMap)
).collect(Collectors.toList());
}
private void recursion(List<AreaEntity> list, AreaEntity t) {
// 得到子节点列表
List<AreaEntity> childList = getChildList(list, t);
t.setChildren(childList);
for (AreaEntity tChild : childList) {
if (hasChild(list, tChild)) {
recursion(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<AreaEntity> getChildList(List<AreaEntity> list, AreaEntity t) {
return list.stream().filter(item -> item.getPid().equals(t.getIid())).collect(Collectors.toList());
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<AreaEntity> list, AreaEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
}
/**
* 递归列表
*/
private void recursionFn(Map<String, AreaEntity> areaMap, AreaEntity t) {
// 得到父节点并加入
AreaEntity areaEntity = areaService.selectOne(new AreaQuery().iid(t.getPid()));
if (!ObjectUtils.isEmpty(areaEntity)) {
areaMap.put(areaEntity.getAreaCode(), areaEntity);
recursionFn(areaMap, areaEntity);
}
}
} }
\ No newline at end of file
package com.mortals.xhx.module.site.web; package com.mortals.xhx.module.site.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.web.BasePhpCRUDJsonMappingController; import com.mortals.framework.web.BasePhpCRUDJsonMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.model.model.ModelQuery; import com.mortals.xhx.module.model.model.ModelQuery;
import com.mortals.xhx.module.model.service.ModelService; import com.mortals.xhx.module.model.service.ModelService;
import com.mortals.xhx.module.site.model.SiteEntity; import com.mortals.xhx.module.site.model.SiteEntity;
import com.mortals.xhx.module.site.model.SiteTreeSelect;
import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -53,4 +58,28 @@ public class SiteController extends BasePhpCRUDJsonMappingController<SiteService ...@@ -53,4 +58,28 @@ public class SiteController extends BasePhpCRUDJsonMappingController<SiteService
} }
/**
* 构建站点树
*/
@GetMapping(value = "siteTree")
public String siteTree() {
JSONObject jsonObject = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = this.getModuleDesc() + "构建站点树";
try {
List<SiteTreeSelect> siteTree = this.service.siteTree(getContext());
model.put("siteTree", siteTree);
this.init(model, getContext());
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_DATA, model);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} catch (Exception e) {
log.error("构建站点树异常", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
} }
\ No newline at end of file
{ {
"local": { "local": {
"baseUrl": "http://127.0.0.1:17311" "baseUrl": "http://127.0.0.1:17311/zwfw"
}, },
"dev": { "dev": {
"baseUrl": "http://192.168.0.217:17311" "baseUrl": "http://192.168.0.217:17311/zwfw"
}, },
"test": { "test": {
"baseUrl": "http://192.168.0.98:11023" "baseUrl": "http://192.168.0.98:11023/zwfw"
} }
} }
\ No newline at end of file
...@@ -64,5 +64,10 @@ GET {{baseUrl}}/site/delete?id={{Site_id}} ...@@ -64,5 +64,10 @@ GET {{baseUrl}}/site/delete?id={{Site_id}}
Accept: application/json Accept: application/json
###构建站点树
GET {{baseUrl}}/site/siteTree
Accept: application/json
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