package com.hzya.frame.mdm.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzya.frame.base.PluginBaseEntity;
import com.hzya.frame.mdm.entity.DbFiledsDto;
import com.hzya.frame.mdm.entity.MdmDataDto;
import com.hzya.frame.mdm.entity.MdmDataFiledDto;
import com.hzya.frame.mdm.entity.MdmDbFiledVo;
import com.hzya.frame.mdm.entity.MdmDbVo;
import com.hzya.frame.mdm.entity.MdmDetailViewVo;
import com.hzya.frame.mdm.entity.MdmDistributeDto;
import com.hzya.frame.mdm.entity.MdmDistributeEntity;
import com.hzya.frame.mdm.entity.MdmDistributeVo;
import com.hzya.frame.mdm.entity.MdmDto;
import com.hzya.frame.mdm.entity.MdmModuleViewDto;
import com.hzya.frame.mdm.entity.MdmModuleViewVo;
import com.hzya.frame.mdm.entity.MdmQuery;
import com.hzya.frame.mdm.entity.MdmRoleDto;
import com.hzya.frame.mdm.entity.MdmViewButtonVo;
import com.hzya.frame.mdm.entity.MdmViewFiledVo;
import com.hzya.frame.mdm.entity.MdmViewVo;
import com.hzya.frame.mdm.entity.MdmVo;
import com.hzya.frame.mdm.mdmModule.dao.IMdmModuleDao;
import com.hzya.frame.mdm.mdmModule.entity.MdmModuleEntity;
import com.hzya.frame.mdm.mdmModuleDb.dao.IMdmModuleDbDao;
import com.hzya.frame.mdm.mdmModuleDb.entity.MdmModuleDbEntity;
import com.hzya.frame.mdm.mdmModuleDbFileds.dao.IMdmModuleDbFiledsDao;
import com.hzya.frame.mdm.mdmModuleDbFileds.entity.MdmModuleDbFiledsEntity;
import com.hzya.frame.mdm.mdmModuleDbFiledsRule.dao.IMdmModuleDbFiledsRuleDao;
import com.hzya.frame.mdm.mdmModuleDbFiledsRule.entity.MdmModuleDbFiledsRuleEntity;
import com.hzya.frame.mdm.mdmModuleDbFiledsRuleFiles.dao.IMdmModuleDbFiledsRuleFilesDao;
import com.hzya.frame.mdm.mdmModuleDbFiledsRuleFiles.entity.MdmModuleDbFiledsRuleFilesEntity;
import com.hzya.frame.mdm.mdmModuleDistribute.dao.IMdmModuleDistributeDao;
import com.hzya.frame.mdm.mdmModuleDistribute.entity.MdmModuleDistributeEntity;
import com.hzya.frame.mdm.mdmModuleDistributeDetail.dao.IMdmModuleDistributeDetailDao;
import com.hzya.frame.mdm.mdmModuleDistributeDetail.entity.MdmModuleDistributeDetailEntity;
import com.hzya.frame.mdm.mdmModuleRole.dao.IMdmModuleRoleDao;
import com.hzya.frame.mdm.mdmModuleRole.entity.MdmModuleRoleEntity;
import com.hzya.frame.mdm.mdmModuleRoleButton.dao.IMdmModuleRoleButtonDao;
import com.hzya.frame.mdm.mdmModuleRoleButton.entity.MdmModuleRoleButtonEntity;
import com.hzya.frame.mdm.mdmModuleUserView.dao.IMdmModuleUserViewDao;
import com.hzya.frame.mdm.mdmModuleUserView.entity.MdmModuleUserViewEntity;
import com.hzya.frame.mdm.mdmModuleView.dao.IMdmModuleViewDao;
import com.hzya.frame.mdm.mdmModuleView.entity.MdmModuleViewEntity;
import com.hzya.frame.mdm.mdmModuleViewDetail.dao.IMdmModuleViewDetailDao;
import com.hzya.frame.mdm.mdmModuleViewDetail.entity.MdmModuleViewDetailEntity;
import com.hzya.frame.mdm.mdmTableCodeRule.dao.IMdmTableCodeRuleDao;
import com.hzya.frame.mdm.mdmTableCodeRule.entity.MdmTableCodeRuleEntity;
import com.hzya.frame.mdm.service.IMdmService;
import com.hzya.frame.sys.entity.FormmainDeleteDto;
import com.hzya.frame.sys.entity.ModuleDto;
import com.hzya.frame.sys.module.dao.IModuleMapper;
import com.hzya.frame.sys.module.entity.Module;
import com.hzya.frame.sys.roleModule.dao.IRoleModuleMapper;
import com.hzya.frame.sys.roleModule.entity.RoleModule;
import com.hzya.frame.sys.userRole.dao.IUserRoleMapper;
import com.hzya.frame.sys.userRole.entity.UserRole;
import com.hzya.frame.sysnew.application.plugin.dao.ISysApplicationPluginDao;
import com.hzya.frame.sysnew.application.plugin.entity.SysApplicationPluginEntity;
import com.hzya.frame.sysnew.buttonConfig.dao.ISysButtonConfigDao;
import com.hzya.frame.sysnew.buttonConfig.entity.SysButtonConfigEntity;
import com.hzya.frame.sysnew.menuConfig.dao.ISysMenuConfigDao;
import com.hzya.frame.sysnew.menuConfig.entity.SysMenuConfigEntity;
import com.hzya.frame.util.PluginUtils;
import com.hzya.frame.uuid.UUIDUtils;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 主数据服务实现类
 */
@Service(value = "mdmService")
public class MdmServiceImpl implements IMdmService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    protected IModuleMapper moduleMapper;
    @Resource
    protected IRoleModuleMapper roleModuleMapper;
    @Resource
    private IMdmModuleDao mdmModuleDao; //主数据模版
    @Resource
    private IMdmModuleDbDao mdmModuleDbDao;//模版数据库表
    @Resource
    private IMdmModuleDbFiledsDao mdmModuleDbFiledsDao;//模版数据库字段表
    @Resource
    private IMdmModuleDbFiledsRuleDao mdmModuleDbFiledsRuleDao;//模版数据库字段规则表
    @Resource
    private IMdmModuleDbFiledsRuleFilesDao mdmModuleDbFiledsRuleFilesDao;//模版数据库字段规则档案表
    @Resource
    private IMdmModuleDistributeDao mdmModuleDistributeDao;//主数据功能应用分发表
    @Resource
    private IMdmModuleDistributeDetailDao mdmModuleDistributeDetailDao;//主数据功能应用分发明细表
    @Resource
    private IMdmModuleRoleDao mdmModuleRoleDao;//主数据功能角色表
    @Resource
    private IMdmModuleRoleButtonDao mdmModuleRoleButtonDao;//主数据功能角色按钮表
    @Resource
    private IMdmModuleUserViewDao mdmModuleUserViewDao;//主数据用户视图表
    @Resource
    private IMdmModuleViewDao mdmModuleViewDao;//主数据视图表
    @Resource
    private IMdmModuleViewDetailDao mdmModuleViewDetailDao;//主数据视图明细表
    @Resource
    private IMdmTableCodeRuleDao mdmTableCodeRuleDao;//模版数据表编码规则表
    @Resource
    protected ISysApplicationPluginDao sysApplicationPluginDao;
    @Resource
    private ISysMenuConfigDao sysMenuConfigDao;
    @Resource
    private ISysButtonConfigDao sysButtonConfigDao;

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据列表查询接口分页
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmPage(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        //判断分页
        if (entity == null || entity.getPageNum() == null || entity.getPageSize() == null) {
            return BaseResult.getFailureMessageEntity("分页查询参数不存在");
        }
        PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
        List<MdmVo> mdmVos = mdmModuleDao.queryMdm(entity);
        PageInfo pageInfo = new PageInfo(mdmVos);
        return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据列表查询接口列表
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmList(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        List<MdmVo> mdmVos = mdmModuleDao.queryMdm(entity);
        return BaseResult.getSuccessMessageEntity("查询数据成功", mdmVos);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据基本信息
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModule(JSONObject object) {
        MdmModuleEntity entity = getData("jsonStr", object, MdmModuleEntity.class);
        MdmModuleEntity mdmModuleEntity = mdmModuleDao.queryOne(entity);
        return BaseResult.getSuccessMessageEntity("查询数据成功", mdmModuleEntity);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据基本信息保存
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity doSaveMdmModule(JSONObject object) {
        MdmModuleEntity entity = getData("jsonStr", object, MdmModuleEntity.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getMdmName() == null || "".equals(entity.getMdmName())) {
            return BaseResult.getFailureMessageEntity("请先输入主数据名称");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            //新增
            entity.setId(UUIDUtils.getUUID());
            entity.setSts("Y");
            entity.setCreate_user_id(StpUtil.getLoginIdAsString());
            entity.setModify_user_id(StpUtil.getLoginIdAsString());
            entity.setCreate_time(new Date());
            entity.setModify_time(new Date());
            mdmModuleDao.save(entity);
        } else {
            //修改
            entity.setSts("Y");
            entity.setModify_user_id(StpUtil.getLoginIdAsString());
            entity.setModify_time(new Date());
            mdmModuleDao.update(entity);
        }
        return BaseResult.getSuccessMessageEntity("保存数据成功", entity);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询数据源
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleDb(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        //判断分页
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        MdmDbVo mdmDbVo = new MdmDbVo();

        //查询设置的规则表
        MdmModuleDbFiledsRuleFilesEntity mdmModuleDbFiledsRuleFilesEntity = new MdmModuleDbFiledsRuleFilesEntity();
        mdmModuleDbFiledsRuleFilesEntity.setSts("Y");
        List<MdmModuleDbFiledsRuleFilesEntity> moduleDbFiledsRuleFiles = mdmModuleDbFiledsRuleFilesDao.queryBase(mdmModuleDbFiledsRuleFilesEntity);
        mdmDbVo.setModuleDbFiledsRuleFiles(moduleDbFiledsRuleFiles);
        //查询设置的规则表
        MdmTableCodeRuleEntity mdmTableCodeRuleEntity = new MdmTableCodeRuleEntity();
        mdmTableCodeRuleEntity.setSts("Y");
        mdmTableCodeRuleEntity.setMdmId(entity.getId());
        List<MdmTableCodeRuleEntity> mdmTableCodeRuleEntityList = mdmTableCodeRuleDao.queryBase(mdmTableCodeRuleEntity);
        mdmDbVo.setMdmTableCodeRuleEntityList(mdmTableCodeRuleEntityList);
        //查询数据源表
        MdmModuleDbEntity queryDb = new MdmModuleDbEntity();
        queryDb.setMdmId(entity.getId());
        queryDb.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(queryDb);
        List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = null;
        List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntityList = null;
        //存在表查询数据下的字段
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            MdmModuleDbFiledsEntity queryDbFiled = new MdmModuleDbFiledsEntity();
            queryDbFiled.setMdmId(entity.getId());
            queryDbFiled.setSts("Y");
            mdmModuleDbFiledsEntityList = mdmModuleDbFiledsDao.queryBase(queryDbFiled);
            //存在字段查询字段的属性
            if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                MdmModuleDbFiledsRuleEntity queryDbFiledRule = new MdmModuleDbFiledsRuleEntity();
                queryDbFiledRule.setMdmId(entity.getId());
                queryDbFiledRule.setSts("Y");
                mdmModuleDbFiledsRuleEntityList = mdmModuleDbFiledsRuleDao.queryBase(queryDbFiledRule);
            }
        }
        //组装数据
        setMdmDb(mdmDbVo, mdmModuleDbEntityList, mdmModuleDbFiledsEntityList, mdmModuleDbFiledsRuleEntityList);
        return BaseResult.getSuccessMessageEntity("查询数据成功", mdmDbVo);
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询数据源的服务
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleServer(JSONObject object) {
        MdmModuleDbEntity entity = getData("jsonStr", object, MdmModuleDbEntity.class);
        //判断分页
        if (entity == null) {
            entity = new MdmModuleDbEntity();
        }
        //查询数据源表
        entity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryByLike(entity);
        return BaseResult.getSuccessMessageEntity("查询数据成功", mdmModuleDbEntityList);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询数据源的服务的字段
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleServerFiled(JSONObject object) {
        MdmModuleDbEntity entity = getData("jsonStr", object, MdmModuleDbEntity.class);
        //判断分页
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getDbName() == null || "".equals(entity.getDbName())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询数据源表
        entity.setSts("Y");
        List<MdmModuleDbEntity> dblist = mdmModuleDbDao.queryBase(entity);
        if (dblist != null && dblist.size() == 1) {
            MdmModuleDbFiledsEntity queryDbFiled = new MdmModuleDbFiledsEntity();
            queryDbFiled.setSts("Y");
            queryDbFiled.setDbId(dblist.get(0).getId());
            List<MdmModuleDbFiledsEntity> list = mdmModuleDbFiledsDao.queryBase(queryDbFiled);
            MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
            mdmModuleDbFiledsEntity.setChName("id");
            mdmModuleDbFiledsEntity.setEnName("id");
            list.add(0, mdmModuleDbFiledsEntity);
            return BaseResult.getSuccessMessageEntity("查询数据成功", list);
        } else {
            return BaseResult.getFailureMessageEntity("服务不存在");
        }
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询主表字段
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleServerMainFiled(JSONObject object) {
        MdmModuleDbEntity entity = getData("jsonStr", object, MdmModuleDbEntity.class);
        //判断分页
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getMdmId() == null || "".equals(entity.getMdmId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询数据源表
        entity.setSts("Y");
        entity.setDbType("1");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(entity);
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() == 1) {
            MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
            mdmModuleDbFiledsEntity.setSts("Y");
            mdmModuleDbFiledsEntity.setDbId(mdmModuleDbEntityList.get(0).getId());
            List<MdmModuleDbFiledsEntity> list = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity);
            return BaseResult.getSuccessMessageEntity("查询数据成功", list);
        } else if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("请先配置数据源");
        } else {
            return BaseResult.getFailureMessageEntity("查询数据失败");
        }
    }

    /**
     * @param mdmDbVo                         返回对象
     * @param mdmModuleDbEntityList           数据表
     * @param mdmModuleDbFiledsEntityList     字段
     * @param mdmModuleDbFiledsRuleEntityList 字段属性
     * @return void
     * @Author lvleigang
     * @Description 组装返回数据
     * @Date 4:51 下午 2023/10/18
     **/
    private void setMdmDb(MdmDbVo mdmDbVo, List<MdmModuleDbEntity> mdmModuleDbEntityList, List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList, List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntityList) {
        //主数据主表
        MdmModuleDbEntity mainMdmModuleDb = new MdmModuleDbEntity();
        //主数据子表
        List<MdmModuleDbEntity> sublistMdmModuleDb = new ArrayList<>();
        //主数据主表字段
        List<MdmModuleDbFiledsEntity> mainMdmModuleDbFileds = new ArrayList<>();


        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    //1、主表 2、明细
                    mainMdmModuleDb = mdmModuleDbEntityList.get(i);
                    //循环字段表
                    if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                        for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                            if (mdmModuleDbEntityList.get(i).getId().equals(mdmModuleDbFiledsEntityList.get(i1).getDbId())) {
                                mainMdmModuleDbFileds.add(mdmModuleDbFiledsEntityList.get(i1));
                                List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules = new ArrayList<>();
                                //循环字段属性
                                if (mdmModuleDbFiledsRuleEntityList != null && mdmModuleDbFiledsRuleEntityList.size() > 0) {
                                    for (int i2 = 0; i2 < mdmModuleDbFiledsRuleEntityList.size(); i2++) {
                                        if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getDbId())
                                                && mdmModuleDbFiledsEntityList.get(i1).getId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getFiledId())) {
                                            mdmModuleDbFiledsRules.add(mdmModuleDbFiledsRuleEntityList.get(i2));
                                        }
                                    }
                                }
                                mdmModuleDbFiledsEntityList.get(i1).setMdmModuleDbFiledsRules(mdmModuleDbFiledsRules);
                            }
                        }
                    }
                } else if ("2".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    //2、明细
                    sublistMdmModuleDb.add(mdmModuleDbEntityList.get(i));
                    //循环字段表
                    if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                        List<MdmModuleDbFiledsEntity> sublistMdmModuleDbFileds = new ArrayList<>();
                        for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                            if (mdmModuleDbEntityList.get(i).getId().equals(mdmModuleDbFiledsEntityList.get(i1).getDbId())) {
                                sublistMdmModuleDbFileds.add(mdmModuleDbFiledsEntityList.get(i1));
                                List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules = new ArrayList<>();
                                //循环字段属性
                                if (mdmModuleDbFiledsRuleEntityList != null && mdmModuleDbFiledsRuleEntityList.size() > 0) {
                                    for (int i2 = 0; i2 < mdmModuleDbFiledsRuleEntityList.size(); i2++) {
                                        if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getDbId())
                                                && mdmModuleDbFiledsEntityList.get(i1).getId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getFiledId())) {
                                            mdmModuleDbFiledsRules.add(mdmModuleDbFiledsRuleEntityList.get(i2));
                                        }
                                    }
                                }
                                mdmModuleDbFiledsEntityList.get(i1).setMdmModuleDbFiledsRules(mdmModuleDbFiledsRules);
                            }
                        }
                        mdmModuleDbEntityList.get(i).setSublistMdmModuleDbFileds(sublistMdmModuleDbFileds);
                    }
                }
            }
        }
        mainMdmModuleDb.setSublistMdmModuleDbFileds(mainMdmModuleDbFileds);
        mdmDbVo.setMainMdmModuleDb(mainMdmModuleDb);
        mdmDbVo.setSublistMdmModuleDb(sublistMdmModuleDb);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置保存数据源
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity saveMdmModuleDb(JSONObject object) {
        //判断新增还是修改，保存数据生成表结构
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getMainMdmModuleDb() == null || entity.getMainMdmModuleDb().getDbName() == null || "".equals(entity.getMainMdmModuleDb().getDbName())) {
            return BaseResult.getFailureMessageEntity("请先输入主表名称");
        }
        //主数据主表
        MdmModuleDbEntity mainMdmModuleDb = entity.getMainMdmModuleDb();
        //主数据主表字段
        List<MdmModuleDbFiledsEntity> mainMdmModuleDbFileds = mainMdmModuleDb.getSublistMdmModuleDbFileds();
        //主数据子表
        List<MdmModuleDbEntity> sublistMdmModuleDb = entity.getSublistMdmModuleDb();
        //判断主表新增还是修改
        if (mainMdmModuleDb.getId() == null || "".equals(mainMdmModuleDb.getId())) {
            //新增 需要校验表是否存在
            if (checkTable(mainMdmModuleDb.getDbName())) {
                return BaseResult.getFailureMessageEntity("主表表名已经存在");
            }
        }
        //判断明细表
        if (sublistMdmModuleDb != null && sublistMdmModuleDb.size() > 0) {
            for (int i = 0; i < sublistMdmModuleDb.size(); i++) {
                if (sublistMdmModuleDb.get(i).getId() == null || "".equals(sublistMdmModuleDb.get(i).getId())) {
                    if (sublistMdmModuleDb.get(i).getSublistMdmModuleDbFileds() == null && sublistMdmModuleDb.get(i).getSublistMdmModuleDbFileds().size() == 0) {
                        return BaseResult.getFailureMessageEntity("请先设置子表" + sublistMdmModuleDb.get(i).getDbName() + "的字段");
                    }
                    //新增 需要校验表是否存在
                    if (checkTable(sublistMdmModuleDb.get(i).getDbName())) {
                        return BaseResult.getFailureMessageEntity("子表" + sublistMdmModuleDb.get(i).getDbName() + "已经存在");
                    }
                }
            }
        }
        //设置保存主表和字段以及字段的属性
        setMainTable(entity, mainMdmModuleDb, mainMdmModuleDbFileds);
        //设置保存子表数据
        setsublistTable(entity, mainMdmModuleDb, sublistMdmModuleDb);
        //保存规则
        List<MdmTableCodeRuleEntity> mdmTableCodeRuleEntityList = entity.getMdmTableCodeRuleEntityList();
        MdmTableCodeRuleEntity deleteOldData = new MdmTableCodeRuleEntity();
        deleteOldData.setDbId(mainMdmModuleDb.getId());
        deleteOldData.setMdmId(entity.getId());
        deleteOldData.setSts("Y");
        deleteOldData.setModify_user_id(StpUtil.getLoginIdAsString());
        deleteOldData.setModify_time(new Date());
        mdmTableCodeRuleDao.logicRemoveMultiCondition(deleteOldData);
        if (mdmTableCodeRuleEntityList != null && mdmTableCodeRuleEntityList.size() > 0) {
            for (int i = 0; i < mdmTableCodeRuleEntityList.size(); i++) {
                MdmTableCodeRuleEntity mdmTableCodeRuleEntity = mdmTableCodeRuleEntityList.get(i);
                mdmTableCodeRuleEntity.setMdmId(entity.getId());
                mdmTableCodeRuleEntity.setDbId(mainMdmModuleDb.getId());
                mdmTableCodeRuleEntity.setId(UUIDUtils.getUUID());
                mdmTableCodeRuleEntity.setSts("Y");
                mdmTableCodeRuleEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                mdmTableCodeRuleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                mdmTableCodeRuleEntity.setCreate_time(new Date());
                mdmTableCodeRuleEntity.setModify_time(new Date());
                mdmTableCodeRuleDao.save(mdmTableCodeRuleEntity);
            }
        }
        return BaseResult.getSuccessMessageEntity("保存数据源成功");
    }

    /**
     * @param entity
     * @param mainMdmModuleDb
     * @param sublistMdmModuleDb
     * @return void
     * @Author lvleigang
     * @Description 设置保存子表数据
     * @Date 11:08 上午 2023/10/19
     **/
    private void setsublistTable(MdmDto entity, MdmModuleDbEntity mainMdmModuleDb, List<MdmModuleDbEntity> sublistMdmModuleDb) {
        //存在明细表
        if (sublistMdmModuleDb != null && sublistMdmModuleDb.size() > 0) {
            for (int i = 0; i < sublistMdmModuleDb.size(); i++) {
                MdmModuleDbEntity mdmModuleDbEntity = sublistMdmModuleDb.get(i);
                mdmModuleDbEntity.setMdmId(entity.getId());
                mdmModuleDbEntity.setDbType("2");
                boolean flag = false;

                //新增还是修改
                if (mdmModuleDbEntity.getId() != null && !"".equals(mdmModuleDbEntity.getId())) {
                    mdmModuleDbEntity.setSts("Y");
                    mdmModuleDbEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                    mdmModuleDbEntity.setModify_time(new Date());
                    mdmModuleDbDao.update(mdmModuleDbEntity);
                } else {
                    flag = true;
                    mdmModuleDbEntity.setId(UUIDUtils.getUUID());
                    mdmModuleDbEntity.setSts("Y");
                    mdmModuleDbEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                    mdmModuleDbEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                    mdmModuleDbEntity.setCreate_time(new Date());
                    mdmModuleDbEntity.setModify_time(new Date());
                    mdmModuleDbDao.save(mdmModuleDbEntity);
                }
                List<DbFiledsDto> dbFiledsDtos = new ArrayList<>();

                //字段
                List<MdmModuleDbFiledsEntity> sublistMdmModuleDbFileds = mdmModuleDbEntity.getSublistMdmModuleDbFileds();
                if (sublistMdmModuleDbFileds != null && sublistMdmModuleDbFileds.size() > 0) {
                    for (int i1 = 0; i1 < sublistMdmModuleDbFileds.size(); i1++) {
                        MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = sublistMdmModuleDbFileds.get(i1);
                        mdmModuleDbFiledsEntity.setMdmId(entity.getId());
                        mdmModuleDbFiledsEntity.setDbId(mdmModuleDbEntity.getId());
                        if (mdmModuleDbFiledsEntity.getId() != null && !"".equals(mdmModuleDbFiledsEntity.getId())) {
                            DbFiledsDto dbFiledsDto = new DbFiledsDto("1", mdmModuleDbFiledsEntity.getChName(), mdmModuleDbFiledsEntity.getEnName(), mdmModuleDbFiledsEntity.getFiledType(), mdmModuleDbFiledsEntity.getFiledLength());
                            dbFiledsDtos.add(dbFiledsDto);
                            mdmModuleDbFiledsEntity.setSts("Y");
                            mdmModuleDbFiledsEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                            mdmModuleDbFiledsEntity.setModify_time(new Date());
                            mdmModuleDbFiledsDao.update(mdmModuleDbFiledsEntity);
                        } else {
                            DbFiledsDto dbFiledsDto = new DbFiledsDto("2", mdmModuleDbFiledsEntity.getChName(), mdmModuleDbFiledsEntity.getEnName(), mdmModuleDbFiledsEntity.getFiledType(), mdmModuleDbFiledsEntity.getFiledLength());
                            dbFiledsDtos.add(dbFiledsDto);
                            mdmModuleDbFiledsEntity.setId(UUIDUtils.getUUID());
                            mdmModuleDbFiledsEntity.setSts("Y");
                            mdmModuleDbFiledsEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                            mdmModuleDbFiledsEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                            mdmModuleDbFiledsEntity.setCreate_time(new Date());
                            mdmModuleDbFiledsEntity.setModify_time(new Date());
                            mdmModuleDbFiledsDao.save(mdmModuleDbFiledsEntity);
                        }
                        //修改或保存属性
                        List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules = mdmModuleDbFiledsEntity.getMdmModuleDbFiledsRules();
                        if (mdmModuleDbFiledsRules != null && mdmModuleDbFiledsRules.size() > 0) {
                            for (int a = 0; a < mdmModuleDbFiledsRules.size(); a++) {
                                MdmModuleDbFiledsRuleEntity mdmModuleDbFiledsRuleEntity = mdmModuleDbFiledsRules.get(a);
                                mdmModuleDbFiledsRuleEntity.setMdmId(entity.getId());
                                mdmModuleDbFiledsRuleEntity.setDbId(mdmModuleDbEntity.getId());
                                mdmModuleDbFiledsRuleEntity.setFiledId(mdmModuleDbFiledsEntity.getId());
                                if (mdmModuleDbFiledsRuleEntity.getId() != null && !"".equals(mdmModuleDbFiledsRuleEntity.getId())) {
                                    mdmModuleDbFiledsRuleEntity.setSts("Y");
                                    mdmModuleDbFiledsRuleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                                    mdmModuleDbFiledsRuleEntity.setModify_time(new Date());
                                    mdmModuleDbFiledsRuleDao.update(mdmModuleDbFiledsRuleEntity);
                                } else {
                                    mdmModuleDbFiledsRuleEntity.setId(UUIDUtils.getUUID());
                                    mdmModuleDbFiledsRuleEntity.setSts("Y");
                                    mdmModuleDbFiledsRuleEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                                    mdmModuleDbFiledsRuleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                                    mdmModuleDbFiledsRuleEntity.setCreate_time(new Date());
                                    mdmModuleDbFiledsRuleEntity.setModify_time(new Date());
                                    mdmModuleDbFiledsRuleDao.save(mdmModuleDbFiledsRuleEntity);
                                }
                            }
                        }
                    }
                }

                if (flag) {
                    //新增
                    Map<String, Object> maps = new HashMap<>();
                    maps.put("dbType", "2");//表类型
                    maps.put("tableName", mdmModuleDbEntity.getDbName());//表名
                    maps.put("tableRemark", mdmModuleDbEntity.getRemark());//表备注
                    maps.put("databaseFields", dbFiledsDtos);//字段
                    DbFiledsDto dbFiledsDto = new DbFiledsDto("1", "上级id", "formmain_id", "3", "50");
                    dbFiledsDtos.add(dbFiledsDto);
                    mdmModuleDao.createTable(maps);
                } else {
                    //修改
                    Map<String, String> tablename = new HashMap<>();
                    tablename.put("tableName", mdmModuleDbEntity.getDbName());//表名
                    tablename.put("tableRemark", mdmModuleDbEntity.getRemark());//表备注
                    mdmModuleDao.alterTableName(tablename);
                    Map<String, Object> maps = new HashMap<>();
                    maps.put("tableName", mdmModuleDbEntity.getDbName());//表名
                    maps.put("tableRemark", mdmModuleDbEntity.getRemark());//表备注
                    maps.put("databaseFields", dbFiledsDtos);//字段
                    mdmModuleDao.alterTable(maps);
                }
            }
        }
    }

    /**
     * @param entity
     * @param mainMdmModuleDb
     * @param mainMdmModuleDbFileds
     * @return void
     * @Author lvleigang
     * @Description 设置保存主表和字段以及字段的属性
     * @Date 10:34 上午 2023/10/19
     **/
    private void setMainTable(MdmDto entity, MdmModuleDbEntity mainMdmModuleDb, List<MdmModuleDbFiledsEntity> mainMdmModuleDbFileds) {
        //先保存或修改主表数据
        mainMdmModuleDb.setMdmId(entity.getId());
        mainMdmModuleDb.setDbType("1");
        boolean flag = false;

        if (mainMdmModuleDb.getId() != null && !"".equals(mainMdmModuleDb.getId())) {
            mainMdmModuleDb.setSts("Y");
            mainMdmModuleDb.setModify_user_id(StpUtil.getLoginIdAsString());
            mainMdmModuleDb.setModify_time(new Date());
            mdmModuleDbDao.update(mainMdmModuleDb);
            //删除规则表
            MdmModuleDbFiledsRuleEntity delectFiledsRule = new MdmModuleDbFiledsRuleEntity();
            delectFiledsRule.setMdmId(entity.getId());
            delectFiledsRule.setModify_user_id(StpUtil.getLoginIdAsString());
            delectFiledsRule.setModify_time(new Date());
            mdmModuleDbFiledsRuleDao.logicRemoveMultiCondition(delectFiledsRule);
        } else {
            flag = true;
            mainMdmModuleDb.setId(UUIDUtils.getUUID());
            mainMdmModuleDb.setSts("Y");
            mainMdmModuleDb.setCreate_user_id(StpUtil.getLoginIdAsString());
            mainMdmModuleDb.setModify_user_id(StpUtil.getLoginIdAsString());
            mainMdmModuleDb.setCreate_time(new Date());
            mainMdmModuleDb.setModify_time(new Date());
            mdmModuleDbDao.save(mainMdmModuleDb);
        }
        List<DbFiledsDto> dbFiledsDtos = new ArrayList<>();

        //保存主表字段 因为字段不允许删除，所以不用先删除再新增
        if (mainMdmModuleDbFileds != null && mainMdmModuleDbFileds.size() > 0) {
            for (int i = 0; i < mainMdmModuleDbFileds.size(); i++) {
                MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = mainMdmModuleDbFileds.get(i);
                mdmModuleDbFiledsEntity.setMdmId(entity.getId());
                mdmModuleDbFiledsEntity.setDbId(mainMdmModuleDb.getId());
                if (mdmModuleDbFiledsEntity.getId() != null && !"".equals(mdmModuleDbFiledsEntity.getId())) {
                    DbFiledsDto dbFiledsDto = new DbFiledsDto("1", mdmModuleDbFiledsEntity.getChName(), mdmModuleDbFiledsEntity.getEnName(), mdmModuleDbFiledsEntity.getFiledType(), mdmModuleDbFiledsEntity.getFiledLength());
                    dbFiledsDtos.add(dbFiledsDto);

                    mdmModuleDbFiledsEntity.setSts("Y");
                    mdmModuleDbFiledsEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                    mdmModuleDbFiledsEntity.setModify_time(new Date());
                    mdmModuleDbFiledsDao.update(mdmModuleDbFiledsEntity);
                } else {
                    DbFiledsDto dbFiledsDto = new DbFiledsDto("2", mdmModuleDbFiledsEntity.getChName(), mdmModuleDbFiledsEntity.getEnName(), mdmModuleDbFiledsEntity.getFiledType(), mdmModuleDbFiledsEntity.getFiledLength());
                    dbFiledsDtos.add(dbFiledsDto);
                    mdmModuleDbFiledsEntity.setId(UUIDUtils.getUUID());
                    mdmModuleDbFiledsEntity.setSts("Y");
                    mdmModuleDbFiledsEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                    mdmModuleDbFiledsEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                    mdmModuleDbFiledsEntity.setCreate_time(new Date());
                    mdmModuleDbFiledsEntity.setModify_time(new Date());
                    mdmModuleDbFiledsDao.save(mdmModuleDbFiledsEntity);
                }
                //修改或保存属性
                List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules = mdmModuleDbFiledsEntity.getMdmModuleDbFiledsRules();
                if (mdmModuleDbFiledsRules != null && mdmModuleDbFiledsRules.size() > 0) {
                    for (int a = 0; a < mdmModuleDbFiledsRules.size(); a++) {
                        MdmModuleDbFiledsRuleEntity mdmModuleDbFiledsRuleEntity = mdmModuleDbFiledsRules.get(a);
                        mdmModuleDbFiledsRuleEntity.setMdmId(entity.getId());
                        mdmModuleDbFiledsRuleEntity.setDbId(mainMdmModuleDb.getId());
                        mdmModuleDbFiledsRuleEntity.setFiledId(mdmModuleDbFiledsEntity.getId());
                        if (mdmModuleDbFiledsRuleEntity.getId() != null && !"".equals(mdmModuleDbFiledsRuleEntity.getId())) {
                            mdmModuleDbFiledsRuleEntity.setSts("Y");
                            mdmModuleDbFiledsRuleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                            mdmModuleDbFiledsRuleEntity.setModify_time(new Date());
                            mdmModuleDbFiledsRuleDao.update(mdmModuleDbFiledsRuleEntity);
                        } else {
                            mdmModuleDbFiledsRuleEntity.setId(UUIDUtils.getUUID());
                            mdmModuleDbFiledsRuleEntity.setSts("Y");
                            mdmModuleDbFiledsRuleEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                            mdmModuleDbFiledsRuleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                            mdmModuleDbFiledsRuleEntity.setCreate_time(new Date());
                            mdmModuleDbFiledsRuleEntity.setModify_time(new Date());
                            mdmModuleDbFiledsRuleDao.save(mdmModuleDbFiledsRuleEntity);
                        }
                    }
                }
            }
        }
        if (flag) {
            //新增
            Map<String, Object> maps = new HashMap<>();
            maps.put("dbType", "1");//表类型
            maps.put("tableName", mainMdmModuleDb.getDbName());//表名
            maps.put("tableRemark", mainMdmModuleDb.getRemark());//表备注
            maps.put("databaseFields", dbFiledsDtos);//字段
            mdmModuleDao.createTable(maps);
            Map<String, Object> mapsDistribute = new HashMap<>();
            mapsDistribute.put("tableName", mainMdmModuleDb.getDbName() + "_distribute");//表名
            List<DbFiledsDto> distribute = getDistribute();
            maps.put("databaseFields", distribute);//字段
            mapsDistribute.put("tableRemark", mainMdmModuleDb.getRemark() + "分发表");//表备注
            mdmModuleDao.createTableDistribute(mapsDistribute);
        } else {
            //修改
            Map<String, String> tablename = new HashMap<>();
            tablename.put("tableName", mainMdmModuleDb.getDbName());//表名
            tablename.put("tableRemark", mainMdmModuleDb.getRemark());//表备注
            mdmModuleDao.alterTableName(tablename);
            Map<String, Object> maps = new HashMap<>();
            maps.put("tableName", mainMdmModuleDb.getDbName());//表名
            maps.put("tableRemark", mainMdmModuleDb.getRemark());//表备注
            maps.put("databaseFields", dbFiledsDtos);//字段
            mdmModuleDao.alterTable(maps);
        }
    }

    /**
     * @param
     * @return java.util.List<com.hzya.frame.mdm.entity.DbFiledsDto>
     * @Author lvleigang
     * @Description 设置分发表字段
     * @Date 8:49 上午 2023/11/9
     **/
    private List<DbFiledsDto> getDistribute() {
        List<DbFiledsDto> dbFiledsDtos = new ArrayList<>();
        dbFiledsDtos.add(new DbFiledsDto("1", "数据id", "formmain_id", "3", "50"));
        dbFiledsDtos.add(new DbFiledsDto("1", "应用id", "app_id", "3", "50"));
        dbFiledsDtos.add(new DbFiledsDto("1", "状态1、发送成功 2、发送中 3、发送失败", "status", "3", "50"));
        dbFiledsDtos.add(new DbFiledsDto("1", "描述", "msg", "3", "50"));
        return dbFiledsDtos;
    }

    /**
     * @param tableName
     * @return java.lang.Long
     * @Author lvleigang
     * @Description 校验表是否存在
     * @Date 3:58 下午 2023/7/11
     **/
    private boolean checkTable(String tableName) {
        Map<String, String> maps = new HashMap<>();
        maps.put("tableName", tableName);
        Integer i = mdmModuleDao.checkTable(maps);
        if (i != null && i > 0) {
            return true;
        }
        return false;
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询显示信息
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleView(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        MdmModuleViewVo mdmModuleViewVo = new MdmModuleViewVo();
        //查询设置各种类型字段
        //查询模版数据源
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(entity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
            mdmModuleDbFiledsEntity.setMdmId(entity.getId());
            mdmModuleDbFiledsEntity.setSts("Y");
            List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity);
            setFiledType(mdmModuleViewVo, mdmModuleDbEntityList, mdmModuleDbFiledsEntityList);
        }
        //查询数据库设置的字段
        MdmModuleViewEntity mdmModuleViewEntity = new MdmModuleViewEntity();
        mdmModuleViewEntity.setMdmId(entity.getId());
        mdmModuleViewEntity.setSts("Y");
        List<MdmModuleViewEntity> moduleViewEntityList = mdmModuleViewDao.queryBase(mdmModuleViewEntity);
        if (moduleViewEntityList != null && moduleViewEntityList.size() == 1) {
            mdmModuleViewVo.setMdmModuleViewEntity(moduleViewEntityList.get(0));
            //查询明细
            MdmModuleViewDetailEntity mdmModuleViewDetailEntity = new MdmModuleViewDetailEntity();
            mdmModuleViewDetailEntity.setMdmId(entity.getId());
            mdmModuleViewDetailEntity.setViewId(moduleViewEntityList.get(0).getId());
            mdmModuleViewDetailEntity.setSts("Y");
            List<MdmModuleViewDetailEntity> mdmModuleViewDetailEntityList = mdmModuleViewDetailDao.queryBase(mdmModuleViewDetailEntity);
            setDbFiledType(mdmModuleViewVo, mdmModuleViewDetailEntityList);
        } else {
            mdmModuleViewVo.setMdmModuleViewEntity(new MdmModuleViewEntity());
            mdmModuleViewVo.setDbAddFiled(new ArrayList<>());
            mdmModuleViewVo.setDbEditFiled(new ArrayList<>());
            mdmModuleViewVo.setDbShowFiled(new ArrayList<>());
            mdmModuleViewVo.setDbQueryFiled(new ArrayList<>());
            mdmModuleViewVo.setDbListFiled(new ArrayList<>());
        }
        return BaseResult.getSuccessMessageEntity("查询视图成功", mdmModuleViewVo);
    }

    private void setDbFiledType(MdmModuleViewVo mdmModuleViewVo, List<MdmModuleViewDetailEntity> mdmModuleViewDetailEntityList) {
        //新增
        List<MdmModuleViewDetailEntity> addFiled = new ArrayList<>();
        //修改
        List<MdmModuleViewDetailEntity> editFiled = new ArrayList<>();
        //查看
        List<MdmModuleViewDetailEntity> showFiled = new ArrayList<>();
        //查询
        List<MdmModuleViewDetailEntity> queryFiled = new ArrayList<>();
        //列表
        List<MdmModuleViewDetailEntity> listFiled = new ArrayList<>();
        if (mdmModuleViewDetailEntityList != null && mdmModuleViewDetailEntityList.size() > 0) {
            for (int i = 0; i < mdmModuleViewDetailEntityList.size(); i++) {
                switch (mdmModuleViewDetailEntityList.get(i).getViewType()) {
                    //1、查询2、列表3、新增4、修改 5、查看
                    case "1":
                        queryFiled.add(mdmModuleViewDetailEntityList.get(i));
                        break;
                    case "2":
                        listFiled.add(mdmModuleViewDetailEntityList.get(i));
                        break;
                    case "3":
                        addFiled.add(mdmModuleViewDetailEntityList.get(i));
                        break;
                    case "4":
                        editFiled.add(mdmModuleViewDetailEntityList.get(i));
                        break;
                    case "5":
                        showFiled.add(mdmModuleViewDetailEntityList.get(i));
                        break;
                    default:
                }
            }
        }
        mdmModuleViewVo.setDbAddFiled(addFiled);
        mdmModuleViewVo.setDbEditFiled(editFiled);
        mdmModuleViewVo.setDbShowFiled(showFiled);
        mdmModuleViewVo.setDbQueryFiled(queryFiled);
        mdmModuleViewVo.setDbListFiled(listFiled);
    }

    /**
     * @param mdmModuleViewVo
     * @param mdmModuleDbEntityList
     * @param mdmModuleDbFiledsEntityList
     * @return void
     * @Author lvleigang
     * @Description 设置对应的字段类型
     * @Date 2023/10/25
     **/
    private void setFiledType(MdmModuleViewVo mdmModuleViewVo, List<MdmModuleDbEntity> mdmModuleDbEntityList, List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList) {
        //新增
        List<MdmDbFiledVo> addFiled = new ArrayList<>();
        //修改
        List<MdmDbFiledVo> editFiled = new ArrayList<>();
        //查看
        List<MdmDbFiledVo> showFiled = new ArrayList<>();
        //查询
        List<MdmDbFiledVo> queryFiled = new ArrayList<>();
        //列表
        List<MdmDbFiledVo> listFiled = new ArrayList<>();
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                    for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                        if (mdmModuleDbEntityList.get(i).getId().equals(mdmModuleDbFiledsEntityList.get(i1).getDbId())) {
                            if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                                //1、主表
                                addFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【主表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                editFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【主表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                showFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【主表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                queryFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【主表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                listFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【主表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                            } else {
                                //2、明细
                                queryFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【子表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                addFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【子表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                editFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【子表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                showFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【子表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                            }
                        }
                    }
                }
            }
        }
        mdmModuleViewVo.setAddFiled(addFiled);
        mdmModuleViewVo.setEditFiled(editFiled);
        mdmModuleViewVo.setShowFiled(showFiled);
        mdmModuleViewVo.setQueryFiled(queryFiled);
        mdmModuleViewVo.setListFiled(listFiled);
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置修改显示信息
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity doSaveMdmModuleView(JSONObject object) {
        MdmModuleViewDto entity = getData("jsonStr", object, MdmModuleViewDto.class);
        //判断是否有数据
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getMdmModuleViewEntity() == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        boolean flag = false;
        //保存主数据视图表
        MdmModuleViewEntity mdmModuleViewEntity = entity.getMdmModuleViewEntity();
        mdmModuleViewEntity.setMdmId(entity.getId());
        mdmModuleViewEntity.setSts("Y");
        mdmModuleViewEntity.setModify_user_id(StpUtil.getLoginIdAsString());
        mdmModuleViewEntity.setModify_time(new Date());
        if (mdmModuleViewEntity.getId() != null && !"".equals(mdmModuleViewEntity.getId())) {
            flag = false;
            //修改
            mdmModuleViewDao.update(mdmModuleViewEntity);
        } else {
            flag = true;
            //新增
            mdmModuleViewEntity.setId(UUIDUtils.getUUID());
            mdmModuleViewEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
            mdmModuleViewEntity.setCreate_time(new Date());
            mdmModuleViewDao.save(mdmModuleViewEntity);
        }
        //保存视图字段表
        //先删除明细表
        MdmModuleViewDetailEntity mdmModuleViewDetailEntity = new MdmModuleViewDetailEntity();
        mdmModuleViewDetailEntity.setMdmId(entity.getId());
        mdmModuleViewDetailEntity.setSts("Y");
        mdmModuleViewDetailEntity.setModify_user_id(StpUtil.getLoginIdAsString());
        mdmModuleViewDetailEntity.setModify_time(new Date());
        mdmModuleViewDetailDao.logicRemoveMultiCondition(mdmModuleViewDetailEntity);
        //1、查询2、列表3、新增4、修改 5、查看
        saveDbViewFiled(entity, mdmModuleViewEntity, entity.getQueryFiled(), "1");
        saveDbViewFiled(entity, mdmModuleViewEntity, entity.getListFiled(), "2");
        saveDbViewFiled(entity, mdmModuleViewEntity, entity.getAddFiled(), "3");
        saveDbViewFiled(entity, mdmModuleViewEntity, entity.getEditFiled(), "4");
        saveDbViewFiled(entity, mdmModuleViewEntity, entity.getShowFiled(), "5");
        MdmModuleEntity moduleEntity = new MdmModuleEntity();
        moduleEntity.setId(entity.getId());
        moduleEntity.setSts("Y");

        moduleEntity = mdmModuleDao.queryOne(moduleEntity);
        if (flag) {
            //新增菜单
            SysMenuConfigEntity module = new SysMenuConfigEntity();
            module.setCreate();
            module.setFormId(entity.getId());
            module.setParentMenuId("ea22757e99c144fb9ef381dd322e233c");
            module.setMenuName(moduleEntity.getMdmName());
            module.setMenuEnglishName("integrationOptionAdmin" + moduleEntity.getMdmCode());
            module.setMenuIcon(null);//模块图标
            module.setRoute("integrationOptionAdmin/" + moduleEntity.getMdmCode());//路由地址
            module.setMenuPage("integrationOptionV2/index");//一级Layout 二级 ParntView 三级component
            module.setRemark("主数据生成菜单");
            module.setVisibles("0");
            module.setShowType("1");
            JSONObject object1 = new JSONObject();
            object1.put("mdmId", moduleEntity.getId());//主数据id
            object1.put("mdmCode", moduleEntity.getMdmCode());//主数据编码
            object1.put("viewType", mdmModuleViewEntity.getViewName());//1、树 2、列表
            module.setOptions(object1.toString());//菜单mate参数
            sysMenuConfigDao.save(module);
            //todo 新增按钮
            SysButtonConfigEntity xz = new SysButtonConfigEntity();
            xz.setCode("new");
            xz.setNameCh("新建");
            xz.setNameEn("new");
            xz.setMenuId(module.getId());
            xz.setIconName("");
            xz.setStyles("");
            xz.setBtnFunction("new");
            xz.setRemark("主数据新建按钮");
            xz.setCreate();
            sysButtonConfigDao.save(xz);
            SysButtonConfigEntity cz = new SysButtonConfigEntity();
            cz.setCode("resize");
            cz.setNameCh("重置");
            cz.setNameEn("resize");
            cz.setMenuId(module.getId());
            cz.setIconName("");
            cz.setStyles("");
            cz.setBtnFunction("resize");
            cz.setRemark("主数据重置按钮");
            cz.setCreate();
            sysButtonConfigDao.save(cz);
            SysButtonConfigEntity cx = new SysButtonConfigEntity();
            cx.setCode("search");
            cx.setNameCh("查询");
            cx.setNameEn("search");
            cx.setMenuId(module.getId());
            cx.setIconName("");
            cx.setStyles("");
            cx.setBtnFunction("search");
            cx.setRemark("主数据查询按钮");
            cx.setCreate();
            sysButtonConfigDao.save(cx);
            SysButtonConfigEntity xg = new SysButtonConfigEntity();
            xg.setCode("edit");
            xg.setNameCh("修改");
            xg.setNameEn("edit");
            xg.setMenuId(module.getId());
            xg.setIconName("");
            xg.setStyles("");
            xg.setBtnFunction("edit");
            xg.setRemark("主数据修改按钮");
            xg.setCreate();
            sysButtonConfigDao.save(xg);
            SysButtonConfigEntity sc = new SysButtonConfigEntity();
            sc.setCode("dele");
            sc.setNameCh("删除");
            sc.setNameEn("dele");
            sc.setMenuId(module.getId());
            sc.setIconName("");
            sc.setStyles("");
            sc.setBtnFunction("dele");
            sc.setRemark("主数据删除按钮");
            sc.setCreate();
            sysButtonConfigDao.save(sc);
            SysButtonConfigEntity ck = new SysButtonConfigEntity();
            ck.setCode("view");
            ck.setNameCh("查看");
            ck.setNameEn("view");
            ck.setMenuId(module.getId());
            ck.setIconName("");
            ck.setStyles("");
            ck.setBtnFunction("view");
            ck.setRemark("主数据查看按钮");
            ck.setCreate();
            sysButtonConfigDao.save(ck);
            SysButtonConfigEntity xf = new SysButtonConfigEntity();
            xf.setCode("send");
            xf.setNameCh("下发");
            xf.setNameEn("send");
            xf.setMenuId(module.getId());
            xf.setIconName("");
            xf.setStyles("");
            xf.setBtnFunction("send");
            xf.setRemark("主数据下发按钮");
            xf.setCreate();
            sysButtonConfigDao.save(xf);
            //module.setServiceName("mdmService");//Spring bean名称
            //module.setLvl("2");//等级
            //module.setName("integrationOptionAdmin"+moduleEntity.getMdmCode());//名称
            //module.setCode(moduleEntity.getMdmCode().toString());//编码
            //module.setFormType("0");//类型  0、menu 1、tree  2、list 3、view
            //module.setLevel("2");//模块操作级别Superadministrator
            //module.setIcon(null);//模块图标
            //module.setUpIds("c3dda399207843eeac91770ac18e91e3");//上级id
            //module.setTableName(null);//bean表名称映射key
            //module.setKeyModular(null);//是否关键模块(Y是N否)
            //module.setTarget(null);//跳转目标
            //module.setRemark("主数据" + moduleEntity.getMdmName());//备注
            //module.setOpenType("1");//菜单打开方式
            //module.setFormId(entity.getId());//表单ID
            //module.setAppId(null);//应用id
            ////module.setPath("integrationOptionAdmin");//路由地址
            //module.setHidden("false");//隐藏
            //module.setRedirect(null);//redirevt
            //module.setAlwaysShow(null);//alwaysShow
            //module.setTitle(moduleEntity.getMdmName());//标题
            //module.setNoCache(null);//nocache缓存
            //module.setLabel(moduleEntity.getMdmName());//label

            //moduleMapper.entity_insert(module);
        } else {
            //修改菜单 注意因为可能修改显示类型，所以需要修改菜单的属性
            SysMenuConfigEntity module = new SysMenuConfigEntity();
            module.setFormId(entity.getId());
            module.setSts("Y");
            List<SysMenuConfigEntity> moduleList = sysMenuConfigDao.queryBase(module);
            if (moduleList != null && moduleList.size() == 1) {
                module = moduleList.get(0);
                module.setUpdate();
                module.setMenuName(moduleEntity.getMdmName());
                //module.setLabel(moduleEntity.getMdmName());//label
                JSONObject object1 = new JSONObject();
                object1.put("mdmId", moduleEntity.getId());//主数据id
                object1.put("mdmCode", moduleEntity.getMdmCode());//主数据id
                object1.put("viewType", mdmModuleViewEntity.getViewName());//1、树 2、列表
                module.setOptions(object1.toString());//菜单mate参数
                sysMenuConfigDao.update(module);
            } else {
                return BaseResult.getFailureMessageEntity("显示信息保存成功，菜单配置失败请检查");
            }
        }
        return BaseResult.getSuccessMessageEntity("保存显示信息成功");
    }

    /**
     * @param entity
     * @param mdmModuleViewEntity
     * @param mdmDbFiledVoList
     * @param type
     * @return void
     * @Author lvleigang
     * @Description 保存数据
     * @Date 1:37 下午 2023/10/25
     **/
    private void saveDbViewFiled(MdmModuleViewDto entity, MdmModuleViewEntity mdmModuleViewEntity, List<MdmDbFiledVo> mdmDbFiledVoList, String type) {
        if (mdmDbFiledVoList != null && mdmDbFiledVoList.size() > 0) {
            for (int i = 0; i < mdmDbFiledVoList.size(); i++) {
                MdmModuleViewDetailEntity mdmModuleViewDetailEntity = new MdmModuleViewDetailEntity();
                mdmModuleViewDetailEntity.setId(UUIDUtils.getUUID());
                mdmModuleViewDetailEntity.setSts("Y");
                mdmModuleViewDetailEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                mdmModuleViewDetailEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                mdmModuleViewDetailEntity.setCreate_time(new Date());
                mdmModuleViewDetailEntity.setModify_time(new Date());
                mdmModuleViewDetailEntity.setMdmId(entity.getId());
                mdmModuleViewDetailEntity.setViewId(mdmModuleViewEntity.getId());
                mdmModuleViewDetailEntity.setViewFiled(mdmDbFiledVoList.get(i).getId());
                mdmModuleViewDetailEntity.setViewType(type);
                mdmModuleViewDetailEntity.setSort(String.valueOf(i + 1));
                mdmModuleViewDetailDao.save(mdmModuleViewDetailEntity);
            }
        }
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询权限配置
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleRule(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询模块下的角色列表
        MdmModuleRoleEntity mdmModuleRoleEntity = new MdmModuleRoleEntity();
        mdmModuleRoleEntity.setSts("Y");
        mdmModuleRoleEntity.setMdmId(entity.getId());
        List<MdmModuleRoleEntity> mdmModuleRoleEntities = mdmModuleRoleDao.queryBase(mdmModuleRoleEntity);
        if (mdmModuleRoleEntities != null && mdmModuleRoleEntities.size() > 0) {
            MdmModuleRoleButtonEntity mdmModuleRoleButtonEntity = new MdmModuleRoleButtonEntity();
            mdmModuleRoleButtonEntity.setSts("Y");
            mdmModuleRoleButtonEntity.setMdmId(entity.getId());
            List<MdmModuleRoleButtonEntity> mdmModuleRoleButtonEntities = mdmModuleRoleButtonDao.queryBase(mdmModuleRoleButtonEntity);
            if (mdmModuleRoleButtonEntities != null && mdmModuleRoleButtonEntities.size() > 0) {
                for (int i = 0; i < mdmModuleRoleEntities.size(); i++) {
                    List<MdmModuleRoleButtonEntity> list = new ArrayList<>();
                    for (int i1 = 0; i1 < mdmModuleRoleButtonEntities.size(); i1++) {
                        if (mdmModuleRoleEntities.get(i).getRoleId().equals(mdmModuleRoleButtonEntities.get(i1).getRoleId())) {
                            list.add(mdmModuleRoleButtonEntities.get(i1));
                        }
                    }
                    mdmModuleRoleEntities.get(i).setMdmModuleRoleButtonEntities(list);
                }
            }
        }
        return BaseResult.getSuccessMessageEntity("查询成功", mdmModuleRoleEntities);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置保存权限配置
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity doSaveMdmModuleRule(JSONObject object) {
        MdmRoleDto entity = getData("jsonStr", object, MdmRoleDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询菜单
        Module module = new Module();
        module.setFormId(entity.getId());
        List<Module> moduleList = moduleMapper.entity_list_base(module);
        if (moduleList != null && moduleList.size() == 1) {
            module = moduleList.get(0);
        } else {
            return BaseResult.getFailureMessageEntity("菜单错误请检查菜单");
        }
        //先删除
        RoleModule roleModule = new RoleModule();
        roleModule.setSts("Y");
        roleModule.setUpdate();
        roleModule.setModuleId(module.getId());
        roleModuleMapper.entity_logicDelete_Multi_Condition(roleModule);
        MdmModuleRoleEntity mdmModuleRoleEntity = new MdmModuleRoleEntity();
        mdmModuleRoleEntity.setMdmId(entity.getId());
        mdmModuleRoleEntity.setSts("Y");
        mdmModuleRoleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
        mdmModuleRoleEntity.setModify_time(new Date());
        mdmModuleRoleDao.logicRemoveMultiCondition(mdmModuleRoleEntity);
        MdmModuleRoleButtonEntity mdmModuleRoleButtonEntity = new MdmModuleRoleButtonEntity();
        mdmModuleRoleButtonEntity.setMdmId(entity.getId());
        mdmModuleRoleButtonEntity.setSts("Y");
        mdmModuleRoleButtonEntity.setModify_user_id(StpUtil.getLoginIdAsString());
        mdmModuleRoleButtonEntity.setModify_time(new Date());
        mdmModuleRoleButtonDao.logicRemoveMultiCondition(mdmModuleRoleButtonEntity);

        if (entity.getMdmModuleRoleEntities() != null && entity.getMdmModuleRoleEntities().size() > 0) {
            for (int i = 0; i < entity.getMdmModuleRoleEntities().size(); i++) {

                MdmModuleRoleEntity moduleRoleEntity = entity.getMdmModuleRoleEntities().get(i);
                moduleRoleEntity.setMdmId(entity.getId());
                moduleRoleEntity.setSts("Y");
                moduleRoleEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                moduleRoleEntity.setModify_time(new Date());
                if (moduleRoleEntity.getId() != null && !"".equals(moduleRoleEntity.getId())) {
                    //修改
                    mdmModuleRoleDao.update(moduleRoleEntity);
                } else {
                    //新增
                    moduleRoleEntity.setId(UUIDUtils.getUUID());
                    moduleRoleEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                    moduleRoleEntity.setCreate_time(new Date());
                    mdmModuleRoleDao.save(moduleRoleEntity);
                }
                if (moduleRoleEntity.getMdmModuleRoleButtonEntities() != null && moduleRoleEntity.getMdmModuleRoleButtonEntities().size() > 0) {
                    for (int i1 = 0; i1 < moduleRoleEntity.getMdmModuleRoleButtonEntities().size(); i1++) {
                        MdmModuleRoleButtonEntity moduleRoleButtonEntity = moduleRoleEntity.getMdmModuleRoleButtonEntities().get(i1);
                        moduleRoleButtonEntity.setMdmId(entity.getId());
                        moduleRoleButtonEntity.setSts("Y");
                        moduleRoleButtonEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                        moduleRoleButtonEntity.setModify_time(new Date());
                        moduleRoleButtonEntity.setModuleRoleId(moduleRoleEntity.getRoleId());
                        moduleRoleButtonEntity.setRoleId(moduleRoleEntity.getRoleId());
                        if (moduleRoleButtonEntity.getId() != null && !"".equals(moduleRoleButtonEntity.getId())) {
                            //修改
                            mdmModuleRoleButtonDao.update(moduleRoleButtonEntity);
                        } else {
                            //新增
                            moduleRoleButtonEntity.setId(UUIDUtils.getUUID());
                            moduleRoleButtonEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                            moduleRoleButtonEntity.setCreate_time(new Date());
                            mdmModuleRoleButtonDao.save(moduleRoleButtonEntity);
                        }
                    }
                }
                //再添加
                RoleModule saveRole = new RoleModule();
                saveRole.setCreate();
                saveRole.setRoleId(moduleRoleEntity.getRoleId());
                saveRole.setModuleId(module.getId());
                roleModuleMapper.entity_insert(saveRole);
            }
        }
        return BaseResult.getSuccessMessageEntity("保存成功");
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置查询分发设置
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmModuleDistribute(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询模块下的应用列表
        MdmModuleDistributeEntity mdmModuleDistributeEntity = new MdmModuleDistributeEntity();
        mdmModuleDistributeEntity.setSts("Y");
        mdmModuleDistributeEntity.setMdmId(entity.getId());
        List<MdmModuleDistributeEntity> mdmModuleDistributeEntities = mdmModuleDistributeDao.queryBase(mdmModuleDistributeEntity);
        if (mdmModuleDistributeEntities != null && mdmModuleDistributeEntities.size() > 0) {
            MdmModuleDistributeDetailEntity mdmModuleDistributeDetailEntity = new MdmModuleDistributeDetailEntity();
            mdmModuleDistributeDetailEntity.setSts("Y");
            mdmModuleDistributeDetailEntity.setMdmId(entity.getId());
            List<MdmModuleDistributeDetailEntity> mdmModuleDistributeDetailEntities = mdmModuleDistributeDetailDao.queryBase(mdmModuleDistributeDetailEntity);
            if (mdmModuleDistributeDetailEntities != null && mdmModuleDistributeDetailEntities.size() > 0) {
                for (int i = 0; i < mdmModuleDistributeEntities.size(); i++) {
                    List<MdmModuleDistributeDetailEntity> addlist = new ArrayList<>();
                    List<MdmModuleDistributeDetailEntity> deletelist = new ArrayList<>();
                    for (int i1 = 0; i1 < mdmModuleDistributeDetailEntities.size(); i1++) {
                        if (mdmModuleDistributeEntities.get(i).getAddApi().equals(mdmModuleDistributeDetailEntities.get(i1).getApiId())
                                && mdmModuleDistributeEntities.get(i).getId().equals(mdmModuleDistributeDetailEntities.get(i1).getDistributeId())) {
                            addlist.add(mdmModuleDistributeDetailEntities.get(i1));
                        }
                        if (mdmModuleDistributeEntities.get(i).getDeleteApi().equals(mdmModuleDistributeDetailEntities.get(i1).getApiId())
                                && mdmModuleDistributeEntities.get(i).getId().equals(mdmModuleDistributeDetailEntities.get(i1).getDistributeId())) {
                            deletelist.add(mdmModuleDistributeDetailEntities.get(i1));
                        }
                    }
                    mdmModuleDistributeEntities.get(i).setAddList(addlist);
                    mdmModuleDistributeEntities.get(i).setDeleteList(deletelist);
                }
            }
        }
        return BaseResult.getSuccessMessageEntity("查询成功", mdmModuleDistributeEntities);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据设置保存分发设置
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity doSaveMdmModuleDistribute(JSONObject object) {
        MdmDistributeDto entity = getData("jsonStr", object, MdmDistributeDto.class);
        //判断是否有数据
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //if(entity.getMdmModuleDistributeEntities() == null ){
        //    return BaseResult.getFailureMessageEntity("参数不允许为空");
        //}
        //先删除
        MdmModuleDistributeEntity mdmModuleDistributeEntity = new MdmModuleDistributeEntity();
        mdmModuleDistributeEntity.setMdmId(entity.getId());
        mdmModuleDistributeEntity.setSts("Y");
        mdmModuleDistributeEntity.setModify_user_id(StpUtil.getLoginIdAsString());
        mdmModuleDistributeEntity.setModify_time(new Date());
        mdmModuleDistributeDao.logicRemoveMultiCondition(mdmModuleDistributeEntity);

        MdmModuleDistributeDetailEntity mdmModuleDistributeDetailEntity = new MdmModuleDistributeDetailEntity();
        mdmModuleDistributeDetailEntity.setMdmId(entity.getId());
        mdmModuleDistributeDetailEntity.setSts("Y");
        mdmModuleDistributeDetailEntity.setModify_user_id(StpUtil.getLoginIdAsString());
        mdmModuleDistributeDetailEntity.setModify_time(new Date());
        mdmModuleDistributeDetailDao.logicRemoveMultiCondition(mdmModuleDistributeDetailEntity);

        //保存主数据
        List<MdmModuleDistributeEntity> mdmModuleDistributeEntities = entity.getMdmModuleDistributeEntities();

        if (mdmModuleDistributeEntities != null && mdmModuleDistributeEntities.size() > 0) {
            for (int i = 0; i < mdmModuleDistributeEntities.size(); i++) {
                MdmModuleDistributeEntity moduleDistributeEntity = mdmModuleDistributeEntities.get(i);
                moduleDistributeEntity.setMdmId(entity.getId());
                moduleDistributeEntity.setSts("Y");
                moduleDistributeEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                moduleDistributeEntity.setModify_time(new Date());
                if (moduleDistributeEntity.getId() != null && !"".equals(moduleDistributeEntity.getId())) {
                    //修改
                    mdmModuleDistributeDao.update(moduleDistributeEntity);
                } else {
                    //新增
                    moduleDistributeEntity.setId(UUIDUtils.getUUID());
                    moduleDistributeEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                    moduleDistributeEntity.setCreate_time(new Date());
                    mdmModuleDistributeDao.save(moduleDistributeEntity);
                }
                if (moduleDistributeEntity.getAddList() != null && moduleDistributeEntity.getAddList().size() > 0) {
                    for (int i1 = 0; i1 < moduleDistributeEntity.getAddList().size(); i1++) {
                        MdmModuleDistributeDetailEntity moduleDistributeDetailEntity = moduleDistributeEntity.getAddList().get(i1);
                        moduleDistributeDetailEntity.setMdmId(entity.getId());
                        moduleDistributeDetailEntity.setSts("Y");
                        moduleDistributeDetailEntity.setApiId(moduleDistributeEntity.getAddApi());
                        moduleDistributeDetailEntity.setDistributeId(moduleDistributeEntity.getId());
                        moduleDistributeDetailEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                        moduleDistributeDetailEntity.setModify_time(new Date());
                        if (moduleDistributeDetailEntity.getId() != null && !"".equals(moduleDistributeDetailEntity.getId())) {
                            //修改
                            mdmModuleDistributeDetailDao.update(moduleDistributeDetailEntity);
                        } else {
                            //新增
                            moduleDistributeDetailEntity.setId(UUIDUtils.getUUID());
                            moduleDistributeDetailEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                            moduleDistributeDetailEntity.setCreate_time(new Date());
                            mdmModuleDistributeDetailDao.save(moduleDistributeDetailEntity);
                        }
                    }
                }
                if (moduleDistributeEntity.getDeleteList() != null && moduleDistributeEntity.getDeleteList().size() > 0) {
                    for (int i1 = 0; i1 < moduleDistributeEntity.getDeleteList().size(); i1++) {
                        MdmModuleDistributeDetailEntity moduleDistributeDetailEntity = moduleDistributeEntity.getDeleteList().get(i1);
                        moduleDistributeDetailEntity.setMdmId(entity.getId());
                        moduleDistributeDetailEntity.setSts("Y");
                        moduleDistributeDetailEntity.setApiId(moduleDistributeEntity.getDeleteApi());
                        moduleDistributeDetailEntity.setDistributeId(moduleDistributeEntity.getId());
                        moduleDistributeDetailEntity.setModify_user_id(StpUtil.getLoginIdAsString());
                        moduleDistributeDetailEntity.setModify_time(new Date());
                        if (moduleDistributeDetailEntity.getId() != null && !"".equals(moduleDistributeDetailEntity.getId())) {
                            //修改
                            mdmModuleDistributeDetailDao.update(moduleDistributeDetailEntity);
                        } else {
                            //新增
                            moduleDistributeDetailEntity.setId(UUIDUtils.getUUID());
                            moduleDistributeDetailEntity.setCreate_user_id(StpUtil.getLoginIdAsString());
                            moduleDistributeDetailEntity.setCreate_time(new Date());
                            mdmModuleDistributeDetailDao.save(moduleDistributeDetailEntity);
                        }
                    }
                }
            }
        }
        return BaseResult.getSuccessMessageEntity("保存发布设置成功");
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据列表显示 树、查询条件、列表字段、按钮
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShow(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getMdmCode() == null || "".equals(entity.getMdmCode())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询模版
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(entity.getMdmCode());
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }

        MdmViewVo mdmViewVo = new MdmViewVo();
        mdmModuleEntity = mdmModuleEntities.get(0);
        mdmViewVo.setMdmModuleEntity(mdmModuleEntity);
        //查询展示类型
        MdmModuleViewEntity mdmModuleViewEntity = new MdmModuleViewEntity();
        mdmModuleViewEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleViewEntity.setSts("Y");
        List<MdmModuleViewEntity> moduleViewEntityList = mdmModuleViewDao.queryBase(mdmModuleViewEntity);
        if (moduleViewEntityList == null || moduleViewEntityList.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        mdmModuleViewEntity = moduleViewEntityList.get(0);
        mdmViewVo.setMdmModuleViewEntity(mdmModuleViewEntity);

        //查询数据源主表
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询数据源表下面的字段
        MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
        mdmModuleDbFiledsEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbFiledsEntity.setSts("Y");
        List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity);
        if (mdmModuleDbFiledsEntityList == null || mdmModuleDbFiledsEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询字段下的规则
        MdmModuleDbFiledsRuleEntity mdmModuleDbFiledsRuleEntity = new MdmModuleDbFiledsRuleEntity();
        mdmModuleDbFiledsRuleEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbFiledsRuleEntity.setSts("Y");
        List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntityList = mdmModuleDbFiledsRuleDao.queryBase(mdmModuleDbFiledsRuleEntity);
        if (mdmModuleDbFiledsRuleEntityList == null || mdmModuleDbFiledsRuleEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询设置的查询字段
        MdmModuleViewDetailEntity mdmModuleViewDetailEntity = new MdmModuleViewDetailEntity();
        mdmModuleViewDetailEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleViewDetailEntity.setSts("Y");
        mdmModuleViewDetailEntity.setViewType("1");
        List<MdmModuleViewDetailEntity> queryList = mdmModuleViewDetailDao.queryBase(mdmModuleViewDetailEntity);
        //设置字段
        List<MdmViewFiledVo> queryListVo = setQueryList(mdmModuleDbEntityList, mdmModuleDbFiledsEntityList, mdmModuleDbFiledsRuleEntityList, queryList, false);
        mdmViewVo.setQueryList(queryListVo);

        //查询用户设置字段
        MdmModuleUserViewEntity mdmModuleUserViewEntity = new MdmModuleUserViewEntity();
        mdmModuleUserViewEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleUserViewEntity.setSts("Y");
        mdmModuleUserViewEntity.setUserId(StpUtil.getLoginIdAsString());
        List<MdmModuleUserViewEntity> mdmModuleUserViewEntities = mdmModuleUserViewDao.queryBase(mdmModuleUserViewEntity);

        //查询设置的查询字段
        MdmModuleViewDetailEntity mdmModuleViewDetailEntity1 = new MdmModuleViewDetailEntity();
        mdmModuleViewDetailEntity1.setMdmId(mdmModuleEntity.getId());
        mdmModuleViewDetailEntity1.setSts("Y");
        mdmModuleViewDetailEntity1.setViewType("2");
        List<MdmModuleViewDetailEntity> listList = mdmModuleViewDetailDao.queryBase(mdmModuleViewDetailEntity1);
        List<MdmModuleViewDetailEntity> dolistList = new ArrayList<>();

        if (mdmModuleUserViewEntities != null && mdmModuleUserViewEntities.size() > 0) {
            dolistList = getDolist(listList, mdmModuleUserViewEntities);
            if (dolistList == null || dolistList.size() == 0) {
                dolistList = listList;
            }
        } else {
            dolistList = listList;
        }
        List<MdmViewFiledVo> listListVo = setQueryList(mdmModuleDbEntityList, mdmModuleDbFiledsEntityList, mdmModuleDbFiledsRuleEntityList, dolistList, true);
        mdmViewVo.setListList(listListVo);

        List<MdmViewButtonVo> buttonList = new ArrayList<>();
        buttonList.add(new MdmViewButtonVo("new", "新建"));
        buttonList.add(new MdmViewButtonVo("resize", "重置"));
        buttonList.add(new MdmViewButtonVo("search", "查询"));
        buttonList.add(new MdmViewButtonVo("edit", "修改"));
        buttonList.add(new MdmViewButtonVo("dele", "删除"));
        buttonList.add(new MdmViewButtonVo("view", "查看"));
        buttonList.add(new MdmViewButtonVo("send", "下发"));
        mdmViewVo.setButtonList(buttonList);
        return BaseResult.getSuccessMessageEntity("获取字段成功", mdmViewVo);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据查询所有字段
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShowAll(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询设置各种类型字段
        //查询模版数据源
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(entity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        List<MdmDbFiledVo> listFiled = new ArrayList<>();
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
            mdmModuleDbFiledsEntity.setMdmId(entity.getId());
            mdmModuleDbFiledsEntity.setSts("Y");
            List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity);
            //
            if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
                for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                    if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                        for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                            if (mdmModuleDbEntityList.get(i).getId().equals(mdmModuleDbFiledsEntityList.get(i1).getDbId())) {
                                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                                    //1、主表
                                    listFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【主表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                } else {
                                    //2、明细
                                    listFiled.add(new MdmDbFiledVo(mdmModuleDbFiledsEntityList.get(i1).getId(), "【子表:" + mdmModuleDbEntityList.get(i).getDbName() + "】" + mdmModuleDbFiledsEntityList.get(i1).getChName()));
                                }
                            }
                        }
                    }
                }
            }
        }
        return BaseResult.getSuccessMessageEntity("查询视图成功", listFiled);
    }

    /**
     * @param mdmModuleRoleButtonEntities
     * @return java.util.List<com.hzya.frame.mdm.entity.MdmViewButtonVo>
     * @Author lvleigang
     * @Description 设置返回按钮
     * @Date 4:48 下午 2023/10/26
     **/
    private List<MdmViewButtonVo> setButton(List<MdmModuleRoleButtonEntity> mdmModuleRoleButtonEntities) {
        List<MdmViewButtonVo> mdmViewButtonVoList = new ArrayList<>();
        if (mdmModuleRoleButtonEntities != null && mdmModuleRoleButtonEntities.size() > 0) {
            for (int i = 0; i < mdmModuleRoleButtonEntities.size(); i++) {
                mdmViewButtonVoList.add(new MdmViewButtonVo(mdmModuleRoleButtonEntities.get(i).getButtonType(), mdmModuleRoleButtonEntities.get(i).getButtonName()));
            }
        }
        return mdmViewButtonVoList;
    }

    /**
     * @param allRecords
     * @param checkedMeters
     * @return java.util.List<com.hzya.frame.mdm.mdmModuleViewDetail.entity.MdmModuleViewDetailEntity>
     * @Author lvleigang
     * @Description 取出重复字段数据
     * @Date 4:34 下午 2023/10/26
     **/
    private List<MdmModuleViewDetailEntity> getDolist(List<MdmModuleViewDetailEntity> allRecords, List<MdmModuleUserViewEntity> checkedMeters) {
        List<MdmModuleViewDetailEntity> meterPlan = allRecords.stream()
                .filter(item -> checkedMeters.stream()
                        .map(e -> {
                            if (!Objects.equals(item.getViewFiled(), e.getViewDetailId())) {
                                return null;
                            } else {
                                return item.getViewFiled();
                            }
                        })
                        .collect(Collectors.toList())
                        .contains(item.getViewFiled()))
                .collect(Collectors.toList());
        return meterPlan;
    }

    /**
     * @param mdmModuleDbEntityList           数据源
     * @param mdmModuleDbFiledsEntityList     数据源下的字段表
     * @param mdmModuleDbFiledsRuleEntityList 数据源字段的规则表
     * @param queryList                       需要的字段
     * @return java.util.List<com.hzya.frame.mdm.entity.MdmViewFiledVo>
     * @Author lvleigang
     * @Description 根据字段设置返回前台字段
     * @Date 4:11 下午 2023/10/26
     **/
    private List<MdmViewFiledVo> setQueryList(List<MdmModuleDbEntity> mdmModuleDbEntityList, List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList, List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntityList, List<MdmModuleViewDetailEntity> queryList, boolean flag) {
        List<MdmViewFiledVo> mdmViewFiledVos = new ArrayList<>();

        if (queryList != null && queryList.size() > 0) {
            for (int i = 0; i < queryList.size(); i++) {
                MdmViewFiledVo mdmViewFiledVo = new MdmViewFiledVo();
                mdmViewFiledVo.setId(queryList.get(i).getViewFiled());//字段id
                mdmViewFiledVo.setSorts(i + 2);//排序
                for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                    if (queryList.get(i).getViewFiled().equals(mdmModuleDbFiledsEntityList.get(i1).getId())) {
                        mdmViewFiledVo.setFiledType(mdmModuleDbFiledsEntityList.get(i1).getFiledType());//英文名
                        mdmViewFiledVo.setEnName(mdmModuleDbFiledsEntityList.get(i1).getEnName());//英文名
                        mdmViewFiledVo.setChName(mdmModuleDbFiledsEntityList.get(i1).getChName());//中文名
                        for (int i2 = 0; i2 < mdmModuleDbEntityList.size(); i2++) {
                            if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbEntityList.get(i2).getId())) {
                                mdmViewFiledVo.setDbType(mdmModuleDbEntityList.get(i2).getDbType());//类型 1、主表 2、明细
                                mdmViewFiledVo.setMdmId(mdmModuleDbEntityList.get(i2).getMdmId());//主数据模版ID
                                mdmViewFiledVo.setDbId(mdmModuleDbEntityList.get(i2).getId());//模版数据库id
                                mdmViewFiledVo.setDbName(mdmModuleDbEntityList.get(i2).getDbName());//表名

                                break;
                            }
                        }
                        break;
                    }
                }
                //设置字段规则
                List<MdmModuleDbFiledsRuleEntity> ruleList = new ArrayList<>();
                if (mdmModuleDbFiledsRuleEntityList != null && mdmModuleDbFiledsRuleEntityList.size() > 0) {
                    for (int i1 = 0; i1 < mdmModuleDbFiledsRuleEntityList.size(); i1++) {
                        if (queryList.get(i).getViewFiled().equals(mdmModuleDbFiledsRuleEntityList.get(i1).getFiledId())) {
                            ruleList.add(mdmModuleDbFiledsRuleEntityList.get(i1));
                        }
                    }
                }
                mdmViewFiledVo.setRuleList(ruleList);
                mdmViewFiledVos.add(mdmViewFiledVo);
            }
        }
        MdmViewFiledVo mdmViewFiledVo = new MdmViewFiledVo();
        mdmViewFiledVo.setSorts(1);//排序
        mdmViewFiledVo.setFiledType("3");
        mdmViewFiledVo.setEnName("document_rule");//英文名
        mdmViewFiledVo.setChName("单据编码");//中文名
        mdmViewFiledVo.setDbType("1");//类型 1、主表 2、明细
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    mdmViewFiledVo.setDbName(mdmModuleDbEntityList.get(i).getDbName());//表名
                }
            }
        }
        List<MdmModuleDbFiledsRuleEntity> msgRule = new ArrayList<>();
        MdmModuleDbFiledsRuleEntity msgRuleTitie = new MdmModuleDbFiledsRuleEntity();
        msgRuleTitie.setFormName("optionRuleForm");
        msgRuleTitie.setRuleCode("title");
        msgRuleTitie.setRuleName("显示名");
        msgRuleTitie.setRuleType("2");
        msgRuleTitie.setRuleValue("单据编码");
        MdmModuleDbFiledsRuleEntity msgRulerow = new MdmModuleDbFiledsRuleEntity();
        msgRulerow.setFormName("optionRuleForm");
        msgRulerow.setRuleCode("row");
        msgRulerow.setRuleName("宽度");
        msgRulerow.setRuleType("2");
        msgRulerow.setRuleValue("12");
        MdmModuleDbFiledsRuleEntity msgRuletype = new MdmModuleDbFiledsRuleEntity();
        msgRuletype.setFormName("optionRuleForm");
        msgRuletype.setRuleCode("type");
        msgRuletype.setRuleName("数据类型");
        msgRuletype.setRuleType("2");
        msgRuletype.setRuleValue("input");
        MdmModuleDbFiledsRuleEntity msgRulerequired = new MdmModuleDbFiledsRuleEntity();
        msgRulerequired.setFormName("optionRuleForm");
        msgRulerequired.setRuleCode("required");
        msgRulerequired.setRuleName("必填");
        msgRulerequired.setRuleType("2");
        MdmModuleDbFiledsRuleEntity withs = new MdmModuleDbFiledsRuleEntity();
        withs.setFormName("optionRuleForm");
        withs.setRuleCode("width");
        withs.setRuleName("宽度");
        withs.setRuleType("2");
        withs.setRuleValue("200");
        msgRule.add(withs);
        msgRule.add(msgRulerequired);
        msgRule.add(msgRuletype);
        msgRule.add(msgRulerow);
        msgRule.add(msgRuleTitie);
        mdmViewFiledVo.setRuleList(msgRule);
        mdmViewFiledVos.add(0, mdmViewFiledVo);

        //添加分发数量
        if (flag) {
            addFfsl(mdmModuleDbEntityList, mdmViewFiledVos);
        }
        return mdmViewFiledVos;
    }

    private void addFfsl(List<MdmModuleDbEntity> mdmModuleDbEntityList, List<MdmViewFiledVo> mdmViewFiledVos) {

        MdmViewFiledVo mdmViewFiledVo = new MdmViewFiledVo();
        mdmViewFiledVo.setSorts(1);//排序
        mdmViewFiledVo.setFiledType("1");
        mdmViewFiledVo.setEnName("qwqwasdasdzxasda");//英文名
        mdmViewFiledVo.setChName("分发数量");//中文名
        mdmViewFiledVo.setDbType("1");//类型 1、主表 2、明细
        if (mdmModuleDbEntityList != null && mdmModuleDbEntityList.size() > 0) {
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    mdmViewFiledVo.setDbName(mdmModuleDbEntityList.get(i).getDbName());//表名
                }
            }
        }
        List<MdmModuleDbFiledsRuleEntity> msgRule = new ArrayList<>();
        MdmModuleDbFiledsRuleEntity msgRuleTitie = new MdmModuleDbFiledsRuleEntity();
        msgRuleTitie.setFormName("optionRuleForm");
        msgRuleTitie.setRuleCode("title");
        msgRuleTitie.setRuleName("显示名");
        msgRuleTitie.setRuleType("2");
        msgRuleTitie.setRuleValue("分发数量");
        MdmModuleDbFiledsRuleEntity msgRulerow = new MdmModuleDbFiledsRuleEntity();
        msgRulerow.setFormName("optionRuleForm");
        msgRulerow.setRuleCode("row");
        msgRulerow.setRuleName("宽度");
        msgRulerow.setRuleType("2");
        msgRulerow.setRuleValue("6");
        MdmModuleDbFiledsRuleEntity msgRuletype = new MdmModuleDbFiledsRuleEntity();
        msgRuletype.setFormName("optionRuleForm");
        msgRuletype.setRuleCode("type");
        msgRuletype.setRuleName("数据类型");
        msgRuletype.setRuleType("2");
        msgRuletype.setRuleValue("input");
        MdmModuleDbFiledsRuleEntity msgRulerequired = new MdmModuleDbFiledsRuleEntity();
        msgRulerequired.setFormName("optionRuleForm");
        msgRulerequired.setRuleCode("required");
        msgRulerequired.setRuleName("必填");
        msgRulerequired.setRuleType("2");
        msgRule.add(msgRulerequired);
        msgRule.add(msgRuletype);
        msgRule.add(msgRulerow);
        msgRule.add(msgRuleTitie);
        mdmViewFiledVo.setRuleList(msgRule);
        mdmViewFiledVos.add(mdmViewFiledVo);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据列表显示 业务数据
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShowData(JSONObject object) {
        MdmQuery entity = getData("jsonStr", object, MdmQuery.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        //判断分页
        if (entity == null || entity.getPageNum() == null || entity.getPageSize() == null) {
            return BaseResult.getFailureMessageEntity("分页查询参数不存在");
        }
        PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
        List<HashMap<String, Object>> businessResult = mdmModuleDao.queryMdmShowData(entity);
        PageInfo pageInfo = new PageInfo(businessResult);
        return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据列表显示 业务数据
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShowDistribute(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getMdmCode() == null || "".equals(entity.getMdmCode())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询模版
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(entity.getMdmCode());
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }

        //查询数据源主表
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntities.get(0).getId());
        mdmModuleDbEntity.setDbType("1");
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        mdmModuleDbEntity = mdmModuleDbEntityList.get(0);
        Map<String, Object> queryData = new HashMap<>();
        queryData.put("tableName", mdmModuleDbEntity.getDbName() + "_distribute");//表名
        queryData.put("id", entity.getId());//字段
        List<MdmDistributeVo> datas = mdmModuleDbDao.getServiceByDistributeIdNoCase(queryData);
        List<MdmDistributeVo> returnData = new ArrayList<>();

        //查询分发表
        MdmModuleDistributeEntity mdmModuleDistributeEntity = new MdmModuleDistributeEntity();
        mdmModuleDistributeEntity.setMdmId(mdmModuleEntities.get(0).getId());
        mdmModuleDistributeEntity.setSts("Y");
        List<MdmModuleDistributeEntity> mdmModuleDistributeEntities = mdmModuleDistributeDao.queryBase(mdmModuleDistributeEntity);
        if (datas != null && datas.size() > 0) {
            if (mdmModuleDistributeEntities != null && mdmModuleDistributeEntities.size() > 0) {
                for (int i = 0; i < mdmModuleDistributeEntities.size(); i++) {
                    boolean flag = false;
                    for (int i1 = 0; i1 < datas.size(); i1++) {
                        if (datas.get(i1).getAppId().equals(mdmModuleDistributeEntities.get(i).getAppId())) {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag) {
                        MdmDistributeVo mdmDistributeVo = new MdmDistributeVo();
                        mdmDistributeVo.setAppId(mdmModuleDistributeEntities.get(i).getAppId());
                        mdmDistributeVo.setStatus("4");
                        mdmDistributeVo.setMsg("未发送");
                        returnData.add(mdmDistributeVo);
                    }
                }
            }
            returnData.addAll(datas);
        } else {
            if (mdmModuleDistributeEntities != null && mdmModuleDistributeEntities.size() > 0) {
                for (int i = 0; i < mdmModuleDistributeEntities.size(); i++) {
                    MdmDistributeVo mdmDistributeVo = new MdmDistributeVo();
                    mdmDistributeVo.setAppId(mdmModuleDistributeEntities.get(i).getAppId());
                    mdmDistributeVo.setStatus("4");
                    mdmDistributeVo.setMsg("未发送");
                    returnData.add(mdmDistributeVo);
                }
            }
        }
        return BaseResult.getSuccessMessageEntity("查询数据成功", returnData);
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 查询数据（list 或者 分页）
     * @Date 1:33 下午 2023/7/12
     **/
    @Override
    public JsonResultEntity queryTemplateData(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        //校验是否有servecr传参
        if (!checkStr(entity.getTableName())) {
            return BaseResult.getFailureMessageEntity("请先传递服务名");
        }
        if (!checkStr(entity.getValue())) {
            return BaseResult.getFailureMessageEntity("请先传递存储字段");
        }
        if (!checkStr(entity.getLabel())) {
            return BaseResult.getFailureMessageEntity("请先传递显示字段");
        }
        if (entity.getPageNum() != null && entity.getPageSize() != null) {
            PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
            List<HashMap<String, Object>> mapList = mdmModuleDao.querySelectData(entity);
            PageInfo pageInfo = new PageInfo(mapList);
            return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
        } else {
            List<HashMap<String, Object>> mapList = mdmModuleDao.querySelectData(entity);
            return BaseResult.getSuccessMessageEntity("查询数据成功", mapList);
        }
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 业务数据树形结构，数据查询
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShowTreeData(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        //if (entity.getTableName() == null || "".equals(entity.getTableName())) {
        //    return BaseResult.getFailureMessageEntity("系统错误");
        //}
        if (entity.getLabel() == null || "".equals(entity.getLabel())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getUpId() == null || "".equals(entity.getUpId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getMdmCode() != null && !"".equals(entity.getMdmCode())) {
            //查询模版
            MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
            mdmModuleEntity.setMdmCode(entity.getMdmCode());
            mdmModuleEntity.setSts("Y");
            List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
            if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
                return BaseResult.getFailureMessageEntity("系统错误");
            }
            //查询数据源主表
            MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
            mdmModuleDbEntity.setMdmId(mdmModuleEntities.get(0).getId());
            mdmModuleDbEntity.setDbType("1");
            mdmModuleDbEntity.setSts("Y");
            List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
            if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
                return BaseResult.getFailureMessageEntity("系统错误");
            }
            mdmModuleDbEntity = mdmModuleDbEntityList.get(0);
            entity.setTableName(mdmModuleDbEntity.getDbName());
        }


        if (checkStr(entity.getId())) {
            if (!checkStr(entity.getValue())) {
                return BaseResult.getFailureMessageEntity("请先传递存储字段");
            }
            if (entity.getId().contains(",")) {
                String[] strArray = entity.getId().split(",");  // 使用逗号和空格作为分隔符
                entity.setIds(strArray);
                List<HashMap<String, Object>> mapList = mdmModuleDao.queryTemplateDataMore(entity);
                if (mapList == null || mapList.size() == 0) {
                    List<HashMap<String, Object>> returnList = new ArrayList<>();
                    return BaseResult.getSuccessMessageEntity("查询数据成功", returnList);
                }
                List<HashMap<String, Object>> returnList = gettochilder(strArray, 0, mapList);
                return BaseResult.getSuccessMessageEntity("查询数据成功", returnList);
            } else {
                HashMap<String, Object> mapList = mdmModuleDao.queryTemplateDataOne(entity);
                if (mapList == null || mapList.size() == 0) {
                    List<HashMap<String, Object>> returnList = new ArrayList<>();
                    return BaseResult.getSuccessMessageEntity("查询数据成功", returnList);
                }
                List<HashMap<String, Object>> returnList = new ArrayList<>();
                returnList.add(mapList);
                return BaseResult.getSuccessMessageEntity("查询数据成功", returnList);
            }
        } else {
            List<HashMap<String, Object>> mapList = mdmModuleDao.queryDataAll(entity);
            List<HashMap<String, Object>> returnList = new ArrayList<>();

            if (mapList != null && mapList.size() > 0) {
                for (int i = 0; i < mapList.size(); i++) {
                    //默认为根
                    if (mapList.get(i).get(entity.getUpId()) == null || "".equals(mapList.get(i).get(entity.getUpId()))) {
                        List<HashMap<String, Object>> children = getchilder(mapList.get(i).get("qsdfg").toString(), mapList, entity);
                        HashMap<String, Object> re = new HashMap<>();
                        re.put("id", mapList.get(i).get("qsdfg"));
                        re.put("label", mapList.get(i).get(entity.getLabel()));
                        re.put("upID", mapList.get(i).get(entity.getUpId()));
                        if (children != null && children.size() > 0) {
                            re.put("children", children);
                        }
                        returnList.add(re);
                    }
                }
            }
            return BaseResult.getSuccessMessageEntity("查询数据成功", returnList);
        }
    }

    private List<HashMap<String, Object>> gettochilder(String[] strArray, int i, List<HashMap<String, Object>> mapList) {
        List<HashMap<String, Object>> maps = new ArrayList<>();
        for (int i1 = 0; i1 < mapList.size(); i1++) {
            if (strArray[i].equals(mapList.get(i1).get("id").toString())) {
                if (strArray.length >= (i + 2)) {
                    mapList.get(i1).put("children", gettochilder(strArray, i + 1, mapList));
                }
                maps.add(mapList.get(i1));
                break;
            }
        }
        return maps;
    }

    private HashMap<String, Object> getFathers(List<HashMap<String, Object>> mapListAll, HashMap<String, Object> mapList, MdmDto entity) {
        if (mapList.get("upID") == null) {
            return mapList;
        }
        HashMap<String, Object> retList = new HashMap<>();
        if (mapListAll != null && mapListAll.size() > 0) {
            for (int i = 0; i < mapListAll.size(); i++) {
                //等于上级id的时候
                if (mapListAll.get(i).get("qsdfg").equals(mapList.get("upID"))) {
                    retList.put("id", mapListAll.get(i).get("qsdfg"));
                    retList.put("label", mapListAll.get(i).get(entity.getLabel()));
                    retList.put("upID", mapListAll.get(i).get(entity.getUpId()));
                    List<HashMap<String, Object>> returnList = new ArrayList<>();
                    returnList.add(mapList);
                    retList.put("children", returnList);
                    break;
                }
            }
        }
        HashMap<String, Object> a = getFathers(mapListAll, retList, entity);
        return a;
    }

    private List<HashMap<String, Object>> getchilder(String stringObjectHashMap, List<HashMap<String, Object>> mapList, MdmDto entity) {
        List<HashMap<String, Object>> returnList = new ArrayList<>();
        if (mapList != null && mapList.size() > 0) {
            for (int i = 0; i < mapList.size(); i++) {
                //等于上级id的时候
                if (stringObjectHashMap.equals(mapList.get(i).get(entity.getUpId()))) {
                    List<HashMap<String, Object>> children = getchilder(mapList.get(i).get(entity.getUpId()) + "," + mapList.get(i).get("qsdfg"), mapList, entity);
                    HashMap<String, Object> re = new HashMap<>();
                    re.put("id", mapList.get(i).get("qsdfg"));
                    re.put("label", mapList.get(i).get(entity.getLabel()));
                    re.put("upID", mapList.get(i).get(entity.getUpId()));
                    if (children != null && children.size() > 0) {
                        re.put("children", children);
                    }
                    returnList.add(re);
                }
            }
        }
        return returnList;
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据详情 区分类型 新增、修改、查看
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShowDetails(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getMdmCode() == null || "".equals(entity.getMdmCode())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getShowType() == null || "".equals(entity.getShowType())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询模版
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(entity.getMdmCode());
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        MdmDetailViewVo mdmViewVo = new MdmDetailViewVo();
        mdmModuleEntity = mdmModuleEntities.get(0);
        mdmViewVo.setMdmModuleEntity(mdmModuleEntity);

        //查询数据源主表
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询数据源表下面的字段
        MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
        mdmModuleDbFiledsEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbFiledsEntity.setSts("Y");
        List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity);
        if (mdmModuleDbFiledsEntityList == null || mdmModuleDbFiledsEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询字段下的规则
        MdmModuleDbFiledsRuleEntity mdmModuleDbFiledsRuleEntity = new MdmModuleDbFiledsRuleEntity();
        mdmModuleDbFiledsRuleEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbFiledsRuleEntity.setSts("Y");
        List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntityList = mdmModuleDbFiledsRuleDao.queryBase(mdmModuleDbFiledsRuleEntity);
        if (mdmModuleDbFiledsRuleEntityList == null || mdmModuleDbFiledsRuleEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        MdmModuleViewDetailEntity mdmModuleViewDetailEntity = new MdmModuleViewDetailEntity();
        mdmModuleViewDetailEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleViewDetailEntity.setSts("Y");
        mdmModuleViewDetailEntity.setViewType(entity.getShowType());//设置显示字段类型
        List<MdmModuleViewDetailEntity> mdmModuleViewDetailEntityList = mdmModuleViewDetailDao.queryBase(mdmModuleViewDetailEntity);
        //组装数据
        assembleMdmShowDetails(mdmViewVo, mdmModuleDbEntityList, mdmModuleDbFiledsEntityList, mdmModuleDbFiledsRuleEntityList, mdmModuleViewDetailEntityList, entity.getShowType());
        return BaseResult.getSuccessMessageEntity("获取字段成功", mdmViewVo);
    }

    /**
     * @param mdmViewVo                       返回对象
     * @param mdmModuleDbEntityList           数据源表
     * @param mdmModuleDbFiledsEntityList     数据源字段
     * @param mdmModuleDbFiledsRuleEntityList 数据源字段规则
     * @param mdmModuleViewDetailEntityList   数据源显示字段
     * @return void
     * @Author lvleigang
     * @Description 组装显示字段
     * @Date 9:10 上午 2023/11/6
     **/
    private void assembleMdmShowDetails(MdmDetailViewVo mdmViewVo, List<MdmModuleDbEntity> mdmModuleDbEntityList, List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList, List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntityList, List<MdmModuleViewDetailEntity> mdmModuleViewDetailEntityList, String showType) {
        //主数据主表
        MdmModuleDbEntity mainMdmModuleDb = new MdmModuleDbEntity();
        List<MdmModuleDbFiledsEntity> mainMdmModuleDbFileds = new ArrayList<>();
        //主数据子表
        List<MdmModuleDbEntity> sublistMdmModuleDb = new ArrayList<>();

        if (mdmModuleViewDetailEntityList != null && mdmModuleViewDetailEntityList.size() > 0) {
            //先循环数据源表，设置出数据字段
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    //1、主表 2、明细
                    mainMdmModuleDb = mdmModuleDbEntityList.get(i);
                    //循环字段表
                    if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                        for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                            if (mdmModuleDbEntityList.get(i).getId().equals(mdmModuleDbFiledsEntityList.get(i1).getDbId())) {
                                for (int b = 0; b < mdmModuleViewDetailEntityList.size(); b++) {
                                    if (mdmModuleViewDetailEntityList.get(b).getViewFiled().equals(mdmModuleDbFiledsEntityList.get(i1).getId())) {
                                        mainMdmModuleDbFileds.add(mdmModuleDbFiledsEntityList.get(i1));
                                        List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules = new ArrayList<>();
                                        //循环字段属性
                                        if (mdmModuleDbFiledsRuleEntityList != null && mdmModuleDbFiledsRuleEntityList.size() > 0) {
                                            for (int i2 = 0; i2 < mdmModuleDbFiledsRuleEntityList.size(); i2++) {
                                                if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getDbId())
                                                        && mdmModuleDbFiledsEntityList.get(i1).getId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getFiledId())) {
                                                    mdmModuleDbFiledsRules.add(mdmModuleDbFiledsRuleEntityList.get(i2));
                                                }
                                            }
                                        }
                                        mdmModuleDbFiledsEntityList.get(i1).setMdmModuleDbFiledsRules(mdmModuleDbFiledsRules);
                                    }
                                }
                            }
                        }
                    }
                } else if ("2".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    //2、明细
                    sublistMdmModuleDb.add(mdmModuleDbEntityList.get(i));
                    //循环字段表
                    if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
                        List<MdmModuleDbFiledsEntity> sublistMdmModuleDbFileds = new ArrayList<>();
                        for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                            if (mdmModuleDbEntityList.get(i).getId().equals(mdmModuleDbFiledsEntityList.get(i1).getDbId())) {
                                for (int b = 0; b < mdmModuleViewDetailEntityList.size(); b++) {
                                    if (mdmModuleViewDetailEntityList.get(b).getViewFiled().equals(mdmModuleDbFiledsEntityList.get(i1).getId())) {
                                        sublistMdmModuleDbFileds.add(mdmModuleDbFiledsEntityList.get(i1));
                                        List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules = new ArrayList<>();
                                        //循环字段属性
                                        if (mdmModuleDbFiledsRuleEntityList != null && mdmModuleDbFiledsRuleEntityList.size() > 0) {
                                            for (int i2 = 0; i2 < mdmModuleDbFiledsRuleEntityList.size(); i2++) {
                                                if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getDbId())
                                                        && mdmModuleDbFiledsEntityList.get(i1).getId().equals(mdmModuleDbFiledsRuleEntityList.get(i2).getFiledId())) {
                                                    mdmModuleDbFiledsRules.add(mdmModuleDbFiledsRuleEntityList.get(i2));
                                                }
                                            }
                                        }
                                        mdmModuleDbFiledsEntityList.get(i1).setMdmModuleDbFiledsRules(mdmModuleDbFiledsRules);
                                    }
                                }

                            }
                        }
                        mdmModuleDbEntityList.get(i).setSublistMdmModuleDbFileds(sublistMdmModuleDbFileds);
                    }
                }
            }
            mainMdmModuleDb.setSublistMdmModuleDbFileds(mainMdmModuleDbFileds);
            mdmViewVo.setMainMdmModuleDb(mainMdmModuleDb);
            //主数据子表
            List<MdmModuleDbEntity> mdmModuleDb = new ArrayList<>();
            if (sublistMdmModuleDb != null && sublistMdmModuleDb.size() > 0) {
                for (int i = 0; i < sublistMdmModuleDb.size(); i++) {
                    if (sublistMdmModuleDb.get(i).getSublistMdmModuleDbFileds() != null && sublistMdmModuleDb.get(i).getSublistMdmModuleDbFileds().size() > 0) {
                        mdmModuleDb.add(sublistMdmModuleDb.get(i));
                    }
                }
            }
            if ("5".equals(showType)) {
                MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
                mdmModuleDbEntity.setDbName(mainMdmModuleDb.getDbName() + "_distribute");
                mdmModuleDbEntity.setRemark(mainMdmModuleDb.getRemark() + "分发表");
                mdmModuleDbEntity.setDbType("2");
                List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList1 = getDistributeRole();
                mdmModuleDbEntity.setSublistMdmModuleDbFileds(mdmModuleDbFiledsEntityList1);
                mdmModuleDb.add(mdmModuleDbEntity);
            }
            mdmViewVo.setSublistMdmModuleDb(mdmModuleDb);


        } else {
            mdmViewVo.setMainMdmModuleDb(mainMdmModuleDb);
            mdmViewVo.setSublistMdmModuleDb(sublistMdmModuleDb);
        }
    }

    private List<MdmModuleDbFiledsEntity> getDistributeRole() {
        List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = new ArrayList<>();
        //app
        MdmModuleDbFiledsEntity appFiled = new MdmModuleDbFiledsEntity();
        appFiled.setChName("应用");
        appFiled.setEnName("app_id");
        appFiled.setFiledLength("50");
        appFiled.setFiledType("3");
        List<MdmModuleDbFiledsRuleEntity> appRule = new ArrayList<>();
        MdmModuleDbFiledsRuleEntity appRuleTitie = new MdmModuleDbFiledsRuleEntity();
        appRuleTitie.setFormName("optionRuleForm");
        appRuleTitie.setRuleCode("title");
        appRuleTitie.setRuleName("显示名");
        appRuleTitie.setRuleType("2");
        appRuleTitie.setRuleValue("应用");
        MdmModuleDbFiledsRuleEntity appRulerow = new MdmModuleDbFiledsRuleEntity();
        appRulerow.setFormName("optionRuleForm");
        appRulerow.setRuleCode("row");
        appRulerow.setRuleName("宽度");
        appRulerow.setRuleType("2");
        appRulerow.setRuleValue("6");
        MdmModuleDbFiledsRuleEntity appRuletype = new MdmModuleDbFiledsRuleEntity();
        appRuletype.setFormName("optionRuleForm");
        appRuletype.setRuleCode("type");
        appRuletype.setRuleName("数据类型");
        appRuletype.setRuleType("2");
        appRuletype.setRuleValue("select");
        MdmModuleDbFiledsRuleEntity appRulerequired = new MdmModuleDbFiledsRuleEntity();
        appRulerequired.setFormName("optionRuleForm");
        appRulerequired.setRuleCode("required");
        appRulerequired.setRuleName("必填");
        appRulerequired.setRuleType("2");
        MdmModuleDbFiledsRuleEntity appRuleservice = new MdmModuleDbFiledsRuleEntity();
        appRuleservice.setFormName("typeOptionRuleForm");
        appRuleservice.setRuleCode("service");
        appRuleservice.setRuleName("服务名称");
        appRuleservice.setRuleType("2");
        appRuleservice.setRuleValue("sys_application");
        MdmModuleDbFiledsRuleEntity appRulelabel = new MdmModuleDbFiledsRuleEntity();
        appRulelabel.setFormName("typeOptionRuleForm");
        appRulelabel.setRuleCode("label");
        appRulelabel.setRuleName("label");
        appRulelabel.setRuleType("2");
        appRulelabel.setRuleValue("name");
        MdmModuleDbFiledsRuleEntity appRulevalue = new MdmModuleDbFiledsRuleEntity();
        appRulevalue.setFormName("typeOptionRuleForm");
        appRulevalue.setRuleCode("value");
        appRulevalue.setRuleName("value");
        appRulevalue.setRuleType("2");
        appRulevalue.setRuleValue("id");
        appRule.add(appRulevalue);
        appRule.add(appRulelabel);
        appRule.add(appRuleservice);
        appRule.add(appRulerequired);
        appRule.add(appRuletype);
        appRule.add(appRulerow);
        appRule.add(appRuleTitie);
        appFiled.setMdmModuleDbFiledsRules(appRule);
        mdmModuleDbFiledsEntityList.add(appFiled);


        //status
        MdmModuleDbFiledsEntity statusFiled = new MdmModuleDbFiledsEntity();
        statusFiled.setChName("状态");
        statusFiled.setEnName("status");
        statusFiled.setFiledLength("50");
        statusFiled.setFiledType("3");
        List<MdmModuleDbFiledsRuleEntity> statusRule = new ArrayList<>();
        MdmModuleDbFiledsRuleEntity statusRuleTitie = new MdmModuleDbFiledsRuleEntity();
        statusRuleTitie.setFormName("optionRuleForm");
        statusRuleTitie.setRuleCode("title");
        statusRuleTitie.setRuleName("显示名");
        statusRuleTitie.setRuleType("2");
        statusRuleTitie.setRuleValue("状态");
        MdmModuleDbFiledsRuleEntity statusRulerow = new MdmModuleDbFiledsRuleEntity();
        statusRulerow.setFormName("optionRuleForm");
        statusRulerow.setRuleCode("row");
        statusRulerow.setRuleName("宽度");
        statusRulerow.setRuleType("2");
        statusRulerow.setRuleValue("6");
        MdmModuleDbFiledsRuleEntity statusRuletype = new MdmModuleDbFiledsRuleEntity();
        statusRuletype.setFormName("optionRuleForm");
        statusRuletype.setRuleCode("type");
        statusRuletype.setRuleName("数据类型");
        statusRuletype.setRuleType("2");
        statusRuletype.setRuleValue("input");
        MdmModuleDbFiledsRuleEntity statusRulerequired = new MdmModuleDbFiledsRuleEntity();
        statusRulerequired.setFormName("optionRuleForm");
        statusRulerequired.setRuleCode("required");
        statusRulerequired.setRuleName("必填");
        statusRulerequired.setRuleType("2");
        statusRule.add(statusRulerequired);
        statusRule.add(statusRuletype);
        statusRule.add(statusRulerow);
        statusRule.add(statusRuleTitie);
        statusFiled.setMdmModuleDbFiledsRules(statusRule);
        mdmModuleDbFiledsEntityList.add(statusFiled);


        //msg
        MdmModuleDbFiledsEntity msgFiled = new MdmModuleDbFiledsEntity();
        msgFiled.setChName("描述");
        msgFiled.setEnName("msg");
        msgFiled.setFiledLength("200");
        msgFiled.setFiledType("3");
        List<MdmModuleDbFiledsRuleEntity> msgRule = new ArrayList<>();
        MdmModuleDbFiledsRuleEntity msgRuleTitie = new MdmModuleDbFiledsRuleEntity();
        msgRuleTitie.setFormName("optionRuleForm");
        msgRuleTitie.setRuleCode("title");
        msgRuleTitie.setRuleName("显示名");
        msgRuleTitie.setRuleType("2");
        msgRuleTitie.setRuleValue("描述");
        MdmModuleDbFiledsRuleEntity msgRulerow = new MdmModuleDbFiledsRuleEntity();
        msgRulerow.setFormName("optionRuleForm");
        msgRulerow.setRuleCode("row");
        msgRulerow.setRuleName("宽度");
        msgRulerow.setRuleType("2");
        msgRulerow.setRuleValue("6");
        MdmModuleDbFiledsRuleEntity msgRuletype = new MdmModuleDbFiledsRuleEntity();
        msgRuletype.setFormName("optionRuleForm");
        msgRuletype.setRuleCode("type");
        msgRuletype.setRuleName("数据类型");
        msgRuletype.setRuleType("2");
        msgRuletype.setRuleValue("input");
        MdmModuleDbFiledsRuleEntity msgRulerequired = new MdmModuleDbFiledsRuleEntity();
        msgRulerequired.setFormName("optionRuleForm");
        msgRulerequired.setRuleCode("required");
        msgRulerequired.setRuleName("必填");
        msgRulerequired.setRuleType("2");
        msgRule.add(msgRulerequired);
        msgRule.add(msgRuletype);
        msgRule.add(msgRulerow);
        msgRule.add(msgRuleTitie);
        msgFiled.setMdmModuleDbFiledsRules(msgRule);
        mdmModuleDbFiledsEntityList.add(msgFiled);
        return mdmModuleDbFiledsEntityList;
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 查询数据（list 或者 分页）
     * @Date 1:33 下午 2023/7/12
     **/
    @Override
    public JsonResultEntity queryMdmOptionData(JSONObject object) {
        ModuleDto entity = getData("jsonStr", object, ModuleDto.class);
        //校验是否有servecr传参
        if (!checkStr(entity.getService())) {
            return BaseResult.getFailureMessageEntity("请先传递服务名");
        }
        if (!checkStr(entity.getValue())) {
            return BaseResult.getFailureMessageEntity("请先传递存储字段");
        }
        if (!checkStr(entity.getLabel())) {
            return BaseResult.getFailureMessageEntity("请先传递显示字段");
        }
        //查询数据源主表
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setId(entity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        entity.setTableName(mdmModuleDbEntityList.get(0).getDbName());
        if (entity.getPageNum() != null && entity.getPageSize() != null) {
            PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
            List<HashMap<String, Object>> mapList = mdmModuleDao.queryTemplateData(entity);
            PageInfo pageInfo = new PageInfo(mapList);
            return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
        } else {
            List<HashMap<String, Object>> mapList = mdmModuleDao.queryTemplateData(entity);
            return BaseResult.getSuccessMessageEntity("查询数据成功", mapList);
        }
    }

    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据详情数据 区分类型 新增、修改、查看
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity queryMdmShowDetailsData(JSONObject object) {
        MdmDto entity = getData("jsonStr", object, MdmDto.class);
        if (entity == null) {
            return BaseResult.getFailureMessageEntity("参数不允许为空");
        }
        if (entity.getMdmCode() == null || "".equals(entity.getMdmCode())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        if (entity.getId() == null || "".equals(entity.getId())) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        //查询模版
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(entity.getMdmCode());
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        mdmModuleEntity = mdmModuleEntities.get(0);
        //查询数据源主表
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        String tablename = null;
        JSONObject jsonObject = new JSONObject();
        for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
            //查询数据
            Map<String, Object> queryData = new HashMap<>();
            queryData.put("tableName", mdmModuleDbEntityList.get(i).getDbName());//表名
            if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                queryData.put("detailFlag", false);//是否明细
                queryData.put("id", entity.getId());//字段
                HashMap<String, Object> datas = mdmModuleDbDao.getServiceDataById(queryData);
                jsonObject.put(mdmModuleDbEntityList.get(i).getDbName(), datas);
                tablename = mdmModuleDbEntityList.get(i).getDbName() + "_distribute";
            } else {
                queryData.put("detailFlag", true);//是否明细
                queryData.put("id", entity.getId());//字段
                List<HashMap<String, Object>> datas = mdmModuleDbDao.getServiceByFormmainId(queryData);
                jsonObject.put(mdmModuleDbEntityList.get(i).getDbName(), datas);
            }
        }
        if (tablename != null && !"".equals(tablename)) {
            Map<String, Object> queryData = new HashMap<>();
            queryData.put("tableName", tablename);//表名
            queryData.put("id", entity.getId());//字段
            List<HashMap<String, Object>> datas = mdmModuleDbDao.getServiceByDistributeId(queryData);
            jsonObject.put(tablename, datas);
        }


        return BaseResult.getSuccessMessageEntity("获取数据成功", jsonObject);
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据详情数据修改
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity updateMdmShowDetailsData(JSONObject object) {
        JSONObject jsonObject = getstrObj("jsonStr", object);
        //校验是否有servecr传参
        if (!checkData(jsonObject, "mdmCode")) {
            return BaseResult.getFailureMessageEntity("请先传递服务名");
        }
        if (!checkData(jsonObject, "data")) {
            return BaseResult.getFailureMessageEntity("请先传递要修改的数据");
        }
        JSONObject saveData = jsonObject.getJSONObject("data");
        //校验唯一
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(jsonObject.getInteger("mdmCode"));
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        mdmModuleEntity = mdmModuleEntities.get(0);
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        String res = checkDataOnly(jsonObject.getInteger("mdmCode"), saveData, true, mdmModuleEntity, mdmModuleDbEntityList);

        if (res == null || "".equals(res)) {
            return BaseResult.getSuccessMessageEntity("修改数据成功");
        } else {
            return BaseResult.getFailureMessageEntity(res);
        }
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据详情数据新增
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity saveMdmShowDetailsData(JSONObject object) {
        JSONObject jsonObject = getstrObj("jsonStr", object);
        //校验是否有servecr传参
        if (!checkData(jsonObject, "mdmCode")) {
            return BaseResult.getFailureMessageEntity("请先传递服务名");
        }
        if (!checkData(jsonObject, "data")) {
            return BaseResult.getFailureMessageEntity("请先传递要修改的数据");
        }
        JSONObject saveData = jsonObject.getJSONObject("data");
        //校验唯一
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(jsonObject.getInteger("mdmCode"));
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        mdmModuleEntity = mdmModuleEntities.get(0);
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        String res = checkDataOnly(jsonObject.getInteger("mdmCode"), saveData, false, mdmModuleEntity, mdmModuleDbEntityList);

        if (res == null || "".equals(res)) {
            return BaseResult.getSuccessMessageEntity("保存数据成功");
        } else {
            return BaseResult.getFailureMessageEntity(res);
        }
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 主数据详情数据修改
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity deleteMdmShowDetailsData(JSONObject object) {
        JSONObject jsonObject = getstrObj("jsonStr", object);
        //校验是否有servecr传参
        if (!checkData(jsonObject, "mdmCode")) {
            return BaseResult.getFailureMessageEntity("请先传递服务名");
        }
        if (!checkData(jsonObject, "id")) {
            return BaseResult.getFailureMessageEntity("请先传递要删除的数据");
        }
        //校验唯一
        MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
        mdmModuleEntity.setMdmCode(jsonObject.getInteger("mdmCode"));
        mdmModuleEntity.setSts("Y");
        List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
        if (mdmModuleEntities == null || mdmModuleEntities.size() != 1) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        mdmModuleEntity = mdmModuleEntities.get(0);
        MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
        mdmModuleDbEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbEntity.setSts("Y");
        List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.queryBase(mdmModuleDbEntity);
        if (mdmModuleDbEntityList == null || mdmModuleDbEntityList.size() == 0) {
            return BaseResult.getFailureMessageEntity("系统错误");
        }
        for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
            if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {

                //查询视图，如果树形，删除下级及子集
                //查询展示类型
                MdmModuleViewEntity mdmModuleViewEntity = new MdmModuleViewEntity();
                mdmModuleViewEntity.setMdmId(mdmModuleEntity.getId());
                mdmModuleViewEntity.setSts("Y");
                List<MdmModuleViewEntity> moduleViewEntityList = mdmModuleViewDao.queryBase(mdmModuleViewEntity);
                if (moduleViewEntityList == null || moduleViewEntityList.size() != 1) {
                    return BaseResult.getFailureMessageEntity("系统错误");
                }
                mdmModuleViewEntity = moduleViewEntityList.get(0);


                //删除自己
                FormmainDeleteDto formmainDeleteDto = new FormmainDeleteDto();
                formmainDeleteDto.setId(jsonObject.getString("id"));
                formmainDeleteDto.setLoginId(StpUtil.getLoginIdAsString());
                formmainDeleteDto.setTableName(mdmModuleDbEntityList.get(i).getDbName());
                if (mdmModuleViewEntity != null && mdmModuleViewEntity.getViewName() != null && "1".equals(mdmModuleViewEntity.getViewName()) &&
                        mdmModuleViewEntity.getUpIdFiled() != null && !"".equals(mdmModuleViewEntity.getUpIdFiled())) {
                    formmainDeleteDto.setUpIdFiled(mdmModuleViewEntity.getUpIdFiled());

                    Map<String, Object> queryData = new HashMap<>();
                    queryData.put("tableName", mdmModuleDbEntityList.get(i).getDbName());//表名
                    queryData.put("detailFlag", false);//是否明细
                    queryData.put("id", jsonObject.getString("id"));//字段
                    HashMap<String, Object> datas = mdmModuleDbDao.getServiceDataById(queryData);
                    String upValue = null;
                    if (datas != null && datas.get(mdmModuleViewEntity.getUpIdFiled()) != null) {
                        upValue = datas.get(mdmModuleViewEntity.getUpIdFiled()).toString();
                    }
                    if (upValue != null) {
                        formmainDeleteDto.setUpIdFiledValue(upValue + "," + jsonObject.getString("id"));
                    } else {
                        formmainDeleteDto.setUpIdFiledValue(jsonObject.getString("id"));
                    }
                    mdmModuleDao.deleteChilder(formmainDeleteDto);
                }
                mdmModuleDao.deleteTemplateById(formmainDeleteDto);

            } else {
                //删除明细
                FormmainDeleteDto formmainDeleteDto = new FormmainDeleteDto();
                formmainDeleteDto.setFormmain_id(jsonObject.getString("id"));
                formmainDeleteDto.setLoginId(StpUtil.getLoginIdAsString());
                formmainDeleteDto.setTableName(mdmModuleDbEntityList.get(i).getDbName());
                mdmModuleDao.deleteTemplateById(formmainDeleteDto);
            }
        }
        return BaseResult.getSuccessMessageEntity("删除数据成功");
    }


    /**
     * @param object
     * @return com.hzya.frame.web.entity.JsonResultEntity
     * @Author lvleigang
     * @Description 处理分发数据
     * @Date 9:40 上午 2023/10/18
     **/
    @Override
    public JsonResultEntity doMdmDistribute(JSONObject object) {
        JSONObject jsonObject = getstrObj("jsonStr", object);
        //校验是否有servecr传参
        if (!checkData(jsonObject, "mdmCode")) {
            return BaseResult.getFailureMessageEntity("请先传递服务名");
        }
        if (!checkData(jsonObject, "id")) {
            return BaseResult.getFailureMessageEntity("请先传递要删除的数据");
        }
        if (!checkData(jsonObject, "appID")) {
            return BaseResult.getFailureMessageEntity("请先传递要删除的数据");
        }
        if (!checkData(jsonObject, "dataType")) {
            return BaseResult.getFailureMessageEntity("请先传递要删除的数据");
        }
        if("2".equals(jsonObject.getString("dataType"))){
            boolean flag = false;
            //1、根据服务名查询分发数据
            MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
            mdmModuleEntity.setMdmCode(jsonObject.getInteger("mdmCode"));
            mdmModuleEntity.setSts("Y");
            List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
            if (mdmModuleEntities != null && mdmModuleEntities.size() == 1) {
                MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
                mdmModuleDbEntity.setMdmId(mdmModuleEntities.get(0).getId());
                mdmModuleDbEntity.setDbType("1");
                mdmModuleDbEntity.setSts("Y");
                List<MdmModuleDbEntity> mdmModuleDbEntities =  mdmModuleDbDao.queryBase(mdmModuleDbEntity);
                if (mdmModuleDbEntities != null && mdmModuleDbEntities.size() == 1) {
                    mdmModuleDbEntity = mdmModuleDbEntities.get(0);
                }
                MdmModuleDistributeEntity mdmModuleDistributeEntity = new MdmModuleDistributeEntity();
                mdmModuleDistributeEntity.setAppId(jsonObject.getString("appID"));
                mdmModuleDistributeEntity.setMdmId(mdmModuleEntities.get(0).getId());
                List<MdmModuleDistributeEntity> mdmModuleDistributeEntities = mdmModuleDistributeDao.queryBase(mdmModuleDistributeEntity);
                if (mdmModuleDistributeEntities != null && mdmModuleDistributeEntities.size() == 1) {
                    if (mdmModuleDistributeEntities.get(0).getAddType() != null && "1".equals(mdmModuleDistributeEntities.get(0).getAddType())) {
                        //2、查找插件
                        if (mdmModuleDistributeEntities.get(0).getAddPlug() != null && !"".equals(mdmModuleDistributeEntities.get(0).getAddPlug())) {
                            //2、查找插件
                            SysApplicationPluginEntity sysApplicationPluginEntity = sysApplicationPluginDao.get(mdmModuleDistributeEntities.get(0).getAddPlug());
                            if(sysApplicationPluginEntity.getPluginCode() != null && !"".equals(sysApplicationPluginEntity.getPluginCode())){
                                //3、调用插件
                                PluginBaseEntity pluginBaseEntity = PluginUtils.getPluginsById(sysApplicationPluginEntity.getPluginCode());
                                try {
                                    JsonResultEntity s = pluginBaseEntity.executeBusiness(jsonObject);
                                    flag = true;
                                } catch (Exception e) {
                                    logger.error("插件处理失败"+e.getMessage());
                                }
                            }
                        }
                    } else {
                        //TODO 连线
                        flag = true;
                    }
                }
                if(mdmModuleDbEntity.getDbName()!= null && !"".equals(mdmModuleDbEntity.getDbName())) {
                    MdmDistributeEntity mdmDistributeEntity = new MdmDistributeEntity();
                    mdmDistributeEntity.setCreate();
                    mdmDistributeEntity.setTableName(mdmModuleDbEntity.getDbName()+"_distribute");
                    mdmDistributeEntity.setFormmainId(jsonObject.getString("id"));
                    mdmDistributeEntity.setAppId(jsonObject.getString("appID"));
                    mdmDistributeEntity.setStatus("1");
                    mdmDistributeEntity.setMsg("发送成功");
                    if (!flag) {
                        mdmDistributeEntity.setStatus("3");
                        mdmDistributeEntity.setMsg("发送失败");
                    }
                    mdmModuleDao.saveDistribute(mdmDistributeEntity);
                    return BaseResult.getSuccessMessageEntity("下发数据成功");

                }else {
                    return BaseResult.getFailureMessageEntity("系统错误");
                }
            }else {
                return BaseResult.getFailureMessageEntity("系统错误");
            }
        }else {
            if (!checkData(jsonObject, "distributeID")) {
                return BaseResult.getFailureMessageEntity("请先传递分发数据");
            }
            boolean flag = false;
            //1、根据服务名查询分发数据
            MdmModuleEntity mdmModuleEntity = new MdmModuleEntity();
            mdmModuleEntity.setMdmCode(jsonObject.getInteger("mdmCode"));
            mdmModuleEntity.setSts("Y");
            List<MdmModuleEntity> mdmModuleEntities = mdmModuleDao.queryBase(mdmModuleEntity);
            if (mdmModuleEntities != null && mdmModuleEntities.size() == 1) {
                MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
                mdmModuleDbEntity.setMdmId(mdmModuleEntities.get(0).getId());
                mdmModuleDbEntity.setDbType("1");
                mdmModuleDbEntity.setSts("Y");
                List<MdmModuleDbEntity> mdmModuleDbEntities =  mdmModuleDbDao.queryBase(mdmModuleDbEntity);
                if (mdmModuleDbEntities != null && mdmModuleDbEntities.size() == 1) {
                    mdmModuleDbEntity = mdmModuleDbEntities.get(0);
                }
                MdmModuleDistributeEntity mdmModuleDistributeEntity = new MdmModuleDistributeEntity();
                mdmModuleDistributeEntity.setAppId(jsonObject.getString("appID"));
                mdmModuleDistributeEntity.setMdmId(mdmModuleEntities.get(0).getId());
                List<MdmModuleDistributeEntity> mdmModuleDistributeEntities = mdmModuleDistributeDao.queryBase(mdmModuleDistributeEntity);
                if (mdmModuleDistributeEntities != null && mdmModuleDistributeEntities.size() == 1) {
                    if (mdmModuleDistributeEntities.get(0).getDeleteType() != null && "1".equals(mdmModuleDistributeEntities.get(0).getDeleteType())) {
                        //2、查找插件
                        if (mdmModuleDistributeEntities.get(0).getDeletePlug() != null && !"".equals(mdmModuleDistributeEntities.get(0).getDeletePlug())) {
                            //2、查找插件
                            SysApplicationPluginEntity sysApplicationPluginEntity = sysApplicationPluginDao.get(mdmModuleDistributeEntities.get(0).getDeletePlug());
                            if(sysApplicationPluginEntity.getPluginCode() != null && !"".equals(sysApplicationPluginEntity.getPluginCode())){
                                //3、调用插件
                                PluginBaseEntity pluginBaseEntity = PluginUtils.getPluginsById(sysApplicationPluginEntity.getPluginCode());
                                try {
                                    JsonResultEntity s = pluginBaseEntity.executeBusiness(jsonObject);
                                    flag = true;
                                } catch (Exception e) {
                                    logger.error("插件处理失败"+e.getMessage());
                                }
                            }
                        }
                    } else {
                        //TODO 连线
                        flag = true;
                    }
                }
                if(mdmModuleDbEntity.getDbName()!= null && !"".equals(mdmModuleDbEntity.getDbName())) {
                    //删除数据
                    MdmDistributeEntity mdmDistributeEntity = new MdmDistributeEntity();
                    mdmDistributeEntity.setId(jsonObject.getString("distributeID"));
                    mdmDistributeEntity.setTableName(mdmModuleDbEntity.getDbName()+"_distribute");
                    mdmDistributeEntity.setFormmainId(jsonObject.getString("id"));
                    mdmDistributeEntity.setAppId(jsonObject.getString("appID"));
                    mdmDistributeEntity.setStatus("1");
                    mdmDistributeEntity.setMsg("删除成功");
                    if (!flag) {
                        mdmDistributeEntity.setStatus("3");
                        mdmDistributeEntity.setMsg("删除失败");
                    }
                    mdmModuleDao.updateDistribute(mdmDistributeEntity);
                    return BaseResult.getSuccessMessageEntity("删除数据成功");

                }else {
                    return BaseResult.getFailureMessageEntity("系统错误");
                }
            }else {
                return BaseResult.getFailureMessageEntity("系统错误");
            }
        }

    }

    /**
     * @param mdmCode
     * @param saveData
     * @param mdmModuleEntity
     * @param mdmModuleDbEntityList
     * @param flag                  修改 新增
     * @return java.lang.String
     * @Author lvleigang
     * @Description 校验数据
     * @Date 11:20 上午 2023/11/6
     **/
    private String checkDataOnly(Integer mdmCode, JSONObject saveData, boolean flag, MdmModuleEntity mdmModuleEntity, List<MdmModuleDbEntity> mdmModuleDbEntityList) {
        StringBuffer str = new StringBuffer();

        //查询字段
        //查询字段下的必填规则
        MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
        mdmModuleDbFiledsEntity.setMdmId(mdmModuleEntity.getId());
        mdmModuleDbFiledsEntity.setSts("Y");
        mdmModuleDbFiledsEntity.setRoletype("required");
        mdmModuleDbFiledsEntity.setRoleValue("true");
        List<MdmModuleDbFiledsEntity> mdmModuleDbFiledsEntityList = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity);

        if (mdmModuleDbFiledsEntityList != null && mdmModuleDbFiledsEntityList.size() > 0) {
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    JSONObject jsonObject = saveData.getJSONObject(mdmModuleDbEntityList.get(i).getDbName());
                    for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                        if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbEntityList.get(i).getId())) {
                            if (jsonObject.get(mdmModuleDbFiledsEntityList.get(i1).getEnName()) == null || "".equals(jsonObject.getString(mdmModuleDbFiledsEntityList.get(i1).getEnName()))) {
                                if (str.toString() != null && !"".equals(str.toString())) {
                                    str.append("；");
                                }
                                str.append(mdmModuleDbEntityList.get(i).getRemark() + "的" + mdmModuleDbFiledsEntityList.get(i1).getChName() + "不为空");
                            }
                        }
                    }
                } else {
                    JSONArray jsonArray = saveData.getJSONArray(mdmModuleDbEntityList.get(i).getDbName());
                    if (jsonArray != null && jsonArray.size() > 0) {
                        for (int i1 = 0; i1 < mdmModuleDbFiledsEntityList.size(); i1++) {
                            if (mdmModuleDbFiledsEntityList.get(i1).getDbId().equals(mdmModuleDbEntityList.get(i).getId())) {
                                for (int i2 = 0; i2 < jsonArray.size(); i2++) {
                                    JSONObject jsonObject = jsonArray.getJSONObject(i2);
                                    if (jsonObject.get(mdmModuleDbFiledsEntityList.get(i1).getEnName()) == null || "".equals(jsonObject.getString(mdmModuleDbFiledsEntityList.get(i1).getEnName()))) {
                                        if (str.toString() != null && !"".equals(str.toString())) {
                                            str.append("；");
                                        }
                                        str.append(mdmModuleDbEntityList.get(i).getRemark() + "的" + mdmModuleDbFiledsEntityList.get(i1).getChName() + "不为空");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (str == null || "".equals(str.toString())) {
            //校验数据
            MdmModuleDbFiledsEntity onlyFiledsEntity = new MdmModuleDbFiledsEntity();
            onlyFiledsEntity.setMdmId(mdmModuleEntity.getId());
            onlyFiledsEntity.setSts("Y");
            onlyFiledsEntity.setRoletype("fieldsSole");
            onlyFiledsEntity.setRoleValue("true");

            List<MdmModuleDbFiledsEntity> onlyEntityList = mdmModuleDbFiledsDao.queryBase(onlyFiledsEntity);

            if (onlyEntityList != null && onlyEntityList.size() > 0) {
                for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                    if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                        JSONObject jsonObject = saveData.getJSONObject(mdmModuleDbEntityList.get(i).getDbName());
                        for (int i1 = 0; i1 < onlyEntityList.size(); i1++) {
                            if (onlyEntityList.get(i1).getDbId().equals(mdmModuleDbEntityList.get(i).getId())) {
                                //校验唯一
                                Map<String, String> map = new HashMap<>();
                                map.put("tableName", mdmModuleDbEntityList.get(i).getDbName());
                                if (flag) {
                                    map.put("id", jsonObject.getString("id"));
                                }
                                map.put("filedName", onlyEntityList.get(i1).getEnName());
                                map.put("filedValue", jsonObject.getString(onlyEntityList.get(i1).getEnName()));
                                Integer count = mdmModuleDao.checkData(map);
                                if (count > 0) {
                                    if (str.toString() != null && !"".equals(str.toString())) {
                                        str.append("；");
                                    }
                                    str.append(mdmModuleDbEntityList.get(i).getRemark() + "的" + mdmModuleDbFiledsEntityList.get(i1).getChName() + "已存在");
                                }
                            }
                        }
                    } else {
                        JSONArray jsonArray = saveData.getJSONArray(mdmModuleDbEntityList.get(i).getDbName());
                        if (jsonArray != null && jsonArray.size() > 0) {
                            for (int i1 = 0; i1 < onlyEntityList.size(); i1++) {
                                if (onlyEntityList.get(i1).getDbId().equals(mdmModuleDbEntityList.get(i).getId())) {
                                    for (int i2 = 0; i2 < jsonArray.size(); i2++) {
                                        JSONObject jsonObject = jsonArray.getJSONObject(i2);

                                        //校验唯一
                                        Map<String, String> map = new HashMap<>();
                                        map.put("tableName", mdmModuleDbEntityList.get(i).getDbName());
                                        if (flag) {
                                            map.put("id", jsonObject.getString("id"));
                                        }
                                        map.put("filedName", onlyEntityList.get(i1).getEnName());
                                        map.put("filedValue", jsonObject.getString(onlyEntityList.get(i1).getEnName()));
                                        Integer count = mdmModuleDao.checkData(map);
                                        if (count > 0) {
                                            if (str.toString() != null && !"".equals(str.toString())) {
                                                str.append("；");
                                            }
                                            str.append(mdmModuleDbEntityList.get(i).getRemark() + "的" + mdmModuleDbFiledsEntityList.get(i1).getChName() + "已存在");
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }


        //保存数据
        if (str == null || "".equals(str.toString())) {
            String id = UUIDUtils.getUUID();
            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("1".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    JSONObject jsonObject = saveData.getJSONObject(mdmModuleDbEntityList.get(i).getDbName());
                    //保存数据
                    MdmDataDto mdmDataDto = new MdmDataDto();
                    mdmDataDto.setTableName(mdmModuleDbEntityList.get(i).getDbName());
                    MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity1 = new MdmModuleDbFiledsEntity();
                    mdmModuleDbFiledsEntity1.setMdmId(mdmModuleEntity.getId());
                    mdmModuleDbFiledsEntity1.setDbId(mdmModuleDbEntityList.get(i).getId());
                    mdmModuleDbFiledsEntity1.setSts("Y");
                    List<MdmModuleDbFiledsEntity> fileds = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity1);
                    //查询单据规则
                    MdmTableCodeRuleEntity mdmTableCodeRuleEntity = new MdmTableCodeRuleEntity();
                    mdmTableCodeRuleEntity.setMdmId(mdmModuleEntity.getId());
                    mdmTableCodeRuleEntity.setDbId(mdmModuleDbEntityList.get(i).getId());
                    mdmTableCodeRuleEntity.setSts("Y");
                    List<MdmTableCodeRuleEntity> mdmTableCodeRuleEntities = mdmTableCodeRuleDao.queryBase(mdmTableCodeRuleEntity);
                    StringBuffer document_rule = new StringBuffer();
                    Integer document_rule_num = 0;
                    if (mdmTableCodeRuleEntities != null && mdmTableCodeRuleEntities.size() > 0) {
                        for (int i1 = 0; i1 < mdmTableCodeRuleEntities.size(); i1++) {
                            //1、连接符号 2、字符串 3、日期 4、流水号
                            if ("1".equals(mdmTableCodeRuleEntities.get(i1).getDbType())) {
                                document_rule.append("-");
                            } else if ("2".equals(mdmTableCodeRuleEntities.get(i1).getDbType())) {
                                document_rule.append(mdmTableCodeRuleEntities.get(i1).getDbValue());
                            } else if ("3".equals(mdmTableCodeRuleEntities.get(i1).getDbType())) {
                                SimpleDateFormat sdf = new SimpleDateFormat(mdmTableCodeRuleEntities.get(i1).getDbValue());//要转换的时间格式
                                String stra = sdf.format(new Date());
                                document_rule.append(stra);
                            } else if ("4".equals(mdmTableCodeRuleEntities.get(i1).getDbType())) {
                                document_rule_num = mdmTableCodeRuleEntities.get(i1).getDbValue().length();
                            }
                        }
                    }
                    List<MdmDataFiledDto> mdmDataFiledDtos = new ArrayList<>();
                    for (int i1 = 0; i1 < fileds.size(); i1++) {
                        if (jsonObject.get(fileds.get(i1).getEnName()) != null) {
                            MdmDataFiledDto mdmDataFiledDto = new MdmDataFiledDto();
                            mdmDataFiledDto.setFiledsName(fileds.get(i1).getEnName());
                            mdmDataFiledDto.setFiledsValue(jsonObject.getString(fileds.get(i1).getEnName()));
                            mdmDataFiledDtos.add(mdmDataFiledDto);
                        }
                    }
                    MdmDataFiledDto mdmDataFiledDto = new MdmDataFiledDto();
                    mdmDataFiledDto.setFiledsName("logid");
                    mdmDataFiledDto.setFiledsValue(StpUtil.getLoginIdAsString());
                    mdmDataFiledDtos.add(mdmDataFiledDto);
                    mdmDataDto.setMdmDataFiledDtos(mdmDataFiledDtos);
                    if (flag) {
                        mdmDataDto.setId(jsonObject.getString("id"));
                        id = jsonObject.getString("id");
                        int a = mdmModuleDao.updateForm(mdmDataDto);
                    } else {

                        mdmDataDto.setDbType(mdmModuleDbEntityList.get(i).getDbType());
                        mdmDataDto.setDocumentRule(document_rule.toString());
                        mdmDataDto.setDocumentRuleNum(document_rule_num);
                        MdmDataFiledDto ids = new MdmDataFiledDto();
                        ids.setFiledsName("id");
                        ids.setFiledsValue(id);
                        mdmDataFiledDtos.add(ids);
                        mdmDataDto.setMdmDataFiledDtos(mdmDataFiledDtos);
                        int a = mdmModuleDao.saveForm(mdmDataDto);
                    }
                }
            }

            for (int i = 0; i < mdmModuleDbEntityList.size(); i++) {
                if ("2".equals(mdmModuleDbEntityList.get(i).getDbType())) {
                    //删除明细
                    FormmainDeleteDto formmainDeleteDto = new FormmainDeleteDto();
                    formmainDeleteDto.setFormmain_id(id);
                    formmainDeleteDto.setLoginId(StpUtil.getLoginIdAsString());
                    formmainDeleteDto.setTableName(mdmModuleDbEntityList.get(i).getDbName());
                    mdmModuleDao.deleteTemplateById(formmainDeleteDto);

                    JSONArray jsonArray = saveData.getJSONArray(mdmModuleDbEntityList.get(i).getDbName());
                    if (jsonArray != null && jsonArray.size() > 0) {
                        MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity1 = new MdmModuleDbFiledsEntity();
                        mdmModuleDbFiledsEntity1.setMdmId(mdmModuleEntity.getId());
                        mdmModuleDbFiledsEntity1.setDbId(mdmModuleDbEntityList.get(i).getId());
                        mdmModuleDbFiledsEntity1.setSts("Y");
                        List<MdmModuleDbFiledsEntity> fileds = mdmModuleDbFiledsDao.queryBase(mdmModuleDbFiledsEntity1);

                        for (int i2 = 0; i2 < jsonArray.size(); i2++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i2);
                            //保存数据
                            MdmDataDto mdmDataDto = new MdmDataDto();
                            mdmDataDto.setTableName(mdmModuleDbEntityList.get(i).getDbName());
                            List<MdmDataFiledDto> mdmDataFiledDtos = new ArrayList<>();
                            for (int i1 = 0; i1 < fileds.size(); i1++) {
                                MdmDataFiledDto mdmDataFiledDto = new MdmDataFiledDto();
                                mdmDataFiledDto.setFiledsName(fileds.get(i1).getEnName());
                                mdmDataFiledDto.setFiledsValue(jsonObject.getString(fileds.get(i1).getEnName()));
                                mdmDataFiledDtos.add(mdmDataFiledDto);
                            }
                            MdmDataFiledDto mdmDataFiledDto = new MdmDataFiledDto();
                            mdmDataFiledDto.setFiledsName("logid");
                            mdmDataFiledDto.setFiledsValue(StpUtil.getLoginIdAsString());
                            mdmDataFiledDtos.add(mdmDataFiledDto);

                            MdmDataFiledDto formain_id = new MdmDataFiledDto();
                            formain_id.setFiledsName("formmain_id");
                            formain_id.setFiledsValue(id);
                            mdmDataFiledDtos.add(formain_id);

                            mdmDataDto.setMdmDataFiledDtos(mdmDataFiledDtos);
                            if (jsonObject.getString("id") != null) {
                                MdmDataFiledDto sts = new MdmDataFiledDto();
                                sts.setFiledsName("sts");
                                sts.setFiledsValue("Y");
                                mdmDataFiledDtos.add(sts);
                                mdmDataDto.setId(jsonObject.getString("id"));
                                int a = mdmModuleDao.updateForm(mdmDataDto);
                            } else {
                                MdmDataFiledDto ids = new MdmDataFiledDto();
                                ids.setFiledsName("id");
                                ids.setFiledsValue(UUIDUtils.getUUID());
                                mdmDataFiledDtos.add(ids);
                                mdmDataDto.setMdmDataFiledDtos(mdmDataFiledDtos);
                                mdmDataDto.setDbType(mdmModuleDbEntityList.get(i).getDbType());
                                int a = mdmModuleDao.saveForm(mdmDataDto);
                            }
                        }
                    }
                }
            }
        }
        return str.toString();
    }

    /**
     * @param jsonObject
     * @return boolean
     * @Author lvleigang
     * @Description 校验是否有值
     * @Date 2:20 下午 2023/7/10
     **/
    private boolean checkData(JSONObject jsonObject, String key) {
        if (jsonObject != null
                && jsonObject.getString(key) != null
                && !"".equals(jsonObject.getString(key))) {
            return true;
        }
        return false;
    }

    protected <T> T getData(String key, JSONObject jsonObject, Class<T> clz) {
        if (checkStr(jsonObject.getString(key))) {
            return jsonObject.getJSONObject(key).toJavaObject(clz);
        }
        return null;
    }

    /**
     * @param key
     * @param object
     * @return com.alibaba.fastjson.JSONObject
     * @Author lvleigang
     * @Description 获取对象转换成jsonobj
     * @Date 11:51 下午 2023/7/10
     **/
    protected JSONObject getstrObj(String key, JSONObject object) {
        if (checkStr(object.getString(key))) {
            return object.getJSONObject(key);
        }
        return new JSONObject();
    }

    /**
     * @param str
     * @return void
     * @Author lvleigang
     * @Description 校验字符串
     * @Date 11:41 上午 2022/12/7
     **/
    protected Boolean checkStr(String str) {
        Boolean flag = true;
        if (str == null || "".equals(str)) {
            flag = false;
        }
        return flag;
    }

    /**
     * @param str
     * @return void
     * @Author lvleigang
     * @Description 校验字符串
     * @Date 11:41 上午 2022/12/7
     **/
    protected Boolean checkInt(Integer str) {
        Boolean flag = true;
        if (str == null) {
            flag = false;
        }
        return flag;
    }

}
