8 changed files with 633 additions and 0 deletions
@ -0,0 +1,107 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.commons.tools.validator.AssertUtils; |
|||
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|||
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; |
|||
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; |
|||
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; |
|||
import com.elink.esua.epdc.dto.CityDTO; |
|||
import com.elink.esua.epdc.dto.epdc.form.CityAreaFormDTO; |
|||
import com.elink.esua.epdc.excel.CityExcel; |
|||
import com.elink.esua.epdc.service.CityService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("city") |
|||
public class CityController { |
|||
|
|||
@Autowired |
|||
private CityService cityService; |
|||
|
|||
@GetMapping("page") |
|||
public Result<PageData<CityDTO>> page(@RequestParam Map<String, Object> params){ |
|||
PageData<CityDTO> page = cityService.page(params); |
|||
return new Result<PageData<CityDTO>>().ok(page); |
|||
} |
|||
|
|||
@GetMapping("{id}") |
|||
public Result<CityDTO> get(@PathVariable("id") String id){ |
|||
CityDTO data = cityService.get(id); |
|||
return new Result<CityDTO>().ok(data); |
|||
} |
|||
|
|||
@PostMapping |
|||
public Result save(@RequestBody CityDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|||
cityService.save(dto); |
|||
return new Result(); |
|||
} |
|||
|
|||
@PutMapping |
|||
public Result update(@RequestBody CityDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|||
cityService.update(dto); |
|||
return new Result(); |
|||
} |
|||
|
|||
@DeleteMapping |
|||
public Result delete(@RequestBody String[] ids){ |
|||
//效验数据
|
|||
AssertUtils.isArrayEmpty(ids, "id"); |
|||
cityService.delete(ids); |
|||
return new Result(); |
|||
} |
|||
|
|||
@GetMapping("export") |
|||
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception { |
|||
List<CityDTO> list = cityService.list(params); |
|||
ExcelUtils.exportExcelToTarget(response, null, list, CityExcel.class); |
|||
} |
|||
|
|||
/** |
|||
* @describe: 行程上报获取省/市/区/街道/社区信息,通过pid |
|||
* @author wangtong |
|||
* @date 2021/10/14 9:35 |
|||
* @params [formDto] |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
*/ |
|||
@GetMapping("export") |
|||
public Result getAreaInfo(@RequestBody CityAreaFormDTO dto) { |
|||
return cityService.getAreaInfo(dto); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.dao; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; |
|||
import com.elink.esua.epdc.dto.epdc.form.CityAreaFormDTO; |
|||
import com.elink.esua.epdc.entity.CityEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
@Mapper |
|||
public interface CityDao extends BaseDao<CityEntity> { |
|||
|
|||
/** |
|||
* @describe: 行程上报获取省/市/区/街道/社区信息,通过pid |
|||
* @author wangtong |
|||
* @date 2021/10/14 9:35 |
|||
* @params [formDto] |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
*/ |
|||
List<CityEntity> getAreaInfoByPid(CityAreaFormDTO dto); |
|||
} |
@ -0,0 +1,111 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("city") |
|||
public class CityEntity extends BaseEpdcEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 区划代码 |
|||
*/ |
|||
private Long id; |
|||
|
|||
/** |
|||
* 名称 |
|||
*/ |
|||
private String name; |
|||
|
|||
/** |
|||
* 父级区划代码 |
|||
*/ |
|||
private Long pid; |
|||
|
|||
/** |
|||
* 省代码 |
|||
*/ |
|||
private Long provinceCode; |
|||
|
|||
/** |
|||
* 市代码 |
|||
*/ |
|||
private Long cityCode; |
|||
|
|||
/** |
|||
* 区代码 |
|||
*/ |
|||
private Long areaCode; |
|||
|
|||
/** |
|||
* 街道代码 |
|||
*/ |
|||
private Long streetCode; |
|||
|
|||
/** |
|||
* 居委/社区 |
|||
*/ |
|||
private Long committeeCode; |
|||
|
|||
/** |
|||
* 简称 |
|||
*/ |
|||
private String shortName; |
|||
|
|||
/** |
|||
* 区号 |
|||
*/ |
|||
private String cityNo; |
|||
|
|||
/** |
|||
* 纬度 |
|||
*/ |
|||
private String lat; |
|||
|
|||
/** |
|||
* 经度 |
|||
*/ |
|||
private String lng; |
|||
|
|||
/** |
|||
* 排序 |
|||
*/ |
|||
private Integer sort; |
|||
|
|||
/** |
|||
* 级别: 0-国家 ,1-省, 2-市, 3-区/县, 4-街/镇, 5-社区/居委 |
|||
*/ |
|||
private Integer level; |
|||
|
|||
} |
@ -0,0 +1,77 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.excel; |
|||
|
|||
import cn.afterturn.easypoi.excel.annotation.Excel; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
@Data |
|||
public class CityExcel { |
|||
|
|||
@Excel(name = "区划代码") |
|||
private Long id; |
|||
|
|||
@Excel(name = "名称") |
|||
private String name; |
|||
|
|||
@Excel(name = "父级区划代码") |
|||
private Long pid; |
|||
|
|||
@Excel(name = "省代码") |
|||
private Long provinceCode; |
|||
|
|||
@Excel(name = "市代码") |
|||
private Long cityCode; |
|||
|
|||
@Excel(name = "区代码") |
|||
private Long areaCode; |
|||
|
|||
@Excel(name = "街道代码") |
|||
private Long streetCode; |
|||
|
|||
@Excel(name = "居委/社区") |
|||
private Long committeeCode; |
|||
|
|||
@Excel(name = "简称") |
|||
private String shortName; |
|||
|
|||
@Excel(name = "区号") |
|||
private String cityNo; |
|||
|
|||
@Excel(name = "纬度") |
|||
private String lat; |
|||
|
|||
@Excel(name = "经度") |
|||
private String lng; |
|||
|
|||
@Excel(name = "排序") |
|||
private Integer sort; |
|||
|
|||
@Excel(name = "级别: 0-国家 ,1-省, 2-市, 3-区/县, 4-街/镇, 5-社区/居委") |
|||
private Integer level; |
|||
|
|||
|
|||
} |
@ -0,0 +1,47 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.redis; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
@Component |
|||
public class CityRedis { |
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
public void delete(Object[] ids) { |
|||
|
|||
} |
|||
|
|||
public void set(){ |
|||
|
|||
} |
|||
|
|||
public String get(String id){ |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,106 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dto.CityDTO; |
|||
import com.elink.esua.epdc.dto.epdc.form.CityAreaFormDTO; |
|||
import com.elink.esua.epdc.entity.CityEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
public interface CityService extends BaseService<CityEntity> { |
|||
|
|||
/** |
|||
* 默认分页 |
|||
* |
|||
* @param params |
|||
* @return PageData<CityDTO> |
|||
* @author generator |
|||
* @date 2021-10-14 |
|||
*/ |
|||
PageData<CityDTO> page(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 默认查询 |
|||
* |
|||
* @param params |
|||
* @return java.util.List<CityDTO> |
|||
* @author generator |
|||
* @date 2021-10-14 |
|||
*/ |
|||
List<CityDTO> list(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 单条查询 |
|||
* |
|||
* @param id |
|||
* @return CityDTO |
|||
* @author generator |
|||
* @date 2021-10-14 |
|||
*/ |
|||
CityDTO get(String id); |
|||
|
|||
/** |
|||
* 默认保存 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-10-14 |
|||
*/ |
|||
void save(CityDTO dto); |
|||
|
|||
/** |
|||
* 默认更新 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-10-14 |
|||
*/ |
|||
void update(CityDTO dto); |
|||
|
|||
/** |
|||
* 批量删除 |
|||
* |
|||
* @param ids |
|||
* @return void |
|||
* @author generator |
|||
* @date 2021-10-14 |
|||
*/ |
|||
void delete(String[] ids); |
|||
|
|||
/** |
|||
* @describe: 行程上报获取省/市/区/街道/社区信息,通过pid |
|||
* @author wangtong |
|||
* @date 2021/10/14 9:35 |
|||
* @params [formDto] |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
*/ |
|||
Result getAreaInfo(CityAreaFormDTO dto); |
|||
} |
@ -0,0 +1,112 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|||
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dao.CityDao; |
|||
import com.elink.esua.epdc.dto.CityDTO; |
|||
import com.elink.esua.epdc.dto.epdc.form.CityAreaFormDTO; |
|||
import com.elink.esua.epdc.entity.CityEntity; |
|||
import com.elink.esua.epdc.redis.CityRedis; |
|||
import com.elink.esua.epdc.service.CityService; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 2019版全国5级信息表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2021-10-14 |
|||
*/ |
|||
@Service |
|||
public class CityServiceImpl extends BaseServiceImpl<CityDao, CityEntity> implements CityService { |
|||
|
|||
@Autowired |
|||
private CityRedis cityRedis; |
|||
|
|||
@Override |
|||
public PageData<CityDTO> page(Map<String, Object> params) { |
|||
IPage<CityEntity> page = baseDao.selectPage( |
|||
getPage(params, FieldConstant.CREATED_TIME, false), |
|||
getWrapper(params) |
|||
); |
|||
return getPageData(page, CityDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
public List<CityDTO> list(Map<String, Object> params) { |
|||
List<CityEntity> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, CityDTO.class); |
|||
} |
|||
|
|||
private QueryWrapper<CityEntity> getWrapper(Map<String, Object> params){ |
|||
String id = (String)params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<CityEntity> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|||
|
|||
return wrapper; |
|||
} |
|||
|
|||
@Override |
|||
public CityDTO get(String id) { |
|||
CityEntity entity = baseDao.selectById(id); |
|||
return ConvertUtils.sourceToTarget(entity, CityDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void save(CityDTO dto) { |
|||
CityEntity entity = ConvertUtils.sourceToTarget(dto, CityEntity.class); |
|||
insert(entity); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void update(CityDTO dto) { |
|||
CityEntity entity = ConvertUtils.sourceToTarget(dto, CityEntity.class); |
|||
updateById(entity); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void delete(String[] ids) { |
|||
// 逻辑删除(@TableLogic 注解)
|
|||
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|||
} |
|||
|
|||
@Override |
|||
public Result getAreaInfo(CityAreaFormDTO dto) { |
|||
List<CityEntity> result = baseDao.getAreaInfoByPid(dto); |
|||
return new Result().ok(result); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,29 @@ |
|||
<?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.elink.esua.epdc.dao.CityDao"> |
|||
|
|||
<resultMap type="com.elink.esua.epdc.entity.CityEntity" id="cityMap"> |
|||
<result property="id" column="id"/> |
|||
<result property="name" column="name"/> |
|||
<result property="pid" column="pid"/> |
|||
<result property="provinceCode" column="province_code"/> |
|||
<result property="cityCode" column="city_code"/> |
|||
<result property="areaCode" column="area_code"/> |
|||
<result property="streetCode" column="street_code"/> |
|||
<result property="committeeCode" column="committee_code"/> |
|||
<result property="shortName" column="short_name"/> |
|||
<result property="cityNo" column="city_no"/> |
|||
<result property="lat" column="lat"/> |
|||
<result property="lng" column="lng"/> |
|||
<result property="sort" column="sort"/> |
|||
<result property="level" column="level"/> |
|||
</resultMap> |
|||
<select id="getAreaInfoByPid" resultType="com.elink.esua.epdc.entity.CityEntity"> |
|||
SELECT * FROM CITY |
|||
WHERE pid=#{pid} |
|||
order by sort asc |
|||
</select> |
|||
|
|||
|
|||
</mapper> |
Loading…
Reference in new issue