package com.chenyang.nse.bussiness.service.info.db;

import com.chenyang.nse.bussiness.commmon.SpringContext;
import com.chenyang.nse.bussiness.dao.table.console.TConsoleFastManageDao;
import com.chenyang.nse.bussiness.entity.redis.TCoreMaskingTaskTableInfo;
import com.chenyang.nse.bussiness.tools.string.StringTool;
import com.power.xml.entity.ColumnInfo;
import com.power.xml.entity.Config;
import com.power.xml.entity.FlatFile;
import com.power.xml.entity.Info;
import com.power.xml.entity.SourceInfo;
import com.power.xml.entity.TargetInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommonMethod {
   public static final String exportname = "normal";
   public static final String importname = "normal";
   public static final String exportmark = "正常导出";
   public static final String importmark = "正常导入";
   public static final String checkstateon = "selected";
   public static final String checkstateoff = "";
   public TConsoleFastManageDao tConsoleFastManageDao = (TConsoleFastManageDao)SpringContext.getContext().getBean("TConsoleFastManageDao");

   public String sourceradio() {
      return "<option value={0}  {2}>{1}</option>";
   }

   public String targetradio() {
      return "<option value={0}  {2}>{1}</option>";
   }

   public String isassignspace() {
      return "</br><label style='cursor:pointer'><input style='cursor:pointer' style='cursor:pointer'  type='checkbox'  name='isassignspace' id='isassignspace' value='isassignspace' />同步表空间</label>";
   }

   public String isrebuild() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' style='cursor:pointer'  type='checkbox'  name='isrebuild' id='isrebuild' value='isrebuild' />删除并重建表</label>";
   }

   public String isindex() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='isindex' type='checkbox' name='isindex' id='isindex'   value='isindex' />同步索引 </label>";
   }

   public String isprimary() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='isprimary' type='checkbox' name='isprimary' id='isprimary' value='isprimary' />同步主键 </label>";
   }

   public String isemptytable() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='isclear' type='checkbox' name='isclear' id='isclear'  value='isclear' checked />清空表</label>";
   }

   public String isfunction() {
      return "<label style='cursor:pointer' id='isfunction_label'><input style='cursor:pointer'  name='isfunction' type='checkbox' name='isfunction' id='isfunction'  value='isfunction' />同步存储过程和函数</label>";
   }

   public String isview() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='isview' type='checkbox' name='isview' id='isview' value='isview' />同步视图 </label>";
   }

   public String ispartition() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='ispartition' type='checkbox' name='ispartition' id='ispartition' value='ispartition' />同步表分区 </label>";
   }

   public String isconstraint() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='isconstraint' type='checkbox' name='isconstraint' id='isconstraint' value='isconstraint' />同步约束 </label>";
   }

   public String istrigger() {
      return "<label style='cursor:pointer' style='cursor:pointer' id='istrigger_label'><input  name='istrigger' type='checkbox' name='istrigger' id='istrigger'  value='istrigger'  />同步触发器</label>";
   }

   public String delete() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='inserttype' type='radio' value='delete'   />删除</label>";
   }

   public String insert() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='inserttype' type='radio' value='insert' checked  />插入 </label>";
   }

   public String insertorupdate() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='inserttype' type='radio' value='insertorupdate'  />插入或更新 </label>";
   }

   public String update() {
      return "<label style='cursor:pointer'><input style='cursor:pointer' name='inserttype' type='radio' value='update' />更新 </label>";
   }

   public Map<String, String> TargetParameter_fnormal() {
      Map<String, String> map = new HashMap();
      map.put("targetParameter", this.isrebuild() + this.isindex() + this.isprimary());
      map.put("targetParameter_empty", this.isemptytable());
      map.put("targetParameter_insert_type", this.insert() + this.delete() + this.insertorupdate() + this.update());
      return map;
   }

   public Map<String, String> TargetParameter_fnotnormal() {
      Map<String, String> map = new HashMap();
      map.put("targetParameter", this.isrebuild() + this.isindex() + this.isprimary());
      map.put("targetParameter_empty", this.isemptytable());
      map.put("targetParameter_insert_type", "");
      return map;
   }

   public void s(Map<String, Object> map) {
      Info info = new Info();
      SourceInfo sourceInfo = new SourceInfo();
      List<ColumnInfo> sourcecolumnInfoList = new ArrayList();
      List<ColumnInfo> targetcolumnInfoList = new ArrayList();
      ColumnInfo columnInfo = new ColumnInfo();
      columnInfo.setColumnName("");
      columnInfo.setDataType("");
      columnInfo.setDateTimeFormat("");
      columnInfo.setKeyType(1);
      columnInfo.setMaskingRule("");
      columnInfo.setNullable(1);
      columnInfo.setPrecision("");
      columnInfo.setQualifierType("");
      columnInfo.setScale("");
      sourceInfo.setColumnInfoList(sourcecolumnInfoList);
      sourceInfo.setConnectName("");
      sourceInfo.setDataBaseType("");
      FlatFile sourceflatFile = new FlatFile();
      sourceflatFile.setCodePage("");
      sourceflatFile.setCommand("");
      sourceflatFile.setDelimiter("");
      sourceflatFile.setFilename("");
      sourceflatFile.setFileType(1);
      sourceflatFile.setQuoteCharacter(1);
      sourceflatFile.setSkipRows(1);
      sourceInfo.setFlatFile(sourceflatFile);
      sourceInfo.setName("");
      sourceInfo.setSchema("");
      sourceInfo.setSqlFilter("");
      sourceInfo.setSqlQuery("");
      TargetInfo targetInfo = new TargetInfo();
      targetInfo.setColumnInfoList(targetcolumnInfoList);
      targetInfo.setConnectName("");
      targetInfo.setDataBaseType("");
      FlatFile targetflatFile = new FlatFile();
      targetflatFile.setCodePage("");
      targetflatFile.setCommand("");
      targetflatFile.setDelimiter("");
      targetflatFile.setFilename("");
      targetflatFile.setFileType(1);
      targetflatFile.setQuoteCharacter(1);
      targetflatFile.setSkipRows(1);
      targetInfo.setFlatFile(targetflatFile);
      targetInfo.setIsTruncate(1);
      targetInfo.setName("");
      targetInfo.setSchema("");
      targetInfo.setWriteType(1);
      Config config = new Config();
      config.setDomainName("");
      config.setFolderName("");
      config.setMappletDir("");
      config.setReadMode(1);
      config.setRepositoryName("");
      config.setServerName("");
      config.setSessionLogCount(1);
      config.setWriteMode(1);
      config.setXmlLocation("");
      info.setSourceInfo(sourceInfo);
      info.setTargetInfo(targetInfo);
      info.setTaskname("t_");
      new ArrayList();
   }

   public ColumnInfo getPwc_columnInfo_target_all_base(Map map) {
      ColumnInfo pwc_columnInfo_target = new ColumnInfo();
      TCoreMaskingTaskTableInfo tCoreMaskingTaskTableInfo = (TCoreMaskingTaskTableInfo)map.get("tCoreMaskingTaskTableInfo");
      int type = (Integer)map.get("type");
      Map<String, String> data_by_source = (Map)map.get("data_by_source");
      Boolean issomedb = (Boolean)map.get("issomedb");
      Map<String, Map<String, String>> data_target_length = (Map)map.get("data_target_length");
      Map<String, Map<String, String>> data_target = (Map)map.get("data_target");
      Map<String, Map<String, String>> data_t_x_length = (Map)map.get("data_t_x_length");
      Map<String, String> data_rule = (Map)map.get("data_rule");
      String qualifierType = (String)map.get("qualifierType");
      Config pwc_config = (Config)map.get("pwc_config");
      String source = StringTool.delparentheses(tCoreMaskingTaskTableInfo.getSourceType().toLowerCase());
      String pwc_type = (String)data_by_source.get(source);
      String targetype = "";
      String targetlength = "";
      String targetscancale = "";
      String targetpwcsqlength = "";
      String targetpwcsqscale = "";
      String targetpwcdateformat = "";
      if (type == 0) {
         if (issomedb) {
            targetype = source;
            targetlength = (String)((Map)data_target_length.get(source)).get("sourcelength");
            targetscancale = (String)((Map)data_target_length.get(source)).get("sourcescancale");
            targetpwcsqlength = (String)((Map)data_target_length.get(source)).get("pwcsqlength");
            targetpwcsqscale = (String)((Map)data_target_length.get(source)).get("pwcsqscale");
            targetpwcdateformat = (String)((Map)data_target_length.get(source)).get("pwcdateformat");
         } else {
            targetype = ((String)((Map)data_target.get(pwc_type)).get("sourcefieldname")).toLowerCase();
            targetlength = (String)((Map)data_target_length.get(targetype)).get("sourcelength");
            targetscancale = (String)((Map)data_target_length.get(targetype)).get("sourcescancale");
            targetpwcsqlength = (String)((Map)data_target_length.get(targetype)).get("pwcsqlength");
            targetpwcsqscale = (String)((Map)data_target_length.get(targetype)).get("pwcsqscale");
            targetpwcdateformat = (String)((Map)data_target_length.get(targetype)).get("pwcdateformat");
         }
      } else {
         targetype = StringTool.delparentheses(tCoreMaskingTaskTableInfo.getTargetType().toLowerCase());
         targetlength = (String)((Map)data_t_x_length.get(targetype + pwc_type)).get("sourcelength");
         targetscancale = (String)((Map)data_t_x_length.get(targetype + pwc_type)).get("sourcescancale");
         targetpwcsqlength = (String)((Map)data_t_x_length.get(targetype + pwc_type)).get("pwcsqlength");
         targetpwcsqscale = (String)((Map)data_t_x_length.get(targetype + pwc_type)).get("pwcsqscale");
         targetpwcdateformat = (String)((Map)data_t_x_length.get(targetype + pwc_type)).get("pwcdateformat");
      }

      pwc_columnInfo_target.setColumnName(tCoreMaskingTaskTableInfo.getColumnName());
      if ("SYSDATE".equalsIgnoreCase(pwc_columnInfo_target.getColumnName())) {
         pwc_columnInfo_target.setColumnName(tCoreMaskingTaskTableInfo.getColumnName() + "1");
      }

      pwc_columnInfo_target.setDataType(StringTool.delparentheses(targetype.toUpperCase()));
      pwc_columnInfo_target.setKeyType(tCoreMaskingTaskTableInfo.getIsPrimaryKey().equals("1") ? 1 : (tCoreMaskingTaskTableInfo.getIsForeignKey() != null ? (tCoreMaskingTaskTableInfo.getIsForeignKey().equals("1") ? 2 : 0) : 0));
      pwc_columnInfo_target.setMaskingRule((String)data_rule.get(tCoreMaskingTaskTableInfo.getRegexRuleId()));
      pwc_columnInfo_target.setNullable(pwc_columnInfo_target.getKeyType() != 0 ? 1 : 0);
      pwc_columnInfo_target.setQualifierType(qualifierType.toLowerCase());
      pwc_columnInfo_target.setScale(targetscancale != null && !targetscancale.equals("") ? targetscancale : tCoreMaskingTaskTableInfo.getColumnPrecision());
      pwc_columnInfo_target.setPrecision(targetlength != null && !targetlength.equals("") ? targetlength : tCoreMaskingTaskTableInfo.getColumnLength());
      if (pwc_columnInfo_target.getPrecision() == null || "".equals(pwc_columnInfo_target.getPrecision())) {
         pwc_columnInfo_target.setPrecision(tCoreMaskingTaskTableInfo.getColumnLength());
      }

      if (targetpwcsqlength != null && !targetpwcsqlength.equals("")) {
         pwc_columnInfo_target.setSqprecision(targetpwcsqlength);
         pwc_columnInfo_target.setSqscale(targetpwcsqscale);
      }

      if (targetpwcdateformat != null && !targetpwcdateformat.equals("") && pwc_config.getWriteMode() == 1) {
         pwc_columnInfo_target.setDateTimeFormat(targetpwcdateformat);
      }

      return pwc_columnInfo_target;
   }

   public ColumnInfo getPwc_columnInfo_source_all_base(Map map) {
      ColumnInfo pwc_columnInfo_source = new ColumnInfo();
      TCoreMaskingTaskTableInfo tCoreMaskingTaskTableInfo = (TCoreMaskingTaskTableInfo)map.get("tCoreMaskingTaskTableInfo");
      pwc_columnInfo_source.setParameterlist(tCoreMaskingTaskTableInfo.getParameterlist());
      Map<String, Map<String, String>> data_source_length = (Map)map.get("data_source_length");
      Map<String, String> data_rule = (Map)map.get("data_rule");
      String qualifierType = (String)map.get("qualifierType");
      Config pwc_config = (Config)map.get("pwc_config");
      String sourcetype = StringTool.delparentheses(tCoreMaskingTaskTableInfo.getSourceType().toUpperCase());
      String source = StringTool.delparentheses(tCoreMaskingTaskTableInfo.getSourceType().toLowerCase());
      pwc_columnInfo_source.setColumnName(tCoreMaskingTaskTableInfo.getColumnName());
      if ("SYSDATE".equalsIgnoreCase(pwc_columnInfo_source.getColumnName())) {
         pwc_columnInfo_source.setColumnName(tCoreMaskingTaskTableInfo.getColumnName() + "1");
      }

      pwc_columnInfo_source.setDataType(sourcetype);
      if (tCoreMaskingTaskTableInfo.getIsPrimaryKey() == null) {
         tCoreMaskingTaskTableInfo.setIsPrimaryKey("");
      }

      pwc_columnInfo_source.setKeyType(tCoreMaskingTaskTableInfo.getIsPrimaryKey().equals("1") ? 1 : (tCoreMaskingTaskTableInfo.getIsForeignKey() != null ? (tCoreMaskingTaskTableInfo.getIsForeignKey().equals("1") ? 2 : 0) : 0));
      pwc_columnInfo_source.setMaskingRule((String)data_rule.get(tCoreMaskingTaskTableInfo.getRegexRuleId()));
      pwc_columnInfo_source.setNullable(pwc_columnInfo_source.getKeyType() != 0 ? 1 : 0);
      pwc_columnInfo_source.setQualifierType(qualifierType.toLowerCase());
      String sourcelength = (String)((Map)data_source_length.get(source)).get("sourcelength");
      String sourcescancale = (String)((Map)data_source_length.get(source)).get("sourcescancale");
      String pwcsqlength = (String)((Map)data_source_length.get(source)).get("pwcsqlength");
      String pwcsqscale = (String)((Map)data_source_length.get(source)).get("pwcsqscale");
      String pwcdateformat = (String)((Map)data_source_length.get(source)).get("pwcdateformat");
      pwc_columnInfo_source.setScale(sourcescancale != null && !sourcescancale.equals("") ? sourcescancale : tCoreMaskingTaskTableInfo.getColumnPrecision());
      pwc_columnInfo_source.setPrecision(sourcelength != null && !sourcelength.equals("") ? sourcelength : tCoreMaskingTaskTableInfo.getColumnLength());
      if (pwcsqlength != null && !pwcsqlength.equals("")) {
         pwc_columnInfo_source.setSqprecision(pwcsqlength);
         pwc_columnInfo_source.setSqscale(pwcsqscale);
      }

      if (pwcdateformat != null && !pwcdateformat.equals("") && pwc_config.getReadMode() == 1) {
         pwc_columnInfo_source.setDateTimeFormat(pwcdateformat);
      } else if (tCoreMaskingTaskTableInfo.getColumnformat() != null && !tCoreMaskingTaskTableInfo.getColumnformat().equals("")) {
         pwc_columnInfo_source.setDateTimeFormat(tCoreMaskingTaskTableInfo.getColumnformat());
      }

      return pwc_columnInfo_source;
   }
}
