1.30晚
parent
cd71fed7e4
commit
0eabfde4d9
|
@ -1,12 +1,12 @@
|
|||
package HomeWork.community.controller;
|
||||
|
||||
import HomeWork.community.domain.City;
|
||||
import HomeWork.community.domain.Province;
|
||||
import HomeWork.common.core.domain.R;
|
||||
import HomeWork.community.domain.dto.PlotDto;
|
||||
import HomeWork.community.domain.vo.PlotVo;
|
||||
import HomeWork.community.domain.vo.TreeVo;
|
||||
import HomeWork.community.service.CommunityService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -21,19 +21,18 @@ import java.util.List;
|
|||
public class CommunityController {
|
||||
@Autowired
|
||||
private CommunityService communityService;
|
||||
@PostMapping("/province")
|
||||
public List<Province> province(){
|
||||
List<Province> list = communityService.province();
|
||||
return list;
|
||||
@GetMapping("/tree/list")
|
||||
public R<List<TreeVo>> treeList() {
|
||||
List<TreeVo> list = communityService.list();
|
||||
return R.ok(list);
|
||||
}
|
||||
@PostMapping("/city")
|
||||
public List<City> city(){
|
||||
List<City> list = communityService.city();
|
||||
return list;
|
||||
@PostMapping("/plot/{id}")
|
||||
public R<List<PlotVo>> plot(@PathVariable Integer id) {
|
||||
List<PlotVo> plotVos= communityService.plotList(id);
|
||||
return R.ok(plotVos);
|
||||
}
|
||||
@PostMapping("/district")
|
||||
public List<City> district(){
|
||||
List<City> list = communityService.district();
|
||||
return list;
|
||||
@PostMapping("/add")
|
||||
public R add(@RequestBody PlotDto plotDto) {
|
||||
return R.ok(communityService.add(plotDto));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
import HomeWork.community.domain.City;
|
||||
import HomeWork.community.domain.Province;
|
||||
import HomeWork.community.domain.dto.PlotDto;
|
||||
import HomeWork.community.domain.entity.TreeEntity;
|
||||
import HomeWork.community.domain.vo.PlotVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -14,9 +16,17 @@ import java.util.List;
|
|||
*/
|
||||
@Mapper
|
||||
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;
|
||||
|
||||
import HomeWork.community.domain.City;
|
||||
import HomeWork.community.domain.Province;
|
||||
import HomeWork.common.core.domain.R;
|
||||
import HomeWork.community.domain.dto.PlotDto;
|
||||
import HomeWork.community.domain.vo.PlotVo;
|
||||
import HomeWork.community.domain.vo.TreeVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,9 +14,10 @@ import java.util.List;
|
|||
* @Date: 2024-01-30 16:41
|
||||
*/
|
||||
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;
|
||||
|
||||
import HomeWork.community.domain.City;
|
||||
import HomeWork.community.domain.Province;
|
||||
import HomeWork.common.core.domain.R;
|
||||
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.service.CommunityService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -19,18 +24,54 @@ import java.util.List;
|
|||
public class CommunityServiceImpl implements CommunityService {
|
||||
@Autowired
|
||||
private CommunityMapper communityMapper;
|
||||
|
||||
@Override
|
||||
public List<Province> province() {
|
||||
return communityMapper.province();
|
||||
public List<TreeVo> list() {
|
||||
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
|
||||
public List<City> city() {
|
||||
return communityMapper.city();
|
||||
public List<PlotVo> plotList(Integer id) {
|
||||
return communityMapper.plotList(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<City> district() {
|
||||
return communityMapper.district();
|
||||
public R add(PlotDto plotDto) {
|
||||
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"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<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 * from t_province
|
||||
<select id="findChildren" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||
select *
|
||||
from tree
|
||||
where parent_id = #{id}
|
||||
</select>
|
||||
<select id="city" resultType="HomeWork.community.domain.City">
|
||||
select * from t_city
|
||||
<select id="treeListByTreeIds" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||
select * from tree where id in
|
||||
<foreach collection="ids" item="treeId" open="(" separator="," close=")">
|
||||
#{treeId}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="district" resultType="HomeWork.community.domain.City">
|
||||
select * from t_district
|
||||
<select id="treeList" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||
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>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue