فهرست منبع

sql改为基于mybatisplus

yfzhang 9 ماه پیش
والد
کامیت
17b83be8c2

+ 6 - 0
sky-pojo/pom.xml

@@ -23,5 +23,11 @@
             <groupId>com.github.xiaoymin</groupId>
             <artifactId>knife4j-spring-boot-starter</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-annotation</artifactId>
+            <version>3.5.3.1</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 </project>

+ 9 - 0
sky-pojo/src/main/java/com/sky/entity/TExpert.java

@@ -5,6 +5,13 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
 import java.io.Serializable;
 
 /**
@@ -20,3 +27,5 @@ public class TExpert implements Serializable {
     private String user;
     private String phone;
 }
+
+

+ 78 - 0
sky-pojo/src/main/java/com/sky/entity/TLandimg.java

@@ -0,0 +1,78 @@
+package com.sky.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * @Author zhangyifan
+ * @Date 2024/4/9 17:22
+ */
+//@Data
+//@Builder
+//@NoArgsConstructor
+//@AllArgsConstructor
+//public class landimg  implements Serializable {
+//
+//
+//    private Integer bh;
+//
+//    private String author;
+//
+//    private String site;
+//
+//    private LocalDate pzdt;
+//
+//    private String imgurl;
+//
+//
+//
+//
+//}
+
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author yfzhang
+ * @since 2024-04-23
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("t_landimg")
+@ApiModel(value="TLandimg对象", description="")
+public class TLandimg implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "bh", type = IdType.AUTO)
+    private Integer bh;
+
+    @ApiModelProperty(value = "拍照作者")
+    private String author;
+
+    @ApiModelProperty(value = "拍照位置")
+    private String site;
+
+    @ApiModelProperty(value = "拍照日期")
+    private LocalDate pzdt;
+
+    @ApiModelProperty(value = "备注")
+    private String imgurl;
+
+    @ApiModelProperty(value = "备注")
+    private String bz;
+
+
+}

+ 0 - 36
sky-pojo/src/main/java/com/sky/entity/landimg.java

@@ -1,36 +0,0 @@
-package com.sky.entity;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.io.Serializable;
-import java.sql.Date;
-import java.time.LocalDate;
-
-/**
- * @Author zhangyifan
- * @Date 2024/4/9 17:22
- */
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class landimg  implements Serializable {
-
-
-    private Integer bh;
-
-    private String author;
-
-    private String site;
-
-    private LocalDate pzdt;
-
-    private String imgurl;
-
-
-
-
-}

+ 16 - 2
sky-server/pom.xml

@@ -9,14 +9,23 @@
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>sky-server</artifactId>
+    <properties>
+        <java.version>1.8</java.version>
+        <elasticsearch.version>7.12.1</elasticsearch.version>
+    </properties>
     <dependencies>
+        <!--es依赖-->
+        <dependency>
+            <groupId>org.elasticsearch.client</groupId>
+            <artifactId>elasticsearch-rest-high-level-client</artifactId>
+        </dependency>
+        <!--阿里云依赖-->
         <dependency>
             <groupId>com.aliyun.oss</groupId>
             <artifactId>aliyun-sdk-oss</artifactId>
             <version>3.15.0</version>
         </dependency>
-
-
+        <!--mybatisplus依赖-->
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
@@ -127,6 +136,11 @@
             <groupId>org.apache.poi</groupId>
             <artifactId>poi-ooxml</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.elasticsearch.client</groupId>
+            <artifactId>elasticsearch-rest-high-level-client</artifactId>
+            <version>6.8.7</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 13 - 0
sky-server/src/main/java/com/sky/SkyApplication.java

@@ -1,9 +1,14 @@
 package com.sky;
 
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpHost;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestClientBuilder;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.elasticsearch.client.RestHighLevelClient;
 
 @SpringBootApplication
 @EnableTransactionManagement //开启注解方式的事务管理
@@ -13,4 +18,12 @@ public class SkyApplication {
         SpringApplication.run(SkyApplication.class, args);
         log.info("server started");
     }
+
+    @Bean
+    public RestHighLevelClient client() {
+        return new RestHighLevelClient(RestClient.builder(
+                HttpHost.create("http://192.168.11.1:9200")
+        ));
+    }
+
 }

+ 17 - 80
sky-server/src/main/java/com/sky/controller/admin/EmployeeController.java

@@ -1,49 +1,19 @@
 package com.sky.controller.admin;
 
-import com.aliyun.oss.ClientException;
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.oss.OSSException;
-import com.aliyun.oss.common.auth.CredentialsProviderFactory;
-import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
-
-import java.io.ByteArrayInputStream;
-
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.oss.OSSException;
-import com.aliyun.oss.common.auth.CredentialsProviderFactory;
-import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
-import com.sky.constant.JwtClaimsConstant;
 import com.sky.dto.EmployeeLoginDTO;
 import com.sky.entity.Employee;
-import com.sky.entity.landimg;
+import com.sky.entity.TLandimg;
 import com.sky.properties.JwtProperties;
 import com.sky.result.Result;
 import com.sky.service.EmployeeService;
 import com.sky.utils.AliOssUtil;
-import com.sky.utils.JwtUtil;
-import com.sky.vo.EmployeeLoginVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.UrlResource;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
 
-import java.io.ByteArrayInputStream;
-import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.UUID;
 /**
  * @Author zhangyifan
@@ -81,19 +51,25 @@ public class EmployeeController {
 
     }
 
+//    /**
+//     * 上传表单信息
+//     *
+//     * @return
+//     */
+//    @PostMapping("/getLandImg")
+//    public Result<String> getLandImg(@RequestBody TLandimg landimg) {
+//        System.out.println("这是site: " + landimg.getSite() + " author: " + landimg.getAuthor());
+//        employeeService.postform(landimg.getAuthor(), landimg.getSite(), landimg.getPzdt(), landimg.getImgurl());
+//        return Result.success();
+//    }
+
+
     /**
-     * 上传表单信息
-     *
+     * 把拍照的图片上传到服务器 然后把url地址返回
+     * @param photo
      * @return
+     * @throws IOException
      */
-    @PostMapping("/getLandImg")
-    public Result<String> getLandImg(@RequestBody landimg landimg) {
-        System.out.println("这是site: " + landimg.getSite() + " author: " + landimg.getAuthor());
-        employeeService.postform(landimg.getAuthor(), landimg.getSite(), landimg.getPzdt(), landimg.getImgurl());
-        return Result.success();
-    }
-
-    /*图片的上传*/
     @PostMapping("/geturl")
     public Result uploadPhoto(@RequestParam("photo") MultipartFile photo) throws IOException {
 //        System.out.println("photo" + photo);
@@ -109,39 +85,9 @@ public class EmployeeController {
         } catch (IOException e) {
             log.error("上传失败");
         }
-
-//        String uploadDir = "E:/App/";
-//        // 获取文件名
-//        String originalFilename = photo.getOriginalFilename();
-//
-//
-//        try {
-//            // 保存文件到服务器
-//            File file = new File(uploadDir + originalFilename);
-//            photo.transferTo(file);
-//            // 构建图片的 URL 地址
-//            String fileUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
-//                    .path("/admin/employee/uploads/")
-//                    .path(originalFilename)
-//                    .toUriString();
-//
-//            return Result.success(fileUrl);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//            return Result.success("error");
-//        }
         return null;
     }
 
-    /*图片的导出与下载*/
-//    @GetMapping("/uploads/{fileName:.+}")
-//    public Result savaFile(@PathVariable String fileName){
-//        System.out.println("这是fielname" + FilePath);
-//        return Result.success(FilePath);
-//    }
-
-
-
     /**
      * 登录
      *
@@ -182,13 +128,4 @@ public class EmployeeController {
         return Result.success();
     }
 
-    /**
-     * 根据手机号查询出该专家的已经填报的所有信息
-     */
-    @GetMapping("/getlandimgbyphone")
-    public Result<List<landimg>> getLandimgByPhone(@RequestParam String phone){
-        return Result.success(employeeService.getLandimgByPhone(phone));
-
-    }
-
 }

+ 48 - 0
sky-server/src/main/java/com/sky/controller/admin/LandImgController.java

@@ -0,0 +1,48 @@
+package com.sky.controller.admin;
+
+import com.sky.entity.TLandimg;
+import com.sky.result.Result;
+import com.sky.service.EmployeeService;
+import com.sky.service.ITLandimgService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/admin/employee")
+@Slf4j
+public class LandImgController {
+    @Autowired
+    private ITLandimgService itLandimgService;
+    @Autowired
+    private EmployeeService employeeService;
+
+    /**
+     * 上传表单信息
+     *
+     * @param landimg
+     * @return
+     */
+    @PostMapping("/getLandImg")
+    public Result<String> getLandImg(@RequestBody TLandimg landimg) {
+        System.out.println("这是site: " + landimg.getSite() + " author: " + landimg.getAuthor());
+//        itLandimgService.postform(landimg.getAuthor(), landimg.getSite(), landimg.getPzdt(), landimg.getImgurl());
+        itLandimgService.save(landimg);
+        return Result.success();
+    }
+
+    /**
+     * 根据当前用户的手机号   查询出当前用户已经填报的所有信息
+     *
+     * @param phone
+     * @return
+     */
+    @GetMapping("/getlandimgbyphone")
+    public Result<List<TLandimg>> getLandimgByPhone(@RequestParam String phone) {
+        return Result.success(itLandimgService.getLandimgByPhone(phone));
+
+    }
+
+}

+ 6 - 8
sky-server/src/main/java/com/sky/mapper/EmployeeMapper.java

@@ -1,9 +1,7 @@
 package com.sky.mapper;
 
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sky.entity.Employee;
-import com.sky.entity.landimg;
-import com.sky.result.Result;
+import com.sky.entity.TLandimg;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
@@ -26,12 +24,12 @@ public interface EmployeeMapper {
     @Select("SELECT * FROM t_loc64 WHERE SQRT( POW(PI() * 12656 * COS((#{volatitude} + lat) * PI() / 360) * (#{volongitude} - lng) / 180, 2) + POW(PI() * 12656 * ((#{volatitude} - lat) / 180), 2) ) < 100 limit 3")
     List<Employee> getLocation(double volatitude, double volongitude);
 
-    @Insert("INSERT INTO t_landimg (author, site, pzdt, imgurl)\n" +
-            "VALUES (#{author}, #{site}, #{pzdt}, #{imgurl})")
-    void postform(String author, String site, LocalDate pzdt, String imgurl);
+//    @Insert("INSERT INTO t_landimg (author, site, pzdt, imgurl)\n" +
+//            "VALUES (#{author}, #{site}, #{pzdt}, #{imgurl})")
+//    void postform(String author, String site, LocalDate pzdt, String imgurl);
 
-   @Select("SELECT * FROM t_landimg where author = (SELECT user FROM t_expert WHERE phone = #{phone} )")
-    List<landimg> getLandimgByPhone(String phone);
+//   @Select("SELECT * FROM t_landimg where author = (SELECT user FROM t_expert WHERE phone = #{phone} )")
+//    List<TLandimg> getLandimgByPhone(String phone);
 
 
 }

+ 23 - 0
sky-server/src/main/java/com/sky/mapper/TLandimgMapper.java

@@ -0,0 +1,23 @@
+package com.sky.mapper;
+
+import com.sky.entity.TLandimg;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author yfzhang
+ * @since 2024-04-23
+ */
+@Mapper
+public interface TLandimgMapper extends BaseMapper<TLandimg> {
+    
+    List<TLandimg> getLandimgByPhone(String phone);
+    
+    
+}

+ 1 - 7
sky-server/src/main/java/com/sky/service/EmployeeService.java

@@ -2,8 +2,7 @@ package com.sky.service;
 
 import com.sky.dto.EmployeeLoginDTO;
 import com.sky.entity.Employee;
-import com.sky.entity.landimg;
-import com.sky.result.Result;
+import com.sky.entity.TLandimg;
 
 import java.time.LocalDate;
 import java.util.List;
@@ -19,12 +18,7 @@ public interface EmployeeService {
 
     List<Employee> getlocation(double volatitude, double volongitude);
 
-    void postform(String author, String site, LocalDate pzdt, String imgurl);
 
-    /**
-     * 根据手机号查询出该专家的已经填报的所有信息
-     */
-    List<landimg> getLandimgByPhone(String phone);
 
 
 }

+ 26 - 0
sky-server/src/main/java/com/sky/service/ITLandimgService.java

@@ -0,0 +1,26 @@
+package com.sky.service;
+
+import com.sky.entity.TLandimg;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author yfzhang
+ * @since 2024-04-23
+ */
+
+
+public interface ITLandimgService extends IService<TLandimg> {
+    /**
+     * 根据手机号查询已填报的信息
+     * @param phone
+     * @return
+     */
+    List<TLandimg> getLandimgByPhone(String phone);
+}

+ 1 - 15
sky-server/src/main/java/com/sky/service/impl/EmployeeServiceImpl.java

@@ -4,16 +4,14 @@ import com.sky.constant.MessageConstant;
 import com.sky.constant.StatusConstant;
 import com.sky.dto.EmployeeLoginDTO;
 import com.sky.entity.Employee;
-import com.sky.entity.landimg;
+import com.sky.entity.TLandimg;
 import com.sky.exception.AccountLockedException;
 import com.sky.exception.AccountNotFoundException;
 import com.sky.exception.PasswordErrorException;
 import com.sky.mapper.EmployeeMapper;
-import com.sky.result.Result;
 import com.sky.service.EmployeeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.DigestUtils;
 
 import java.time.LocalDate;
 import java.util.List;
@@ -64,19 +62,7 @@ public class EmployeeServiceImpl implements EmployeeService {
         return employeeMapper.getLocation(volatitude, volongitude);
     }
 
-    @Override
-    public void postform(String author, String site, LocalDate pzdt, String imgurl) {
-        employeeMapper.postform(author, site, pzdt, imgurl);
-    }
 
-    /**
-     * 根据手机号查询出该专家的已经填报的所有信息
-     */
-    @Override
-    public List<landimg> getLandimgByPhone(String phone) {
-        return employeeMapper.getLandimgByPhone(phone);
-
-    }
 
 
 }

+ 35 - 0
sky-server/src/main/java/com/sky/service/impl/TLandimgServiceImpl.java

@@ -0,0 +1,35 @@
+package com.sky.service.impl;
+
+import com.sky.entity.TLandimg;
+import com.sky.mapper.TLandimgMapper;
+import com.sky.service.ITLandimgService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sky.service.ITLandimgService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author yfzhang
+ * @since 2024-04-23
+ */
+@Service
+public class TLandimgServiceImpl extends ServiceImpl<TLandimgMapper, TLandimg> implements ITLandimgService {
+@Autowired
+private TLandimgMapper tLandimgMapper;
+
+    /**
+     * 根据手机号查询已填报的信息
+     * @param phone
+     * @return
+     */
+    @Override
+    public List<TLandimg> getLandimgByPhone(String phone) {
+        return tLandimgMapper.getLandimgByPhone(phone);
+    }
+}

+ 2 - 0
sky-server/src/main/resources/application-dev.yml

@@ -13,5 +13,7 @@ aielab:
     access-key-id: LTAI5tAkp8NfeaDavReh4s3U
     access-key-secret: RUT4IGfE79ObWbolXeDAiVXqdtrobT
     bucket-name: aielab-zht
+mybatis-plus:
+  mapper-locations: "classpath*:/mapper/**/*.xml" # Mapper.xml文件地址,当前这个是默认值。
 
 

+ 11 - 0
sky-server/src/main/resources/mapper/TLandimgMapper.xml

@@ -0,0 +1,11 @@
+<?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.sky.mapper.TLandimgMapper">
+
+
+    <select id="getLandimgByPhone" resultType="com.sky.entity.TLandimg" parameterType="String">
+        SELECT * FROM t_landimg
+        WHERE author = (SELECT user FROM t_expert WHERE phone = #{phone})
+    </select>
+
+</mapper>