2.1
parent
0eabfde4d9
commit
8b5cb3f715
|
@ -1,5 +1,6 @@
|
|||
package HomeWork.system.api;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
@ -15,7 +16,7 @@ import HomeWork.system.api.model.LoginUser;
|
|||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
||||
|
@ -40,4 +41,6 @@ public interface RemoteUserService
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
R<LoginUser> faceLogin(@Param("s") String s, @Param("inner") String inner);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import HomeWork.system.api.model.LoginUser;
|
|||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
|
@ -36,6 +36,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
{
|
||||
return R.fail("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<LoginUser> faceLogin(String s, String inner) {
|
||||
return R.fail("人脸登录失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,53 +7,63 @@
|
|||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>HomeWork-auth</artifactId>
|
||||
|
||||
|
||||
<description>
|
||||
HomeWork-auth认证授权中心
|
||||
</description>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Oss上传 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.10.2</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 Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- RuoYi Common Security-->
|
||||
<dependency>
|
||||
<groupId>HomeWork</groupId>
|
||||
<artifactId>HomeWork-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
|
@ -70,5 +80,5 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
package HomeWork.auth;
|
||||
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
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 = "LTAI5tLE4XbyvvbuT7D2stCk";
|
||||
private static String accessKeySecret = "W7ZeT4dMrMPP0c8BBwcyIPnhe3P4E8";
|
||||
private static String accessPre = "https://lyb1314.oss-cn-shanghai.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "lyb1314";
|
||||
|
||||
private static OSS ossClient ;
|
||||
|
||||
static {
|
||||
ossClient = new OSSClientBuilder().build(
|
||||
endPoint,
|
||||
accessKeyId,
|
||||
accessKeySecret);
|
||||
log.info("oss服务连接成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传本地文件
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,10 +2,7 @@ package HomeWork.auth.controller;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import HomeWork.auth.form.LoginBody;
|
||||
import HomeWork.auth.form.RegisterBody;
|
||||
import HomeWork.auth.service.SysLoginService;
|
||||
|
@ -16,10 +13,11 @@ import HomeWork.common.security.auth.AuthUtil;
|
|||
import HomeWork.common.security.service.TokenService;
|
||||
import HomeWork.common.security.utils.SecurityUtils;
|
||||
import HomeWork.system.api.model.LoginUser;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
|
@ -39,6 +37,15 @@ public class TokenController
|
|||
// 获取登录token
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
@PostMapping("/faceLogin")
|
||||
public R<?> faceLogin(@RequestParam MultipartFile file){
|
||||
LoginUser userInfo=sysLoginService.faceLogin(file);
|
||||
if (userInfo!=null){
|
||||
return R.fail("登录失败");
|
||||
}
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("logout")
|
||||
public R<?> logout(HttpServletRequest request)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package HomeWork.auth.service;
|
||||
|
||||
import HomeWork.auth.OssUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import HomeWork.common.core.constant.CacheConstants;
|
||||
|
@ -17,10 +18,11 @@ import HomeWork.common.security.utils.SecurityUtils;
|
|||
import HomeWork.system.api.RemoteUserService;
|
||||
import HomeWork.system.api.domain.SysUser;
|
||||
import HomeWork.system.api.model.LoginUser;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
|
@ -83,7 +85,7 @@ public class SysLoginService
|
|||
{
|
||||
throw new ServiceException(userResult.getMsg());
|
||||
}
|
||||
|
||||
|
||||
LoginUser userInfo = userResult.getData();
|
||||
SysUser user = userResult.getData().getSysUser();
|
||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
||||
|
@ -140,4 +142,16 @@ public class SysLoginService
|
|||
}
|
||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
}
|
||||
|
||||
public LoginUser faceLogin(MultipartFile file) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@ package HomeWork.community.controller;
|
|||
|
||||
import HomeWork.common.core.domain.R;
|
||||
import HomeWork.community.domain.dto.PlotDto;
|
||||
import HomeWork.community.domain.entity.PopulationEntity;
|
||||
import HomeWork.community.domain.vo.PlotVo;
|
||||
import HomeWork.community.domain.vo.TreeVo;
|
||||
import HomeWork.community.service.CommunityService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -35,4 +38,28 @@ public class CommunityController {
|
|||
public R add(@RequestBody PlotDto plotDto) {
|
||||
return R.ok(communityService.add(plotDto));
|
||||
}
|
||||
//批量删除
|
||||
@DeleteMapping("/del")
|
||||
public String delall(String ids){
|
||||
List<String> delList = new ArrayList<>();
|
||||
String[] strs = ids.split(",");
|
||||
for (String str : strs) {
|
||||
delList.add(str);
|
||||
}
|
||||
//开始循环批量删除
|
||||
return communityService.batchDeletes(delList);
|
||||
}
|
||||
@RequestMapping("/delByID")
|
||||
public String delByID(int id){
|
||||
return communityService.delByID(id);
|
||||
}
|
||||
@GetMapping("/population/list")
|
||||
public R<List<PopulationEntity>> populationList() {
|
||||
List<PopulationEntity> populationEntityList = communityService.populationList();
|
||||
return R.ok(populationEntityList);
|
||||
}
|
||||
@PostMapping("/file")
|
||||
public R uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
return R.ok(communityService.uploadFile(file));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package HomeWork.community.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName : PopulationEntity
|
||||
* @Description :人口
|
||||
* @Author : FJJ
|
||||
* @Date: 2024-02-01 14:33
|
||||
*/
|
||||
@Data
|
||||
public class PopulationEntity {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String nation;
|
||||
private Integer sex;
|
||||
private String appearance;
|
||||
private String phone;
|
||||
private String plot;
|
||||
private String certificate;
|
||||
private String address;
|
||||
private String avatar;
|
||||
private Integer deletes;
|
||||
}
|
|
@ -29,4 +29,8 @@ public interface CommunityMapper {
|
|||
List<PlotVo> plotList(@Param("id") Integer id);
|
||||
|
||||
int add(PlotDto plotDto);
|
||||
|
||||
String batchDeletes(List<String> delList);
|
||||
|
||||
String delByID(@Param("id") int id);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@ package HomeWork.community.service;
|
|||
|
||||
import HomeWork.common.core.domain.R;
|
||||
import HomeWork.community.domain.dto.PlotDto;
|
||||
import HomeWork.community.domain.entity.PopulationEntity;
|
||||
import HomeWork.community.domain.vo.PlotVo;
|
||||
import HomeWork.community.domain.vo.TreeVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -20,4 +22,12 @@ public interface CommunityService {
|
|||
List<PlotVo> plotList(Integer id);
|
||||
|
||||
R add(PlotDto plotDto);
|
||||
|
||||
String batchDeletes(List<String> delList);
|
||||
|
||||
String delByID(int id);
|
||||
|
||||
List<PopulationEntity> populationList();
|
||||
|
||||
R uploadFile(MultipartFile file);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package HomeWork.community.service.serviceImpl;
|
|||
|
||||
import HomeWork.common.core.domain.R;
|
||||
import HomeWork.community.domain.dto.PlotDto;
|
||||
import HomeWork.community.domain.entity.PopulationEntity;
|
||||
import HomeWork.community.domain.entity.TreeEntity;
|
||||
import HomeWork.community.domain.vo.PlotVo;
|
||||
import HomeWork.community.domain.vo.TreeVo;
|
||||
|
@ -10,6 +11,7 @@ import HomeWork.community.service.CommunityService;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -54,6 +56,26 @@ public class CommunityServiceImpl implements CommunityService {
|
|||
return R.ok("添加成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String batchDeletes(List<String> delList) {
|
||||
return communityMapper.batchDeletes(delList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String delByID(int id) {
|
||||
return communityMapper.delByID(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PopulationEntity> populationList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R uploadFile(MultipartFile file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<TreeVo> findChildren(Integer id) {
|
||||
ArrayList<TreeVo> treeVos = new ArrayList<>();
|
||||
List<TreeEntity> treeEntities = communityMapper.findChildren(id);
|
||||
|
|
|
@ -7,6 +7,15 @@
|
|||
insert into plot
|
||||
values (0, #{name}, #{parentId}, #{address}, #{img}, null, null,#{num})
|
||||
</insert>
|
||||
<delete id="batchDeletes">
|
||||
delete from plot where id in
|
||||
<foreach collection="delList" item="plotId" open="(" separator="," close=")">
|
||||
#{plotId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="delByID">
|
||||
delete from plot where id = #{id}
|
||||
</delete>
|
||||
|
||||
|
||||
<select id="findChildren" resultType="HomeWork.community.domain.entity.TreeEntity">
|
||||
|
|
Loading…
Reference in New Issue