【7.2.2】【expand】处理用户详情数据的动态表单

pull/29/head
fengshuonan 2022-03-31 21:53:44 +08:00
parent 4a0022f1c0
commit b4447dd27e
7 changed files with 111 additions and 3 deletions

View File

@ -24,6 +24,8 @@
*/
package cn.stylefeng.roses.kernel.expand.modular.api;
import cn.stylefeng.roses.kernel.expand.modular.api.pojo.ExpandDataInfo;
/**
* Api
*
@ -32,5 +34,12 @@ package cn.stylefeng.roses.kernel.expand.modular.api;
*/
public interface ExpandApi {
/**
*
*
* @author fengshuonan
* @date 2022/3/31 21:20
*/
void saveOrUpdateExpandData(ExpandDataInfo expandDataInfo);
}

View File

@ -0,0 +1,31 @@
package cn.stylefeng.roses.kernel.expand.modular.api.pojo;
import lombok.Data;
import java.util.Map;
/**
*
*
* @author fengshuonan
* @date 2022/3/31 21:25
*/
@Data
public class ExpandDataInfo {
/**
* id
*/
private Long expandId;
/**
*
*/
private Map<String, Object> expandData;
/**
*
*/
private Long primaryFieldValue;
}

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.expand.modular.modular.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.expand.modular.api.ExpandApi;
import cn.stylefeng.roses.kernel.expand.modular.modular.entity.SysExpand;
import cn.stylefeng.roses.kernel.expand.modular.modular.entity.SysExpandData;
import cn.stylefeng.roses.kernel.expand.modular.modular.pojo.request.SysExpandRequest;
@ -14,7 +15,7 @@ import java.util.List;
* @author fengshuonan
* @date 2022/03/29 23:47
*/
public interface SysExpandService extends IService<SysExpand> {
public interface SysExpandService extends IService<SysExpand>, ExpandApi {
/**
*

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
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.expand.modular.api.pojo.ExpandDataInfo;
import cn.stylefeng.roses.kernel.expand.modular.modular.entity.SysExpand;
import cn.stylefeng.roses.kernel.expand.modular.modular.entity.SysExpandData;
import cn.stylefeng.roses.kernel.expand.modular.modular.entity.SysExpandField;
@ -18,6 +19,7 @@ import cn.stylefeng.roses.kernel.expand.modular.modular.service.SysExpandFieldSe
import cn.stylefeng.roses.kernel.expand.modular.modular.service.SysExpandService;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -25,6 +27,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
*
@ -109,6 +112,7 @@ public class SysExpandServiceImpl extends ServiceImpl<SysExpandMapper, SysExpand
}
// 设置返回信息
sysExpandData.setExpandId(sysExpand.getExpandId());
sysExpandData.setFieldInfoList(list);
sysExpandData.setExpandInfo(sysExpand);
@ -123,6 +127,40 @@ public class SysExpandServiceImpl extends ServiceImpl<SysExpandMapper, SysExpand
return this.list(wrapper);
}
@Override
public void saveOrUpdateExpandData(ExpandDataInfo expandDataInfo) {
if (expandDataInfo == null) {
return;
}
Map<String, Object> dynamicFormData = expandDataInfo.getExpandData();
if (dynamicFormData == null || dynamicFormData.size() <= 0) {
return;
}
// 具体数据转化为json
String dynamicData = JSON.toJSONString(dynamicFormData);
SysExpandData saveData = new SysExpandData();
saveData.setExpandId(expandDataInfo.getExpandId());
saveData.setPrimaryFieldValue(expandDataInfo.getPrimaryFieldValue());
saveData.setExpandData(dynamicData);
// 查询数据有没有在库中存在
LambdaQueryWrapper<SysExpandData> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysExpandData::getExpandId, expandDataInfo.getExpandId());
wrapper.eq(SysExpandData::getPrimaryFieldValue, expandDataInfo.getPrimaryFieldValue());
SysExpandData sysExpandData = this.sysExpandDataService.getOne(wrapper, false);
// 数据库中不存在,则保存
if (sysExpandData == null) {
this.sysExpandDataService.save(saveData);
} else {
saveData.setExpandDataId(sysExpandData.getExpandDataId());
this.sysExpandDataService.updateById(saveData);
}
}
/**
*
*
@ -156,5 +194,4 @@ public class SysExpandServiceImpl extends ServiceImpl<SysExpandMapper, SysExpand
return queryWrapper;
}
}

View File

@ -17,6 +17,13 @@
<dependencies>
<!--数据拓展的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>expand-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--参数校验模块的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>

View File

@ -24,6 +24,7 @@
*/
package cn.stylefeng.roses.kernel.system.api.pojo.user.request;
import cn.stylefeng.roses.kernel.expand.modular.api.pojo.ExpandDataInfo;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.validator.api.validators.date.DateValue;
@ -192,6 +193,12 @@ public class SysUserRequest extends BaseRequest {
@ChineseDescription("用户id的数据范围集合")
private Set<Long> userScopeIds;
/**
*
*/
@ChineseDescription("动态表单数据")
private ExpandDataInfo expandDataInfo;
/**
*
*/

View File

@ -41,6 +41,7 @@ import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
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.expand.modular.api.ExpandApi;
import cn.stylefeng.roses.kernel.file.api.FileInfoApi;
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
import cn.stylefeng.roses.kernel.jwt.api.context.JwtContext;
@ -145,6 +146,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Resource
private PositionServiceApi positionServiceApi;
@Resource
private ExpandApi expandApi;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(SysUserRequest sysUserRequest) {
@ -172,6 +176,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} else {
sysUserOrgService.add(sysUser.getUserId(), sysUserRequest.getOrgId(), sysUserRequest.getPositionId());
}
// 处理动态表单数据
if (sysUserRequest.getExpandDataInfo() != null) {
sysUserRequest.getExpandDataInfo().setPrimaryFieldValue(sysUser.getUserId());
expandApi.saveOrUpdateExpandData(sysUserRequest.getExpandDataInfo());
}
}
@Override
@ -239,6 +249,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 清除缓存中的用户信息
sysUserCacheOperatorApi.remove(String.valueOf(sysUserId));
// 处理动态表单数据
if (sysUserRequest.getExpandDataInfo() != null) {
sysUserRequest.getExpandDataInfo().setPrimaryFieldValue(sysUser.getUserId());
expandApi.saveOrUpdateExpandData(sysUserRequest.getExpandDataInfo());
}
}
@Override