forked from opengaussexamples/examples
add Find Friends Server
This commit is contained in:
parent
e7d3fbffde
commit
5cfa0b9072
|
|
@ -0,0 +1,33 @@
|
|||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
### Description
|
||||
|
||||
This is a server for finding friends.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
### 介绍
|
||||
|
||||
这是一个找朋友的服务端案例。
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>gauss</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>gauss</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gauss</groupId>
|
||||
<artifactId>java-connector</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.lamdaer.opengauss.gauss;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/23
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "com.lamdaer")
|
||||
@MapperScan(basePackages = "com.lamdaer.opengauss.gauss.mapper")
|
||||
public class GaussApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GaussApplication.class, args);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.lamdaer.opengauss.gauss.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/23
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class GaussException extends RuntimeException {
|
||||
private Integer code;
|
||||
private String message;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.lamdaer.opengauss.gauss.common;
|
||||
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/23
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(GaussException.class)
|
||||
@ResponseBody
|
||||
public Result customError(GaussException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.toString());
|
||||
return Result.error().message(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseBody
|
||||
public Result methodArgumentNotValid(MethodArgumentNotValidException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.toString());
|
||||
return Result.error().message(e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Result exception(Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.toString());
|
||||
return Result.error().message(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.lamdaer.opengauss.gauss.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/23
|
||||
*/
|
||||
@Data
|
||||
public class Result {
|
||||
private Boolean success;
|
||||
private Integer code;
|
||||
private String message;
|
||||
private Map<String, Object> data = new HashMap<>();
|
||||
|
||||
private Result() {
|
||||
}
|
||||
|
||||
public static Result ok() {
|
||||
Result result = new Result();
|
||||
result.setSuccess(true);
|
||||
result.setCode(ResultCode.SUCCESS);
|
||||
result.setMessage("成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error() {
|
||||
Result result = new Result();
|
||||
result.setSuccess(false);
|
||||
result.setCode(ResultCode.ERROR);
|
||||
result.setMessage("失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
public Result success(Boolean success) {
|
||||
this.setSuccess(success);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result code(Integer code) {
|
||||
this.setCode(code);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result message(String message) {
|
||||
this.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result data(String key, Object value) {
|
||||
this.data.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.lamdaer.opengauss.gauss.common;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/23
|
||||
*/
|
||||
public interface ResultCode {
|
||||
Integer SUCCESS = 20000;
|
||||
Integer ERROR = 20001;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.lamdaer.opengauss.gauss.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
|
||||
/**
|
||||
* Jackson 全局转化 Long 类型为String,解决前端 Long 类型精度丢失问题
|
||||
* @return Jackson2ObjectMapperBuilderCustomizer 注入的对象
|
||||
*/
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||
return jacksonObjectMapperBuilder -> {
|
||||
jacksonObjectMapperBuilder.serializerByType(Long.TYPE, ToStringSerializer.instance);
|
||||
jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.lamdaer.opengauss.gauss.controller;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.common.Result;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyVo;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好二级分类 前端控制器
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Api(tags = "爱好")
|
||||
@RestController
|
||||
@RequestMapping("/gauss/hobby")
|
||||
public class HobbyController {
|
||||
@Autowired
|
||||
private HobbyService hobbyService;
|
||||
|
||||
@ApiOperation("添加爱好")
|
||||
@PostMapping
|
||||
public Result addHobby(@RequestBody @Valid HobbyVo hobbyVo) {
|
||||
hobbyService.addHobby(hobbyVo);
|
||||
return Result.ok();
|
||||
}
|
||||
@ApiOperation("获取爱好列表")
|
||||
@GetMapping
|
||||
public Result getHobbyList() {
|
||||
List<Hobby> hobbyList = hobbyService.getHobbyList();
|
||||
return Result.ok().data("hobbyList", hobbyList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.lamdaer.opengauss.gauss.controller;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.common.Result;
|
||||
import com.lamdaer.opengauss.gauss.entity.HobbyParent;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyParentVo;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyParentService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好一级分类 前端控制器
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Api(tags = "爱好一级分类")
|
||||
@RestController
|
||||
@RequestMapping("/gauss/hobby_parent")
|
||||
public class HobbyParentController {
|
||||
|
||||
@Autowired
|
||||
private HobbyParentService hobbyParentService;
|
||||
|
||||
@ApiOperation("添加爱好一级分类")
|
||||
@PostMapping
|
||||
public Result addHobbyParent(String name) {
|
||||
hobbyParentService.addHobbyParent(name);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("获取爱好一级分类")
|
||||
@GetMapping
|
||||
public Result getHobbyParentList() {
|
||||
List<HobbyParent> hobbyParentList = hobbyParentService.getHobbyParentList();
|
||||
return Result.ok().data("hobbyParentList", hobbyParentList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取爱好一级分类及其子分类")
|
||||
@GetMapping("with_children")
|
||||
public Result getHobbyParentListWithChildren() {
|
||||
List<HobbyParentVo> list = hobbyParentService.getHobbyParentListWithChildren();
|
||||
return Result.ok().data("list", list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.lamdaer.opengauss.gauss.controller;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.common.Result;
|
||||
import com.lamdaer.opengauss.gauss.entity.Job;
|
||||
import com.lamdaer.opengauss.gauss.service.JobService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位 前端控制器
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Api(tags = "岗位")
|
||||
@RestController
|
||||
@RequestMapping("/gauss/job")
|
||||
public class JobController {
|
||||
@Autowired
|
||||
private JobService jobService;
|
||||
|
||||
@ApiOperation("添加岗位")
|
||||
@PostMapping
|
||||
public Result addJob(@RequestParam String name) {
|
||||
jobService.addJob(name);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("获取岗位列表")
|
||||
@GetMapping
|
||||
public Result getJobList() {
|
||||
List<Job> jobList = jobService.getJobList();
|
||||
return Result.ok().data("jobList", jobList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.lamdaer.opengauss.gauss.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 com.lamdaer.opengauss.gauss.common.Result;
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
import com.lamdaer.opengauss.gauss.service.SimilarityService;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/gauss/similarity")
|
||||
public class SimilarityController {
|
||||
@Autowired
|
||||
private SimilarityService similarityService;
|
||||
|
||||
@ApiOperation("相似度检测")
|
||||
@GetMapping("{userId}")
|
||||
public Result getSimilarUser(@PathVariable Long userId) {
|
||||
List<UserInfo> userList = similarityService.similarity(userId);
|
||||
return Result.ok().data("similarUser", userList);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.lamdaer.opengauss.gauss.controller;
|
||||
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.common.Result;
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.UserInfoVo;
|
||||
import com.lamdaer.opengauss.gauss.service.UserInfoService;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息 前端控制器
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/gauss/user_info")
|
||||
public class UserInfoController {
|
||||
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@ApiOperation("添加用户信息")
|
||||
@PostMapping
|
||||
public Result addUserInfo(@RequestBody @Valid UserInfoVo userInfoVo) {
|
||||
Long userId = userInfoService.add(userInfoVo);
|
||||
return Result.ok().data("userId", userId);
|
||||
}
|
||||
|
||||
@GetMapping("{userId}")
|
||||
public Result getUserInfo(@PathVariable Long userId) {
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
return Result.ok().data("userInfo", userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.lamdaer.opengauss.gauss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好二级分类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Hobby对象", description = "爱好二级分类")
|
||||
public class Hobby implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "爱好id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "一级分类id")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty(value = "爱好名称")
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.lamdaer.opengauss.gauss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好一级分类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "HobbyParent对象", description = "爱好一级分类")
|
||||
public class HobbyParent implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "爱好一级分类id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "爱好名称")
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.lamdaer.opengauss.gauss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Job对象", description = "岗位")
|
||||
public class Job implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "岗位id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "岗位名称")
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.lamdaer.opengauss.gauss.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "UserInfo对象", description = "用户信息")
|
||||
public class UserInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "用户id")
|
||||
@TableId(value = "user_id", type = IdType.ASSIGN_ID)
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "岗位id")
|
||||
private Long jobId;
|
||||
|
||||
@ApiModelProperty(value = "爱好id")
|
||||
private String hobbyIdList;
|
||||
|
||||
@ApiModelProperty(value = "性别 1 男性 2女性")
|
||||
private Integer sex;
|
||||
|
||||
@ApiModelProperty(value = "姓名")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "年龄")
|
||||
private Integer age;
|
||||
|
||||
@ApiModelProperty(value = "手机号")
|
||||
private String phoneNumber;
|
||||
|
||||
@ApiModelProperty(value = "昵称")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty(value = "头像url")
|
||||
private String avatarUrl;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.lamdaer.opengauss.gauss.entity.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class HobbyListVo {
|
||||
@ApiModelProperty(value = "爱好id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "一级分类id")
|
||||
private Long parentId;
|
||||
|
||||
@ApiModelProperty(value = "爱好名称")
|
||||
private String text;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.lamdaer.opengauss.gauss.entity.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HobbyParentVo {
|
||||
@ApiModelProperty(value = "爱好一级分类id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "爱好名称")
|
||||
private String text;
|
||||
|
||||
@ApiModelProperty(value = "爱好二级分类列表")
|
||||
private List<HobbyListVo> children;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.lamdaer.opengauss.gauss.entity.vo;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class HobbyVo {
|
||||
@NotNull(message = "patentId can not be empty.")
|
||||
@ApiModelProperty(value = "一级分类id")
|
||||
private Long parentId;
|
||||
|
||||
@NotBlank(message = "name can not be empty.")
|
||||
@ApiModelProperty(value = "爱好名称")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.lamdaer.opengauss.gauss.entity.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserInfoVo {
|
||||
@ApiModelProperty(value = "岗位id")
|
||||
@NotNull(message = "jobId can not be empty.")
|
||||
private Long jobId;
|
||||
|
||||
@ApiModelProperty(value = "爱好id")
|
||||
@NotEmpty(message = "hobbyIdList can not be empty.")
|
||||
private List<Long> hobbyIdList;
|
||||
|
||||
@ApiModelProperty(value = "性别 1 男性 2女性")
|
||||
@NotNull(message = "sex can not be empty.")
|
||||
@Min(value = 1, message = "Illegal parameter.")
|
||||
@Max(value = 2, message = "Illegal parameter.")
|
||||
private Integer sex;
|
||||
|
||||
@ApiModelProperty(value = "年龄")
|
||||
@NotNull(message = "age can not be empty.")
|
||||
private Integer age;
|
||||
|
||||
@ApiModelProperty(value = "姓名")
|
||||
@NotBlank(message = "name can not be empty.")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "手机号")
|
||||
@NotBlank(message = "phoneNumber can not be empty.")
|
||||
private String phoneNumber;
|
||||
|
||||
@ApiModelProperty(value = "昵称")
|
||||
@NotBlank(message = "nickName can not be empty.")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty(value = "头像url")
|
||||
@NotBlank(message = "avatarUrl can not be empty.")
|
||||
private String avatarUrl;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.lamdaer.opengauss.gauss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好二级分类 Mapper 接口
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface HobbyMapper extends BaseMapper<Hobby> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.lamdaer.opengauss.gauss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lamdaer.opengauss.gauss.entity.HobbyParent;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好一级分类 Mapper 接口
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface HobbyParentMapper extends BaseMapper<HobbyParent> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.lamdaer.opengauss.gauss.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lamdaer.opengauss.gauss.entity.Job;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位 Mapper 接口
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface JobMapper extends BaseMapper<Job> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.lamdaer.opengauss.gauss.mapper;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.lamdaer.opengauss.gauss.mapper.HobbyMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.lamdaer.opengauss.gauss.mapper.HobbyParentMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.lamdaer.opengauss.gauss.mapper.JobMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.lamdaer.opengauss.gauss.mapper.UserInfoMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.lamdaer.opengauss.gauss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lamdaer.opengauss.gauss.entity.HobbyParent;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyParentVo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好一级分类 服务类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface HobbyParentService extends IService<HobbyParent> {
|
||||
/**
|
||||
* 添加爱好一级分类
|
||||
* @param name 一级分类名称
|
||||
* @return
|
||||
*/
|
||||
Boolean addHobbyParent(String name);
|
||||
|
||||
/**
|
||||
* 获取爱好一级分类列表
|
||||
* @return
|
||||
*/
|
||||
List<HobbyParent> getHobbyParentList();
|
||||
|
||||
/**
|
||||
* 获取爱好一级分类及其对应的二级分类列表
|
||||
* @return
|
||||
*/
|
||||
List<HobbyParentVo> getHobbyParentListWithChildren();
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.lamdaer.opengauss.gauss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyVo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好二级分类 服务类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface HobbyService extends IService<Hobby> {
|
||||
|
||||
/**
|
||||
* 添加爱好
|
||||
* @param hobbyVo 爱好vo
|
||||
* @return
|
||||
*/
|
||||
Boolean addHobby(HobbyVo hobbyVo);
|
||||
|
||||
/**
|
||||
* 获取爱好列表
|
||||
* @return
|
||||
*/
|
||||
List<Hobby> getHobbyList();
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.lamdaer.opengauss.gauss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lamdaer.opengauss.gauss.entity.Job;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位 服务类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface JobService extends IService<Job> {
|
||||
|
||||
/**
|
||||
* 添加岗位
|
||||
* @param name 岗位名称
|
||||
* @return
|
||||
*/
|
||||
Boolean addJob(String name);
|
||||
|
||||
/**
|
||||
* 获取岗位列表
|
||||
* @return
|
||||
*/
|
||||
List<Job> getJobList();
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.lamdaer.opengauss.gauss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
public interface SimilarityService {
|
||||
/**
|
||||
* 相似度计算
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<UserInfo> similarity(Long userId);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.lamdaer.opengauss.gauss.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.UserInfoVo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息 服务类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
public interface UserInfoService extends IService<UserInfo> {
|
||||
/**
|
||||
* 添加用户信息
|
||||
* @param userInfoVo
|
||||
* @return
|
||||
*/
|
||||
Long add(UserInfoVo userInfoVo);
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package com.lamdaer.opengauss.gauss.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lamdaer.opengauss.gauss.common.GaussException;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
import com.lamdaer.opengauss.gauss.entity.HobbyParent;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyListVo;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyParentVo;
|
||||
import com.lamdaer.opengauss.gauss.mapper.HobbyParentMapper;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyParentService;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好一级分类 服务实现类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Service
|
||||
public class HobbyParentServiceImpl extends ServiceImpl<HobbyParentMapper, HobbyParent> implements HobbyParentService {
|
||||
@Autowired
|
||||
private HobbyService hobbyService;
|
||||
|
||||
@Override
|
||||
public Boolean addHobbyParent(String name) {
|
||||
if (StringUtils.isEmpty(name) || name.trim() == "") {
|
||||
throw new GaussException(20001, "Illegal parameter.");
|
||||
}
|
||||
HobbyParent hobbyParent = new HobbyParent();
|
||||
hobbyParent.setName(name);
|
||||
int insert = baseMapper.insert(hobbyParent);
|
||||
return insert > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HobbyParent> getHobbyParentList() {
|
||||
List<HobbyParent> hobbyParents = baseMapper.selectList(null);
|
||||
return hobbyParents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HobbyParentVo> getHobbyParentListWithChildren() {
|
||||
List<HobbyParent> hobbyParentList = this.getHobbyParentList();
|
||||
List<HobbyParentVo> hobbyParentVoList = new ArrayList<>();
|
||||
for (HobbyParent parent : hobbyParentList) {
|
||||
Long parentId = parent.getId();
|
||||
|
||||
// 通过一级爱好 ID 查询子爱好
|
||||
QueryWrapper<Hobby> hobbyQueryWrapper = new QueryWrapper<>();
|
||||
hobbyQueryWrapper.eq("parent_id", parentId);
|
||||
List<Hobby> hobbies = hobbyService.getBaseMapper().selectList(hobbyQueryWrapper);
|
||||
List<HobbyListVo> hobbyListVos = new ArrayList<>();
|
||||
for (Hobby hobby : hobbies) {
|
||||
HobbyListVo hobbyListVo = new HobbyListVo();
|
||||
BeanUtils.copyProperties(hobby, hobbyListVo);
|
||||
hobbyListVo.setText(hobby.getName());
|
||||
hobbyListVos.add(hobbyListVo);
|
||||
}
|
||||
|
||||
HobbyParentVo hobbyParentVo = new HobbyParentVo();
|
||||
BeanUtils.copyProperties(parent, hobbyParentVo);
|
||||
hobbyParentVo.setText(parent.getName());
|
||||
hobbyParentVo.setChildren(hobbyListVos);
|
||||
hobbyParentVoList.add(hobbyParentVo);
|
||||
}
|
||||
return hobbyParentVoList;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.lamdaer.opengauss.gauss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lamdaer.opengauss.gauss.common.GaussException;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
import com.lamdaer.opengauss.gauss.entity.HobbyParent;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.HobbyVo;
|
||||
import com.lamdaer.opengauss.gauss.mapper.HobbyMapper;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyParentService;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 爱好二级分类 服务实现类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Service
|
||||
public class HobbyServiceImpl extends ServiceImpl<HobbyMapper, Hobby> implements HobbyService {
|
||||
@Autowired
|
||||
private HobbyParentService hobbyParentService;
|
||||
|
||||
@Override
|
||||
public Boolean addHobby(HobbyVo hobbyVo) {
|
||||
HobbyParent hobbyParent = hobbyParentService.getById(hobbyVo.getParentId());
|
||||
if (hobbyParent == null) {
|
||||
throw new GaussException(20001, "hobby parent is not exist.");
|
||||
}
|
||||
Hobby hobby = new Hobby();
|
||||
BeanUtils.copyProperties(hobbyVo, hobby);
|
||||
int insert = baseMapper.insert(hobby);
|
||||
return insert > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Hobby> getHobbyList() {
|
||||
List<Hobby> hobbies = baseMapper.selectList(null);
|
||||
return hobbies;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.lamdaer.opengauss.gauss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lamdaer.opengauss.gauss.common.GaussException;
|
||||
import com.lamdaer.opengauss.gauss.entity.Job;
|
||||
import com.lamdaer.opengauss.gauss.mapper.JobMapper;
|
||||
import com.lamdaer.opengauss.gauss.service.JobService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位 服务实现类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Service
|
||||
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobService {
|
||||
@Override
|
||||
public Boolean addJob(String name) {
|
||||
if (StringUtils.isEmpty(name) || name.trim() == "") {
|
||||
throw new GaussException(20001, "Illegal parameter.");
|
||||
}
|
||||
Job job = new Job();
|
||||
job.setName(name);
|
||||
int insert = baseMapper.insert(job);
|
||||
return insert > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Job> getJobList() {
|
||||
List<Job> jobList = baseMapper.selectList(null);
|
||||
return jobList;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
package com.lamdaer.opengauss.gauss.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.lamdaer.opengauss.gauss.common.GaussException;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyService;
|
||||
import com.lamdaer.opengauss.gauss.service.SimilarityService;
|
||||
import com.lamdaer.opengauss.gauss.service.UserInfoService;
|
||||
import com.lamdaer.opengauss.gauss.utils.MapUtil;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
@Service
|
||||
public class SimilarityServiceImpl implements SimilarityService {
|
||||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
private HobbyService hobbyService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserInfo> similarity(Long userId) {
|
||||
if (userId == null) {
|
||||
throw new GaussException(20001, "Illegal parameter.");
|
||||
}
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
Long jobId = userInfo.getJobId();
|
||||
Integer age = userInfo.getAge();
|
||||
Integer sex = userInfo.getSex();
|
||||
List<Hobby> hobbyList = hobbyService.getHobbyList();
|
||||
List<UserInfo> userInfoList = userInfoService.getBaseMapper().selectList(null);
|
||||
Map<Long, Integer> result = new HashMap<>(userInfoList.size());
|
||||
for (UserInfo user : userInfoList) {
|
||||
if (user.getUserId().equals(userId)) {
|
||||
continue;
|
||||
}
|
||||
int count = 0;
|
||||
|
||||
// 岗位相似度
|
||||
if (user.getJobId().equals(jobId)) {
|
||||
count += 4;
|
||||
}
|
||||
|
||||
// 性别
|
||||
if (!user.getSex().equals(sex)){
|
||||
count += 10;
|
||||
}
|
||||
|
||||
// 年龄相似度
|
||||
int differenceAge = Math.abs(age - user.getAge());
|
||||
switch (differenceAge) {
|
||||
case 0:
|
||||
count += 5;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
count += 4;
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
count += 3;
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
count += 2;
|
||||
break;
|
||||
default:
|
||||
count += 1;
|
||||
}
|
||||
|
||||
// 爱好相似度
|
||||
String[] split = user.getHobbyIdList().split(",");
|
||||
List<Long> hobbies = Arrays.stream(split).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
||||
if (user.getJobId().equals(jobId)) {
|
||||
count += 4;
|
||||
}
|
||||
Set<Long> same = new HashSet<>();
|
||||
Set<Long> temp = new HashSet<>();
|
||||
for (int i = 0; i < hobbyList.size(); i++) {
|
||||
temp.add(hobbyList.get(i).getId());
|
||||
}
|
||||
for (int j = 0; j < hobbies.size(); j++) {
|
||||
if (!temp.add(hobbies.get(j))) {
|
||||
same.add(hobbies.get(j));
|
||||
}
|
||||
}
|
||||
count += same.size() * 5;
|
||||
|
||||
result.put(user.getUserId(), count);
|
||||
|
||||
}
|
||||
Map<Long, Integer> longIntegerMap = MapUtil.sortByValueDesc(result);
|
||||
Set<Long> userIds = longIntegerMap.keySet();
|
||||
List<Long> userIdList = new ArrayList<>(userIds);
|
||||
List<UserInfo> userInfos = new ArrayList<>();
|
||||
for (Long id : userIdList.subList(0, 3)) {
|
||||
UserInfo user = userInfoService.getById(id);
|
||||
userInfos.add(user);
|
||||
}
|
||||
return userInfos;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.lamdaer.opengauss.gauss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lamdaer.opengauss.gauss.common.GaussException;
|
||||
import com.lamdaer.opengauss.gauss.entity.Hobby;
|
||||
import com.lamdaer.opengauss.gauss.entity.Job;
|
||||
import com.lamdaer.opengauss.gauss.entity.UserInfo;
|
||||
import com.lamdaer.opengauss.gauss.entity.vo.UserInfoVo;
|
||||
import com.lamdaer.opengauss.gauss.mapper.UserInfoMapper;
|
||||
import com.lamdaer.opengauss.gauss.service.HobbyService;
|
||||
import com.lamdaer.opengauss.gauss.service.JobService;
|
||||
import com.lamdaer.opengauss.gauss.service.UserInfoService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息 服务实现类
|
||||
* </p>
|
||||
* @author Lamdaer
|
||||
* @since 2020-10-24
|
||||
*/
|
||||
@Service
|
||||
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
|
||||
@Autowired
|
||||
private HobbyService hobbyService;
|
||||
|
||||
@Autowired
|
||||
private JobService jobService;
|
||||
|
||||
@Override
|
||||
public Long add(UserInfoVo userInfoVo) {
|
||||
Long jobId = userInfoVo.getJobId();
|
||||
List<Long> hobbyIdList = userInfoVo.getHobbyIdList();
|
||||
|
||||
// 检查岗位是否存在
|
||||
Job job = jobService.getById(jobId);
|
||||
if (job == null) {
|
||||
throw new GaussException(20001, "job is not exist.");
|
||||
}
|
||||
|
||||
// 检查爱好是否存在
|
||||
for (Long hobbyId : hobbyIdList) {
|
||||
Hobby hobby = hobbyService.getById(hobbyId);
|
||||
if (hobby == null) {
|
||||
throw new GaussException(20001, "hobby is not exist.");
|
||||
}
|
||||
}
|
||||
UserInfo userInfo = new UserInfo();
|
||||
BeanUtils.copyProperties(userInfoVo, userInfo);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
// 爱好id列表转换为字符串 格式如:[11111,22222]
|
||||
for (int i = 0; i < hobbyIdList.size(); i++) {
|
||||
stringBuilder.append(hobbyIdList.get(i));
|
||||
if (i != hobbyIdList.size() - 1) {
|
||||
stringBuilder.append(",");
|
||||
}
|
||||
}
|
||||
String str = stringBuilder.toString();
|
||||
userInfo.setHobbyIdList(str);
|
||||
int insert = baseMapper.insert(userInfo);
|
||||
if (insert > 0) {
|
||||
return userInfo.getUserId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.lamdaer.opengauss.gauss.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author lamdaer
|
||||
* @createTime 2020/10/24
|
||||
*/
|
||||
public class MapUtil {
|
||||
private static Comparator<Map.Entry> comparatorByValueAsc = (Map.Entry o1, Map.Entry o2) -> {
|
||||
if (o1.getValue() instanceof Comparable) {
|
||||
return ((Comparable) o1.getValue()).compareTo(o2.getValue());
|
||||
}
|
||||
throw new UnsupportedOperationException("值的类型尚未实现Comparable接口");
|
||||
};
|
||||
|
||||
|
||||
private static Comparator<Map.Entry> comparatorByValueDesc = (Map.Entry o1, Map.Entry o2) -> {
|
||||
if (o1.getValue() instanceof Comparable) {
|
||||
return ((Comparable) o2.getValue()).compareTo(o1.getValue());
|
||||
}
|
||||
throw new UnsupportedOperationException("值的类型尚未实现Comparable接口");
|
||||
};
|
||||
|
||||
/**
|
||||
* 按值升序排列
|
||||
*/
|
||||
public static <K, V> Map<K, V> sortByValueAsc(Map<K, V> originMap) {
|
||||
if (originMap == null) {
|
||||
return null;
|
||||
}
|
||||
return sort(originMap, comparatorByValueAsc);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按值降序排列
|
||||
*/
|
||||
public static <K, V> Map<K, V> sortByValueDesc(Map<K, V> originMap) {
|
||||
if (originMap == null) {
|
||||
return null;
|
||||
}
|
||||
return sort(originMap, comparatorByValueDesc);
|
||||
}
|
||||
|
||||
private static <K, V> Map<K, V> sort(Map<K, V> originMap, Comparator<Map.Entry> comparator) {
|
||||
return originMap.entrySet()
|
||||
.stream()
|
||||
.sorted(comparator)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
server:
|
||||
port: 8001
|
||||
#生产环境设为 false
|
||||
springfox:
|
||||
documentation:
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
spring:
|
||||
datasource:
|
||||
url:
|
||||
username:
|
||||
password:
|
||||
driver-class-name:
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
name: opengauss
|
||||
|
||||
mybatis-plus:
|
||||
global-config:
|
||||
db-config:
|
||||
logic-delete-field: isDeleted
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.example.gauss;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class GaussApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue