All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.mingsoft.mdiy.biz.impl.ConfigBizImpl Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2012-present 铭软科技(mingsoft.net)
 * 本软件及相关文档文件(以下简称“软件”)的版权归 铭软科技 所有
 * 遵循 铭软科技《服务协议》中的《保密条款》
 */




package net.mingsoft.mdiy.biz.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.mdiy.bean.ModelJsonBean;
import net.mingsoft.mdiy.biz.IConfigBiz;
import net.mingsoft.mdiy.biz.IModelBiz;
import net.mingsoft.mdiy.dao.IConfigDao;
import net.mingsoft.mdiy.entity.ConfigEntity;
import net.mingsoft.mdiy.entity.ModelEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 自定义配置管理持久化层
 * @author SMILE
 * 创建日期:2021-3-25 11:42:09
* 历史修订:
*/ @Service("mdiyConfigBizImpl") public class ConfigBizImpl extends BaseBizImpl implements IConfigBiz { @Autowired private IConfigDao configDao; @Autowired private IModelBiz modelBiz; @Override protected IBaseDao getDao() { return configDao; } @Override public boolean importConfig(String customType, ModelJsonBean modelJsonBean) { if (StringUtils.isBlank(modelJsonBean.getTitle())){ return false; } // 判断导入的模型业务类型一致的情况下,判断模型名 或 表名是否存在 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(ModelEntity::getModelName, modelJsonBean.getTitle()) .eq(ModelEntity::getModelCustomType, customType); List modelEntities = modelBiz.list(queryWrapper); //判断表名是否存在 if (CollectionUtil.isNotEmpty(modelEntities)) { return false; } ModelEntity model = new ModelEntity(); model.setModelName(modelJsonBean.getTitle()); model.setModelCustomType(customType); model.setModelIdType(modelJsonBean.getId()); Map json = new HashMap(); json.put("html", modelJsonBean.getHtml()); json.put("searchJson", modelJsonBean.getSearchJson()); json.put("script", modelJsonBean.getScript()); json.put("isWebSubmit", modelJsonBean.isWebSubmit()); json.put("isWebCode", modelJsonBean.isWebCode()); json.put("id", modelJsonBean.getId()); //因为ModelAop会进行站群插件id拼接,保存模型的时候需要还原最原始的表名称,方便复制JSON模型使用 if (BasicUtil.getWebsiteApp() != null) { json.put("sql", modelJsonBean.getSql().replace("_" + BasicUtil.getWebsiteApp().getId(), "")); json.put("tableName", modelJsonBean.getTableName().replace("_" + BasicUtil.getWebsiteApp().getId(), "")); } else { json.put("tableName", modelJsonBean.getTableName()); json.put("sql", modelJsonBean.getSql()); } json.put("form", modelJsonBean.getForm()); model.setModelField(modelJsonBean.getField()); model.setModelType(""); model.setModelJson(JSONUtil.toJsonStr(json)); model.setCreateDate(new Date()); //保存自定义模型实体 modelBiz.save(model); //保存自定义配置 ConfigEntity configEntity = new ConfigEntity(); configEntity.setConfigName(modelJsonBean.getTitle()); // 设置模型类型,防止与全局自定义重复 configEntity.setConfigType(customType); configEntity.setModelId(model.getId()); this.save(configEntity); return true; } @Override public boolean updateConfig(String modelId, ModelJsonBean modelJsonBean) { if (StringUtils.isEmpty(modelId) || modelJsonBean == null) { return false; } ModelEntity modelEntity = modelBiz.getById(modelId); if (ObjectUtil.isNull(modelEntity)) { return false; } //模型名称必须唯一,需要进行查询判断 ModelEntity model = new ModelEntity(); model.setModelName(modelJsonBean.getTitle()); model.setModelCustomType(modelEntity.getModelCustomType()); ModelEntity oldModel = modelBiz.getOne(new QueryWrapper<>(model)); //判断表名是否存在 if (ObjectUtil.isNotNull(oldModel) && !modelEntity.getId().equals(oldModel.getId())) { return false; } // 更新模型字段field modelBiz.updateModelField(modelJsonBean, modelEntity, ""); // 更新自定义配置 List mapList = JSONUtil.toList(JSONUtil.parseArray(modelJsonBean.getField()), Map.class); List fieldList = mapList.stream().map(map -> StrUtil.toCamelCase(map.get("field").toString().toLowerCase())).collect(Collectors.toList()); fieldList.add("linkId"); fieldList.add("modelId"); ConfigEntity configEntity = getOne(new QueryWrapper().eq("model_id", modelId)); Map map = JSONUtil.toBean(configEntity.getConfigData(), Map.class); if (CollUtil.isNotEmpty(map)) { Object[] keys = map.keySet().toArray(); for (Object key : keys) { if (!fieldList.contains(key)) { map.remove(key); } } configEntity.setConfigName(modelJsonBean.getTitle()); configEntity.setConfigData(JSONUtil.toJsonStr(map)); updateById(configEntity); } return true; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy