Browse Source

新增导入功能

feature/v.2.0.0
caoyizhong 3 years ago
parent
commit
8ed2442683
  1. 7
      air/pom.xml
  2. 18
      air/src/main/java/com/air/baseRegion/controller/BaseRegionController.java
  3. 34
      air/src/main/java/com/air/baseRegion/dto/BaseRegionDTO.java
  4. 104
      air/src/main/java/com/air/baseRegion/entity/BaseRegion.java
  5. 17
      air/src/main/java/com/air/baseRegion/mapper/BaseRegionMapper.java
  6. 13
      air/src/main/java/com/air/baseRegion/service/BaseRegionService.java
  7. 17
      air/src/main/java/com/air/baseRegion/service/impl/BaseRegionServiceImpl.java
  8. 61
      air/src/main/java/com/air/baseRegion/vo/BaseRegionVO.java
  9. 15
      air/src/main/java/com/air/facilities/controller/FacilitiesController.java
  10. 65
      air/src/main/java/com/air/facilities/dto/FacilitiesFileDTO.java
  11. 7
      air/src/main/java/com/air/facilities/entity/Facilities.java
  12. 12
      air/src/main/java/com/air/facilities/mapper/FacilitiesMapper.java
  13. 14
      air/src/main/java/com/air/facilities/service/FacilitiesService.java
  14. 103
      air/src/main/java/com/air/facilities/service/impl/FacilitiesServiceImpl.java
  15. 18
      air/src/main/resources/mapper/BaseRegionMapper.xml
  16. 12
      air/src/main/resources/mapper/FacilitiesMapper.xml

7
air/pom.xml

@ -29,6 +29,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--easy excel依赖-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.5</version>
</dependency>
</dependencies>

18
air/src/main/java/com/air/baseRegion/controller/BaseRegionController.java

@ -0,0 +1,18 @@
package com.air.baseRegion.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @program: back-end
* @description:
* @author: cyz
* @create: 2022-07-12 09:15
**/
@RestController
@RequestMapping("/baseRegion")
public class BaseRegionController {
}

34
air/src/main/java/com/air/baseRegion/dto/BaseRegionDTO.java

@ -0,0 +1,34 @@
package com.air.baseRegion.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* @program: back-end
* @description:
* @author: cyz
* @create: 2022-07-12 09:48
**/
@Data
public class BaseRegionDTO {
/**
*
*/
@ExcelProperty(value = "省", index = 2)
private String province;
/**
*
*/
@ExcelProperty(value = "市", index = 3)
private String city;
/**
*
*/
@ExcelProperty(value = "区", index = 4)
private String area;
}

104
air/src/main/java/com/air/baseRegion/entity/BaseRegion.java

@ -0,0 +1,104 @@
package com.air.baseRegion.entity;
import com.air.cityarea.entity.CityArea;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigInteger;
import java.util.Date;
/**
* @program: back-end
* @description: 地区类
* @author: cyz
* @create: 2022-07-11 17:12
**/
@Data
@TableName("sys_base_region")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "地区")
public class BaseRegion extends Model<BaseRegion> {
/**
*省市区编码
*/
// @TableId(value = "uuid") 设置主键
@ApiModelProperty(value = "省市区编码")
private BigInteger regionId;
/**
*父级id
*/
// @TableField(value = "uname") 设置别名
@ApiModelProperty(value = "父级id")
private BigInteger parRegionId;
/**
*省市区名称
*/
@ApiModelProperty(value = "省市区名称")
private String regionName;
/**
*层级
*/
@ApiModelProperty(value = "层级")
private BigInteger regionLevel;
/**
*类型
*/
@ApiModelProperty(value = "类型")
private Integer regionType;
/**
*说明
*/
@ApiModelProperty(value = "说明")
private String regionDesc;
/**
*区域排序
*/
@ApiModelProperty(value = "区域排序")
private BigInteger regionSort;
/**
*长途区号
*/
@ApiModelProperty(value = "长途区号")
private BigInteger regionLong;
/**
*记录首次创建的员工标识
*/
@ApiModelProperty(value = "记录首次创建的员工标识")
private BigInteger createStaff;
/**
*记录每次修改的员工标识
*/
@ApiModelProperty(value = "记录每次修改的员工标识")
private BigInteger updateStaff;
/**
*记录实例信息创建的时间
*/
@ApiModelProperty(value = "记录实例信息创建的时间")
private Date createDate;
/**
*记录每次信息变更的时间
*/
@ApiModelProperty(value = "记录每次信息变更的时间")
private Date statusDate;
/**
*记录任何变动时修改的时间
*/
@ApiModelProperty(value = "记录任何变动时,修改的时间。")
private Date updateDate;
/**
*备注
*/
@ApiModelProperty(value = "备注")
private String remark;
}

17
air/src/main/java/com/air/baseRegion/mapper/BaseRegionMapper.java

@ -0,0 +1,17 @@
package com.air.baseRegion.mapper;
import com.air.baseRegion.dto.BaseRegionDTO;
import com.air.baseRegion.entity.BaseRegion;
import com.air.baseRegion.vo.BaseRegionVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
@Repository
public interface BaseRegionMapper extends BaseMapper<BaseRegion> {
/**
* 根据条件查询地区信息
* @param baseRegionDTO
* @return
*/
BaseRegionVO selectBaseRegion(BaseRegionDTO baseRegionDTO);
}

13
air/src/main/java/com/air/baseRegion/service/BaseRegionService.java

@ -0,0 +1,13 @@
package com.air.baseRegion.service;
import com.air.baseRegion.entity.BaseRegion;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @program: back-end
* @description:
* @author: cyz
* @create: 2022-07-12 09:14
**/
public interface BaseRegionService extends IService<BaseRegion> {
}

17
air/src/main/java/com/air/baseRegion/service/impl/BaseRegionServiceImpl.java

@ -0,0 +1,17 @@
package com.air.baseRegion.service.impl;
import com.air.baseRegion.entity.BaseRegion;
import com.air.baseRegion.mapper.BaseRegionMapper;
import com.air.baseRegion.service.BaseRegionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @program: back-end
* @description:
* @author: cyz
* @create: 2022-07-12 09:19
**/
public class BaseRegionServiceImpl extends ServiceImpl<BaseRegionMapper, BaseRegion> implements BaseRegionService {
}

61
air/src/main/java/com/air/baseRegion/vo/BaseRegionVO.java

@ -0,0 +1,61 @@
package com.air.baseRegion.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigInteger;
import java.util.Date;
/**
* @program: back-end
* @description:
* @author: cyz
* @create: 2022-07-12 09:57
**/
@Data
public class BaseRegionVO {
/**
*区ID
*/
// @TableId(value = "uuid") 设置主键
@ApiModelProperty(value = "县、区ID")
private BigInteger xianId;
/**
*市ID
*/
// @TableField(value = "uname") 设置别名
@ApiModelProperty(value = "市ID")
private BigInteger shiId;
/**
*省市区名称
*/
@ApiModelProperty(value = "省市区名称")
private String regionName;
/**
*省ID
*/
@ApiModelProperty(value = "省ID")
private BigInteger shengId;
/**
*省名称
*/
@ApiModelProperty(value = "省名称")
private String shengName;
/**
*市名称
*/
@ApiModelProperty(value = "市名称")
private String shiName;
/**
*县名称
*/
@ApiModelProperty(value = "县名称")
private String xianName;
/**
*备注
*/
@ApiModelProperty(value = "备注")
private String remark;
}

15
air/src/main/java/com/air/facilities/controller/FacilitiesController.java

@ -11,7 +11,9 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
@ -75,5 +77,18 @@ public class FacilitiesController {
return R.ok(facilities);
}
@ApiOperation(value = "导入周边信息")
@PostMapping("/importFile")
public R<List<Facilities>> importFile(@RequestParam(value = "uploadFile") MultipartFile file){
try {
boolean b = facilitiesService.importFile(file);
return R.ok();
} catch (IOException e) {
e.printStackTrace();
return R.failed();
}
}
}

65
air/src/main/java/com/air/facilities/dto/FacilitiesFileDTO.java

@ -0,0 +1,65 @@
package com.air.facilities.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* @program: back-end
* @description:
* @author: cyz
* @create: 2022-07-11 15:53
**/
@Data
public class FacilitiesFileDTO {
private static final long serialVersionUID = 1L;
/**
* 名称
*/
@ExcelProperty(value = "名称", index = 0)
private String name;
/**
* 地址
*/
@ExcelProperty(value = "地址", index = 1)
private String address;
/**
*
*/
@ExcelProperty(value = "省", index = 2)
private String province;
/**
*
*/
@ExcelProperty(value = "市", index = 3)
private String city;
/**
*
*/
@ExcelProperty(value = "区", index = 4)
private String area;
/**
* 经纬度
*/
@ExcelProperty(value = "高德经纬", index = 5)
private String nautica;
/**
* 分类
*/
@ExcelProperty(value = "分类", index = 6)
private String classify;
}

7
air/src/main/java/com/air/facilities/entity/Facilities.java

@ -10,6 +10,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* @program: back-end
@ -46,4 +47,10 @@ public class Facilities extends Model<Facilities> {
private String geom;
@ApiModelProperty(value="计算坐标对象")
private String miniGeom;
@ApiModelProperty(value = "所属地区ID")
private BigInteger site;
@ApiModelProperty(value = "所在地址")
private String address;
}

12
air/src/main/java/com/air/facilities/mapper/FacilitiesMapper.java

@ -39,9 +39,17 @@ public interface FacilitiesMapper extends BaseMapper<Facilities> {
*/
int delFacilities(String[] ids);
/**
* 添加
* @param facilities
* @return
*/
int insertFacilities(Facilities facilities);
/**
* 修改
* @param facilities
* @return
*/
int updateFacilities(Facilities facilities);
}

14
air/src/main/java/com/air/facilities/service/FacilitiesService.java

@ -4,7 +4,9 @@ import com.air.facilities.dto.FacilitiesDTO;
import com.air.facilities.entity.Facilities;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface FacilitiesService extends IService<Facilities> {
@ -50,7 +52,17 @@ public interface FacilitiesService extends IService<Facilities> {
*/
List<Facilities> selectTypeList();
/**
* 修改信息
* @param facilitiesDTO
* @return
*/
int updateFacilities(FacilitiesDTO facilitiesDTO);
/**
* 导入周边信息
* @param file
* @return
*/
boolean importFile(MultipartFile file) throws IOException;
}

103
air/src/main/java/com/air/facilities/service/impl/FacilitiesServiceImpl.java

@ -1,19 +1,34 @@
package com.air.facilities.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import com.air.baseRegion.dto.BaseRegionDTO;
import com.air.baseRegion.entity.BaseRegion;
import com.air.baseRegion.mapper.BaseRegionMapper;
import com.air.baseRegion.vo.BaseRegionVO;
import com.air.facilities.dto.FacilitiesDTO;
import com.air.facilities.dto.FacilitiesFileDTO;
import com.air.facilities.entity.Facilities;
import com.air.facilities.mapper.FacilitiesMapper;
import com.air.facilities.service.FacilitiesService;
import com.air.land.entity.LandListed;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cinderella.framework.common.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
/**
@ -22,14 +37,19 @@ import java.util.List;
* @author: cyz
* @create: 2022-07-07 15:44
**/
@Slf4j
@Service
public class FacilitiesServiceImpl extends ServiceImpl<FacilitiesMapper, Facilities> implements FacilitiesService {
@Autowired
private FacilitiesMapper facilitiesMapper;
@Autowired
private BaseRegionMapper baseRegionMapper;
/**
* 查询全部数据
*
* @param facilities
* @return
*/
@ -41,6 +61,7 @@ public class FacilitiesServiceImpl extends ServiceImpl<FacilitiesMapper, Facilit
/**
* 根据ID查询具体信息
*
* @param id
* @return
*/
@ -52,13 +73,14 @@ public class FacilitiesServiceImpl extends ServiceImpl<FacilitiesMapper, Facilit
/**
* 修改周边信息
*
* @param facilities
* @return
*/
@Override
public int putFacilities(Facilities facilities) {
return facilitiesMapper.update(facilities,null);
return facilitiesMapper.update(facilities, null);
}
/**
@ -73,19 +95,21 @@ public class FacilitiesServiceImpl extends ServiceImpl<FacilitiesMapper, Facilit
/**
* 添加
*
* @param facilitiesDTO
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int addFacilities(FacilitiesDTO facilitiesDTO) {
Facilities facilities = new Facilities();
BeanUtils.copyProperties(facilitiesDTO,facilities);
String srt = "POINT("+facilitiesDTO.getLon()+" "+facilitiesDTO.getLat()+")";
BeanUtils.copyProperties(facilitiesDTO, facilities);
String srt = "POINT(" + facilitiesDTO.getLon() + " " + facilitiesDTO.getLat() + ")";
facilities.setGeom(srt);
if(StrUtil.isNotBlank(facilitiesDTO.getOldType())){
if (StrUtil.isNotBlank(facilitiesDTO.getOldType())) {
List<Facilities> facilities1 = facilitiesMapper.selectList(Wrappers.<Facilities>query().lambda().
eq(StringUtils.isNotEmpty(facilitiesDTO.getOldType()), Facilities::getType, facilitiesDTO.getOldType()));
if(facilities1.size() > 0){
if (facilities1.size() > 0) {
facilities.setType(facilities1.get(0).getType());
facilities.setTypecn(facilities1.get(0).getTypecn());
}
@ -96,30 +120,33 @@ public class FacilitiesServiceImpl extends ServiceImpl<FacilitiesMapper, Facilit
/**
* 查询周边类型集合
*
* @return
*/
@Override
public List<Facilities> selectTypeList() {
return facilitiesMapper.selectTypeList();
return facilitiesMapper.selectTypeList();
}
/**
* 修改
*
* @param facilitiesDTO
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int updateFacilities(FacilitiesDTO facilitiesDTO) {
Facilities facilities = new Facilities();
BeanUtils.copyProperties(facilitiesDTO,facilities);
String srt = "POINT("+facilitiesDTO.getLon()+" "+facilitiesDTO.getLat()+")";
BeanUtils.copyProperties(facilitiesDTO, facilities);
String srt = "POINT(" + facilitiesDTO.getLon() + " " + facilitiesDTO.getLat() + ")";
facilities.setGeom(srt);
facilities.setGid(facilitiesDTO.getGid());
if(StrUtil.isNotBlank(facilitiesDTO.getOldType())){
if (StrUtil.isNotBlank(facilitiesDTO.getOldType())) {
List<Facilities> facilities1 = facilitiesMapper.selectList(Wrappers.<Facilities>query().lambda().
eq(StringUtils.isNotEmpty(facilitiesDTO.getOldType()), Facilities::getType, facilitiesDTO.getOldType()));
if(facilities1.size() > 0){
if (facilities1.size() > 0) {
facilities.setType(facilities1.get(0).getType());
facilities.setTypecn(facilities1.get(0).getTypecn());
}
@ -127,4 +154,60 @@ public class FacilitiesServiceImpl extends ServiceImpl<FacilitiesMapper, Facilit
}
return facilitiesMapper.updateFacilities(facilities);
}
/**
* 导入周边信息
*
* @param file
* @return
*/
@Override
@Transactional
public boolean importFile(MultipartFile file) {
try {
InputStream inputStream = file.getInputStream();
EasyExcel.read(inputStream, FacilitiesFileDTO.class, new PageReadListener<FacilitiesFileDTO>(dataList -> {
dataList.forEach( demoData -> {
// for (FacilitiesFileDTO demoData : dataList) {
Facilities facilities = new Facilities();
facilities.setName(demoData.getName());
String[] split = demoData.getNautica().split(",");
String srt = "POINT(" + split[0] + " " + split[1] + ")";
String s = split[0];
BigDecimal bd=new BigDecimal(s);
facilities.setLon(bd);//经度
String se = split[1];
BigDecimal bed=new BigDecimal(se);
facilities.setLat(bed);//纬度
facilities.setGeom(srt);
//查询周边类型
List<Facilities> facilities1 = facilitiesMapper.selectList(Wrappers.<Facilities>query().lambda()
.eq(StringUtils.isNotBlank(demoData.getClassify()), Facilities::getTypecn, demoData.getClassify()));
if(facilities1.size() > 0 ){
facilities.setType(facilities1.get(0).getType());
facilities.setTypecn(facilities1.get(0).getTypecn());
}else{
throw new BusinessException("没有该分类");
}
//查询地区ID
BaseRegionDTO baseRegionDTO = new BaseRegionDTO();
baseRegionDTO.setProvince(demoData.getProvince());
baseRegionDTO.setCity(demoData.getCity());
baseRegionDTO.setArea(demoData.getArea());
BaseRegionVO baseRegionVO = baseRegionMapper.selectBaseRegion(baseRegionDTO);
facilities.setSite(baseRegionVO.getXianId());
if(StringUtils.isNotBlank(demoData.getAddress())){
facilities.setAddress(demoData.getAddress());
}
facilitiesMapper.insertFacilities(facilities);
});
})).sheet().headRowNumber(1).doRead();
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}

18
air/src/main/resources/mapper/BaseRegionMapper.xml

@ -0,0 +1,18 @@
<?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.air.baseRegion.mapper.BaseRegionMapper">
<select id="selectBaseRegion" resultType="com.air.baseRegion.vo.BaseRegionVO">
select shi.REGION_ID xianId,sen.REGION_ID shiId,sbr.REGION_ID shengId,sbr.REGION_NAME shengName,sen.REGION_NAME shiName,shi.REGION_NAME xianName
from sys_base_region sbr
join sys_base_region sen on sbr.REGION_ID= sen.PAR_REGION_ID
join sys_base_region shi on sen.REGION_ID= shi.PAR_REGION_ID
<where>
<if test="province != null and province != '' "> sbr.REGION_NAME = #{ province }</if>
<if test="city != null and city != ''">and sen.REGION_NAME = #{ city } </if>
<if test="area != null and area != ''">and shi.REGION_NAME= #{area }</if>
</where>
</select>
</mapper>

12
air/src/main/resources/mapper/FacilitiesMapper.xml

@ -7,7 +7,7 @@
select gid,id,name,typecn,remark,lon,lat,type,geom,mini_geom from facilities
<where>
<if test="facilities.name != null and facilities.name != ''"> and name like concat('%', #{facilities.name},'%') </if>
<if test="facilities.typecn != null and facilities.typecn != ''"> and typecn =#{facilities.typecn} </if>
<if test="facilities.typecn != null and facilities.typecn != ''"> and typecn = #{facilities.typecn} </if>
</where>
</select>
@ -34,6 +34,8 @@
<if test="type != null">type,</if>
<if test="geom != null">geom,</if>
<if test="miniGeom != null">mini_geom,</if>
<if test="site != null ">site,</if>
<if test="address != null">address,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
@ -45,19 +47,23 @@
<if test="type != null">#{type},</if>
<if test="geom != null">ST_GeomFromText(#{geom}),</if>
<if test="miniGeom != null">#{miniGeom},</if>
<if test="site != null"> #{ site },</if>
<if test="address != null">#{ address },</if>
</trim>
</insert>
<update id="updateFacilities" >
update facilities
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="typecn != null"> typecn =#{typecn},</if>
<if test="remark != null">remark =#{remark},</if>
<if test="typecn != null"> typecn = #{typecn},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="lon != null">lon = #{lon},</if>
<if test="lat != null">lat = #{lat},</if>
<if test="type != null">type = #{type},</if>
<if test="geom != null">geom = ST_GeomFromText(#{geom}),</if>
<if test="miniGeom != null">miniGeom = #{miniGeom},</if>
<if test="site != null">site = #{ site },</if>
<if test="address != null">address = #{address},</if>
</trim>
where gid = #{gid}
</update>

Loading…
Cancel
Save