master
fjj 2024-02-01 20:59:48 +08:00
parent 0eabfde4d9
commit 8b5cb3f715
12 changed files with 310 additions and 21 deletions

View File

@ -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;
@ -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);
}

View File

@ -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());
}
};
}
}

View File

@ -15,6 +15,12 @@
</description>
<dependencies>
<!-- Oss上传 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
@ -51,6 +57,10 @@
<groupId>HomeWork</groupId>
<artifactId>HomeWork-common-security</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

View File

@ -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 AccessKeyaccessKeySecretAPI访 访
*/
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;
}
/**
* 使FilePutObject ** 使
* @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;
}
}

View File

@ -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,6 +13,7 @@ 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
@ -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)

View File

@ -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,6 +18,7 @@ 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;
/**
*
@ -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;
}
}

View File

@ -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));
}
}

View 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;
}

View File

@ -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);
}

View File

@ -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);
}

View 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);

View File

@ -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">