1.30晚
parent
cd71fed7e4
commit
0eabfde4d9
|
@ -1,12 +1,12 @@
|
||||||
package HomeWork.community.controller;
|
package HomeWork.community.controller;
|
||||||
|
|
||||||
import HomeWork.community.domain.City;
|
import HomeWork.common.core.domain.R;
|
||||||
import HomeWork.community.domain.Province;
|
import HomeWork.community.domain.dto.PlotDto;
|
||||||
|
import HomeWork.community.domain.vo.PlotVo;
|
||||||
|
import HomeWork.community.domain.vo.TreeVo;
|
||||||
import HomeWork.community.service.CommunityService;
|
import HomeWork.community.service.CommunityService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -21,19 +21,18 @@ import java.util.List;
|
||||||
public class CommunityController {
|
public class CommunityController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommunityService communityService;
|
private CommunityService communityService;
|
||||||
@PostMapping("/province")
|
@GetMapping("/tree/list")
|
||||||
public List<Province> province(){
|
public R<List<TreeVo>> treeList() {
|
||||||
List<Province> list = communityService.province();
|
List<TreeVo> list = communityService.list();
|
||||||
return list;
|
return R.ok(list);
|
||||||
}
|
}
|
||||||
@PostMapping("/city")
|
@PostMapping("/plot/{id}")
|
||||||
public List<City> city(){
|
public R<List<PlotVo>> plot(@PathVariable Integer id) {
|
||||||
List<City> list = communityService.city();
|
List<PlotVo> plotVos= communityService.plotList(id);
|
||||||
return list;
|
return R.ok(plotVos);
|
||||||
}
|
}
|
||||||
@PostMapping("/district")
|
@PostMapping("/add")
|
||||||
public List<City> district(){
|
public R add(@RequestBody PlotDto plotDto) {
|
||||||
List<City> list = communityService.district();
|
return R.ok(communityService.add(plotDto));
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package HomeWork.community.domain;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName : City
|
|
||||||
* @Description : 市
|
|
||||||
* @Author : FJJ
|
|
||||||
* @Date: 2024-01-30 16:31
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class City {
|
|
||||||
private int cityId;
|
|
||||||
private String name;
|
|
||||||
private Province province;
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package HomeWork.community.domain;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName : District
|
|
||||||
* @Description : 区
|
|
||||||
* @Author : FJJ
|
|
||||||
* @Date: 2024-01-30 16:32
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class District {
|
|
||||||
private int districtId;
|
|
||||||
private String name;
|
|
||||||
private City city;
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package HomeWork.community.domain;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName : Province
|
|
||||||
* @Description : 省
|
|
||||||
* @Author : FJJ
|
|
||||||
* @Date: 2024-01-30 16:30
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Province {
|
|
||||||
private Integer id;
|
|
||||||
private String name;
|
|
||||||
}
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package HomeWork.community.domain.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PlotDto {
|
||||||
|
private String name;
|
||||||
|
private String num;
|
||||||
|
private String img;
|
||||||
|
private Integer parentId;
|
||||||
|
private String address;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package HomeWork.community.domain.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PlotEntity {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer parentId;
|
||||||
|
private String address;
|
||||||
|
private String img;
|
||||||
|
private Integer building;
|
||||||
|
private Integer tenement;
|
||||||
|
private String num;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package HomeWork.community.domain.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : Tree
|
||||||
|
* @Description :目录树
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2024-01-30 20:15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TreeEntity {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer parentId;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package HomeWork.community.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PlotVo {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer parentId;
|
||||||
|
private String address;
|
||||||
|
private String img;
|
||||||
|
private Integer building;
|
||||||
|
private Integer tenement;
|
||||||
|
private String num;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package HomeWork.community.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName : Tree
|
||||||
|
* @Description :目录树
|
||||||
|
* @Author : FJJ
|
||||||
|
* @Date: 2024-01-30 20:15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TreeVo {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer parentId;
|
||||||
|
private List<TreeVo> children;
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package HomeWork.community.mapper;
|
package HomeWork.community.mapper;
|
||||||
|
|
||||||
import HomeWork.community.domain.City;
|
import HomeWork.community.domain.dto.PlotDto;
|
||||||
import HomeWork.community.domain.Province;
|
import HomeWork.community.domain.entity.TreeEntity;
|
||||||
|
import HomeWork.community.domain.vo.PlotVo;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,9 +16,17 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CommunityMapper {
|
public interface CommunityMapper {
|
||||||
List<Province> province();
|
|
||||||
|
|
||||||
List<City> city();
|
|
||||||
|
|
||||||
List<City> district();
|
List<TreeEntity> findChildren(@Param("id") Integer id);
|
||||||
|
|
||||||
|
List<TreeEntity> treeListByTreeParentId(Integer parentId);
|
||||||
|
|
||||||
|
List<TreeEntity> treeListByTreeIds(@Param("ids")String[] split);
|
||||||
|
|
||||||
|
List<TreeEntity> treeList();
|
||||||
|
|
||||||
|
List<PlotVo> plotList(@Param("id") Integer id);
|
||||||
|
|
||||||
|
int add(PlotDto plotDto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package HomeWork.community.service;
|
package HomeWork.community.service;
|
||||||
|
|
||||||
import HomeWork.community.domain.City;
|
import HomeWork.common.core.domain.R;
|
||||||
import HomeWork.community.domain.Province;
|
import HomeWork.community.domain.dto.PlotDto;
|
||||||
|
import HomeWork.community.domain.vo.PlotVo;
|
||||||
|
import HomeWork.community.domain.vo.TreeVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,9 +14,10 @@ import java.util.List;
|
||||||
* @Date: 2024-01-30 16:41
|
* @Date: 2024-01-30 16:41
|
||||||
*/
|
*/
|
||||||
public interface CommunityService {
|
public interface CommunityService {
|
||||||
List<Province> province();
|
|
||||||
|
|
||||||
List<City> city();
|
List<TreeVo> list();
|
||||||
|
|
||||||
List<City> district();
|
List<PlotVo> plotList(Integer id);
|
||||||
|
|
||||||
|
R add(PlotDto plotDto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package HomeWork.community.service.serviceImpl;
|
package HomeWork.community.service.serviceImpl;
|
||||||
|
|
||||||
import HomeWork.community.domain.City;
|
import HomeWork.common.core.domain.R;
|
||||||
import HomeWork.community.domain.Province;
|
import HomeWork.community.domain.dto.PlotDto;
|
||||||
|
import HomeWork.community.domain.entity.TreeEntity;
|
||||||
|
import HomeWork.community.domain.vo.PlotVo;
|
||||||
|
import HomeWork.community.domain.vo.TreeVo;
|
||||||
import HomeWork.community.mapper.CommunityMapper;
|
import HomeWork.community.mapper.CommunityMapper;
|
||||||
import HomeWork.community.service.CommunityService;
|
import HomeWork.community.service.CommunityService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
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 java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,18 +24,54 @@ import java.util.List;
|
||||||
public class CommunityServiceImpl implements CommunityService {
|
public class CommunityServiceImpl implements CommunityService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CommunityMapper communityMapper;
|
private CommunityMapper communityMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Province> province() {
|
public List<TreeVo> list() {
|
||||||
return communityMapper.province();
|
ArrayList<TreeVo> treeVos = new ArrayList<>();
|
||||||
|
List<TreeEntity> treeVoList = communityMapper.treeList();
|
||||||
|
if (treeVoList.size()>0){
|
||||||
|
for (TreeEntity tree : treeVoList) {
|
||||||
|
TreeVo treeVo = new TreeVo();
|
||||||
|
BeanUtils.copyProperties(tree,treeVo);
|
||||||
|
List<TreeVo> children = findChildren(tree.getId());
|
||||||
|
treeVo.setChildren(children);
|
||||||
|
treeVos.add(treeVo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return treeVos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<City> city() {
|
public List<PlotVo> plotList(Integer id) {
|
||||||
return communityMapper.city();
|
return communityMapper.plotList(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<City> district() {
|
public R add(PlotDto plotDto) {
|
||||||
return communityMapper.district();
|
if (communityMapper.add(plotDto)==0){
|
||||||
|
return R.fail("添加失败");
|
||||||
|
}
|
||||||
|
return R.ok("添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TreeVo> findChildren(Integer id) {
|
||||||
|
ArrayList<TreeVo> treeVos = new ArrayList<>();
|
||||||
|
List<TreeEntity> treeEntities = communityMapper.findChildren(id);
|
||||||
|
String ids="";
|
||||||
|
for (TreeEntity treeVo : treeEntities) {
|
||||||
|
ids+=treeVo.getId()+",";
|
||||||
|
}
|
||||||
|
String[] split = ids.split(",");
|
||||||
|
List<TreeEntity> treeVos1 = communityMapper.treeListByTreeIds(split);
|
||||||
|
for (TreeEntity treeVo : treeVos1) {
|
||||||
|
TreeVo treeVo1 = new TreeVo();
|
||||||
|
BeanUtils.copyProperties(treeVo,treeVo1);
|
||||||
|
List<TreeEntity> children = communityMapper.findChildren(treeVo1.getId());
|
||||||
|
if (children.size()>0){
|
||||||
|
treeVo1.setChildren(findChildren(treeVo1.getId()));
|
||||||
|
}
|
||||||
|
treeVos.add(treeVo1);
|
||||||
|
}
|
||||||
|
return treeVos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,30 @@
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="HomeWork.community.mapper.CommunityMapper">
|
<mapper namespace="HomeWork.community.mapper.CommunityMapper">
|
||||||
|
<insert id="add">
|
||||||
|
insert into plot
|
||||||
|
values (0, #{name}, #{parentId}, #{address}, #{img}, null, null,#{num})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
<select id="province" resultType="HomeWork.community.domain.Province">
|
<select id="findChildren" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||||
select * from t_province
|
select *
|
||||||
|
from tree
|
||||||
|
where parent_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
<select id="city" resultType="HomeWork.community.domain.City">
|
<select id="treeListByTreeIds" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||||
select * from t_city
|
select * from tree where id in
|
||||||
|
<foreach collection="ids" item="treeId" open="(" separator="," close=")">
|
||||||
|
#{treeId}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
<select id="district" resultType="HomeWork.community.domain.City">
|
<select id="treeList" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||||
select * from t_district
|
select * from tree where parent_id=0
|
||||||
|
</select>
|
||||||
|
<select id="treeListByTreeParentId" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||||
|
select * from tree where id = #{parentId}
|
||||||
|
</select>
|
||||||
|
<select id="plotList" resultType="HomeWork.community.domain.vo.PlotVo">
|
||||||
|
select * from plot where parent_id=#{id}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue