【7.2.2】【expand】更新列表相关元数据接口

pull/29/head
fengshuonan 2022-04-01 11:27:03 +08:00
parent b4447dd27e
commit 7061b059aa
9 changed files with 182 additions and 10 deletions

View File

@ -25,6 +25,10 @@
package cn.stylefeng.roses.kernel.expand.modular.api;
import cn.stylefeng.roses.kernel.expand.modular.api.pojo.ExpandDataInfo;
import cn.stylefeng.roses.kernel.expand.modular.api.pojo.ExpandFieldInfo;
import java.util.List;
import java.util.Map;
/**
* Api
@ -42,4 +46,20 @@ public interface ExpandApi {
*/
void saveOrUpdateExpandData(ExpandDataInfo expandDataInfo);
/**
*
*
* @author fengshuonan
* @date 2022/4/1 9:48
*/
List<ExpandFieldInfo> getPageListExpandFieldList(String expandCode);
/**
*
*
* @author fengshuonan
* @date 2022/4/1 9:55
*/
Map<String, Object> getExpandDataInfo(String expandCode, Long primaryFieldValue);
}

View File

@ -0,0 +1,35 @@
package cn.stylefeng.roses.kernel.expand.modular.api.enums;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @date 2022/4/1 10:34
*/
@Getter
public enum FieldTypeEnum {
/**
*
*/
STR(1),
/**
*
*/
NUM(2),
/**
*
*/
DICT(3);
private final Integer code;
FieldTypeEnum(Integer code) {
this.code = code;
}
}

View File

@ -0,0 +1,29 @@
package cn.stylefeng.roses.kernel.expand.modular.api.pojo;
import lombok.Data;
/**
*
*
* @author fengshuonan
* @date 2022/4/1 9:46
*/
@Data
public class ExpandFieldInfo {
/**
* id
*/
private Long expandId;
/**
*
*/
private String fieldName;
/**
*
*/
private String fieldCode;
}

View File

@ -47,6 +47,13 @@
<version>${roses.version}</version>
</dependency>
<!--字典api模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>dict-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--数据库sdk-->
<!--数据库dao框架-->
<dependency>

View File

@ -1,6 +1,8 @@
package cn.stylefeng.roses.kernel.expand.modular.modular.controller;
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.api.pojo.ExpandFieldInfo;
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;
@ -31,6 +33,9 @@ public class SysExpandController {
@Resource
private SysExpandService sysExpandService;
@Resource
private ExpandApi expandApi;
/**
*
*
@ -123,4 +128,15 @@ public class SysExpandController {
return new SuccessResponseData<>(sysExpandService.findPage(sysExpandRequest));
}
/**
*
*
* @author fengshuonan
* @date 2022/03/29 23:47
*/
@GetResource(name = "获取某个业务,需要列表展示的拓展字段", path = "/sysExpand/getListFields")
public ResponseData<List<ExpandFieldInfo>> getListFields(@Validated(SysExpandRequest.getByExpandCode.class) SysExpandRequest sysExpandRequest) {
return new SuccessResponseData<>(expandApi.getPageListExpandFieldList(sysExpandRequest.getExpandCode()));
}
}

View File

@ -69,7 +69,7 @@ public class SysExpandRequest extends BaseRequest {
* id
*/
@ChineseDescription("业务主键id的值")
private String primaryFieldValue;
private Long primaryFieldValue;
/**
*

View File

@ -57,7 +57,7 @@ public interface SysExpandDataService extends IService<SysExpandData> {
* @author fengshuonan
* @date 2022/03/29 23:47
*/
SysExpandData detailByPrimaryFieldValue(String primaryFieldValue);
SysExpandData detailByPrimaryFieldValue(Long primaryFieldValue);
/**
*

View File

@ -82,7 +82,7 @@ public class SysExpandDataServiceImpl extends ServiceImpl<SysExpandDataMapper, S
}
@Override
public SysExpandData detailByPrimaryFieldValue(String primaryFieldValue) {
public SysExpandData detailByPrimaryFieldValue(Long primaryFieldValue) {
LambdaQueryWrapper<SysExpandData> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysExpandData::getPrimaryFieldValue, primaryFieldValue);
return this.getOne(wrapper, false);

View File

@ -6,7 +6,10 @@ 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.dict.api.DictApi;
import cn.stylefeng.roses.kernel.expand.modular.api.enums.FieldTypeEnum;
import cn.stylefeng.roses.kernel.expand.modular.api.pojo.ExpandDataInfo;
import cn.stylefeng.roses.kernel.expand.modular.api.pojo.ExpandFieldInfo;
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,14 +21,18 @@ import cn.stylefeng.roses.kernel.expand.modular.modular.service.SysExpandDataSer
import cn.stylefeng.roses.kernel.expand.modular.modular.service.SysExpandFieldService;
import cn.stylefeng.roses.kernel.expand.modular.modular.service.SysExpandService;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -44,6 +51,9 @@ public class SysExpandServiceImpl extends ServiceImpl<SysExpandMapper, SysExpand
@Resource
private SysExpandDataService sysExpandDataService;
@Resource
private DictApi dictApi;
@Override
public void add(SysExpandRequest sysExpandRequest) {
SysExpand sysExpand = new SysExpand();
@ -104,7 +114,7 @@ public class SysExpandServiceImpl extends ServiceImpl<SysExpandMapper, SysExpand
// 如果传了主键id则查询一下业务表单的数据
SysExpandData sysExpandData = new SysExpandData();
if (StrUtil.isNotBlank(sysExpandRequest.getPrimaryFieldValue())) {
if (sysExpandRequest.getPrimaryFieldValue() != null) {
sysExpandData = sysExpandDataService.detailByPrimaryFieldValue(sysExpandRequest.getPrimaryFieldValue());
if (sysExpandData == null) {
sysExpandData = new SysExpandData();
@ -161,6 +171,61 @@ public class SysExpandServiceImpl extends ServiceImpl<SysExpandMapper, SysExpand
}
}
@Override
public List<ExpandFieldInfo> getPageListExpandFieldList(String expandCode) {
SysExpandRequest sysExpandRequest = new SysExpandRequest();
sysExpandRequest.setExpandCode(expandCode);
SysExpandData sysExpandData = this.getByExpandCode(sysExpandRequest);
List<SysExpandField> fieldInfoList = sysExpandData.getFieldInfoList();
ArrayList<ExpandFieldInfo> expandFieldInfos = new ArrayList<>();
for (SysExpandField sysExpandField : fieldInfoList) {
// 获取是否需要列表展示
String listShowFlag = sysExpandField.getListShowFlag();
if (YesOrNotEnum.Y.getCode().equals(listShowFlag)) {
ExpandFieldInfo expandFieldInfo = new ExpandFieldInfo();
expandFieldInfo.setExpandId(sysExpandField.getExpandId());
expandFieldInfo.setFieldName(sysExpandField.getFieldName());
expandFieldInfo.setFieldCode(sysExpandField.getFieldCode());
expandFieldInfos.add(expandFieldInfo);
}
}
return expandFieldInfos;
}
@Override
public Map<String, Object> getExpandDataInfo(String expandCode, Long primaryFieldValue) {
SysExpandRequest sysExpandRequest = new SysExpandRequest();
sysExpandRequest.setExpandCode(expandCode);
SysExpandData sysExpandData = this.getByExpandCode(sysExpandRequest);
// 获取对应数据
HashMap<String, Object> result = new HashMap<>();
String expandData = sysExpandData.getExpandData();
if (StrUtil.isEmpty(expandData)) {
return result;
}
// 将json转化为Map
JSONObject jsonObject = JSON.parseObject(expandData);
// 获取字段元数据,将需要进行字典转化的,转化为字典中文名称
List<SysExpandField> fieldInfoList = sysExpandData.getFieldInfoList();
for (SysExpandField sysExpandField : fieldInfoList) {
if (FieldTypeEnum.DICT.getCode().equals(sysExpandField.getFieldType())) {
String dictTypeCode = sysExpandField.getFieldDictTypeCode();
String dictValue = jsonObject.getString(sysExpandField.getFieldCode());
String dictName = dictApi.getDictName(dictTypeCode, dictValue);
jsonObject.put(sysExpandField.getFieldCode(), dictName);
}
}
return jsonObject;
}
/**
*
*