Browse Source

fit: 用户管理-新增用户功能

fit: 风险问题录入时调用重新计算分值的接口
main
wxc 12 months ago
parent
commit
7b9bff7da0
  1. 5
      src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelController.java
  2. 11
      src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskClueController.java
  3. 5
      src/main/java/com/biutag/supervision/controller/system/UserController.java
  4. 2
      src/main/java/com/biutag/supervision/pojo/dto/UserDto.java
  5. 2
      src/main/java/com/biutag/supervision/pojo/entity/RiskModelTaskClue.java
  6. 54
      src/main/java/com/biutag/supervision/service/BaseUserService.java
  7. 21
      src/test/java/com/biutag/supervision/StrUtil.java

5
src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelController.java

@ -39,6 +39,11 @@ public class ModelController {
return Result.success(modelService.page(new Page<>(queryParam.getCurrent(), queryParam.getSize()), queryWrapper));
}
@GetMapping("{id}")
public Result<Model> list(@PathVariable String id) {
return Result.success(modelService.getById(id));
}
@GetMapping("tree")
public Result<List<ModelTree>> tree() {
List<ModelClassModel> modelClasses = modelClassMapper.selectListByStatus();

11
src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskClueController.java

@ -2,6 +2,8 @@ package com.biutag.supervision.controller.sensitivePerception;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -13,6 +15,7 @@ import com.biutag.supervision.pojo.param.RiskModelTaskClueQueryParam;
import com.biutag.supervision.service.ModelService;
import com.biutag.supervision.service.RiskModelTaskClueService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
@ -25,6 +28,7 @@ import java.util.stream.Collectors;
* @author wxc
* @date 2024/11/14
*/
@Slf4j
@RequiredArgsConstructor
@RequestMapping("risk/clues")
@RestController
@ -56,7 +60,6 @@ public class RiskClueController {
}
@PostMapping
public Result<Void> save(@RequestBody RiskClueDto clue) {
List<Model> models = modelService.list(new LambdaUpdateWrapper<Model>().eq(Model::getRiskScoreRuleId, clue.getRiskScoreRuleId()));
if (models.isEmpty()) {
@ -67,8 +70,14 @@ public class RiskClueController {
riskModelTaskClue.setModelId(models.get(0).getId());
riskModelTaskClue.setCreateTime(LocalDateTime.now());
riskModelTaskClue.setTaskId(-1);
// 来源
riskModelTaskClue.setSource(1);
riskModelTaskClueService.save(riskModelTaskClue);
HttpResponse httpResponse = HttpUtil.createGet(String.format("http://65.47.6.110:8567/api/score?idCodes=%s", clue.getIdCode()))
.execute();
log.info("请求重新计算返回结果为:{}", httpResponse.body());
return Result.success();
}
}

5
src/main/java/com/biutag/supervision/controller/system/UserController.java

@ -23,6 +23,11 @@ public class UserController {
}
@PostMapping
public Result<Boolean> add(@RequestBody UserDto userDto) {
return Result.success(baseUserService.save(userDto));
}
@PutMapping
public Result<Boolean> update(@RequestBody UserDto userDto) {
return Result.success(baseUserService.update(userDto));
}

2
src/main/java/com/biutag/supervision/pojo/dto/UserDto.java

@ -34,4 +34,6 @@ public class UserDto {
private List<String> roleIds;
private String password;
}

2
src/main/java/com/biutag/supervision/pojo/entity/RiskModelTaskClue.java

@ -91,4 +91,6 @@ public class RiskModelTaskClue {
@TableLogic(value = AppConstants.UN_DEL, delval = AppConstants.DEL)
private Boolean del;
private Integer source;
}

54
src/main/java/com/biutag/supervision/service/BaseUserService.java

@ -1,12 +1,15 @@
package com.biutag.supervision.service;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biutag.supervision.mapper.BaseUserMapper;
import com.biutag.supervision.pojo.dto.UserDto;
import com.biutag.supervision.pojo.entity.BaseAccount;
import com.biutag.supervision.pojo.entity.BaseRole;
import com.biutag.supervision.pojo.entity.BaseRoleUser;
import com.biutag.supervision.pojo.entity.BaseUser;
@ -14,7 +17,10 @@ import com.biutag.supervision.pojo.model.UserModel;
import com.biutag.supervision.pojo.param.UserQueryParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
@ -30,6 +36,8 @@ public class BaseUserService extends ServiceImpl<BaseUserMapper, BaseUser> {
private final BaseRoleService roleService;
private final BaseAccountService accountService;
public Page<UserModel> page(UserQueryParam queryParam) {
LambdaQueryWrapper<BaseUser> queryWrapper = new LambdaQueryWrapper<BaseUser>()
.like(StrUtil.isNotBlank(queryParam.getUserName()), BaseUser::getUserName, queryParam.getUserName())
@ -70,12 +78,44 @@ public class BaseUserService extends ServiceImpl<BaseUserMapper, BaseUser> {
return getOne(new LambdaQueryWrapper<BaseUser>().eq(BaseUser::getUserName, userName));
}
@Transactional(rollbackFor = Exception.class)
@DS("slave")
public boolean update(UserDto userDto) {
public boolean save(UserDto userDto) {
if (exists(new LambdaQueryWrapper<BaseUser>().eq(BaseUser::getUserName, userDto.getUserName()))) {
throw new RuntimeException(String.format("该用户[登录名:%s]已存在", userDto.getUserName()));
}
BaseUser baseUser = new BaseUser();
BeanUtils.copyProperties(userDto, baseUser);
baseUser.setUserId(IdUtil.getSnowflakeNextIdStr());
baseUser.setUpdateTime(LocalDateTime.now());
roleUserService.remove(userDto.getUserId());
baseUser.setCreateTime(LocalDateTime.now());
save(baseUser);
if (!userDto.getRoleIds().isEmpty()) {
roleUserService.saveBatch(userDto.getRoleIds().stream().map(roleId -> {
BaseRoleUser baseRoleUser = new BaseRoleUser();
baseRoleUser.setUserId(baseUser.getUserId());
baseRoleUser.setRoleId(roleId);
baseRoleUser.setCreateTime(LocalDateTime.now());
baseRoleUser.setUpdateTime(LocalDateTime.now());
return baseRoleUser;
}).toList());
}
BaseAccount account = new BaseAccount();
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String encode = encoder.encode(userDto.getPassword());
account.setPassword(encode);
account.setAccount(userDto.getUserName());
account.setAccountId(IdUtil.getSnowflakeNextIdStr());
account.setUserId(baseUser.getUserId());
account.setAccountType("username");
account.setDomain("@admin.com");
account.setCreateTime(LocalDateTime.now());
account.setUpdateTime(LocalDateTime.now());
return accountService.save(account);
}
@DS("slave")
public boolean update(UserDto userDto) {
if (!userDto.getRoleIds().isEmpty()) {
roleUserService.saveBatch(userDto.getRoleIds().stream().map(roleId -> {
BaseRoleUser baseRoleUser = new BaseRoleUser();
@ -86,7 +126,15 @@ public class BaseUserService extends ServiceImpl<BaseUserMapper, BaseUser> {
return baseRoleUser;
}).toList());
}
return updateById(baseUser);
LambdaUpdateWrapper<BaseUser> updateWrapper = new LambdaUpdateWrapper<BaseUser>()
.eq(BaseUser::getUserId, userDto.getUserId())
.set(BaseUser::getNickName, userDto.getNickName())
.set(BaseUser::getEmail, userDto.getEmail())
.set(BaseUser::getMobile, userDto.getMobile())
.set(BaseUser::getUserName, userDto.getUserType())
.set(BaseUser::getUserDesc, userDto.getUserDesc())
.set(BaseUser::getUpdateTime, LocalDateTime.now());
return update(updateWrapper);
}
}

21
src/test/java/com/biutag/supervision/StrUtil.java

@ -1,29 +1,18 @@
package com.biutag.supervision;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileTypeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import com.biutag.supervision.util.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URL;
import java.time.LocalDate;
import java.util.List;
public class StrUtil {
@Test
public void testSubstr() throws FileNotFoundException {
ImgUtil.compress(new File("C:\\Users\\ldj\\Desktop\\文件类型\\1204.png"), new File("C:\\Users\\ldj\\Desktop\\文件类型\\1204.jpg"), 1);
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String encode = encoder.encode("123456");
System.out.println(BCrypt.checkpw("123456", encode));
}
}

Loading…
Cancel
Save