package com.cm.common.plugin.service.dynamic.impl;

import com.cm.common.base.AbstractService;
import com.cm.common.exception.SaveException;
import com.cm.common.exception.SearchException;
import com.cm.common.plugin.dao.dynamic.IDynamicFormDao;
import com.cm.common.plugin.enums.database.table.ColumnDataTypeEnum;
import com.cm.common.plugin.enums.dynamic.FieldTypeEnum;
import com.cm.common.plugin.pojo.dtos.database.table.TableColumnDTO;
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormDTO;
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormFormShowFieldDTO;
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormListShowFieldDTO;
import com.cm.common.plugin.pojo.vos.database.table.TableColumnVO;
import com.cm.common.plugin.pojo.vos.database.table.TableVO;
import com.cm.common.plugin.pojo.vos.dynamic.DynamicFormFieldVO;
import com.cm.common.plugin.pojo.vos.dynamic.DynamicFormVO;
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
import com.cm.common.plugin.service.dynamic.IDynamicFormService;
import com.cm.common.plugin.service.dynamic.IDynamicTableService;
import com.cm.common.utils.WStringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DynamicFormServiceImpl
 * @Description: 动态表单
 * @Author: WangGeng
 * @Date: 2019/12/2 4:05 下午
 * @Version: 1.0
 **/
@Service
public class DynamicFormServiceImpl extends AbstractService implements IDynamicFormService {

    @Autowired
    private IDynamicFormDao dynamicFormDao;
    @Autowired
    private IDynamicTableService dynamicTableService;
    @Autowired
    private IDataDictionaryService dataDictionaryService;


    @Override
    public void saveDynamicForm(DynamicFormVO dynamicFormVO) throws SaveException {
        saveDynamicFormInfo(dynamicFormVO);
    }

    @Override
    public void updateDynamicForm(DynamicFormVO dynamicFormVO) throws Exception {
        updateDynamicFormInfo(StringUtils.removeStart(dynamicFormVO.getTableName(), IDynamicTableService.DYNAMIC_TABLE_PREFIX), dynamicFormVO);
    }

    @Override
    public List<DynamicFormDTO> listDynamicForm(String tableName) throws SearchException {
        Map<String, Object> params = getHashMap(1);
        params.put("tableName", tableName);
        return dynamicFormDao.listDynamicForm(params);
    }

    @Override
    public List<Map<String, Object>> listListShowField(String tableName) throws SearchException {
        List<DynamicFormDTO> dynamicFormDTOs = listDynamicForm(tableName);
        return listListShowField(dynamicFormDTOs);
    }

    @Override
    public List<Map<String, Object>> listListShowField(List<DynamicFormDTO> dynamicFormDTOs) throws SearchException {
        List<Map<String, Object>> listShowField = new ArrayList<>();
        for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
            if (dynamicFormDTO.getListShow() == 1) {
                Map<String, Object> listShow = new HashMap<>(2);
                listShow.put("fieldName", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
                listShow.put("fieldType", dynamicFormDTO.getFieldType());
                listShowField.add(listShow);
            }
        }
        return listShowField;
    }

    @Override
    public List<String> listFormShowField(String tableName) throws SearchException {
        List<DynamicFormDTO> dynamicFormDTOs = listDynamicForm(tableName);
        List<String> listShowField = new ArrayList<>();
        for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
            if (dynamicFormDTO.getFormShow() == 1) {
                listShowField.add(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
            }
        }
        return listShowField;
    }

    @Override
    public List<DynamicFormListShowFieldDTO> listListShowFieldOfPage(String tableName) throws SearchException {
        List<DynamicFormDTO> dynamicFormDTOs = listDynamicForm(tableName);
        List<DynamicFormListShowFieldDTO> dynamicFormListShowFieldDTOList = new ArrayList<>();
        Integer joinIndex = 0;
        for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
            // 显示字段
            if (dynamicFormDTO.getListShow() == 1) {
                dynamicFormListShowFieldDTOList.add(getDynamicFormListShowFieldDTOByDynamicFormDTO(dynamicFormDTO));
            }
            // 联表字段
            if (isJoinDynamicField(dynamicFormDTO)) {
                dynamicFormListShowFieldDTOList.addAll(listJoinDynamicFormListShowField(dynamicFormDTO, ++joinIndex));
            }
        }
        return dynamicFormListShowFieldDTOList;
    }

    @Override
    public List<DynamicFormFormShowFieldDTO> listFormShowFieldOfPage(String tableName) throws SearchException {
        List<DynamicFormDTO> dynamicFormDTOs = listDynamicForm(tableName);
        List<DynamicFormFormShowFieldDTO> dynamicFormFormShowFieldDTOList = new ArrayList<>();
        for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
            // 显示字段
            if (dynamicFormDTO.getFormShow() == 1) {
                dynamicFormFormShowFieldDTOList.add(getDynamicFormFormShowFieldDTOByDynamicFormDTO(dynamicFormDTO));
            }
        }
        return dynamicFormFormShowFieldDTOList;
    }

    /**
     * 设置动态表单列表 联表 列表显示字段
     *
     * @param dynamicFormDTO
     * @param index          下标
     * @return
     */
    private List<DynamicFormListShowFieldDTO> listJoinDynamicFormListShowField(DynamicFormDTO dynamicFormDTO, int index) {
        List<DynamicFormListShowFieldDTO> dynamicFormListShowFieldDTOList = new ArrayList<>();
        Map<String, Object> params = getHashMap(2);
        params.put("tableName", dynamicFormDTO.getJoinTable());
        params.put("fieldNameList", Arrays.asList(dynamicFormDTO.getJoinTableListShow().split(",")));
        List<DynamicFormDTO> joinDynamicFormDTOs = dynamicFormDao.listDynamicForm(params);
        for (DynamicFormDTO joinDynamicFormDTO : joinDynamicFormDTOs) {
            DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = getDynamicFormListShowFieldDTOByDynamicFormDTO(joinDynamicFormDTO);
            dynamicFormListShowFieldDTO.setFieldName(String.format("%sJt%d", dynamicFormListShowFieldDTO.getFieldName(), index));
            dynamicFormListShowFieldDTO.setFieldExplain(String.format("%s%d", dynamicFormListShowFieldDTO.getFieldExplain(), index));
            dynamicFormListShowFieldDTOList.add(dynamicFormListShowFieldDTO);
        }
        return dynamicFormListShowFieldDTOList;
    }

    /**
     * 设置动态表单的列表字段
     *
     * @param dynamicFormDTO
     * @return
     */
    private DynamicFormListShowFieldDTO getDynamicFormListShowFieldDTOByDynamicFormDTO(DynamicFormDTO dynamicFormDTO) {
        DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = new DynamicFormListShowFieldDTO();
        dynamicFormListShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName());
        dynamicFormListShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain());
        dynamicFormListShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType());
        dynamicFormListShowFieldDTO.setFieldWidth(dynamicFormDTO.getListShowWidth());
        return dynamicFormListShowFieldDTO;
    }

    /**
     * 设置动态表单的表单字段
     *
     * @param dynamicFormDTO
     * @return
     */
    private DynamicFormFormShowFieldDTO getDynamicFormFormShowFieldDTOByDynamicFormDTO(DynamicFormDTO dynamicFormDTO) {
        DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO = new DynamicFormFormShowFieldDTO();
        dynamicFormFormShowFieldDTO.setFieldName(dynamicFormDTO.getFieldName());
        dynamicFormFormShowFieldDTO.setFieldExplain(dynamicFormDTO.getFieldExplain());
        dynamicFormFormShowFieldDTO.setFieldDefault(dynamicFormDTO.getFieldDefault());
        dynamicFormFormShowFieldDTO.setDictionaryId(dynamicFormDTO.getDictionaryId());
        dynamicFormFormShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType());
        dynamicFormFormShowFieldDTO.setVerifyType(dynamicFormDTO.getVerifyType());
        dynamicFormFormShowFieldDTO.setVerifyRegular(dynamicFormDTO.getVerifyRegular());
        dynamicFormFormShowFieldDTO.setJoinTable(dynamicFormDTO.getJoinTable());
        dynamicFormFormShowFieldDTO.setJoinTableField(dynamicFormDTO.getJoinTableField());
        dynamicFormFormShowFieldDTO.setJoinTableFormShow(dynamicFormDTO.getJoinTableFormShow());
        return dynamicFormFormShowFieldDTO;
    }

    @Override
    public List<Map<String, Object>> listJoinTableField(List<DynamicFormDTO> dynamicFormDTOs) throws SearchException {
        List<Map<String, Object>> listShowField = new ArrayList<>();
        for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
            boolean isJoin = isJoinDynamicField(dynamicFormDTO);
            if (isJoin) {
                Map<String, Object> listShow = new HashMap<>(2);
                listShow.put("fieldType", dynamicFormDTO.getFieldType());
                listShow.put("fieldName", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
                listShow.put("joinTable", String.format("%s%s", IDynamicTableService.DYNAMIC_TABLE_PREFIX, WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTable())));
                listShow.put("joinTableField", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTableField()));
                listShow.put("joinTableSort", dynamicFormDTO.getJoinTableSort());
                // 构建连表显示字段
                List<String> listJoinTableListShow = new ArrayList<>();
                if (!StringUtils.isBlank(dynamicFormDTO.getJoinTableListShow())) {
                    String[] joinTableListShowArray = dynamicFormDTO.getJoinTableListShow().split(",");
                    for (String joinTableListShow : joinTableListShowArray) {
                        listJoinTableListShow.add(WStringUtil.lowerUpper2UnderLine(joinTableListShow));
                    }
                } else {
                    listJoinTableListShow.add(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTableListShow()));
                }
                listShow.put("joinTableListShow", listJoinTableListShow);
                listShowField.add(listShow);
            }
        }
        return listShowField;
    }

    @Override
    public void setDynamicFieldData(ModelAndView mv, List<DynamicFormFormShowFieldDTO> dynamicFormFormShowFieldDTOs) {
        List<Map<String, Object>> selectMapList = new ArrayList<>(0);
        List<Map<String, Object>> checkboxMapList = new ArrayList<>(0);
        List<Map<String, Object>> radioMapList = new ArrayList<>(0);
        for (DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO : dynamicFormFormShowFieldDTOs) {
            String dictionaryId = dynamicFormFormShowFieldDTO.getDictionaryId();
            if (StringUtils.equals(FieldTypeEnum.SELECT.getValue(), dynamicFormFormShowFieldDTO.getFieldType())) {
                Map<String, Object> selectMap = new HashMap<>(2);
                selectMap.put("name", dynamicFormFormShowFieldDTO.getFieldName());
                selectMap.put("list", dataDictionaryService.listDictionaryByParentId(dictionaryId));
                selectMapList.add(selectMap);
            } else if (StringUtils.equals(FieldTypeEnum.CHECKBOX.getValue(), dynamicFormFormShowFieldDTO.getFieldType())) {
                Map<String, Object> checkboxMap = new HashMap<>(2);
                checkboxMap.put("name", dynamicFormFormShowFieldDTO.getFieldName());
                checkboxMap.put("list", dataDictionaryService.listDictionaryByParentId(dictionaryId));
                checkboxMapList.add(checkboxMap);
            } else if (StringUtils.equals(FieldTypeEnum.RADIO.getValue(), dynamicFormFormShowFieldDTO.getFieldType())) {
                Map<String, Object> radioMap = new HashMap<>(2);
                radioMap.put("name", dynamicFormFormShowFieldDTO.getFieldName());
                radioMap.put("list", dataDictionaryService.listDictionaryByParentId(dictionaryId));
                radioMapList.add(radioMap);
            }
        }
        mv.addObject("selectMapList", selectMapList);
        mv.addObject("checkboxMapList", checkboxMapList);
        mv.addObject("radioMapList", radioMapList);
    }

    @Override
    public List<String> listDataDictionaryField(List<DynamicFormDTO> dynamicFormDTOs) throws SearchException {
        List<String> dataDictionaryFields = new ArrayList<>();
        for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
            if (StringUtils.equals(dynamicFormDTO.getFieldType(), FieldTypeEnum.SELECT.getValue())
                    || StringUtils.equals(dynamicFormDTO.getFieldType(), FieldTypeEnum.RADIO.getValue())
                    || StringUtils.equals(dynamicFormDTO.getFieldType(), FieldTypeEnum.CHECKBOX.getValue())) {
                dataDictionaryFields.add(dynamicFormDTO.getFieldName());
            }
        }
        return dataDictionaryFields;
    }

    /**
     * 判断是否是动态字段
     *
     * @param dynamicFormDTO
     * @return
     */
    private boolean isJoinDynamicField(DynamicFormDTO dynamicFormDTO) {
        return (StringUtils.equals(FieldTypeEnum.INNER_JOIN.getValue(), dynamicFormDTO.getFieldType())
                || StringUtils.equals(FieldTypeEnum.LEFT_JOIN.getValue(), dynamicFormDTO.getFieldType())
                || StringUtils.equals(FieldTypeEnum.RIGHT_JOIN.getValue(), dynamicFormDTO.getFieldType()));
    }

    /**
     * 保存动态表单信息
     *
     * @param dynamicFormVO
     * @throws Exception
     */
    private void saveDynamicFormInfo(DynamicFormVO dynamicFormVO) throws SaveException {
        List<TableColumnVO> tableColumns = new ArrayList<>();
        for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormVO.getDynamicFormFields()) {
            TableColumnVO tableColumn = getTableColumn(dynamicFormFieldVO);
            tableColumns.add(tableColumn);
        }
        LOG.debug("建表");
        TableVO tableVO = new TableVO();
        tableVO.setTableName(dynamicFormVO.getTableName());
        tableVO.setTableColumns(tableColumns);
        dynamicTableService.createTable(tableVO);
    }

    /**
     * 更新动态表单信息
     */
    private void updateDynamicFormInfo(String tableName, DynamicFormVO dynamicFormVO) throws Exception {
        List<DynamicFormFieldVO> dynamicFormFields = dynamicFormVO.getDynamicFormFields();
        List<TableColumnDTO> tableColumnDTOs = dynamicTableService.listTableColumns(tableName);
        List<DynamicFormFieldVO> saveDynamicFormFieldList = new ArrayList<>(0);
        List<DynamicFormFieldVO> updateDynamicFormFieldList = new ArrayList<>(0);
        List<String> deleteDynamicFormFieldList = new ArrayList<>(0);
        LOG.debug("获取新增和修改的字段");
        for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormFields) {
            int checkTableColumn = checkTableColumn(dynamicFormFieldVO, tableColumnDTOs);
            if (checkTableColumn == -1) {
                updateDynamicFormFieldList.add(dynamicFormFieldVO);
            } else if (checkTableColumn == 1) {
                saveDynamicFormFieldList.add(dynamicFormFieldVO);
            }
        }
        LOG.debug("获取删除的字段");
        String tableId = String.format("%s_id", WStringUtil.lowerUpper2UnderLine(tableName));
        for (TableColumnDTO tableColumnDTO : tableColumnDTOs) {
            if (StringUtils.equals("id", tableColumnDTO.getColumnName()) ||
                    StringUtils.equals(tableId, tableColumnDTO.getColumnName()) ||
                    StringUtils.equals("gmt_create", tableColumnDTO.getColumnName()) ||
                    StringUtils.equals("creator", tableColumnDTO.getColumnName()) ||
                    StringUtils.equals("gmt_modified", tableColumnDTO.getColumnName()) ||
                    StringUtils.equals("modifier", tableColumnDTO.getColumnName()) ||
                    StringUtils.equals("is_delete", tableColumnDTO.getColumnName())) {
                continue;
            }
            int checkDeleteTableColumn = checkDeleteTableColumn(tableColumnDTO, dynamicFormFields);
            if (checkDeleteTableColumn == 1) {
                deleteDynamicFormFieldList.add(tableColumnDTO.getColumnName());
            }
        }
        LOG.debug("新增表字段");
        for (DynamicFormFieldVO dynamicFormFieldVO : saveDynamicFormFieldList) {
            TableColumnVO tableColumnVO = getTableColumn(dynamicFormFieldVO);
            dynamicTableService.saveTableColumn(tableName, tableColumnVO);
        }
        LOG.debug("更新表字段");
        for (DynamicFormFieldVO dynamicFormFieldVO : updateDynamicFormFieldList) {
            TableColumnVO tableColumnVO = getTableColumn(dynamicFormFieldVO);
            dynamicTableService.updateTableColumnType(tableName, tableColumnVO);
        }
        LOG.debug("删除表字段");
        for (String deleteDynamicFormField : deleteDynamicFormFieldList) {
            dynamicTableService.deleteTableColumnType(tableName, deleteDynamicFormField);
        }
    }

    /**
     * 检查table的列
     *
     * @param dynamicFormFieldVO
     * @param tableColumnDTOs
     * @return -1：需要修改，0：无需修改，1：需要新增
     */
    private int checkTableColumn(DynamicFormFieldVO dynamicFormFieldVO, List<TableColumnDTO> tableColumnDTOs) {
        for (TableColumnDTO tableColumnDTO : tableColumnDTOs) {
            if (StringUtils.equals(WStringUtil.lowerUpper2UnderLine(dynamicFormFieldVO.getFieldName()), tableColumnDTO.getColumnName())) {
                if (isSameType(dynamicFormFieldVO.getFieldType(), tableColumnDTO.getDataType())) {
                    return 0;
                } else {
                    return -1;
                }
            }
        }
        return 1;
    }

    /**
     * 检查需要删除的table列
     *
     * @param tableColumnDTO
     * @param dynamicFormFields
     * @return 0：无需修改，1：需要删除
     */
    private int checkDeleteTableColumn(TableColumnDTO tableColumnDTO, List<DynamicFormFieldVO> dynamicFormFields) {
        for (DynamicFormFieldVO dynamicFormFieldVO : dynamicFormFields) {
            if (StringUtils.equals(tableColumnDTO.getColumnName(), WStringUtil.lowerUpper2UnderLine(dynamicFormFieldVO.getFieldName()))) {
                return 0;
            }
        }
        return 1;
    }

    /**
     * 字段类型是否相同
     *
     * @param fieldType
     * @param dataType
     * @return
     */
    private boolean isSameType(String fieldType, String dataType) {
        if (StringUtils.equals(FieldTypeEnum.STRING.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.VARCHAR.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.DATETIME.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.DATETIME.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.DATE.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.DATE.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.NUMBER.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.INT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.DOUBLE.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.DOUBLE.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.TEXTAREA.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.RICH_TEXT.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.LONGTEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.SELECT.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.CHAR.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.CHECKBOX.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.RADIO.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.CHAR.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.SELECT_USER.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.SELECT_DEPARTMENT.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.FILE.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.IMAGE.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.VIDEO.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.AUDIO.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.TEXT.getDataType(), dataType)) {
            return true;
        } else if (StringUtils.equals(FieldTypeEnum.JOIN.getValue(), fieldType) && StringUtils.equals(ColumnDataTypeEnum.CHAR.getDataType(), dataType)) {
            return true;
        }
        return false;
    }

    /**
     * 获取建表的列
     *
     * @param dynamicFormFieldVO
     * @return
     */
    private TableColumnVO getTableColumn(DynamicFormFieldVO dynamicFormFieldVO) {
        TableColumnVO tableColumnVO = new TableColumnVO();
        tableColumnVO.setColumnName(dynamicFormFieldVO.getFieldName());
        tableColumnVO.setColumnComment(dynamicFormFieldVO.getFieldExplain());
        tableColumnVO.setColumnDefault(dynamicFormFieldVO.getFieldDefault());
        if (StringUtils.equals(FieldTypeEnum.STRING.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType());
            tableColumnVO.setColumnLength(255);
        } else if (StringUtils.equals(FieldTypeEnum.DATETIME.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.DATETIME.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.DATE.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.DATE.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.NUMBER.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.INT.getDataType());
            tableColumnVO.setColumnLength(11);
        } else if (StringUtils.equals(FieldTypeEnum.DOUBLE.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.DOUBLE.getDataType());
            tableColumnVO.setColumnLength(11);
            tableColumnVO.setColumnFloatLength(2);
        } else if (StringUtils.equals(FieldTypeEnum.TEXTAREA.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.RICH_TEXT.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.LONGTEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.SELECT.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.CHAR.getDataType());
            tableColumnVO.setColumnLength(36);
        } else if (StringUtils.equals(FieldTypeEnum.CHECKBOX.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.RADIO.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.CHAR.getDataType());
            tableColumnVO.setColumnLength(36);
        } else if (StringUtils.equals(FieldTypeEnum.SELECT_USER.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.SELECT_DEPARTMENT.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.FILE.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.IMAGE.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.VIDEO.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.AUDIO.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.TEXT.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.JOIN.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.CHAR.getDataType());
            tableColumnVO.setColumnLength(36);
        } else if (StringUtils.equals(FieldTypeEnum.LEFT_JOIN.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType());
            tableColumnVO.setColumnLength(255);
        } else if (StringUtils.equals(FieldTypeEnum.INNER_JOIN.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType());
            tableColumnVO.setColumnLength(255);
        } else if (StringUtils.equals(FieldTypeEnum.RIGHT_JOIN.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.VARCHAR.getDataType());
            tableColumnVO.setColumnLength(255);
        } else if (StringUtils.equals(FieldTypeEnum.CURRENT_USER.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.ID_AND_NAME.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.CURRENT_DEPARTMENT.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.IDS_AND_NAMES.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.CURRENT_ROLE.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.IDS_AND_NAMES.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.CURRENT_GROUP.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.IDS_AND_NAMES.getDataType());
        } else if (StringUtils.equals(FieldTypeEnum.CURRENT_POSITION.getValue(), dynamicFormFieldVO.getFieldType())) {
            tableColumnVO.setDataType(ColumnDataTypeEnum.IDS_AND_NAMES.getDataType());
        }
        return tableColumnVO;
    }

}
