Commit 23fcd536 authored by 赵啸非's avatar 赵啸非

添加区域树

parent efa10d54
package com.mortals.xhx.common.code; package com.mortals.xhx.common.code;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
/** /**
* 区域级别 * 区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)枚举类
* *
* @author yiqimin * @author zxfei
* @create 2018/09/26 */
*/ public enum AreaLevelEnum {
public enum AreaLevelEnum implements IBaseEnum { (1, "省"),
地市州(2, "地市州"),
PROVINCE(1, "省", SysConstains.STYLE_DEFAULT), 区县(3, "区县"),
CITY(2, "市", SysConstains.STYLE_DEFAULT), 街道(4, "街道"),
AREA(3, "区/县", SysConstains.STYLE_DEFAULT), 社区(5, "社区");
TOWN(4, "镇", SysConstains.STYLE_DEFAULT); private Integer value;
private int value;
private String desc; private String desc;
private String style;
AreaLevelEnum(int value, String desc, String style) { AreaLevelEnum(Integer value, String desc) {
this.value = value; this.value = value;
this.desc = desc; this.desc = desc;
this.style = style;
} }
@Override public Integer getValue() {
public int getValue() {
return this.value; return this.value;
} }
public String getDesc() { public String getDesc() {
return desc; return this.desc;
} }
public String getStyle() public static AreaLevelEnum getByValue(Integer value) {
{ for (AreaLevelEnum areaLevelEnum : AreaLevelEnum.values()) {
return style; if (areaLevelEnum.getValue() == value) {
} return areaLevelEnum;
public static AreaLevelEnum getByValue(int value) {
for (AreaLevelEnum e : AreaLevelEnum.values()) {
if (e.getValue() == value) {
return e;
} }
} }
return null; return null;
} }
public static Map<String,String> getEnumMap(int... eItem) { /**
Map<String,String> resultMap= new LinkedHashMap<String,String>(); * 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (AreaLevelEnum item : AreaLevelEnum.values()) { for (AreaLevelEnum item : AreaLevelEnum.values()) {
try{ try {
boolean hasE = false; boolean hasE = false;
for (int e : eItem){ for (Integer e : eItem) {
if(item.getValue()==e){ if (item.getValue() == e) {
hasE = true; hasE = true;
break; break;
} }
} }
if(!hasE){ if (!hasE) {
resultMap.put(item.getValue()+"", item.getDesc()); resultMap.put(item.getValue() + "", item.getDesc());
} }
}catch(Exception ex){ } catch (Exception ex) {
} }
} }
return resultMap; return resultMap;
} }
}
} \ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 是否获取部门(true.是,false.否)枚举类
*
* @author zxfei
*/
public enum HaveGetDeptEnum {
("true", "是"),
("false", "否");
private String value;
private String desc;
HaveGetDeptEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static HaveGetDeptEnum getByValue(String value) {
for (HaveGetDeptEnum haveGetDeptEnum : HaveGetDeptEnum.values()) {
if (haveGetDeptEnum.getValue() == value) {
return haveGetDeptEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (HaveGetDeptEnum item : HaveGetDeptEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 是否获取事项列表(true.是,false.否)枚举类
*
* @author zxfei
*/
public enum HaveGetMatterListEnum {
("true", "是"),
("false", "否");
private String value;
private String desc;
HaveGetMatterListEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static HaveGetMatterListEnum getByValue(String value) {
for (HaveGetMatterListEnum haveGetMatterListEnum : HaveGetMatterListEnum.values()) {
if (haveGetMatterListEnum.getValue() == value) {
return haveGetMatterListEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (HaveGetMatterListEnum item : HaveGetMatterListEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 是否有下级区域(True.是,False.否)枚举类
*
* @author zxfei
*/
public enum HaveSonAreaEnum {
("True", "是"),
("False", "否");
private String value;
private String desc;
HaveSonAreaEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static HaveSonAreaEnum getByValue(String value) {
for (HaveSonAreaEnum haveSonAreaEnum : HaveSonAreaEnum.values()) {
if (haveSonAreaEnum.getValue() == value) {
return haveSonAreaEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (HaveSonAreaEnum item : HaveSonAreaEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 是否有下级部门(True.是,False.否)枚举类
*
* @author zxfei
*/
public enum HaveSonDeptEnum {
("True", "是"),
("False", "否");
private String value;
private String desc;
HaveSonDeptEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static HaveSonDeptEnum getByValue(String value) {
for (HaveSonDeptEnum haveSonDeptEnum : HaveSonDeptEnum.values()) {
if (haveSonDeptEnum.getValue() == value) {
return haveSonDeptEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (HaveSonDeptEnum item : HaveSonDeptEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 区域状态 (0.停用,1.正常)枚举类
*
* @author zxfei
*/
public enum StatusEnum {
停用(0, "停用"),
正常(1, "正常");
private Integer value;
private String desc;
StatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static StatusEnum getByValue(Integer value) {
for (StatusEnum statusEnum : StatusEnum.values()) {
if (statusEnum.getValue() == value) {
return statusEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (StatusEnum item : StatusEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
...@@ -2,16 +2,23 @@ package com.mortals.xhx.module.base.dao; ...@@ -2,16 +2,23 @@ package com.mortals.xhx.module.base.dao;
import com.mortals.framework.dao.ICRUDDao; import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.base.model.BaseAreaEntity; import com.mortals.xhx.module.base.model.BaseAreaEntity;
import java.util.List;
/** /**
* 区域Dao * 区域Dao
* 区域 DAO接口 * 区域 DAO接口
* *
* @author zxfei * @author zxfei
* @date 2022-11-22 * @date 2024-11-01
*/ */
public interface BaseAreaDao extends ICRUDDao<BaseAreaEntity,Long>{ public interface BaseAreaDao extends ICRUDDao<BaseAreaEntity,Long>{
/**
* 查询子节点
*
* @param
* @return
*/
List<BaseAreaEntity> selectChildrenBaseAreaById(String baseAreaId);
} }
package com.mortals.xhx.module.base.dao.ibatis; package com.mortals.xhx.module.base.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis; import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.base.dao.BaseAreaDao; import com.mortals.xhx.module.base.dao.BaseAreaDao;
import com.mortals.xhx.module.base.model.BaseAreaEntity; import com.mortals.xhx.module.base.model.BaseAreaEntity;
import org.springframework.stereotype.Repository; import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import java.util.List;
/** /**
* 区域DaoImpl DAO接口 * 区域DaoImpl DAO接口
* *
* @author zxfei * @author zxfei
* @date 2022-11-22 * @date 2024-11-01
*/ */
@Repository("baseAreaDao") @Repository("baseAreaDao")
public class BaseAreaDaoImpl extends BaseCRUDDaoMybatis<BaseAreaEntity,Long> implements BaseAreaDao { public class BaseAreaDaoImpl extends BaseCRUDDaoMybatis<BaseAreaEntity,Long> implements BaseAreaDao {
@Override
public List<BaseAreaEntity> selectChildrenBaseAreaById(String baseAreaId) {
return getSqlSession().selectList(getSqlId("selectChildrenBaseAreaById"), baseAreaId);
}
} }
package com.mortals.xhx.module.base.model; package com.mortals.xhx.module.base.model;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.base.model.vo.BaseAreaVo; import com.mortals.xhx.module.base.model.vo.BaseAreaVo;
import lombok.Data;
/** /**
* 区域实体对象 * 区域实体对象
* *
* @author zxfei * @author zxfei
* @date 2022-11-22 * @date 2024-11-01
*/ */
@Data
public class BaseAreaEntity extends BaseAreaVo { public class BaseAreaEntity extends BaseAreaVo {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -63,196 +71,6 @@ public class BaseAreaEntity extends BaseAreaVo { ...@@ -63,196 +71,6 @@ public class BaseAreaEntity extends BaseAreaVo {
* 区域状态 (0.停用,1.正常) * 区域状态 (0.停用,1.正常)
*/ */
private Integer status; private Integer status;
public BaseAreaEntity(){}
/**
* 获取 祖级列表,逗号分隔
* @return String
*/
public String getAncestors(){
return ancestors;
}
/**
* 设置 祖级列表,逗号分隔
* @param ancestors
*/
public void setAncestors(String ancestors){
this.ancestors = ancestors;
}
/**
* 获取 区域名称
* @return String
*/
public String getName(){
return name;
}
/**
* 设置 区域名称
* @param name
*/
public void setName(String name){
this.name = name;
}
/**
* 获取 一体化的ID号
* @return String
*/
public String getIid(){
return iid;
}
/**
* 设置 一体化的ID号
* @param iid
*/
public void setIid(String iid){
this.iid = iid;
}
/**
* 获取 一体化的父id
* @return String
*/
public String getPid(){
return pid;
}
/**
* 设置 一体化的父id
* @param pid
*/
public void setPid(String pid){
this.pid = pid;
}
/**
* 获取 是否有下级区域(True.是,False.否)
* @return String
*/
public String getHaveSonArea(){
return haveSonArea;
}
/**
* 设置 是否有下级区域(True.是,False.否)
* @param haveSonArea
*/
public void setHaveSonArea(String haveSonArea){
this.haveSonArea = haveSonArea;
}
/**
* 获取 是否有下级部门(True.是,False.否)
* @return String
*/
public String getHaveSonDept(){
return haveSonDept;
}
/**
* 设置 是否有下级部门(True.是,False.否)
* @param haveSonDept
*/
public void setHaveSonDept(String haveSonDept){
this.haveSonDept = haveSonDept;
}
/**
* 获取 是否获取部门(true.是,false.否)
* @return String
*/
public String getHaveGetDept(){
return haveGetDept;
}
/**
* 设置 是否获取部门(true.是,false.否)
* @param haveGetDept
*/
public void setHaveGetDept(String haveGetDept){
this.haveGetDept = haveGetDept;
}
/**
* 获取 是否获取事项列表(true.是,false.否)
* @return String
*/
public String getHaveGetMatterList(){
return haveGetMatterList;
}
/**
* 设置 是否获取事项列表(true.是,false.否)
* @param haveGetMatterList
*/
public void setHaveGetMatterList(String haveGetMatterList){
this.haveGetMatterList = haveGetMatterList;
}
/**
* 获取 区域编码
* @return String
*/
public String getAreaCode(){
return areaCode;
}
/**
* 设置 区域编码
* @param areaCode
*/
public void setAreaCode(String areaCode){
this.areaCode = areaCode;
}
/**
* 获取 区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)
* @return Integer
*/
public Integer getAreaLevel(){
return areaLevel;
}
/**
* 设置 区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)
* @param areaLevel
*/
public void setAreaLevel(Integer areaLevel){
this.areaLevel = areaLevel;
}
/**
* 获取 名称简称
* @return String
*/
public String getShortName(){
return shortName;
}
/**
* 设置 名称简称
* @param shortName
*/
public void setShortName(String shortName){
this.shortName = shortName;
}
/**
* 获取 访问地址
* @return String
*/
public String getDomain(){
return domain;
}
/**
* 设置 访问地址
* @param domain
*/
public void setDomain(String domain){
this.domain = domain;
}
/**
* 获取 区域状态 (0.停用,1.正常)
* @return Integer
*/
public Integer getStatus(){
return status;
}
/**
* 设置 区域状态 (0.停用,1.正常)
* @param status
*/
public void setStatus(Integer status){
this.status = status;
}
@Override @Override
public int hashCode() { public int hashCode() {
return this.getId().hashCode(); return this.getId().hashCode();
...@@ -269,50 +87,19 @@ public class BaseAreaEntity extends BaseAreaVo { ...@@ -269,50 +87,19 @@ public class BaseAreaEntity extends BaseAreaVo {
return false; return false;
} }
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",ancestors:").append(getAncestors());
sb.append(",name:").append(getName());
sb.append(",iid:").append(getIid());
sb.append(",pid:").append(getPid());
sb.append(",haveSonArea:").append(getHaveSonArea());
sb.append(",haveSonDept:").append(getHaveSonDept());
sb.append(",haveGetDept:").append(getHaveGetDept());
sb.append(",haveGetMatterList:").append(getHaveGetMatterList());
sb.append(",areaCode:").append(getAreaCode());
sb.append(",areaLevel:").append(getAreaLevel());
sb.append(",shortName:").append(getShortName());
sb.append(",domain:").append(getDomain());
sb.append(",status:").append(getStatus());
return sb.toString();
}
public void initAttrValue(){ public void initAttrValue(){
this.ancestors = ""; this.ancestors = "";
this.name = "";
this.name = null; this.iid = "";
this.pid = "";
this.iid = null; this.haveSonArea = "";
this.haveSonDept = "";
this.pid = null; this.haveGetDept = "";
this.haveGetMatterList = "";
this.haveSonArea = null; this.areaCode = "";
this.haveSonDept = null;
this.haveGetDept = null;
this.haveGetMatterList = null;
this.areaCode = null;
this.areaLevel = 1; this.areaLevel = 1;
this.shortName = "";
this.shortName = null; this.domain = "";
this.domain = null;
this.status = 1; this.status = 1;
} }
} }
\ No newline at end of file
package com.mortals.xhx.module.base.model;
import java.lang.reflect.Type;
import java.util.List;
import java.util.ArrayList;
import com.mortals.xhx.module.base.model.vo.BaseAreaVo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.io.Serializable;
import java.util.stream.Collectors;
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 org.springframework.util.ObjectUtils;
/**
* 区域前端映射树结构实体类
*
* @author zxfei
* @date 2024-11-01
*/
@Data
public class BaseAreaTreeSelect implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 节点ID
*/
private Long id;
/**
* 节点名称
*/
private String label;
/**
* 区域编码
*/
private String areaCode;
/**
* 是否叶子节点
*/
private Boolean isLeaf;
/**
* 节点类型
*/
private String type;
/**
* 图标
*/
private String icon;
/**
* 区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)
*/
private Integer areaLevel;
/**
* 子节点
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<BaseAreaTreeSelect> children;
public BaseAreaTreeSelect() {};
public BaseAreaTreeSelect(BaseAreaEntity entity) {
this.id = entity.getId();
this.label = entity.getName();
if ("False".equalsIgnoreCase(entity.getHaveSonArea())) {
this.isLeaf = true;
this.children = new ArrayList();
} else {
this.isLeaf = false;
}
this.areaCode=entity.getAreaCode();
this.areaLevel=entity.getAreaLevel();
this.type = "area";
this.icon = "el-icon-folder";
if(!ObjectUtils.isEmpty(entity.getChildren())){
this.children = entity.getChildren().stream().map(BaseAreaTreeSelect::new).collect(Collectors.toList());
}
}
// 反序列化器
public class Deserializer implements ObjectDeserializer {
@Override
public BaseAreaTreeSelect deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
BaseAreaTreeSelect node = new BaseAreaTreeSelect();
JSONObject jsonObject = parser.parseObject();
node.setId(jsonObject.getLong("id"));
node.setLabel(jsonObject.getString("label"));
JSONArray jsonArray = jsonObject.getJSONArray("children");
List<BaseAreaTreeSelect> children = new ArrayList<>();
if(!ObjectUtils.isEmpty(jsonArray)){
for (int i = 0; i < jsonArray.size(); i++) {
BaseAreaTreeSelect child = JSON.parseObject(jsonArray.getJSONObject(i).toJSONString(), BaseAreaTreeSelect.class);
children.add(child);
}
}
node.setChildren(children);
return node;
}
@Override
public int getFastMatchToken() {
return JSONToken.LBRACE;
}
}
}
\ No newline at end of file
package com.mortals.xhx.module.base.model.vo; package com.mortals.xhx.module.base.model.vo;
import com.mortals.framework.model.BaseEntityLong; import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.base.model.BaseAreaEntity; import com.mortals.xhx.module.base.model.BaseAreaEntity;
import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.Data;
import com.mortals.framework.annotation.Excel;
import java.math.BigDecimal;
import java.util.Date;
/** /**
* 区域视图对象 * 区域视图对象
* *
* @author zxfei * @author zxfei
* @date 2022-11-22 * @date 2024-11-01
*/ */
@Data @Data
public class BaseAreaVo extends BaseEntityLong { public class BaseAreaVo extends BaseEntityLong {
private List<BaseAreaEntity> children = new ArrayList<>();
/** 序号,主键,自增长列表 */
private List <Long> idList;
/** 子区域 */
private List<BaseAreaEntity> children = new ArrayList<>();
} }
\ No newline at end of file
package com.mortals.xhx.module.base.service; package com.mortals.xhx.module.base.service;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.base.model.BaseAreaEntity; import com.mortals.xhx.module.base.model.BaseAreaEntity;
import com.mortals.xhx.module.base.model.BaseAreaTreeSelect;
import java.util.List;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
/** /**
* BaseAreaService * BaseAreaService
* <p> *
* 区域 service接口 * 区域 service接口
* *
* @author zxfei * @author zxfei
* @date 2022-11-22 * @date 2024-11-01
*/ */
public interface BaseAreaService extends ICRUDService<BaseAreaEntity, Long> { public interface BaseAreaService extends ICRUDService<BaseAreaEntity,Long>{
/**
* 是否存在区域节点
*
* @param baseAreaId 区域ID
* @return 结果
*/
boolean hasChildByBaseAreaId(String baseAreaId);
/**
* 构建前端所需要下拉树结构
*
* @param baseAreaList 区域列表
* @return 下拉树结构列表
*/
List<BaseAreaTreeSelect> buildBaseAreaTreeSelect(List<BaseAreaEntity> baseAreaList);
/**
* 根据父id查询子节点
* @param parentId
* @param context
* @return
*/
List<BaseAreaTreeSelect> getListByParentId(String parentId,Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.base.service.impl; package com.mortals.xhx.module.base.service.impl;
import org.springframework.stereotype.Service;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.base.dao.BaseAreaDao; import com.mortals.xhx.module.base.dao.BaseAreaDao;
import com.mortals.xhx.module.base.model.BaseAreaEntity; import com.mortals.xhx.module.base.model.BaseAreaEntity;
import com.mortals.xhx.module.base.model.BaseAreaQuery;
import com.mortals.xhx.module.base.service.BaseAreaService; import com.mortals.xhx.module.base.service.BaseAreaService;
import org.springframework.stereotype.Service; import com.mortals.xhx.module.base.model.BaseAreaTreeSelect;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* BaseAreaService * BaseAreaService
* 区域 service实现 * 区域 service实现
* *
* @author zxfei * @author zxfei
* @date 2022-11-22 * @date 2024-11-01
*/ */
@Service("baseAreaService") @Service("baseAreaService")
public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, BaseAreaEntity, Long> implements BaseAreaService { public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, BaseAreaEntity, Long> implements BaseAreaService {
/**
* 修改子元素关系
*
* @param baseAreaId 被修改的区域ID
* @param newAncestors 新的父ID集合
* @param oldAncestors 旧的父ID集合
*/
public void updateBaseAreaChildren(Long baseAreaId, String newAncestors, String oldAncestors, Context context) {
List<BaseAreaEntity> children = getDao().selectChildrenBaseAreaById(baseAreaId.toString());
for (BaseAreaEntity child : children) {
child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
}
if (children.size() > 0) {
this.updateAfter(children, context);
}
}
@Override
protected void removeBefore(Long[] ids, Context context) throws AppException {
//有子节点 禁止删除
if (!ObjectUtils.isEmpty(ids)) {
BaseAreaEntity baseAreaEntity = this.get(ids[0]);
if(hasChildByBaseAreaId(baseAreaEntity.getIid())){
throw new AppException("存在下级区域,不允许删除");
}
}
super.removeBefore(ids, context);
}
@Override
public boolean hasChildByBaseAreaId(String baseAreaId) {
List<BaseAreaEntity> list = this.find(new BaseAreaQuery().pid(baseAreaId));
return list.size() > 0 ? true : false;
}
@Override
public List<BaseAreaTreeSelect> buildBaseAreaTreeSelect(List<BaseAreaEntity> list) {
List<BaseAreaEntity> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(BaseAreaEntity::getId).collect(Collectors.toList());
for (Iterator<BaseAreaEntity> iterator = list.iterator(); iterator.hasNext(); ) {
BaseAreaEntity baseAreaEntity = iterator.next();
if (!tempList.contains(baseAreaEntity.getPid())) {
recursionFn(list, baseAreaEntity);
returnList.add(baseAreaEntity);
}
}
if (returnList.isEmpty()) {
returnList = list;
}
return returnList.stream().map(BaseAreaTreeSelect::new).collect(Collectors.toList());
}
/**
* 递归列表
*/
private void recursionFn(List<BaseAreaEntity> list, BaseAreaEntity t) {
// 得到子节点列表
List<BaseAreaEntity> childList = getChildList(list, t);
t.setChildren(childList);
for (BaseAreaEntity tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<BaseAreaEntity> list, BaseAreaEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
}
/**
* 得到子节点列表
*/
private List<BaseAreaEntity> getChildList(List<BaseAreaEntity> list, BaseAreaEntity t) {
return list.stream().map(item->{
if (!ObjectUtils.isEmpty(item.getPid()) && item.getPid().equals(t.getIid())) {
return item;
}
return null;
}).filter(f->f!=null).collect(Collectors.toList());
}
@Override
public List<BaseAreaTreeSelect> getListByParentId(String parentId, Context context) {
if (ObjectUtils.isEmpty(parentId)) {
parentId = "0";
}
//只做一层
List<BaseAreaTreeSelect> collect = this.find(new BaseAreaQuery().pid(parentId), context).stream().map(item -> new BaseAreaTreeSelect(item)
).collect(Collectors.toList());
return collect;
}
} }
\ No newline at end of file
package com.mortals.xhx.module.base.web; package com.mortals.xhx.module.base.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.base.model.BaseAreaEntity;
import com.mortals.xhx.module.base.service.BaseAreaService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.base.model.BaseAreaEntity;
import com.mortals.xhx.module.base.service.BaseAreaService;
import com.mortals.xhx.module.base.model.BaseAreaQuery;
import com.mortals.xhx.module.base.model.BaseAreaTreeSelect;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
import com.mortals.xhx.common.code.*;
/** /**
* 区域 *
* * 区域
* @author zxfei *
* @date 2022-11-22 * @author zxfei
*/ * @date 2024-11-01
*/
@RestController @RestController
@RequestMapping("base/area") @RequestMapping("base/area")
public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAreaService, BaseAreaEntity, Long> { public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAreaService,BaseAreaEntity,Long> {
@Autowired @Autowired
private ParamService paramService; private ParamService paramService;
@Autowired
private ICacheService cacheService;
public BaseAreaController() { public BaseAreaController(){
super.setModuleDesc("区域"); super.setModuleDesc( "区域");
} }
@Override @Override
protected void init(Map<String, Object> model, Context context) { protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "haveSonArea", paramService.getParamBySecondOrganize("BaseArea", "haveSonArea")); this.addDict(model, "haveSonArea", HaveSonAreaEnum.getEnumMap());
this.addDict(model, "haveSonDept", paramService.getParamBySecondOrganize("BaseArea", "haveSonDept")); this.addDict(model, "haveSonDept", HaveSonDeptEnum.getEnumMap());
this.addDict(model, "haveGetDept", paramService.getParamBySecondOrganize("BaseArea", "haveGetDept")); this.addDict(model, "haveGetDept", HaveGetDeptEnum.getEnumMap());
this.addDict(model, "haveGetMatterList", paramService.getParamBySecondOrganize("BaseArea", "haveGetMatterList")); this.addDict(model, "haveGetMatterList", HaveGetMatterListEnum.getEnumMap());
this.addDict(model, "areaLevel", paramService.getParamBySecondOrganize("BaseArea", "areaLevel")); this.addDict(model, "areaLevel", AreaLevelEnum.getEnumMap());
this.addDict(model, "status", paramService.getParamBySecondOrganize("BaseArea", "status")); this.addDict(model, "status", StatusEnum.getEnumMap());
super.init(model, context); super.init(model, context);
} }
/**
* 获取站点下拉树列表
*/
@PostMapping("treeselect")
@UnAuth
public String treeselect() {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
int code=VALUE_RESULT_SUCCESS;
try {
List<BaseAreaEntity> list = this.service.find(new BaseAreaQuery());
List<BaseAreaTreeSelect> treeSelects = this.service.buildBaseAreaTreeSelect(list);
model.put("result", treeSelects);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 根据parentId查询子信息
*/
@GetMapping(value = "getListByParentId")
@UnAuth
public String getListByParentId(String parentId) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc()+"子节点";
try {
List<BaseAreaTreeSelect> treeList = this.service.getListByParentId(parentId, getContext());
model.put(RESULT_KEY,treeList);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
recordSysLog(request, busiDesc+"【成功】");
} catch (Exception e) {
log.error("根据parentId查询子信息错误", e);
this.doException(request, busiDesc, model, e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
return ret.toJSONString();
}
} }
\ No newline at end of file
###登录
POST {{baseUrl}}/login/login
Content-Type: application/json
{
"loginName":"admin",
"password":"admin",
"securityCode":"8888"
}
> {%
client.global.set("SmsSet_id", JSON.parse(response.body).data.id);
client.global.set("authToken", JSON.parse(response.body).data.token);
%}
###区域列表
POST {{baseUrl}}/base/area/list
Content-Type: application/json
{
"page":1,
"size":10
}
###区域更新与保存
POST {{baseUrl}}/base/area/save
Authorization: {{authToken}}
Content-Type: application/json
{
"ancestors":"LdZ2li",
"name":"i3SKJc",
"iid":"suSUQY",
"pid":"uRSFOx",
"haveSonArea":"BfkquZ",
"haveSonDept":"pCokey",
"haveGetDept":"2yYsnf",
"haveGetMatterList":"r9jokc",
"areaCode":"gWJcgU",
"areaLevel":1,
"shortName":"fWbdcd",
"domain":"u7GMku",
"status":1,
}
> {%
client.global.set("BaseArea_id", JSON.parse(response.body).data.id);
%}
###区域查看
GET {{baseUrl}}/base/area/info?id=1
###区域编辑
GET {{baseUrl}}/base/area/edit?id=1
Accept: application/json
###区域删除
GET {{baseUrl}}/base/area/delete?id=1
Authorization: {{authToken}}
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