From 245ab3bcc323dbcc877f8d49fb725b2eec91e118 Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Tue, 12 Jun 2018 08:46:33 +0800
Subject: [PATCH] 区域 增加 镇村选项
---
src/main/java/com/moral/service/AreaService.java | 5 ++
src/main/java/com/moral/entity/AreaNames.java | 2 +
src/main/resources/mapper/DeviceMapper.xml | 12 ++++++
src/main/resources/mapper/HistoryMinutelyMapper.xml | 6 +--
src/main/java/com/moral/mapper/VillageMapper.java | 7 +++
src/main/java/com/moral/service/impl/AreaServiceImpl.java | 24 ++++++++++++
src/main/resources/mapper/MonitorPointMapper.xml | 4 ++
src/main/java/com/moral/entity/Village.java | 25 ++++++++++++
src/main/java/com/moral/controller/AreaController.java | 20 ++++++++++
9 files changed, 101 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/moral/controller/AreaController.java b/src/main/java/com/moral/controller/AreaController.java
index 4a2a58b..e43be29 100644
--- a/src/main/java/com/moral/controller/AreaController.java
+++ b/src/main/java/com/moral/controller/AreaController.java
@@ -4,6 +4,8 @@
import com.moral.entity.Area;
import com.moral.entity.City;
import com.moral.entity.Province;
+import com.moral.entity.Town;
+import com.moral.entity.Village;
import com.moral.service.AreaService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@@ -47,4 +49,22 @@
resultBean.setCode(ResultBean.SUCCESS);
return resultBean;
}
+
+ @GetMapping("get-towns")
+ public ResultBean<List<Town>> getTowns(int areaCode){
+ ResultBean<List<Town>> resultBean = new ResultBean<>();
+ List<Town> list = areaService.getTowns(areaCode);
+ resultBean.setData(list);
+ resultBean.setCode(ResultBean.SUCCESS);
+ return resultBean;
+ }
+
+ @GetMapping("get-villages")
+ public ResultBean<List<Village>> getVillages(Long townCode){
+ ResultBean<List<Village>> resultBean = new ResultBean<>();
+ List<Village> list = areaService.getVillages(townCode);
+ resultBean.setData(list);
+ resultBean.setCode(ResultBean.SUCCESS);
+ return resultBean;
+ }
}
diff --git a/src/main/java/com/moral/entity/AreaNames.java b/src/main/java/com/moral/entity/AreaNames.java
index 9e7021e..e3a6f4c 100644
--- a/src/main/java/com/moral/entity/AreaNames.java
+++ b/src/main/java/com/moral/entity/AreaNames.java
@@ -7,4 +7,6 @@
private String provinceName;
private String cityName;
private String areaName;
+ private String townName;
+ private String villageName;
}
diff --git a/src/main/java/com/moral/entity/Village.java b/src/main/java/com/moral/entity/Village.java
new file mode 100644
index 0000000..d367ab6
--- /dev/null
+++ b/src/main/java/com/moral/entity/Village.java
@@ -0,0 +1,25 @@
+package com.moral.entity;
+
+import javax.persistence.Id;
+
+import lombok.Data;
+
+@Data
+public class Village {
+ /**
+ * This field was generated by MyBatis Generator. This field corresponds to the database column village.village_code
+ * @mbg.generated Mon Jun 11 14:09:26 CST 2018
+ */
+ @Id
+ private Long villageCode;
+ /**
+ * This field was generated by MyBatis Generator. This field corresponds to the database column village.village_name
+ * @mbg.generated Mon Jun 11 14:09:26 CST 2018
+ */
+ private String villageName;
+ /**
+ * This field was generated by MyBatis Generator. This field corresponds to the database column village.town_code
+ * @mbg.generated Mon Jun 11 14:09:26 CST 2018
+ */
+ private Long townCode;
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/mapper/VillageMapper.java b/src/main/java/com/moral/mapper/VillageMapper.java
new file mode 100644
index 0000000..d54bad7
--- /dev/null
+++ b/src/main/java/com/moral/mapper/VillageMapper.java
@@ -0,0 +1,7 @@
+package com.moral.mapper;
+
+import com.moral.common.mapper.BaseMapper;
+import com.moral.entity.Village;
+
+public interface VillageMapper extends BaseMapper<Village>{
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/service/AreaService.java b/src/main/java/com/moral/service/AreaService.java
index 9df15cd..8c381b4 100644
--- a/src/main/java/com/moral/service/AreaService.java
+++ b/src/main/java/com/moral/service/AreaService.java
@@ -3,6 +3,8 @@
import com.moral.entity.Area;
import com.moral.entity.City;
import com.moral.entity.Province;
+import com.moral.entity.Town;
+import com.moral.entity.Village;
import java.util.List;
@@ -12,4 +14,7 @@
List<Area> getAreas(int cityCode);
String queryFullNameByCode(Integer code);
+
+ List<Town> getTowns(Integer areaCode);
+ List<Village> getVillages(Long townCode);
}
diff --git a/src/main/java/com/moral/service/impl/AreaServiceImpl.java b/src/main/java/com/moral/service/impl/AreaServiceImpl.java
index 1706532..3f5b3db 100644
--- a/src/main/java/com/moral/service/impl/AreaServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/AreaServiceImpl.java
@@ -3,9 +3,13 @@
import com.moral.entity.Area;
import com.moral.entity.City;
import com.moral.entity.Province;
+import com.moral.entity.Town;
+import com.moral.entity.Village;
import com.moral.mapper.AreaMapper;
import com.moral.mapper.CityMapper;
import com.moral.mapper.ProvinceMapper;
+import com.moral.mapper.TownMapper;
+import com.moral.mapper.VillageMapper;
import com.moral.service.AreaService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
@@ -22,6 +26,12 @@
CityMapper cityMapper;
@Resource
AreaMapper areaMapper;
+
+ @Resource
+ private TownMapper townMapper;
+
+ @Resource
+ private VillageMapper villageMapper;
@Override
public List<Province> getProvinces() {
@@ -75,4 +85,18 @@
}
return fullName;
}
+
+ @Override
+ public List<Town> getTowns(Integer areaCode) {
+ Example example = new Example(Town.class);
+ example.or().andEqualTo("areaCode",areaCode);
+ return townMapper.selectByExample(example);
+ }
+
+ @Override
+ public List<Village> getVillages(Long townCode) {
+ Example example = new Example(Village.class);
+ example.createCriteria().andEqualTo("townCode",townCode);
+ return villageMapper.selectByExample(example);
+ }
}
diff --git a/src/main/resources/mapper/DeviceMapper.xml b/src/main/resources/mapper/DeviceMapper.xml
index b9d9f2b..dec7671 100644
--- a/src/main/resources/mapper/DeviceMapper.xml
+++ b/src/main/resources/mapper/DeviceMapper.xml
@@ -259,6 +259,12 @@
<if test="areaCode != null">
AND mp.area_code = #{areaCode}
</if>
+ <if test="townCode != null">
+ AND mp.town_code = #{townCode}
+ </if>
+ <if test="villageCode != null">
+ AND mp.village_code = #{villageCode}
+ </if>
)
<if test="professionId != null">
AND d.profession_id = #{professionId}
@@ -291,6 +297,12 @@
<if test="monitorPointId != null">
AND mp.id = #{monitorPointId}
</if>
+ <if test="townCode != null">
+ AND mp.town_code = #{townCode}
+ </if>
+ <if test="villageCode != null">
+ AND mp.village_code = #{villageCode}
+ </if>
)
<if test="professionId != null">
AND d.profession_id = #{professionId}
diff --git a/src/main/resources/mapper/HistoryMinutelyMapper.xml b/src/main/resources/mapper/HistoryMinutelyMapper.xml
index 70c57d3..d9c4cd8 100644
--- a/src/main/resources/mapper/HistoryMinutelyMapper.xml
+++ b/src/main/resources/mapper/HistoryMinutelyMapper.xml
@@ -17,13 +17,11 @@
(SELECT
d.mac
FROM
- device d,
- monitor_point mp
+ device d
WHERE
d.is_delete = 0
- AND d.monitor_point_id = mp.id
<if test="monitorPointId != null">
- AND mp.id = #{monitorPointId}
+ AND d.monitor_point_id = #{monitorPointId}
</if>
<if test="mac != null">
AND d.mac = #{mac}
diff --git a/src/main/resources/mapper/MonitorPointMapper.xml b/src/main/resources/mapper/MonitorPointMapper.xml
index ed57416..9088367 100644
--- a/src/main/resources/mapper/MonitorPointMapper.xml
+++ b/src/main/resources/mapper/MonitorPointMapper.xml
@@ -19,6 +19,8 @@
<result column="province_name" property="provinceName" jdbcType="VARCHAR" />
<result column="city_name" property="cityName" jdbcType="VARCHAR" />
<result column="area_name" property="areaName" jdbcType="VARCHAR" />
+ <result column="town_name" property="townName" jdbcType="VARCHAR" />
+ <result column="village_name" property="villageName" jdbcType="VARCHAR" />
</association>
<association property="organization" javaType="com.moral.entity.Organization">
<result column="organization_id" property="id" jdbcType="INTEGER" />
@@ -74,6 +76,8 @@
left join city cti on mpt.city_code = cti.city_code
left join province pro on mpt.province_code = pro.province_code
left join organization org on mpt.organization_id = org.id
+ left join town t on mpt.town_code = t.town_code
+ left join village v on mpt.village_code = v.village_code
where mpt.id in (
select id from monitor_point
<if test="_parameter != null">
--
Gitblit v1.8.0