|
@@ -1,7 +1,9 @@
|
|
|
package com.pj.project.app_user;
|
|
|
|
|
|
import cn.dev33.satoken.spring.SpringMVCUtil;
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -18,6 +20,7 @@ import com.pj.current.satoken.StpAPPUserUtil;
|
|
|
import com.pj.current.satoken.StpUserUtil;
|
|
|
import com.pj.enummj.DeleteStatus;
|
|
|
import com.pj.enummj.IsLock;
|
|
|
+import com.pj.face.factory.FaceFactory;
|
|
|
import com.pj.project.app_user.dto.ForgetPasswordDto;
|
|
|
import com.pj.project.app_user.dto.LoginDto;
|
|
|
import com.pj.project.app_user.dto.PassDto;
|
|
@@ -40,7 +43,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -79,7 +85,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
* 阿里云验证码
|
|
|
*/
|
|
|
@Autowired
|
|
|
- private SmsRetryService smsRetryService;
|
|
|
+ private FaceFactory faceFactory;
|
|
|
@Autowired
|
|
|
private LevelOneServerInterface levelOneServerInterface;
|
|
|
@Autowired
|
|
@@ -121,11 +127,12 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
|
|
|
/**
|
|
|
* 修改密码
|
|
|
+ *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
boolean pass(PassDto dto) {
|
|
|
- AppUser user=new AppUser();
|
|
|
+ AppUser user = new AppUser();
|
|
|
user.setId(dto.getId());
|
|
|
user.setUpdateTime(new Date());
|
|
|
user.setPassword(passwordEncoder.encode(dto.getPassword()));
|
|
@@ -232,7 +239,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
//注册身份
|
|
|
appUser.setUserType(registerDto.getType());
|
|
|
//加密并设置登陆密码
|
|
|
- String password =Aes.aesDecrypt(registerDto.getPassword());
|
|
|
+ String password = Aes.aesDecrypt(registerDto.getPassword());
|
|
|
String encode = passwordEncoder.encode(password);
|
|
|
appUser.setPassword(encode);
|
|
|
//创建单位
|
|
@@ -277,9 +284,12 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
}
|
|
|
//获取登录用户
|
|
|
AppUser appUser = userList.get(0);
|
|
|
+ if (appUser.getFace() == 1) {
|
|
|
+ // return AjaxJson.getError("该账号只支持人脸登录");
|
|
|
+ }
|
|
|
//比对密码
|
|
|
String userPassword = appUser.getPassword();
|
|
|
- boolean matches = passwordEncoder.matches(Aes.aesDecrypt(dto.getPassword()),userPassword);
|
|
|
+ boolean matches = passwordEncoder.matches(Aes.aesDecrypt(dto.getPassword()), userPassword);
|
|
|
if (!matches) {
|
|
|
loginLog.setStatus("1");
|
|
|
appUserLoginLogService.save(loginLog);
|
|
@@ -577,7 +587,6 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 用户数量统计
|
|
|
*
|
|
@@ -595,7 +604,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
* @param createDTO
|
|
|
*/
|
|
|
public void createUser(AppUserCreateDTO createDTO) {
|
|
|
- log.info("创建账号:{}",JSONUtil.toJsonStr(createDTO));
|
|
|
+ log.info("创建账号:{}", JSONUtil.toJsonStr(createDTO));
|
|
|
String phone = createDTO.getPhone().trim();
|
|
|
AppUser appUser = this.findByPhone(phone);
|
|
|
if (appUser != null) {
|
|
@@ -617,4 +626,99 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public void authFace(Long loginId, MultipartFile file) {
|
|
|
+ String img;
|
|
|
+ try (InputStream is = file.getInputStream()) {
|
|
|
+ img = Base64.encode(is);
|
|
|
+ boolean isLive = faceFactory.handler().checkIsLive(img);
|
|
|
+ if (!isLive) {
|
|
|
+ log.error("人脸注册为非活体人脸:{}", loginId);
|
|
|
+ throw new AjaxError("非活体人脸");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new AjaxError("识别失败");
|
|
|
+ }
|
|
|
+ String faceId = RandomUtil.randomString(32);
|
|
|
+ AppUser appUser = this.getById(loginId);
|
|
|
+ appUser.setFace(1);
|
|
|
+ appUser.setFaceTime(new Date()).setFaceId(faceId);
|
|
|
+ this.updateById(appUser);
|
|
|
+ faceFactory.handler().createPersonByBase(faceId, appUser.getName(), img);
|
|
|
+ }
|
|
|
+
|
|
|
+ public AjaxJson faceLogin(MultipartFile file) {
|
|
|
+ String img;
|
|
|
+ try (InputStream is = file.getInputStream()) {
|
|
|
+ img = Base64.encode(is);
|
|
|
+ boolean isLive = faceFactory.handler().checkIsLive(img);
|
|
|
+ if (!isLive) {
|
|
|
+ throw new AjaxError("非活体人脸");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new AjaxError("识别失败");
|
|
|
+ }
|
|
|
+ String faceId = faceFactory.handler().faceSearch(img);
|
|
|
+ if (StrUtil.isEmpty(faceId)) {
|
|
|
+ return AjaxJson.getError("人员未录入人脸");
|
|
|
+ }
|
|
|
+ AppUser appUser = findByFaceId(faceId);
|
|
|
+ if (appUser == null) {
|
|
|
+ return AjaxJson.getError("人员信息未找到");
|
|
|
+ }
|
|
|
+ if (appUser.getUserType() != 1) {
|
|
|
+ return AjaxJson.getError("当前用户不支持人脸登录");
|
|
|
+ }
|
|
|
+ AppUserLoginLog loginLog = new AppUserLoginLog();
|
|
|
+ loginLog.setCreateTime(new Date());
|
|
|
+ loginLog.setUserName(appUser.getPhone());
|
|
|
+ loginLog.setLoginIp(WebNbUtil.getIP(SpringMVCUtil.getRequest()));
|
|
|
+ appUserLoginLogService.save(loginLog);
|
|
|
+ //设置登录次数
|
|
|
+ appUser.setLoginCount(appUser.getLoginCount() + 1);
|
|
|
+ //设置登陆时间
|
|
|
+ appUser.setLastLoginTime(new Date());
|
|
|
+ //保存
|
|
|
+ appUserMapper.updateById(appUser);
|
|
|
+
|
|
|
+ //开始执行登录
|
|
|
+ StpAPPUserUtil.login(appUser.getId());
|
|
|
+ // 组织返回参数,直接拿过来用的,然后自己改吧改吧
|
|
|
+ SoMap map = new SoMap();
|
|
|
+ //敏感信息置空
|
|
|
+ appUser.setPassword(null);
|
|
|
+ //执行
|
|
|
+ map.put("appUser", appUser);
|
|
|
+ //获取当前用户角色权限字符
|
|
|
+ List<ReRoleMenu> reRoleMenus = reRoleMenuMapper.selectList(new LambdaQueryWrapper<ReRoleMenu>().eq(ReRoleMenu::getAppRoleId, appUser.getUserType()));
|
|
|
+ //使用stream流对其reRoleMenus集合的权限字符进行过滤顺便转成String类型
|
|
|
+ List<String> per_list = reRoleMenus.stream().map(ReRoleMenu::getAppMenuId).collect(Collectors.toList()).stream().map(String::valueOf).collect(Collectors.toList());
|
|
|
+ //过滤出权限字符
|
|
|
+ map.put("per_list", per_list);
|
|
|
+ map.put("tokenInfo", StpAPPUserUtil.getTokenInfo());
|
|
|
+ APPLoginUserInfo info = new APPLoginUserInfo();
|
|
|
+ PeopleDto rpcById = levelOneServerInterface.getRpcById(appUser.getFkId());
|
|
|
+ if (rpcById != null) {
|
|
|
+ info.setTradeAreaId(rpcById.getTradeAreaId());
|
|
|
+ info.setTradeAreaName(rpcById.getTradeAreaName());
|
|
|
+ }
|
|
|
+ info.setLoginId(appUser.getId());
|
|
|
+ info.setLoginName(appUser.getName());
|
|
|
+ info.setFk(appUser.getFkId());
|
|
|
+ info.setUserType(appUser.getUserType());
|
|
|
+ StpAPPUserUtil.cacheAPPLoginInfo(info);
|
|
|
+ return AjaxJson.getSuccessData(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据人脸ID查找数据库
|
|
|
+ *
|
|
|
+ * @param faceId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AppUser findByFaceId(String faceId) {
|
|
|
+ QueryWrapper<AppUser> ew = new QueryWrapper<>();
|
|
|
+ ew.lambda().eq(AppUser::getFaceId, faceId);
|
|
|
+ List<AppUser> list = list(ew);
|
|
|
+ return list.isEmpty() ? null : list.get(0);
|
|
|
+ }
|
|
|
}
|