【8.0.3】【system】新增用户增加调用更新证书信息

pull/60/head
fengshuonan 2023-11-09 23:50:20 +08:00
parent 28c18ee45b
commit 6308ea4136
6 changed files with 44 additions and 153 deletions

View File

@ -17,6 +17,13 @@
<dependencies>
<!-- 多数据源模块,获取数据源上下文 -->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>ds-container-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!-- 事件模块 -->
<dependency>
<groupId>cn.stylefeng.roses</groupId>

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kernel.sys.modular.user.mapper;
import cn.stylefeng.roses.kernel.db.mp.injector.CustomBaseMapper;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserCertificate;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserCertificateRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.response.SysUserCertificateVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
@ -15,7 +15,7 @@ import java.util.List;
* @author fengshuonan
* @since 2023/11/09 22:44
*/
public interface SysUserCertificateMapper extends BaseMapper<SysUserCertificate> {
public interface SysUserCertificateMapper extends CustomBaseMapper<SysUserCertificate> {
/**
*

View File

@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.sys.modular.user.pojo.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserCertificate;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg;
import cn.stylefeng.roses.kernel.validator.api.validators.unique.TableUniqueValue;
import lombok.Data;
@ -159,6 +160,12 @@ public class SysUserRequest extends BaseRequest {
@NotEmpty(message = "用户和组织机构关系集合不能为空", groups = {add.class, edit.class})
private List<SysUserOrg> userOrgList;
/**
*
*/
@ChineseDescription("用户证书信息集合")
private List<SysUserCertificate> userCertificateList;
/**
* id
*/

View File

@ -1,8 +1,6 @@
package cn.stylefeng.roses.kernel.sys.modular.user.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserCertificate;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserCertificateRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -16,68 +14,13 @@ import java.util.List;
public interface SysUserCertificateService extends IService<SysUserCertificate> {
/**
*
*
*
* @param sysUserCertificateRequest
* @param userId id
* @param sysUserCertificateList
* @author fengshuonan
* @since 2023/11/09 22:44
*/
void add(SysUserCertificateRequest sysUserCertificateRequest);
/**
*
*
* @param sysUserCertificateRequest
* @author fengshuonan
* @since 2023/11/09 22:44
*/
void del(SysUserCertificateRequest sysUserCertificateRequest);
/**
*
*
* @param sysUserCertificateRequest
* @author fengshuonan
* @since 2023/11/09 22:44
*/
void batchDelete(SysUserCertificateRequest sysUserCertificateRequest);
/**
*
*
* @param sysUserCertificateRequest
* @author fengshuonan
* @since 2023/11/09 22:44
*/
void edit(SysUserCertificateRequest sysUserCertificateRequest);
/**
*
*
* @param sysUserCertificateRequest
* @author fengshuonan
* @since 2023/11/09 22:44
*/
SysUserCertificate detail(SysUserCertificateRequest sysUserCertificateRequest);
/**
*
*
* @param sysUserCertificateRequest
* @return List<SysUserCertificate>
* @author fengshuonan
* @since 2023/11/09 22:44
*/
List<SysUserCertificate> findList(SysUserCertificateRequest sysUserCertificateRequest);
/**
*
*
* @param sysUserCertificateRequest
* @return PageResult<SysUserCertificate>
* @author fengshuonan
* @since 2023/11/09 22:44
*/
PageResult<SysUserCertificate> findPage(SysUserCertificateRequest sysUserCertificateRequest);
void updateUserCertificate(Long userId, List<SysUserCertificate> sysUserCertificateList);
}

View File

@ -1,18 +1,12 @@
package cn.stylefeng.roses.kernel.sys.modular.user.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.dsctn.api.context.DataSourceContext;
import cn.stylefeng.roses.kernel.rule.enums.DbTypeEnum;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserCertificate;
import cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserCertificateExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.user.mapper.SysUserCertificateMapper;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserCertificateRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserCertificateService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -26,94 +20,27 @@ import java.util.List;
* @since 2023/11/09 22:44
*/
@Service
public class SysUserCertificateServiceImpl extends ServiceImpl<SysUserCertificateMapper, SysUserCertificate> implements SysUserCertificateService {
@Override
public void add(SysUserCertificateRequest sysUserCertificateRequest) {
SysUserCertificate sysUserCertificate = new SysUserCertificate();
BeanUtil.copyProperties(sysUserCertificateRequest, sysUserCertificate);
this.save(sysUserCertificate);
}
@Override
public void del(SysUserCertificateRequest sysUserCertificateRequest) {
SysUserCertificate sysUserCertificate = this.querySysUserCertificate(sysUserCertificateRequest);
this.removeById(sysUserCertificate.getUserCertificateId());
}
public class SysUserCertificateServiceImpl extends ServiceImpl<SysUserCertificateMapper, SysUserCertificate> implements
SysUserCertificateService {
@Override
@Transactional(rollbackFor = Exception.class)
public void batchDelete(SysUserCertificateRequest sysUserCertificateRequest) {
this.removeByIds(sysUserCertificateRequest.getBatchDeleteIdList());
}
@Override
public void edit(SysUserCertificateRequest sysUserCertificateRequest) {
SysUserCertificate sysUserCertificate = this.querySysUserCertificate(sysUserCertificateRequest);
BeanUtil.copyProperties(sysUserCertificateRequest, sysUserCertificate);
this.updateById(sysUserCertificate);
}
@Override
public SysUserCertificate detail(SysUserCertificateRequest sysUserCertificateRequest) {
return this.querySysUserCertificate(sysUserCertificateRequest);
}
@Override
public PageResult<SysUserCertificate> findPage(SysUserCertificateRequest sysUserCertificateRequest) {
LambdaQueryWrapper<SysUserCertificate> wrapper = createWrapper(sysUserCertificateRequest);
Page<SysUserCertificate> pageList = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(pageList);
}
@Override
public List<SysUserCertificate> findList(SysUserCertificateRequest sysUserCertificateRequest) {
LambdaQueryWrapper<SysUserCertificate> wrapper = this.createWrapper(sysUserCertificateRequest);
return this.list(wrapper);
}
/**
*
*
* @author fengshuonan
* @since 2023/11/09 22:44
*/
private SysUserCertificate querySysUserCertificate(SysUserCertificateRequest sysUserCertificateRequest) {
SysUserCertificate sysUserCertificate = this.getById(sysUserCertificateRequest.getUserCertificateId());
if (ObjectUtil.isEmpty(sysUserCertificate)) {
throw new ServiceException(SysUserCertificateExceptionEnum.SYS_USER_CERTIFICATE_NOT_EXISTED);
public void updateUserCertificate(Long userId, List<SysUserCertificate> sysUserCertificateList) {
if (ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(sysUserCertificateList)) {
return;
}
return sysUserCertificate;
}
/**
* wrapper
*
* @author fengshuonan
* @since 2023/11/09 22:44
*/
private LambdaQueryWrapper<SysUserCertificate> createWrapper(SysUserCertificateRequest sysUserCertificateRequest) {
LambdaQueryWrapper<SysUserCertificate> queryWrapper = new LambdaQueryWrapper<>();
// 先清空当前绑定的证书信息
LambdaQueryWrapper<SysUserCertificate> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(SysUserCertificate::getUserId, userId);
this.remove(deleteWrapper);
Long userCertificateId = sysUserCertificateRequest.getUserCertificateId();
Long userId = sysUserCertificateRequest.getUserId();
Long certificateType = sysUserCertificateRequest.getCertificateType();
String certificateNo = sysUserCertificateRequest.getCertificateNo();
String issuingAuthority = sysUserCertificateRequest.getIssuingAuthority();
String dateIssued = sysUserCertificateRequest.getDateIssued();
String dateExpires = sysUserCertificateRequest.getDateExpires();
String delFlag = sysUserCertificateRequest.getDelFlag();
queryWrapper.eq(ObjectUtil.isNotNull(userCertificateId), SysUserCertificate::getUserCertificateId, userCertificateId);
queryWrapper.eq(ObjectUtil.isNotNull(userId), SysUserCertificate::getUserId, userId);
queryWrapper.eq(ObjectUtil.isNotNull(certificateType), SysUserCertificate::getCertificateType, certificateType);
queryWrapper.like(ObjectUtil.isNotEmpty(certificateNo), SysUserCertificate::getCertificateNo, certificateNo);
queryWrapper.like(ObjectUtil.isNotEmpty(issuingAuthority), SysUserCertificate::getIssuingAuthority, issuingAuthority);
queryWrapper.eq(ObjectUtil.isNotNull(dateIssued), SysUserCertificate::getDateIssued, dateIssued);
queryWrapper.eq(ObjectUtil.isNotNull(dateExpires), SysUserCertificate::getDateExpires, dateExpires);
queryWrapper.like(ObjectUtil.isNotEmpty(delFlag), SysUserCertificate::getDelFlag, delFlag);
return queryWrapper;
// 重新绑定用户证书信息
if (DbTypeEnum.MYSQL.equals(DataSourceContext.me().getCurrentDbType())) {
this.getBaseMapper().insertBatchSomeColumn(sysUserCertificateList);
} else {
this.saveBatch(sysUserCertificateList);
}
}
}

View File

@ -35,6 +35,7 @@ import cn.stylefeng.roses.kernel.sys.modular.user.factory.SysUserCreateFactory;
import cn.stylefeng.roses.kernel.sys.modular.user.mapper.SysUserMapper;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.response.PersonalInfo;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserCertificateService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserService;
@ -79,6 +80,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Resource
private SecurityConfigService securityConfigService;
@Resource
private SysUserCertificateService sysUserCertificateService;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(SysUserRequest sysUserRequest) {
@ -109,6 +113,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 添加用户一个默认角色
sysUserRoleService.bindUserDefaultRole(sysUser.getUserId());
// 增加用户证书的信息
sysUserCertificateService.updateUserCertificate(sysUser.getUserId(), sysUserRequest.getUserCertificateList());
// 记录日志
BusinessLogUtil.setLogTitle("新增用户,用户账号:" + sysUser.getAccount());
BusinessLogUtil.addContent("新增用户账号信息:", sysUser.getAccount());