Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
e16aecb8d5
|
@ -3,6 +3,7 @@ package com.diboot.core.starter;
|
|||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.diboot.core.config.Cons;
|
||||
import com.diboot.core.util.D;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -17,6 +18,7 @@ import org.springframework.core.env.Environment;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -55,9 +57,9 @@ public class CoreAutoConfiguration{
|
|||
@Bean
|
||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
|
||||
//处理中文乱码问题
|
||||
converter.setDefaultCharset(Charset.forName(Cons.CHARSET_UTF8));
|
||||
List<MediaType> fastMediaTypes = new ArrayList<>();
|
||||
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
fastMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
converter.setSupportedMediaTypes(fastMediaTypes);
|
||||
// 配置转换格式
|
||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Map;
|
|||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseExcelFileController extends BaseFileController {
|
||||
// 初始文件名参数
|
||||
protected static final String ORIGIN_FILE_NAME = "originFileName";
|
||||
// 预览文件名参数
|
||||
protected static final String PREVIEW_FILE_NAME = "previewFileName";
|
||||
|
||||
|
@ -106,7 +108,7 @@ public abstract class BaseExcelFileController extends BaseFileController {
|
|||
}
|
||||
// 绑定属性到model
|
||||
dataMap.put("header", listener.getHeadMap());
|
||||
dataMap.put("originFileName", fileName);
|
||||
dataMap.put(ORIGIN_FILE_NAME, fileName);
|
||||
dataMap.put(PREVIEW_FILE_NAME, newFileName);
|
||||
List dataList = listener.getDataList();
|
||||
if(V.notEmpty(dataList) && dataList.size() > BaseConfig.getPageSize()){
|
||||
|
|
|
@ -39,7 +39,7 @@ public interface IamUserService extends BaseIamService<IamUser> {
|
|||
* @param userAccountDTO
|
||||
* @return
|
||||
*/
|
||||
boolean createUserAndAccount(IamUserAccountDTO userAccountDTO);
|
||||
boolean createUserAndAccount(IamUserAccountDTO userAccountDTO) throws Exception;
|
||||
|
||||
/***
|
||||
* 更新用户和账号
|
||||
|
|
|
@ -99,9 +99,74 @@ public class IamUserServiceImpl extends BaseIamServiceImpl<IamUserMapper, IamUse
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createUserAndAccount(IamUserAccountDTO userAccountDTO) {
|
||||
public boolean createUserAndAccount(IamUserAccountDTO userAccountDTO) throws Exception {
|
||||
// 创建用户信息
|
||||
boolean userSuccess = this.createEntity(userAccountDTO);
|
||||
this.createEntity(userAccountDTO);
|
||||
// 如果提交的有账号信息,则新建账号信息
|
||||
if (V.notEmpty(userAccountDTO.getUsername())) {
|
||||
// 新建account账号
|
||||
this.createAccount(userAccountDTO);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateUserAndAccount(IamUserAccountDTO userAccountDTO) throws Exception {
|
||||
// 更新用户信息
|
||||
this.updateEntity(userAccountDTO);
|
||||
|
||||
IamAccount iamAccount = iamAccountService.getSingleEntity(
|
||||
Wrappers.<IamAccount>lambdaQuery()
|
||||
.eq(IamAccount::getUserType, IamUser.class.getSimpleName())
|
||||
.eq(IamAccount::getUserId, userAccountDTO.getId())
|
||||
);
|
||||
|
||||
if (iamAccount == null) {
|
||||
if (V.isEmpty(userAccountDTO.getUsername())){
|
||||
return true;
|
||||
} else {
|
||||
// 新建account账号
|
||||
this.createAccount(userAccountDTO);
|
||||
}
|
||||
} else {
|
||||
if (V.isEmpty(userAccountDTO.getUsername())) {
|
||||
// 删除账号
|
||||
this.deleteAccount(userAccountDTO.getId());
|
||||
} else {
|
||||
// 更新账号
|
||||
iamAccount.setAuthAccount(userAccountDTO.getUsername())
|
||||
.setStatus(userAccountDTO.getStatus());
|
||||
// 设置密码
|
||||
if (V.notEmpty(userAccountDTO.getPassword())){
|
||||
iamAccount.setAuthSecret(userAccountDTO.getPassword());
|
||||
IamSecurityUtils.encryptPwd(iamAccount);
|
||||
}
|
||||
iamAccountService.updateEntity(iamAccount);
|
||||
|
||||
// 批量更新角色关联关系
|
||||
iamUserRoleService.updateUserRoleRelations(iamAccount.getUserType(), iamAccount.getUserId(), userAccountDTO.getRoleIdList());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteUserAndAccount(Long id) throws Exception {
|
||||
IamUser iamUser = this.getEntity(id);
|
||||
if (iamUser == null){
|
||||
throw new BusinessException(Status.FAIL_OPERATION, "删除的记录不存在");
|
||||
}
|
||||
// 删除用户信息
|
||||
this.deleteEntity(id);
|
||||
// 删除账号信息
|
||||
this.deleteAccount(id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void createAccount(IamUserAccountDTO userAccountDTO) throws Exception{
|
||||
// 创建账号信息
|
||||
IamAccount iamAccount = new IamAccount();
|
||||
iamAccount
|
||||
|
@ -115,73 +180,25 @@ public class IamUserServiceImpl extends BaseIamServiceImpl<IamUserMapper, IamUse
|
|||
if (V.notEmpty(iamAccount.getAuthSecret())){
|
||||
IamSecurityUtils.encryptPwd(iamAccount);
|
||||
}
|
||||
boolean accountSuccess = iamAccountService.createEntity(iamAccount);
|
||||
iamAccountService.createEntity(iamAccount);
|
||||
|
||||
// 批量创建角色关联关系
|
||||
boolean relationsSuccess = iamUserRoleService.createUserRoleRelations(iamAccount.getUserType(), iamAccount.getUserId(), userAccountDTO.getRoleIdList());
|
||||
|
||||
if (!userSuccess || !accountSuccess || !relationsSuccess){
|
||||
throw new BusinessException(Status.FAIL_OPERATION, "创建用户失败");
|
||||
}
|
||||
return true;
|
||||
iamUserRoleService.createUserRoleRelations(iamAccount.getUserType(), iamAccount.getUserId(), userAccountDTO.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateUserAndAccount(IamUserAccountDTO userAccountDTO) {
|
||||
// 更新用户信息
|
||||
boolean userSuccess = this.updateEntity(userAccountDTO);
|
||||
|
||||
// 更新账号信息
|
||||
IamAccount iamAccount = iamAccountService.getSingleEntity(
|
||||
Wrappers.<IamAccount>lambdaQuery()
|
||||
.eq(IamAccount::getUserType, IamUser.class.getSimpleName())
|
||||
.eq(IamAccount::getUserId, userAccountDTO.getId())
|
||||
);
|
||||
iamAccount.setAuthAccount(userAccountDTO.getUsername())
|
||||
.setStatus(userAccountDTO.getStatus());
|
||||
// 设置密码
|
||||
if (V.notEmpty(userAccountDTO.getPassword())){
|
||||
iamAccount.setAuthSecret(userAccountDTO.getPassword());
|
||||
IamSecurityUtils.encryptPwd(iamAccount);
|
||||
}
|
||||
boolean accountSuccess = iamAccountService.updateEntity(iamAccount);
|
||||
|
||||
// 批量更新角色关联关系
|
||||
boolean relationsSuccess = iamUserRoleService.updateUserRoleRelations(iamAccount.getUserType(), iamAccount.getUserId(), userAccountDTO.getRoleIdList());
|
||||
|
||||
if (!userSuccess || !accountSuccess || !relationsSuccess){
|
||||
throw new BusinessException(Status.FAIL_OPERATION, "更新用户失败");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteUserAndAccount(Long id) throws Exception {
|
||||
IamUser iamUser = this.getEntity(id);
|
||||
if (iamUser == null){
|
||||
throw new BusinessException(Status.FAIL_OPERATION, "删除的记录不存在");
|
||||
}
|
||||
// 删除用户信息
|
||||
boolean userSuccess = this.deleteEntity(id);
|
||||
private void deleteAccount(Long userId) throws Exception {
|
||||
// 删除账号信息
|
||||
boolean accountSuccess = iamAccountService.deleteEntities(
|
||||
iamAccountService.deleteEntities(
|
||||
Wrappers.<IamAccount>lambdaQuery()
|
||||
.eq(IamAccount::getUserType, IamUser.class.getSimpleName())
|
||||
.eq(IamAccount::getUserId, id)
|
||||
.eq(IamAccount::getUserId, userId)
|
||||
);
|
||||
// 删除用户角色关联关系列表
|
||||
boolean relationsSuccess = iamUserRoleService.deleteEntities(
|
||||
iamUserRoleService.deleteEntities(
|
||||
Wrappers.<IamUserRole>lambdaQuery()
|
||||
.eq(IamUserRole::getUserType, IamUser.class.getSimpleName())
|
||||
.eq(IamUserRole::getUserId, id)
|
||||
.eq(IamUserRole::getUserId, userId)
|
||||
);
|
||||
|
||||
if (!userSuccess || !accountSuccess || !relationsSuccess){
|
||||
throw new BusinessException(Status.FAIL_OPERATION, "删除用户失败");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -147,25 +147,6 @@ public class IamBaseAutoConfig implements WebMvcConfigurer {
|
|||
return shiroFilterFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
|
||||
converter.setDefaultCharset(Charset.forName(Cons.CHARSET_UTF8));
|
||||
List<MediaType> fastMediaTypes = new ArrayList<>();
|
||||
fastMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
converter.setSupportedMediaTypes(fastMediaTypes);
|
||||
// 配置转换格式
|
||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
// 设置fastjson的序列化参数:禁用循环依赖检测,数据兼容浏览器端(避免JS端Long精度丢失问题)
|
||||
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect,
|
||||
SerializerFeature.BrowserCompatible);
|
||||
fastJsonConfig.setDateFormat(D.FORMAT_DATETIME_Y4MDHM);
|
||||
converter.setFastJsonConfig(fastJsonConfig);
|
||||
|
||||
HttpMessageConverter<?> httpMsgConverter = converter;
|
||||
return new HttpMessageConverters(httpMsgConverter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
registry.addConverter(new DateConverter());
|
||||
|
|
Loading…
Reference in New Issue