|
@@ -14,6 +14,8 @@ import me.zhengjie.annotation.rest.AnonymousGetMapping;
|
|
import me.zhengjie.annotation.rest.AnonymousPostMapping;
|
|
import me.zhengjie.annotation.rest.AnonymousPostMapping;
|
|
import me.zhengjie.base.BaseResponse;
|
|
import me.zhengjie.base.BaseResponse;
|
|
import me.zhengjie.base.QueryPageParams;
|
|
import me.zhengjie.base.QueryPageParams;
|
|
|
|
+import me.zhengjie.config.RsaProperties;
|
|
|
|
+import me.zhengjie.domain.LocalStorage;
|
|
import me.zhengjie.exception.BadRequestException;
|
|
import me.zhengjie.exception.BadRequestException;
|
|
import me.zhengjie.modules.dm.user.domain.DmUser;
|
|
import me.zhengjie.modules.dm.user.domain.DmUser;
|
|
import me.zhengjie.modules.dm.user.service.DmUserService;
|
|
import me.zhengjie.modules.dm.user.service.DmUserService;
|
|
@@ -25,12 +27,14 @@ import me.zhengjie.modules.security.security.TokenProvider;
|
|
import me.zhengjie.modules.security.service.OnlineUserService;
|
|
import me.zhengjie.modules.security.service.OnlineUserService;
|
|
import me.zhengjie.modules.security.service.dto.JwtUserDto;
|
|
import me.zhengjie.modules.security.service.dto.JwtUserDto;
|
|
import me.zhengjie.modules.system.domain.User;
|
|
import me.zhengjie.modules.system.domain.User;
|
|
|
|
+import me.zhengjie.modules.system.domain.vo.UserMessage;
|
|
|
|
+import me.zhengjie.modules.system.domain.vo.UserPassVo;
|
|
import me.zhengjie.modules.system.repository.UserRepository;
|
|
import me.zhengjie.modules.system.repository.UserRepository;
|
|
import me.zhengjie.modules.system.service.*;
|
|
import me.zhengjie.modules.system.service.*;
|
|
import me.zhengjie.modules.system.service.dto.*;
|
|
import me.zhengjie.modules.system.service.dto.*;
|
|
-import me.zhengjie.utils.EncryptUtils;
|
|
|
|
-import me.zhengjie.utils.SecurityUtils;
|
|
|
|
-import me.zhengjie.utils.StringUtils;
|
|
|
|
|
|
+import me.zhengjie.modules.system.service.mapstruct.UserMapper;
|
|
|
|
+import me.zhengjie.service.LocalStorageService;
|
|
|
|
+import me.zhengjie.utils.*;
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Criteria;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
@@ -42,14 +46,14 @@ import org.springframework.security.config.annotation.authentication.builders.Au
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -71,9 +75,10 @@ public class UserApiController {
|
|
private final SecurityProperties properties;
|
|
private final SecurityProperties properties;
|
|
@Resource
|
|
@Resource
|
|
private LoginProperties loginProperties;
|
|
private LoginProperties loginProperties;
|
|
-
|
|
|
|
|
|
+ private final LocalStorageService localStorageService;
|
|
private final PasswordEncoder passwordEncoder;
|
|
private final PasswordEncoder passwordEncoder;
|
|
private final UserRepository userRepository;
|
|
private final UserRepository userRepository;
|
|
|
|
+ private final UserMapper userMapper;
|
|
private final String erpapiUrl = "https://portal.caih.com";
|
|
private final String erpapiUrl = "https://portal.caih.com";
|
|
|
|
|
|
private final String key = "DMERPYT!@#$QWER2021+{:>";
|
|
private final String key = "DMERPYT!@#$QWER2021+{:>";
|
|
@@ -209,6 +214,9 @@ public class UserApiController {
|
|
public BaseResponse<Object> login(String name,String pass) throws Exception {
|
|
public BaseResponse<Object> login(String name,String pass) throws Exception {
|
|
// String dataStr = passwordEncoder.encode(pass);
|
|
// String dataStr = passwordEncoder.encode(pass);
|
|
User user = userRepository.findByUsername(name);
|
|
User user = userRepository.findByUsername(name);
|
|
|
|
+
|
|
|
|
+ Map<String,Object> path = this.localStorageService.findByRealName(user.getAvatarName());
|
|
|
|
+ user.setAvatarName(path.get("url").toString());
|
|
if (user != null){
|
|
if (user != null){
|
|
boolean bo = passwordEncoder.matches(pass,user.getPassword());
|
|
boolean bo = passwordEncoder.matches(pass,user.getPassword());
|
|
if (bo){
|
|
if (bo){
|
|
@@ -239,10 +247,63 @@ public class UserApiController {
|
|
public BaseResponse<Object> getzkusers(@RequestBody QueryPageParams<DmUserQueryCriteria> params, Pageable pageable) {
|
|
public BaseResponse<Object> getzkusers(@RequestBody QueryPageParams<DmUserQueryCriteria> params, Pageable pageable) {
|
|
SecurityUtils.CheckApiAuth(params);
|
|
SecurityUtils.CheckApiAuth(params);
|
|
Map<String, Object> list = dmUserService.queryAll(params.getQuery(), pageable);
|
|
Map<String, Object> list = dmUserService.queryAll(params.getQuery(), pageable);
|
|
-
|
|
|
|
return new BaseResponse<>(list);
|
|
return new BaseResponse<>(list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Log("修改密码")
|
|
|
|
+ @ApiOperation("修改用户数据密码")
|
|
|
|
+ @AnonymousPostMapping(value = "/edit/zkuser/pass")
|
|
|
|
+ public BaseResponse<Object> editzkuser(@RequestBody QueryPageParams<UserMessage> params) throws Exception{
|
|
|
|
+ SecurityUtils.CheckApiAuth(params);
|
|
|
|
+ String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, RsaUtils.encryptByPublicKey(RsaProperties.publicKey,params.getQuery().getOldPass()));
|
|
|
|
+ String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,RsaUtils.encryptByPublicKey(RsaProperties.publicKey,params.getQuery().getNewPass()));
|
|
|
|
+ Map<String,String> map = userRepository.findUserById(params.getQuery().getUserId());
|
|
|
|
+ User user = JSONObject.parseObject(JSONObject.toJSONString(map), User.class);
|
|
|
|
+ if(!passwordEncoder.matches(oldPass, map.get("password"))){
|
|
|
|
+ throw new BadRequestException("修改失败,旧密码错误");
|
|
|
|
+ }
|
|
|
|
+ if(passwordEncoder.matches(newPass, user.getPassword())){
|
|
|
|
+ throw new BadRequestException("新密码不能与旧密码相同");
|
|
|
|
+ }
|
|
|
|
+ userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass));
|
|
|
|
+ return new BaseResponse(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Log("修改头像")
|
|
|
|
+ @ApiOperation("修改用户数据头像")
|
|
|
|
+ @AnonymousPostMapping(value = "/edit/zkuser/picture")
|
|
|
|
+ public BaseResponse<Object> editzkuserpicture(@RequestParam String params,@RequestParam(value = "multipartFile") MultipartFile multipartFile) throws Exception {
|
|
|
|
+ QueryPageParams queryPageParams = JSONObject.parseObject(params, QueryPageParams.class);
|
|
|
|
+
|
|
|
|
+ SecurityUtils.CheckApiAuth(queryPageParams);
|
|
|
|
+ UserMessage userMessage = JSONObject.parseObject(queryPageParams.getQuery().toString(), UserMessage.class);
|
|
|
|
+ //根据用户名查询用户 一对一 精准查询
|
|
|
|
+ UserDto user= userService.findById(userMessage.getUserId());
|
|
|
|
+ //获取头像旧文件名 唯一的
|
|
|
|
+ String oldName = user.getAvatarName();
|
|
|
|
+ //上传文件
|
|
|
|
+ LocalStorage file = this.localStorageService.create(null, multipartFile);
|
|
|
|
+ //设置头像路径
|
|
|
|
+ user.setAvatarPath(Objects.requireNonNull(file).getPath());
|
|
|
|
+ //设置头像名称
|
|
|
|
+ user.setAvatarName(file.getRealName());
|
|
|
|
+ //保存用户 会根据数据自动修改
|
|
|
|
+ userService.update(userMapper.toEntity(user));
|
|
|
|
+ //判断旧文件名是否是null的
|
|
|
|
+ if (StringUtils.isNotBlank(oldName)) {
|
|
|
|
+ //根据旧文件地址名删除文件
|
|
|
|
+ if (FileUtil.del(oldName)){
|
|
|
|
+// 删除成功需要删除对应文件表中的数据 toolf_local_storage
|
|
|
|
+ this.localStorageService.deleteByUrl(oldName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return new BaseResponse(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
@Log("根据密文获取用户信息")
|
|
@Log("根据密文获取用户信息")
|
|
@ApiOperation("根据密文获取用户信息")
|
|
@ApiOperation("根据密文获取用户信息")
|
|
@AnonymousGetMapping(value = "/getZkUserByCipher")
|
|
@AnonymousGetMapping(value = "/getZkUserByCipher")
|