15 changed files with 657 additions and 16 deletions
@ -0,0 +1,71 @@ |
|||
/** |
|||
* 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.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 行政区划 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:22 |
|||
*/ |
|||
@Data |
|||
public class AreaDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 9173956433924027751L; |
|||
|
|||
/** |
|||
* ID |
|||
*/ |
|||
private Integer id; |
|||
/** |
|||
* 父级ID |
|||
*/ |
|||
private Integer parentId; |
|||
/** |
|||
* 名称 |
|||
*/ |
|||
private String name; |
|||
/** |
|||
* 简称 |
|||
*/ |
|||
private String shortName; |
|||
/** |
|||
* 经度 |
|||
*/ |
|||
private Float longitude; |
|||
/** |
|||
* 纬度 |
|||
*/ |
|||
private Float latitude; |
|||
/** |
|||
* 等级(1省/直辖市,2地级市,3区县,4镇/街道) |
|||
*/ |
|||
private Integer level; |
|||
/** |
|||
* 排序 |
|||
*/ |
|||
private Integer sort; |
|||
/** |
|||
* 状态(0禁用/1启用) |
|||
*/ |
|||
private Integer status; |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
|
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
/** |
|||
* 行政区划简要信息 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:22 |
|||
*/ |
|||
@Data |
|||
public class SimpleAreaDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -3243672014476007901L; |
|||
|
|||
/** |
|||
* ID |
|||
*/ |
|||
private Integer id; |
|||
/** |
|||
* 名称 |
|||
*/ |
|||
private String name; |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
|
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 数据字典简要信息 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/7/15 09:29 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "数据字典") |
|||
public class SysSimpleDictDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -4827806651372425347L; |
|||
|
|||
@ApiModelProperty(value = "字典名称") |
|||
@NotBlank(message = "{sysdict.name.require}", groups = DefaultGroup.class) |
|||
private String dictName; |
|||
|
|||
@ApiModelProperty(value = "字典值") |
|||
private String dictValue; |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
|
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dto.SimpleAreaDTO; |
|||
import com.elink.esua.epdc.service.AreaService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PathVariable; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* 获取行政区划 |
|||
* |
|||
* @author liuhongwei @elink-cn.com |
|||
* @since v1.0.0 2019-05-13 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("area") |
|||
public class AreaController { |
|||
|
|||
@Autowired |
|||
private AreaService areaService; |
|||
|
|||
/** |
|||
* 根据区划ID,获取下属区域列表 |
|||
* |
|||
* @param areaId |
|||
* @return com.elink.esua.commons.tools.utils.Result<java.util.List < com.elink.esua.dto.AreaDTO>> |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:28 |
|||
*/ |
|||
@GetMapping("listSimple/{areaId}") |
|||
public Result<List<SimpleAreaDTO>> listSimpleAreaInfo(@PathVariable("areaId") String areaId) { |
|||
return this.areaService.listSimpleAreaInfo(areaId); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
|
|||
package com.elink.esua.epdc.dao; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; |
|||
import com.elink.esua.epdc.entity.AreaEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:54 |
|||
*/ |
|||
@Mapper |
|||
public interface AreaDao extends BaseDao<AreaEntity> { |
|||
|
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
package com.elink.esua.epdc.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 行政区划 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:25 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@TableName("area") |
|||
public class AreaEntity implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -2139014717755304245L; |
|||
|
|||
/** |
|||
* ID |
|||
*/ |
|||
private Integer id; |
|||
/** |
|||
* 父级ID |
|||
*/ |
|||
private Integer parentId; |
|||
/** |
|||
* 名称 |
|||
*/ |
|||
private String name; |
|||
/** |
|||
* 简称 |
|||
*/ |
|||
private String shortName; |
|||
/** |
|||
* 经度 |
|||
*/ |
|||
private Float longitude; |
|||
/** |
|||
* 纬度 |
|||
*/ |
|||
private Float latitude; |
|||
/** |
|||
* 等级(1省/直辖市,2地级市,3区县,4镇/街道) |
|||
*/ |
|||
private Integer level; |
|||
/** |
|||
* 排序 |
|||
*/ |
|||
private Integer sort; |
|||
/** |
|||
* 状态(0禁用/1启用) |
|||
*/ |
|||
private Integer status; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
/** |
|||
* 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.RedisKeys; |
|||
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|||
import com.elink.esua.epdc.dto.SimpleAreaDTO; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 区划信息表 |
|||
* |
|||
* @author yujintao yujintao@elink-cn.com |
|||
* @since v1.0.0 2019-05-08 |
|||
*/ |
|||
@Component |
|||
public class AreaRedis { |
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
/** |
|||
* 取出区划信息 |
|||
* |
|||
* @param areaId 区域ID |
|||
* @return java.lang.String |
|||
* @author yujintao |
|||
* @date 2019/6/13 11:05 |
|||
*/ |
|||
public List<SimpleAreaDTO> getSimpleAreaList(String areaId) { |
|||
String configAreaKey = RedisKeys.getSimpleAreaKey(areaId); |
|||
return (List<SimpleAreaDTO>) redisUtils.get(configAreaKey); |
|||
} |
|||
|
|||
/** |
|||
* 缓存区划信息 |
|||
* |
|||
* @param areaId |
|||
* @param areaDtoList |
|||
* @return void |
|||
* @author yujintao |
|||
* @date 2019/6/13 11:02 |
|||
*/ |
|||
public void setSimpleAreaList(String areaId, List<SimpleAreaDTO> areaDtoList) { |
|||
String configAreaKey = RedisKeys.getSimpleAreaKey(areaId); |
|||
redisUtils.set(configAreaKey, areaDtoList); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
/** |
|||
* 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.RedisKeys; |
|||
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|||
import com.elink.esua.epdc.dto.SimpleAreaDTO; |
|||
import com.elink.esua.epdc.dto.SysSimpleDictDTO; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 区划信息表 |
|||
* |
|||
* @author yujintao yujintao@elink-cn.com |
|||
* @since v1.0.0 2019-05-08 |
|||
*/ |
|||
@Component |
|||
public class SysDictRedis { |
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
/** |
|||
* 根据数据字典类型,从redis获取简版数据字典列表 |
|||
* |
|||
* @param dictType 数据字典类型 |
|||
* @return java.util.List<com.elink.esua.dto.SysSimpleDictDTO> |
|||
* @author yujintao |
|||
* @date 2019/7/15 09:42 |
|||
*/ |
|||
public List<SysSimpleDictDTO> getSimpleDictList(String dictType) { |
|||
String dictKey = RedisKeys.getSimpleDictKey(dictType); |
|||
return (List<SysSimpleDictDTO>) redisUtils.get(dictKey); |
|||
} |
|||
|
|||
/** |
|||
* 根据数据字典类型,将简版数据字典列表放入缓存 |
|||
* |
|||
* @param dictType 数据字典类型 |
|||
* @param simpleDictList 列表 |
|||
* @return void |
|||
* @author yujintao |
|||
* @date 2019/7/15 09:50 |
|||
*/ |
|||
public void setSimpleDictList(String dictType, List<SysSimpleDictDTO> simpleDictList) { |
|||
String dictKey = RedisKeys.getSimpleDictKey(dictType); |
|||
redisUtils.set(dictKey, simpleDictList); |
|||
} |
|||
|
|||
/** |
|||
* 根据数据字典类型,从redis删除简版数据字典列表 |
|||
* |
|||
* @param dictType |
|||
* @return void |
|||
* @author yujintao |
|||
* @date 2019/7/15 10:10 |
|||
*/ |
|||
public void removeSimpleDictList(String dictType) { |
|||
String dictKey = RedisKeys.getSimpleDictKey(dictType); |
|||
redisUtils.delete(dictKey); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
|
|||
package com.elink.esua.epdc.service; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dto.SimpleAreaDTO; |
|||
import com.elink.esua.epdc.entity.AreaEntity; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 行政区划 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:54 |
|||
*/ |
|||
public interface AreaService extends BaseService<AreaEntity> { |
|||
|
|||
|
|||
/** |
|||
* 根据区划ID,获取下属区域列表 |
|||
* |
|||
* @param areaId |
|||
* @return com.elink.esua.commons.tools.utils.Result<java.util.List < com.elink.esua.dto.AreaDTO>> |
|||
* @author yujintao |
|||
* @date 2019/6/13 10:35 |
|||
*/ |
|||
Result<List<SimpleAreaDTO>> listSimpleAreaInfo(String areaId); |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
|
|||
package com.elink.esua.epdc.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|||
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dao.AreaDao; |
|||
import com.elink.esua.epdc.dto.SimpleAreaDTO; |
|||
import com.elink.esua.epdc.entity.AreaEntity; |
|||
import com.elink.esua.epdc.redis.AreaRedis; |
|||
import com.elink.esua.epdc.service.AreaService; |
|||
import com.google.common.collect.Lists; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @date 2019/9/3 16:55 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
public class AreaServiceImpl extends BaseServiceImpl<AreaDao, AreaEntity> implements AreaService { |
|||
|
|||
|
|||
@Autowired |
|||
private AreaRedis areaRedis; |
|||
|
|||
@Override |
|||
public Result<List<SimpleAreaDTO>> listSimpleAreaInfo(String areaId) { |
|||
|
|||
List<SimpleAreaDTO> simpleAreaList = Lists.newArrayList(); |
|||
|
|||
try { |
|||
if (StringUtils.isNotBlank(areaId)) { |
|||
|
|||
List<SimpleAreaDTO> areaList = areaRedis.getSimpleAreaList(areaId); |
|||
if (null != areaList) { |
|||
return new Result<List<SimpleAreaDTO>>().ok(areaList); |
|||
} |
|||
|
|||
Integer pid = Integer.parseInt(areaId); |
|||
QueryWrapper<AreaEntity> arWrapper = new QueryWrapper<>(); |
|||
arWrapper.select("ID", "NAME"); |
|||
arWrapper.eq("PARENT_ID", pid); |
|||
arWrapper.eq("STATUS", NumConstant.ONE); |
|||
arWrapper.orderByAsc("LEVEL", "SORT"); |
|||
List<AreaEntity> entityList = baseDao.selectList(arWrapper); |
|||
if (!entityList.isEmpty()) { |
|||
simpleAreaList = ConvertUtils.sourceToTarget(entityList, SimpleAreaDTO.class); |
|||
areaRedis.setSimpleAreaList(areaId, simpleAreaList); |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("获取区划信息失败,错误信息{}", e.getMessage()); |
|||
} |
|||
return new Result<List<SimpleAreaDTO>>().ok(simpleAreaList); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue