修改formcreate
This commit is contained in:
parent
733e0c1558
commit
0644e06e8e
@ -20,6 +20,6 @@ import java.util.Map;
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreDatasetTableMapper extends BaseMapper<CoreDatasetTable> {
|
||||
@Select("select b.name group_name,a.table_name table_name,a.id table_id from core_dataset_table a join core_dataset_group b on (a.dataset_group_id=b.id) where b.app_id=#{appid} and a.type='db' order by a.name")
|
||||
@Select("select b.name group_name,a.table_name table_name,a.id table_id,a.datasource_id datasource_id from core_dataset_table a join core_dataset_group b on (a.dataset_group_id=b.id) where b.app_id=#{appid} and a.type='db' order by a.name")
|
||||
List<Map<String,Object>> getTablesByAppId(String appid);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import io.gisbi.extensions.view.dto.ColumnPermissionItem;
|
||||
import io.gisbi.extensions.view.dto.SqlVariableDetails;
|
||||
import io.gisbi.i18n.Translator;
|
||||
import io.gisbi.utils.BeanUtils;
|
||||
import io.gisbi.utils.IDUtils;
|
||||
import io.gisbi.utils.JsonUtil;
|
||||
import io.gisbi.utils.TreeUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -1188,7 +1189,10 @@ public class DatasetDataManage {
|
||||
Map<String, Object> field = fieldList.get(i);
|
||||
String fieldName = (String) field.get("fieldName");
|
||||
Object fieldValue = field.get("fieldValue");
|
||||
|
||||
boolean isPrimaryKey = field.get("IsPrimaryKey") != null && (boolean) field.get("IsPrimaryKey");
|
||||
if (isPrimaryKey) {
|
||||
if (fieldValue == null) {fieldValue= IDUtils.snowID();}
|
||||
}
|
||||
if (i > 0) {
|
||||
columns.append(", ");
|
||||
values.append(", ");
|
||||
@ -1223,6 +1227,68 @@ public class DatasetDataManage {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Map<String, Object> getTableDataByPk(Long datasourceId, String tableData) throws Exception {
|
||||
// 获取数据源信息
|
||||
CoreDatasource coreDatasource = coreDatasourceMapper.selectById(datasourceId);
|
||||
if (coreDatasource == null) {
|
||||
DEException.throwException("数据源不存在");
|
||||
}
|
||||
|
||||
// 解析 JSON 数据
|
||||
Map<String, Object> dataMap = JsonUtil.parseObject(tableData, Map.class);
|
||||
String tableName = (String) dataMap.get("tableName");
|
||||
String primaryKeyField = (String) dataMap.get("primaryKeyField");
|
||||
Object primaryKeyValue = dataMap.get("primaryKeyValue");
|
||||
|
||||
// 参数校验
|
||||
if (StringUtils.isBlank(tableName)) {
|
||||
DEException.throwException("表名不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(primaryKeyField) || primaryKeyValue == null) {
|
||||
DEException.throwException("主键字段或值不能为空");
|
||||
}
|
||||
|
||||
// 构建 SELECT 语句
|
||||
String whereClause;
|
||||
if (primaryKeyValue instanceof String) {
|
||||
whereClause = String.format("%s = '%s'", primaryKeyField, primaryKeyValue);
|
||||
} else {
|
||||
whereClause = String.format("%s = %s", primaryKeyField, primaryKeyValue);
|
||||
}
|
||||
String sql = String.format("SELECT * FROM %s WHERE %s", tableName, whereClause);
|
||||
|
||||
// 执行查询操作
|
||||
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
|
||||
BeanUtils.copyBean(datasourceSchemaDTO, coreDatasource);
|
||||
|
||||
Provider provider = ProviderFactory.getProvider(coreDatasource.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setQuery(sql);
|
||||
datasourceRequest.setDsList(Map.of(datasourceSchemaDTO.getId(), datasourceSchemaDTO));
|
||||
|
||||
logger.debug("执行查询数据的SQL: {}", sql);
|
||||
|
||||
// 获取查询结果
|
||||
Map<String, Object> data = provider.fetchResultField(datasourceRequest);
|
||||
|
||||
// 处理查询结果
|
||||
List<String[]> dataList = (List<String[]>) data.get("data");
|
||||
List<TableField> fields = (List<TableField>) data.get("fields");
|
||||
|
||||
if (CollectionUtils.isEmpty(dataList) || dataList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 将结果转换为 Map 格式
|
||||
String[] row = dataList.get(0);
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
TableField field = fields.get(i);
|
||||
String fieldName = field.getOriginName();
|
||||
resultMap.put(fieldName, row[i]);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
public boolean updateTableData(Long datasourceId, String tableData) throws Exception {
|
||||
// 获取数据源信息
|
||||
|
@ -104,6 +104,12 @@ public class DatasetDataServer implements DatasetDataApi {
|
||||
}
|
||||
}
|
||||
|
||||
// @GetMapping("getTablesByAppId")
|
||||
// public List<Map<String,Object>> getTablesByAppId(String appid) throws Exception {
|
||||
// List<Map<String,Object>> result = datasetDataManage.getTablesByAppId(appid);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
@GetMapping("getTablesByAppId")
|
||||
public List<Map<String,Object>> getTablesByAppId(String appid) throws Exception {
|
||||
List<Map<String,Object>> result = datasetDataManage.getTablesByAppId(appid);
|
||||
@ -115,15 +121,24 @@ public class DatasetDataServer implements DatasetDataApi {
|
||||
return result;
|
||||
}
|
||||
@PostMapping("addTableData")
|
||||
public boolean addTableData(Long datasourceId, @RequestBody String tableData) throws Exception {
|
||||
public boolean addTableData(Long datasourceId, @RequestParam("tableData") String tableData) throws Exception {
|
||||
boolean result = datasetDataManage.addTableData(
|
||||
datasourceId,
|
||||
tableData
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("getTableDataByPk")
|
||||
public Map<String, Object> getTableDataByPk(Long datasourceId,@RequestParam("whereJson") String whereJson) throws Exception {
|
||||
Map<String, Object> result=datasetDataManage.getTableDataByPk(
|
||||
datasourceId,
|
||||
whereJson
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@PostMapping("updateTableData")
|
||||
public boolean updateTableData(Long datasourceId, @RequestBody String tableData) throws Exception {
|
||||
public boolean updateTableData(Long datasourceId, @RequestParam("tableData") String tableData) throws Exception {
|
||||
boolean result = datasetDataManage.updateTableData(
|
||||
datasourceId,
|
||||
tableData
|
||||
@ -131,7 +146,7 @@ public class DatasetDataServer implements DatasetDataApi {
|
||||
return result;
|
||||
}
|
||||
@PostMapping("deleteTableData")
|
||||
public boolean deleteTableData(Long datasourceId, @RequestBody String whereJson) throws Exception {
|
||||
public boolean deleteTableData(Long datasourceId, @RequestParam("whereJson") String whereJson) throws Exception {
|
||||
boolean result = datasetDataManage.deleteTableData(
|
||||
datasourceId,
|
||||
whereJson
|
||||
@ -139,7 +154,7 @@ public class DatasetDataServer implements DatasetDataApi {
|
||||
return result;
|
||||
}
|
||||
@PostMapping("queryTableDataPaged")
|
||||
public Page<Map<String, Object>> queryTableDataPaged(Long datasourceId, @RequestBody String queryJson) throws Exception {
|
||||
public Page<Map<String, Object>> queryTableDataPaged(Long datasourceId, @RequestParam("queryJson") String queryJson) throws Exception {
|
||||
Page<Map<String, Object>> result = datasetDataManage.queryTableDataPaged(
|
||||
datasourceId,
|
||||
queryJson
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -17,6 +17,7 @@ import formCreate from "@form-create/element-ui";
|
||||
import { useRoute } from 'vue-router'
|
||||
import { moduleById,moduleUpdate } from '@/api/application/module'
|
||||
const route = useRoute()
|
||||
const designerForm = formCreate.factory();
|
||||
const appId:any = ref(route.query.appId)
|
||||
if(route.query.appId == null){
|
||||
appId.value = '00'
|
||||
@ -26,14 +27,12 @@ const field:any = [{}]
|
||||
const config:any = {
|
||||
fieldReadonly: false,
|
||||
showSaveBtn: true,
|
||||
// varList: [],
|
||||
// fieldList: []
|
||||
}
|
||||
}
|
||||
const exportData = () => {
|
||||
if (!designerRef.value) return;
|
||||
// 获取规则和配置
|
||||
const rules = JSON.stringify(designerRef.value.getRule()) ;
|
||||
const options = JSON.stringify(designerRef.value.getOption());
|
||||
const rules = designerForm.toJson(designerRef.value.getRule()) ;
|
||||
const options = designerForm.toJson(designerRef.value.getOption());
|
||||
let data = {
|
||||
id:route.query.moduleId,
|
||||
canvasStyleData:rules,
|
||||
@ -51,6 +50,8 @@ const exportData = () => {
|
||||
})
|
||||
};
|
||||
onMounted(() => {
|
||||
// designerRef.value.setOption(formCreate.parseJson('{"form":{"inline":false,"hideRequiredAsterisk":false,"labelPosition":"right","size":"default","labelWidth":"125px"},"resetBtn":{"show":false,"innerText":"重置"},"submitBtn":{"show":true,"innerText":"提交"}}'));
|
||||
// designerRef.value.setRule(formCreate.parseJson('[{"type":"fcInlineForm","_fc_id":"id_Fjdrm1vqsjnub0c","name":"ref_F1mkm1vqsjnub1c","_fc_drag_tag":"fcInlineForm","children":[{"type":"input","field":"Fwqlm1vqu2c1b2c","title":"关键字","$required":false,"_fc_id":"id_F6omm1vqu2c1b3c","name":"ref_F8l5m1vqu2c1b4c","_fc_drag_tag":"input","wrap":{"labelWidth":"5em"},"style":{"width":"180px"},"display":true,"hidden":false},{"type":"select","field":"Fkh7m1vqzakub7c","title":"商品分类","effect":{"fetch":""},"$required":false,"options":[{"label":"熊熊百货","value":"6"},{"label":"时尚优品","value":"3"}],"_fc_id":"id_Ffb3m1vqzakub8c","name":"ref_Floem1vqzakub9c","_fc_drag_tag":"select","wrap":{"labelWidth":"6em"},"style":{"width":"180px"},"display":true,"hidden":false},{"type":"elButton","children":["搜索"],"_fc_id":"id_Fgecm1vquanjb5c","name":"ref_Fdshm1vquanjb6c","_fc_drag_tag":"elButton","style":{"marginLeft":"15px"},"display":true,"hidden":false,"on":{"click":"$FNX:$inject.api.getRule(\'ref_Fd9xlxvrabk0jmc\').props.fetch.action = `https://mer.crmeb.net/api/product/spu/lst?keywrod=${$inject.api.form.Fwqlm1vqu2c1b2c || \'\'}&mer_id=${$inject.api.form.Fkh7m1vqzakub7c || \'\'}`;\\n\\n$inject.api.el(\'ref_Fd9xlxvrabk0jmc\').initPage();"}}],"style":{"display":"flex","flexDirection":"row","alignItems":"flex-start"},"display":true,"hidden":false},{"type":"dataTable","native":true,"props":{"height":"500px","button":{"open":true,"column":[{"key":1,"name":"详情","prop":["link"],"type":"primary","size":"small","click":"[[FORM-CREATE-PREFIX-function click(scope, api){api.open(\'ref_Fraim1unt0jhisc\', scope.row);}-FORM-CREATE-SUFFIX]]"},{"key":2,"name":"删除","prop":["link"],"type":"primary","handle":"[[FORM-CREATE-PREFIX-function render(props, scope){return scope.row.spu_id % 2 === 1;}-FORM-CREATE-SUFFIX]]","size":"small"}],"width":"100px"},"column":[{"format":"default","prop":"spu_id","label":"ID","width":"150"},{"format":"default","prop":"store_name","label":"商品名称","width":""},{"format":"default","prop":"stock","label":"库存","width":"100"},{"format":"tag","prop":"unit_name","label":"单位","width":"100"},{"format":"image","prop":"image","label":"主图","width":"200"}],"page":{"totalField":"count","dataField":"list","orderField":"order","orderByField":"orderBy","pageField":"page","pageSizeField":"limit","open":true,"props":{"pageSize":10,"small":true,"background":true}},"_optionType":2,"fetch":{"action":"https://mer.crmeb.net/api/product/spu/lst","method":"GET","headers":{},"data":{},"parse":"[[FORM-CREATE-PREFIX-function parse(res){return res.data;}-FORM-CREATE-SUFFIX]]","onError":"","to":"options"},"rowKey":"spu_id"},"_fc_id":"id_Fe33lxvrabk0jlc","name":"ref_Fd9xlxvrabk0jmc","_fc_drag_tag":"dataTable","display":true,"hidden":false},{"type":"fcDialog","props":{"title":"弹出框","rule":[{"type":"input","field":"store_name","title":"商品名称","$required":false,"_fc_id":"id_F22lm1unts3aiuc","name":"ref_Ft1nm1unts3aivc","_fc_drag_tag":"input","display":true,"hidden":false},{"type":"inputNumber","field":"stock","title":"库存","$required":false,"_fc_id":"id_Fmzhm1ununlrixc","name":"ref_Fhj5m1ununlriyc","_fc_drag_tag":"inputNumber","display":true,"hidden":false},{"type":"input","field":"unit_name","title":"单位","$required":false,"_fc_id":"id_Fzp1m1unv5trj0c","name":"ref_Fxc0m1unv5trj1c","_fc_drag_tag":"input","display":true,"hidden":false}]},"_fc_id":"id_Ft1em1unt0jhirc","name":"ref_Fraim1unt0jhisc","_fc_drag_tag":"fcDialog","native":true,"ignore":true,"field":"Fwxrmb0h4qovafc","display":true,"hidden":false}]'));
|
||||
|
||||
if(route.query.moduleId == null){
|
||||
return
|
||||
@ -59,13 +60,17 @@ onMounted(() => {
|
||||
route.query.moduleId
|
||||
moduleById(route.query.moduleId).then(res => {
|
||||
if(res.code ==0){
|
||||
|
||||
if(res.data.data.canvas_style_data != null && res.data.data.canvas_style_data != ""){
|
||||
|
||||
|
||||
designerRef.value.setOption(formCreate.parseJson(res.data.data.component_data))
|
||||
designerRef.value.setRule( formCreate.parseJson(res.data.data.canvas_style_data))
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
Loading…
Reference in New Issue
Block a user