假期作业
parent
a353d1caef
commit
79d3f69f3c
|
@ -44,6 +44,6 @@ public interface RemoteUserService
|
|||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/user/faceLogin")
|
||||
public R<LoginUser> faceLogin(@RequestParam("url") String url) throws Exception;
|
||||
public R<LoginUser> faceLogin(@RequestParam("url") String url, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
}
|
||||
|
|
|
@ -89,6 +89,9 @@ public class SysUser extends BaseEntity
|
|||
/** 角色ID */
|
||||
private Long roleId;
|
||||
|
||||
@Excel(name = "人脸识别图片")
|
||||
private String faceImg;
|
||||
|
||||
public SysUser()
|
||||
{
|
||||
|
||||
|
@ -296,6 +299,15 @@ public class SysUser extends BaseEntity
|
|||
{
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public String getFaceImg() {
|
||||
return faceImg;
|
||||
}
|
||||
|
||||
public void setFaceImg(String faceImg) {
|
||||
this.faceImg = faceImg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
@ -318,6 +330,7 @@ public class SysUser extends BaseEntity
|
|||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.append("dept", getDept())
|
||||
.append("faceImg",getFaceImg())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
}
|
||||
|
||||
@Override
|
||||
public R<LoginUser> faceLogin(String url) throws Exception {
|
||||
public R<LoginUser> faceLogin(String url,String source) {
|
||||
return R.fail("人脸登录失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -58,11 +58,6 @@
|
|||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-common-security</artifactId>
|
||||
</dependency>
|
||||
<!--lombok依赖-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -38,11 +38,13 @@ public class TokenController
|
|||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
||||
@PostMapping("faceLogin")
|
||||
public R<?> login(@RequestParam MultipartFile file)
|
||||
{
|
||||
@PostMapping("/faceLogin")
|
||||
public R<?> login(@RequestParam MultipartFile file) throws Exception {
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.faceLogin(file);
|
||||
if (userInfo==null){
|
||||
return R.fail("人脸登录失败");
|
||||
}
|
||||
// 获取登录token
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
|
|
@ -143,8 +143,15 @@ public class SysLoginService
|
|||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
}
|
||||
|
||||
public LoginUser faceLogin(MultipartFile file) {
|
||||
public LoginUser faceLogin(MultipartFile file) throws Exception {
|
||||
String s = OssUtil.uploadMultipartFile(file);
|
||||
R<LoginUser> loginUserR = remoteUserService.faceLogin(s,SecurityConstants.INNER);
|
||||
if (loginUserR!=null){
|
||||
if (loginUserR.getData()!=null){
|
||||
return loginUserR.getData();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,11 @@
|
|||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--lombok依赖-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,119 @@
|
|||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>HomeWork-modules-MedicalTreatment</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 人脸-->
|
||||
<dependency>
|
||||
<groupId>com.baidu.aip</groupId>
|
||||
<artifactId>java-sdk</artifactId>
|
||||
<version>4.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20160810</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Log -->
|
||||
<dependency>
|
||||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,34 @@
|
|||
package HomeWork;
|
||||
|
||||
import HomeWork.common.security.annotation.EnableCustomConfig;
|
||||
import HomeWork.common.security.annotation.EnableRyFeignClients;
|
||||
import HomeWork.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 系统模块
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableRyFeignClients
|
||||
@SpringBootApplication
|
||||
public class HomeWorkMedicalTreatmentApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(HomeWorkMedicalTreatmentApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ 系统模块启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
" .-------. ____ __ \n" +
|
||||
" | _ _ \\ \\ \\ / / \n" +
|
||||
" | ( ' ) | \\ _. / ' \n" +
|
||||
" |(_ o _) / _( )_ .' \n" +
|
||||
" | (_,_).' __ ___(_ o _)' \n" +
|
||||
" | |\\ \\ | || |(_,_)' \n" +
|
||||
" | | \\ `' /| `-' / \n" +
|
||||
" | | \\ / \\ / \n" +
|
||||
" ''-' `'-' `-..-' ");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package HomeWork.controller;
|
||||
|
||||
import HomeWork.common.core.domain.R;
|
||||
import HomeWork.domain.vo.TreeVo;
|
||||
import HomeWork.service.TreeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class TreeController {
|
||||
@Autowired
|
||||
private TreeService treeService;
|
||||
|
||||
@GetMapping("/tree")
|
||||
public R<List<TreeVo>> tree() {
|
||||
List<TreeVo> treeVos= treeService.treeList();
|
||||
return R.ok(treeVos);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package HomeWork.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TreeEntity {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer parentId;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package HomeWork.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TreeVo {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer parentId;
|
||||
private List<TreeVo> children;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package HomeWork.mapper;
|
||||
|
||||
import HomeWork.domain.TreeEntity;
|
||||
import HomeWork.domain.vo.TreeVo;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@DS("slave")
|
||||
public interface TreeMapper {
|
||||
List<TreeEntity> treeList();
|
||||
|
||||
List<TreeEntity> treeListByTreeParentId(Integer parentId);
|
||||
|
||||
List<TreeEntity> findChildren(Integer id);
|
||||
|
||||
List<TreeEntity> treeListByTreeIds(@Param("ids") String[] split);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package HomeWork.service;
|
||||
|
||||
import HomeWork.domain.vo.TreeVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TreeService {
|
||||
List<TreeVo> treeList();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package HomeWork.service.impl;
|
||||
|
||||
import HomeWork.domain.TreeEntity;
|
||||
import HomeWork.domain.vo.TreeVo;
|
||||
import HomeWork.mapper.TreeMapper;
|
||||
import HomeWork.service.TreeService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class TreeServiceImpl implements TreeService {
|
||||
@Autowired
|
||||
private TreeMapper treeMapper;
|
||||
@Override
|
||||
public List<TreeVo> treeList() {
|
||||
ArrayList<TreeVo> treeVos = new ArrayList<>();
|
||||
List<TreeEntity> treeVoList = treeMapper.treeList();
|
||||
if (treeVoList.size()>0){
|
||||
for (TreeEntity tree : treeVoList) {
|
||||
TreeVo treeVo = new TreeVo();
|
||||
BeanUtils.copyProperties(tree,treeVo);
|
||||
List<TreeVo> children = findChildren(tree.getId());
|
||||
treeVo.setChildren(children);
|
||||
treeVos.add(treeVo);
|
||||
}
|
||||
}
|
||||
return treeVos;
|
||||
}
|
||||
|
||||
private List<TreeVo> findChildren(Integer id) {
|
||||
ArrayList<TreeVo> treeVos = new ArrayList<>();
|
||||
List<TreeEntity> treeEntities = treeMapper.findChildren(id);
|
||||
String ids="";
|
||||
for (TreeEntity treeVo : treeEntities) {
|
||||
ids+=treeVo.getId()+",";
|
||||
}
|
||||
String[] split = ids.split(",");
|
||||
List<TreeEntity> treeVos1 = treeMapper.treeListByTreeIds(split);
|
||||
for (TreeEntity treeVo : treeVos1) {
|
||||
TreeVo treeVo1 = new TreeVo();
|
||||
BeanUtils.copyProperties(treeVo,treeVo1);
|
||||
List<TreeEntity> children = treeMapper.findChildren(treeVo1.getId());
|
||||
if (children.size()>0){
|
||||
treeVo1.setChildren(findChildren(treeVo1.getId()));
|
||||
}
|
||||
treeVos.add(treeVo1);
|
||||
}
|
||||
return treeVos;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
||||
_ _
|
||||
(_) | |
|
||||
_ __ _ _ ___ _ _ _ ______ ___ _ _ ___ | |_ ___ _ __ ___
|
||||
| '__|| | | | / _ \ | | | || ||______|/ __|| | | |/ __|| __| / _ \| '_ ` _ \
|
||||
| | | |_| || (_) || |_| || | \__ \| |_| |\__ \| |_ | __/| | | | | |
|
||||
|_| \__,_| \___/ \__, ||_| |___/ \__, ||___/ \__| \___||_| |_| |_|
|
||||
__/ | __/ |
|
||||
|___/ |___/
|
|
@ -0,0 +1,27 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9301
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: HomeWork-community
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 101.34.77.101:8848
|
||||
namespace: 20041112
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 101.34.77.101:8848
|
||||
namespace: 20041112
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/HomeWork-system" />
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="HomeWork" level="info" />
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn" />
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info" />
|
||||
<appender-ref ref="file_error" />
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,23 @@
|
|||
<?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="HomeWork.mapper.TreeMapper">
|
||||
|
||||
|
||||
<select id="treeList" resultType="HomeWork.domain.TreeEntity">
|
||||
select * from tree where parent_id=0
|
||||
</select>
|
||||
<select id="treeListByTreeParentId" resultType="HomeWork.domain.TreeEntity">
|
||||
select * from tree where id = #{parentId}
|
||||
</select>
|
||||
<select id="findChildren" resultType="HomeWork.domain.TreeEntity">
|
||||
select * from tree where parent_id = #{id}
|
||||
</select>
|
||||
<select id="treeListByTreeIds" resultType="HomeWork.domain.TreeEntity">
|
||||
select * from tree where id in
|
||||
<foreach collection="ids" item="treeId" open="(" separator="," close=")">
|
||||
#{treeId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>HomeWork</groupId>
|
||||
|
@ -16,8 +16,13 @@
|
|||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 人脸-->
|
||||
<!-- 人脸-->
|
||||
<dependency>
|
||||
<groupId>com.baidu.aip</groupId>
|
||||
<artifactId>java-sdk</artifactId>
|
||||
|
|
|
@ -125,18 +125,18 @@ public class SysUserController extends BaseController
|
|||
|
||||
/**
|
||||
* 人脸登录
|
||||
* @param username
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
|
||||
@InnerAuth
|
||||
@GetMapping("/faceLogin")
|
||||
@PostMapping("/faceLogin")
|
||||
public R<LoginUser> faceLogin(@RequestParam("url") String url)
|
||||
{
|
||||
SysUser sysUser = userService.selectUserByUrl(url);
|
||||
if (StringUtils.isNull(sysUser))
|
||||
{
|
||||
return R.fail("用户名或密码错误");
|
||||
return R.fail("人脸识别错误");
|
||||
}
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(sysUser);
|
||||
|
|
|
@ -124,4 +124,10 @@ public interface SysUserMapper
|
|||
* @return 结果
|
||||
*/
|
||||
public SysUser checkEmailUnique(String email);
|
||||
|
||||
/**
|
||||
* 人脸识别查询所有信息
|
||||
* @return
|
||||
*/
|
||||
public List<SysUser> selectUserListUserFace();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import HomeWork.system.api.model.LoginUser;
|
||||
import HomeWork.system.utils.FaceDetect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -58,6 +61,10 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private FaceDetect faceDetect;
|
||||
|
||||
|
||||
@Autowired
|
||||
protected Validator validator;
|
||||
|
||||
|
@ -544,7 +551,15 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
|
||||
@Override
|
||||
public SysUser selectUserByUrl(String url) {
|
||||
//TODO 人脸识别 调用工具类,工具类可以进行查询数据库然后进行循环比对
|
||||
//人脸识别 调用工具类,工具类可以进行查询数据库然后进行循环比对
|
||||
try {
|
||||
SysUser sysUser = faceDetect.faceDetect(url);
|
||||
if (sysUser!=null){
|
||||
return sysUser;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package HomeWork.system.test;
|
||||
|
||||
import HomeWork.system.utils.Base64Util;
|
||||
import com.baidu.aip.face.AipFace;
|
||||
import com.baidu.aip.face.MatchRequest;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class test {
|
||||
public static void main(String[] args) throws Exception {
|
||||
/**
|
||||
* 传入appId、apiKey、secretkey。创建Java代码和百度云交互的Client对象
|
||||
*/
|
||||
AipFace client = new AipFace("47745660", "ZEaoK2kFZsLdYQkt8sGrUq6M", "DcFgxv6hTgvPoENNpwKfo9CCGeXqFOAU");
|
||||
|
||||
// 登录图片
|
||||
String loginImagePath = "D:\\Camera Roll\\WIN_20240101_18_50_58_Pro.jpg";
|
||||
// 对比的图片
|
||||
String comparedImagePath = "D:\\Camera Roll\\WIN_20240101_18_50_58_Pro.jpg";
|
||||
|
||||
Double faceComparison = faceComparison(client, loginImagePath, comparedImagePath);
|
||||
System.out.println("返回信息:"+faceComparison);
|
||||
}
|
||||
|
||||
static Double faceComparison(AipFace client, String loginImagePath, String comparedImagePath) throws Exception {
|
||||
byte[] loginImageBytes = Files.readAllBytes(Paths.get(loginImagePath));
|
||||
byte[] comparedImageBytes = Files.readAllBytes(Paths.get(comparedImagePath));
|
||||
String image1 = Base64Util.encode(loginImageBytes);
|
||||
String image2 = Base64Util.encode(comparedImageBytes);
|
||||
|
||||
// image1/image2也可以为url或facetoken, 相应的imageType参数需要与之对应。
|
||||
MatchRequest req1 = new MatchRequest(image1, "BASE64");
|
||||
MatchRequest req2 = new MatchRequest(image2, "BASE64");
|
||||
ArrayList<MatchRequest> requests = new ArrayList<>();
|
||||
requests.add(req1);
|
||||
requests.add(req2);
|
||||
|
||||
JSONObject match = client.match(requests);
|
||||
System.out.println(match.toString(2));
|
||||
return match.getJSONObject("result").getDouble("score");
|
||||
}
|
||||
}
|
|
@ -1,16 +1,25 @@
|
|||
package HomeWork.system.utils;
|
||||
|
||||
import HomeWork.system.utils.Base64Util;
|
||||
import HomeWork.system.api.domain.SysUser;
|
||||
import HomeWork.system.mapper.SysUserMapper;
|
||||
import com.baidu.aip.face.AipFace;
|
||||
import com.baidu.aip.face.MatchRequest;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
public class FaceDetect {
|
||||
import java.util.List;
|
||||
|
||||
public String faceDetect(String face) throws Exception {
|
||||
@Component
|
||||
public class FaceDetect {
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
public SysUser faceDetect(String face) throws Exception {
|
||||
/**
|
||||
* 传入appId、apiKey、secretkey。创建Java代码和百度云交互的Client对象
|
||||
*/
|
||||
|
@ -18,21 +27,33 @@ public class FaceDetect {
|
|||
|
||||
// 登录图片
|
||||
String loginImagePath = face;
|
||||
// 对比的图片
|
||||
String comparedImagePath = "D:\\Camera Roll\\WIN_20240101_18_50_58_Pro.jpg";
|
||||
List<SysUser> users=sysUserMapper.selectUserListUserFace();
|
||||
if(users.size()>0){
|
||||
//循环整个用户信息拿到用户保存的图片
|
||||
for (SysUser user : users) {
|
||||
// 对比的图片
|
||||
String comparedImagePath = user.getFaceImg();
|
||||
|
||||
Double faceComparison = faceComparison(client, loginImagePath, comparedImagePath);
|
||||
System.out.println("返回信息:"+faceComparison);
|
||||
if (faceComparison > 90) {
|
||||
return "人脸识别登录成功";
|
||||
} else {
|
||||
return "人脸识别登录失败";
|
||||
Double faceComparison = faceComparison(client, loginImagePath, comparedImagePath);
|
||||
System.out.println("返回信息:"+faceComparison);
|
||||
if (faceComparison > 90) {
|
||||
return user;
|
||||
}else {
|
||||
//抛异常
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Double faceComparison(AipFace client, String loginImagePath, String comparedImagePath) throws Exception {
|
||||
byte[] loginImageBytes = Files.readAllBytes(Paths.get(loginImagePath));
|
||||
byte[] comparedImageBytes = Files.readAllBytes(Paths.get(comparedImagePath));
|
||||
URL url = new URL(loginImagePath);
|
||||
URLConnection conn = url.openConnection();
|
||||
byte[] loginImageBytes = IOUtils.toByteArray(conn.getInputStream());
|
||||
URL url2 = new URL(comparedImagePath);
|
||||
URLConnection conn2 = url2.openConnection();
|
||||
byte[] comparedImageBytes = IOUtils.toByteArray(conn2.getInputStream());
|
||||
String image1 = Base64Util.encode(loginImageBytes);
|
||||
String image2 = Base64Util.encode(comparedImageBytes);
|
||||
|
||||
|
|
|
@ -141,6 +141,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
|
||||
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
||||
</select>
|
||||
<select id="selectUserListUserFace" resultType="HomeWork.system.api.domain.SysUser">
|
||||
select * from sys_user
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="HomeWork.system.api.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into sys_user(
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<module>HomeWork-gen</module>
|
||||
<module>HomeWork-job</module>
|
||||
<module>HomeWork-file</module>
|
||||
<module>HomeWork-MedicalTreatment</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>HomeWork-modules</artifactId>
|
||||
|
|
Loading…
Reference in New Issue