<template>
  <div class="app-container">
    <el-descriptions class="margin-top" :title="ruleEngineInfo.name" :column="3" border>
      <template slot="extra">
        <el-dropdown split-button type="primary" @command="handleClick">
          更多操作
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="add">版本添加</el-dropdown-item>
            <el-dropdown-item command="activate">{{(ruleEngineInfo.isActivate === 'no-activate' ? "激活": "禁用")+'引擎'}}</el-dropdown-item>
            <el-dropdown-item command="status">{{(ruleEngineInfo.status === '0' ? "关闭": "开启")+'引擎'}}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

      </template>
      <el-descriptions-item label="规则名称"> {{ruleEngineInfo.name}} </el-descriptions-item>
      <el-descriptions-item label="规则类型">
        <dict-tag :options="dict.type.rule_engine_type" :value="ruleEngineInfo.type"/>
      </el-descriptions-item>
      <el-descriptions-item label="规则作用域">
        <dict-tag :options="dict.type.rule_engine_level" :value="ruleEngineInfo.level"/>
      </el-descriptions-item>
      <el-descriptions-item label="引擎编码"> {{ruleEngineInfo.code + " ("+ruleEngineInfo.engineCode+")"}} </el-descriptions-item>
      <el-descriptions-item label="是否激活">
        <dict-tag :options="dict.type.rule_engine_activate_status" :value="ruleEngineInfo.isActivate"/>
      </el-descriptions-item>
      <el-descriptions-item label="规则状态">
        <dict-tag :options="dict.type.sys_normal_disable" :value="ruleEngineInfo.status"/>
      </el-descriptions-item>
    </el-descriptions>
    <editor style="margin-top: 20px" :read-only="true" v-model="ruleEngineInfo.description"></editor>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>规则引擎版本</span>
      </div>
      <el-row :gutter="20">
        <el-col :span="12" v-for="ruleEngineVersion in ruleEngineInfo.ruleEngineVersionList">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>{{ruleEngineVersion.name + "-" + ruleEngineVersion.code}}</span>
              <el-dropdown style="float: right; padding: 3px 0"  @command="checkRuleEngineVersion">
                <span class="el-dropdown-link">
                  更多操作<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item :command="{event: 'info',ruleEngineVersion: ruleEngineVersion}">规则详情</el-dropdown-item>
                  <el-dropdown-item :command="{event:'test',ruleEngineVersion: ruleEngineVersion}"
                                    :disabled="ruleEngineVersion.status === '0'"
                  >测试规则</el-dropdown-item>
                  <el-dropdown-item :command="{event: 'status',ruleEngineVersion: ruleEngineVersion}" :disabled="ruleEngineVersion.status !=='2'">
                    {{ruleEngineVersion.isActivate !== 'no-activate' ? '禁用':'激活'}}规则
                  </el-dropdown-item>
                  <el-dropdown-item
                    :command="{event: 'publish',ruleEngineVersion: ruleEngineVersion}"
                    v-if="ruleEngineVersion.status ==='1' && ruleEngineVersion.isTest ==='1'">
                    发布规则
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
            <el-descriptions class="margin-top" :column="2" border>
              <el-descriptions-item label="版本类" :span="2"> {{ruleEngineVersion.versionCode}} </el-descriptions-item>
              <el-descriptions-item label="版本名称"> {{ruleEngineVersion.name}} </el-descriptions-item>
              <el-descriptions-item label="版本CODE"> {{ruleEngineVersion.code}} </el-descriptions-item>
              <el-descriptions-item label="是否激活">
                <dict-tag :options="dict.type.rule_engine_activate_status" :value="ruleEngineVersion.isActivate"/>
              </el-descriptions-item>
              <el-descriptions-item label="版本状态">
                <dict-tag :options="dict.type.rule_engine_version_status" :value="ruleEngineVersion.status"/>
              </el-descriptions-item>
              <el-descriptions-item label="是否测试">
                <dict-tag :options="dict.type.rule_engine_activate_is_test" :value="ruleEngineVersion.isTest"></dict-tag>
              </el-descriptions-item>
            </el-descriptions>
            <editor style="margin-top: 10px" :read-only="true" v-model="ruleEngineInfo.description"></editor>
          </el-card>
        </el-col>
      </el-row>
    </el-card>
    <el-dialog
      title="新增版本" :visible.sync="addVersionStatus"
      width="75%">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>基本信息</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="genEngineVersion">生成引擎版本类</el-button>
        </div>
        <el-form label-width="80px" :model="engineVersionForm">
          <el-row>
            <el-col :span="24">
              <el-form-item label="版本类">
                <el-input v-model="engineVersionForm.versionCode" disabled placeholder="点击类生成自动生成类名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="名称">
                <el-input v-model="engineVersionForm.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="编码">
                <el-input v-model="engineVersionForm.code"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="状态">
                <dict-tag :options="dict.type.rule_engine_version_status" :value="engineVersionForm.status"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否激活">
                <dict-tag :options="dict.type.rule_engine_activate_status" :value="engineVersionForm.isActivate"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <editor v-model="engineVersionForm.description" :min-height="150"/>
      </el-card>

      <el-card class="box-card" v-if="engineVersionForm.codeIng != null && engineVersionForm.codeIng!=''">
        <div slot="header" class="clearfix">
          <span>引擎编码</span>
        </div>
        <encoding style="height: 800px" v-model="engineVersionForm.codeIng"></encoding>
      </el-card>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addVersionCancel">取 消</el-button>
        <el-button type="primary" @click="addVersionSubmission">确 定</el-button>
      </span>
    </el-dialog>
    <el-drawer
      title="规则版本详情" size="80%" :before-close="ruleEngineVersionInfoStatusClose"
      :visible.sync="ruleEngineVersionInfoStatus"
      :direction="'rtl'">
      <div class="app-container">
        <el-descriptions v-if="ruleEngineVersionInfoAndTest != null" class="margin-top" :cloumn="2" border>
          <el-descriptions-item label="版本类" :span="2">{{ruleEngineVersionInfoAndTest.versionCode}}</el-descriptions-item>
          <el-descriptions-item label="版本名称">{{ruleEngineVersionInfoAndTest.name}}</el-descriptions-item>
          <el-descriptions-item label="版本CODE">{{ruleEngineVersionInfoAndTest.code}}</el-descriptions-item>
          <el-descriptions-item label="是否激活">
            <dict-tag :options="dict.type.rule_engine_activate_status" :value="ruleEngineVersionInfoAndTest.isActivate"></dict-tag>
          </el-descriptions-item>
          <el-descriptions-item label="版本状态">
            <dict-tag :options="dict.type.rule_engine_version_status" :value="ruleEngineVersionInfoAndTest.status"></dict-tag>
          </el-descriptions-item>
          <el-descriptions-item label="是否测试">
            <dict-tag :options="dict.type.rule_engine_activate_is_test" :value="ruleEngineVersionInfoAndTest.isTest"></dict-tag>
          </el-descriptions-item>
        </el-descriptions>
        <editor style="margin-top: 10px" :read-only="true" :min-height="100" v-model="ruleEngineVersionInfoAndTest.description"></editor>
        <el-row style="margin-top: 10px">
          <el-button @click="saveCoding">保存代码</el-button>
        </el-row>
        <encoding style="height: 800px; margin-top: 20px" v-model="ruleEngineVersionInfoAndTest.codeIng"></encoding>
      </div>

    </el-drawer>
    <el-drawer
      title="规则版本测试" size="80%" :before-close="ruleEngineVersionInfoStatusClose"
      :visible.sync="ruleEngineVersionTestStatus"
      :direction="'rtl'">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-descriptions v-if="ruleEngineVersionInfoAndTest != null" class="margin-top" :column="2">
            <el-descriptions-item label="版本类" :span="2">{{ruleEngineVersionInfoAndTest.versionCode}}</el-descriptions-item>
            <el-descriptions-item label="版本名称">{{ruleEngineVersionInfoAndTest.name}}</el-descriptions-item>
            <el-descriptions-item label="版本CODE">{{ruleEngineVersionInfoAndTest.code}}</el-descriptions-item>
            <el-descriptions-item label="是否激活">
              <dict-tag :options="dict.type.rule_engine_activate_status" :value="ruleEngineVersionInfoAndTest.isActivate"></dict-tag>
            </el-descriptions-item>
            <el-descriptions-item label="版本状态">
              <dict-tag :options="dict.type.rule_engine_version_status" :value="ruleEngineVersionInfoAndTest.status"></dict-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否测试">
              <dict-tag :options="dict.type.rule_engine_activate_is_test" :value="ruleEngineVersionInfoAndTest.isTest"></dict-tag>
            </el-descriptions-item>
          </el-descriptions>
        </el-col>
        <el-col :span="12">
          <editor style="margin-top: 10px" :read-only="true" :min-height="105" v-model="ruleEngineVersionInfoAndTest.description"></editor>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <encoding style="margin-top: 20px" v-model="ruleEngineVersionInfoAndTest.codeIng" :read-only="true"></encoding>
        </el-col>
        <el-col :span="12">
          <el-col :span="assetStructure == null ? 24: 12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>选择数据接入</span>
              </div>
              <el-select v-model="assetStructure" style="width: 100%">
                <el-option v-for="_asserStructure in assetStructureList"
                           :key="_asserStructure.dataSourceName"
                           :value="_asserStructure.dataSourceName"
                           :label="_asserStructure.dataSourceName+'('+_asserStructure.systemName+')'"
                ></el-option>
              </el-select>
            </el-card>
          </el-col>
          <el-col :span="12" v-if="assetStructure != null">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>选择资产结构</span>
              </div>
              <el-select v-model="assets" style="width: 100%">
                <el-option v-for="_assets in assetsList"
                           :key="_assets.tableName"
                           :value="_assets.tableName"
                           :label="_assets.tableName+'('+_assets.tableComment+')'"
                ></el-option>
              </el-select>
            </el-card>
          </el-col>
          <el-col :span="24" v-if="assets != null">
            <el-card class="box-card" v-if="this.ruleEngineInfo.level === 'data-field'">
              <div slot="header" class="clearfix">
                <span>选择资产模型</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="dataModelRandom">随机数据</el-button>
              </div>
              <el-descriptions direction="vertical" :column="3" border>
                <el-descriptions-item v-for="_dataModel in dataModelList"
                                      :label="_dataModel.name+'('+_dataModel.comment+')'">
                  <el-radio v-model="dataMode" :label="_dataModel.name" :value="_dataModel.id">{{dataModeMapList[dataModeMapIndex][_dataModel.name].value}}</el-radio>
                </el-descriptions-item>
              </el-descriptions>
            </el-card>
            <el-card class="box-card" v-if="this.ruleEngineInfo.level !== 'data-field'">
              <div slot="header" class="clearfix">
                <span>{{this.ruleEngineInfo.level === "data-set" ? "选择资产集" : "选择资产记录"}}</span>
              </div>
              <el-table :data="dataModeMapList" max-height="200px"
                        @selection-change="changeDataRow">
                <el-table-column type="selection" width="55" v-if="this.ruleEngineInfo.level === 'data-set'"></el-table-column>
                <el-table-column v-for="dataModel in dataModelList" :label="dataModel.name">
                  <template slot-scope="scope">
                    {{scope.row[dataModel.name].value}}
                  </template>
                </el-table-column>
                <el-table-column label="操作" v-if="this.ruleEngineInfo.level !== 'data-set'">
                  <template slot-scope="scope">
                    <el-button type="text" @click="dataRecordSelect(scope.row)">选择</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <el-descriptions title="选择行数据" direction="vertical" :column="3" border style="margin-top: 20px" v-if="dataRecordSelectData != null">
                <el-descriptions-item v-for="(val, key) in dataRecordSelectData"
                                      :label="key">
                  <el-checkbox v-model="dataRecordSelectKeyList" :label="key" :value="key">{{val.value}}</el-checkbox>
                </el-descriptions-item>
              </el-descriptions>
              <el-descriptions title="选择模型" :column="3" border style="margin-top: 20px" v-if="changeDataList.length !== 0">
                <el-descriptions-item v-for="_dataModel in dataModelList"
                                      :label="_dataModel.comment">
                  <el-checkbox v-model="dataRecordSelectKeyList" :label="_dataModel.name" :value="_dataModel.id"></el-checkbox>
                </el-descriptions-item>
              </el-descriptions>
            </el-card>
          </el-col>
          <el-col :span="24" style="margin-top: 10px" v-if="dataMode != null || dataRecordSelectKeyList.length > 0">
            <el-button @click="dataTest">测试</el-button>
            <el-input style="margin-top: 10px" v-model="testResult" type="textarea" placeholder="请点击测试"></el-input>
          </el-col>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
import {getMaintenance, selectEngineVersionListByEngineId, updateMaintenance} from "@/api/ruleEngine/maintenance";
import Encoding from "@/components/Encoding/index.vue";
import {
  addVersion,
  generatedCode,
  getDataRegionList,
  initializeRuleEngine,
  updateVersion
} from "@/api/ruleEngine/version";
import {dataAssetList, listModel, listSource} from "@/api/etl/source";
export default {
  name: "EngineVersion",
  components: {Encoding},
  dicts: ['rule_engine_activate_status', 'rule_engine_type', 'sys_normal_disable', 'rule_engine_level', 'rule_engine_version_status','rule_engine_activate_is_test'],
  watch: {
    'assetStructure': {
      handler(val) {
        if (val != null) {
          let assetStructureData;
          this.assetStructureList.forEach(_assetStructure => {
            if (_assetStructure.dataSourceName === val) {
              assetStructureData = _assetStructure
            }
          })
          dataAssetList(assetStructureData).then(res => {
            this.assetsList = res.data
          })
        }
      }
    },
    'assets': {
      handler(val) {
        if (val != null) {
          let assetStructureData;
          let dataAssetStructureData;
          this.assetsList.forEach(_assetStructure => {
            if (_assetStructure.tableName === val) {
              assetStructureData = _assetStructure
            }
          })
          this.assetStructureList.forEach(_assetStructure => {
            if (_assetStructure.dataSourceName === this.assetStructure) {
              dataAssetStructureData = _assetStructure
            }
          })
          listModel({dataAssetId: assetStructureData.id}).then(res => {
            this.dataModelList = res.data.rows
            console.log(this.dataModelList)
          })
          getDataRegionList({dataSource: dataAssetStructureData,dataAsset: assetStructureData}).then(res => {
            this.dataModeMapList = res.data
            console.log(this.dataModeMapList)
          })

        }
      }
    }
  },
  data() {
    return {
      //详情抽屉状态
      ruleEngineVersionInfoStatus: false,
      //测试抽屉状态
      ruleEngineVersionTestStatus: false,
      //弹框抽屉
      ruleEngineVersionInfoAndTest: {},
      //数据接入集合
      assetStructureList: [],
      //数据接入选择
      assetStructure: null,
      //数据资产集合
      assetsList:[],
      //数据资产选择
      assets: null,
      //数据模型集合
      dataModelList: [
        {
          id: 1,
          name: "id",
          comment: "主键",
          isPrimaryKey: "Y",
          type: "bigint",
          mappingType: "Long",
          length: "-",
          decimalPlaces: "-",
          isNull: "N",
          defaultValue: "-",
          isDict: "N",
          dictKey: "-",
        }, {
          id: 2,
          name: "name",
          comment: "姓名",
          isPrimaryKey: "N",
          type: "varchar",
          mappingType: "String",
          length: "64",
          decimalPlaces: "-",
          isNull: "N",
          defaultValue: "-",
          isDict: "N",
          dictKey: "-",
        }, {
          id: 3,
          name: "sex",
          comment: "性别",
          isPrimaryKey: "N",
          type: "char",
          mappingType: "String",
          length: "1",
          decimalPlaces: "-",
          isNull: "N",
          defaultValue: "-",
          isDict: "Y",
          dictKey: "system_sex",
        }, {
          id: 4,
          name: "price",
          comment: "金额",
          isPrimaryKey: "N",
          type: "double",
          mappingType: "BigDecimal",
          length: "10",
          decimalPlaces: "2",
          isNull: "N",
          defaultValue: "0.00",
          isDict: "N",
          dictKey: "-",
        }, {
          id: 5,
          name: "create_time",
          comment: "创建时间",
          isPrimaryKey: "N",
          type: "datetime",
          mappingType: "Date",
          length: "-",
          decimalPlaces: "-",
          isNull: "Y",
          defaultValue: "-",
          isDict: "N",
          dictKey: "-",
        }],
      //数据模型选择
      dataMode: null,
      //数据示例
      dataModeMap:{},
      dataModeMapList: [],
      dataModeMapIndex: 0,
      dataRecordSelectData: null,
      //条记录选中key集合
      dataRecordSelectKeyList: [],
      //选择行记录List
      changeDataList: [],
      testResult: "",
      ruleEngineId: this.$route.params && this.$route.params.ruleEngineId,
      ruleEngineInfo: {},
      // 新增版本
      addVersionStatus: false,
      engineVersionForm: {
        "engineMaintenanceId": this.ruleEngineId,
        "name": null,
        "code": null,
        "status": "0",
        "versionCode": "",
        "isActivate": "no-activate",
        "description": "",
        "codeIng": ""
      }
    }
  },
  created() {
    this.initRuleEngine();
    this.getListVersion();
  },
  methods: {
    //选中行
    dataRecordSelect(row) {
      this.dataRecordSelectKeyList = [];
      this.dataRecordSelectData = row;
    },
    //测试
    dataTest(){
      let number = Math.floor(Math.random()*3);
      if (number === 0){
        this.testResult = "测试正常,无异常数据返回";
      }else if (number === 1){
        this.testResult = "测试失败: 触发*****异常条例,数据发生动作[移出/忽略/记录]";
      }else if (number === 2){
        this.testResult = "程序异常: *****异常";
      }
    },
    //选择数据行
    changeDataRow(val){
      this.changeDataList = val
    },
    //随机单条数据
    dataModelRandom(){
      this.dataModeMapIndex = Math.floor(Math.random()*this.dataModeMapList.length)
    },
    //获取数据接入集合
    getAssetStructureList(){
      listSource({}).then(response => {
        this.assetStructureList = response.data.rows;
      })
    },
    saveCoding(){
      updateVersion({id: this.ruleEngineVersionInfoAndTest.id, codeIng: this.ruleEngineVersionInfoAndTest.codeIng,status: '1'})
        .then(res => {
          if (res.code == 200) {
            this.ruleEngineVersionInfoStatus = false;
            this.$message.success('编码保存成功');
            this.initRuleEngine();
          }
        })
    },
    ruleEngineVersionInfoStatusClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
          this.ruleEngineVersionInfoAndTest = {};
          done();
        })
        .catch(_ => {})
    },
    ruleEngineVersionTestStatusClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
          this.ruleEngineVersionInfoAndTest = {};
          done();
        })
        .catch(_ => {});
    },
    //点击规则事件
    checkRuleEngineVersion(command) {
      switch (command.event) {
        case "info"://详情
          this.ruleEngineVersionInfoStatus = true;
          this.ruleEngineVersionInfoAndTest = command.ruleEngineVersion;
          break;
        case "test"://测试
          this.ruleEngineVersionTestStatus = true;
          this.ruleEngineVersionInfoAndTest = command.ruleEngineVersion;
          this.getAssetStructureList();
          break;
        case  "status"://激活状态
          command.ruleEngineVersion.isActivate = 'no-activate' === command.ruleEngineVersion.isActivate ? 'activated' : 'no-activate'
          break;
        case "publish"://发布
          command.ruleEngineVersion.status = '2'
          break;
      }
    },
    // 生成规则版本
    genEngineVersion(){
      if (this.engineVersionForm.name == null || this.engineVersionForm.name === "") {
        this.$message.error('规则名称不可为空');
        return false;
      }
      if (this.engineVersionForm.code == null || this.engineVersionForm.code === "") {
        this.$message.error('规则CODE不可为空');
        return false;
      }
      console.log(this.engineVersionForm)
      generatedCode(this.engineVersionForm).then(res => {
        if (res.code === 200){
          console.log(res.data)
          this.engineVersionForm = res.data
        }
      })
      // this.engineVersionForm.versionCode = this.ruleEngineInfo.engineCode + "_" + this.engineVersionForm.code
      // this.engineVersionForm.codeIng = this.getCodeIng()
    },
    // 确定新增
    addVersionSubmission(){
      initializeRuleEngine(this.engineVersionForm).then(res => {
        if (res.code === 200){
          this.$modal.msgSuccess("新增版本成功");
          this.addVersionStatus = false;
          this.initRuleEngine();
        }
      })
    },
    // 取消新增
    addVersionCancel(){
      this.engineVersionForm = {
        "engineMaintenanceId": this.ruleEngineId,
        "name": "",
        "code": "",
        "status": "0",
        "versionCode": "",
        "isActivate": "no-activate",
        "description": "",
        "codeIng": ""
      }
      this.addVersionStatus = false;
    },
    handleClick(clickType){
      if (clickType === "add"){
        this.engineVersionForm = {
          "engineMaintenanceId": this.ruleEngineId,
          "name": "",
          "code": "",
          "status": "0",
          "versionCode": "",
          "isActivate": "no-activate",
          "description": "",
          "codeIng": ""
        }
        this.addVersionStatus = true;
      }else if(clickType === "activate"){
        this.ruleEngineInfo.isActivate = 'no-activate' === this.ruleEngineInfo.isActivate ? 'activated' : 'no-activate'
        updateMaintenance({id: this.ruleEngineInfo.id, isActivate: this.ruleEngineInfo.isActivate}).then(res => {
          if (res.code === 200){
            this.$modal.msgSuccess("引擎激活状态修改成功");
          }
        })
      }else if(clickType === "status"){
        this.ruleEngineInfo.status = '0' === this.ruleEngineInfo.status ? '1' : '0'
        updateMaintenance({id: this.ruleEngineInfo.id, status: this.ruleEngineInfo.status}).then(res => {
          if (res.code === 200){
            this.$modal.msgSuccess("引擎状态操作成功");
          }
        })
      }
    },
    initRuleEngine(){
      getMaintenance(this.ruleEngineId).then(res => {
        console.log(res,"res")
        if (res.code === 200){
          this.ruleEngineInfo = res.data;
        }
      })
    },

    getListVersion(){
      selectEngineVersionListByEngineId(this.ruleEngineId).then(res => {
        console.log(res,"res")
        if (res.code === 200){
          this.ruleEngineInfo = res.data;
        }
      })
    },

    //获取当前时间
    now() {
      let time = new Date()
      const year = time.getFullYear();
      const month = String(time.getMonth() + 1).padStart(2, '0');
      const day = String(time.getDate()).padStart(2, '0');
      let date = `${year}/${month}/${day}`;
      return date;
    },
    // 获取代码模板
    getCodeIng(){

      let packageName = "com.muyu.rule.rule.engine";
      let customName = "custom";
      let templateName = "template";
      let parentClass = null;
      switch (this.ruleEngineInfo.level) {
        case "data-field":
          parentClass = "DataModelEngine";
          break;
        case "data-record":
          parentClass = "RecordEngine";
          break;
        case "data-set":
          parentClass = "DataSetEngine";
          break;
      }
      let date = this.now();
      let codeIng = `package ${packageName}.${customName};
import com.muyu.rule.engine.action.ActionDiscard;
import com.muyu.rule.engine.scope.${parentClass};

/**
 * @Author: YaoXin
 * @date: ${date}
 * @Description: ${this.engineVersionForm.name}-${this.engineVersionForm.code}
 * @Version: 1.0
 */
public class ${this.engineVersionForm.versionCode} extends ${parentClass} {
    @Override
    public void execution () {
        Object value = getValue();

        if (value == null || "".equals(value) || "null".equals(value)) {
            throw new ActionDiscard();
        }
    }
}`;
      return codeIng;
    }

  }
}
</script>

<style scoped>
.box-card{
  margin-top: 20px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.CodeMirror {
  height: 600px;
}
</style>
