小区管理
parent
4bf2faaa34
commit
72fa4fcff4
|
@ -0,0 +1,14 @@
|
||||||
|
package com.zyh.common.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Area {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer areaId;
|
||||||
|
private Integer parentId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.zyh.common.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class House {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private Integer jurisdiction;
|
||||||
|
private Double lng;
|
||||||
|
private Double lat;
|
||||||
|
private String pic;
|
||||||
|
private String plotId;
|
||||||
|
private String areaname;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -61,7 +61,18 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tobato</groupId>
|
||||||
|
<artifactId>fastdfs-client</artifactId>
|
||||||
|
<version>1.26.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 阿里云oss -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
<version>3.10.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.zyh.system.controller;
|
||||||
|
|
||||||
|
import com.zyh.common.domain.Area;
|
||||||
|
import com.zyh.common.domain.House;
|
||||||
|
import com.zyh.common.result.Result;
|
||||||
|
import com.zyh.system.service.HouseService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class HouseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HouseService houseService;
|
||||||
|
|
||||||
|
//新增小区
|
||||||
|
@PostMapping("addHouse")
|
||||||
|
public Result addHouse(@RequestBody House house) {
|
||||||
|
return houseService.addHouse(house);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询小区
|
||||||
|
@PostMapping("getHouse")
|
||||||
|
public Result<List<House>> getHouse() {
|
||||||
|
return houseService.getHouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询行政区树
|
||||||
|
@PostMapping("getJurisdictionTree")
|
||||||
|
public Result<List<Area>> getJurisdictionTree(@RequestParam Integer parentId) {
|
||||||
|
return houseService.getJurisdictionTree(parentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//上传图片
|
||||||
|
@PostMapping("sendPic")
|
||||||
|
public Result sendPic(@RequestParam("file") MultipartFile multipartFile) {
|
||||||
|
|
||||||
|
Result result = houseService.sendPic(multipartFile);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.zyh.system.mapper;
|
||||||
|
|
||||||
|
import com.zyh.common.domain.Area;
|
||||||
|
import com.zyh.common.domain.House;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface HouseMapper {
|
||||||
|
Integer addHouse(House house);
|
||||||
|
|
||||||
|
List<Area> getJurisdictionTree(@Param("parentId") Integer parentId);
|
||||||
|
|
||||||
|
List<House> getHouse();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.zyh.system.service;
|
||||||
|
|
||||||
|
import com.zyh.common.domain.Area;
|
||||||
|
import com.zyh.common.domain.House;
|
||||||
|
import com.zyh.common.result.Result;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface HouseService {
|
||||||
|
Result addHouse(House house);
|
||||||
|
|
||||||
|
Result<List<Area>> getJurisdictionTree(Integer parentId);
|
||||||
|
|
||||||
|
Result<List<House>> getHouse();
|
||||||
|
|
||||||
|
Result sendPic(MultipartFile pic) ;
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.zyh.system.service.impl;
|
||||||
|
|
||||||
|
import com.zyh.common.domain.Area;
|
||||||
|
import com.zyh.common.domain.House;
|
||||||
|
import com.zyh.common.result.Result;
|
||||||
|
import com.zyh.common.utils.StringUtils;
|
||||||
|
import com.zyh.system.mapper.HouseMapper;
|
||||||
|
import com.zyh.system.service.HouseService;
|
||||||
|
import com.zyh.system.util.FastUtil;
|
||||||
|
import com.zyh.system.util.OssUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class HouseServicempl implements HouseService {
|
||||||
|
@Autowired
|
||||||
|
FastUtil fastUtil;
|
||||||
|
@Autowired
|
||||||
|
private HouseMapper houseMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result addHouse(House house) {
|
||||||
|
//校验参数
|
||||||
|
|
||||||
|
checkHouse(house);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Integer add = houseMapper.addHouse(house);
|
||||||
|
if (add > 0) {
|
||||||
|
return Result.success("添加成功");
|
||||||
|
} else {
|
||||||
|
return Result.error("添加失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkHouse(House house) {
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(house.getName())) {
|
||||||
|
throw new RuntimeException("名称不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(house.getPlotId())) {
|
||||||
|
throw new RuntimeException("所属小区编号不能为空");
|
||||||
|
}
|
||||||
|
if (house.getJurisdiction() == null) {
|
||||||
|
throw new RuntimeException("所属辖区不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<Area>> getJurisdictionTree(Integer parentId) {
|
||||||
|
List<Area> list=houseMapper.getJurisdictionTree(parentId);
|
||||||
|
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<House>> getHouse() {
|
||||||
|
List<House> list=houseMapper.getHouse();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result sendPic(MultipartFile pic) {
|
||||||
|
|
||||||
|
|
||||||
|
String sendPic = "";
|
||||||
|
sendPic= OssUtil.uploadMultipartFile(pic);
|
||||||
|
|
||||||
|
return Result.success(sendPic);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.zyh.system.util;
|
||||||
|
|
||||||
|
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
||||||
|
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: 0107day02
|
||||||
|
* @BelongsPackage: com.bw.config
|
||||||
|
* @Author: zhupengfei
|
||||||
|
* @CreateTime: 2023-02-01 08:52
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class FastUtil {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FastUtil.class);
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FastFileStorageClient storageClient ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*/
|
||||||
|
public String upload(MultipartFile multipartFile) throws Exception{
|
||||||
|
String originalFilename = multipartFile.getOriginalFilename().
|
||||||
|
substring(multipartFile.getOriginalFilename().
|
||||||
|
lastIndexOf(".") + 1);
|
||||||
|
StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage(
|
||||||
|
multipartFile.getInputStream(),
|
||||||
|
multipartFile.getSize(),originalFilename , null);
|
||||||
|
return storePath.getFullPath() ;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除文件
|
||||||
|
*/
|
||||||
|
public String deleteFile(String fileUrl) {
|
||||||
|
if (StringUtils.isEmpty(fileUrl)) {
|
||||||
|
log.info("fileUrl == >>文件路径为空...");
|
||||||
|
return "文件路径不能为空";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
StorePath storePath = StorePath.parseFromUrl(fileUrl);
|
||||||
|
storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return "删除成功";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,188 @@
|
||||||
|
package com.zyh.system.util;
|
||||||
|
|
||||||
|
import com.aliyun.oss.OSS;
|
||||||
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
|
import com.aliyun.oss.model.GetObjectRequest;
|
||||||
|
import com.aliyun.oss.model.ObjectMetadata;
|
||||||
|
import com.aliyun.oss.model.PutObjectRequest;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Oss服务调用
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class OssUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||||
|
*/
|
||||||
|
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||||
|
private static String accessKeyId = "LTAI5tN8mAfrDAwgKQwyAapY";
|
||||||
|
private static String accessKeySecret = "AliAqC58cSClsFp5esdKfk48K1bXeD";
|
||||||
|
private static String accessPre = "https://sirzpengbucket.oss-cn-shanghai.aliyuncs.com/";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bucket名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String bucketName = "sirzpengbucket";
|
||||||
|
|
||||||
|
private static OSS ossClient ;
|
||||||
|
|
||||||
|
static {
|
||||||
|
ossClient = new OSSClientBuilder().build(
|
||||||
|
endPoint,
|
||||||
|
accessKeyId,
|
||||||
|
accessKeySecret);
|
||||||
|
log.info("oss服务连接成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业级阿里云 OSS 上传指定文件。
|
||||||
|
* @param filePath 待上传的文件路径。
|
||||||
|
* @return 如果上传成功,返回该文件在阿里云 OSS 存储上的访问路径;否则返回 null。
|
||||||
|
**/
|
||||||
|
public static String uploadFileFilePath(String filePath) {
|
||||||
|
// 创建OSSClient实例
|
||||||
|
OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 生成唯一的文件名,可以根据需要进行调整
|
||||||
|
String key = System.currentTimeMillis() + "_" + new File(filePath).getName();
|
||||||
|
|
||||||
|
// 设置上传文件的元信息
|
||||||
|
ObjectMetadata metadata = new ObjectMetadata();
|
||||||
|
// 可以根据需要设置其他元信息,例如Content-Type
|
||||||
|
|
||||||
|
// 执行文件上传
|
||||||
|
ossClient.putObject(bucketName, key, new File(filePath), metadata);
|
||||||
|
|
||||||
|
// 返回访问路径
|
||||||
|
return accessPre+key;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
// 关闭OSSClient
|
||||||
|
ossClient.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "上传失败";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认路径上传本地文件
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static String uploadFile(String filePath){
|
||||||
|
return uploadFileForBucket(bucketName,getOssFilePath(filePath) ,filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认路径上传multipartFile文件
|
||||||
|
* @param multipartFile
|
||||||
|
*/
|
||||||
|
public static String uploadMultipartFile(MultipartFile multipartFile) {
|
||||||
|
return uploadMultipartFile(bucketName,getOssFilePath(multipartFile.getOriginalFilename()),multipartFile);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 上传 multipartFile 类型文件
|
||||||
|
* @param bucketName
|
||||||
|
* @param ossPath
|
||||||
|
* @param multipartFile
|
||||||
|
*/
|
||||||
|
public static String uploadMultipartFile(String bucketName , String ossPath , MultipartFile multipartFile){
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = multipartFile.getInputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||||
|
return accessPre+ossPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||||
|
* @param bucketName 实例名称
|
||||||
|
* @param ossPath oss存储路径
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
*/
|
||||||
|
public static String uploadFileForBucket(String bucketName , String ossPath , String filePath) {
|
||||||
|
// 创建PutObjectRequest对象。
|
||||||
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
|
||||||
|
|
||||||
|
// 上传
|
||||||
|
ossClient.putObject(putObjectRequest);
|
||||||
|
return accessPre+ossPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用文件流上传到指定的bucket实例
|
||||||
|
* @param bucketName 实例名称
|
||||||
|
* @param ossPath oss存储路径
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
*/
|
||||||
|
public static String uploadFileInputStreamForBucket(String bucketName , String ossPath , String filePath){
|
||||||
|
|
||||||
|
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(filePath);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
|
||||||
|
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||||
|
return accessPre+ossPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void uploadFileInputStreamForBucket(String bucketName , String ossPath , InputStream inputStream ){
|
||||||
|
ossClient.putObject(bucketName, ossPath, inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
* @param ossFilePath
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static void downloadFile(String ossFilePath , String filePath ){
|
||||||
|
downloadFileForBucket(bucketName , ossFilePath , filePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
* @param bucketName 实例名称
|
||||||
|
* @param ossFilePath oss存储路径
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
*/
|
||||||
|
public static void downloadFileForBucket(String bucketName , String ossFilePath , String filePath ){
|
||||||
|
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getOssDefaultPath(){
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
String url =
|
||||||
|
now.getYear()+"/"+
|
||||||
|
now.getMonth()+"/"+
|
||||||
|
now.getDayOfMonth()+"/"+
|
||||||
|
now.getHour()+"/"+
|
||||||
|
now.getMinute()+"/";
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOssFilePath(String filePath){
|
||||||
|
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
|
||||||
|
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?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.zyh.system.mapper.HouseMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="addHouse">
|
||||||
|
insert into house values(0,#{plotId},#{name},#{jurisdiction},#{lng},#{lat},#{pic})
|
||||||
|
</insert>
|
||||||
|
<select id="getJurisdictionTree" resultType="com.zyh.common.domain.Area">
|
||||||
|
select * from area
|
||||||
|
<where>
|
||||||
|
<if test="parentId != null">
|
||||||
|
and parent_id = #{parentId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
<select id="getHouse" resultType="com.zyh.common.domain.House">
|
||||||
|
select house.*,area.name areaname from house left join area on house.jurisdiction=area.id
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue