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

添加事项同步数据

parent cf1dd547
......@@ -133,9 +133,7 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
public List<AreaTreeSelect> buildAreaTreeSelect(List<AreaEntity> list) {
List<AreaEntity> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(AreaEntity::getId).collect(Collectors.toList());
for (Iterator<AreaEntity> iterator = list.iterator(); iterator.hasNext(); ) {
AreaEntity areaEntity = iterator.next();
for (AreaEntity areaEntity : list) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(areaEntity.getPid())) {
recursionFn(list, areaEntity);
......@@ -164,7 +162,7 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
if (!ObjectUtils.isEmpty(areaEntity)) {
//查询当前区域是否有站点。
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);
}
......@@ -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
}).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;
import com.mortals.framework.model.Context;
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.SiteTreeSelect;
import java.util.List;
import java.util.Map;
/**
* SiteService
*
* 站点 service接口
*
* @author zxfei
* @date 2022-01-12
*/
public interface SiteService extends ICRUDService<SiteEntity,Long>{
* SiteService
* <p>
* 站点 service接口
*
* @author zxfei
* @date 2022-01-12
*/
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;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
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.site.model.SiteQuery;
import com.mortals.xhx.module.site.model.SiteTreeSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
......@@ -12,15 +16,19 @@ import com.mortals.xhx.module.site.model.SiteEntity;
import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* SiteService
* 站点 service实现
*
* @author zxfei
* @date 2022-01-12
*/
* SiteService
* 站点 service实现
*
* @author zxfei
* @date 2022-01-12
*/
@Service("siteService")
public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity, Long> implements SiteService {
@Autowired
......@@ -28,11 +36,11 @@ public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity
@Override
protected void validData(SiteEntity entity, Context context) throws AppException {
if(ObjectUtils.isEmpty(entity.getAreaCode())){
if (ObjectUtils.isEmpty(entity.getAreaCode())) {
throw new AppException("区域编码不能为空!");
}
AreaEntity areaEntity = areaService.getCache(entity.getAreaCode());
if(ObjectUtils.isEmpty(areaEntity)){
if (ObjectUtils.isEmpty(areaEntity)) {
throw new AppException(String.format("区域不存在!区域编码:%s", entity.getAreaCode()));
}
super.validData(entity, context);
......@@ -41,7 +49,89 @@ public class SiteServiceImpl extends AbstractCRUDServiceImpl<SiteDao, SiteEntity
@Override
protected void saveBefore(SiteEntity entity, Context context) throws AppException {
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);
}
@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;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BasePhpCRUDJsonMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.model.model.ModelQuery;
import com.mortals.xhx.module.model.service.ModelService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -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": {
"baseUrl": "http://127.0.0.1:17311"
"baseUrl": "http://127.0.0.1:17311/zwfw"
},
"dev": {
"baseUrl": "http://192.168.0.217:17311"
"baseUrl": "http://192.168.0.217:17311/zwfw"
},
"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}}
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