12 changed files with 221 additions and 236 deletions
@ -1,59 +0,0 @@
@@ -1,59 +0,0 @@
|
||||
package com.cloud.kicc.system.api.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.cloud.kicc.common.data.entity.CommonEntity; |
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: TangSheng |
||||
* @Description: 地址管理实体 |
||||
* @Since 1.0 |
||||
* @Date Created in 9:57 2022/3/21 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@TableName(value="sys_address") |
||||
public class Address extends CommonEntity { |
||||
/** 编号 **/ |
||||
@ApiModelProperty("id") |
||||
@TableId(value = "id") |
||||
private String id; |
||||
@ApiModelProperty("编码") |
||||
private String code; |
||||
/** 父级编号 **/ |
||||
@ApiModelProperty("父级编号") |
||||
private String parentId; |
||||
|
||||
/** 名称 */ |
||||
@ApiModelProperty("名称") |
||||
protected String name; |
||||
|
||||
/** 排序 **/ |
||||
@ApiModelProperty("排序") |
||||
private Integer sort; |
||||
|
||||
@ApiModelProperty("子级集合") |
||||
@TableField(exist = false) |
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY) |
||||
protected List<Address> children = new ArrayList(); |
||||
|
||||
@ApiModelProperty("标识字段") |
||||
@TableField(exist = false) |
||||
private String fooLevel; |
||||
// @ApiModelProperty("层级")
|
||||
// private Integer level;
|
||||
|
||||
// @ApiModelProperty("排序")
|
||||
// private boolean lastLevel;
|
||||
|
||||
} |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
package com.cloud.kicc.system.api.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.cloud.kicc.common.data.entity.TreeEntity; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
*<p> |
||||
* 区域管理 |
||||
* 区域数据量太大了,采用懒加载形式处理 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @Date: 2022/7/18 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = false) |
||||
@Accessors(chain = true) |
||||
@TableName(value="sys_region", excludeProperty = { "remarks", "delFlag" }) |
||||
public class Region extends TreeEntity<Region> { |
||||
|
||||
/** 区域编码 */ |
||||
private String code; |
||||
|
||||
/** 地区级别 */ |
||||
private Integer level; |
||||
|
||||
/** 层级标记 */ |
||||
@TableField(exist = false) |
||||
private String tag; |
||||
|
||||
} |
@ -1,20 +0,0 @@
@@ -1,20 +0,0 @@
|
||||
package com.cloud.kicc.system.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.cloud.kicc.system.api.entity.Address; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: TangSheng |
||||
* @Description: |
||||
* @Since 1.0 |
||||
* @Date Created in 11:07 2022/3/21 |
||||
*/ |
||||
public interface AddressMapper extends BaseMapper<Address> { |
||||
|
||||
List<Address> lazyList(String parentId); |
||||
|
||||
List<Address> queryList(Address address); |
||||
|
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
package com.cloud.kicc.system.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.cloud.kicc.system.api.entity.Region; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: TangSheng |
||||
* @Description: |
||||
* @Since 1.0 |
||||
* @Date Created in 11:07 2022/3/21 |
||||
*/ |
||||
public interface RegionMapper extends BaseMapper<Region> { |
||||
|
||||
/** |
||||
* 懒加载查询 |
||||
* @param parentId 父节点 |
||||
* @return List |
||||
*/ |
||||
List<Region> lazyList(String parentId); |
||||
|
||||
/** |
||||
* 条件查询 |
||||
* @param region 区域对象 |
||||
* @return List |
||||
*/ |
||||
List<Region> queryList(Region region); |
||||
|
||||
} |
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
package com.cloud.kicc.system.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.cloud.kicc.system.api.entity.Address; |
||||
|
||||
import java.util.List; |
||||
|
||||
|
||||
public interface AddressService extends IService<Address> { |
||||
|
||||
|
||||
List<Address> lazyList(String parentId); |
||||
|
||||
List<Address> queryList(Address address); |
||||
|
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
package com.cloud.kicc.system.service; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.cloud.kicc.system.api.entity.Region; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
*<p> |
||||
* 区域服务 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @Date: 2022/7/18 |
||||
*/ |
||||
public interface RegionService extends IService<Region> { |
||||
|
||||
|
||||
/** |
||||
* 懒加载查询 |
||||
* @param parentId 父节点 |
||||
* @return List |
||||
*/ |
||||
List<Region> lazyList(String parentId); |
||||
|
||||
/** |
||||
* 条件查询 |
||||
* @param region 区域对象 |
||||
* @return List |
||||
*/ |
||||
List<Region> queryList(Region region); |
||||
|
||||
} |
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
package com.cloud.kicc.system.service.impl; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.cloud.kicc.system.api.entity.Address; |
||||
import com.cloud.kicc.system.mapper.AddressMapper; |
||||
import com.cloud.kicc.system.service.AddressService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
@Service |
||||
@RequiredArgsConstructor |
||||
@Slf4j |
||||
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService { |
||||
|
||||
|
||||
@Override |
||||
public List<Address> queryList(Address address) { |
||||
List<Address> addressList = this.baseMapper.queryList(address); |
||||
return addressList.stream().filter(item ->"1".equals(item.getFooLevel())) |
||||
.map(item -> { |
||||
List<Address> addresses = addressList.stream().filter(e -> "1".equals(item.getFooLevel())).collect(Collectors.toList()); |
||||
if(addresses.size() != 0) { |
||||
item.setChildren(addresses); |
||||
} |
||||
return item; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
|
||||
@Override |
||||
public List<Address> lazyList(String parentId) { |
||||
List<Address> addressList = this.baseMapper.lazyList(parentId); |
||||
return addressList.stream().filter(item -> item.getParentId().equals(parentId)) |
||||
.map(item -> { |
||||
List<Address> address = addressList.stream().filter(e -> e.getParentId().equals(item.getId())).collect(Collectors.toList()); |
||||
if(address.size() != 0) { |
||||
item.setChildren(address); |
||||
} |
||||
return item; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
package com.cloud.kicc.system.service.impl; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.cloud.kicc.system.api.entity.Region; |
||||
import com.cloud.kicc.system.mapper.RegionMapper; |
||||
import com.cloud.kicc.system.service.RegionService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
*<p> |
||||
* 区域服务实现 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @Date: 2022/7/18 |
||||
*/ |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements RegionService { |
||||
|
||||
@Override |
||||
public List<Region> queryList(Region region) { |
||||
List<Region> regionList = this.baseMapper.queryList(region); |
||||
return regionList.stream().filter(item ->"1".equals(item.getTag())) |
||||
.map(item -> { |
||||
List<Region> regions = regionList.stream().filter(e -> "1".equals(item.getTag())).collect(Collectors.toList()); |
||||
if(regions.size() != 0) { |
||||
item.setChildren(regions); |
||||
} |
||||
return item; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
|
||||
@Override |
||||
public List<Region> lazyList(String parentId) { |
||||
List<Region> regionList = this.baseMapper.lazyList(parentId); |
||||
return regionList.stream().filter(item -> item.getParentId().equals(parentId)) |
||||
.map(item -> { |
||||
List<Region> regions = regionList.stream().filter(e -> e.getParentId().equals(item.getId())).collect(Collectors.toList()); |
||||
if(regions.size() != 0) { |
||||
item.setChildren(regions); |
||||
} |
||||
return item; |
||||
}).collect(Collectors.toList()); |
||||
} |
||||
|
||||
} |
@ -1,74 +0,0 @@
@@ -1,74 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||
<mapper namespace="com.cloud.kicc.system.mapper.AddressMapper"> |
||||
|
||||
<resultMap id="AddressResult" type="com.cloud.kicc.system.api.entity.Address"> |
||||
<id column="id" property="id" /> |
||||
<result column="parent_id" property="parentId" /> |
||||
<!-- <result column="level" property="level" />--> |
||||
<!-- <result column="lastLevel" property="lastLevel" />--> |
||||
<result column="code" property="code" /> |
||||
<result column="name" property="name" /> |
||||
<result column="sort" property="sort" /> |
||||
<result column="tenant_id" property="tenantId" /> |
||||
<result column="create_by_id" property="createById"/> |
||||
<result column="create_by_name" property="createByName"/> |
||||
<result column="create_time" property="createTime"/> |
||||
<result column="update_by_id" property="updateById"/> |
||||
<result column="update_by_name" property="updateByName"/> |
||||
<result column="update_time" property="updateTime"/> |
||||
<result column="remarks" property="remarks"/> |
||||
<result column="del_flag" property="delFlag" /> |
||||
<result column="begin_time" property="beginTime"/> |
||||
<result column="end_time" property="endTime"/> |
||||
</resultMap> |
||||
|
||||
|
||||
<select id="queryList" resultType="com.cloud.kicc.system.api.entity.Address"> |
||||
|
||||
SELECT * FROM |
||||
( |
||||
SELECT *, '1' as 'fooLevel' FROM sys_address |
||||
where |
||||
<if test="name!=null and name!=''"> |
||||
name like concat('%',#{name},'%') |
||||
</if> |
||||
<if test="id!=null and id!=''"> |
||||
and id like concat('%',#{id},'%') |
||||
</if> |
||||
<if test="createTime!= null and createTime!=''"> |
||||
and createTime between #{beginTime} and #{endTime} |
||||
</if> |
||||
|
||||
UNION ALL |
||||
SELECT T2.*, '2' as 'fooLevel' FROM |
||||
(SELECT id FROM sys_address where |
||||
<if test="name!=null and name!=''"> |
||||
name like concat('%',#{name},'%') |
||||
</if> |
||||
<if test="id!=null and id!=''"> |
||||
and id like concat('%',#{id},'%') |
||||
</if> |
||||
<if test="createTime!= null and createTime!=''"> |
||||
and createTime between #{beginTime} and #{endTime} |
||||
</if> |
||||
|
||||
) T1, |
||||
sys_address T2 |
||||
WHERE T1.id = T2.parent_id |
||||
) result where del_flag ='0' |
||||
ORDER BY sort ASC |
||||
</select> |
||||
|
||||
<select id="lazyList" resultType="com.cloud.kicc.system.api.entity.Address"> |
||||
SELECT * FROM |
||||
( |
||||
SELECT * FROM sys_address where parent_id = #{parent_id} |
||||
UNION ALL |
||||
SELECT T2.* FROM (SELECT id FROM sys_address where parent_id = #{parent_id}) T1, sys_address T2 |
||||
WHERE T1.id = T2.parent_id |
||||
)result where del_flag ='0' |
||||
ORDER BY sort ASC |
||||
</select> |
||||
|
||||
</mapper> |
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||
<mapper namespace="com.cloud.kicc.system.mapper.RegionMapper"> |
||||
|
||||
<select id="queryList" resultType="com.cloud.kicc.system.api.entity.Region"> |
||||
select * from ( |
||||
select *, '1' as 'tag' from sys_region |
||||
<where> |
||||
<if test="name != null and name != ''"> |
||||
name like concat(#{name},'%') |
||||
</if> |
||||
<if test="code != null and code!=''"> |
||||
and code = #{code} |
||||
</if> |
||||
<if test="createTime != null and createTime != ''"> |
||||
and createTime between #{beginTime} and #{endTime} |
||||
</if> |
||||
</where> |
||||
union all |
||||
select T2.*, '2' as 'tag' from |
||||
(select id from sys_region |
||||
<where> |
||||
<if test="name != null and name != ''"> |
||||
and name like concat(#{name},'%') |
||||
</if> |
||||
<if test="code != null and code != ''"> |
||||
and code = #{code} |
||||
</if> |
||||
<if test="createTime != null and createTime != ''"> |
||||
and createTime between #{beginTime} and #{endTime} |
||||
</if> |
||||
</where> |
||||
) T1, sys_region T2 |
||||
WHERE T1.id = T2.parent_id |
||||
) result where del_flag ='0' |
||||
ORDER BY sort ASC |
||||
</select> |
||||
|
||||
<select id="lazyList" parameterType="String" resultType="com.cloud.kicc.system.api.entity.Region"> |
||||
SELECT * FROM |
||||
( |
||||
SELECT * FROM sys_region where parent_id = #{parentId} |
||||
UNION ALL |
||||
SELECT T2.* FROM (SELECT id FROM sys_region where parent_id = #{parentId}) T1, sys_region T2 |
||||
WHERE T1.id = T2.parent_id |
||||
)result where del_flag ='0' |
||||
ORDER BY sort ASC |
||||
</select> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue